Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/slick-queens-laugh.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/package': patch
---

fix: resolve aliases before transpiling for `rewriteRelativeImportExtensions`
5 changes: 4 additions & 1 deletion packages/package/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,14 @@ async function process_file(input, output, file, preprocessor, aliases, tsconfig
}
}

// _before_ transpilining TS, that way TS will apply rewriteRelativeImportExtensions
// to these now-resolved path aliases, too
contents = resolve_aliases(input, file.name, contents, aliases);

if (file.name.endsWith('.ts') && !file.name.endsWith('.d.ts')) {
contents = await transpile_ts(tsconfig, filename, contents);
}

contents = resolve_aliases(input, file.name, contents, aliases);
analyse_code(file.name, contents);
write(dest, contents);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export declare const helper: () => string;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const helper = () => '';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { helper } from "./helper.ts";
export { helper };
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { helper } from "./helper.js";
export { helper };
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "typescript-alias-rewrites",
"private": true,
"version": "1.0.0",
"description": "typescript package with extension rewrites to aliased import paths",
"type": "module",
"peerDependencies": {
"svelte": "^5.0.0"
},
"exports": {
".": {
"types": "./dist/index.d.ts",
"svelte": "./dist/index.js"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const helper = () => '';
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { helper } from '$lib/helper.ts';
export { helper };
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import preprocess from 'svelte-preprocess';

export default {
preprocess: preprocess()
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "ESNext",
"allowImportingTsExtensions": true,
"rewriteRelativeImportExtensions": true
}
}
4 changes: 4 additions & 0 deletions packages/package/test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ test('create package with typescript using nodenext', async () => {
await test_make_package('typescript-nodenext');
});

test('create package with typescript alias extension rewrites', async () => {
await test_make_package('typescript-alias-rewrites');
});

// only run this test in newer Node versions
// TODO: remove after dropping support for Node < 22.18
const [major, minor] = process.versions.node.split('.', 2).map((str) => +str);
Expand Down
Loading