-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: basic implementation of dts generation
- Loading branch information
1 parent
f8965f1
commit fceec04
Showing
41 changed files
with
1,183 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,17 @@ | ||
import { extname, join } from 'node:path'; | ||
import { expect, test } from 'vitest'; | ||
import { buildAndGetJsResults } from '#shared'; | ||
import { buildAndGetResults } from '#shared'; | ||
|
||
test('autoExtension generate .mjs in build artifacts with esm format when type is commonjs', async () => { | ||
const fixturePath = join(__dirname, 'type-commonjs'); | ||
const { entryFiles } = await buildAndGetJsResults(fixturePath); | ||
const { entryFiles } = await buildAndGetResults(fixturePath); | ||
expect(extname(entryFiles.esm!)).toEqual('.mjs'); | ||
expect(extname(entryFiles.cjs!)).toEqual('.js'); | ||
}); | ||
|
||
test('autoExtension generate .cjs in build artifacts with cjs format when type is module', async () => { | ||
const fixturePath = join(__dirname, 'type-module'); | ||
const { entryFiles } = await buildAndGetJsResults(fixturePath); | ||
const { entryFiles } = await buildAndGetResults(fixturePath); | ||
expect(extname(entryFiles.esm!)).toEqual('.js'); | ||
expect(extname(entryFiles.cjs!)).toEqual('.cjs'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`dts when bundle: false 1`] = ` | ||
{ | ||
"./dist/esm/index.d.ts": "export * from './utils/numbers'; | ||
export * from './utils/strings'; | ||
export * from './sum'; | ||
", | ||
"./dist/esm/sum.d.ts": "export declare const numSum: number; | ||
export declare const strSum: string; | ||
", | ||
"./dist/esm/utils/numbers.d.ts": "export declare const num1 = 1; | ||
export declare const num2 = 2; | ||
export declare const num3 = 3; | ||
", | ||
"./dist/esm/utils/strings.d.ts": "export declare const str1 = "str1"; | ||
export declare const str2 = "str2"; | ||
export declare const str3 = "str3"; | ||
", | ||
} | ||
`; | ||
|
||
exports[`dts when bundle: true 1`] = ` | ||
{ | ||
"esm": "export declare const num1 = 1; | ||
export declare const num2 = 2; | ||
export declare const num3 = 3; | ||
export declare const numSum: number; | ||
export declare const str1 = "str1"; | ||
export declare const str2 = "str2"; | ||
export declare const str3 = "str3"; | ||
export declare const strSum: string; | ||
export { } | ||
", | ||
} | ||
`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { defineConfig } from '@rslib/core'; | ||
import { generateBundleCjsConfig, generateBundleEsmConfig } from '#shared'; | ||
|
||
export default defineConfig({ | ||
lib: [ | ||
generateBundleEsmConfig(__dirname, { | ||
bundle: false, | ||
dts: { | ||
bundle: false, | ||
}, | ||
}), | ||
generateBundleCjsConfig(__dirname, { | ||
bundle: false, | ||
}), | ||
], | ||
source: { | ||
entry: { | ||
main: ['./src/**'], | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './utils/numbers'; | ||
export * from './utils/strings'; | ||
export * from './sum'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { num1, num2, num3 } from './utils/numbers'; | ||
import { str1, str2, str3 } from './utils/strings'; | ||
|
||
export const numSum = num1 + num2 + num3; | ||
export const strSum = str1 + str2 + str3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const num1 = 1; | ||
export const num2 = 2; | ||
export const num3 = 3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const str1 = 'str1'; | ||
export const str2 = 'str2'; | ||
export const str3 = 'str3'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "@rslib/tsconfig/base", | ||
"compilerOptions": { | ||
"baseUrl": "./" | ||
}, | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"name": "dts-bundle-test", | ||
"version": "1.0.0", | ||
"private": true, | ||
"type": "module" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { defineConfig } from '@rslib/core'; | ||
import { | ||
generateBundleCjsConfig, | ||
generateBundleEsmConfig, | ||
} from '../../../scripts/shared'; | ||
|
||
export default defineConfig({ | ||
lib: [ | ||
generateBundleEsmConfig(__dirname, { | ||
dts: { | ||
bundle: true, | ||
}, | ||
}), | ||
generateBundleCjsConfig(__dirname), | ||
], | ||
source: { | ||
entry: { | ||
main: './src/index.ts', | ||
}, | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './utils/numbers'; | ||
export * from './utils/strings'; | ||
export * from './sum'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { num1, num2, num3 } from './utils/numbers'; | ||
import { str1, str2, str3 } from './utils/strings'; | ||
|
||
export const numSum = num1 + num2 + num3; | ||
export const strSum = str1 + str2 + str3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const num1 = 1; | ||
export const num2 = 2; | ||
export const num3 = 3; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export const str1 = 'str1'; | ||
export const str2 = 'str2'; | ||
export const str3 = 'str3'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"extends": "@rslib/tsconfig/base", | ||
"compilerOptions": { | ||
"baseUrl": "./" | ||
}, | ||
"include": ["src"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { join } from 'node:path'; | ||
import { expect, test } from 'vitest'; | ||
import { buildAndGetResults } from '#shared'; | ||
|
||
test('dts when bundle: false', async () => { | ||
const fixturePath = join(__dirname, 'bundle-false'); | ||
const { files, contents } = await buildAndGetResults(fixturePath, 'dts'); | ||
|
||
expect(files.esm?.length).toBe(4); | ||
expect(files.esm?.[0]!.endsWith('.d.ts')).toEqual(true); | ||
expect(contents.esm).toMatchSnapshot(); | ||
}); | ||
|
||
test('dts when bundle: true', async () => { | ||
const fixturePath = join(__dirname, 'bundle'); | ||
const { entryFiles, entries } = await buildAndGetResults(fixturePath, 'dts'); | ||
|
||
expect(entryFiles.esm!.endsWith('index.d.ts')).toEqual(true); | ||
expect(entries).toMatchSnapshot(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,9 @@ | ||
import { join } from 'node:path'; | ||
import { expect, test } from 'vitest'; | ||
import { buildAndGetJsResults } from '#shared'; | ||
import { buildAndGetResults } from '#shared'; | ||
|
||
test('should fail to build when `output.target` is not "node"', async () => { | ||
const fixturePath = join(__dirname); | ||
const build = buildAndGetJsResults(fixturePath); | ||
const build = buildAndGetResults(fixturePath); | ||
await expect(build).rejects.toThrowError('Rspack build failed!'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.