jiek 2.2.6 → 2.2.7-alpha.1
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/build.cjs +2 -0
- package/bin/index.cjs +2 -0
- package/bin-helper/index.cjs +31 -0
- package/bin-helper/index.d.cts +1 -0
- package/bin-helper/index.d.ts +1 -0
- package/bin-helper/package.json +5 -1
- package/dist/.internal/+/bin/parseArgv.cjs +33 -0
- package/dist/.internal/+/bin/parseArgv.d.cts +5 -0
- package/dist/.internal/+/bin/parseArgv.d.ts +5 -0
- package/dist/.internal/+/bin/parseArgv.js +27 -0
- package/dist/.internal/+/bridge.cjs +12 -0
- package/dist/.internal/+/bridge.d.cts +39 -0
- package/dist/.internal/+/bridge.d.ts +39 -0
- package/dist/.internal/+/bridge.js +9 -0
- package/dist/.internal/+/commands/build/analyzer.cjs +201 -0
- package/dist/.internal/+/commands/build/analyzer.d.cts +30 -0
- package/dist/.internal/+/commands/build/analyzer.d.ts +30 -0
- package/dist/.internal/+/commands/build/analyzer.js +195 -0
- package/dist/.internal/+/commands/descriptions.cjs +21 -0
- package/dist/.internal/+/commands/descriptions.d.cts +5 -0
- package/dist/.internal/+/commands/descriptions.d.ts +5 -0
- package/dist/.internal/+/commands/descriptions.js +17 -0
- package/dist/.internal/+/commands/meta.cjs +16 -0
- package/dist/.internal/+/commands/meta.d.cts +3 -0
- package/dist/.internal/+/commands/meta.d.ts +3 -0
- package/dist/.internal/+/commands/meta.js +15 -0
- package/dist/.internal/+/commands/utils/optionParser.cjs +8 -0
- package/dist/.internal/+/commands/utils/optionParser.d.cts +3 -0
- package/dist/.internal/+/commands/utils/optionParser.d.ts +3 -0
- package/dist/.internal/+/commands/utils/optionParser.js +6 -0
- package/dist/.internal/+/rollup/base.cjs +10 -0
- package/dist/{cli-only-build.d.cts → .internal/+/rollup/base.d.cts} +8 -15
- package/dist/{cli-only-build.d.ts → .internal/+/rollup/base.d.ts} +8 -15
- package/dist/.internal/+/rollup/base.js +7 -0
- package/dist/.internal/+/rollup/bundle-analyzer.cjs +51 -0
- package/dist/.internal/+/rollup/bundle-analyzer.d.cts +92 -0
- package/dist/.internal/+/rollup/bundle-analyzer.d.ts +92 -0
- package/dist/.internal/+/rollup/bundle-analyzer.js +45 -0
- package/dist/.internal/+/server.cjs +33 -0
- package/dist/.internal/+/server.d.cts +8 -0
- package/dist/.internal/+/server.d.ts +8 -0
- package/dist/.internal/+/server.js +27 -0
- package/dist/.internal/+/utils/checkDependency.cjs +39 -0
- package/dist/.internal/+/utils/checkDependency.d.cts +3 -0
- package/dist/.internal/+/utils/checkDependency.d.ts +3 -0
- package/dist/.internal/+/utils/checkDependency.js +34 -0
- package/dist/.internal/+/utils/filterSupport.cjs +20 -0
- package/dist/.internal/+/utils/filterSupport.d.cts +15 -0
- package/dist/.internal/+/utils/filterSupport.d.ts +15 -0
- package/dist/.internal/+/utils/filterSupport.js +10 -0
- package/dist/.internal/+/utils/getInternalModuleName.cjs +5 -0
- package/dist/.internal/+/utils/getInternalModuleName.d.cts +3 -0
- package/dist/.internal/+/utils/getInternalModuleName.d.ts +3 -0
- package/dist/.internal/+/utils/getInternalModuleName.js +3 -0
- package/dist/.internal/+/utils/getRoot.cjs +17 -0
- package/dist/.internal/+/utils/getRoot.d.cts +3 -0
- package/dist/.internal/+/utils/getRoot.d.ts +3 -0
- package/dist/.internal/+/utils/getRoot.js +11 -0
- package/dist/.internal/+/utils/getWD.cjs +15 -0
- package/dist/.internal/+/utils/getWD.d.cts +6 -0
- package/dist/.internal/+/utils/getWD.d.ts +6 -0
- package/dist/.internal/+/utils/getWD.js +10 -0
- package/dist/.internal/+/utils/intersection.cjs +5 -0
- package/dist/.internal/+/utils/intersection.d.cts +3 -0
- package/dist/.internal/+/utils/intersection.d.ts +3 -0
- package/dist/.internal/+/utils/intersection.js +3 -0
- package/dist/.internal/+/utils/loadConfig.cjs +100 -0
- package/dist/.internal/+/utils/loadConfig.d.cts +10 -0
- package/dist/.internal/+/utils/loadConfig.d.ts +10 -0
- package/dist/.internal/+/utils/loadConfig.js +94 -0
- package/dist/.internal/+/utils/recursiveListFiles.cjs +19 -0
- package/dist/.internal/+/utils/recursiveListFiles.d.cts +3 -0
- package/dist/.internal/+/utils/recursiveListFiles.d.ts +3 -0
- package/dist/.internal/+/utils/recursiveListFiles.js +13 -0
- package/dist/.internal/+/utils/resolveExports.cjs +118 -0
- package/dist/.internal/+/utils/resolveExports.d.cts +26 -0
- package/dist/.internal/+/utils/resolveExports.d.ts +26 -0
- package/dist/.internal/+/utils/resolveExports.js +111 -0
- package/dist/.internal/+/utils/ts.cjs +68 -0
- package/dist/.internal/+/utils/ts.d.cts +3 -0
- package/dist/.internal/+/utils/ts.d.ts +3 -0
- package/dist/.internal/+/utils/ts.js +62 -0
- package/dist/.internal/+/utils/tsRegister.cjs +25 -0
- package/dist/.internal/+/utils/tsRegister.d.cts +3 -0
- package/dist/.internal/+/utils/tsRegister.d.ts +3 -0
- package/dist/.internal/+/utils/tsRegister.js +26 -0
- package/dist/.internal/getWD-BRJ3PK1S.js +105 -0
- package/dist/.internal/getWD-Cmxzjf-f.js +95 -0
- package/dist/{cli.js → .internal/index-B6RQz1DZ.js} +1 -735
- package/dist/{cli.cjs → .internal/index-DlHFuTjM.js} +1 -757
- package/dist/.internal/jiek_create-require-CWFWNQHj.js +5 -0
- package/dist/.internal/jiek_create-require-CxSGbkTB.js +5 -0
- package/dist/.internal/package.json +10 -0
- package/dist/bin/build.cjs +505 -0
- package/dist/bin/index.cjs +488 -0
- package/dist/index.d.cts +1 -113
- package/dist/index.d.ts +1 -113
- package/dist/rollup/index.cjs +282 -4569
- package/dist/rollup/index.d.cts +7 -1
- package/dist/rollup/index.d.ts +7 -1
- package/dist/rollup/index.js +270 -4554
- package/package.json +25 -28
- package/src/bin/build.cts +11 -0
- package/src/bin/index.cts +6 -0
- package/src/bridge.ts +1 -1
- package/src/commands/base.ts +3 -3
- package/src/commands/build/analyzer.ts +5 -5
- package/src/commands/build/client/analyzer.tsx +1 -1
- package/src/commands/build/client/index.ts +5 -7
- package/src/commands/build.ts +218 -209
- package/src/commands/meta.ts +1 -1
- package/src/commands/publish.ts +87 -25
- package/src/rollup/base.ts +2 -2
- package/src/rollup/index.ts +309 -115
- package/src/rollup/plugins/with-external.ts +23 -0
- package/src/rollup/utils/externalResolver.ts +20 -8
- package/src/utils/checkDependency.ts +1 -1
- package/src/utils/filterSupport.ts +17 -16
- package/src/utils/getInternalModuleName.ts +5 -0
- package/src/utils/intersection.ts +1 -0
- package/src/utils/{recusiveListFiles.ts → recursiveListFiles.ts} +2 -2
- package/src/utils/{getExports.ts → resolveExports.ts} +16 -14
- package/bin/jiek-build.js +0 -16
- package/bin/jiek.js +0 -13
- package/bin-helper.cjs +0 -43
- package/cli/package.json +0 -1
- package/cli-only-build/package.json +0 -1
- package/dist/cli-only-build.cjs +0 -977
- package/dist/cli-only-build.js +0 -969
- package/dist/cli.d.cts +0 -14
- package/dist/cli.d.ts +0 -14
- package/src/bin/build.ts +0 -0
- package/src/cli-only-build.ts +0 -11
- package/src/cli.ts +0 -6
- /package/{bin-helper.js → bin-helper/index.js} +0 -0
- /package/src/{parseArgv.ts → bin/parseArgv.ts} +0 -0
package/src/commands/build.ts
CHANGED
@@ -6,20 +6,21 @@ import { MultiBar, Presets } from 'cli-progress'
|
|
6
6
|
import { program } from 'commander'
|
7
7
|
import { execaCommand } from 'execa'
|
8
8
|
|
9
|
-
import type { RollupBuildEvent } from '#~/bridge
|
10
|
-
import type { AnalyzerBuildOptions } from '#~/commands/build/analyzer
|
11
|
-
import { registerAnalyzerCommandOptions, useAnalyzer } from '#~/commands/build/analyzer
|
12
|
-
import { entriesDescription, filterDescription, outdirDescription } from '#~/commands/descriptions
|
13
|
-
import { IS_WORKSPACE } from '#~/commands/meta
|
14
|
-
import { parseBoolean } from '#~/commands/utils/optionParser
|
15
|
-
import type { TemplateOptions } from '#~/rollup/base
|
16
|
-
import { BUILDER_TYPES, BUILDER_TYPE_PACKAGE_NAME_MAP } from '#~/rollup/base
|
17
|
-
import { createServer } from '#~/server
|
18
|
-
import { checkDependency } from '#~/utils/checkDependency
|
19
|
-
import type {
|
20
|
-
import { filterPackagesGraph, getSelectedProjectsGraph } from '#~/utils/filterSupport
|
21
|
-
import {
|
22
|
-
import {
|
9
|
+
import type { RollupBuildEvent } from '#~/bridge'
|
10
|
+
import type { AnalyzerBuildOptions } from '#~/commands/build/analyzer'
|
11
|
+
import { registerAnalyzerCommandOptions, useAnalyzer } from '#~/commands/build/analyzer'
|
12
|
+
import { entriesDescription, filterDescription, outdirDescription } from '#~/commands/descriptions'
|
13
|
+
import { IS_WORKSPACE } from '#~/commands/meta'
|
14
|
+
import { parseBoolean } from '#~/commands/utils/optionParser'
|
15
|
+
import type { TemplateOptions } from '#~/rollup/base'
|
16
|
+
import { BUILDER_TYPES, BUILDER_TYPE_PACKAGE_NAME_MAP } from '#~/rollup/base'
|
17
|
+
import { createServer } from '#~/server'
|
18
|
+
import { checkDependency } from '#~/utils/checkDependency'
|
19
|
+
import type { Manifest } from '#~/utils/filterSupport'
|
20
|
+
import { filterPackagesGraph, getSelectedProjectsGraph } from '#~/utils/filterSupport'
|
21
|
+
import { getWD } from '#~/utils/getWD'
|
22
|
+
import { loadConfig } from '#~/utils/loadConfig'
|
23
|
+
import { tsRegisterName } from '#~/utils/tsRegister'
|
23
24
|
|
24
25
|
declare module 'jiek' {
|
25
26
|
export interface Config {
|
@@ -38,7 +39,11 @@ const FILE_TEMPLATE = (manifest: unknown) => (`
|
|
38
39
|
module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
|
39
40
|
`.trimStart())
|
40
41
|
|
41
|
-
const
|
42
|
+
const ROLLUP_BIN = require
|
43
|
+
.resolve('rollup')
|
44
|
+
.replace(/dist\/rollup.js$/, 'dist/bin/rollup')
|
45
|
+
|
46
|
+
const isDefault = process.env.JIEK_BIN__FILENAME === 'build.cjs'
|
42
47
|
|
43
48
|
const description = `
|
44
49
|
Build the package according to the 'exports' field from the package.json.
|
@@ -102,6 +107,8 @@ interface BuildOptions extends AnalyzerBuildOptions {
|
|
102
107
|
* - ./tsconfig.dts.json
|
103
108
|
*/
|
104
109
|
dtsconfig?: string
|
110
|
+
|
111
|
+
'features.keepImportAttributes'?: boolean | 'assert'
|
105
112
|
}
|
106
113
|
|
107
114
|
let DEFAULT_BUILDER_TYPE: typeof BUILDER_TYPES[number]
|
@@ -143,7 +150,6 @@ let command = isDefault
|
|
143
150
|
command = command
|
144
151
|
.description(description)
|
145
152
|
.option('-t, --type <TYPE>', `The type of build, support ${BUILDER_TYPES.map(s => `"${s}"`).join(', ')}.`, v => {
|
146
|
-
// eslint-disable-next-line ts/no-unsafe-argument
|
147
153
|
if (!BUILDER_TYPES.includes(v as any)) {
|
148
154
|
throw new Error(`The value of 'type' must be ${BUILDER_TYPES.map(s => `"${s}"`).join(', ')}`)
|
149
155
|
}
|
@@ -173,6 +179,9 @@ command = command
|
|
173
179
|
parseBoolean
|
174
180
|
)
|
175
181
|
|
182
|
+
command = command
|
183
|
+
.option('--features.keepImportAttributes', 'Keep the import attributes in the output.')
|
184
|
+
|
176
185
|
command = command
|
177
186
|
.option('--tsconfig <TSCONFIG>', 'The path of the tsconfig file which is used to generate js and dts files.', String)
|
178
187
|
.option('--dtsconfig <DTSCONFIG>', 'The path of the tsconfig file which is used to generate dts files.', String)
|
@@ -277,6 +286,9 @@ command
|
|
277
286
|
JIEK_MINIFY_TYPE: minifyType,
|
278
287
|
JIEK_TSCONFIG: tsconfig,
|
279
288
|
JIEK_DTSCONFIG: dtsconfig,
|
289
|
+
JIEK_FEATURES: JSON.stringify({
|
290
|
+
keepImportAttributes: options['features.keepImportAttributes']
|
291
|
+
}),
|
280
292
|
...process.env
|
281
293
|
}
|
282
294
|
|
@@ -286,201 +298,196 @@ command
|
|
286
298
|
format: '- {bar} | {status} | {pkgName} | {input} | {message}'
|
287
299
|
}, Presets.shades_classic)
|
288
300
|
|
289
|
-
const
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
301
|
+
const { wd } = getWD()
|
302
|
+
const wdNodeModules = path.resolve(wd, 'node_modules')
|
303
|
+
if (!existsSync(wdNodeModules)) {
|
304
|
+
mkdirSync(wdNodeModules)
|
305
|
+
}
|
306
|
+
const resolveByJiekTemp = (...paths: string[]) => path.resolve(wdNodeModules, '.jiek', ...paths)
|
307
|
+
const jiekTemp = resolveByJiekTemp()
|
308
|
+
if (!existsSync(jiekTemp)) {
|
309
|
+
mkdirSync(jiekTemp)
|
310
|
+
}
|
311
|
+
|
312
|
+
let i = 0
|
313
|
+
const buildPackage = async ([pkgCWD, manifest]: [
|
314
|
+
string,
|
315
|
+
Manifest
|
316
|
+
], {
|
317
|
+
resolveByJiekTemp
|
318
|
+
}: {
|
319
|
+
resolveByJiekTemp: (...paths: string[]) => string
|
320
|
+
}) => {
|
321
|
+
if (manifest.name == null) {
|
322
|
+
throw new Error('package.json must have a name field')
|
295
323
|
}
|
296
|
-
|
297
|
-
|
298
|
-
|
324
|
+
|
325
|
+
// TODO support auto build child packages in workspaces
|
326
|
+
const escapeManifestName = manifest.name.replace(/^@/g, '').replace(/\//g, '+')
|
327
|
+
const configFile = resolveByJiekTemp(
|
328
|
+
`${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
|
329
|
+
)
|
330
|
+
writeFileSync(configFile, FILE_TEMPLATE(manifest))
|
331
|
+
const command = [ROLLUP_BIN, '--silent', '-c', configFile]
|
332
|
+
if (tsRegisterName != null) {
|
333
|
+
command.unshift(`node -r ${tsRegisterName}`)
|
299
334
|
}
|
300
|
-
|
301
|
-
|
302
|
-
if (!existsSync(jiekTemp)) {
|
303
|
-
try {
|
304
|
-
mkdirSync(jiekTemp)
|
305
|
-
} catch {}
|
335
|
+
if (watch) {
|
336
|
+
command.push('--watch')
|
306
337
|
}
|
307
|
-
|
308
|
-
const
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
JIEK_ROOT: wd
|
338
|
-
}
|
339
|
-
})
|
340
|
-
const bars: Record<string, ReturnType<typeof multiBars.create>> = {}
|
341
|
-
const times: Record<string, number> = {}
|
342
|
-
const locks: Record<string, boolean> = {}
|
343
|
-
let inputMaxLen = 10
|
344
|
-
child.on('message', (e: RollupBuildEvent) => {
|
345
|
-
if (
|
346
|
-
silent && [
|
347
|
-
'init',
|
348
|
-
'progress',
|
349
|
-
'watchChange'
|
350
|
-
].includes(e.type)
|
351
|
-
) return
|
352
|
-
switch (e.type) {
|
353
|
-
case 'init': {
|
354
|
-
const { leafMap, targetsLength } = e.data
|
355
|
-
const leafs = Array
|
356
|
-
.from(leafMap.entries())
|
357
|
-
.flatMap(([input, pathAndCondiions]) =>
|
358
|
-
pathAndCondiions.map(([path, ...conditions]) => ({
|
359
|
-
input,
|
360
|
-
path,
|
361
|
-
conditions
|
362
|
-
}))
|
363
|
-
)
|
364
|
-
let initMessage = `Package '${manifest.name}' has ${targetsLength} targets to build`
|
365
|
-
if (watch) {
|
366
|
-
initMessage += ' and watching...'
|
367
|
-
}
|
368
|
-
// eslint-disable-next-line no-console
|
369
|
-
console.log(initMessage)
|
370
|
-
leafs.forEach(({ input }) => {
|
371
|
-
inputMaxLen = Math.max(inputMaxLen, input.length)
|
372
|
-
})
|
373
|
-
leafs.forEach(({ input, path }) => {
|
374
|
-
const key = `${input}:${path}`
|
375
|
-
// eslint-disable-next-line ts/strict-boolean-expressions
|
376
|
-
if (bars[key]) return
|
377
|
-
bars[key] = multiBars.create(50, 0, {
|
378
|
-
pkgName: manifest.name,
|
379
|
-
input: input.padEnd(inputMaxLen + 5),
|
380
|
-
status: 'waiting'.padEnd(10)
|
381
|
-
}, {
|
382
|
-
barsize: 20,
|
383
|
-
linewrap: true
|
384
|
-
})
|
385
|
-
})
|
386
|
-
break
|
387
|
-
}
|
388
|
-
case 'progress': {
|
389
|
-
const {
|
390
|
-
path,
|
391
|
-
tags,
|
338
|
+
command.push(...passThroughOptions)
|
339
|
+
const child = execaCommand(command.join(' '), {
|
340
|
+
ipc: true,
|
341
|
+
cwd: pkgCWD,
|
342
|
+
windowsHide: true,
|
343
|
+
env: {
|
344
|
+
...env,
|
345
|
+
JIEK_NAME: manifest.name,
|
346
|
+
JIEK_ROOT: wd
|
347
|
+
}
|
348
|
+
})
|
349
|
+
const bars: Record<string, ReturnType<typeof multiBars.create>> = {}
|
350
|
+
const times: Record<string, number> = {}
|
351
|
+
const locks: Record<string, boolean> = {}
|
352
|
+
let inputMaxLen = 10
|
353
|
+
child.on('message', (e: RollupBuildEvent) => {
|
354
|
+
if (
|
355
|
+
silent && [
|
356
|
+
'init',
|
357
|
+
'progress',
|
358
|
+
'watchChange'
|
359
|
+
].includes(e.type)
|
360
|
+
) return
|
361
|
+
switch (e.type) {
|
362
|
+
case 'init': {
|
363
|
+
const { leafMap, targetsLength } = e.data
|
364
|
+
const leafs = Array
|
365
|
+
.from(leafMap.entries())
|
366
|
+
.flatMap(([input, pathAndConditions]) =>
|
367
|
+
pathAndConditions.map(([path, ...conditions]) => ({
|
392
368
|
input,
|
393
|
-
event,
|
394
|
-
message
|
395
|
-
} = e.data
|
396
|
-
const bar = bars[`${input}:${path}`]
|
397
|
-
// eslint-disable-next-line ts/strict-boolean-expressions
|
398
|
-
if (!bar) return
|
399
|
-
const time = times[`${input}:${path}`]
|
400
|
-
bar.update(
|
401
|
-
{
|
402
|
-
start: 0,
|
403
|
-
resolve: 20,
|
404
|
-
end: 50
|
405
|
-
}[event ?? 'start'] ?? 0,
|
406
|
-
{
|
407
|
-
input: (
|
408
|
-
time
|
409
|
-
? `${input}(x${time.toString().padStart(2, '0')})`
|
410
|
-
: input
|
411
|
-
).padEnd(inputMaxLen + 5),
|
412
|
-
status: event?.padEnd(10),
|
413
|
-
message: `${tags?.join(', ')}: ${message}`
|
414
|
-
}
|
415
|
-
)
|
416
|
-
break
|
417
|
-
}
|
418
|
-
case 'watchChange': {
|
419
|
-
const {
|
420
369
|
path,
|
421
|
-
|
422
|
-
}
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
|
427
|
-
let time = times[key] ?? 1
|
428
|
-
if (!locks[key]) {
|
429
|
-
time += 1
|
430
|
-
times[key] = time
|
431
|
-
setTimeout(() => {
|
432
|
-
locks[key] = false
|
433
|
-
}, 100)
|
434
|
-
bar.update(0, {
|
435
|
-
input: `${input}(x${time.toString().padStart(2, '0')})`.padEnd(inputMaxLen + 5),
|
436
|
-
status: 'watching'.padEnd(10),
|
437
|
-
message: 'watching...'
|
438
|
-
})
|
439
|
-
}
|
440
|
-
locks[key] = true
|
441
|
-
break
|
442
|
-
}
|
443
|
-
case 'modulesAnalyze': {
|
444
|
-
const {
|
445
|
-
data: {
|
446
|
-
type,
|
447
|
-
modules: pkgModules
|
448
|
-
}
|
449
|
-
} = e
|
450
|
-
void refreshAnalyzer(
|
451
|
-
pkgCWD,
|
452
|
-
pkgModules.map(m => ({
|
453
|
-
...m,
|
454
|
-
type,
|
455
|
-
filename: `${manifest.name}/${m.filename}`,
|
456
|
-
label: `${manifest.name}/${m.label}`
|
457
|
-
}))
|
458
|
-
)
|
459
|
-
break
|
460
|
-
}
|
461
|
-
case 'debug': {
|
462
|
-
// eslint-disable-next-line no-console,ts/no-unsafe-argument
|
463
|
-
console.log(...(Array.isArray(e.data) ? e.data : [e.data]))
|
464
|
-
break
|
465
|
-
}
|
466
|
-
default:
|
370
|
+
conditions
|
371
|
+
}))
|
372
|
+
)
|
373
|
+
let initMessage = `Package '${manifest.name}' has ${targetsLength} targets to build`
|
374
|
+
if (watch) {
|
375
|
+
initMessage += ' and watching...'
|
467
376
|
}
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
+ `cwd: ${pkgCWD}\n\n`
|
473
|
-
child.stderr?.on('data', (data) => {
|
474
|
-
errorStr += data
|
377
|
+
// eslint-disable-next-line no-console
|
378
|
+
console.log(initMessage)
|
379
|
+
leafs.forEach(({ input }) => {
|
380
|
+
inputMaxLen = Math.max(inputMaxLen, input.length)
|
475
381
|
})
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
382
|
+
leafs.forEach(({ input, path }) => {
|
383
|
+
const key = `${input}:${path}`
|
384
|
+
// eslint-disable-next-line ts/strict-boolean-expressions
|
385
|
+
if (bars[key]) return
|
386
|
+
bars[key] = multiBars.create(50, 0, {
|
387
|
+
pkgName: manifest.name,
|
388
|
+
input: input.padEnd(inputMaxLen + 5),
|
389
|
+
status: 'waiting'.padEnd(10)
|
390
|
+
}, {
|
391
|
+
barsize: 20,
|
392
|
+
linewrap: true
|
393
|
+
})
|
394
|
+
})
|
395
|
+
break
|
396
|
+
}
|
397
|
+
case 'progress': {
|
398
|
+
const {
|
399
|
+
path,
|
400
|
+
tags,
|
401
|
+
input,
|
402
|
+
event,
|
403
|
+
message
|
404
|
+
} = e.data
|
405
|
+
const bar = bars[`${input}:${path}`]
|
406
|
+
// eslint-disable-next-line ts/strict-boolean-expressions
|
407
|
+
if (!bar) return
|
408
|
+
const time = times[`${input}:${path}`]
|
409
|
+
bar.update(
|
410
|
+
{
|
411
|
+
start: 0,
|
412
|
+
resolve: 20,
|
413
|
+
end: 50
|
414
|
+
}[event ?? 'start'] ?? 0,
|
415
|
+
{
|
416
|
+
input: (
|
417
|
+
time
|
418
|
+
? `${input}(x${time.toString().padStart(2, '0')})`
|
419
|
+
: input
|
420
|
+
).padEnd(inputMaxLen + 5),
|
421
|
+
status: event?.padEnd(10),
|
422
|
+
message: `${tags?.join(', ')}: ${message}`
|
423
|
+
}
|
424
|
+
)
|
425
|
+
break
|
426
|
+
}
|
427
|
+
case 'watchChange': {
|
428
|
+
const {
|
429
|
+
path,
|
430
|
+
input
|
431
|
+
} = e.data
|
432
|
+
const key = `${input}:${path}`
|
433
|
+
const bar = bars[key]
|
434
|
+
// eslint-disable-next-line ts/strict-boolean-expressions
|
435
|
+
if (!bar) return
|
436
|
+
let time = times[key] ?? 1
|
437
|
+
if (!locks[key]) {
|
438
|
+
time += 1
|
439
|
+
times[key] = time
|
440
|
+
setTimeout(() => {
|
441
|
+
locks[key] = false
|
442
|
+
}, 100)
|
443
|
+
bar.update(0, {
|
444
|
+
input: `${input}(x${time.toString().padStart(2, '0')})`.padEnd(inputMaxLen + 5),
|
445
|
+
status: 'watching'.padEnd(10),
|
446
|
+
message: 'watching...'
|
447
|
+
})
|
448
|
+
}
|
449
|
+
locks[key] = true
|
450
|
+
break
|
451
|
+
}
|
452
|
+
case 'modulesAnalyze': {
|
453
|
+
const {
|
454
|
+
data: {
|
455
|
+
type,
|
456
|
+
modules: pkgModules
|
457
|
+
}
|
458
|
+
} = e
|
459
|
+
void refreshAnalyzer(
|
460
|
+
pkgCWD,
|
461
|
+
pkgModules.map(m => ({
|
462
|
+
...m,
|
463
|
+
type,
|
464
|
+
filename: `${manifest.name}/${m.filename}`,
|
465
|
+
label: `${manifest.name}/${m.label}`
|
466
|
+
}))
|
467
|
+
)
|
468
|
+
break
|
469
|
+
}
|
470
|
+
case 'debug': {
|
471
|
+
// eslint-disable-next-line no-console,ts/no-unsafe-argument
|
472
|
+
console.log(...(Array.isArray(e.data) ? e.data : [e.data]))
|
473
|
+
break
|
474
|
+
}
|
475
|
+
default:
|
476
|
+
}
|
477
|
+
})
|
478
|
+
await new Promise<void>((resolve, reject) => {
|
479
|
+
let errorStr = `rollup build failed\n`
|
480
|
+
+ `package name: ${manifest.name}\n`
|
481
|
+
+ `cwd: ${pkgCWD}\n\n`
|
482
|
+
child.stderr?.on('data', (data) => {
|
483
|
+
errorStr += data
|
482
484
|
})
|
483
|
-
|
485
|
+
child.once('exit', (code) =>
|
486
|
+
code === 0
|
487
|
+
? resolve()
|
488
|
+
: reject(new Error(errorStr)))
|
489
|
+
verbose && child.stdout?.pipe(process.stdout)
|
490
|
+
})
|
484
491
|
}
|
485
492
|
|
486
493
|
const commandFilters = IS_WORKSPACE ? commandFiltersOrEntries : undefined
|
@@ -499,12 +506,14 @@ command
|
|
499
506
|
])
|
500
507
|
]
|
501
508
|
try {
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
509
|
+
const packages = (
|
510
|
+
filters.length > 0
|
511
|
+
? await filterPackagesGraph(filters)
|
512
|
+
: [await getSelectedProjectsGraph()]
|
513
|
+
).flatMap(({ value }) => Object.entries(value ?? {}))
|
514
|
+
await Promise.allSettled(
|
515
|
+
packages.map(async ([cwd, manifest]) => buildPackage([cwd, manifest], { resolveByJiekTemp }))
|
516
|
+
)
|
508
517
|
} finally {
|
509
518
|
multiBars.stop()
|
510
519
|
// eslint-disable-next-line no-console
|
package/src/commands/meta.ts
CHANGED
package/src/commands/publish.ts
CHANGED
@@ -7,12 +7,16 @@ import process from 'node:process'
|
|
7
7
|
import { type BumperType, TAGS, bump } from '@jiek/utils/bumper'
|
8
8
|
import { program } from 'commander'
|
9
9
|
import detectIndent from 'detect-indent'
|
10
|
+
import type { JSONPath } from 'jsonc-parser'
|
10
11
|
import { applyEdits, modify } from 'jsonc-parser'
|
11
12
|
|
12
|
-
import type { ProjectsGraph } from '
|
13
|
-
import { getSelectedProjectsGraph } from '
|
14
|
-
import {
|
15
|
-
import {
|
13
|
+
import type { ProjectsGraph } from '#~/utils/filterSupport'
|
14
|
+
import { getSelectedProjectsGraph } from '#~/utils/filterSupport'
|
15
|
+
import { loadConfig } from '#~/utils/loadConfig'
|
16
|
+
import type { ResolveExportsOptions } from '#~/utils/resolveExports'
|
17
|
+
import { resolveExports } from '#~/utils/resolveExports'
|
18
|
+
|
19
|
+
import { getInternalModuleName } from '#~/utils/getInternalModuleName'
|
16
20
|
import { outdirDescription } from './descriptions'
|
17
21
|
|
18
22
|
declare module 'jiek' {
|
@@ -108,27 +112,44 @@ async function prepublish({ bumper }: {
|
|
108
112
|
)
|
109
113
|
|
110
114
|
const generateNewManifest = (dir: string, manifest: NonNullable<ProjectsGraph['value']>[string]) => {
|
111
|
-
const {
|
115
|
+
const {
|
116
|
+
name,
|
117
|
+
type,
|
118
|
+
exports: entrypoints = {},
|
119
|
+
imports: internalEntrypoints = {}
|
120
|
+
} = manifest
|
112
121
|
if (!name) {
|
113
122
|
throw new Error(`package.json in ${dir} must have a name field`)
|
114
123
|
}
|
115
124
|
|
116
125
|
const pkgIsModule = type === 'module'
|
117
126
|
const newManifest = { ...manifest }
|
118
|
-
const
|
119
|
-
entrypoints,
|
127
|
+
const commonOptions = {
|
120
128
|
pkgIsModule,
|
121
129
|
pkgName: name,
|
122
130
|
config: loadConfig(dir),
|
123
131
|
dir,
|
124
|
-
defaultOutdir: outdir,
|
125
132
|
noFilter: true,
|
126
133
|
isPublish: true
|
134
|
+
} satisfies Partial<ResolveExportsOptions>
|
135
|
+
const [resolvedEntrypoints, exports, resolvedOutdir] = resolveExports({
|
136
|
+
entrypoints,
|
137
|
+
defaultOutdir: outdir,
|
138
|
+
...commonOptions
|
127
139
|
})
|
128
140
|
newManifest.exports = {
|
129
141
|
...resolvedEntrypoints,
|
130
142
|
...exports
|
131
143
|
}
|
144
|
+
const [resolvedInternalEntrypoints, imports] = resolveExports({
|
145
|
+
entrypoints: internalEntrypoints,
|
146
|
+
defaultOutdir: `${outdir}/.internal`,
|
147
|
+
...commonOptions
|
148
|
+
})
|
149
|
+
newManifest.imports = {
|
150
|
+
...resolvedInternalEntrypoints,
|
151
|
+
...imports
|
152
|
+
}
|
132
153
|
return [newManifest, resolvedOutdir] as const
|
133
154
|
}
|
134
155
|
|
@@ -146,26 +167,33 @@ async function prepublish({ bumper }: {
|
|
146
167
|
insertSpaces: boolean
|
147
168
|
}
|
148
169
|
}) => {
|
170
|
+
const internalModuleName = getInternalModuleName(manifest.name!)
|
171
|
+
|
149
172
|
let newJSONString = oldJSONString
|
150
|
-
|
151
|
-
newJSONString
|
152
|
-
modify(
|
173
|
+
const update = (path: JSONPath, value: unknown) => {
|
174
|
+
newJSONString = applyEdits(
|
153
175
|
newJSONString,
|
154
|
-
|
155
|
-
{
|
156
|
-
'<5.0': {
|
157
|
-
'*': [
|
158
|
-
'*',
|
159
|
-
`./*`,
|
160
|
-
`./*/index.d.ts`,
|
161
|
-
`./*/index.d.mts`,
|
162
|
-
`./*/index.d.cts`
|
163
|
-
]
|
164
|
-
}
|
165
|
-
},
|
166
|
-
{ formattingOptions }
|
176
|
+
modify(newJSONString, path, value, { formattingOptions })
|
167
177
|
)
|
168
|
-
|
178
|
+
}
|
179
|
+
|
180
|
+
update(['publishConfig', 'typesVersions'], {
|
181
|
+
'<5.0': {
|
182
|
+
'*': [
|
183
|
+
'*',
|
184
|
+
'./*',
|
185
|
+
'./*/index.d.ts',
|
186
|
+
'./*/index.d.mts',
|
187
|
+
'./*/index.d.cts'
|
188
|
+
]
|
189
|
+
}
|
190
|
+
})
|
191
|
+
update(['dependencies', internalModuleName], `file:./${outdir}/.internal`)
|
192
|
+
update(['dependenciesMeta', internalModuleName], {
|
193
|
+
'injected': true
|
194
|
+
})
|
195
|
+
update(['imports'], undefined)
|
196
|
+
|
169
197
|
for (const [key, value] of Object.entries(manifest)) {
|
170
198
|
if (key === 'version') continue
|
171
199
|
if (JSON.stringify(value) === JSON.stringify(oldJSON[key])) continue
|
@@ -207,9 +235,13 @@ async function prepublish({ bumper }: {
|
|
207
235
|
const indexExports = index as Record<string, string>
|
208
236
|
indexPublishConfig.main = indexExports.require ?? indexExports.default
|
209
237
|
indexPublishConfig.module = indexExports.import ?? indexExports.module ?? indexExports.default
|
238
|
+
indexPublishConfig.types = indexExports.types
|
210
239
|
break
|
211
240
|
}
|
212
241
|
}
|
242
|
+
indexPublishConfig.types = indexPublishConfig[
|
243
|
+
manifest?.type === 'module' ? 'module' : 'main'
|
244
|
+
].replace(/\.([cm]?)js$/, '.d.$1ts')
|
213
245
|
for (const [k, v] of Object.entries(indexPublishConfig)) {
|
214
246
|
if (v === undefined) continue
|
215
247
|
newJSONString = applyEdits(
|
@@ -434,6 +466,36 @@ async function prepublish({ bumper }: {
|
|
434
466
|
}
|
435
467
|
throw new Error(`file type of ${path} is not supported`)
|
436
468
|
}
|
469
|
+
|
470
|
+
if ('imports' in manifest && manifest.imports) {
|
471
|
+
Object
|
472
|
+
.entries(manifest.imports)
|
473
|
+
.forEach(([key, value]) => {
|
474
|
+
if (typeof value !== 'object') return
|
475
|
+
const [start] = key.split('*')
|
476
|
+
manifest.imports![key] = JSON.parse(
|
477
|
+
JSON
|
478
|
+
.stringify(value)
|
479
|
+
.replaceAll(`${resolvedOutdir}/.internal/`, start)
|
480
|
+
)
|
481
|
+
})
|
482
|
+
fs.writeFileSync(
|
483
|
+
resolveByDir(resolvedOutdir, resolvedOutdir, '.internal', 'package.json'),
|
484
|
+
JSON.stringify(
|
485
|
+
{
|
486
|
+
name: getInternalModuleName(manifest.name!),
|
487
|
+
exports: JSON.parse(
|
488
|
+
JSON
|
489
|
+
.stringify(manifest.imports)
|
490
|
+
.replaceAll('#', './')
|
491
|
+
.replaceAll('~', '+')
|
492
|
+
) as Record<string, unknown>
|
493
|
+
},
|
494
|
+
null,
|
495
|
+
2
|
496
|
+
)
|
497
|
+
)
|
498
|
+
}
|
437
499
|
})
|
438
500
|
}
|
439
501
|
|
package/src/rollup/base.ts
CHANGED
@@ -54,9 +54,9 @@ export interface TemplateOptions {
|
|
54
54
|
* When use esbuild type builder, it will inject `supported.import-attributes` option.
|
55
55
|
* When use swc type builder, it will inject `jsc.experimental.keepImportAttributes` option.
|
56
56
|
*
|
57
|
-
* And it will auto set the rollup output externalImportAttributes and importAttributesKey options.
|
57
|
+
* And it will auto set the rollup output `externalImportAttributes` and `importAttributesKey` options.
|
58
58
|
*
|
59
|
-
* @default
|
59
|
+
* @default false
|
60
60
|
*/
|
61
61
|
keepImportAttributes?: boolean | 'assert'
|
62
62
|
}
|