Skip to content
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
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,11 @@ The following `esbuild` options are automatically set.

#### Packager Options

| Option | Description | Default |
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| `scripts` | A string or array of scripts to be executed, currently only supports 'scripts' for npm, pnpm and yarn | `undefined` |
| `noInstall` | [Yarn only] A boolean that deactivates the install step | `false` |
| `ignoreLockfile` | [Yarn only] A boolean to bypass lockfile validation, typically paired with `external` dependencies because we generate a new package.json with only the externalized dependencies. | `false` |
| Option | Description | Default |
| ---------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
| `scripts` | A string or array of scripts to be executed, currently only supports 'scripts' for npm, pnpm and yarn | `undefined` |
| `noInstall` | [Yarn only] A boolean that deactivates the install step | `false` |
| `ignoreLockfile` | [Yarn, npm only] A boolean to bypass lockfile validation, typically paired with `external` dependencies because we generate a new package.json with only the externalized dependencies. | `false` |

#### Watch Options

Expand Down
4 changes: 2 additions & 2 deletions src/packagers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import type { PackagerId, PackagerOptions } from '../types';
import type { Packager } from './packager';

const packagerFactories: Record<PackagerId, (packagerOptions: PackagerOptions) => Promise<Packager>> = {
async npm() {
async npm(packagerOptions: PackagerOptions) {
const { NPM } = await import('./npm');

return new NPM();
return new NPM(packagerOptions);
},
async pnpm() {
const { Pnpm } = await import('./pnpm');
Expand Down
12 changes: 9 additions & 3 deletions src/packagers/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Predicate } from 'effect';
import { any, isEmpty, replace, split, startsWith, takeWhile } from 'ramda';
import * as path from 'path';

import type { DependenciesResult, DependencyMap, JSONObject } from '../types';
import type { DependenciesResult, DependencyMap, JSONObject, PackagerOptions } from '../types';
import { SpawnError, spawnProcess } from '../utils';
import type { Packager } from './packager';

Expand Down Expand Up @@ -90,6 +90,12 @@ export interface NpmV6Deps {
* NPM packager.
*/
export class NPM implements Packager {
private packagerOptions: PackagerOptions;

constructor(packagerOptions: PackagerOptions) {
Comment thread
floydspace marked this conversation as resolved.
Resolved
this.packagerOptions = packagerOptions;
}

get lockfileName() {
return 'package-lock.json';
}
Expand Down Expand Up @@ -269,10 +275,10 @@ export class NPM implements Packager {
return lockfile;
}

async install(cwd: string, extraArgs: Array<string>) {
async install(cwd: string, extraArgs: Array<string>, useLockfile: boolean) {
const command = /^win/.test(process.platform) ? 'npm.cmd' : 'npm';

const args = ['install', ...extraArgs];
const args = [!this.packagerOptions.ignoreLockfile && useLockfile ? 'ci' : 'install', ...extraArgs];

await spawnProcess(command, args, { cwd });
}
Expand Down
2 changes: 1 addition & 1 deletion src/tests/packagers/npm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import * as utils from '../../utils';

jest.mock('process');
describe('NPM Packager', () => {
const npm = new NPM();
const npm = new NPM({});
const path = './';

let spawnSpy: jest.SpyInstance;
Expand Down