Skip to content

Commit

Permalink
feat(packager): add noInstall option (#1003)
Browse files Browse the repository at this point in the history
* feat(packager): add noInstall option

Co-authored-by: Russell Anthony <russell@kingsmen.cc>
  • Loading branch information
j0k3r and russell-dot-js authored Nov 19, 2021
1 parent da776c3 commit 8ade442
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 3 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,11 @@ configuration setting. For details see below.
By default, the plugin uses NPM to package the external modules. However, if you use npm,
you should use any version `<5.5 >=5.7.1` as the versions in-between have some nasty bugs.

Right now there are no `packagerOptions` that can be set with NPM.
The NPM packager supports the following `packagerOptions`:

| Option | Type | Default | Description |
| ------------------ | ---- | ------- | --------------------------------------------------- |
| noInstall | bool | false | Do not run `npm install` (assume install completed) |

##### Yarn

Expand All @@ -382,6 +386,7 @@ The yarn packager supports the following `packagerOptions`:
| Option | Type | Default | Description |
| ------------------ | ---- | ------- | --------------------------------------------------- |
| ignoreScripts | bool | false | Do not execute package.json hook scripts on install |
| noInstall | bool | false | Do not run `yarn install` (assume install completed)|
| noFrozenLockfile | bool | false | Do not require an up-to-date yarn.lock |
| networkConcurrency | int | | Specify number of concurrent network requests |

Expand Down
6 changes: 5 additions & 1 deletion lib/packagers/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,11 @@ class NPM {
return lockfile;
}

static install(cwd) {
static install(cwd, packagerOptions) {
if (packagerOptions.noInstall) {
return BbPromise.resolve();
}

const command = /^win/.test(process.platform) ? 'npm.cmd' : 'npm';
const args = ['install'];

Expand Down
12 changes: 11 additions & 1 deletion lib/packagers/npm.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe('npm', () => {
describe('install', () => {
it('should use npm install', () => {
Utils.spawnProcess.returns(BbPromise.resolve({ stdout: 'installed successfully', stderr: '' }));
return expect(npmModule.install('myPath')).to.be.fulfilled.then(result => {
return expect(npmModule.install('myPath', {})).to.be.fulfilled.then(result => {
expect(result).to.be.undefined;
expect(Utils.spawnProcess).to.have.been.calledOnce;
expect(Utils.spawnProcess).to.have.been.calledWithExactly(sinon.match(/^npm/), ['install'], {
Expand All @@ -60,6 +60,16 @@ describe('npm', () => {
});
});

describe('noInstall', () => {
it('should skip npm install', () => {
return expect(npmModule.install('myPath', { noInstall: true })).to.be.fulfilled.then(result => {
expect(result).to.be.undefined;
expect(Utils.spawnProcess).not.to.have.been.called;
return null;
});
});
});

describe('prune', () => {
it('should use npm prune', () => {
Utils.spawnProcess.returns(BbPromise.resolve({ stdout: 'success', stderr: '' }));
Expand Down
4 changes: 4 additions & 0 deletions lib/packagers/yarn.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ class Yarn {
}

static install(cwd, packagerOptions) {
if (packagerOptions.noInstall) {
return BbPromise.resolve();
}

const command = /^win/.test(process.platform) ? 'yarn.cmd' : 'yarn';
const args = [ 'install', '--non-interactive' ];

Expand Down
9 changes: 9 additions & 0 deletions lib/packagers/yarn.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,15 @@ describe('yarn', () => {
});
});

describe('noInstall', () => {
it('should skip yarn install', () => {
return expect(yarnModule.install('myPath', { noInstall: true })).to.be.fulfilled.then(result => {
expect(result).to.be.undefined;
return null;
});
});
});

describe('prune', () => {
let installStub;

Expand Down

0 comments on commit 8ade442

Please sign in to comment.