jiek 1.1.4 → 1.1.6
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/bin/jiek.js +1 -1
- package/dist/cli.cjs +120 -109
- package/dist/cli.d.cts +3 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.js +120 -109
- package/dist/cli.min.cjs +4 -4
- package/dist/cli.min.js +4 -4
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/rollup/index.cjs +23 -10
- package/dist/rollup/index.js +24 -11
- package/dist/rollup/index.min.cjs +4 -4
- package/dist/rollup/index.min.js +4 -4
- package/package.json +3 -3
- package/src/commands/build.ts +127 -110
- package/src/rollup/base.ts +4 -0
- package/src/rollup/index.ts +32 -7
- package/src/rollup/utils/externalResolver.ts +5 -1
- package/src/utils/filterSupport.ts +9 -4
package/package.json
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
{
|
2
2
|
"name": "jiek",
|
3
3
|
"type": "module",
|
4
|
-
"version": "1.1.
|
4
|
+
"version": "1.1.6",
|
5
5
|
"description": "YiJie's personal kits.",
|
6
6
|
"bin": {
|
7
7
|
"jiek": "bin/jiek.js",
|
@@ -61,8 +61,8 @@
|
|
61
61
|
"rollup": "^4.1.5",
|
62
62
|
"rollup-plugin-esbuild": "^6.1.0",
|
63
63
|
"typescript": "^5.0.0",
|
64
|
-
"@jiek/
|
65
|
-
"@jiek/
|
64
|
+
"@jiek/utils": "^0.2.2",
|
65
|
+
"@jiek/pkger": "^0.2.0"
|
66
66
|
},
|
67
67
|
"optionalDependencies": {
|
68
68
|
"@pnpm/filter-workspace-packages": "^7.2.13",
|
package/src/commands/build.ts
CHANGED
@@ -8,7 +8,8 @@ import { execaCommand } from 'execa'
|
|
8
8
|
|
9
9
|
import { actionDone, actionRestore } from '../inner'
|
10
10
|
import type { RollupProgressEvent, TemplateOptions } from '../rollup/base'
|
11
|
-
import {
|
11
|
+
import type { ProjectsGraph } from '../utils/filterSupport'
|
12
|
+
import { filterPackagesGraph } from '../utils/filterSupport'
|
12
13
|
import { loadConfig } from '../utils/loadConfig'
|
13
14
|
import { tsRegisterName } from '../utils/tsRegister'
|
14
15
|
|
@@ -40,138 +41,154 @@ program
|
|
40
41
|
.description(description)
|
41
42
|
.option('-s, --silent', "Don't display logs.")
|
42
43
|
.option('-e, --entries <ENTRIES>', "Specify the entries of the package.json's 'exports' field.(support glob)")
|
44
|
+
.option('--without-js', 'Do not output js files.')
|
45
|
+
.option('--without-dts', 'Do not output dts files.')
|
43
46
|
.option('-v, --verbose', 'Display debug logs.')
|
44
47
|
.action(async ({
|
45
48
|
silent,
|
46
49
|
entries,
|
47
|
-
verbose
|
50
|
+
verbose,
|
51
|
+
withoutJs,
|
52
|
+
withoutDts
|
48
53
|
}: {
|
49
54
|
silent: boolean
|
50
55
|
entries: string
|
51
56
|
verbose: boolean
|
57
|
+
withoutJs: boolean
|
58
|
+
withoutDts: boolean
|
52
59
|
}) => {
|
53
60
|
actionRestore()
|
54
61
|
const { build } = loadConfig()
|
55
62
|
silent = silent ?? build?.silent ?? false
|
56
|
-
const {
|
57
|
-
wd,
|
58
|
-
value = {}
|
59
|
-
} = await getSelectedProjectsGraph() ?? {}
|
60
|
-
|
61
|
-
if (Object.keys(value).length === 0) {
|
62
|
-
throw new Error('no package found')
|
63
|
-
}
|
64
|
-
const wdNodeModules = path.resolve(wd, 'node_modules')
|
65
|
-
if (!fs.existsSync(wdNodeModules)) {
|
66
|
-
fs.mkdirSync(wdNodeModules)
|
67
|
-
}
|
68
|
-
const jiekTempDir = (...paths: string[]) => path.resolve(wdNodeModules, '.jiek', ...paths)
|
69
|
-
if (!fs.existsSync(jiekTempDir())) {
|
70
|
-
fs.mkdirSync(jiekTempDir())
|
71
|
-
}
|
72
63
|
|
73
|
-
const rollupBinaryPath = require.resolve('rollup')
|
74
|
-
.replace(/dist\/rollup.js$/, 'dist/bin/rollup')
|
75
64
|
const multiBars = new MultiBar({
|
76
65
|
clearOnComplete: false,
|
77
66
|
hideCursor: true,
|
78
|
-
format: '- {bar} | {status} | {input} | {message}'
|
67
|
+
format: '- {bar} | {status} | {pkgName} | {input} | {message}'
|
79
68
|
}, Presets.shades_classic)
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
69
|
+
|
70
|
+
const buildPackage = async ({
|
71
|
+
wd,
|
72
|
+
value = {}
|
73
|
+
}: ProjectsGraph) => {
|
74
|
+
if (Object.keys(value).length === 0) {
|
75
|
+
throw new Error('no package found')
|
76
|
+
}
|
77
|
+
const wdNodeModules = path.resolve(wd, 'node_modules')
|
78
|
+
if (!fs.existsSync(wdNodeModules)) {
|
79
|
+
fs.mkdirSync(wdNodeModules)
|
80
|
+
}
|
81
|
+
const jiekTempDir = (...paths: string[]) => path.resolve(wdNodeModules, '.jiek', ...paths)
|
82
|
+
if (!fs.existsSync(jiekTempDir())) {
|
83
|
+
fs.mkdirSync(jiekTempDir())
|
84
|
+
}
|
85
|
+
|
86
|
+
const rollupBinaryPath = require.resolve('rollup')
|
87
|
+
.replace(/dist\/rollup.js$/, 'dist/bin/rollup')
|
88
|
+
let i = 0
|
89
|
+
await Promise.all(
|
90
|
+
Object.entries(value).map(async ([dir, manifest]) => {
|
91
|
+
// TODO support auto build child packages in workspaces
|
92
|
+
const escapeManifestName = manifest.name?.replace(/^@/g, '').replace(/\//g, '+')
|
93
|
+
const configFile = jiekTempDir(
|
94
|
+
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
95
|
+
)
|
96
|
+
fs.writeFileSync(configFile, FILE_TEMPLATE(manifest))
|
97
|
+
let prefix = ''
|
98
|
+
if (tsRegisterName) {
|
99
|
+
prefix = `node -r ${tsRegisterName} `
|
101
100
|
}
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
101
|
+
const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`
|
102
|
+
const child = execaCommand(command, {
|
103
|
+
ipc: true,
|
104
|
+
cwd: dir,
|
105
|
+
env: {
|
106
|
+
...process.env,
|
107
|
+
JIEK_ROOT: wd,
|
108
|
+
JIEK_ENTRIES: entries,
|
109
|
+
JIEK_WITHOUT_JS: String(withoutJs),
|
110
|
+
JIEK_WITHOUT_DTS: String(withoutDts)
|
111
|
+
}
|
112
|
+
})
|
113
|
+
const bars: Record<string, ReturnType<typeof multiBars.create>> = {}
|
114
|
+
let inputMaxLen = 10
|
115
|
+
child.on('message', (e: RollupProgressEvent) => {
|
116
|
+
if (e.type === 'debug') console.log(...(Array.isArray(e.data) ? e.data : [e.data]))
|
117
|
+
})
|
118
|
+
!silent && child.on('message', (e: RollupProgressEvent) => {
|
119
|
+
if (e.type === 'init') {
|
120
|
+
const { leafMap, targetsLength } = e.data
|
121
|
+
const leafs = Array
|
122
|
+
.from(leafMap.entries())
|
123
|
+
.flatMap(([input, pathAndCondiions]) =>
|
124
|
+
pathAndCondiions.map(([path, ...conditions]) => ({
|
125
|
+
input,
|
126
|
+
path,
|
127
|
+
conditions
|
128
|
+
}))
|
129
|
+
)
|
130
|
+
console.log(`Package '${manifest.name}' has ${targetsLength} targets to build`)
|
131
|
+
leafs.forEach(({ input }) => {
|
132
|
+
inputMaxLen = Math.max(inputMaxLen, input.length)
|
133
|
+
})
|
134
|
+
leafs.forEach(({ input, path }) => {
|
135
|
+
const key = `${input}:${path}`
|
136
|
+
if (bars[key]) return
|
137
|
+
bars[key] = multiBars.create(50, 0, {
|
138
|
+
pkgName: manifest.name,
|
139
|
+
input: input.padEnd(inputMaxLen),
|
140
|
+
status: 'waiting'.padEnd(10)
|
141
|
+
}, {
|
142
|
+
barsize: 20,
|
143
|
+
linewrap: true
|
144
|
+
})
|
133
145
|
})
|
146
|
+
}
|
147
|
+
if (e.type === 'progress') {
|
148
|
+
const {
|
149
|
+
path,
|
150
|
+
tags,
|
151
|
+
input,
|
152
|
+
event,
|
153
|
+
message
|
154
|
+
} = e.data
|
155
|
+
const bar = bars[`${input}:${path}`]
|
156
|
+
if (!bar) return
|
157
|
+
bar.update(
|
158
|
+
{
|
159
|
+
start: 0,
|
160
|
+
resolve: 20,
|
161
|
+
end: 50
|
162
|
+
}[event ?? 'start'] ?? 0,
|
163
|
+
{
|
164
|
+
input: input.padEnd(inputMaxLen),
|
165
|
+
status: event?.padEnd(10),
|
166
|
+
message: `${tags?.join(', ')}: ${message}`
|
167
|
+
}
|
168
|
+
)
|
169
|
+
}
|
170
|
+
})
|
171
|
+
await new Promise<void>((resolve, reject) => {
|
172
|
+
let errorStr = ''
|
173
|
+
child.stderr?.on('data', (data) => {
|
174
|
+
errorStr += data
|
134
175
|
})
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
input,
|
141
|
-
event,
|
142
|
-
message
|
143
|
-
} = e.data
|
144
|
-
const bar = bars[`${input}:${path}`]
|
145
|
-
if (!bar) return
|
146
|
-
bar.update(
|
147
|
-
{
|
148
|
-
start: 0,
|
149
|
-
resolve: 20,
|
150
|
-
end: 50
|
151
|
-
}[event ?? 'start'] ?? 0,
|
152
|
-
{
|
153
|
-
input: input.padEnd(inputMaxLen),
|
154
|
-
status: event?.padEnd(10),
|
155
|
-
message: `${tags?.join(', ')}: ${message}`
|
156
|
-
}
|
157
|
-
)
|
158
|
-
}
|
159
|
-
})
|
160
|
-
await new Promise<void>((resolve, reject) => {
|
161
|
-
let errorStr = ''
|
162
|
-
child.stderr?.on('data', (data) => {
|
163
|
-
errorStr += data
|
176
|
+
child.once('exit', (code) =>
|
177
|
+
code === 0
|
178
|
+
? resolve()
|
179
|
+
: reject(new Error(`rollup build failed:\n${errorStr}`)))
|
180
|
+
verbose && child.stdout?.pipe(process.stdout)
|
164
181
|
})
|
165
|
-
child.once('exit', (code) =>
|
166
|
-
code === 0
|
167
|
-
? resolve()
|
168
|
-
: reject(new Error(`rollup build failed:\n${errorStr}`)))
|
169
|
-
verbose && child.stdout?.pipe(process.stdout)
|
170
182
|
})
|
183
|
+
)
|
184
|
+
}
|
185
|
+
const filters: string[] = program.getOptionValue('filter').split(',')
|
186
|
+
const packages = await filterPackagesGraph(filters)
|
187
|
+
await Promise
|
188
|
+
.all(packages.map(buildPackage))
|
189
|
+
.finally(() => {
|
190
|
+
multiBars.stop()
|
171
191
|
})
|
172
|
-
).finally(() => {
|
173
|
-
multiBars.stop()
|
174
|
-
})
|
175
192
|
|
176
193
|
actionDone()
|
177
194
|
})
|
package/src/rollup/base.ts
CHANGED
@@ -15,6 +15,8 @@ export interface ConfigGenerateContext {
|
|
15
15
|
conditionals: string[]
|
16
16
|
}
|
17
17
|
|
18
|
+
export type OutputControl = boolean | ((context: ConfigGenerateContext) => boolean)
|
19
|
+
|
18
20
|
export interface TemplateOptions {
|
19
21
|
/**
|
20
22
|
* When the user configures type: module, the generated output from entry points that don't
|
@@ -39,6 +41,8 @@ export interface TemplateOptions {
|
|
39
41
|
dir?: Mapping2ROO<'dir'>
|
40
42
|
sourcemap?: Mapping2ROO<'sourcemap'>
|
41
43
|
strict?: Mapping2ROO<'strict'>
|
44
|
+
js?: OutputControl
|
45
|
+
dts?: OutputControl
|
42
46
|
}
|
43
47
|
plugins?:
|
44
48
|
| InputPluginOption
|
package/src/rollup/index.ts
CHANGED
@@ -33,13 +33,17 @@ interface PackageJSON {
|
|
33
33
|
|
34
34
|
const {
|
35
35
|
JIEK_ROOT,
|
36
|
-
JIEK_ENTRIES
|
36
|
+
JIEK_ENTRIES,
|
37
|
+
JIEK_WITHOUT_JS,
|
38
|
+
JIEK_WITHOUT_DTS
|
37
39
|
} = process.env
|
38
40
|
const WORKSPACE_ROOT = JIEK_ROOT ?? getWorkspaceDir()
|
39
41
|
const COMMON_OPTIONS = {} satisfies RollupOptions
|
40
42
|
const COMMON_PLUGINS = [
|
41
43
|
json()
|
42
44
|
]
|
45
|
+
const WITHOUT_JS = JIEK_WITHOUT_JS === 'true'
|
46
|
+
const WITHOUT_DTS = JIEK_WITHOUT_DTS === 'true'
|
43
47
|
|
44
48
|
const config = loadConfig({
|
45
49
|
root: WORKSPACE_ROOT
|
@@ -88,6 +92,22 @@ const resolveBuildPlugins = (context: ConfigGenerateContext, plugins: TemplateOp
|
|
88
92
|
return { js, dts }
|
89
93
|
}
|
90
94
|
|
95
|
+
const resolveOutputControls = (
|
96
|
+
context: ConfigGenerateContext,
|
97
|
+
output: TemplateOptions['output']
|
98
|
+
): { js: boolean; dts: boolean } => ({
|
99
|
+
js: typeof output?.js === 'boolean'
|
100
|
+
? output.js
|
101
|
+
: typeof output?.js === 'function'
|
102
|
+
? output.js(context)
|
103
|
+
: true,
|
104
|
+
dts: typeof output?.dts === 'boolean'
|
105
|
+
? output.dts
|
106
|
+
: typeof output?.dts === 'function'
|
107
|
+
? output.dts(context)
|
108
|
+
: true
|
109
|
+
})
|
110
|
+
|
91
111
|
const resolveWorkspacePath = (p: string) => resolve(WORKSPACE_ROOT, p)
|
92
112
|
|
93
113
|
const pascalCase = (str: string) =>
|
@@ -212,8 +232,10 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
212
232
|
}
|
213
233
|
const jsOutputSuffix = extname(output)
|
214
234
|
const tsOutputSuffix = jsOutputSuffix.replace(/(\.[cm]?)js$/, '.d$1ts')
|
215
|
-
|
216
|
-
|
235
|
+
const { js: jsOutput, dts: dtsOutput } = resolveOutputControls(context, build.output)
|
236
|
+
const rollupOptions: RollupOptions[] = []
|
237
|
+
if (jsOutput && !WITHOUT_JS) {
|
238
|
+
rollupOptions.push({
|
217
239
|
input: inputObj,
|
218
240
|
external,
|
219
241
|
output: [
|
@@ -268,8 +290,10 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
268
290
|
}),
|
269
291
|
jsPlugins
|
270
292
|
]
|
271
|
-
}
|
272
|
-
|
293
|
+
})
|
294
|
+
}
|
295
|
+
if (dtsOutput && !WITHOUT_DTS) {
|
296
|
+
rollupOptions.push({
|
273
297
|
input: inputObj,
|
274
298
|
external,
|
275
299
|
output: [
|
@@ -321,8 +345,9 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
321
345
|
}),
|
322
346
|
dtsPlugins
|
323
347
|
]
|
324
|
-
}
|
325
|
-
|
348
|
+
})
|
349
|
+
}
|
350
|
+
return rollupOptions
|
326
351
|
}
|
327
352
|
|
328
353
|
export function template(packageJSON: PackageJSON): RollupOptions[] {
|
@@ -1,4 +1,5 @@
|
|
1
1
|
import fs from 'node:fs'
|
2
|
+
import { builtinModules } from 'node:module'
|
2
3
|
|
3
4
|
const EXCLUDE_SUFFIX = [
|
4
5
|
'te?xt',
|
@@ -18,11 +19,14 @@ export default function(jsonOrPath: string | Record<string, unknown> = process.c
|
|
18
19
|
if (!name) {
|
19
20
|
throw new Error('package.json must have a name field')
|
20
21
|
}
|
22
|
+
|
21
23
|
const external = <(string | RegExp)[]> Object
|
22
24
|
.keys(dependencies)
|
23
25
|
.concat(Object.keys(peerDependencies))
|
24
26
|
.concat(Object.keys(optionalDependencies))
|
25
|
-
|
27
|
+
.concat(builtinModules)
|
28
|
+
|
29
|
+
return [...new Set(external)]
|
26
30
|
.map(dep => new RegExp(`^${dep}(/.*)?$`))
|
27
31
|
.concat([
|
28
32
|
new RegExp(`^${name}(/.*)?(?<!${EXCLUDE_SUFFIX.map(suffix => `\\.${suffix}`).join('|')})$`),
|
@@ -18,10 +18,10 @@ try {
|
|
18
18
|
} catch { /* empty */ }
|
19
19
|
if (type !== '') {
|
20
20
|
program
|
21
|
-
.option('-f, --filter <filter>', 'filter packages')
|
21
|
+
.option('-f, --filter <filter>', 'filter packages, support fuzzy match and array. e.g. -f core,utils')
|
22
22
|
}
|
23
23
|
|
24
|
-
interface ProjectsGraph {
|
24
|
+
export interface ProjectsGraph {
|
25
25
|
wd: string
|
26
26
|
root: string
|
27
27
|
value?: Record<string, {
|
@@ -31,8 +31,13 @@ interface ProjectsGraph {
|
|
31
31
|
}>
|
32
32
|
}
|
33
33
|
|
34
|
-
export
|
35
|
-
|
34
|
+
export function filterPackagesGraph(filters: string[]): Promise<ProjectsGraph[]> {
|
35
|
+
return Promise.all(filters.map(async filter => getSelectedProjectsGraph(filter)))
|
36
|
+
}
|
37
|
+
|
38
|
+
export async function getSelectedProjectsGraph(
|
39
|
+
filter = program.getOptionValue('filter')
|
40
|
+
): Promise<ProjectsGraph> {
|
36
41
|
const root = getRoot()
|
37
42
|
const { wd, notWorkspace } = getWD()
|
38
43
|
if (!notWorkspace && type === 'pnpm') {
|