"Fossies" - the Fresh Open Source Software Archive

Member "angular-cli-15.2.4/tests/legacy-cli/e2e/setup/002-npm-sandbox.ts" (16 Mar 2023, 2497 Bytes) of package /linux/www/angular-cli-15.2.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) TypeScript source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "002-npm-sandbox.ts": 15.1.6_vs_15.2.0.

    1 import { mkdir, writeFile } from 'fs/promises';
    2 import { join } from 'path';
    3 import { getGlobalVariable, setGlobalVariable } from '../utils/env';
    4 
    5 /**
    6  * Configure npm to use a unique sandboxed environment.
    7  */
    8 export default async function () {
    9   const tempRoot: string = getGlobalVariable('tmp-root');
   10   const npmModulesPrefix = join(tempRoot, 'npm-global');
   11   const yarnModulesPrefix = join(tempRoot, 'yarn-global');
   12   const npmRegistry: string = getGlobalVariable('package-registry');
   13   const npmrc = join(tempRoot, '.npmrc');
   14   const yarnrc = join(tempRoot, '.yarnrc');
   15 
   16   // Change the npm+yarn userconfig to the sandboxed npmrc to override the default ~
   17   process.env.NPM_CONFIG_USERCONFIG = npmrc;
   18 
   19   // The npm+yarn registry URL
   20   process.env.NPM_CONFIG_REGISTRY = npmRegistry;
   21 
   22   // Configure npm+yarn to use a sandboxed bin directory
   23   // From this point onward all yarn/npm bin files/symlinks are put into the prefix directories
   24   process.env.NPM_CONFIG_PREFIX = npmModulesPrefix;
   25   process.env.YARN_CONFIG_PREFIX = yarnModulesPrefix;
   26 
   27   // Put the npm+yarn caches in the temp dir
   28   process.env.NPM_CONFIG_CACHE = join(tempRoot, 'npm-cache');
   29   process.env.YARN_CACHE_FOLDER = join(tempRoot, 'yarn-cache');
   30 
   31   // Snapshot builds may contain versions that are not yet released (e.g., RC phase main branch).
   32   // In this case peer dependency ranges may not resolve causing npm 7+ to fail during tests.
   33   // To support this case, legacy peer dependency mode is enabled for snapshot builds.
   34   if (getGlobalVariable('argv')['ng-snapshots']) {
   35     process.env['NPM_CONFIG_legacy_peer_deps'] = 'true';
   36   }
   37 
   38   // Configure the registry and prefix used within the test sandbox via rc files
   39   await writeFile(npmrc, `registry=${npmRegistry}\nprefix=${npmModulesPrefix}`);
   40   await writeFile(yarnrc, `registry ${npmRegistry}\nprefix ${yarnModulesPrefix}`);
   41 
   42   await mkdir(npmModulesPrefix);
   43   await mkdir(yarnModulesPrefix);
   44 
   45   setGlobalVariable('npm-global', npmModulesPrefix);
   46   setGlobalVariable('yarn-global', yarnModulesPrefix);
   47 
   48   // Disable all update/notification related npm/yarn features such as the NPM updater notifier.
   49   // The NPM updater notifier may prevent the child process from closing until it timeouts after 3 minutes.
   50   process.env.NO_UPDATE_NOTIFIER = '1';
   51   process.env.NPM_CONFIG_UPDATE_NOTIFIER = 'false';
   52 
   53   console.log(`  Using "${npmModulesPrefix}" as e2e test global npm bin dir.`);
   54   console.log(`  Using "${yarnModulesPrefix}" as e2e test global yarn bin dir.`);
   55 }