-
Notifications
You must be signed in to change notification settings - Fork 12k
use private yarn pkg cache, ensure private npm/yarn bin always on path #23372
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,46 @@ | ||
import { mkdir, writeFile } from 'fs/promises'; | ||
import { join } from 'path'; | ||
import { getGlobalVariable } from '../utils/env'; | ||
import { getGlobalVariable, setGlobalVariable } from '../utils/env'; | ||
|
||
/** | ||
* Configure npm to use a unique sandboxed environment. | ||
*/ | ||
export default async function () { | ||
const tempRoot: string = getGlobalVariable('tmp-root'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the configured based on the package manager is used? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The packages being tested (cli + yarn + npm) are all installed using npm before running the tests so I think we always need both (see 100-global-cli.ts). |
||
const npmModulesPrefix = join(tempRoot, 'npm-global'); | ||
const yarnModulesPrefix = join(tempRoot, 'yarn-global'); | ||
const npmRegistry: string = getGlobalVariable('package-registry'); | ||
const npmrc = join(tempRoot, '.npmrc'); | ||
const yarnrc = join(tempRoot, '.yarnrc'); | ||
|
||
// Configure npm to use the sandboxed npm globals and rc file | ||
// From this point onward all npm transactions use the "global" npm cache | ||
// isolated within this e2e test invocation. | ||
// Change the npm+yarn userconfig to the sandboxed npmrc to override the default ~ | ||
process.env.NPM_CONFIG_USERCONFIG = npmrc; | ||
process.env.NPM_CONFIG_PREFIX = npmModulesPrefix; | ||
|
||
// The npm+yarn registry URL | ||
process.env.NPM_CONFIG_REGISTRY = npmRegistry; | ||
|
||
// Configure npm+yarn to use a sandboxed bin directory | ||
// From this point onward all yarn/npm bin files/symlinks are put into the prefix directories | ||
process.env.NPM_CONFIG_PREFIX = npmModulesPrefix; | ||
process.env.YARN_CONFIG_PREFIX = yarnModulesPrefix; | ||
|
||
// Snapshot builds may contain versions that are not yet released (e.g., RC phase main branch). | ||
// In this case peer dependency ranges may not resolve causing npm 7+ to fail during tests. | ||
// To support this case, legacy peer dependency mode is enabled for snapshot builds. | ||
if (getGlobalVariable('argv')['ng-snapshots']) { | ||
process.env['NPM_CONFIG_legacy_peer_deps'] = 'true'; | ||
} | ||
|
||
// Configure the registry and prefix used within the test sandbox | ||
// Configure the registry and prefix used within the test sandbox via rc files | ||
await writeFile(npmrc, `registry=${npmRegistry}\nprefix=${npmModulesPrefix}`); | ||
await writeFile(yarnrc, `registry ${npmRegistry}\nprefix ${yarnModulesPrefix}`); | ||
|
||
await mkdir(npmModulesPrefix); | ||
await mkdir(yarnModulesPrefix); | ||
|
||
setGlobalVariable('npm-global', npmModulesPrefix); | ||
setGlobalVariable('yarn-global', yarnModulesPrefix); | ||
|
||
console.log(` Using "${npmModulesPrefix}" as e2e test global npm cache.`); | ||
console.log(` Using "${npmModulesPrefix}" as e2e test global npm bin dir.`); | ||
console.log(` Using "${yarnModulesPrefix}" as e2e test global yarn bin dir.`); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a commit adding this line to ensure the correct ng/yarn/npm are being used. You can omit that commit if you don't think it's useful.