From b66a939d1702eff43624e4ea880b41c132dc4f9a Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 18 Sep 2020 17:53:31 +0200 Subject: [PATCH] switch to fetch-enhanced and ncc --- Makefile | 3 ++- package.json | 10 +++------- rollup.config.js | 46 ---------------------------------------------- updates.js | 18 +++++++++--------- 4 files changed, 14 insertions(+), 63 deletions(-) delete mode 100644 rollup.config.js diff --git a/Makefile b/Makefile index 242c60c..8ba344c 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/package.json b/package.json index 4fd3047..0c4275f 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/rollup.config.js b/rollup.config.js deleted file mode 100644 index b48c644..0000000 --- a/rollup.config.js +++ /dev/null @@ -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); -}); diff --git a/updates.js b/updates.js index ab914d6..990a8c7 100755 --- a/updates.js +++ b/updates.js @@ -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}`}; }