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/fix-ts6-rootdir.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"zile": patch
---

Fixed TypeScript 6 compatibility by adding `rootDir` to the generated tsconfig. Uses the computed common source directory from entry points as the default.
7 changes: 5 additions & 2 deletions src/Package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export async function build(options: build.Options): Promise<build.ReturnType> {
const sourceDir = getSourceDir({ cwd, sources })

if (!link) {
const result = await transpile({ cwd, sources, tsgo })
const result = await transpile({ cwd, sources, sourceDir, tsgo })
tsConfig = result.tsConfig
}

Expand Down Expand Up @@ -679,7 +679,7 @@ export declare namespace readTsconfigJson {
* @returns Transpilation artifacts.
*/
export async function transpile(options: transpile.Options): Promise<transpile.ReturnType> {
const { cwd = process.cwd(), sources, project = './tsconfig.json', tsgo } = options
const { cwd = process.cwd(), sources, sourceDir, project = './tsconfig.json', tsgo } = options

const tsConfigJson = await readTsconfigJson({ cwd, project })
const tsconfigPath = path.resolve(cwd, project)
Expand Down Expand Up @@ -709,6 +709,7 @@ export async function transpile(options: transpile.Options): Promise<transpile.R
esModuleInterop: true,
noEmit: false,
outDir: tsConfigJson.compilerOptions?.outDir ?? path.resolve(cwd, 'dist'),
rootDir: tsConfigJson.compilerOptions?.rootDir ?? sourceDir ?? '.',
skipLibCheck: true,
sourceMap: true,
target: tsConfigJson.compilerOptions?.target ?? 'es2022',
Expand Down Expand Up @@ -749,6 +750,8 @@ export declare namespace transpile {
cwd?: string | undefined
/** Source files to include in the transpilation. */
sources: string[]
/** Common source directory, used as rootDir fallback. */
sourceDir?: string | undefined
/** Path to tsconfig.json file, relative to the working directory. @default './tsconfig.json' */
project?: string | undefined
/** Whether to use tsgo for transpilation. @default false */
Expand Down
8 changes: 8 additions & 0 deletions src/__snapshots__/Package.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ exports[`'/basic': Package.build > default > result 1`] = `
"moduleResolution": "nodenext",
"noEmit": false,
"outDir": "/repos/basic/dist",
"rootDir": "/repos/basic",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
Expand Down Expand Up @@ -403,6 +404,7 @@ exports[`'/basic-object-exports': Package.build > default > result 1`] = `
"moduleResolution": "nodenext",
"noEmit": false,
"outDir": "/repos/basic-object-exports/dist",
"rootDir": "/repos/basic-object-exports",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
Expand Down Expand Up @@ -610,6 +612,7 @@ exports[`'/bin-with-src': Package.build > default > result 1`] = `
"moduleResolution": "NodeNext",
"noEmit": false,
"outDir": "dist",
"rootDir": "/repos/bin-with-src/src",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
Expand Down Expand Up @@ -831,6 +834,7 @@ exports[`'/dts-exports': Package.build > default > result 1`] = `
"moduleResolution": "nodenext",
"noEmit": false,
"outDir": "/repos/dts-exports/dist",
"rootDir": "/repos/dts-exports/src",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
Expand Down Expand Up @@ -1046,6 +1050,7 @@ exports[`'/dts-exports-object': Package.build > default > result 1`] = `
"moduleResolution": "nodenext",
"noEmit": false,
"outDir": "/repos/dts-exports-object/dist",
"rootDir": "/repos/dts-exports-object/src",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
Expand Down Expand Up @@ -1326,6 +1331,7 @@ exports[`'/multiple-entrypoint': Package.build > default > result 1`] = `
"moduleResolution": "nodenext",
"noEmit": false,
"outDir": "/repos/multiple-entrypoint/dist",
"rootDir": "/repos/multiple-entrypoint/src",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
Expand Down Expand Up @@ -1572,6 +1578,7 @@ exports[`'/single-entrypoint': Package.build > default > result 1`] = `
"moduleResolution": "nodenext",
"noEmit": false,
"outDir": "/repos/single-entrypoint/dist",
"rootDir": "/repos/single-entrypoint",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
Expand Down Expand Up @@ -1814,6 +1821,7 @@ exports[`'/wildcard-exports': Package.build > default > result 1`] = `
"moduleResolution": "nodenext",
"noEmit": false,
"outDir": "/repos/wildcard-exports/dist",
"rootDir": "/repos/wildcard-exports",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
Expand Down
8 changes: 8 additions & 0 deletions src/__snapshots__/Packages.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ exports[`Packages.build > builds all packages 1`] = `
"moduleResolution": "nodenext",
"noEmit": false,
"outDir": "/repos/wildcard-exports/dist",
"rootDir": "/repos/wildcard-exports",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
Expand Down Expand Up @@ -85,6 +86,7 @@ exports[`Packages.build > builds all packages 1`] = `
"moduleResolution": "nodenext",
"noEmit": false,
"outDir": "/repos/single-entrypoint/dist",
"rootDir": "/repos/single-entrypoint",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
Expand Down Expand Up @@ -138,6 +140,7 @@ exports[`Packages.build > builds all packages 1`] = `
"moduleResolution": "nodenext",
"noEmit": false,
"outDir": "/repos/multiple-entrypoint/dist",
"rootDir": "/repos/multiple-entrypoint/src",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
Expand Down Expand Up @@ -187,6 +190,7 @@ exports[`Packages.build > builds all packages 1`] = `
"moduleResolution": "nodenext",
"noEmit": false,
"outDir": "/repos/dts-exports-object/dist",
"rootDir": "/repos/dts-exports-object/src",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
Expand Down Expand Up @@ -234,6 +238,7 @@ exports[`Packages.build > builds all packages 1`] = `
"moduleResolution": "nodenext",
"noEmit": false,
"outDir": "/repos/dts-exports/dist",
"rootDir": "/repos/dts-exports/src",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
Expand Down Expand Up @@ -279,6 +284,7 @@ exports[`Packages.build > builds all packages 1`] = `
"moduleResolution": "NodeNext",
"noEmit": false,
"outDir": "dist",
"rootDir": "/repos/bin-with-src/src",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
Expand Down Expand Up @@ -323,6 +329,7 @@ exports[`Packages.build > builds all packages 1`] = `
"moduleResolution": "nodenext",
"noEmit": false,
"outDir": "/repos/basic-object-exports/dist",
"rootDir": "/repos/basic-object-exports",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
Expand Down Expand Up @@ -376,6 +383,7 @@ exports[`Packages.build > builds all packages 1`] = `
"moduleResolution": "nodenext",
"noEmit": false,
"outDir": "/repos/basic/dist",
"rootDir": "/repos/basic",
"skipLibCheck": true,
"sourceMap": true,
"strict": true,
Expand Down
Loading