Skip to content

Commit

Permalink
feat: mac rapid (#34)
Browse files Browse the repository at this point in the history
* feat: mac rapid

* fix: ci
  • Loading branch information
elrrrrrrr authored Oct 20, 2023
1 parent 3d1e914 commit fa88553
Show file tree
Hide file tree
Showing 20 changed files with 166 additions and 485 deletions.
35 changes: 25 additions & 10 deletions integration/index.2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ describe('test/index.v2.test.js', () => {
afterEach(async () => {
await clean(cwd);
if (process.platform === 'darwin') {
await forceExitDaemon();
try {
await forceExitDaemon();
} catch (err) {
console.warn('force exit daemon error: %s', err.message);
}
} else {
await exitDaemon();
}
Expand All @@ -43,7 +47,7 @@ describe('test/index.v2.test.js', () => {
if (process.platform === 'linux') {
it('should run postinstall successfully', async () => {
cwd = path.join(__dirname, './fixtures/node-crc');
await coffee.fork(rapid, [ '--by=npm', `--deps-tree-path=${path.join(cwd, 'package-lock.json')}` ], { cwd })
await coffee.fork(rapid, [ 'install', '--by=npm', `--deps-tree-path=${path.join(cwd, 'package-lock.json')}` ], { cwd })
.debug()
.expect('stdout', /execute 1 lifecycle script\(s\)/)
.expect('code', 0)
Expand All @@ -56,7 +60,7 @@ describe('test/index.v2.test.js', () => {
describe('INIT_CWD', async () => {
it('should set INIT_CWD', async () => {
cwd = path.join(__dirname, './fixtures/init-cwd');
await coffee.fork(rapid, [ '--by=npminstall', `--deps-tree-path=${path.join(cwd, 'package-lock.json')}` ], { cwd })
await coffee.fork(rapid, [ 'install', '--by=npminstall', `--deps-tree-path=${path.join(cwd, 'package-lock.json')}` ], { cwd })
.debug()
.expect('stdout', new RegExp(`INIT_CWD=${process.cwd()}`))
.expect('code', 0)
Expand All @@ -67,8 +71,17 @@ describe('test/index.v2.test.js', () => {
describe('production mode', async () => {
it('should install production deps', async () => {
cwd = path.join(__dirname, './fixtures/prod-deps');
await coffee.fork(rapid, [
'--by=npminstall', '--production', `--deps-tree-path=${path.join(cwd, 'package-lock.json')}` ], { cwd })
await coffee
.fork(
rapid,
[
'install',
'--by=npminstall',
'--production',
`--deps-tree-path=${path.join(cwd, 'package-lock.json')}`,
],
{ cwd }
)
.debug()
.expect('code', 0)
.end();
Expand All @@ -81,7 +94,7 @@ describe('test/index.v2.test.js', () => {
it('should install node-canvas successfully', async () => {
cwd = path.join(__dirname, './fixtures/canvas');
await coffee
.fork(rapid, [ `--deps-tree-path=${path.join(cwd, 'package-lock.json')}` ], { cwd })
.fork(rapid, [ 'install' ], { cwd })
.debug()
.expect('code', 0)
.end();
Expand All @@ -100,8 +113,9 @@ describe('test/index.v2.test.js', () => {
delete process.env[k];
}
}

await coffee
.fork(rapid, [ `--deps-tree-path=${path.join(cwd, 'package-lock.json')}` ], {
.fork(rapid, [ 'install', '--ignore-scripts' ], {
cwd,
})
.debug()
Expand All @@ -118,8 +132,8 @@ describe('test/index.v2.test.js', () => {
cwd = path.join(__dirname, './fixtures/esbuild');
await coffee
.fork(rapid, [
'--by=npm',
`--deps-tree-path=${path.join(cwd, 'package-lock.json')}`,
'install',
'--ignore-scripts',
], {
cwd,
})
Expand All @@ -137,8 +151,9 @@ describe('test/index.v2.test.js', () => {
cwd = path.join(__dirname, './fixtures/esbuild');
await coffee
.fork(rapid, [
'install',
'--by=npminstall',
`--deps-tree-path=${path.join(cwd, 'package-lock.json')}`,
'--ignore-scripts',
], {
cwd,
})
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,3 @@
"node": ">=14.19.1"
}
}

127 changes: 53 additions & 74 deletions packages/cli/bin/rapid.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,84 +2,63 @@

'use strict';


const { clean, install } = require('../lib/index.js');
const parser = require('yargs-parser');
const { clean, install, list } = require('../lib/index.js');
const yargs = require('yargs');
const { NpmFsMode } = require('../lib/constants.js');
const httpclient = require('../lib/httpclient');
const util = require('../lib/util');

async function runner() {
const params = parser(process.argv.slice(2), {
alias: {
'save-dev': [ 'D' ],
save: [ 'save-prod', 'S', 'P' ],
'save-optional': [ 'O' ],
'save-bundle': [ 'B' ],
'save-exact': [ 'E' ],
version: [ 'v' ],
usage: [ 'H', 'h', 'help', '?' ],
global: [ 'g' ],
detail: [ 'd' ],
mode: [ 'by' ],
prefix: [ 'C' ],
registry: [ 'reg' ],
yargs
.command({
command: 'install',
describe: 'Install dependencies',
builder: yargs => {
return yargs
.option('ignore-scripts', {
describe: 'Skip running scripts during install',
type: 'boolean',
})
.option('by', {
describe: 'Set the installation mode, support npm or npminstall',
type: 'string',
});
},
boolean: [
'clean',
'save',
'save-dev',
'save-optional',
'save-bundle',
'save-peer',
'save-exact',
'version',
'usage',
'global',
'detail',
'update',
'package-lock-only',
'ignore-scripts',
'experimental-local-resolver',
'legacy-peer-deps',
'force',
'strict-peer-deps',
'update-lockfile',
],
string: [
'registry',
'prefix',
'deps-tree-path',
'lock-id',
'mode',
'omit',
'cache-dir',
],
});
handler: async argv => {
const ignoreScripts = argv['ignore-scripts'];
const mode = argv.by || NpmFsMode.NPM;

const cwd = process.cwd();
const pkgRes = await util.readPkgJSON();
const pkg = pkgRes?.pkg || {};

const cwd = params.prefix || process.cwd();
if (params.clean) {
await clean(cwd);
} else {
const pkgRes = await util.readPkgJSON();
const pkg = pkgRes?.pkg || {};
await install({
...params,
cwd,
pkg,
registry: params.registry || 'https://registry.npmjs.org',
mode: params.mode || NpmFsMode.NPM,
env: process.env,
httpclient,
});
}
}
await install({
cwd,
pkg,
mode,
ignoreScripts,
});

console.log('[rapid] install finished');
// 首次执行 nydusd 后台服务可能会 hang 住输入
process.exit(0);
},
})
.command({
command: 'clean',
describe: 'Clean up the project',
handler: async () => {
const cwd = process.cwd();
await clean(cwd);

runner()
.then(() => {
process.exit(0);
console.log('[rapid] clean finished');
},
})
.command({
command: 'list',
describe: 'List rapid mount info',
handler: async () => {
const cwd = process.cwd();
await list(cwd);
},
})
.catch(e => {
console.error(e);
process.exit(1);
});
.help()
.parse();
37 changes: 0 additions & 37 deletions packages/cli/lib/dep/arborist_logger.js

This file was deleted.

42 changes: 0 additions & 42 deletions packages/cli/lib/dep/dep_context.js

This file was deleted.

Loading

0 comments on commit fa88553

Please sign in to comment.