Skip to content

Commit 809dc86

Browse files
[heft-isolated-typescript-transpile-plugin] Various fixes to @rushstack/heft-isolated-typescript-transpile-plugin (#5167)
* Fix a casing issue in the @rushstack/heft-isolated-typescript-transpile-plugin heft-plugin.json file. * Fix an issue where the `rootPath` `tsconfig.json` property wasn't supported. * Fix a crash when there are zero files to transpile. * fixup! Fix an issue where the `rootPath` `tsconfig.json` property wasn't supported. Co-authored-by: David Michon <[email protected]> * Fix an issue with the paths in sourcemaps. --------- Co-authored-by: David Michon <[email protected]>
1 parent ead2016 commit 809dc86

File tree

6 files changed

+70
-15
lines changed

6 files changed

+70
-15
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/heft-isolated-typescript-transpile-plugin",
5+
"comment": "Fix a casing issue in the `heft-plugin.json` `entryPoint` field.",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@rushstack/heft-isolated-typescript-transpile-plugin"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/heft-isolated-typescript-transpile-plugin",
5+
"comment": "Fix an issue where the `rootPath` `tsconfig.json` property wasn't supported.",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@rushstack/heft-isolated-typescript-transpile-plugin"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/heft-isolated-typescript-transpile-plugin",
5+
"comment": "Fix a crash when there are zero files to transpile.",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@rushstack/heft-isolated-typescript-transpile-plugin"
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/heft-isolated-typescript-transpile-plugin",
5+
"comment": "Fix an issue with the paths in sourcemaps.",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@rushstack/heft-isolated-typescript-transpile-plugin"
10+
}

heft-plugins/heft-isolated-typescript-transpile-plugin/heft-plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"taskPlugins": [
55
{
66
"pluginName": "swc-isolated-transpile-plugin",
7-
"entryPoint": "./lib/SWCIsolatedTranspilePlugin",
7+
"entryPoint": "./lib/SwcIsolatedTranspilePlugin",
88
"optionsSchema": "./lib/schemas/swc-isolated-transpile-plugin.schema.json"
99
}
1010
]

heft-plugins/heft-isolated-typescript-transpile-plugin/src/SwcIsolatedTranspilePlugin.ts

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,15 @@ async function transpileProjectAsync(
159159
const { sourceMap, sourceRoot, experimentalDecorators, inlineSourceMap, useDefineForClassFields } =
160160
tsConfigOptions;
161161

162-
const rootDirsPaths: LookupByPath<number> = new LookupByPath(
163-
(tsConfigOptions.rootDirs ?? []).map((rd) => [rd, rd.length])
164-
);
162+
const rootDirs: Set<string> = new Set(tsConfigOptions.rootDirs);
163+
if (tsConfigOptions.rootDir) {
164+
rootDirs.add(tsConfigOptions.rootDir);
165+
}
166+
167+
const rootDirsPaths: LookupByPath<number> = new LookupByPath();
168+
for (const rootDir of rootDirs) {
169+
rootDirsPaths.setItem(rootDir, rootDir.length);
170+
}
165171

166172
const sourceFilePaths: string[] = filesFromTsConfig.filter((filePath) => !filePath.endsWith('.d.ts'));
167173

@@ -231,7 +237,8 @@ async function transpileProjectAsync(
231237
swcrc: false,
232238
minify: false,
233239

234-
inputSourceMap: false,
240+
sourceMaps: externalSourceMaps,
241+
inputSourceMap: true,
235242
sourceRoot,
236243
isModule: true,
237244

@@ -296,6 +303,10 @@ async function transpileProjectAsync(
296303
for (const [outputPrefix, optionsByExtension] of outputOptions) {
297304
const jsFilePath: string = `${outputPrefix}${relativeJsFilePath}`;
298305
const mapFilePath: string | undefined = externalSourceMaps ? `${jsFilePath}.map` : undefined;
306+
const absoluteMapFilePath: string = `${buildFolderPath}${mapFilePath}`;
307+
const relativeMapSrcFilePath: string = Path.convertToSlashes(
308+
path.relative(path.dirname(absoluteMapFilePath), srcFilePath)
309+
);
299310

300311
const options: string = tsx ? optionsByExtension.tsx : optionsByExtension.ts;
301312
let optionsIndex: number | undefined = indexForOptions.get(options);
@@ -305,7 +316,7 @@ async function transpileProjectAsync(
305316
}
306317
const item: ITransformTask = {
307318
srcFilePath,
308-
relativeSrcFilePath,
319+
relativeSrcFilePath: relativeMapSrcFilePath,
309320
optionsIndex,
310321
jsFilePath,
311322
mapFilePath
@@ -369,17 +380,21 @@ function printTiming(logger: IScopedLogger, times: [string, number][], descripto
369380
return y[1] - x[1];
370381
});
371382

372-
logger.terminal.writeVerboseLine(`${descriptor} ${times.length} files at `, `${process.uptime()}`);
373-
logger.terminal.writeVerboseLine(`Slowest files:`);
374-
for (let i: number = 0, len: number = Math.min(times.length, 10); i < len; i++) {
375-
const [fileName, time] = times[i];
383+
const timesCount: number = times.length;
384+
logger.terminal.writeVerboseLine(`${descriptor} ${timesCount} files at ${process.uptime()}`);
385+
if (timesCount > 0) {
386+
logger.terminal.writeVerboseLine(`Slowest files:`);
387+
for (let i: number = 0, len: number = Math.min(timesCount, 10); i < len; i++) {
388+
const [fileName, time] = times[i];
376389

377-
logger.terminal.writeVerboseLine(`- ${fileName}: ${time.toFixed(2)}ms`);
378-
}
379-
const medianIndex: number = times.length >> 1;
380-
const [medianFileName, medianTime] = times[medianIndex];
390+
logger.terminal.writeVerboseLine(`- ${fileName}: ${time.toFixed(2)}ms`);
391+
}
381392

382-
logger.terminal.writeVerboseLine(`Median: (${medianFileName}): ${medianTime.toFixed(2)}ms`);
393+
const medianIndex: number = timesCount >> 1;
394+
const [medianFileName, medianTime] = times[medianIndex];
395+
396+
logger.terminal.writeVerboseLine(`Median: (${medianFileName}): ${medianTime.toFixed(2)}ms`);
397+
}
383398
}
384399

385400
function endsWithCharacterX(filePath: string): boolean {

0 commit comments

Comments
 (0)