Skip to content

Commit 91331e2

Browse files
alan-agius4vikerman
authored andcommitted
fix(@angular/cli): don't install using global command but rather install in a different folder
Fixes: #16010
1 parent 3aafc21 commit 91331e2

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

packages/angular/cli/tasks/install-package.ts

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,28 @@ interface PackageManagerOptions {
2424
silent: string;
2525
install: string;
2626
prefix: string;
27+
noBinLinks: string;
28+
noLockfile: string;
2729
}
2830

2931
export function installPackage(
3032
packageName: string,
3133
logger: logging.Logger,
3234
packageManager: PackageManager = PackageManager.Npm,
3335
extraArgs: string[] = [],
34-
global = false,
36+
cwd = process.cwd(),
3537
) {
3638
const packageManagerArgs = getPackageManagerArguments(packageManager);
3739

3840
const installArgs: string[] = [
3941
packageManagerArgs.install,
4042
packageName,
4143
packageManagerArgs.silent,
44+
packageManagerArgs.noBinLinks,
4245
];
4346

4447
logger.info(colors.green(`Installing packages for tooling via ${packageManager}.`));
4548

46-
if (global) {
47-
if (packageManager === PackageManager.Yarn) {
48-
installArgs.unshift('global');
49-
} else {
50-
installArgs.push('--global');
51-
}
52-
}
53-
5449
const { status } = spawnSync(
5550
packageManager,
5651
[
@@ -60,6 +55,7 @@ export function installPackage(
6055
{
6156
stdio: 'inherit',
6257
shell: true,
58+
cwd,
6359
},
6460
);
6561

@@ -82,13 +78,6 @@ export function installTempPackage(
8278

8379
// setup prefix/global modules path
8480
const packageManagerArgs = getPackageManagerArguments(packageManager);
85-
const installArgs: string[] = [
86-
packageManagerArgs.prefix,
87-
tempPath,
88-
];
89-
90-
installPackage(packageName, logger, packageManager, installArgs, true);
91-
9281
let tempNodeModules: string;
9382
if (packageManager !== PackageManager.Yarn && process.platform !== 'win32') {
9483
// Global installs on Unix systems go to {prefix}/lib/node_modules.
@@ -98,6 +87,15 @@ export function installTempPackage(
9887
tempNodeModules = join(tempPath, 'node_modules');
9988
}
10089

90+
const installArgs: string[] = [
91+
packageManagerArgs.prefix,
92+
// Yarn will no append 'node_modules' to the path
93+
packageManager === PackageManager.Yarn ? tempNodeModules : tempPath,
94+
packageManagerArgs.noLockfile,
95+
];
96+
97+
installPackage(packageName, logger, packageManager, installArgs, tempPath);
98+
10199
// Needed to resolve schematics from this location since we use a custom
102100
// resolve strategy in '@angular/devkit-core/node'
103101
// todo: this should be removed when we change the resolutions to use require.resolve
@@ -165,11 +163,15 @@ function getPackageManagerArguments(packageManager: PackageManager): PackageMana
165163
? {
166164
silent: '--silent',
167165
install: 'add',
168-
prefix: '--global-folder',
166+
prefix: '--modules-folder',
167+
noBinLinks: '--no-bin-links',
168+
noLockfile: '--no-lockfile',
169169
}
170170
: {
171171
silent: '--quiet',
172172
install: 'install',
173173
prefix: '--prefix',
174+
noBinLinks: '--no-bin-links',
175+
noLockfile: '--no-package-lock',
174176
};
175177
}

0 commit comments

Comments
 (0)