Skip to content

Commit

Permalink
feat: generate package lock file
Browse files Browse the repository at this point in the history
  • Loading branch information
akitaSummer committed Dec 2, 2023
1 parent a20bffd commit 8a66d8f
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
7 changes: 7 additions & 0 deletions integration/fixtures/not-exist-lock-file/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "test",
"version": "1.0.0",
"dependencies": {
"lodash.has": "4.5.2"
}
}
19 changes: 18 additions & 1 deletion integration/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const {
forceExitDaemon,
} = require('@cnpmjs/rapid/lib/nydusd/nydusd_api');

describe('test/index.test.js', () => {
describe.only('test/index.test.js', () => {

Check warning on line 16 in integration/index.test.js

View workflow job for this annotation

GitHub Actions / linux-test (16.x, ubuntu-20.04, bash, 3.9)

describe.only not permitted

Check warning on line 16 in integration/index.test.js

View workflow job for this annotation

GitHub Actions / linux-test (18.x, ubuntu-20.04, bash, 3.9)

describe.only not permitted

Check warning on line 16 in integration/index.test.js

View workflow job for this annotation

GitHub Actions / linux-test (20.x, ubuntu-20.04, bash, 3.9)

describe.only not permitted
let fixture;
afterEach(async () => {
await clean({
Expand Down Expand Up @@ -87,4 +87,21 @@ describe('test/index.test.js', () => {
.end(done);
});
});



Check failure on line 92 in integration/index.test.js

View workflow job for this annotation

GitHub Actions / linux-test (16.x, ubuntu-20.04, bash, 3.9)

More than 2 blank lines not allowed

Check failure on line 92 in integration/index.test.js

View workflow job for this annotation

GitHub Actions / linux-test (18.x, ubuntu-20.04, bash, 3.9)

More than 2 blank lines not allowed

Check failure on line 92 in integration/index.test.js

View workflow job for this annotation

GitHub Actions / linux-test (20.x, ubuntu-20.04, bash, 3.9)

More than 2 blank lines not allowed
describe('package-lock.json', done => {
beforeEach(() => {
fixture = path.join(fixtures, 'not-exist-lock-file');
});

it('should work', async () => {
coffee.fork(rapid, [], {
cwd: fixture,
})
.debug()
.expect('code', 0)
.end(done);
});
});
});
6 changes: 6 additions & 0 deletions packages/cli/bin/rapid.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,17 @@ const argv = yargs
describe: 'Dependency types to omit from the installation tree on disk',
type: 'array',
default: [],
})
.option('no-package-lock', {
describe: 'Disable package-lock.json',
type: 'boolean',
});
},
handler: async argv => {
const ignoreScripts = argv['ignore-scripts'];
const mode = argv.by || NpmFsMode.NPM;
const productionMode = argv.production || argv.omit.includes('dev') || process.env.NODE_ENV === 'production';
const noPackageLock = argv['no-package-lock'];

const cwd = process.cwd();
const pkgRes = await util.readPkgJSON();
Expand All @@ -57,6 +62,7 @@ const argv = yargs
nydusMode: NYDUS_TYPE.FUSE,
ignoreScripts,
productionMode,
noPackageLock,
});

Alert.success('🚀 Success', [
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const { MirrorConfig } = require('binary-mirror-config');
// 有依赖树(package-lock.json)走 npm / npminstall 极速安装
exports.install = async options => {
options.env = util.getEnv(options.env, options.args);
const { packageLock } = options.packageLock || (await util.readPackageLock(options.cwd));
const { packageLock } = options.packageLock || (await util.readPackageLock(options.cwd, options.noPackageLock));

const currentMountInfo = await util.listMountInfo();

Expand Down
11 changes: 10 additions & 1 deletion packages/cli/lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ const os = require('node:os');
const url = require('node:url');
const crypto = require('node:crypto');
const mapWorkspaces = require('@npmcli/map-workspaces');
const Arborist = require('@npmcli/arborist');
const fuse_t = require('./fuse_t');
const { Spin } = require('./logger');

Expand Down Expand Up @@ -600,9 +601,17 @@ exports.readPkgJSON = async function readPkgJSON(cwd) {
return { pkg, pkgPath };
};

exports.readPackageLock = async function readPackageLock(cwd) {
exports.readPackageLock = async function readPackageLock(cwd, noPackageLock) {
try {
const lockPath = path.join(cwd || exports.findLocalPrefix(), './package-lock.json');
if (!noPackageLock) {
try {
await fs.startTime(lockPath)

Check failure on line 609 in packages/cli/lib/util.js

View workflow job for this annotation

GitHub Actions / linux-test (16.x, ubuntu-20.04, bash, 3.9)

Missing semicolon

Check failure on line 609 in packages/cli/lib/util.js

View workflow job for this annotation

GitHub Actions / linux-test (18.x, ubuntu-20.04, bash, 3.9)

Missing semicolon

Check failure on line 609 in packages/cli/lib/util.js

View workflow job for this annotation

GitHub Actions / linux-test (20.x, ubuntu-20.04, bash, 3.9)

Missing semicolon
} catch {
const arb = new Arborist()

Check failure on line 611 in packages/cli/lib/util.js

View workflow job for this annotation

GitHub Actions / linux-test (16.x, ubuntu-20.04, bash, 3.9)

Missing semicolon

Check failure on line 611 in packages/cli/lib/util.js

View workflow job for this annotation

GitHub Actions / linux-test (18.x, ubuntu-20.04, bash, 3.9)

Missing semicolon

Check failure on line 611 in packages/cli/lib/util.js

View workflow job for this annotation

GitHub Actions / linux-test (20.x, ubuntu-20.04, bash, 3.9)

Missing semicolon
arb.reify({ save: true })

Check failure on line 612 in packages/cli/lib/util.js

View workflow job for this annotation

GitHub Actions / linux-test (16.x, ubuntu-20.04, bash, 3.9)

Missing semicolon

Check failure on line 612 in packages/cli/lib/util.js

View workflow job for this annotation

GitHub Actions / linux-test (18.x, ubuntu-20.04, bash, 3.9)

Missing semicolon

Check failure on line 612 in packages/cli/lib/util.js

View workflow job for this annotation

GitHub Actions / linux-test (20.x, ubuntu-20.04, bash, 3.9)

Missing semicolon
}
}
const packageLock = JSON.parse(await fs.readFile(lockPath, 'utf8'));
return { packageLock, lockPath };
} catch (e) {
Expand Down

0 comments on commit 8a66d8f

Please sign in to comment.