MCPcopy Index your code
hub / github.com/angular/angular-cli / setupConditionImport

Function setupConditionImport

modules/testing/builder/src/dev_prod_mode.ts:15–36  ·  view source on GitHub ↗
(harness: BuilderHarness<unknown>)

Source from the content-addressed store, hash-verified

13
14/** Setup project for use of conditional imports. */
15export async function setupConditionImport(harness: BuilderHarness<unknown>) {
16 // Files that can be used as targets for the conditional import.
17 await harness.writeFile('src/good.ts', `export const VALUE = 'good-value';`);
18 await harness.writeFile('src/bad.ts', `export const VALUE = 'bad-value';`);
19 await harness.writeFile('src/wrong.ts', `export const VALUE = 1;`);
20
21 // Simple application file that accesses conditional code.
22 await harness.writeFile(
23 'src/main.ts',
24 `import {VALUE} from '#target';
25console.log(VALUE);
26console.log(VALUE.length);
27export default 42 as any;
28`,
29 );
30
31 // Ensure that good/bad can be resolved from tsconfig.
32 const tsconfig = JSON.parse(harness.readFile('src/tsconfig.app.json')) as TypeScriptConfig;
33 tsconfig.compilerOptions.moduleResolution = 'bundler';
34 tsconfig.files.push('good.ts', 'bad.ts', 'wrong.ts');
35 await harness.writeFile('src/tsconfig.app.json', JSON.stringify(tsconfig));
36}
37
38/** Update package.json with the given mapping for #target. */
39export async function setTargetMapping(harness: BuilderHarness<unknown>, mapping: unknown) {

Callers

nothing calls this directly

Calls 3

writeFileMethod · 0.65
readFileMethod · 0.65
pushMethod · 0.45

Tested by

no test coverage detected