diff --git a/.eslintrc b/.eslintrc index 72c1d0e..e3a0efd 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,2 +1,5 @@ root: true extends: silverwind + +ignorePatterns: + - /updates diff --git a/.gitignore b/.gitignore index bdafb89..b563d52 100644 --- a/.gitignore +++ b/.gitignore @@ -2,5 +2,6 @@ /node_modules /npm-debug.log* /package-lock.json +/updates /yarn-error.log /yarn.lock diff --git a/Makefile b/Makefile index d6ed9bd..663ef90 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,10 @@ -test: +test: rollup yarn -s run eslint --color . yarn -s run jest --color +rollup: + yarn -s run rollup --silent --compact -c rollup.config.js + publish: git push -u --tags origin master npm publish @@ -26,4 +29,4 @@ major: test yarn -s run versions -C major $(MAKE) publish -.PHONY: test publish deps update patch minor major +.PHONY: test rollup publish deps update patch minor major diff --git a/package.json b/package.json index 7666aea..c122661 100644 --- a/package.json +++ b/package.json @@ -5,7 +5,7 @@ "author": "silverwind", "repository": "silverwind/updates", "license": "BSD-2-Clause", - "bin": "./updates.js", + "bin": "./updates", "engines": { "node": ">=10" }, @@ -23,31 +23,36 @@ "packages" ], "files": [ - "updates.js" + "updates" ], - "dependencies": { - "colorette": "1.1.0", - "hosted-git-info": "3.0.4", - "make-fetch-happen": "8.0.3", - "minimist": "1.2.0", - "rc": "1.2.8", - "registry-auth-token": "4.1.1", - "semver": "7.1.3", - "string-width": "4.2.0", - "text-table": "0.2.0" - }, "devDependencies": { + "@rollup/plugin-commonjs": "11.0.2", + "@rollup/plugin-json": "4.0.2", + "@rollup/plugin-node-resolve": "7.1.1", + "colorette": "1.1.0", "create-test-server": "3.0.1", "del": "5.1.0", "eslint": "6.8.0", "eslint-config-silverwind": "10.0.0", "execa": "4.0.0", + "hosted-git-info": "3.0.4", "jest": "25.1.0", + "make-fetch-happen": "8.0.3", + "minimist": "1.2.0", + "node-fetch": "2.6.0", + "rc": "1.2.8", + "registry-auth-token": "4.1.1", + "rollup": "2.0.2", + "rollup-plugin-hashbang": "2.2.2", + "rollup-plugin-terser": "5.3.0", + "semver": "7.1.3", + "string-width": "4.2.0", "tempy": "0.4.0", + "text-table": "0.2.0", "versions": "8.2.4" }, "jest": { "verbose": false, - "testTimeout": 30000 + "testTimeout": 10000 } } diff --git a/rollup.config.js b/rollup.config.js new file mode 100644 index 0000000..fe5aa64 --- /dev/null +++ b/rollup.config.js @@ -0,0 +1,28 @@ +const {name} = require("./package.json"); + +module.exports = { + input: `${name}.js`, + output: { + file: name, + name, + format: "cjs", + }, + plugins: [ + require("rollup-plugin-hashbang")(), + require("@rollup/plugin-json")(), + require("@rollup/plugin-node-resolve")({ + preferBuiltins: true, + jail: __dirname, + customResolveOptions: { + packageFilter: (pkg) => { + if (pkg.name === "cacache") { + return {main: "/dev/null"}; + } + return pkg; + } + } + }), + require("@rollup/plugin-commonjs")(), + require("rollup-plugin-terser").terser({output: {comments: false}}), + ], +}; diff --git a/test.js b/test.js index d2d4308..8d7efbe 100644 --- a/test.js +++ b/test.js @@ -7,10 +7,10 @@ const tempy = require("tempy"); const {join} = require("path"); const {test, expect, beforeAll, afterAll} = global; const {writeFile, readFile} = require("fs").promises; +const {bin} = require("./package.json"); const packageJson = require("./fixtures/test.json"); const testDir = tempy.directory(); -let npmServer, githubServer, githubApiUrl; const dependencyTypes = [ "dependencies", @@ -26,9 +26,16 @@ for (const dependencyType of dependencyTypes) { } } +let npmServer, githubServer, githubApiUrl; beforeAll(async () => { - npmServer = await createTestServer(); // npm api response - githubServer = await createTestServer(); // github api response + let commits, tags; + + [npmServer, githubServer, commits, tags] = await Promise.all([ + createTestServer(), + createTestServer(), + readFile(join(__dirname, "fixtures/github/updates-commits.json")), + readFile(join(__dirname, "fixtures/github/updates-tags.json")) + ]); for (const packageName of testPackages) { const name = packageName.replace(/\//g, "%2f"); @@ -36,8 +43,6 @@ beforeAll(async () => { npmServer.get(`/${name}`, await readFile(path)); } - const commits = await readFile(join(__dirname, "fixtures/github/updates-commits.json")); - const tags = await readFile(join(__dirname, "fixtures/github/updates-tags.json")); githubServer.get("/repos/silverwind/updates/commits", commits); githubServer.get("/repos/silverwind/updates/git/refs/tags", tags); @@ -57,7 +62,7 @@ afterAll(async () => { function makeTest(args, expected) { return async () => { const argsArr = [...args.split(/\s+/), "-G", githubApiUrl]; - const {stdout} = await execa(join(__dirname, "updates.js"), argsArr, {cwd: testDir}); + const {stdout} = await execa(join(__dirname, bin), argsArr, {cwd: testDir}); const {results} = JSON.parse(stdout); // Parse results, with custom validation for the dynamic "age" property diff --git a/updates.js b/updates.js index a1d7987..9d2c84a 100755 --- a/updates.js +++ b/updates.js @@ -297,7 +297,12 @@ function getAuthAndRegistry(name, registry) { } function fetchFromRegistry(name, registry, auth) { - const opts = {maxSockets}; + const opts = { + maxSockets, + cacheManager: null, + retry: 5, + }; + if (auth && auth.token) { opts.headers = {Authorization: `${auth.type} ${auth.token}`}; }