diff --git a/src/LocalInstaller.ts b/src/LocalInstaller.ts index 2ae308e..1e1d2e3 100644 --- a/src/LocalInstaller.ts +++ b/src/LocalInstaller.ts @@ -97,7 +97,7 @@ export class LocalInstaller extends EventEmitter { }; const { stdout, stderr } = await exec( 'npm', - ['i', '--no-save', ...toInstall], + ['i', '--no-save', '--no-package-lock', ...toInstall], options, ); this.emit( diff --git a/src/cli.ts b/src/cli.ts index 56c36e2..62dec98 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -1,6 +1,6 @@ import { execute, Options } from './index'; -export function cli(argv: string[]): Promise { +export async function cli(argv: string[]): Promise { const l = console.log; const options = new Options(argv); if (options.help) { @@ -44,8 +44,8 @@ export function cli(argv: string[]): Promise { l( ' install the packages of 2 sibling directories into the current directory and save them to "localDependencies" in your package.json file.', ); - return Promise.resolve(); } else { - return options.validate().then(() => execute(options)); + await options.validate(); + await execute(options); } } diff --git a/src/index.ts b/src/index.ts index 0ab7d5e..8ec7dec 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,6 +20,8 @@ export interface PackageJson { name: string; version: string; localDependencies?: Dependencies; + devDependencies?: Dependencies; + dependencies?: Dependencies; } export interface Dependencies { diff --git a/test/integration/cli.it.ts b/test/integration/cli.it.ts index a69cac1..96941cc 100644 --- a/test/integration/cli.it.ts +++ b/test/integration/cli.it.ts @@ -93,6 +93,53 @@ describe('install-local cli given 3 packages', () => { cwd: packages.one.directory, }); }); + + it('should not install additional (dev) dependencies (https://github.com/nicojs/node-install-local/issues/23)', async () => { + // Arrange + packages.one.packageJson.localDependencies = { + two: '../two', + }; + packages.one.packageJson.devDependencies = { + typescript: '4.0.3', + }; + packages.one.packageJson.dependencies = { + 'typed-inject': '3.0.0', + }; + packages.one.packageLock = { + name: 'one', + version: '0.0.0', + lockfileVersion: 1, + requires: true, + dependencies: { + 'typed-inject': { + version: '3.0.0', + resolved: + 'https://registry.npmjs.org/typed-inject/-/typed-inject-3.0.0.tgz', + integrity: + 'sha512-LDuyPsk6mO1R0qpe/rm/4u/6pPgT2Fob5T+u2D/wDlORxqlwtG9oWxruTaFZ6L61kzwWGzSp80soc3UUScHmaQ==', + }, + typescript: { + version: '4.0.3', + resolved: + 'https://registry.npmjs.org/typescript/-/typescript-4.0.3.tgz', + integrity: + 'sha512-tEu6DGxGgRJPb/mVPIZ48e69xCn2yRmCgYmDugAVwmJ6o+0u1RI18eO7E7WBTLYLaEVVOhwQmcdhQHweux/WPg==', + dev: true, + }, + }, + }; + await packages.one.writePackage(); + + // Act + await execa.command(`node ${installLocal}`, { + cwd: packages.one.directory, + }); + + // Assert + const installed = await packages.one.readdir('node_modules'); + expect(installed).not.include('typescript'); + expect(installed).not.include('typed-inject'); + }); }); const rm = (directory: string) => @@ -109,6 +156,7 @@ const rm = (directory: string) => class PackageHelper implements Package { public directory: string; public packageJson: PackageJson; + public packageLock: Record | undefined; constructor(private name: string) { this.directory = tmpFolder(name); this.packageJson = { @@ -135,6 +183,13 @@ class PackageHelper implements Package { 'utf8', ), fs.writeFile(path.resolve(this.directory, this.name), '', 'utf8'), + this.packageLock + ? fs.writeFile( + path.resolve(this.directory, 'package-lock.json'), + JSON.stringify(this.packageLock, null, 2), + 'utf-8', + ) + : Promise.resolve(), ]); } } diff --git a/test/unit/LocalInstallerSpec.ts b/test/unit/LocalInstallerSpec.ts index 49550a2..184a52d 100644 --- a/test/unit/LocalInstallerSpec.ts +++ b/test/unit/LocalInstallerSpec.ts @@ -83,12 +83,18 @@ describe('LocalInstaller install', () => { await sut.install(); expect(helper.execStub).calledWith( 'npm', - ['i', '--no-save', tmp('b-0.0.1.tgz'), tmp('c-0.0.2.tgz')], + [ + 'i', + '--no-save', + '--no-package-lock', + tmp('b-0.0.1.tgz'), + tmp('c-0.0.2.tgz'), + ], { cwd: resolve('/a'), env: undefined, maxBuffer: TEN_MEGA_BYTE }, ); expect(helper.execStub).calledWith( 'npm', - ['i', '--no-save', tmp('e-0.0.4.tgz')], + ['i', '--no-save', '--no-package-lock', tmp('e-0.0.4.tgz')], { cwd: resolve('d'), env: undefined, maxBuffer: TEN_MEGA_BYTE }, ); }); @@ -140,6 +146,7 @@ describe('LocalInstaller install', () => { expect(helper.execStub).calledWith('npm', [ 'i', '--no-save', + '--no-package-lock', tmp('s-b-0.0.1.tgz'), ]); }); @@ -160,7 +167,7 @@ describe('LocalInstaller install', () => { await sut.install(); expect(helper.execStub).calledWith( 'npm', - ['i', '--no-save', tmp('b-0.0.1.tgz')], + ['i', '--no-save', '--no-package-lock', tmp('b-0.0.1.tgz')], { env: npmEnv, cwd: resolve('/a'), maxBuffer: TEN_MEGA_BYTE }, ); });