-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: basic support of dts generation
- Loading branch information
1 parent
f8965f1
commit bc82d40
Showing
39 changed files
with
1,132 additions
and
39 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,33 @@ | ||
import { execSync } from 'node:child_process'; | ||
import { join } from 'node:path'; | ||
import { expect, test } from 'vitest'; | ||
import { getResults } from '#shared'; | ||
import { loadConfig } from '../../../packages/core/src/config'; | ||
|
||
// TODO: we use npx here to test since node api will directly exit main process | ||
test('dts when bundle: false', async () => { | ||
const fixturePath = join(__dirname, 'bundle-false'); | ||
const rslibConfig = await loadConfig(join(fixturePath, 'rslib.config.ts')); | ||
|
||
execSync('npx rslib build', { | ||
cwd: fixturePath, | ||
}); | ||
|
||
const { files } = await getResults(rslibConfig, '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 rslibConfig = await loadConfig(join(fixturePath, 'rslib.config.ts')); | ||
|
||
execSync('npx rslib build', { | ||
cwd: fixturePath, | ||
}); | ||
|
||
const { entryFiles } = await getResults(rslibConfig, '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.