From 810ee29f7a892b68ce9fd20da52dd8968688194e Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Fri, 25 Mar 2022 22:12:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=F0=9F=93=A6=20NEW:=20Support=20override=20?= =?UTF-8?q?custom=20scripts=20on=20bug-versions=20(#393)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Deps https://github.com/cnpm/bug-versions/pull/185 --- lib/download/npm.js | 21 +++++++++++++++++++++ test/fix-bug-versions.test.js | 19 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/lib/download/npm.js b/lib/download/npm.js index 05a77e19..6c6cd1d6 100644 --- a/lib/download/npm.js +++ b/lib/download/npm.js @@ -77,6 +77,7 @@ async function resolve(pkg, options) { let realPkgVersion = utils.findMaxSatisfyingVersion(spec, distTags, packageMeta.allVersions); let fixDependencies; + let fixScripts; if (!realPkgVersion) { throw new Error(`[${pkg.displayName}] Can\'t find package ${pkg.name}@${pkg.rawSpec}`); @@ -93,6 +94,20 @@ async function resolve(pkg, options) { options.console.warn(`[${pkg.name}@${realPkgVersion}] use dependencies: ${chalk.green(JSON.stringify(fixVersion.dependencies))} instead, reason: ${chalk.yellow(fixVersion.reason)}`); fixDependencies = fixVersion.dependencies; } + // https://github.com/npm/rfcs/pull/488/files + // merge custom scripts + // { + // "foo": { + // "1.0.0": { + // "scripts": { "postinstall": "" }, + // "reason": "some description message" + // } + // } + // } + if (fixVersion.scripts) { + options.console.warn(`[${pkg.name}@${realPkgVersion}] use scripts: ${chalk.green(JSON.stringify(fixVersion.scripts))} instead, reason: ${chalk.yellow(fixVersion.reason)}`); + fixScripts = fixVersion.scripts; + } } } @@ -104,6 +119,9 @@ async function resolve(pkg, options) { if (fixDependencies) { realPkg.__fixDependencies = fixDependencies; } + if (fixScripts) { + realPkg.__fixScripts = fixScripts; + } debug('[%s@%s] spec: %s, real version: %s, dist-tags: %j', pkg.name, pkg.rawSpec, pkg.fetchSpec, realPkg.version, distTags); @@ -335,6 +353,9 @@ async function download(pkg, options) { if (pkg.__fixDependencies) { pkg.dependencies = Object.assign({}, pkg.dependencies, pkg.__fixDependencies); } + if (pkg.__fixScripts) { + pkg.scripts = Object.assign({}, pkg.scripts, pkg.__fixScripts); + } await utils.setInstallDone(ungzipDir); diff --git a/test/fix-bug-versions.test.js b/test/fix-bug-versions.test.js index ba2e3a05..1a7b9af3 100644 --- a/test/fix-bug-versions.test.js +++ b/test/fix-bug-versions.test.js @@ -58,6 +58,25 @@ describe('test/fix-bug-versions.test.js', () => { assert(getPkg('node_modules/accord/node_modules/less/package.json').version.split('.')[0] === '2'); }); + it('should use fix "scripts"', async () => { + await coffee.fork(bin, [ + 'styled-components@5.3.5', + '-d', + '--fix-bug-versions', + '--no-cache', + ], { cwd: tmp }) + .debug() + .expect('code', 0) + .expect('stderr', /use scripts: {\"postinstall\":\"\"} instead, reason:/) + .notExpect('stderr', /scripts.postinstall styled-components@5.3.5 finished/) + .notExpect('stdout', /scripts.postinstall styled-components@5.3.5 finished/) + .end(); + + const pkg = getPkg('node_modules/styled-components/package.json'); + assert(pkg.version === '5.3.5'); + assert(pkg.scripts.postinstall === 'node ./postinstall.js'); + }); + it('should support on install and update', async () => { await coffee.fork(bin, [ '-d', From d19e5de81cfc0ecba023b453c3299aa725d02e12 Mon Sep 17 00:00:00 2001 From: fengmk2 Date: Fri, 25 Mar 2022 22:35:11 +0800 Subject: [PATCH 2/2] f --- .github/workflows/ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 81e12f6b..4d633da9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,9 +5,9 @@ name: Node CI on: push: - branches: [ master ] + branches: [ master, 5.x, 4.x, 3.x ] pull_request: - branches: [ master ] + branches: [ master, 5.x, 4.x, 3.x ] jobs: build: