Skip to content

Commit bcb24ac

Browse files
committed
refactor to ts
1 parent ab832b2 commit bcb24ac

32 files changed

+203
-323
lines changed

.ls-lint.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ ignore:
1313
- '**/*.test.{js,mjs,cjs,ts,cts,mts}'
1414
- packages/rollup-tests/test # Copied from rollup repo
1515
- 'crates/rolldown/tests/fixtures/**/_test.js' # `_test.js` is a special file, which will be treat as the entry file while executing the build output of fixture.
16-
- packages/rolldown/build.config.ts # convention name for using unbuild
17-
- packages/rolldown/vitest.config.ts
1816
- web/docs/.vitepress/cache # cache files generated by vitepress
1917
# FIXME: should not ignore following folders
2018
- web

cspell.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@
100100
"transpiling",
101101
"treeshake",
102102
"consola",
103-
"jiti",
104-
"JITI",
105103
"citty",
106104
"underfin",
107105
"UNKEYED",
Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1-
import { performance } from 'node:perf_hooks'
2-
import * as rolldown from 'rolldown'
1+
import { defineConfig } from 'rolldown'
32

4-
const start = performance.now()
5-
6-
const build = await rolldown.rolldown({
3+
export default defineConfig({
74
input: './index.js',
85
resolve: {
96
// This needs to be explicitly set for now because oxc resolver doesn't
@@ -12,7 +9,3 @@ const build = await rolldown.rolldown({
129
conditionNames: ['import'],
1310
},
1411
})
15-
16-
await build.write()
17-
18-
console.log(`bundled in ${(performance.now() - start).toFixed(2)}ms`)

packages/rolldown/bin/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
#!/usr/bin/env node
2-
import('../cli/main.js')
2+
import('../dist/cli.mjs')

packages/rolldown/build.config.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,21 @@ import nodePath from 'node:path'
55
import { globSync } from 'glob'
66

77
export default defineBuildConfig({
8-
entries: ['./src/index'],
8+
entries: [
9+
'./src/index',
10+
{
11+
builder: 'rollup',
12+
input: './src/cli/index',
13+
name: 'cli',
14+
},
15+
],
916
clean: true,
1017
declaration: true, // generate .d.ts files
1118
externals: [/rolldown-binding\..*\.node/, /@rolldown\/binding-.*/],
1219
rollup: {
1320
emitCJS: true,
1421
cjsBridge: true,
22+
inlineDependencies: true,
1523
},
1624
hooks: {
1725
'build:done'(_ctx) {
@@ -25,8 +33,8 @@ export default defineBuildConfig({
2533
// Move the binary file to dist
2634
binaryFiles.forEach((file) => {
2735
const fileName = nodePath.basename(file)
28-
console.log('Copying', file, 'to ./dist')
29-
nodeFs.copyFileSync(file, `./dist/${fileName}`)
36+
console.log('Copying', file, 'to ./dist/shared')
37+
nodeFs.copyFileSync(file, `./dist/shared/${fileName}`)
3038
})
3139
},
3240
},

packages/rolldown/cli/build.js

Lines changed: 0 additions & 74 deletions
This file was deleted.

packages/rolldown/cli/config.js

Lines changed: 0 additions & 70 deletions
This file was deleted.

packages/rolldown/cli/main.js

Lines changed: 0 additions & 46 deletions
This file was deleted.

packages/rolldown/package.json

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
"bin": {
2222
"rolldown": "./bin/cli.js"
2323
},
24-
"type": "module",
2524
"main": "./dist/index.cjs",
2625
"types": "./dist/index.d.ts",
2726
"exports": {
@@ -67,14 +66,11 @@
6766
"armv7-linux-androideabi"
6867
]
6968
},
70-
"dependencies": {
71-
"citty": "^0.1.6",
72-
"consola": "^3.2.3",
73-
"jiti": "^1.21.0"
74-
},
7569
"devDependencies": {
7670
"@napi-rs/cli": "^3.0.0-alpha.43",
71+
"citty": "^0.1.6",
7772
"colorette": "^2.0.20",
73+
"consola": "^3.2.3",
7874
"glob": "^10.3.10",
7975
"rollup": "^4.12.1",
8076
"type-fest": "^4.12.0",
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { performance } from 'node:perf_hooks'
2+
import consola from 'consola'
3+
import { colors } from 'consola/utils'
4+
import { RolldownOptions, rolldown } from '../../index'
5+
import { RolldownConfigExport } from '../../types/rolldown-config-export'
6+
import { arraify } from '../../utils'
7+
8+
export async function bundle(configExport: RolldownConfigExport) {
9+
const options = arraify(configExport)
10+
11+
for (const option of options) {
12+
await bundleInner(option)
13+
}
14+
}
15+
16+
async function bundleInner(options: RolldownOptions) {
17+
const start = performance.now()
18+
19+
const build = await rolldown(options)
20+
21+
const _output = await build.write(options?.output)
22+
23+
consola.log(
24+
`Finished in ${colors.bold((performance.now() - start).toFixed(2))} ms`,
25+
)
26+
}
File renamed without changes.

packages/rolldown/src/cli/index.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { defineCommand, runMain, showUsage } from 'citty'
2+
import consola from 'consola'
3+
import process from 'node:process'
4+
import path from 'node:path'
5+
import pkgJson from '../../package.json' assert { type: 'json' }
6+
import { loadConfig } from './utils.js'
7+
import { bundle } from './commands/bundle'
8+
9+
const main = defineCommand({
10+
meta: {
11+
name: 'rolldown',
12+
version: pkgJson.version,
13+
description: pkgJson.description,
14+
},
15+
args: {
16+
config: {
17+
type: 'string',
18+
alias: 'c',
19+
description:
20+
'Use this config file (if argument is used but value is unspecified, defaults to rolldown.config.js)',
21+
},
22+
help: {
23+
type: 'boolean',
24+
alias: 'h',
25+
description: 'Show this help message',
26+
},
27+
},
28+
async run(ctx) {
29+
if (ctx.args.help) {
30+
await showUsage(ctx.cmd)
31+
return
32+
}
33+
const cwd = process.cwd()
34+
let configPath
35+
if (ctx.args.config) {
36+
configPath = path.resolve(cwd, ctx.args.config)
37+
} else {
38+
configPath = path.resolve(cwd, 'rolldown.config.js')
39+
}
40+
41+
const config = await loadConfig(configPath)
42+
43+
if (!config) {
44+
consola.error(`No configuration found at ${configPath}`)
45+
process.exit(1)
46+
}
47+
48+
await bundle(config)
49+
},
50+
})
51+
52+
runMain(main)

0 commit comments

Comments
 (0)