ARTICLE AD BOX
I've my own diagnostic formatter for tsc diagnostics. It used to work fine on Linux; but now on Windows it seems like module paths are reported differently.
E.g., on Windows:
ERROR: src/Main.es:2:10 - Error ES2305: Module '"../target/pkg/dist/local/com.example.secondary/src/__mod__.js"' has no exported member 'NonExisting'. import { NonExisting } from "com.example.secondary";How it used to be on Linux (it reports the module name like the following because I do a "replace" from plain absolute .d.ts path to original module name):
ERROR: src/Main.es:2:10 - Error ES2305: Module '"com.example.secondary"' has no exported member 'NonExisting'. import { NonExisting } from "com.example.secondary";Here's the replacement code:
private rewriteModuleNames(text: string): string { for (let [resolvedPath, originalName] of this.system.m_originalModuleNames) { // replace with extension text = text.replaceAll(resolvedPath, originalName); text = text.replaceAll(JSON.stringify(resolvedPath), JSON.stringify(originalName)); // replace without extension resolvedPath = resolvedPath.replace(/(\.d)?\.tsx?$/, ""); text = text.replaceAll(resolvedPath, originalName); text = text.replaceAll(JSON.stringify(resolvedPath), JSON.stringify(originalName)); } return text; }I feed BuildSystem.m_originalModuleNames on my custom module resolution logic. An example:
// host.resolveModuleNameLiterals = ( // moduleLiterals: readonly ts.StringLiteralLike[], // containingFile: string, // redirectedReference: ts.ResolvedProjectReference | undefined, // options: ts.CompilerOptions, // containingSourceFile: ts.SourceFile, // reusedNames: readonly ts.StringLiteralLike[] | undefined, // ): readonly ts.ResolvedModuleWithFailedLookupLocations[] => { ... const [module_name, item] = literal.text.split("::"); const module_name_comps = module_name.split("."); let pkg_id_comp_count = 0; // com.<organisation-name>.<project-name> // org.<organisation-name>.<project-name> // net.<organisation-name>.<project-name> // me.<person-name>.<project-name> if (module_name_comps.length >= 3 && ["com", "org", "net", "me"].includes(module_name_comps[0])) { pkg_id_comp_count = 3; // goog.<project-name> } else if (module_name_comps.length >= 2 && module_name_comps[0] == "goog") { pkg_id_comp_count = 2; // <simple-name> } else { pkg_id_comp_count = 1; } const package_id = module_name_comps.slice(0, pkg_id_comp_count).join("."); let import_pkg: null | Package = package_id == this.package.manifest.package!.id ? this.package : (containing_pkg?.dependencies.get(package_id) ?? null); ... const path = pathMod.resolve(...[ import_pkg.manifest.compilerOptions?.declaration ? import_pkg.path : this.system._getDist(import_pkg), import_pkg.manifest.compilerOptions?.sourcePath ?? manifestMod.CompilerOptions.DEFAULT_SOURCE_PATH, rest, item ? item + ".d.ts" : "__mod__.d.ts" ]); if (host.fileExists(path)) { // map original module name this.system.m_originalModuleNames.set(path, import_pkg.manifest.package!.id + (rest.length == 0 ? "" : ".") + rest.replace(/\//g, ".") + (item ? "::" + item : "")); return { resolvedModule: { resolvedFileName: path, extension: ts.Extension.Dts, isExternalLibraryImport: true, }, }; } // return ts.resolveModuleName(literal.text, containingFile, options, host); return { resolvedModule: undefined };