Skip to content

Commit

Permalink
Merge pull request #1246 from jagonzalr/bug/non-interactive-yarn-2
Browse files Browse the repository at this point in the history
Add new `packagerOptions`: `noNonInteractive` to disable interactive mode when using Yarn 2 or above
  • Loading branch information
j0k3r authored Sep 20, 2022
2 parents bd25c97 + 7f82877 commit 070395d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,7 @@ The yarn packager supports the following `packagerOptions`:
| ------------------ | ---- | ------- | --------------------------------------------------- |
| ignoreScripts | bool | false | Do not execute package.json hook scripts on install |
| noInstall | bool | false | Do not run `yarn install` (assume install completed)|
| noNonInteractive | bool | false | Disable interactive mode when using Yarn 2 or above |
| 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/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
* noNonInteractive (false) - Disable interactive mode when using Yarn 2 or above
* noFrozenLockfile (false) - Do not require an up-to-date yarn.lock
* networkConcurrency (8) - Specify number of concurrent network requests
*/
Expand Down Expand Up @@ -123,9 +124,12 @@ class Yarn {
}

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

// Convert supported packagerOptions
if (!packagerOptions.noNonInteractive) {
args.push('--non-interactive');
}
if (!packagerOptions.noFrozenLockfile) {
args.push('--frozen-lockfile');
}
Expand Down
17 changes: 17 additions & 0 deletions tests/packagers/yarn.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,23 @@ describe('yarn', () => {
});
});

it('should use noNonInteractive option', () => {
Utils.spawnProcess.mockReturnValue(BbPromise.resolve({ stdout: 'installed successfully', stderr: '' }));
return expect(yarnModule.install('myPath', { noNonInteractive: true }))
.resolves.toBeUndefined()
.then(() => {
expect(Utils.spawnProcess).toHaveBeenCalledTimes(1);
expect(Utils.spawnProcess).toHaveBeenCalledWith(
expect.stringMatching(/^yarn/),
['install', '--frozen-lockfile'],
{
cwd: 'myPath'
}
);
return null;
});
});

it('should use ignoreScripts option', () => {
Utils.spawnProcess.mockReturnValue(BbPromise.resolve({ stdout: 'installed successfully', stderr: '' }));
return expect(yarnModule.install('myPath', { ignoreScripts: true }))
Expand Down

0 comments on commit 070395d

Please sign in to comment.