Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(install): ignore other dependencies #30

Merged
merged 2 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/LocalInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { execute, Options } from './index';

export function cli(argv: string[]): Promise<void> {
export async function cli(argv: string[]): Promise<void> {
const l = console.log;
const options = new Options(argv);
if (options.help) {
Expand Down Expand Up @@ -44,8 +44,8 @@ export function cli(argv: string[]): Promise<void> {
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);
}
}
2 changes: 2 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export interface PackageJson {
name: string;
version: string;
localDependencies?: Dependencies;
devDependencies?: Dependencies;
dependencies?: Dependencies;
}

export interface Dependencies {
Expand Down
55 changes: 55 additions & 0 deletions test/integration/cli.it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -109,6 +156,7 @@ const rm = (directory: string) =>
class PackageHelper implements Package {
public directory: string;
public packageJson: PackageJson;
public packageLock: Record<string, unknown> | undefined;
constructor(private name: string) {
this.directory = tmpFolder(name);
this.packageJson = {
Expand All @@ -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(),
]);
}
}
13 changes: 10 additions & 3 deletions test/unit/LocalInstallerSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
);
});
Expand Down Expand Up @@ -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'),
]);
});
Expand All @@ -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 },
);
});
Expand Down