-
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 688c31d
Showing
39 changed files
with
1,111 additions
and
49 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,24 @@ | ||
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, | ||
dts: { | ||
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,25 @@ | ||
import { defineConfig } from '@rslib/core'; | ||
import { | ||
generateBundleCjsConfig, | ||
generateBundleEsmConfig, | ||
} from '../../../scripts/shared'; | ||
|
||
export default defineConfig({ | ||
lib: [ | ||
generateBundleEsmConfig(__dirname, { | ||
dts: { | ||
bundle: true, | ||
}, | ||
}), | ||
generateBundleCjsConfig(__dirname, { | ||
dts: { | ||
bundle: true, | ||
}, | ||
}), | ||
], | ||
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,18 @@ | ||
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 } = await buildAndGetResults(fixturePath, 'dts'); | ||
|
||
expect(files.esm?.length).toBe(4); | ||
expect(files.esm?.[0]!.endsWith('.d.ts')).toEqual(true); | ||
}); | ||
|
||
test('dts when bundle: true', async () => { | ||
const fixturePath = join(__dirname, 'bundle'); | ||
const { entryFiles } = await buildAndGetResults(fixturePath, 'dts'); | ||
|
||
expect(entryFiles.esm!.endsWith('index.d.ts')).toEqual(true); | ||
}); |
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
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.