Skip to content

Commit

Permalink
Support noFrozenLockfile options
Browse files Browse the repository at this point in the history
  • Loading branch information
tgroutars committed Nov 4, 2020
1 parent 38135e4 commit 3aaf0dd
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,10 @@ Using yarn will switch the whole packaging pipeline to use yarn, so does it use

The yarn packager supports the following `packagerOptions`:

| Option | Type | Default | Description |
|---------------|------|---------|-------------|
| ignoreScripts | bool | true | Do not execute package.json hook scripts on install |
| Option | Type | Default | Description |
|------------------|------|----------|-----------------------------------------------------|
| ignoreScripts | bool | false | Do not execute package.json hook scripts on install |
| noFrozenLockfile | bool | false | Do not require an up-to-date yarn.lock |

##### Common packager options

Expand Down
6 changes: 5 additions & 1 deletion lib/packagers/yarn.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Yarn specific packagerOptions (default):
* flat (false) - Use --flat with install
* ignoreScripts (false) - Do not execute scripts during install
* noFrozenLockfile (false) - Do not require an up-to-date yarn.lock
*/

const _ = require('lodash');
Expand Down Expand Up @@ -117,9 +118,12 @@ class Yarn {

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

// Convert supported packagerOptions
if (!packagerOptions.noFrozenLockfile) {
args.push('--frozen-lockfile');
}
if (packagerOptions.ignoreScripts) {
args.push('--ignore-scripts');
}
Expand Down
20 changes: 18 additions & 2 deletions lib/packagers/yarn.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ describe('yarn', () => {
expect(Utils.spawnProcess).to.have.been.calledOnce;
expect(Utils.spawnProcess).to.have.been.calledWithExactly(
sinon.match(/^yarn/),
[ 'install', '--frozen-lockfile', '--non-interactive' ],
[ 'install', '--non-interactive', '--frozen-lockfile' ],
{
cwd: 'myPath'
}
Expand All @@ -234,7 +234,23 @@ describe('yarn', () => {
expect(Utils.spawnProcess).to.have.been.calledOnce;
expect(Utils.spawnProcess).to.have.been.calledWithExactly(
sinon.match(/^yarn/),
[ 'install', '--frozen-lockfile', '--non-interactive', '--ignore-scripts' ],
[ 'install', '--non-interactive', '--frozen-lockfile', '--ignore-scripts' ],
{
cwd: 'myPath'
}
);
return null;
});
});

it('should use noFrozenLockfile option', () => {
Utils.spawnProcess.returns(BbPromise.resolve({ stdout: 'installed successfully', stderr: '' }));
return expect(yarnModule.install('myPath', { noFrozenLockfile: true })).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(/^yarn/),
[ 'install', '--non-interactive' ],
{
cwd: 'myPath'
}
Expand Down

0 comments on commit 3aaf0dd

Please sign in to comment.