Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(@angular/cli): don't install using global command but rather install in a different folder #16011

Merged
merged 1 commit into from
Nov 4, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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',
};
}