-
Notifications
You must be signed in to change notification settings - Fork 12k
/
Copy pathdev_prod_mode.ts
56 lines (49 loc) · 1.73 KB
/
dev_prod_mode.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.dev/license
*/
import { BuilderHarness } from './builder-harness';
export const GOOD_TARGET = './src/good.js';
export const BAD_TARGET = './src/bad.js';
/** Setup project for use of conditional imports. */
export async function setupConditionImport(harness: BuilderHarness<unknown>) {
// Files that can be used as targets for the conditional import.
await harness.writeFile('src/good.ts', `export const VALUE = 'good-value';`);
await harness.writeFile('src/bad.ts', `export const VALUE = 'bad-value';`);
await harness.writeFile('src/wrong.ts', `export const VALUE = 1;`);
// Simple application file that accesses conditional code.
await harness.writeFile(
'src/main.ts',
`import {VALUE} from '#target';
console.log(VALUE);
console.log(VALUE.length);
export default 42 as any;
`,
);
// Ensure that good/bad can be resolved from tsconfig.
const tsconfig = JSON.parse(harness.readFile('src/tsconfig.app.json')) as TypeScriptConfig;
tsconfig.compilerOptions.moduleResolution = 'bundler';
tsconfig.files.push('good.ts', 'bad.ts', 'wrong.ts');
await harness.writeFile('src/tsconfig.app.json', JSON.stringify(tsconfig));
}
/** Update package.json with the given mapping for #target. */
export async function setTargetMapping(harness: BuilderHarness<unknown>, mapping: unknown) {
await harness.writeFile(
'package.json',
JSON.stringify({
name: 'ng-test-app',
imports: {
'#target': mapping,
},
}),
);
}
interface TypeScriptConfig {
compilerOptions: {
moduleResolution: string;
};
files: string[];
}