switch to fetch-enhanced and ncc

This commit is contained in:
silverwind 2020-09-18 17:53:31 +02:00
parent cdaaab7eec
commit b66a939d17
Signed by: silverwind
GPG Key ID: 2E62B41C93869443
4 changed files with 14 additions and 63 deletions

@ -8,7 +8,8 @@ unittest:
yarn -s run jest --color --watchAll
build:
yarn -s run rollup --silent --compact -c rollup.config.js
yarn -s run ncc build updates.js -q -m -o .
@mv index.js updates
publish:
git push -u --tags origin master

@ -26,25 +26,21 @@
"updates"
],
"devDependencies": {
"@rollup/plugin-commonjs": "15.0.0",
"@rollup/plugin-json": "4.1.0",
"@rollup/plugin-node-resolve": "9.0.0",
"@vercel/ncc": "0.24.1",
"ansi-regex": "5.0.0",
"del": "5.1.0",
"eslint": "7.9.0",
"eslint-config-silverwind": "18.0.8",
"execa": "4.0.3",
"fetch-enhanced": "2.2.0",
"hosted-git-info": "3.0.5",
"jest": "26.4.2",
"jest-extended": "0.11.5",
"make-fetch-happen": "8.0.9",
"minimist": "1.2.5",
"node-fetch": "2.6.1",
"rc": "1.2.8",
"registry-auth-token": "4.2.0",
"restana": "4.7.4",
"rollup": "2.26.11",
"rollup-plugin-hashbang": "2.2.2",
"rollup-plugin-terser": "7.0.2",
"semver": "7.3.2",
"tempy": "0.6.0",
"text-table": "0.2.0",

@ -1,46 +0,0 @@
const {unlinkSync} = require("fs");
const {writeSync} = require("tempy");
const {name} = require("./package.json");
const nullTemp = writeSync("export default null;", {extension: "mjs"});
const nullRouted = new Set([
"cacache",
"ssri",
"stripJsonComments",
"encoding",
]);
module.exports = {
input: `${name}.js`,
output: {
file: name,
name,
format: "cjs",
exports: "auto",
},
plugins: [
require("rollup-plugin-hashbang")(),
require("@rollup/plugin-json")({
indent: "",
preferConst: true,
}),
require("@rollup/plugin-node-resolve").default({
customResolveOptions: {
packageFilter: pkg => {
if (nullRouted.has(pkg.name)) return {main: nullTemp, type: "module"};
return pkg;
},
}
}),
require("@rollup/plugin-commonjs")({
sourceMap: false,
}),
require("rollup-plugin-terser").terser({
output: {comments: false},
}),
],
};
process.on("exit", () => {
unlinkSync(nullTemp);
});

@ -1,8 +1,9 @@
#!/usr/bin/env node
const ansiRegex = require("ansi-regex");
const dns = require("dns");
const fetch = require("make-fetch-happen");
const fetchEnhanced = require("fetch-enhanced");
const minimist = require("minimist");
const nodeFetch = require("node-fetch");
const rat = require("registry-auth-token");
const rc = require("rc");
const ru = require("registry-auth-token/registry-url");
@ -15,6 +16,8 @@ const {lstatSync, readFileSync, truncateSync, writeFileSync, accessSync} = requi
const {platform} = require("os");
const {version} = require("./package.json");
const fetch = fetchEnhanced(nodeFetch);
env.NODE_ENV = "production";
const MAX_SOCKETS = 96;
@ -184,9 +187,12 @@ const defaultRegistry = "https://registry.npmjs.org";
const npmrc = rc("npm", {registry: defaultRegistry});
const authTokenOpts = {npmrc, recursive: true};
const registry = normalizeUrl(args.registry || npmrc.registry);
const maxSockets = typeof args.sockets === "number" ? args.sockets : MAX_SOCKETS;
const githubApiUrl = args.githubapi ? normalizeUrl(args.githubapi) : "https://api.github.com";
const fetchOpts = {
maxSockets: typeof args.sockets === "number" ? args.sockets : MAX_SOCKETS,
};
let packageFile;
const deps = {};
const maybeUrlDeps = {};
@ -342,13 +348,7 @@ function getAuthAndRegistry(name, registry) {
}
function fetchFromRegistry(name, registry, auth) {
const opts = {
maxSockets,
cacheManager: null,
integrity: null,
retry: 5,
};
const opts = {...fetchOpts};
if (auth && auth.token) {
opts.headers = {Authorization: `${auth.type} ${auth.token}`};
}