From 998fb7161aeb17c7ce3d8ec458b2a63088958b8d Mon Sep 17 00:00:00 2001 From: Greg Sexton Date: Fri, 26 Jan 2024 11:13:29 +0000 Subject: [PATCH] Do not massage declaration import paths These are now correctly produced and work. But the path stuff does still need to be stripped. It is not supported and requires downstream projects to also define the paths. Refer: https://stackoverflow.com/a/52501384 https://github.com/Microsoft/TypeScript/issues/15479 --- sknpm/src/main.sk | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/sknpm/src/main.sk b/sknpm/src/main.sk index 8b979af01..1d095ca00 100644 --- a/sknpm/src/main.sk +++ b/sknpm/src/main.sk @@ -698,7 +698,7 @@ fun manage( if (bc.env.verbose) { print_string(">> Copy types declaration files."); }; - declFiles.each(f -> copyToDir(f, distDir, ".mjs")); + declFiles.each(f -> copyToDir(f, distDir)); srcDir = Path.join(npmDir, "src"); checkDir(srcDir); if (bc.env.verbose) { @@ -708,7 +708,7 @@ fun manage( tsDir, f -> f.endsWith(".ts"), _f -> false, - ).each(f -> copyToDir(f, srcDir, "")); + ).each(f -> copyToDir(f, srcDir)); if (bc.env.verbose) { print_string(">> Manage license and package files."); }; @@ -825,11 +825,15 @@ fun tsc(tsDir: String, link: ?(String, String), verbose: Bool): void { Skargo.run(Array["tsc", "--project", tsconfig], verbose); } -fun copyToDir(tsFile: String, dir: String, ext: String = ".ts"): void { +fun copyToDir(tsFile: String, dir: String): void { contents = FileSystem.readTextFile(tsFile); target = Path.join(dir, Path.basename(tsFile)); lines = contents.split("\n").map(line -> { - if (line.startsWith("import ") || line.startsWith("export {")) { + if ( + line.startsWith("import ") || + line.startsWith("export {") || + line.startsWith("export type {") + ) { elements = line.split(" from "); if (elements.size() == 2) { imported = elements[1].split("\""); @@ -837,13 +841,7 @@ fun copyToDir(tsFile: String, dir: String, ext: String = ".ts"): void { elems = imported[1].split("/"); size = elems.size(); if (size > 1 && elems[0].startsWith("#")) { - !elems = elems.mapWithIndex((idx, v) -> - if (idx == 0) "." else if (idx == size - 1) { - `${v}${ext}` - } else { - v - } - ); + !elems = elems.mapWithIndex((idx, v) -> if (idx == 0) "." else v); !line = `${elements[0]} from "${elems.join("/")}"` } }