@vitus-labs/tools-rolldown 1.15.5 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +11 -6
- package/CHANGELOG.md +0 -96
- package/src/bin/run-build.ts +0 -4
- package/src/bin/run-watch.ts +0 -54
- package/src/config/baseConfig.test.ts +0 -60
- package/src/config/baseConfig.ts +0 -51
- package/src/config/index.ts +0 -10
- package/src/index.ts +0 -3
- package/src/rolldown/config.test.ts +0 -348
- package/src/rolldown/config.ts +0 -228
- package/src/rolldown/createBuildPipeline.test.ts +0 -375
- package/src/rolldown/createBuildPipeline.ts +0 -218
- package/src/rolldown/index.ts +0 -4
- package/src/scripts/build.test.ts +0 -336
- package/src/scripts/build.ts +0 -172
- package/tsconfig.json +0 -15
- package/vitest.config.ts +0 -3
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vitus-labs/tools-rolldown",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -12,6 +12,10 @@
|
|
|
12
12
|
"Vit Bokisch <vit@bokisch.com>"
|
|
13
13
|
],
|
|
14
14
|
"type": "module",
|
|
15
|
+
"files": [
|
|
16
|
+
"lib",
|
|
17
|
+
"global"
|
|
18
|
+
],
|
|
15
19
|
"exports": {
|
|
16
20
|
".": {
|
|
17
21
|
"types": "./lib/types/index.d.ts",
|
|
@@ -37,16 +41,17 @@
|
|
|
37
41
|
"access": "public"
|
|
38
42
|
},
|
|
39
43
|
"dependencies": {
|
|
40
|
-
"@vitus-labs/tools-core": "^
|
|
44
|
+
"@vitus-labs/tools-core": "^2.0.0",
|
|
41
45
|
"chalk": "^5.6.2",
|
|
42
46
|
"rimraf": "^6.1.3",
|
|
43
|
-
"rolldown": "^1.0.0-rc.
|
|
44
|
-
"rolldown-plugin-dts": "^0.
|
|
47
|
+
"rolldown": "^1.0.0-rc.17",
|
|
48
|
+
"rolldown-plugin-dts": "^0.23.2",
|
|
45
49
|
"rollup-plugin-filesize": "^10.0.0",
|
|
46
50
|
"rollup-plugin-visualizer": "^7.0.1"
|
|
47
51
|
},
|
|
48
52
|
"devDependencies": {
|
|
49
|
-
"@
|
|
50
|
-
"typescript": "^
|
|
53
|
+
"@types/node": "^25.6.0",
|
|
54
|
+
"@vitus-labs/tools-typescript": "^2.0.0",
|
|
55
|
+
"typescript": "^6.0.3"
|
|
51
56
|
}
|
|
52
57
|
}
|
package/CHANGELOG.md
DELETED
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
# Change Log
|
|
2
|
-
|
|
3
|
-
## 1.15.5
|
|
4
|
-
|
|
5
|
-
### Patch Changes
|
|
6
|
-
|
|
7
|
-
- [#98](https://github.com/vitus-labs/tools/pull/98) [`9ec732d`](https://github.com/vitus-labs/tools/commit/9ec732d7899c10e035cce253088eaa10bf63f1af) Thanks [@vitbokisch](https://github.com/vitbokisch)! - Resolve `.tsx`, `.js`, and `.jsx` extensions for DTS subpath export inputs instead of assuming `.ts`
|
|
8
|
-
|
|
9
|
-
- Updated dependencies []:
|
|
10
|
-
- @vitus-labs/tools-core@1.15.5
|
|
11
|
-
|
|
12
|
-
## 1.15.4
|
|
13
|
-
|
|
14
|
-
### Patch Changes
|
|
15
|
-
|
|
16
|
-
- [#85](https://github.com/vitus-labs/tools/pull/85) [`c0b6735`](https://github.com/vitus-labs/tools/commit/c0b6735c3255f0fa275d247b3dee6f95696e0fda) Thanks [@vitbokisch](https://github.com/vitbokisch)! - Pass `emitDtsOnly: true` to rolldown-plugin-dts to prevent JS output chunks in declaration builds
|
|
17
|
-
|
|
18
|
-
- Updated dependencies []:
|
|
19
|
-
- @vitus-labs/tools-core@1.15.4
|
|
20
|
-
|
|
21
|
-
## 1.15.3
|
|
22
|
-
|
|
23
|
-
### Patch Changes
|
|
24
|
-
|
|
25
|
-
- [`559aa76`](https://github.com/vitus-labs/tools/commit/559aa76cbcfd95f21a20d15a38cea04174294192) Thanks [@vitbokisch](https://github.com/vitbokisch)! - Build each DTS entry in an isolated temp dir to prevent collisions with subpath exports
|
|
26
|
-
|
|
27
|
-
- Updated dependencies []:
|
|
28
|
-
- @vitus-labs/tools-core@1.15.3
|
|
29
|
-
|
|
30
|
-
## 1.15.2
|
|
31
|
-
|
|
32
|
-
### Patch Changes
|
|
33
|
-
|
|
34
|
-
- [`99a7d1f`](https://github.com/vitus-labs/tools/commit/99a7d1f5548f81009a616baeb726487e0affcaa6) Thanks [@vitbokisch](https://github.com/vitbokisch)! - Fix DTS generation collisions for packages with multiple subpath exports
|
|
35
|
-
|
|
36
|
-
- Updated dependencies []:
|
|
37
|
-
- @vitus-labs/tools-core@1.15.2
|
|
38
|
-
|
|
39
|
-
## 1.15.1
|
|
40
|
-
|
|
41
|
-
### Patch Changes
|
|
42
|
-
|
|
43
|
-
- [`2aa6a53`](https://github.com/vitus-labs/tools/commit/2aa6a531eac6b1f48bdd81b0883efa8672e7b29d) Thanks [@vitbokisch](https://github.com/vitbokisch)! - Fix DTS generation collisions for packages with multiple subpath exports
|
|
44
|
-
|
|
45
|
-
- Updated dependencies []:
|
|
46
|
-
- @vitus-labs/tools-core@1.15.1
|
|
47
|
-
|
|
48
|
-
## 1.15.0
|
|
49
|
-
|
|
50
|
-
### Patch Changes
|
|
51
|
-
|
|
52
|
-
- [`41ac6c5`](https://github.com/vitus-labs/tools/commit/41ac6c5288dec3d1e113db15c2a62a042174f6b4) Thanks [@vitbokisch](https://github.com/vitbokisch)! - **vitest**: Upgrade to vite 8 peer dependency. Plugin types use `unknown[]` for cross-version compatibility.
|
|
53
|
-
|
|
54
|
-
**rolldown**: Skip passthrough exports (e.g. `"./package.json": "./package.json"`) and exports without build conditions.
|
|
55
|
-
|
|
56
|
-
**all**: Update next 16.1.7, vite 8.0.0. Fix publish script tarball parsing.
|
|
57
|
-
|
|
58
|
-
- Updated dependencies [[`41ac6c5`](https://github.com/vitus-labs/tools/commit/41ac6c5288dec3d1e113db15c2a62a042174f6b4)]:
|
|
59
|
-
- @vitus-labs/tools-core@1.15.0
|
|
60
|
-
|
|
61
|
-
## 1.14.0
|
|
62
|
-
|
|
63
|
-
### Minor Changes
|
|
64
|
-
|
|
65
|
-
- [`3605125`](https://github.com/vitus-labs/tools/commit/36051255315da3d87a2a6b8d6b7ecd8cb9f718f9) Thanks [@vitbokisch](https://github.com/vitbokisch)! - **rolldown**: Auto-derive build entries from package.json subpath exports (e.g., `"./devtools"`, `"./validation/zod"`). Generates separate `.d.ts` declarations per subpath.
|
|
66
|
-
|
|
67
|
-
**vitest**: Export `DEFAULT_COVERAGE_EXCLUDE` and `DEFAULT_COVERAGE_INCLUDE` for `mergeConfig` compatibility. Add `coverageInclude` option.
|
|
68
|
-
|
|
69
|
-
**all**: Switch to `workspace:^` protocol, custom publish script with OIDC provenance.
|
|
70
|
-
|
|
71
|
-
### Patch Changes
|
|
72
|
-
|
|
73
|
-
- Updated dependencies [[`3605125`](https://github.com/vitus-labs/tools/commit/36051255315da3d87a2a6b8d6b7ecd8cb9f718f9)]:
|
|
74
|
-
- @vitus-labs/tools-core@1.14.0
|
|
75
|
-
|
|
76
|
-
## 1.13.0
|
|
77
|
-
|
|
78
|
-
### Minor Changes
|
|
79
|
-
|
|
80
|
-
- [`d76a254`](https://github.com/vitus-labs/tools/commit/d76a2541c1149d88c2d6af50181e502b78c6d1ec) Thanks [@vitbokisch](https://github.com/vitbokisch)! - Add advanced rolldown build options (entries, bundleAll, copyFiles, banner/footer, alias, plugins) for non-library targets like Chrome extensions, CLI tools, and Lambda functions. Replace Lerna with Changesets for versioning and changelog generation.
|
|
81
|
-
|
|
82
|
-
### Patch Changes
|
|
83
|
-
|
|
84
|
-
- Updated dependencies [[`d76a254`](https://github.com/vitus-labs/tools/commit/d76a2541c1149d88c2d6af50181e502b78c6d1ec)]:
|
|
85
|
-
- @vitus-labs/tools-core@1.13.0
|
|
86
|
-
|
|
87
|
-
All notable changes to this project will be documented in this file.
|
|
88
|
-
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
89
|
-
|
|
90
|
-
## [1.5.2-alpha.1](https://github.com/vitus-labs/tools/compare/v1.5.2-alpha.0...v1.5.2-alpha.1) (2026-02-07)
|
|
91
|
-
|
|
92
|
-
**Note:** Version bump only for package @vitus-labs/tools-rolldown
|
|
93
|
-
|
|
94
|
-
## [1.5.2-alpha.0](https://github.com/vitus-labs/tools/compare/v1.5.1...v1.5.2-alpha.0) (2026-02-06)
|
|
95
|
-
|
|
96
|
-
**Note:** Version bump only for package @vitus-labs/tools-rolldown
|
package/src/bin/run-build.ts
DELETED
package/src/bin/run-watch.ts
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import chalk from 'chalk'
|
|
3
|
-
import { watch } from 'rolldown'
|
|
4
|
-
import { PKG } from '../config/index.js'
|
|
5
|
-
import {
|
|
6
|
-
createBuildPipeline,
|
|
7
|
-
config as rolldownConfig,
|
|
8
|
-
} from '../rolldown/index.js'
|
|
9
|
-
|
|
10
|
-
const { log } = console
|
|
11
|
-
const allBuilds = createBuildPipeline()
|
|
12
|
-
|
|
13
|
-
const label = (text: string) => chalk.bold.bgCyan.black(` ${text} `)
|
|
14
|
-
const dim = chalk.dim
|
|
15
|
-
const bold = chalk.bold
|
|
16
|
-
|
|
17
|
-
const watchConfigs = allBuilds.map((item: Record<string, any>) => {
|
|
18
|
-
const { output, ...input } = rolldownConfig(item)
|
|
19
|
-
return { ...input, output }
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
log(`\n${label('rolldown')} ${bold(PKG.name || '')} ${dim('watch mode')}\n`)
|
|
23
|
-
log(dim('Waiting for changes...\n'))
|
|
24
|
-
|
|
25
|
-
const watcher = watch(watchConfigs)
|
|
26
|
-
|
|
27
|
-
watcher.on('event', (event) => {
|
|
28
|
-
switch (event.code) {
|
|
29
|
-
case 'START':
|
|
30
|
-
log(dim('Rebuilding...'))
|
|
31
|
-
break
|
|
32
|
-
case 'BUNDLE_END':
|
|
33
|
-
log(
|
|
34
|
-
` ${chalk.green('+')} ${dim(event.output.join(', '))} ${dim(`(${event.duration}ms)`)}`,
|
|
35
|
-
)
|
|
36
|
-
event.result.close()
|
|
37
|
-
break
|
|
38
|
-
case 'END':
|
|
39
|
-
log(`${chalk.green('Ready')} ${dim('- waiting for changes...')}\n`)
|
|
40
|
-
break
|
|
41
|
-
case 'ERROR':
|
|
42
|
-
log(`\n${chalk.red('Error')} ${event.error.message || event.error}\n`)
|
|
43
|
-
if ('frame' in event.error && event.error.frame) {
|
|
44
|
-
log(dim(String(event.error.frame)))
|
|
45
|
-
}
|
|
46
|
-
break
|
|
47
|
-
}
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
process.on('SIGINT', () => {
|
|
51
|
-
log(dim('\nStopping...\n'))
|
|
52
|
-
watcher.close()
|
|
53
|
-
process.exit(0)
|
|
54
|
-
})
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import baseConfig from './baseConfig'
|
|
3
|
-
|
|
4
|
-
describe('baseConfig', () => {
|
|
5
|
-
it('should have correct directory settings', () => {
|
|
6
|
-
expect(baseConfig.sourceDir).toBe('src')
|
|
7
|
-
expect(baseConfig.outputDir).toBe('lib')
|
|
8
|
-
expect(baseConfig.typesDir).toBe('lib/types')
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
it('should have typescript enabled', () => {
|
|
12
|
-
expect(baseConfig.typescript).toBe(true)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
it('should include all expected file extensions', () => {
|
|
16
|
-
const expectedExtensions = [
|
|
17
|
-
'.json',
|
|
18
|
-
'.js',
|
|
19
|
-
'.jsx',
|
|
20
|
-
'.ts',
|
|
21
|
-
'.tsx',
|
|
22
|
-
'.es6',
|
|
23
|
-
'.es',
|
|
24
|
-
'.mjs',
|
|
25
|
-
]
|
|
26
|
-
expect(baseConfig.extensions).toEqual(expectedExtensions)
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
it('should exclude test patterns', () => {
|
|
30
|
-
expect(baseConfig.exclude).toContain('**/__tests__/**')
|
|
31
|
-
expect(baseConfig.exclude).toContain('**/__specs__/**')
|
|
32
|
-
expect(baseConfig.exclude).toContain('**/__stories__/**')
|
|
33
|
-
expect(baseConfig.exclude).toContain('*.test.*')
|
|
34
|
-
expect(baseConfig.exclude).toContain('*.spec.*')
|
|
35
|
-
expect(baseConfig.exclude).toContain('*.stories.*')
|
|
36
|
-
expect(baseConfig.exclude).toContain('*.story.*')
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('should define globals for react, ReactDOM, and styled', () => {
|
|
40
|
-
expect(baseConfig.globals).toEqual({
|
|
41
|
-
react: 'React',
|
|
42
|
-
ReactDOM: 'react-dom',
|
|
43
|
-
styled: 'styled-components',
|
|
44
|
-
})
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
it('should include react/jsx-runtime as external', () => {
|
|
48
|
-
expect(baseConfig.external).toContain('react/jsx-runtime')
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
it('should have safe defaults for advanced build options', () => {
|
|
52
|
-
expect(baseConfig.entries).toBeUndefined()
|
|
53
|
-
expect(baseConfig.bundleAll).toBe(false)
|
|
54
|
-
expect(baseConfig.copyFiles).toBeUndefined()
|
|
55
|
-
expect(baseConfig.banner).toBeUndefined()
|
|
56
|
-
expect(baseConfig.footer).toBeUndefined()
|
|
57
|
-
expect(baseConfig.alias).toBeUndefined()
|
|
58
|
-
expect(baseConfig.plugins).toEqual([])
|
|
59
|
-
})
|
|
60
|
-
})
|
package/src/config/baseConfig.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
sourceDir: 'src',
|
|
3
|
-
outputDir: 'lib',
|
|
4
|
-
typesDir: 'lib/types',
|
|
5
|
-
typescript: true,
|
|
6
|
-
esModulesOnly: false,
|
|
7
|
-
replaceGlobals: true,
|
|
8
|
-
visualise: {
|
|
9
|
-
template: 'network',
|
|
10
|
-
gzipSize: true,
|
|
11
|
-
outputDir: 'analysis',
|
|
12
|
-
},
|
|
13
|
-
filesize: true,
|
|
14
|
-
extensions: ['.json', '.js', '.jsx', '.ts', '.tsx', '.es6', '.es', '.mjs'],
|
|
15
|
-
include: ['src'],
|
|
16
|
-
external: ['react/jsx-runtime'],
|
|
17
|
-
exclude: [
|
|
18
|
-
'lib',
|
|
19
|
-
'node_modules/**',
|
|
20
|
-
'**/__tests__/**',
|
|
21
|
-
'**/__specs__/**',
|
|
22
|
-
'**/__stories__/**',
|
|
23
|
-
'*.test.*',
|
|
24
|
-
'*.spec.*',
|
|
25
|
-
'*.stories.*',
|
|
26
|
-
'stories.*',
|
|
27
|
-
'*.story.*',
|
|
28
|
-
],
|
|
29
|
-
globals: {
|
|
30
|
-
react: 'React',
|
|
31
|
-
ReactDOM: 'react-dom',
|
|
32
|
-
styled: 'styled-components',
|
|
33
|
-
},
|
|
34
|
-
|
|
35
|
-
// Advanced build options
|
|
36
|
-
entries: undefined as
|
|
37
|
-
| {
|
|
38
|
-
input: string
|
|
39
|
-
file: string
|
|
40
|
-
format?: string
|
|
41
|
-
env?: string
|
|
42
|
-
platform?: string
|
|
43
|
-
}[]
|
|
44
|
-
| undefined,
|
|
45
|
-
bundleAll: false,
|
|
46
|
-
copyFiles: undefined as { from: string; to: string }[] | undefined,
|
|
47
|
-
banner: undefined as string | undefined,
|
|
48
|
-
footer: undefined as string | undefined,
|
|
49
|
-
alias: undefined as Record<string, string> | undefined,
|
|
50
|
-
plugins: [] as unknown[],
|
|
51
|
-
}
|
package/src/config/index.ts
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { PKG, TS_CONFIG, VL_CONFIG } from '@vitus-labs/tools-core'
|
|
2
|
-
import baseConfig from './baseConfig.js'
|
|
3
|
-
|
|
4
|
-
const CONFIG_KEY = 'build'
|
|
5
|
-
|
|
6
|
-
const CONFIG = VL_CONFIG(CONFIG_KEY).merge(baseConfig).config
|
|
7
|
-
|
|
8
|
-
const PLATFORMS = ['browser', 'node', 'web', 'native'] as const
|
|
9
|
-
|
|
10
|
-
export { CONFIG, PKG, PLATFORMS, TS_CONFIG }
|
package/src/index.ts
DELETED
|
@@ -1,348 +0,0 @@
|
|
|
1
|
-
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
-
|
|
3
|
-
vi.mock('rolldown-plugin-dts', () => ({
|
|
4
|
-
dts: vi.fn(() => [{ name: 'mock-dts' }]),
|
|
5
|
-
}))
|
|
6
|
-
vi.mock('rollup-plugin-filesize', () => ({
|
|
7
|
-
default: vi.fn(() => ({ name: 'mock-filesize' })),
|
|
8
|
-
}))
|
|
9
|
-
vi.mock('rollup-plugin-visualizer', () => ({
|
|
10
|
-
visualizer: vi.fn(() => ({ name: 'mock-visualizer' })),
|
|
11
|
-
}))
|
|
12
|
-
vi.mock('@vitus-labs/tools-core', () => ({
|
|
13
|
-
swapGlobals: (globals: Record<string, string>) =>
|
|
14
|
-
Object.fromEntries(Object.entries(globals).map(([k, v]) => [v, k])),
|
|
15
|
-
}))
|
|
16
|
-
|
|
17
|
-
const { mockConfig, mockPKG } = vi.hoisted(() => ({
|
|
18
|
-
mockConfig: {
|
|
19
|
-
sourceDir: 'src',
|
|
20
|
-
outputDir: 'lib',
|
|
21
|
-
typesDir: 'lib/types',
|
|
22
|
-
extensions: ['.ts', '.tsx', '.js'],
|
|
23
|
-
typescript: true,
|
|
24
|
-
replaceGlobals: true,
|
|
25
|
-
visualise: { template: 'network', gzipSize: true, outputDir: 'analysis' },
|
|
26
|
-
filesize: true,
|
|
27
|
-
external: ['react/jsx-runtime'],
|
|
28
|
-
globals: { react: 'React' },
|
|
29
|
-
} as Record<string, any>,
|
|
30
|
-
mockPKG: {
|
|
31
|
-
name: '@test/pkg',
|
|
32
|
-
version: '1.0.0',
|
|
33
|
-
bundleName: 'testPkg',
|
|
34
|
-
externalDependencies: ['react'],
|
|
35
|
-
exports: { types: './lib/index.d.ts', import: './lib/index.js' },
|
|
36
|
-
} as Record<string, any>,
|
|
37
|
-
}))
|
|
38
|
-
|
|
39
|
-
vi.mock('../config/index.js', () => ({
|
|
40
|
-
CONFIG: mockConfig,
|
|
41
|
-
PKG: mockPKG,
|
|
42
|
-
PLATFORMS: ['browser', 'node', 'web', 'native'],
|
|
43
|
-
}))
|
|
44
|
-
|
|
45
|
-
import rolldownConfig, { buildDts } from './config.js'
|
|
46
|
-
|
|
47
|
-
const defaultConfig = { ...mockConfig }
|
|
48
|
-
const defaultPKG = { ...mockPKG }
|
|
49
|
-
|
|
50
|
-
describe('rolldownConfig', () => {
|
|
51
|
-
beforeEach(() => {
|
|
52
|
-
Object.assign(mockConfig, defaultConfig)
|
|
53
|
-
Object.assign(mockPKG, defaultPKG)
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
it('should create a valid ES module build config', () => {
|
|
57
|
-
const config = rolldownConfig({
|
|
58
|
-
file: 'lib/index.js',
|
|
59
|
-
format: 'es',
|
|
60
|
-
env: 'development',
|
|
61
|
-
platform: 'universal',
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
expect(config.input).toBe('src')
|
|
65
|
-
expect(config.output.format).toBe('es')
|
|
66
|
-
expect(config.output.sourcemap).toBe(true)
|
|
67
|
-
expect(config.output.esModule).toBe(true)
|
|
68
|
-
expect(config.external).toContain('react')
|
|
69
|
-
expect(config.external).toContain('react/jsx-runtime')
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
it('should set platform to node for node builds', () => {
|
|
73
|
-
const config = rolldownConfig({
|
|
74
|
-
file: 'lib/index.cjs',
|
|
75
|
-
format: 'cjs',
|
|
76
|
-
env: 'development',
|
|
77
|
-
platform: 'node',
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
expect(config.platform).toBe('node')
|
|
81
|
-
expect(config.output.exports).toBe('named')
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it('should set platform to browser for browser builds', () => {
|
|
85
|
-
const config = rolldownConfig({
|
|
86
|
-
file: 'lib/index.js',
|
|
87
|
-
format: 'es',
|
|
88
|
-
env: 'development',
|
|
89
|
-
platform: 'browser',
|
|
90
|
-
})
|
|
91
|
-
|
|
92
|
-
expect(config.platform).toBe('browser')
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
it('should set platform to neutral for unknown platforms', () => {
|
|
96
|
-
const config = rolldownConfig({
|
|
97
|
-
file: 'lib/index.js',
|
|
98
|
-
format: 'es',
|
|
99
|
-
env: 'development',
|
|
100
|
-
platform: 'universal',
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
expect(config.platform).toBe('neutral')
|
|
104
|
-
})
|
|
105
|
-
|
|
106
|
-
it('should add platform-specific extensions for known platforms', () => {
|
|
107
|
-
const config = rolldownConfig({
|
|
108
|
-
file: 'lib/index.js',
|
|
109
|
-
format: 'es',
|
|
110
|
-
env: 'development',
|
|
111
|
-
platform: 'browser',
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
expect(config.resolve.extensions).toContain('.browser.ts')
|
|
115
|
-
expect(config.resolve.extensions).toContain('.ts')
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
it('should not add platform extensions for unknown platforms', () => {
|
|
119
|
-
const config = rolldownConfig({
|
|
120
|
-
file: 'lib/index.js',
|
|
121
|
-
format: 'es',
|
|
122
|
-
env: 'development',
|
|
123
|
-
platform: 'universal',
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
expect(config.resolve.extensions).not.toContain('.universal.ts')
|
|
127
|
-
expect(config.resolve.extensions).toContain('.ts')
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
it('should set name for UMD format', () => {
|
|
131
|
-
const config = rolldownConfig({
|
|
132
|
-
file: 'lib/index.umd.js',
|
|
133
|
-
format: 'umd',
|
|
134
|
-
env: 'development',
|
|
135
|
-
platform: 'universal',
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
expect(config.output.name).toBe('testPkg')
|
|
139
|
-
expect(config.output.exports).toBe('named')
|
|
140
|
-
})
|
|
141
|
-
|
|
142
|
-
it('should add define options with replaceGlobals', () => {
|
|
143
|
-
const config = rolldownConfig({
|
|
144
|
-
file: 'lib/index.js',
|
|
145
|
-
format: 'es',
|
|
146
|
-
env: 'development',
|
|
147
|
-
platform: 'node',
|
|
148
|
-
})
|
|
149
|
-
|
|
150
|
-
expect(config.transform?.define?.__VERSION__).toBe('"1.0.0"')
|
|
151
|
-
expect(config.transform?.define?.__NODE__).toBe('true')
|
|
152
|
-
})
|
|
153
|
-
|
|
154
|
-
it('should add process.env.NODE_ENV for production builds', () => {
|
|
155
|
-
const config = rolldownConfig({
|
|
156
|
-
file: 'lib/index.js',
|
|
157
|
-
format: 'es',
|
|
158
|
-
env: 'production',
|
|
159
|
-
platform: 'universal',
|
|
160
|
-
})
|
|
161
|
-
|
|
162
|
-
expect(config.transform?.define?.['process.env.NODE_ENV']).toBe(
|
|
163
|
-
'"production"',
|
|
164
|
-
)
|
|
165
|
-
expect(config.output.minify).toBe(true)
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
it('should not minify development builds', () => {
|
|
169
|
-
const config = rolldownConfig({
|
|
170
|
-
file: 'lib/index.js',
|
|
171
|
-
format: 'es',
|
|
172
|
-
env: 'development',
|
|
173
|
-
platform: 'universal',
|
|
174
|
-
})
|
|
175
|
-
|
|
176
|
-
expect(config.output.minify).toBe(false)
|
|
177
|
-
})
|
|
178
|
-
|
|
179
|
-
it('should skip define options when replaceGlobals is false', () => {
|
|
180
|
-
mockConfig.replaceGlobals = false
|
|
181
|
-
|
|
182
|
-
const config = rolldownConfig({
|
|
183
|
-
file: 'lib/index.js',
|
|
184
|
-
format: 'es',
|
|
185
|
-
env: 'development',
|
|
186
|
-
platform: 'universal',
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
expect(config.transform).toBeUndefined()
|
|
190
|
-
})
|
|
191
|
-
|
|
192
|
-
it('should skip visualizer when visualise is false', () => {
|
|
193
|
-
mockConfig.visualise = false
|
|
194
|
-
|
|
195
|
-
const config = rolldownConfig({
|
|
196
|
-
file: 'lib/index.js',
|
|
197
|
-
format: 'es',
|
|
198
|
-
env: 'development',
|
|
199
|
-
platform: 'universal',
|
|
200
|
-
})
|
|
201
|
-
|
|
202
|
-
const hasVisualizer = config.plugins.some(
|
|
203
|
-
(p: any) => p?.name === 'mock-visualizer',
|
|
204
|
-
)
|
|
205
|
-
expect(hasVisualizer).toBe(false)
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
it('should skip filesize when filesize is false', () => {
|
|
209
|
-
mockConfig.filesize = false
|
|
210
|
-
|
|
211
|
-
const config = rolldownConfig({
|
|
212
|
-
file: 'lib/index.js',
|
|
213
|
-
format: 'es',
|
|
214
|
-
env: 'development',
|
|
215
|
-
platform: 'universal',
|
|
216
|
-
})
|
|
217
|
-
|
|
218
|
-
const hasFilesize = config.plugins.some(
|
|
219
|
-
(p: any) => p?.name === 'mock-filesize',
|
|
220
|
-
)
|
|
221
|
-
expect(hasFilesize).toBe(false)
|
|
222
|
-
})
|
|
223
|
-
|
|
224
|
-
it('should set tsconfig when typescript is enabled', () => {
|
|
225
|
-
const config = rolldownConfig({
|
|
226
|
-
file: 'lib/index.js',
|
|
227
|
-
format: 'es',
|
|
228
|
-
env: 'development',
|
|
229
|
-
platform: 'universal',
|
|
230
|
-
})
|
|
231
|
-
|
|
232
|
-
expect(config.tsconfig).toBe('tsconfig.json')
|
|
233
|
-
})
|
|
234
|
-
|
|
235
|
-
it('should skip tsconfig when typescript is disabled', () => {
|
|
236
|
-
mockConfig.typescript = false
|
|
237
|
-
|
|
238
|
-
const config = rolldownConfig({
|
|
239
|
-
file: 'lib/index.js',
|
|
240
|
-
format: 'es',
|
|
241
|
-
env: 'development',
|
|
242
|
-
platform: 'universal',
|
|
243
|
-
})
|
|
244
|
-
|
|
245
|
-
expect(config.tsconfig).toBeUndefined()
|
|
246
|
-
})
|
|
247
|
-
|
|
248
|
-
it('should swap globals in output', () => {
|
|
249
|
-
const config = rolldownConfig({
|
|
250
|
-
file: 'lib/index.js',
|
|
251
|
-
format: 'es',
|
|
252
|
-
env: 'development',
|
|
253
|
-
platform: 'universal',
|
|
254
|
-
})
|
|
255
|
-
|
|
256
|
-
expect(config.output.globals).toEqual({ React: 'react' })
|
|
257
|
-
})
|
|
258
|
-
|
|
259
|
-
it('should set correct dir and entryFileNames from file path', () => {
|
|
260
|
-
const config = rolldownConfig({
|
|
261
|
-
file: 'lib/esm/index.js',
|
|
262
|
-
format: 'es',
|
|
263
|
-
env: 'development',
|
|
264
|
-
platform: 'universal',
|
|
265
|
-
})
|
|
266
|
-
|
|
267
|
-
expect(config.output.dir).toBe('lib/esm')
|
|
268
|
-
expect(config.output.entryFileNames).toBe('index.js')
|
|
269
|
-
})
|
|
270
|
-
|
|
271
|
-
it('should handle file path without slash', () => {
|
|
272
|
-
const config = rolldownConfig({
|
|
273
|
-
file: 'bundle.js',
|
|
274
|
-
format: 'es',
|
|
275
|
-
env: 'development',
|
|
276
|
-
platform: 'universal',
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
expect(config.output.dir).toBe('.')
|
|
280
|
-
expect(config.output.entryFileNames).toBe('bundle.js')
|
|
281
|
-
})
|
|
282
|
-
})
|
|
283
|
-
|
|
284
|
-
describe('buildDts', () => {
|
|
285
|
-
beforeEach(() => {
|
|
286
|
-
Object.assign(mockConfig, defaultConfig)
|
|
287
|
-
Object.assign(mockPKG, defaultPKG)
|
|
288
|
-
})
|
|
289
|
-
|
|
290
|
-
it('should return DTS config when typescript and types are available', () => {
|
|
291
|
-
const result = buildDts()
|
|
292
|
-
|
|
293
|
-
expect(result).not.toBeNull()
|
|
294
|
-
expect(result?.file).toBe('./lib/index.d.ts')
|
|
295
|
-
expect(result?.input).toBe('src/index.ts')
|
|
296
|
-
expect(result?.tsconfig).toBe('tsconfig.json')
|
|
297
|
-
expect(result?.output.format).toBe('es')
|
|
298
|
-
})
|
|
299
|
-
|
|
300
|
-
it('should return null when typescript is disabled', () => {
|
|
301
|
-
mockConfig.typescript = false
|
|
302
|
-
|
|
303
|
-
expect(buildDts()).toBeNull()
|
|
304
|
-
})
|
|
305
|
-
|
|
306
|
-
it('should return null when no types path exists', () => {
|
|
307
|
-
mockPKG.exports = { import: './lib/index.js' }
|
|
308
|
-
delete mockPKG.types
|
|
309
|
-
delete mockPKG.typings
|
|
310
|
-
|
|
311
|
-
expect(buildDts()).toBeNull()
|
|
312
|
-
})
|
|
313
|
-
|
|
314
|
-
it('should use PKG.types as fallback', () => {
|
|
315
|
-
mockPKG.exports = {}
|
|
316
|
-
mockPKG.types = './lib/types.d.ts'
|
|
317
|
-
|
|
318
|
-
const result = buildDts()
|
|
319
|
-
|
|
320
|
-
expect(result?.file).toBe('./lib/types.d.ts')
|
|
321
|
-
})
|
|
322
|
-
|
|
323
|
-
it('should use PKG.typings as final fallback', () => {
|
|
324
|
-
mockPKG.exports = {}
|
|
325
|
-
delete mockPKG.types
|
|
326
|
-
mockPKG.typings = './lib/typings.d.ts'
|
|
327
|
-
|
|
328
|
-
const result = buildDts()
|
|
329
|
-
|
|
330
|
-
expect(result?.file).toBe('./lib/typings.d.ts')
|
|
331
|
-
})
|
|
332
|
-
|
|
333
|
-
it('should include external dependencies', () => {
|
|
334
|
-
const result = buildDts()
|
|
335
|
-
|
|
336
|
-
expect(result?.external).toContain('react')
|
|
337
|
-
expect(result?.external).toContain('react/jsx-runtime')
|
|
338
|
-
})
|
|
339
|
-
|
|
340
|
-
it('should handle types path without slash', () => {
|
|
341
|
-
mockPKG.exports = { types: 'index.d.ts' }
|
|
342
|
-
|
|
343
|
-
const result = buildDts()
|
|
344
|
-
|
|
345
|
-
expect(result?.output.dir).toBe('.')
|
|
346
|
-
expect(result?.output.entryFileNames).toBe('index.d.ts')
|
|
347
|
-
})
|
|
348
|
-
})
|