Skip to content

Commit

Permalink
Do not massage declaration import paths
Browse files Browse the repository at this point in the history
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
microsoft/TypeScript#15479
  • Loading branch information
gregsexton committed Jan 29, 2024
1 parent d0f4a2d commit 998fb71
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions sknpm/src/main.sk
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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.");
};
Expand Down Expand Up @@ -825,25 +825,23 @@ 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("\"");
if (imported.size() == 3) {
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("/")}"`
}
}
Expand Down

0 comments on commit 998fb71

Please sign in to comment.