@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/src/scripts/build.ts
DELETED
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { cpSync, mkdirSync, readdirSync, renameSync, statSync } from 'node:fs'
|
|
2
|
-
import { join } from 'node:path'
|
|
3
|
-
import chalk from 'chalk'
|
|
4
|
-
import { rimraf } from 'rimraf'
|
|
5
|
-
import { rolldown } from 'rolldown'
|
|
6
|
-
import { CONFIG, PKG } from '../config/index.js'
|
|
7
|
-
import {
|
|
8
|
-
buildAllDts,
|
|
9
|
-
createBuildPipeline,
|
|
10
|
-
config as rolldownConfig,
|
|
11
|
-
} from '../rolldown/index.js'
|
|
12
|
-
|
|
13
|
-
const { log } = console
|
|
14
|
-
const allBuilds = createBuildPipeline()
|
|
15
|
-
const allBuildsCount = allBuilds.length
|
|
16
|
-
|
|
17
|
-
const FORMAT_LABEL: Record<string, string> = {
|
|
18
|
-
cjs: 'CJS',
|
|
19
|
-
es: 'ESM',
|
|
20
|
-
umd: 'UMD',
|
|
21
|
-
iife: 'IIFE',
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const label = (text: string) => chalk.bold.bgCyan.black(` ${text} `)
|
|
25
|
-
const dim = chalk.dim
|
|
26
|
-
const bold = chalk.bold
|
|
27
|
-
|
|
28
|
-
async function build({
|
|
29
|
-
inputOptions,
|
|
30
|
-
outputOptions,
|
|
31
|
-
}: {
|
|
32
|
-
inputOptions: any
|
|
33
|
-
outputOptions: any
|
|
34
|
-
}) {
|
|
35
|
-
const bundle = await rolldown(inputOptions)
|
|
36
|
-
await bundle.write(outputOptions)
|
|
37
|
-
await bundle.close()
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const createBuilds = async () => {
|
|
41
|
-
let p = Promise.resolve()
|
|
42
|
-
|
|
43
|
-
allBuilds.forEach((item: Record<string, any>) => {
|
|
44
|
-
const { output, ...input } = rolldownConfig(item)
|
|
45
|
-
const format = FORMAT_LABEL[output.format] || output.format
|
|
46
|
-
p = p.then(() => {
|
|
47
|
-
const start = performance.now()
|
|
48
|
-
|
|
49
|
-
return build({ inputOptions: input, outputOptions: output })
|
|
50
|
-
.then(() => {
|
|
51
|
-
const duration = Math.round(performance.now() - start)
|
|
52
|
-
log(
|
|
53
|
-
` ${chalk.green('+')} ${bold(format)} ${dim('->')} ${dim(`${output.dir}/${output.entryFileNames}`)} ${dim(`(${duration}ms)`)}`,
|
|
54
|
-
)
|
|
55
|
-
})
|
|
56
|
-
.catch((e) => {
|
|
57
|
-
log(`\n${chalk.bold.red('Build failed')}`)
|
|
58
|
-
log(chalk.gray(` Format: ${format}`))
|
|
59
|
-
log(chalk.gray(` File: ${output.dir}/${output.entryFileNames}`))
|
|
60
|
-
log(e)
|
|
61
|
-
throw e
|
|
62
|
-
})
|
|
63
|
-
})
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
return p
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const copyStaticFiles = () => {
|
|
70
|
-
if (!Array.isArray(CONFIG.copyFiles) || CONFIG.copyFiles.length === 0) return
|
|
71
|
-
|
|
72
|
-
log(`\n${dim('Copying')} static files...\n`)
|
|
73
|
-
for (const { from, to } of CONFIG.copyFiles as {
|
|
74
|
-
from: string
|
|
75
|
-
to: string
|
|
76
|
-
}[]) {
|
|
77
|
-
cpSync(from, to, { recursive: true })
|
|
78
|
-
log(` ${chalk.green('+')} ${dim(from)} ${dim('->')} ${dim(to)}`)
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Build a single DTS entry in an isolated temp directory, then move the
|
|
84
|
-
* largest .d.ts file (the real declarations) to the final output path.
|
|
85
|
-
*
|
|
86
|
-
* Rolldown code-splits DTS output: the entry file is a tiny re-export stub,
|
|
87
|
-
* and the actual types go into a chunk. Building into a temp dir avoids
|
|
88
|
-
* collisions when multiple DTS entries share the same output directory.
|
|
89
|
-
*/
|
|
90
|
-
const buildDtsIsolated = async (
|
|
91
|
-
dtsConfig: ReturnType<typeof buildAllDts>[number],
|
|
92
|
-
) => {
|
|
93
|
-
const { output, file, ...input } = dtsConfig
|
|
94
|
-
const finalDir = output.dir as string
|
|
95
|
-
const entryName = output.entryFileNames as string
|
|
96
|
-
const tempDir = join(finalDir, `__dts_tmp_${entryName.replace(/\W/g, '_')}`)
|
|
97
|
-
|
|
98
|
-
// Build into isolated temp directory
|
|
99
|
-
const tempOutput = { ...output, dir: tempDir }
|
|
100
|
-
await build({ inputOptions: input, outputOptions: tempOutput })
|
|
101
|
-
|
|
102
|
-
// Find the largest .d.ts file — that's the real declarations
|
|
103
|
-
const absTempDir = join(process.cwd(), tempDir)
|
|
104
|
-
const dtsFiles = readdirSync(absTempDir).filter((f) => f.endsWith('.d.ts'))
|
|
105
|
-
|
|
106
|
-
let bestFile = dtsFiles[0] || entryName
|
|
107
|
-
let bestSize = 0
|
|
108
|
-
for (const f of dtsFiles) {
|
|
109
|
-
const size = statSync(join(absTempDir, f)).size
|
|
110
|
-
if (size > bestSize) {
|
|
111
|
-
bestSize = size
|
|
112
|
-
bestFile = f
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
// Move the best file to the final location
|
|
117
|
-
const absFinalDir = join(process.cwd(), finalDir)
|
|
118
|
-
mkdirSync(absFinalDir, { recursive: true })
|
|
119
|
-
renameSync(join(absTempDir, bestFile), join(absFinalDir, entryName))
|
|
120
|
-
|
|
121
|
-
// Move sourcemap if it exists
|
|
122
|
-
const mapName = `${bestFile}.map`
|
|
123
|
-
try {
|
|
124
|
-
renameSync(join(absTempDir, mapName), join(absFinalDir, `${entryName}.map`))
|
|
125
|
-
} catch {
|
|
126
|
-
// sourcemap may not exist
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// Clean up temp directory
|
|
130
|
-
rimraf.sync(absTempDir)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
const generateDeclarations = async () => {
|
|
134
|
-
const dtsConfigs = buildAllDts()
|
|
135
|
-
if (dtsConfigs.length === 0) return
|
|
136
|
-
|
|
137
|
-
log(`\n${dim('Generating')} declarations...`)
|
|
138
|
-
|
|
139
|
-
for (const dtsFile of dtsConfigs) {
|
|
140
|
-
const tscStart = performance.now()
|
|
141
|
-
await buildDtsIsolated(dtsFile)
|
|
142
|
-
|
|
143
|
-
const tscDuration = Math.round(performance.now() - tscStart)
|
|
144
|
-
log(
|
|
145
|
-
` ${chalk.green('+')} ${bold('DTS')} ${dim('->')} ${dim(dtsFile.file)} ${dim(`(${tscDuration}ms)`)}`,
|
|
146
|
-
)
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
const runBuild = async () => {
|
|
151
|
-
const start = performance.now()
|
|
152
|
-
|
|
153
|
-
log(
|
|
154
|
-
`\n${label('rolldown')} ${bold(PKG.name || '')} ${dim(`v${PKG.version || '0.0.0'}`)}\n`,
|
|
155
|
-
)
|
|
156
|
-
|
|
157
|
-
log(`${dim('Cleaning')} ${CONFIG.outputDir}/`)
|
|
158
|
-
rimraf.sync(`${process.cwd()}/${CONFIG.outputDir}`)
|
|
159
|
-
|
|
160
|
-
log(
|
|
161
|
-
`${dim('Building')} ${bold(String(allBuildsCount))} bundle${allBuildsCount > 1 ? 's' : ''}...\n`,
|
|
162
|
-
)
|
|
163
|
-
|
|
164
|
-
await createBuilds()
|
|
165
|
-
copyStaticFiles()
|
|
166
|
-
await generateDeclarations()
|
|
167
|
-
|
|
168
|
-
const total = Math.round(performance.now() - start)
|
|
169
|
-
log(`\n${chalk.green('Done')} ${dim(`in ${total}ms`)}\n`)
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export { runBuild }
|
package/tsconfig.json
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "@vitus-labs/tools-typescript/lib",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"noEmit": false,
|
|
5
|
-
"outDir": "lib",
|
|
6
|
-
"rootDir": "src",
|
|
7
|
-
"baseUrl": ".",
|
|
8
|
-
"declarationDir": "./lib/types",
|
|
9
|
-
"paths": {
|
|
10
|
-
"~/*": ["src/*"]
|
|
11
|
-
}
|
|
12
|
-
},
|
|
13
|
-
"include": ["typings", "src"],
|
|
14
|
-
"exclude": ["node_modules", "__stories__", "lib", "**/*.test.ts"]
|
|
15
|
-
}
|
package/vitest.config.ts
DELETED