Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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/wild-rats-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@sveltejs/package': patch
---

fix: overwrite nodenext option when transpiling
2 changes: 1 addition & 1 deletion packages/kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"dts-buddy": "^0.2.4",
"rollup": "^3.29.4",
"svelte": "^4.2.2",
"svelte-preprocess": "^5.0.4",
"svelte-preprocess": "^5.1.1",
"typescript": "^4.9.4",
"vite": "^4.4.9",
"vitest": "^0.34.5"
Expand Down
2 changes: 1 addition & 1 deletion packages/package/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"@types/node": "^16.18.6",
"@types/semver": "^7.5.0",
"svelte": "^4.2.2",
"svelte-preprocess": "^5.0.4",
"svelte-preprocess": "^5.1.1",
"typescript": "^4.9.4",
"uvu": "^0.5.6"
},
Expand Down
9 changes: 8 additions & 1 deletion packages/package/src/typescript.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,15 @@ export async function emit_dts(input, output, cwd, alias, files) {
*/
export async function transpile_ts(filename, source) {
const ts = await try_load_ts();
const options = load_tsconfig(filename, ts);
// transpileModule treats NodeNext as CommonJS because it doesn't read the package.json. Therefore we need to override it.
// Also see https://github.com/microsoft/TypeScript/issues/53022 (the filename workaround doesn't work).
return ts.transpileModule(source, {
compilerOptions: load_tsconfig(filename, ts),
compilerOptions: {
...options,
module: ts.ModuleKind.ESNext,
moduleResolution: ts.ModuleResolutionKind.NodeJs // switch this to bundler in the next major, although it probably doesn't make a difference
},
fileName: filename
}).outputText;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script>
import { createEventDispatcher } from 'svelte';
export const astring = 'potato';
const dispatch = createEventDispatcher();
dispatch('event', true);
</script>

<slot {astring} />
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { SvelteComponent } from 'svelte';
declare const __propDef: {
props: {
astring?: string;
};
events: {
event: CustomEvent<boolean>;
} & {
[evt: string]: CustomEvent<any>;
};
slots: {
default: {
astring: string;
};
};
};
export type TestProps = typeof __propDef.props;
export type TestEvents = typeof __propDef.events;
export type TestSlots = typeof __propDef.slots;
export default class Test extends SvelteComponent<TestProps, TestEvents, TestSlots> {
get astring(): string;
}
export {};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Test } from './Test.svelte';
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Test } from './Test.svelte';
16 changes: 16 additions & 0 deletions packages/package/test/fixtures/typescript-nodenext/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "typescript-nodenext",
"private": true,
"version": "1.0.0",
"description": "typescript package using nodenext",
"type": "module",
"peerDependencies": {
"svelte": "^4.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,9 @@
<script lang="ts">
import { createEventDispatcher } from 'svelte';
export const astring: string = 'potato';

const dispatch = createEventDispatcher<{ event: boolean }>();
dispatch('event', true);
</script>

<slot {astring} />
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default as Test } from './Test.svelte';
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,7 @@
{
"compilerOptions": {
"target": "ESNext",
"module": "NodeNext",
"moduleResolution": "NodeNext"
}
}
4 changes: 4 additions & 0 deletions packages/package/test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ test('create standard package with typescript', async () => {
await test_make_package('typescript');
});

test('create standard package with typescript using nodenext', async () => {
await test_make_package('typescript-nodenext');
});

test('create package and assets are not tampered', async () => {
await test_make_package('assets');
});
Expand Down
74 changes: 37 additions & 37 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.