|
2 | 2 | // Licensed under the MIT License.
|
3 | 3 |
|
4 | 4 | import path from "node:path";
|
5 |
| -import { |
6 |
| - cpSync, |
7 |
| - existsSync, |
8 |
| - mkdirSync, |
9 |
| - readFileSync, |
10 |
| - readdirSync, |
11 |
| - statSync, |
12 |
| - writeFileSync, |
13 |
| -} from "node:fs"; |
| 5 | +import { cpSync, existsSync, mkdirSync, readdirSync, statSync, writeFileSync } from "node:fs"; |
14 | 6 | import { leafCommand, makeCommandInfo } from "../../framework/command";
|
15 | 7 | import { createPrinter } from "../../util/printer";
|
16 | 8 | import { resolveProject } from "../../util/resolveProject";
|
| 9 | +import { resolveConfig } from "../../util/resolveTsConfig"; |
17 | 10 | import { spawnSync } from "node:child_process";
|
18 | 11 |
|
19 | 12 | const log = createPrinter("build-test");
|
@@ -107,15 +100,18 @@ function compileForEnvironment(
|
107 | 100 | overrideMap: Map<string, string>,
|
108 | 101 | ): boolean {
|
109 | 102 | const tsconfigPath = path.join(process.cwd(), tsConfig);
|
110 |
| - const tsConfigFile = readFileSync(tsconfigPath, "utf8"); |
111 |
| - const tsConfigJSON = JSON.parse(tsConfigFile); |
| 103 | + const tsConfigJSON = resolveConfig(tsconfigPath); |
112 | 104 | const outputPath = tsConfigJSON.compilerOptions.outDir;
|
113 | 105 | if (!existsSync(tsconfigPath)) {
|
114 | 106 | log.error(`TypeScript config ${tsConfig} does not exist`);
|
115 | 107 | return false;
|
116 | 108 | }
|
117 | 109 |
|
118 |
| - const browserTestPath = path.join(process.cwd(), outputPath); |
| 110 | + const browserTestPath = outputPath; |
| 111 | + if (!browserTestPath) { |
| 112 | + log.error(`Output path not defined in ${tsConfig}`); |
| 113 | + return false; |
| 114 | + } |
119 | 115 | if (!existsSync(browserTestPath)) {
|
120 | 116 | mkdirSync(browserTestPath, { recursive: true });
|
121 | 117 | }
|
@@ -191,8 +187,8 @@ function overrideFile(
|
191 | 187 | sourceFile: string,
|
192 | 188 | destinationFile: string,
|
193 | 189 | ): void {
|
194 |
| - const sourceFileType = path.join(process.cwd(), rootDir, relativeDir, sourceFile); |
195 |
| - const destFileType = path.join(process.cwd(), rootDir, relativeDir, destinationFile); |
| 190 | + const sourceFileType = path.join(rootDir, relativeDir, sourceFile); |
| 191 | + const destFileType = path.join(rootDir, relativeDir, destinationFile); |
196 | 192 |
|
197 | 193 | cpSync(sourceFileType, destFileType, { force: true });
|
198 | 194 | }
|
|
0 commit comments