Skip to content

Commit

Permalink
feat: use npmupdate binary (#414)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed May 2, 2023
1 parent da36942 commit af6fede
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
uses: artusjs/github-actions/.github/workflows/node-test.yml@v1
with:
os: 'ubuntu-latest, macos-latest, windows-latest'
version: '14.18.0, 14, 16, 18'
version: '14.18.0, 14, 16, 18, 20'
# npm install npm will be fail on Windows with Node.js 14.x, use npminstall instead
# see https://github.com/npm/cli/issues/4438
install: 'npm i -g npminstall && npminstall'
1 change: 0 additions & 1 deletion bin/cnpm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const extendsMethd = {
doc: 1,
sync: 1,
user: 1,
update: 1,
};

debug('cnpm %s', action);
Expand Down
24 changes: 0 additions & 24 deletions bin/cnpm-update

This file was deleted.

11 changes: 11 additions & 0 deletions lib/origin_npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const program = parseArgv();
const rawArgs = program.rawArgs.slice(2);
const args = [];
let isInstall = false;
let isUpdate = false;
let installer = 'npminstall';

for (let i = 0; i < rawArgs.length; i++) {
Expand All @@ -22,6 +23,10 @@ for (let i = 0; i < rawArgs.length; i++) {
isInstall = true;
continue;
}
if (i === 0 && (arg === 'update')) {
isUpdate = true;
continue;
}

// support `$ cnpm i --by=npm`
if (arg.indexOf('--by=') === 0) {
Expand Down Expand Up @@ -77,6 +82,12 @@ if (isInstall) {
if (!fs.existsSync(npmBin)) {
npmBin = installer;
}
} else if (isUpdate) {
execMethod = cp.fork;
stdio.push('ipc');
npmBin = require.resolve('npminstall/bin/update.js');
args.unshift('--china');
args.unshift('--fix-bug-versions');
} else {
npmBin = path.join(__dirname, '..', 'node_modules', '.bin', 'npm');
}
Expand Down
10 changes: 6 additions & 4 deletions test/cnpm-update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,20 @@ describe('test/cnpm-update.test.js', () => {
cwd: root,
})
.debug()
.expect('stdout', /\[cnpm:update] Removing/)
.expect('stdout', /\[cnpm:update] Running "cnpm install" on /)
.expect('stdout', /\[npmupdate] removing/)
.expect('stdout', /\[npmupdate] reinstall on /)
.expect('code', 0)
.end();
await coffee.fork(cnpm, [
'update',
'--offline',
], {
cwd: root,
})
.debug()
.expect('stdout', /\[cnpm:update] Removing/)
.expect('stdout', /\[cnpm:update] Running "cnpm install" on /)
.expect('stderr', /npminstall WARN running on offline mode/)
.expect('stdout', /\[npmupdate] removing/)
.expect('stdout', /\[npmupdate] reinstall on /)
.expect('code', 0)
.end();
});
Expand Down

0 comments on commit af6fede

Please sign in to comment.