jiek 2.1.12 → 2.1.13
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/dist/cli-only-build.cjs +221 -96
- package/dist/cli-only-build.js +221 -97
- package/dist/rollup/index.cjs +75 -94
- package/dist/rollup/index.js +76 -95
- package/package.json +13 -2
- package/src/bridge.ts +42 -0
- package/src/commands/build.ts +207 -99
- package/src/rollup/base.ts +0 -35
- package/src/rollup/bundle-analyzer.ts +62 -0
- package/src/rollup/index.ts +43 -117
- package/src/server.ts +22 -0
package/src/rollup/index.ts
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
/* eslint-disable ts/strict-boolean-expressions */
|
2
2
|
import fs from 'node:fs'
|
3
|
-
import { dirname, extname,
|
3
|
+
import { dirname, extname, relative, resolve } from 'node:path'
|
4
4
|
import process from 'node:process'
|
5
5
|
|
6
6
|
import type { RecursiveRecord } from '@jiek/pkger/entrypoints'
|
@@ -10,17 +10,19 @@ import { getWorkspaceDir } from '@jiek/utils/getWorkspaceDir'
|
|
10
10
|
import commonjs from '@rollup/plugin-commonjs'
|
11
11
|
import json from '@rollup/plugin-json'
|
12
12
|
import { nodeResolve } from '@rollup/plugin-node-resolve'
|
13
|
-
import { sendMessage } from 'execa'
|
14
13
|
import { isMatch } from 'micromatch'
|
15
|
-
import type { InputPluginOption, OutputOptions, OutputPlugin, Plugin, RollupOptions } from 'rollup'
|
14
|
+
import type { InputPluginOption, OutputOptions, OutputPlugin, OutputPluginOption, Plugin, RollupOptions } from 'rollup'
|
16
15
|
import ts from 'typescript'
|
17
16
|
|
17
|
+
import type { RollupBuildEntryCtx, RollupBuildEventMap } from '#~/bridge.ts'
|
18
|
+
import { publish } from '#~/bridge.ts'
|
19
|
+
import { bundleAnalyzer } from '#~/rollup/bundle-analyzer.ts'
|
18
20
|
import { getExports, getOutDirs } from '#~/utils/getExports.ts'
|
19
21
|
import { loadConfig } from '#~/utils/loadConfig.ts'
|
20
22
|
import { recusiveListFiles } from '#~/utils/recusiveListFiles.ts'
|
21
23
|
import { getCompilerOptionsByFilePath } from '#~/utils/ts.ts'
|
22
24
|
|
23
|
-
import type { ConfigGenerateContext,
|
25
|
+
import type { ConfigGenerateContext, TemplateOptions } from './base'
|
24
26
|
import createRequire, { isFormatEsm } from './plugins/create-require'
|
25
27
|
import progress from './plugins/progress'
|
26
28
|
import skip from './plugins/skip'
|
@@ -33,7 +35,6 @@ interface PackageJSON {
|
|
33
35
|
}
|
34
36
|
|
35
37
|
const {
|
36
|
-
JIEK_ANALYZER,
|
37
38
|
JIEK_ROOT,
|
38
39
|
JIEK_NAME,
|
39
40
|
JIEK_BUILDER,
|
@@ -62,14 +63,6 @@ const resolveArrayString = (str: string | undefined) => {
|
|
62
63
|
return arr?.length ? arr : undefined
|
63
64
|
}
|
64
65
|
|
65
|
-
const ANALYZER = JIEK_ANALYZER && JSON.parse(JIEK_ANALYZER) as {
|
66
|
-
dir?: string
|
67
|
-
mode?: string
|
68
|
-
size?: string
|
69
|
-
port?: number
|
70
|
-
open?: boolean
|
71
|
-
}
|
72
|
-
|
73
66
|
const entries = resolveArrayString(JIEK_ENTRIES)?.map(e => ({ 'index': '.' }[e] ?? e))
|
74
67
|
|
75
68
|
const commandExternal = resolveArrayString(JIEK_EXTERNAL)?.map(e => new RegExp(`^${e}$`))
|
@@ -203,16 +196,10 @@ const withMinify = (
|
|
203
196
|
output: OutputOptions & {
|
204
197
|
plugins?: OutputPlugin[]
|
205
198
|
},
|
206
|
-
|
199
|
+
onlyOncePlugins: OutputPluginOption[] = []
|
207
200
|
): OutputOptions[] => {
|
201
|
+
const minify = build?.output?.minify ?? MINIFY_DEFAULT_VALUE
|
208
202
|
output.plugins = output.plugins ?? []
|
209
|
-
const onlyOncePlugins: Plugin[] = [
|
210
|
-
// adapter(analyzer({
|
211
|
-
// analyzerMode: 'server',
|
212
|
-
// analyzerPort: 8888,
|
213
|
-
// reportTitle: 'Bundle Analysis'
|
214
|
-
// }))
|
215
|
-
]
|
216
203
|
if (minify === false) {
|
217
204
|
output.plugins.push(...onlyOncePlugins)
|
218
205
|
return [output]
|
@@ -276,6 +263,14 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
276
263
|
const isModule = conditionals.includes('import')
|
277
264
|
const isCommonJS = conditionals.includes('require')
|
278
265
|
const isBrowser = conditionals.includes('browser')
|
266
|
+
const format = isModule ? 'esm' : (
|
267
|
+
isCommonJS ? 'cjs' : (
|
268
|
+
isBrowser ? 'umd' : (
|
269
|
+
pkgIsModule ? 'esm' : 'cjs'
|
270
|
+
)
|
271
|
+
)
|
272
|
+
)
|
273
|
+
|
279
274
|
const dtsTSConfigPaths = [
|
280
275
|
resolveWorkspacePath('tsconfig.json'),
|
281
276
|
resolveWorkspacePath('tsconfig.dts.json')
|
@@ -315,10 +310,22 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
315
310
|
delete compilerOptions.composite
|
316
311
|
}
|
317
312
|
const exportConditions = [...conditionals, ...(compilerOptions.customConditions ?? [])]
|
318
|
-
const
|
319
|
-
type:
|
320
|
-
data:
|
321
|
-
|
313
|
+
const publishInEntry = <K extends keyof RollupBuildEventMap>(
|
314
|
+
type: K,
|
315
|
+
data: Omit<RollupBuildEventMap[K], keyof RollupBuildEntryCtx>
|
316
|
+
) =>
|
317
|
+
// eslint-disable-next-line ts/no-unsafe-argument
|
318
|
+
void publish(type, {
|
319
|
+
...{
|
320
|
+
type: format,
|
321
|
+
name,
|
322
|
+
path,
|
323
|
+
exportConditions,
|
324
|
+
input
|
325
|
+
} as RollupBuildEntryCtx,
|
326
|
+
...data
|
327
|
+
} as any)
|
328
|
+
|
322
329
|
const { js: jsPlugins, dts: dtsPlugins } = resolveBuildPlugins(context, build.plugins)
|
323
330
|
if (input.includes('**')) {
|
324
331
|
throw new Error(
|
@@ -377,59 +384,10 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
377
384
|
...noTypeResolvedBuilderOptions
|
378
385
|
})
|
379
386
|
)
|
380
|
-
const ana =
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
stat: 'stat',
|
385
|
-
gzip: 'gzip'
|
386
|
-
} as const)[ANALYZER.size ?? 'stat'] ?? 'parsed'
|
387
|
-
const title = `${join(context.name, context.path)} ${context.conditionals.join(',')}`
|
388
|
-
const filename = title
|
389
|
-
.replace('\/', '_')
|
390
|
-
.replace(' ', '_')
|
391
|
-
switch (ANALYZER.mode ?? 'server') {
|
392
|
-
case 'server':
|
393
|
-
return adapter(analyzer({
|
394
|
-
defaultSizes,
|
395
|
-
analyzerMode: 'server',
|
396
|
-
analyzerPort: ANALYZER.port ?? 'auto',
|
397
|
-
openAnalyzer: ANALYZER.open ?? false,
|
398
|
-
reportTitle: `Bundle Analysis ${title}`
|
399
|
-
}))
|
400
|
-
case 'json':
|
401
|
-
return adapter(analyzer({
|
402
|
-
defaultSizes,
|
403
|
-
analyzerMode: 'json',
|
404
|
-
fileName: ANALYZER.dir ? join(ANALYZER.dir, filename) : filename
|
405
|
-
}))
|
406
|
-
case 'static':
|
407
|
-
return adapter(analyzer({
|
408
|
-
defaultSizes,
|
409
|
-
analyzerMode: 'static',
|
410
|
-
analyzerPort: ANALYZER.port ?? 'auto',
|
411
|
-
openAnalyzer: ANALYZER.open ?? false,
|
412
|
-
reportTitle: `Bundle Analysis ${title}`,
|
413
|
-
fileName: ANALYZER.dir ? join(ANALYZER.dir, filename) : filename
|
414
|
-
}))
|
415
|
-
case undefined: {
|
416
|
-
throw new Error('Not implemented yet: undefined case')
|
417
|
-
}
|
418
|
-
default:
|
419
|
-
void sendMessage(
|
420
|
-
{
|
421
|
-
...throughEventProps,
|
422
|
-
data: {
|
423
|
-
...throughEventProps.data,
|
424
|
-
event: 'error',
|
425
|
-
message: 'ANALYZER.mode not supported',
|
426
|
-
tags: ['js']
|
427
|
-
}
|
428
|
-
} satisfies RollupProgressEvent
|
429
|
-
)
|
430
|
-
}
|
431
|
-
})
|
432
|
-
: undefined
|
387
|
+
const [ana, anaOutputPlugin] = bundleAnalyzer(modules => void publishInEntry('modulesAnalyze', { modules }))
|
388
|
+
const onlyOncePlugins = [
|
389
|
+
anaOutputPlugin
|
390
|
+
]
|
433
391
|
rollupOptions.push({
|
434
392
|
input: inputObj,
|
435
393
|
external,
|
@@ -446,20 +404,14 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
446
404
|
: output.replace(`${jsOutdir}/`, '')
|
447
405
|
),
|
448
406
|
sourcemap,
|
449
|
-
format
|
450
|
-
isCommonJS ? 'cjs' : (
|
451
|
-
isBrowser ? 'umd' : (
|
452
|
-
pkgIsModule ? 'esm' : 'cjs'
|
453
|
-
)
|
454
|
-
)
|
455
|
-
),
|
407
|
+
format,
|
456
408
|
strict: typeof options?.output?.strict === 'object'
|
457
409
|
? options.output.strict.js
|
458
410
|
: options?.output?.strict,
|
459
411
|
plugins: [
|
460
|
-
isFormatEsm(
|
412
|
+
isFormatEsm(format === 'esm')
|
461
413
|
]
|
462
|
-
})
|
414
|
+
}, onlyOncePlugins)
|
463
415
|
],
|
464
416
|
plugins: [
|
465
417
|
...commonPlugins,
|
@@ -476,13 +428,7 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
476
428
|
builder,
|
477
429
|
ana,
|
478
430
|
progress({
|
479
|
-
onEvent: (event, message) =>
|
480
|
-
void sendMessage(
|
481
|
-
{
|
482
|
-
...throughEventProps,
|
483
|
-
data: { ...throughEventProps.data, event, message, tags: ['js'] }
|
484
|
-
} satisfies RollupProgressEvent
|
485
|
-
)
|
431
|
+
onEvent: (event, message) => void publishInEntry('progress', { event, message, tags: ['js'] })
|
486
432
|
}),
|
487
433
|
jsPlugins
|
488
434
|
]
|
@@ -532,13 +478,7 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
532
478
|
tsconfig: dtsTSConfigPath
|
533
479
|
}),
|
534
480
|
progress({
|
535
|
-
onEvent: (event, message) =>
|
536
|
-
void sendMessage(
|
537
|
-
{
|
538
|
-
...throughEventProps,
|
539
|
-
data: { ...throughEventProps.data, event, message, tags: ['dts'] }
|
540
|
-
} satisfies RollupProgressEvent
|
541
|
-
)
|
481
|
+
onEvent: (event, message) => void publishInEntry('progress', { event, message, tags: ['dts'] })
|
542
482
|
}),
|
543
483
|
dtsPlugins
|
544
484
|
]
|
@@ -549,13 +489,7 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
549
489
|
rollupOptions[0].plugins = [
|
550
490
|
{
|
551
491
|
name: 'jiek-plugin-watcher',
|
552
|
-
watchChange: (id)
|
553
|
-
void sendMessage(
|
554
|
-
{
|
555
|
-
type: 'watchChange',
|
556
|
-
data: { id, name: JIEK_NAME!, path, input }
|
557
|
-
} satisfies RollupProgressEvent
|
558
|
-
)
|
492
|
+
watchChange: id => void publishInEntry('watchChange', { id })
|
559
493
|
},
|
560
494
|
...(rollupOptions[0].plugins as Plugin[])
|
561
495
|
]
|
@@ -634,15 +568,7 @@ export function template(packageJSON: PackageJSON): RollupOptions[] {
|
|
634
568
|
}
|
635
569
|
})
|
636
570
|
)
|
637
|
-
void
|
638
|
-
{
|
639
|
-
type: 'init',
|
640
|
-
data: {
|
641
|
-
leafMap,
|
642
|
-
targetsLength: configs.length
|
643
|
-
}
|
644
|
-
} satisfies RollupProgressEvent
|
645
|
-
)
|
571
|
+
void publish('init', { leafMap, targetsLength: configs.length })
|
646
572
|
return configs.map(c => ({
|
647
573
|
...COMMON_OPTIONS,
|
648
574
|
...c,
|
package/src/server.ts
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
import Koa from 'koa'
|
2
|
+
|
3
|
+
export const createServer = (port: number, host: string) => {
|
4
|
+
const app = new Koa()
|
5
|
+
app.listen(port, host)
|
6
|
+
const streams = new Map<string, string>()
|
7
|
+
app.use(async (ctx) => {
|
8
|
+
const stream = streams.get(ctx.path)
|
9
|
+
if (stream != null) {
|
10
|
+
ctx.body = stream
|
11
|
+
}
|
12
|
+
})
|
13
|
+
// noinspection HttpUrlsUsage
|
14
|
+
return {
|
15
|
+
port,
|
16
|
+
host,
|
17
|
+
rootUrl: `http://${host}:${port}`,
|
18
|
+
renderTo: async (path: string, stream: string) => {
|
19
|
+
streams.set(path, stream)
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|