| 13 | |
| 14 | /** Setup project for use of conditional imports. */ |
| 15 | export 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'; |
| 25 | console.log(VALUE); |
| 26 | console.log(VALUE.length); |
| 27 | export 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. */ |
| 39 | export async function setTargetMapping(harness: BuilderHarness<unknown>, mapping: unknown) { |