Skip to content

Commit

Permalink
fix(@angular/cli): don't install using global command but rather inst…
Browse files Browse the repository at this point in the history
…all in a different folder

Fixes: #16010
  • Loading branch information
alan-agius4 authored and vikerman committed Nov 4, 2019
1 parent 30eb7d2 commit 7174f91
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions packages/angular/cli/tasks/install-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ interface PackageManagerOptions {
saveDev: string;
install: string;
prefix: string;
noBinLinks: string;
noLockfile: string;
}

export function installPackage(
Expand All @@ -34,14 +36,15 @@ export function installPackage(
packageManager: PackageManager = PackageManager.Npm,
save: Exclude<NgAddSaveDepedency, false> = true,
extraArgs: string[] = [],
global = false,
cwd = process.cwd(),
) {
const packageManagerArgs = getPackageManagerArguments(packageManager);

const installArgs: string[] = [
packageManagerArgs.install,
packageName,
packageManagerArgs.silent,
packageManagerArgs.noBinLinks,
];

logger.info(colors.green(`Installing packages for tooling via ${packageManager}.`));
Expand All @@ -50,14 +53,6 @@ export function installPackage(
installArgs.push(packageManagerArgs.saveDev);
}

if (global) {
if (packageManager === PackageManager.Yarn) {
installArgs.unshift('global');
} else {
installArgs.push('--global');
}
}

const { status } = spawnSync(
packageManager,
[
Expand All @@ -67,6 +62,7 @@ export function installPackage(
{
stdio: 'inherit',
shell: true,
cwd,
},
);

Expand All @@ -93,21 +89,15 @@ export function installTempPackage(

// setup prefix/global modules path
const packageManagerArgs = getPackageManagerArguments(packageManager);
const tempNodeModules = join(tempPath, 'node_modules');
const installArgs: string[] = [
packageManagerArgs.prefix,
tempPath,
// Yarn will no append 'node_modules' to the path
packageManager === PackageManager.Yarn ? tempNodeModules : tempPath,
packageManagerArgs.noLockfile,
];

installPackage(packageName, logger, packageManager, true, installArgs, true);

let tempNodeModules: string;
if (packageManager !== PackageManager.Yarn && process.platform !== 'win32') {
// Global installs on Unix systems go to {prefix}/lib/node_modules.
// Global installs on Windows go to {prefix}/node_modules (that is, no lib folder.)
tempNodeModules = join(tempPath, 'lib', 'node_modules');
} else {
tempNodeModules = join(tempPath, 'node_modules');
}
installPackage(packageName, logger, packageManager, true, installArgs, tempPath);

return tempNodeModules;
}
Expand Down Expand Up @@ -172,12 +162,16 @@ function getPackageManagerArguments(packageManager: PackageManager): PackageMana
silent: '--silent',
saveDev: '--dev',
install: 'add',
prefix: '--global-folder',
prefix: '--modules-folder',
noBinLinks: '--no-bin-links',
noLockfile: '--no-lockfile',
}
: {
silent: '--quiet',
saveDev: '--save-dev',
install: 'install',
prefix: '--prefix',
noBinLinks: '--no-bin-links',
noLockfile: '--no-package-lock',
};
}

0 comments on commit 7174f91

Please sign in to comment.