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/rollup/index.ts
CHANGED
@@ -11,30 +11,27 @@ import commonjs from '@rollup/plugin-commonjs'
|
|
11
11
|
import inject from '@rollup/plugin-inject'
|
12
12
|
import json from '@rollup/plugin-json'
|
13
13
|
import { nodeResolve } from '@rollup/plugin-node-resolve'
|
14
|
-
import { isMatch } from 'micromatch'
|
15
14
|
import type { InputPluginOption, OutputOptions, OutputPlugin, OutputPluginOption, Plugin, RollupOptions } from 'rollup'
|
16
15
|
import ts from 'typescript'
|
17
16
|
|
18
|
-
import type { RollupBuildEntryCtx, RollupBuildEventMap } from '#~/bridge
|
19
|
-
import { publish } from '#~/bridge
|
20
|
-
import { bundleAnalyzer } from '#~/rollup/bundle-analyzer
|
21
|
-
import {
|
22
|
-
import {
|
23
|
-
import {
|
24
|
-
import {
|
17
|
+
import type { RollupBuildEntryCtx, RollupBuildEventMap } from '#~/bridge'
|
18
|
+
import { publish } from '#~/bridge'
|
19
|
+
import { bundleAnalyzer } from '#~/rollup/bundle-analyzer'
|
20
|
+
import { getInternalModuleName } from '#~/utils/getInternalModuleName'
|
21
|
+
import { intersection } from '#~/utils/intersection'
|
22
|
+
import { loadConfig } from '#~/utils/loadConfig'
|
23
|
+
import { recursiveListFiles } from '#~/utils/recursiveListFiles'
|
24
|
+
import { getOutDirs, resolveExports } from '#~/utils/resolveExports'
|
25
|
+
import { getCompilerOptionsByFilePath } from '#~/utils/ts'
|
25
26
|
|
26
27
|
import type { ConfigGenerateContext, TemplateOptions } from './base'
|
27
28
|
import createRequire, { CREATE_REQUIRE_VIRTUAL_MODULE_NAME } from './plugins/create-require'
|
28
29
|
import progress from './plugins/progress'
|
29
30
|
import skip from './plugins/skip'
|
31
|
+
import withExternal from './plugins/with-external.ts'
|
32
|
+
import type { PackageJSON } from './utils/externalResolver'
|
30
33
|
import externalResolver from './utils/externalResolver'
|
31
34
|
|
32
|
-
interface PackageJSON {
|
33
|
-
name?: string
|
34
|
-
type?: string
|
35
|
-
exports?: Record<string, unknown> | string | string[]
|
36
|
-
}
|
37
|
-
|
38
35
|
const {
|
39
36
|
JIEK_ROOT,
|
40
37
|
JIEK_NAME,
|
@@ -48,7 +45,8 @@ const {
|
|
48
45
|
JIEK_CLEAN,
|
49
46
|
JIEK_ONLY_MINIFY,
|
50
47
|
JIEK_TSCONFIG,
|
51
|
-
JIEK_DTSCONFIG
|
48
|
+
JIEK_DTSCONFIG,
|
49
|
+
JIEK_FEATURES
|
52
50
|
} = process.env
|
53
51
|
|
54
52
|
const resolveArrayString = (str: string | undefined) => {
|
@@ -74,6 +72,8 @@ const COMMON_PLUGINS = [
|
|
74
72
|
json()
|
75
73
|
]
|
76
74
|
|
75
|
+
const INTERNAL_MODULE_NAME = getInternalModuleName(JIEK_NAME!)
|
76
|
+
|
77
77
|
const WITHOUT_JS = JIEK_WITHOUT_JS === 'true'
|
78
78
|
const WITHOUT_DTS = JIEK_WITHOUT_DTS === 'true'
|
79
79
|
const WITHOUT_MINIFY = JIEK_WITHOUT_MINIFY === 'true'
|
@@ -82,6 +82,8 @@ const ONLY_MINIFY = JIEK_ONLY_MINIFY === 'true'
|
|
82
82
|
|
83
83
|
const CLEAN = JIEK_CLEAN === 'true'
|
84
84
|
|
85
|
+
const FEATURES = JSON.parse(JIEK_FEATURES ?? '{}') as Record<string, unknown>
|
86
|
+
|
85
87
|
const MINIFY_DEFAULT_VALUE = WITHOUT_MINIFY
|
86
88
|
? false
|
87
89
|
: ONLY_MINIFY
|
@@ -116,6 +118,10 @@ if (CLEAN) {
|
|
116
118
|
|
117
119
|
const STYLE_REGEXP = /\.(css|s[ac]ss|less|styl)$/
|
118
120
|
|
121
|
+
const CWD_FILES = recursiveListFiles(process.cwd())
|
122
|
+
.filter(p => /(?<!\.d)\.[cm]?tsx?$/.test(p))
|
123
|
+
.map(p => relative(process.cwd(), p))
|
124
|
+
|
119
125
|
const resolveBuildPlugins = (context: ConfigGenerateContext, plugins: TemplateOptions['plugins']): {
|
120
126
|
js: InputPluginOption
|
121
127
|
dts: InputPluginOption
|
@@ -197,9 +203,12 @@ const withMinify = (
|
|
197
203
|
output: OutputOptions & {
|
198
204
|
plugins?: OutputPlugin[]
|
199
205
|
},
|
206
|
+
disableMinify?: boolean,
|
200
207
|
onlyOncePlugins: OutputPluginOption[] = []
|
201
208
|
): OutputOptions[] => {
|
202
|
-
const minify =
|
209
|
+
const minify = disableMinify !== undefined
|
210
|
+
? !disableMinify
|
211
|
+
: build?.output?.minify ?? MINIFY_DEFAULT_VALUE
|
203
212
|
|
204
213
|
output.plugins = output.plugins ?? []
|
205
214
|
const notOnlyOncePlugins = [...output.plugins]
|
@@ -226,7 +235,7 @@ const withMinify = (
|
|
226
235
|
typeof output.entryFileNames === 'function'
|
227
236
|
? output.entryFileNames(chunkInfo)
|
228
237
|
: (() => {
|
229
|
-
throw new
|
238
|
+
throw new TypeError('entryFileNames must be a function')
|
230
239
|
})(),
|
231
240
|
plugins: [
|
232
241
|
...output.plugins,
|
@@ -253,7 +262,25 @@ const withMinify = (
|
|
253
262
|
]
|
254
263
|
}
|
255
264
|
|
256
|
-
|
265
|
+
interface GenerateConfigsOptions {
|
266
|
+
internalModuleCollect?: (id: string) => void
|
267
|
+
commonPlugins?: InputPluginOption[]
|
268
|
+
disableDTS?: boolean
|
269
|
+
disableMinify?: boolean
|
270
|
+
disableCollectInternalModule?: boolean
|
271
|
+
}
|
272
|
+
|
273
|
+
const generateConfigs = (
|
274
|
+
context: ConfigGenerateContext,
|
275
|
+
{
|
276
|
+
internalModuleCollect,
|
277
|
+
commonPlugins: inputCommonPlugins = [],
|
278
|
+
disableDTS = false,
|
279
|
+
disableMinify,
|
280
|
+
disableCollectInternalModule
|
281
|
+
}: GenerateConfigsOptions = {}
|
282
|
+
): RollupOptions[] => {
|
283
|
+
const buildOptions: TemplateOptions = build
|
257
284
|
const {
|
258
285
|
path,
|
259
286
|
name,
|
@@ -263,7 +290,7 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
263
290
|
pkgIsModule,
|
264
291
|
conditionals
|
265
292
|
} = context
|
266
|
-
const external = [...inputExternal, ...(
|
293
|
+
const external = [...inputExternal, ...(buildOptions.external ?? []), ...(commandExternal ?? [])]
|
267
294
|
const isModule = conditionals.includes('import')
|
268
295
|
const isCommonJS = conditionals.includes('require')
|
269
296
|
const isBrowser = conditionals.includes('browser')
|
@@ -314,6 +341,23 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
314
341
|
delete compilerOptions.composite
|
315
342
|
}
|
316
343
|
const exportConditions = [...conditionals, ...(compilerOptions.customConditions ?? [])]
|
344
|
+
const nodeResolvePluginInstance = nodeResolve({
|
345
|
+
exportConditions,
|
346
|
+
extensions: [
|
347
|
+
'.js',
|
348
|
+
'.cjs',
|
349
|
+
'.mjs',
|
350
|
+
'.jsx',
|
351
|
+
'.cjsx',
|
352
|
+
'.mjsx',
|
353
|
+
'.ts',
|
354
|
+
'.cts',
|
355
|
+
'.mts',
|
356
|
+
'.tsx',
|
357
|
+
'.ctsx',
|
358
|
+
'.mtsx'
|
359
|
+
]
|
360
|
+
})
|
317
361
|
const publishInEntry = <K extends keyof RollupBuildEventMap>(
|
318
362
|
type: K,
|
319
363
|
data: Omit<RollupBuildEventMap[K], keyof RollupBuildEntryCtx>
|
@@ -336,12 +380,15 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
336
380
|
'input should not include "**", please read the [documentation](https://nodejs.org/api/packages.html#subpath-patterns).'
|
337
381
|
)
|
338
382
|
}
|
383
|
+
const reg = new RegExp(`^${
|
384
|
+
input
|
385
|
+
.slice(2)
|
386
|
+
.replace(/\./g, '\\.')
|
387
|
+
.replace(/\*/g, '.*')
|
388
|
+
}$`)
|
339
389
|
const inputObj = !input.includes('*')
|
340
390
|
? input
|
341
|
-
:
|
342
|
-
.filter(p => /(?<!\.d)\.[cm]?tsx?$/.test(p))
|
343
|
-
.map(p => relative(process.cwd(), p))
|
344
|
-
.filter(p => isMatch(p, input.slice(2)))
|
391
|
+
: CWD_FILES.filter(p => reg.test(p))
|
345
392
|
const globCommonDir = input.includes('*')
|
346
393
|
? input.split('*')[0].replace('./', '')
|
347
394
|
: ''
|
@@ -359,32 +406,59 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
359
406
|
const { js: jsOutput, dts: dtsOutput } = resolveOutputControls(context, build.output)
|
360
407
|
const rollupOptions: RollupOptions[] = []
|
361
408
|
|
362
|
-
const commonPlugins:
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
'
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
409
|
+
const commonPlugins: InputPluginOption[] = [
|
410
|
+
...inputCommonPlugins,
|
411
|
+
withExternal(),
|
412
|
+
!disableCollectInternalModule && {
|
413
|
+
name: 'jiek:collect-internal-module',
|
414
|
+
resolveId: {
|
415
|
+
order: 'pre',
|
416
|
+
async handler(source, importer, options) {
|
417
|
+
if (!source.startsWith('#')) return
|
418
|
+
|
419
|
+
if (!nodeResolvePluginInstance.resolveId || !('handler' in nodeResolvePluginInstance.resolveId)) {
|
420
|
+
throw new Error('nodeResolvePluginInstance.resolveId is not a plugin instance')
|
421
|
+
}
|
422
|
+
let resolved = await nodeResolvePluginInstance
|
423
|
+
.resolveId
|
424
|
+
.handler
|
425
|
+
.call(this, source, importer, options)
|
426
|
+
if (typeof resolved === 'string') {
|
427
|
+
resolved = { id: resolved }
|
428
|
+
}
|
429
|
+
if (!resolved || !('id' in resolved)) {
|
430
|
+
throw new Error('nodeResolvePluginInstance.resolveId.handler did not return a resolved object')
|
431
|
+
}
|
432
|
+
internalModuleCollect?.(relative(process.cwd(), resolved.id))
|
433
|
+
return {
|
434
|
+
id: source
|
435
|
+
.replaceAll('#', `${INTERNAL_MODULE_NAME}/`)
|
436
|
+
.replaceAll('~', '+'),
|
437
|
+
external: true
|
438
|
+
}
|
439
|
+
}
|
440
|
+
}
|
441
|
+
}
|
380
442
|
]
|
443
|
+
const features = Object.assign(
|
444
|
+
{
|
445
|
+
keepImportAttributes: false
|
446
|
+
},
|
447
|
+
build.features,
|
448
|
+
FEATURES
|
449
|
+
)
|
450
|
+
const importAttributesKey = (
|
451
|
+
features.keepImportAttributes === false
|
452
|
+
|| features.keepImportAttributes === undefined
|
453
|
+
)
|
454
|
+
? undefined
|
455
|
+
: features.keepImportAttributes === true
|
456
|
+
? 'with'
|
457
|
+
: features.keepImportAttributes
|
381
458
|
if (jsOutput && !WITHOUT_JS) {
|
382
|
-
const sourcemap = typeof
|
383
|
-
?
|
384
|
-
:
|
385
|
-
const features = Object.assign({
|
386
|
-
keepImportAttributes: true
|
387
|
-
}, build.features)
|
459
|
+
const sourcemap = typeof buildOptions?.output?.sourcemap === 'object'
|
460
|
+
? buildOptions.output.sourcemap.js
|
461
|
+
: buildOptions?.output?.sourcemap
|
388
462
|
const builder = resolvedBuilderOptions.type === 'esbuild'
|
389
463
|
? import('rollup-plugin-esbuild').then(({ default: esbuild }) =>
|
390
464
|
esbuild({
|
@@ -402,8 +476,8 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
402
476
|
},
|
403
477
|
...noTypeResolvedBuilderOptions,
|
404
478
|
supported: {
|
405
|
-
|
406
|
-
|
479
|
+
...resolvedBuilderOptions.supported,
|
480
|
+
'import-attributes': true
|
407
481
|
}
|
408
482
|
})
|
409
483
|
)
|
@@ -431,7 +505,7 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
431
505
|
},
|
432
506
|
experimental: {
|
433
507
|
...resolvedBuilderOptions.jsc?.experimental,
|
434
|
-
keepImportAttributes:
|
508
|
+
keepImportAttributes: true
|
435
509
|
}
|
436
510
|
}
|
437
511
|
})
|
@@ -444,36 +518,36 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
444
518
|
input: inputObj,
|
445
519
|
external,
|
446
520
|
output: [
|
447
|
-
...withMinify(
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
.
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
:
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
}, onlyOncePlugins)
|
521
|
+
...withMinify(
|
522
|
+
{
|
523
|
+
dir: jsOutdir,
|
524
|
+
name,
|
525
|
+
interop: 'auto',
|
526
|
+
entryFileNames: (chunkInfo) => {
|
527
|
+
return Array.isArray(inputObj)
|
528
|
+
? chunkInfo.facadeModuleId!
|
529
|
+
.replace(`${process.cwd()}/`, '')
|
530
|
+
.replace(globCommonDir, pathCommonDir)
|
531
|
+
.replace(/(\.[cm]?)ts$/, jsOutputSuffix)
|
532
|
+
: output.replace(`${jsOutdir}/`, '')
|
533
|
+
},
|
534
|
+
sourcemap,
|
535
|
+
format,
|
536
|
+
strict: typeof buildOptions?.output?.strict === 'object'
|
537
|
+
? buildOptions.output.strict.js
|
538
|
+
: buildOptions?.output?.strict,
|
539
|
+
externalImportAttributes: features.keepImportAttributes === true
|
540
|
+
? true
|
541
|
+
: features.keepImportAttributes,
|
542
|
+
importAttributesKey
|
543
|
+
},
|
544
|
+
disableMinify,
|
545
|
+
onlyOncePlugins
|
546
|
+
)
|
474
547
|
],
|
475
548
|
plugins: [
|
476
549
|
...commonPlugins,
|
550
|
+
nodeResolvePluginInstance,
|
477
551
|
import('rollup-plugin-postcss')
|
478
552
|
.then(({ default: postcss }) =>
|
479
553
|
postcss({
|
@@ -502,10 +576,10 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
502
576
|
})
|
503
577
|
}
|
504
578
|
|
505
|
-
if (dtsOutput && !WITHOUT_DTS) {
|
506
|
-
const sourcemap = typeof
|
507
|
-
?
|
508
|
-
:
|
579
|
+
if (!disableDTS && dtsOutput && !WITHOUT_DTS) {
|
580
|
+
const sourcemap = typeof buildOptions?.output?.sourcemap === 'object'
|
581
|
+
? buildOptions.output.sourcemap.dts
|
582
|
+
: buildOptions?.output?.sourcemap
|
509
583
|
rollupOptions.push({
|
510
584
|
input: inputObj,
|
511
585
|
external,
|
@@ -522,9 +596,11 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
522
596
|
.replace(`${jsOutdir}/`, '')
|
523
597
|
.replace(/(\.[cm]?)js$/, tsOutputSuffix)
|
524
598
|
),
|
525
|
-
strict: typeof
|
526
|
-
?
|
527
|
-
:
|
599
|
+
strict: typeof buildOptions?.output?.strict === 'object'
|
600
|
+
? buildOptions.output.strict.dts
|
601
|
+
: buildOptions?.output?.strict,
|
602
|
+
externalImportAttributes: features.keepImportAttributes !== false,
|
603
|
+
importAttributesKey
|
528
604
|
}
|
529
605
|
],
|
530
606
|
plugins: [
|
@@ -566,57 +642,174 @@ const generateConfigs = (context: ConfigGenerateContext, options: TemplateOption
|
|
566
642
|
}
|
567
643
|
|
568
644
|
export function template(packageJSON: PackageJSON): RollupOptions[] {
|
569
|
-
const {
|
645
|
+
const {
|
646
|
+
name,
|
647
|
+
type,
|
648
|
+
bin,
|
649
|
+
exports: entrypoints,
|
650
|
+
imports: internalEntrypoints
|
651
|
+
} = packageJSON
|
570
652
|
const pkgIsModule = type === 'module'
|
571
|
-
if (!name) throw new Error('package.json name is required')
|
572
|
-
if (!entrypoints) throw new Error('package.json exports is required')
|
573
|
-
|
574
653
|
const packageName = pascalCase(name)
|
575
|
-
|
576
|
-
const external = externalResolver(packageJSON as Record<string, unknown>)
|
577
|
-
|
578
|
-
const [filteredResolvedEntrypoints, exports] = getExports({
|
579
|
-
entrypoints,
|
580
|
-
pkgIsModule,
|
581
|
-
entries,
|
582
|
-
pkgName: JIEK_NAME!,
|
583
|
-
outdir: jsOutdir,
|
584
|
-
config
|
585
|
-
})
|
586
|
-
|
587
654
|
const leafMap = new Map<string, string[][]>()
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
655
|
+
const inputTags = new Map<string, string>()
|
656
|
+
const inputExports = new Map<string, Record<string, unknown>>()
|
657
|
+
const configs: RollupOptions[] = []
|
658
|
+
const external = externalResolver(packageJSON)
|
659
|
+
|
660
|
+
let collectConfigTotal = 0
|
661
|
+
const collected = Promise.withResolvers<void>()
|
662
|
+
const internalModules = new Set<string>()
|
663
|
+
const internalModuleCollect = (id?: string) => {
|
664
|
+
if (!id) return
|
665
|
+
internalModules.add(id)
|
666
|
+
}
|
667
|
+
const collectPlugin: Plugin = {
|
668
|
+
name: 'jiek:collect',
|
669
|
+
buildStart() {
|
670
|
+
collectConfigTotal++
|
671
|
+
},
|
672
|
+
buildEnd() {
|
673
|
+
if (--collectConfigTotal === 0) {
|
674
|
+
collected.resolve()
|
675
|
+
}
|
593
676
|
}
|
594
|
-
|
595
|
-
|
677
|
+
}
|
678
|
+
|
679
|
+
if (entrypoints) {
|
680
|
+
const [filteredResolvedEntrypoints, exports] = resolveExports({
|
681
|
+
entrypoints,
|
682
|
+
pkgIsModule,
|
683
|
+
entries,
|
684
|
+
pkgName: JIEK_NAME!,
|
685
|
+
outdir: jsOutdir,
|
686
|
+
config
|
687
|
+
})
|
688
|
+
getAllLeafs(filteredResolvedEntrypoints as RecursiveRecord<string>, ({ keys, value }) => {
|
689
|
+
if (typeof value === 'string') {
|
690
|
+
const keysArr = leafMap.get(value) ?? []
|
691
|
+
leafMap.set(value, keysArr)
|
692
|
+
inputExports.set(value, exports)
|
693
|
+
keysArr.push(keys)
|
694
|
+
}
|
695
|
+
return false
|
696
|
+
})
|
697
|
+
}
|
698
|
+
if (bin) {
|
699
|
+
;[...new Set(typeof bin === 'string' ? [bin] : Object.values(bin))]
|
700
|
+
.filter(binFile => binFile.startsWith('bin'))
|
701
|
+
.map(binFile => [
|
702
|
+
`./src/${binFile.replace(/(\.[cm]?)js$/, '$1ts')}`,
|
703
|
+
`./dist/${binFile}`
|
704
|
+
])
|
705
|
+
.forEach(([input, output]) => {
|
706
|
+
configs.push(...generateConfigs({
|
707
|
+
path: output,
|
708
|
+
name,
|
709
|
+
input,
|
710
|
+
output,
|
711
|
+
external,
|
712
|
+
pkgIsModule,
|
713
|
+
conditionals: output.endsWith('.mjs')
|
714
|
+
? ['import']
|
715
|
+
: output.endsWith('.cjs')
|
716
|
+
? ['require']
|
717
|
+
: []
|
718
|
+
}, {
|
719
|
+
internalModuleCollect,
|
720
|
+
disableDTS: true,
|
721
|
+
disableMinify: true,
|
722
|
+
commonPlugins: [
|
723
|
+
collectPlugin
|
724
|
+
]
|
725
|
+
}))
|
726
|
+
leafMap.set(input, [[output]])
|
727
|
+
inputTags.set(input, 'binary')
|
728
|
+
})
|
729
|
+
}
|
730
|
+
if (internalEntrypoints) {
|
731
|
+
const [filteredResolvedInternalEntrypoints, imports] = resolveExports({
|
732
|
+
entrypoints: internalEntrypoints,
|
733
|
+
pkgIsModule,
|
734
|
+
pkgName: JIEK_NAME!,
|
735
|
+
outdir: `${jsOutdir}/.internal`,
|
736
|
+
config
|
737
|
+
})
|
738
|
+
getAllLeafs(filteredResolvedInternalEntrypoints as RecursiveRecord<string>, ({ keys, value }) => {
|
739
|
+
if (typeof value === 'string') {
|
740
|
+
const keysArr = leafMap.get(value) ?? []
|
741
|
+
leafMap.set(value, keysArr)
|
742
|
+
inputExports.set(value, imports)
|
743
|
+
inputTags.set(value, 'internal')
|
744
|
+
keysArr.push(keys)
|
745
|
+
}
|
746
|
+
return false
|
747
|
+
})
|
748
|
+
}
|
749
|
+
|
750
|
+
leafMap.forEach((keysArr, input) => {
|
751
|
+
if (inputTags.get(input) === 'binary') return
|
752
|
+
const isInternal = inputTags.get(input) === 'internal'
|
753
|
+
const exports = inputExports.get(input)!
|
596
754
|
|
597
|
-
const configs: RollupOptions[] = []
|
598
|
-
leafMap.forEach((keysArr, input) =>
|
599
755
|
keysArr.forEach((keys) => {
|
600
756
|
const [path, ...conditionals] = keys
|
601
757
|
|
602
758
|
const name = packageName + (path === '.' ? '' : pascalCase(path))
|
603
759
|
const keyExports = reveal(exports, keys)
|
604
|
-
const
|
760
|
+
const commonContext = {
|
605
761
|
path,
|
606
762
|
name,
|
607
763
|
input,
|
608
764
|
external,
|
609
765
|
pkgIsModule
|
610
766
|
}
|
767
|
+
const commonOptions: GenerateConfigsOptions = isInternal
|
768
|
+
? {
|
769
|
+
commonPlugins: [
|
770
|
+
{
|
771
|
+
name: 'jiek:loadInternalModules',
|
772
|
+
async options(inputOptions) {
|
773
|
+
await collected.promise
|
774
|
+
inputOptions.input = [...intersection(
|
775
|
+
inputOptions.input as string[],
|
776
|
+
internalModules
|
777
|
+
)]
|
778
|
+
return inputOptions
|
779
|
+
},
|
780
|
+
outputOptions(outputOptions) {
|
781
|
+
outputOptions.dir = `${outputOptions.dir}/.internal`
|
782
|
+
const oldEntryFileNames = outputOptions.entryFileNames
|
783
|
+
outputOptions.entryFileNames = (chunkInfo) => {
|
784
|
+
if (typeof oldEntryFileNames !== 'function') {
|
785
|
+
throw new TypeError('entryFileNames must be a function')
|
786
|
+
}
|
787
|
+
const oldFileName = oldEntryFileNames(chunkInfo)
|
788
|
+
return oldFileName
|
789
|
+
.replaceAll('#', '')
|
790
|
+
.replaceAll('~', '+')
|
791
|
+
}
|
792
|
+
return outputOptions
|
793
|
+
}
|
794
|
+
}
|
795
|
+
],
|
796
|
+
disableCollectInternalModule: true
|
797
|
+
}
|
798
|
+
: {
|
799
|
+
internalModuleCollect,
|
800
|
+
commonPlugins: [
|
801
|
+
collectPlugin
|
802
|
+
]
|
803
|
+
}
|
611
804
|
|
612
805
|
// eslint-disable-next-line ts/switch-exhaustiveness-check
|
613
806
|
switch (typeof keyExports) {
|
614
807
|
case 'string': {
|
615
808
|
configs.push(...generateConfigs({
|
616
|
-
...
|
809
|
+
...commonContext,
|
617
810
|
output: keyExports,
|
618
811
|
conditionals
|
619
|
-
},
|
812
|
+
}, commonOptions))
|
620
813
|
break
|
621
814
|
}
|
622
815
|
case 'object': {
|
@@ -624,10 +817,10 @@ export function template(packageJSON: PackageJSON): RollupOptions[] {
|
|
624
817
|
const allConditionals = [...new Set([...conditionals, ...nextKeys])]
|
625
818
|
if (typeof value === 'string') {
|
626
819
|
configs.push(...generateConfigs({
|
627
|
-
...
|
820
|
+
...commonContext,
|
628
821
|
output: value,
|
629
822
|
conditionals: allConditionals
|
630
|
-
},
|
823
|
+
}, commonOptions))
|
631
824
|
}
|
632
825
|
return false
|
633
826
|
})
|
@@ -635,7 +828,8 @@ export function template(packageJSON: PackageJSON): RollupOptions[] {
|
|
635
828
|
}
|
636
829
|
}
|
637
830
|
})
|
638
|
-
)
|
831
|
+
})
|
832
|
+
|
639
833
|
void publish('init', { leafMap, targetsLength: configs.length })
|
640
834
|
return configs.map(c => ({
|
641
835
|
...COMMON_OPTIONS,
|
@@ -0,0 +1,23 @@
|
|
1
|
+
import type { PluginImpl } from 'rollup'
|
2
|
+
|
3
|
+
export default (() => ({
|
4
|
+
name: 'jiek:with-external',
|
5
|
+
resolveId: {
|
6
|
+
order: 'pre',
|
7
|
+
handler: (source, _, { attributes }) => {
|
8
|
+
if (
|
9
|
+
'external' in attributes || 'bundle' in attributes
|
10
|
+
) {
|
11
|
+
delete attributes.external
|
12
|
+
delete attributes.bundle
|
13
|
+
return {
|
14
|
+
id: source,
|
15
|
+
external: attributes.external === 'true'
|
16
|
+
? true
|
17
|
+
: attributes.bundle !== 'true',
|
18
|
+
attributes
|
19
|
+
}
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
})) as PluginImpl<{}>
|
@@ -1,5 +1,6 @@
|
|
1
1
|
import fs from 'node:fs'
|
2
2
|
import { builtinModules } from 'node:module'
|
3
|
+
import process from 'node:process'
|
3
4
|
|
4
5
|
const EXCLUDE_SUFFIX = [
|
5
6
|
'te?xt',
|
@@ -7,21 +8,32 @@ const EXCLUDE_SUFFIX = [
|
|
7
8
|
'(css|s[ac]ss|less|styl)'
|
8
9
|
]
|
9
10
|
|
10
|
-
export
|
11
|
+
export interface PackageJSON {
|
12
|
+
name: string
|
13
|
+
type?: string
|
14
|
+
bin?: string | Record<string, string>
|
15
|
+
exports?: Record<string, unknown> | string | string[]
|
16
|
+
imports?: Record<string, unknown>
|
17
|
+
dependencies?: Record<string, unknown>
|
18
|
+
peerDependencies?: Record<string, unknown>
|
19
|
+
optionalDependencies?: Record<string, unknown>
|
20
|
+
}
|
21
|
+
|
22
|
+
export default function(json: PackageJSON): (string | RegExp)[]
|
11
23
|
export default function(path?: string): (string | RegExp)[]
|
12
|
-
export default function(jsonOrPath: string |
|
13
|
-
const pkg = typeof jsonOrPath === 'string'
|
24
|
+
export default function(jsonOrPath: string | PackageJSON = process.cwd()): (string | RegExp)[] {
|
25
|
+
const pkg: PackageJSON = typeof jsonOrPath === 'string'
|
14
26
|
? fs.existsSync(`${jsonOrPath}/package.json`)
|
15
|
-
? JSON.parse(fs.readFileSync(`${jsonOrPath}/package.json`, 'utf-8'))
|
16
|
-
: {}
|
27
|
+
? JSON.parse(fs.readFileSync(`${jsonOrPath}/package.json`, 'utf-8')) as PackageJSON
|
28
|
+
: {} as PackageJSON
|
17
29
|
: jsonOrPath
|
18
30
|
const { name, dependencies = {}, peerDependencies = {}, optionalDependencies = {} } = pkg
|
19
|
-
if (
|
31
|
+
if (name == null) {
|
20
32
|
throw new Error('package.json must have a name field')
|
21
33
|
}
|
22
34
|
|
23
|
-
const external = <(string | RegExp)[]>
|
24
|
-
.keys(dependencies)
|
35
|
+
const external = (<(string | RegExp)[]> [])
|
36
|
+
.concat(Object.keys(dependencies))
|
25
37
|
.concat(Object.keys(peerDependencies))
|
26
38
|
.concat(Object.keys(optionalDependencies))
|
27
39
|
.concat(builtinModules)
|