Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| ca27db1d75 | |||
| c8a1582ec4 |
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@git.zone/tsbuild",
|
||||
"version": "4.1.1",
|
||||
"version": "4.1.2",
|
||||
"private": false,
|
||||
"description": "A tool for compiling TypeScript files using the latest nightly features, offering flexible APIs and a CLI for streamlined development.",
|
||||
"main": "dist_ts/index.js",
|
||||
|
||||
@@ -373,8 +373,9 @@ export class TsCompiler {
|
||||
|
||||
// Rewrite import paths in all output directories to handle cross-module references
|
||||
// This must happen after ALL compilations so all destination folders exist
|
||||
// Use fromProjectDirectory to detect ALL ts_* folders, not just the ones being compiled
|
||||
if (successfulOutputDirs.length > 0) {
|
||||
const rewriter = TsPathRewriter.fromGlobPatterns(globPatterns);
|
||||
const rewriter = await TsPathRewriter.fromProjectDirectory(this.cwd);
|
||||
let totalRewritten = 0;
|
||||
for (const outputDir of successfulOutputDirs) {
|
||||
totalRewritten += await rewriter.rewriteDirectory(outputDir);
|
||||
|
||||
@@ -51,6 +51,39 @@ export class TsPathRewriter {
|
||||
return new TsPathRewriter(mappings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a TsPathRewriter by auto-detecting all ts_* folders in the project directory.
|
||||
* This ensures that cross-module imports are rewritten even when compiling a single module.
|
||||
*
|
||||
* For example, if the project has ts/, ts_shared/, ts_web/ folders:
|
||||
* - ts → dist_ts
|
||||
* - ts_shared → dist_ts_shared
|
||||
* - ts_web → dist_ts_web
|
||||
*
|
||||
* @param cwd - The project root directory
|
||||
* @returns TsPathRewriter instance with all detected folder mappings
|
||||
*/
|
||||
public static async fromProjectDirectory(cwd: string): Promise<TsPathRewriter> {
|
||||
const mappings: IFolderMapping[] = [];
|
||||
|
||||
try {
|
||||
const entries = await FsHelpers.listDirectory(cwd);
|
||||
|
||||
for (const entry of entries) {
|
||||
// Match folders starting with 'ts' (ts, ts_shared, ts_web, ts_core, etc.)
|
||||
if (entry.isDirectory && /^ts(_|$)/.test(entry.name)) {
|
||||
const sourceFolder = entry.name;
|
||||
const destFolder = `dist_${sourceFolder}`;
|
||||
mappings.push({ sourceFolder, destFolder });
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Directory listing failed, return empty mappings
|
||||
}
|
||||
|
||||
return new TsPathRewriter(mappings);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current folder mappings
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user