Skip to content

Commit 2d72640

Browse files
Force requireWithInstall (#496)
1 parent 6c8c8a3 commit 2d72640

File tree

3 files changed

+15
-12
lines changed

3 files changed

+15
-12
lines changed

packages/gasket-utils/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# `@gasket/utils`
22

3+
- force install with npm ([#496])
4+
35
### 6.35.2
46
- add requireWithInstall & tryResolve utils ([#492])
57

@@ -70,3 +72,4 @@
7072
[#348]: https://github.com/godaddy/gasket/pull/348
7173
[#436]: https://github.com/godaddy/gasket/pull/436
7274
[#492]: https://github.com/godaddy/gasket/pull/492
75+
[#496]: https://github.com/godaddy/gasket/pull/496

packages/gasket-utils/lib/require-with-install.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ async function getPkgManager(root) {
1414
try {
1515
await fs.readFile(path.join(root, 'yarn.lock'), 'utf8');
1616
return {
17-
pkgMananger: 'yarn',
17+
pkgManager: 'yarn',
1818
cmd: 'add',
19-
flag: '--dev',
19+
flags: ['--dev'],
2020
logMsg: (pkg) =>
2121
`requireWithInstall - installing "${pkg}" with "yarn" - saving as a devDependency`
2222
};
2323
} catch (err) {
2424
return {
25-
pkgMananger: 'npm',
25+
pkgManager: 'npm',
2626
cmd: 'install',
27-
flag: '--no-save',
27+
flags: ['--no-save', '--force'],
2828
logMsg: (pkg) =>
2929
`requireWithInstall - installing "${pkg}" with "npm" - save as a devDependency to avoid this`
3030
};
@@ -45,15 +45,15 @@ async function requireWithInstall(dependency, gasket) {
4545

4646
if (modulePath) return require(modulePath);
4747

48-
const { pkgMananger, cmd, flag, logMsg } = await getPkgManager(root);
48+
const { pkgManager, cmd, flags, logMsg } = await getPkgManager(root);
4949
const pkg = dependency.match(rePackage)[0];
5050

51-
const manager = new PackageManager({ packageManager: pkgMananger, dest: root });
51+
const manager = new PackageManager({ packageManager: pkgManager, dest: root });
5252
logger.info(logMsg(pkg));
5353
try {
54-
await manager.exec(cmd, [pkg, flag]);
54+
await manager.exec(cmd, [pkg, ...flags]);
5555
} catch (err) {
56-
logger.error(`requireWithInstall - Failed to install "${pkg}" using "${pkgMananger}"`);
56+
logger.error(`requireWithInstall - Failed to install "${pkg}" using "${pkgManager}"`);
5757
throw err;
5858
}
5959
return require(resolve(dependency, resolveOptions));

packages/gasket-utils/test/require-with-install.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ describe('requireWithInstall', function () {
7575
.equals('npm');
7676
assume(packageManagerExecStub.args[0][0])
7777
.equals('install');
78-
assume(packageManagerExecStub.args[0][1][0])
79-
.equals('my-package');
78+
assume(packageManagerExecStub.args[0][1])
79+
.eqls(['my-package', '--no-save', '--force']);
8080
});
8181

8282
it('does not install when package is present', async function () {
@@ -104,8 +104,8 @@ describe('requireWithInstall', function () {
104104
.equals('yarn');
105105
assume(packageManagerExecStub.args[0][0])
106106
.equals('add');
107-
assume(packageManagerExecStub.args[0][1][0])
108-
.equals('my-package');
107+
assume(packageManagerExecStub.args[0][1])
108+
.eqls(['my-package', '--dev']);
109109
});
110110

111111
it('does not install when package is present', async function () {

0 commit comments

Comments
 (0)