jiek 2.2.7-alpha.1 → 2.2.7-alpha.4
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/.jiek-production-tag +0 -0
- package/bin-helper/index.cjs +1 -1
- package/dist/.internal/{getWD-BRJ3PK1S.js → .chunks/filterSupport.4rM7f6jB.cjs} +38 -29
- package/dist/.internal/{getWD-Cmxzjf-f.js → .chunks/filterSupport.BXWpLBpT.js} +37 -28
- package/dist/.internal/{+/utils/loadConfig.js → .chunks/loadConfig.CFfzkm_p.js} +24 -8
- package/dist/.internal/{+/utils/loadConfig.cjs → .chunks/loadConfig.OOKddvHF.cjs} +29 -12
- package/dist/.internal/bin/common.cjs +743 -0
- package/dist/.internal/bin/common.d.cts +18 -0
- package/dist/.internal/bin/common.d.ts +18 -0
- package/dist/.internal/bin/common.js +736 -0
- package/dist/.internal/{+/utils → utils}/filterSupport.cjs +1 -3
- package/dist/.internal/{+/utils → utils}/filterSupport.js +1 -3
- package/dist/.internal/utils/loadConfig.cjs +14 -0
- package/dist/.internal/{+/utils/getWD.js → utils/loadConfig.js} +5 -6
- package/dist/.internal/{+/utils → utils}/resolveExports.cjs +1 -1
- package/dist/.internal/{+/utils → utils}/resolveExports.js +1 -1
- package/dist/.internal/{+/utils → utils}/ts.cjs +1 -1
- package/dist/.internal/{+/utils → utils}/ts.js +1 -1
- package/dist/bin/build.cjs +3 -498
- package/dist/bin/index.cjs +56 -43
- package/dist/index.d.cts +12 -2
- package/dist/index.d.ts +12 -2
- package/dist/rollup/index.cjs +25 -31
- package/dist/rollup/index.js +25 -31
- package/package.json +12 -15
- package/src/bin/build.cts +2 -8
- package/src/bin/common.ts +3 -0
- package/src/bin/index.cts +2 -1
- package/src/commands/build.ts +9 -3
- package/src/commands/publish.ts +62 -39
- package/src/index.ts +6 -1
- package/src/rollup/index.ts +36 -33
- package/dist/.internal/+/commands/build/analyzer.cjs +0 -201
- package/dist/.internal/+/commands/build/analyzer.d.cts +0 -30
- package/dist/.internal/+/commands/build/analyzer.d.ts +0 -30
- package/dist/.internal/+/commands/build/analyzer.js +0 -195
- package/dist/.internal/+/commands/descriptions.cjs +0 -21
- package/dist/.internal/+/commands/descriptions.d.cts +0 -5
- package/dist/.internal/+/commands/descriptions.d.ts +0 -5
- package/dist/.internal/+/commands/descriptions.js +0 -17
- package/dist/.internal/+/commands/meta.cjs +0 -16
- package/dist/.internal/+/commands/meta.d.cts +0 -3
- package/dist/.internal/+/commands/meta.d.ts +0 -3
- package/dist/.internal/+/commands/meta.js +0 -15
- package/dist/.internal/+/commands/utils/optionParser.cjs +0 -8
- package/dist/.internal/+/commands/utils/optionParser.d.cts +0 -3
- package/dist/.internal/+/commands/utils/optionParser.d.ts +0 -3
- package/dist/.internal/+/commands/utils/optionParser.js +0 -6
- package/dist/.internal/+/server.cjs +0 -33
- package/dist/.internal/+/server.d.cts +0 -8
- package/dist/.internal/+/server.d.ts +0 -8
- package/dist/.internal/+/server.js +0 -27
- package/dist/.internal/+/utils/checkDependency.cjs +0 -39
- package/dist/.internal/+/utils/checkDependency.d.cts +0 -3
- package/dist/.internal/+/utils/checkDependency.d.ts +0 -3
- package/dist/.internal/+/utils/checkDependency.js +0 -34
- package/dist/.internal/+/utils/getRoot.cjs +0 -17
- package/dist/.internal/+/utils/getRoot.d.cts +0 -3
- package/dist/.internal/+/utils/getRoot.d.ts +0 -3
- package/dist/.internal/+/utils/getRoot.js +0 -11
- package/dist/.internal/+/utils/getWD.cjs +0 -15
- package/dist/.internal/+/utils/getWD.d.cts +0 -6
- package/dist/.internal/+/utils/getWD.d.ts +0 -6
- package/dist/.internal/+/utils/tsRegister.cjs +0 -25
- package/dist/.internal/+/utils/tsRegister.d.cts +0 -3
- package/dist/.internal/+/utils/tsRegister.d.ts +0 -3
- package/dist/.internal/+/utils/tsRegister.js +0 -26
- package/dist/.internal/jiek_create-require-CWFWNQHj.js +0 -5
- package/dist/.internal/jiek_create-require-CxSGbkTB.js +0 -5
- package/dist/.internal/package.json +0 -10
- /package/dist/.internal/{index-B6RQz1DZ.js → .chunks/index.B6RQz1DZ.js} +0 -0
- /package/dist/.internal/{index-DlHFuTjM.js → .chunks/index.DlHFuTjM.cjs} +0 -0
- /package/dist/.internal/{+/bin → bin}/parseArgv.cjs +0 -0
- /package/dist/.internal/{+/bin → bin}/parseArgv.d.cts +0 -0
- /package/dist/.internal/{+/bin → bin}/parseArgv.d.ts +0 -0
- /package/dist/.internal/{+/bin → bin}/parseArgv.js +0 -0
- /package/dist/.internal/{+/bridge.cjs → bridge.cjs} +0 -0
- /package/dist/.internal/{+/bridge.d.cts → bridge.d.cts} +0 -0
- /package/dist/.internal/{+/bridge.d.ts → bridge.d.ts} +0 -0
- /package/dist/.internal/{+/bridge.js → bridge.js} +0 -0
- /package/dist/.internal/{+/rollup → rollup}/base.cjs +0 -0
- /package/dist/.internal/{+/rollup → rollup}/base.d.cts +0 -0
- /package/dist/.internal/{+/rollup → rollup}/base.d.ts +0 -0
- /package/dist/.internal/{+/rollup → rollup}/base.js +0 -0
- /package/dist/.internal/{+/rollup → rollup}/bundle-analyzer.cjs +0 -0
- /package/dist/.internal/{+/rollup → rollup}/bundle-analyzer.d.cts +0 -0
- /package/dist/.internal/{+/rollup → rollup}/bundle-analyzer.d.ts +0 -0
- /package/dist/.internal/{+/rollup → rollup}/bundle-analyzer.js +0 -0
- /package/dist/.internal/{+/utils → utils}/filterSupport.d.cts +0 -0
- /package/dist/.internal/{+/utils → utils}/filterSupport.d.ts +0 -0
- /package/dist/.internal/{+/utils → utils}/getInternalModuleName.cjs +0 -0
- /package/dist/.internal/{+/utils → utils}/getInternalModuleName.d.cts +0 -0
- /package/dist/.internal/{+/utils → utils}/getInternalModuleName.d.ts +0 -0
- /package/dist/.internal/{+/utils → utils}/getInternalModuleName.js +0 -0
- /package/dist/.internal/{+/utils → utils}/intersection.cjs +0 -0
- /package/dist/.internal/{+/utils → utils}/intersection.d.cts +0 -0
- /package/dist/.internal/{+/utils → utils}/intersection.d.ts +0 -0
- /package/dist/.internal/{+/utils → utils}/intersection.js +0 -0
- /package/dist/.internal/{+/utils → utils}/loadConfig.d.cts +0 -0
- /package/dist/.internal/{+/utils → utils}/loadConfig.d.ts +0 -0
- /package/dist/.internal/{+/utils → utils}/recursiveListFiles.cjs +0 -0
- /package/dist/.internal/{+/utils → utils}/recursiveListFiles.d.cts +0 -0
- /package/dist/.internal/{+/utils → utils}/recursiveListFiles.d.ts +0 -0
- /package/dist/.internal/{+/utils → utils}/recursiveListFiles.js +0 -0
- /package/dist/.internal/{+/utils → utils}/resolveExports.d.cts +0 -0
- /package/dist/.internal/{+/utils → utils}/resolveExports.d.ts +0 -0
- /package/dist/.internal/{+/utils → utils}/ts.d.cts +0 -0
- /package/dist/.internal/{+/utils → utils}/ts.d.ts +0 -0
package/src/commands/publish.ts
CHANGED
@@ -7,6 +7,7 @@ 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 { Config } from 'jiek'
|
10
11
|
import type { JSONPath } from 'jsonc-parser'
|
11
12
|
import { applyEdits, modify } from 'jsonc-parser'
|
12
13
|
|
@@ -20,6 +21,13 @@ import { getInternalModuleName } from '#~/utils/getInternalModuleName'
|
|
20
21
|
import { outdirDescription } from './descriptions'
|
21
22
|
|
22
23
|
declare module 'jiek' {
|
24
|
+
interface ConfigExperimental {
|
25
|
+
/**
|
26
|
+
* Polyfill `imports` fields in package.json to local dependencies and exports fields.
|
27
|
+
* @default false
|
28
|
+
*/
|
29
|
+
importsDowngrade?: boolean
|
30
|
+
}
|
23
31
|
export interface Config {
|
24
32
|
publish?: {
|
25
33
|
/**
|
@@ -111,12 +119,16 @@ async function prepublish({ bumper }: {
|
|
111
119
|
bumperEnv ? JSON.parse(bumperEnv) as string | boolean : false
|
112
120
|
)
|
113
121
|
|
114
|
-
const generateNewManifest = (
|
122
|
+
const generateNewManifest = (
|
123
|
+
dir: string,
|
124
|
+
manifest: NonNullable<ProjectsGraph['value']>[string],
|
125
|
+
config: Config
|
126
|
+
) => {
|
115
127
|
const {
|
116
128
|
name,
|
117
129
|
type,
|
118
|
-
exports: entrypoints
|
119
|
-
imports: internalEntrypoints
|
130
|
+
exports: entrypoints,
|
131
|
+
imports: internalEntrypoints
|
120
132
|
} = manifest
|
121
133
|
if (!name) {
|
122
134
|
throw new Error(`package.json in ${dir} must have a name field`)
|
@@ -127,38 +139,51 @@ async function prepublish({ bumper }: {
|
|
127
139
|
const commonOptions = {
|
128
140
|
pkgIsModule,
|
129
141
|
pkgName: name,
|
130
|
-
config
|
142
|
+
config,
|
131
143
|
dir,
|
132
144
|
noFilter: true,
|
133
145
|
isPublish: true
|
134
146
|
} satisfies Partial<ResolveExportsOptions>
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
147
|
+
let resolvedOutdir = outdir
|
148
|
+
if (entrypoints) {
|
149
|
+
const [resolvedEntrypoints, exports, _resolvedOutdir] = resolveExports({
|
150
|
+
entrypoints,
|
151
|
+
defaultOutdir: outdir,
|
152
|
+
...commonOptions
|
153
|
+
})
|
154
|
+
newManifest.exports = {
|
155
|
+
...resolvedEntrypoints,
|
156
|
+
...exports
|
157
|
+
}
|
158
|
+
if (resolvedOutdir === outdir) {
|
159
|
+
resolvedOutdir = _resolvedOutdir
|
160
|
+
}
|
143
161
|
}
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
162
|
+
if (internalEntrypoints) {
|
163
|
+
const [resolvedInternalEntrypoints, imports, _resolvedOutdir] = resolveExports({
|
164
|
+
entrypoints: internalEntrypoints,
|
165
|
+
defaultOutdir: `${outdir}/.internal`,
|
166
|
+
...commonOptions
|
167
|
+
})
|
168
|
+
newManifest.imports = {
|
169
|
+
...resolvedInternalEntrypoints,
|
170
|
+
...imports
|
171
|
+
}
|
172
|
+
if (resolvedOutdir === outdir) {
|
173
|
+
resolvedOutdir = _resolvedOutdir
|
174
|
+
}
|
152
175
|
}
|
153
176
|
return [newManifest, resolvedOutdir] as const
|
154
177
|
}
|
155
178
|
|
156
179
|
const generateNewPackageJSONString = ({
|
180
|
+
config,
|
157
181
|
oldJSONString,
|
158
182
|
oldJSON,
|
159
183
|
manifest,
|
160
184
|
formattingOptions
|
161
185
|
}: {
|
186
|
+
config: Config
|
162
187
|
oldJSONString: string
|
163
188
|
oldJSON: Record<string, unknown>
|
164
189
|
manifest: NonNullable<ProjectsGraph['value']>[string]
|
@@ -188,11 +213,13 @@ async function prepublish({ bumper }: {
|
|
188
213
|
]
|
189
214
|
}
|
190
215
|
})
|
191
|
-
|
192
|
-
|
193
|
-
'
|
194
|
-
|
195
|
-
|
216
|
+
if (config.experimental?.importsDowngrade) {
|
217
|
+
update(['dependencies', internalModuleName], `file:./${outdir}/.internal`)
|
218
|
+
update(['dependenciesMeta', internalModuleName], {
|
219
|
+
'injected': true
|
220
|
+
})
|
221
|
+
update(['imports'], undefined)
|
222
|
+
}
|
196
223
|
|
197
224
|
for (const [key, value] of Object.entries(manifest)) {
|
198
225
|
if (key === 'version') continue
|
@@ -301,7 +328,8 @@ async function prepublish({ bumper }: {
|
|
301
328
|
}
|
302
329
|
|
303
330
|
await forEachSelectedProjectsGraphEntries((dir, originalManifest) => {
|
304
|
-
const
|
331
|
+
const config = loadConfig(dir)
|
332
|
+
const [manifest, resolvedOutdir] = generateNewManifest(dir, originalManifest, config)
|
305
333
|
const resolveByDir = (...paths: string[]) => path.resolve(dir, ...paths)
|
306
334
|
|
307
335
|
const oldJSONString = fs.readFileSync(resolveByDir('package.json'), 'utf-8')
|
@@ -326,6 +354,7 @@ async function prepublish({ bumper }: {
|
|
326
354
|
)
|
327
355
|
|
328
356
|
const newJSONString = generateNewPackageJSONString({
|
357
|
+
config,
|
329
358
|
oldJSONString: modifyVersionPackageJSON,
|
330
359
|
oldJSON: {
|
331
360
|
...oldJSON,
|
@@ -467,18 +496,7 @@ async function prepublish({ bumper }: {
|
|
467
496
|
throw new Error(`file type of ${path} is not supported`)
|
468
497
|
}
|
469
498
|
|
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
|
-
})
|
499
|
+
if (config.experimental?.importsDowngrade && 'imports' in manifest && manifest.imports) {
|
482
500
|
fs.writeFileSync(
|
483
501
|
resolveByDir(resolvedOutdir, resolvedOutdir, '.internal', 'package.json'),
|
484
502
|
JSON.stringify(
|
@@ -488,7 +506,7 @@ async function prepublish({ bumper }: {
|
|
488
506
|
JSON
|
489
507
|
.stringify(manifest.imports)
|
490
508
|
.replaceAll('#', './')
|
491
|
-
.replaceAll('~', '
|
509
|
+
.replaceAll('~', '')
|
492
510
|
) as Record<string, unknown>
|
493
511
|
},
|
494
512
|
null,
|
@@ -496,6 +514,11 @@ async function prepublish({ bumper }: {
|
|
496
514
|
)
|
497
515
|
)
|
498
516
|
}
|
517
|
+
|
518
|
+
const jiekProductionTag = path.resolve(resolvedOutdir, '.jiek-production-tag')
|
519
|
+
if (!fs.existsSync(jiekProductionTag)) {
|
520
|
+
fs.writeFileSync(jiekProductionTag, '')
|
521
|
+
}
|
499
522
|
})
|
500
523
|
}
|
501
524
|
|
package/src/index.ts
CHANGED
@@ -2,6 +2,11 @@ import type {} from './commands/base'
|
|
2
2
|
import type {} from './commands/build'
|
3
3
|
import type {} from './commands/publish'
|
4
4
|
|
5
|
-
export interface
|
5
|
+
export interface ConfigExperimental {
|
6
|
+
}
|
7
|
+
|
8
|
+
export interface Config {
|
9
|
+
experimental?: ConfigExperimental
|
10
|
+
}
|
6
11
|
|
7
12
|
export const defineConfig = (config: Config) => config
|
package/src/rollup/index.ts
CHANGED
@@ -105,7 +105,7 @@ const MINIFY_OPTIONS = {
|
|
105
105
|
const config = loadConfig({
|
106
106
|
root: WORKSPACE_ROOT
|
107
107
|
}) ?? {}
|
108
|
-
const { build = {} } = config
|
108
|
+
const { experimental, build = {} } = config
|
109
109
|
const { js: jsOutdir, dts: dtsOutdir } = getOutDirs({
|
110
110
|
config,
|
111
111
|
pkgName: JIEK_NAME
|
@@ -120,7 +120,7 @@ const STYLE_REGEXP = /\.(css|s[ac]ss|less|styl)$/
|
|
120
120
|
|
121
121
|
const CWD_FILES = recursiveListFiles(process.cwd())
|
122
122
|
.filter(p => /(?<!\.d)\.[cm]?tsx?$/.test(p))
|
123
|
-
.map(p => relative(process.cwd(), p))
|
123
|
+
.map(p => `./${relative(process.cwd(), p)}`)
|
124
124
|
|
125
125
|
const resolveBuildPlugins = (context: ConfigGenerateContext, plugins: TemplateOptions['plugins']): {
|
126
126
|
js: InputPluginOption
|
@@ -253,6 +253,12 @@ const withMinify = (
|
|
253
253
|
: (() => {
|
254
254
|
throw new Error('entryFileNames must be a function')
|
255
255
|
})(),
|
256
|
+
chunkFileNames: chunkInfo =>
|
257
|
+
typeof output.chunkFileNames === 'function'
|
258
|
+
? output.chunkFileNames(chunkInfo).replace(/(\.[cm]?js)$/, '.min$1')
|
259
|
+
: (() => {
|
260
|
+
throw new Error('chunkFileNames must be a function')
|
261
|
+
})(),
|
256
262
|
file: output.file?.replace(/(\.[cm]?js)$/, '.min$1'),
|
257
263
|
plugins: [
|
258
264
|
...notOnlyOncePlugins,
|
@@ -380,7 +386,7 @@ const generateConfigs = (
|
|
380
386
|
'input should not include "**", please read the [documentation](https://nodejs.org/api/packages.html#subpath-patterns).'
|
381
387
|
)
|
382
388
|
}
|
383
|
-
const reg = new RegExp(
|
389
|
+
const reg = new RegExp(`^\./${
|
384
390
|
input
|
385
391
|
.slice(2)
|
386
392
|
.replace(/\./g, '\\.')
|
@@ -390,14 +396,14 @@ const generateConfigs = (
|
|
390
396
|
? input
|
391
397
|
: CWD_FILES.filter(p => reg.test(p))
|
392
398
|
const globCommonDir = input.includes('*')
|
393
|
-
? input.split('*')[0]
|
399
|
+
? input.split('*')[0]
|
394
400
|
: ''
|
395
|
-
const
|
396
|
-
?
|
401
|
+
const outputCommonDir = output.includes('*')
|
402
|
+
? output.split('*')[0]
|
397
403
|
: ''
|
398
404
|
if (
|
399
|
-
(globCommonDir.length > 0 &&
|
400
|
-
|| (globCommonDir.length === 0 &&
|
405
|
+
(globCommonDir.length > 0 && outputCommonDir.length === 0)
|
406
|
+
|| (globCommonDir.length === 0 && outputCommonDir.length > 0)
|
401
407
|
) {
|
402
408
|
throw new Error('input and path should both include "*" or not include "*"')
|
403
409
|
}
|
@@ -429,11 +435,13 @@ const generateConfigs = (
|
|
429
435
|
if (!resolved || !('id' in resolved)) {
|
430
436
|
throw new Error('nodeResolvePluginInstance.resolveId.handler did not return a resolved object')
|
431
437
|
}
|
432
|
-
internalModuleCollect?.(relative(process.cwd(), resolved.id))
|
438
|
+
internalModuleCollect?.(`./${relative(process.cwd(), resolved.id)}`)
|
433
439
|
return {
|
434
|
-
id:
|
435
|
-
|
436
|
-
|
440
|
+
id: experimental?.importsDowngrade
|
441
|
+
? source
|
442
|
+
.replaceAll('#', `${INTERNAL_MODULE_NAME}/`)
|
443
|
+
.replaceAll('~', '+')
|
444
|
+
: source,
|
437
445
|
external: true
|
438
446
|
}
|
439
447
|
}
|
@@ -526,10 +534,15 @@ const generateConfigs = (
|
|
526
534
|
entryFileNames: (chunkInfo) => {
|
527
535
|
return Array.isArray(inputObj)
|
528
536
|
? chunkInfo.facadeModuleId!
|
529
|
-
.replace(`${process.cwd()}/`, '')
|
530
|
-
.replace(globCommonDir,
|
537
|
+
.replace(`${process.cwd()}/`, './')
|
538
|
+
.replace(globCommonDir, outputCommonDir)
|
531
539
|
.replace(/(\.[cm]?)ts$/, jsOutputSuffix)
|
532
|
-
|
540
|
+
.replace(`${jsOutdir}/`, '')
|
541
|
+
: output
|
542
|
+
.replace(`${jsOutdir}/`, '')
|
543
|
+
},
|
544
|
+
chunkFileNames: (chunkInfo) => {
|
545
|
+
return `.internal/.chunks/${chunkInfo.name}.[hash]${jsOutputSuffix}`
|
533
546
|
},
|
534
547
|
sourcemap,
|
535
548
|
format,
|
@@ -589,12 +602,14 @@ const generateConfigs = (
|
|
589
602
|
sourcemap,
|
590
603
|
entryFileNames: (chunkInfo) => (
|
591
604
|
Array.isArray(inputObj)
|
592
|
-
? chunkInfo.facadeModuleId
|
593
|
-
.replace(
|
605
|
+
? chunkInfo.facadeModuleId!
|
606
|
+
.replace(`${process.cwd()}/`, './')
|
607
|
+
.replace(globCommonDir, outputCommonDir)
|
594
608
|
.replace(/(\.[cm]?)ts$/, tsOutputSuffix)
|
595
|
-
: output
|
596
609
|
.replace(`${jsOutdir}/`, '')
|
610
|
+
: output
|
597
611
|
.replace(/(\.[cm]?)js$/, tsOutputSuffix)
|
612
|
+
.replace(`${jsOutdir}/`, '')
|
598
613
|
),
|
599
614
|
strict: typeof buildOptions?.output?.strict === 'object'
|
600
615
|
? buildOptions.output.strict.dts
|
@@ -772,24 +787,12 @@ export function template(packageJSON: PackageJSON): RollupOptions[] {
|
|
772
787
|
async options(inputOptions) {
|
773
788
|
await collected.promise
|
774
789
|
inputOptions.input = [...intersection(
|
775
|
-
inputOptions.input
|
790
|
+
Array.isArray(inputOptions.input)
|
791
|
+
? inputOptions.input
|
792
|
+
: [inputOptions.input as string],
|
776
793
|
internalModules
|
777
794
|
)]
|
778
795
|
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
796
|
}
|
794
797
|
}
|
795
798
|
],
|
@@ -1,201 +0,0 @@
|
|
1
|
-
'use strict';
|
2
|
-
|
3
|
-
var optionParser = require('../utils/optionParser.cjs');
|
4
|
-
var checkDependency = require('../../utils/checkDependency.cjs');
|
5
|
-
var fs = require('node:fs');
|
6
|
-
var path = require('node:path');
|
7
|
-
require('../../../jiek_create-require-CWFWNQHj.js');
|
8
|
-
require('node:child_process');
|
9
|
-
require('node:process');
|
10
|
-
require('@inquirer/prompts');
|
11
|
-
require('../../../getWD-BRJ3PK1S.js');
|
12
|
-
require('@jiek/utils/getWorkspaceDir');
|
13
|
-
require('commander');
|
14
|
-
require('js-yaml');
|
15
|
-
require('../../utils/getRoot.cjs');
|
16
|
-
|
17
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
18
|
-
|
19
|
-
var path__default = /*#__PURE__*/_interopDefault(path);
|
20
|
-
|
21
|
-
function Main() {
|
22
|
-
const { useState, useMemo, useEffect, useCallback } = React;
|
23
|
-
const [path, setPath] = useState(() => location.pathname.replace(/^\/ana\/?/, ""));
|
24
|
-
const [pkgName, entry] = useMemo(() => {
|
25
|
-
const pkgName2 = /^(@[^/]+\/[^/]+|[^/]+)\/?/.exec(path)?.[1];
|
26
|
-
return [
|
27
|
-
pkgName2,
|
28
|
-
pkgName2 != null ? path.replace(`${pkgName2}/`, "") : void 0
|
29
|
-
];
|
30
|
-
}, [path]);
|
31
|
-
const push = useCallback((newPath) => {
|
32
|
-
setPath(newPath);
|
33
|
-
document.title = `${document.title.replace(/ - \/.*/, "")} - /${newPath}`;
|
34
|
-
history.pushState(null, "", `/ana/${newPath}`);
|
35
|
-
}, []);
|
36
|
-
const filterModules = useCallback((startWith) => {
|
37
|
-
const modules = analyzeModule.filter((m) => m.filename.startsWith(startWith));
|
38
|
-
dispatchEvent(new CustomEvent("send:filter", { detail: { analyzeModule: modules } }));
|
39
|
-
}, []);
|
40
|
-
useEffect(() => {
|
41
|
-
if (path !== "") {
|
42
|
-
document.title = `${document.title.replace(/ - \/.*/, "")} - /${path}`;
|
43
|
-
} else {
|
44
|
-
document.title = document.title.replace(/ - \/.*/, "");
|
45
|
-
}
|
46
|
-
filterModules(path);
|
47
|
-
}, [path, filterModules]);
|
48
|
-
useEffect(() => {
|
49
|
-
const offGraphClick = listen("graph:click", ({ detail }) => {
|
50
|
-
if (!detail) return;
|
51
|
-
let root = detail.node;
|
52
|
-
while (root.parent) {
|
53
|
-
root = root.parent;
|
54
|
-
}
|
55
|
-
if (root.filename === path) return;
|
56
|
-
push(root.filename);
|
57
|
-
});
|
58
|
-
return () => {
|
59
|
-
offGraphClick();
|
60
|
-
};
|
61
|
-
}, [push]);
|
62
|
-
function listen(type, listener) {
|
63
|
-
window.addEventListener(type, listener);
|
64
|
-
return () => {
|
65
|
-
window.removeEventListener(type, listener);
|
66
|
-
};
|
67
|
-
}
|
68
|
-
return /* @__PURE__ */ React.createElement(
|
69
|
-
"div",
|
70
|
-
{
|
71
|
-
style: {
|
72
|
-
padding: "12px 55px"
|
73
|
-
}
|
74
|
-
},
|
75
|
-
"/",
|
76
|
-
/* @__PURE__ */ React.createElement(
|
77
|
-
"select",
|
78
|
-
{
|
79
|
-
style: {
|
80
|
-
appearance: "none",
|
81
|
-
border: "none",
|
82
|
-
background: "none"
|
83
|
-
},
|
84
|
-
value: pkgName,
|
85
|
-
onChange: (e) => push(e.target.value)
|
86
|
-
},
|
87
|
-
/* @__PURE__ */ React.createElement("option", { value: "" }, "All"),
|
88
|
-
analyzeModule.map((m) => /^(@[^/]+\/[^/]+|[^/]+)\/?/.exec(m.filename)?.[1]).filter((v, i, a) => a.indexOf(v) === i).map((v) => /* @__PURE__ */ React.createElement("option", { key: v, value: v }, v))
|
89
|
-
),
|
90
|
-
pkgName != null && /* @__PURE__ */ React.createElement(React.Fragment, null, "/", /* @__PURE__ */ React.createElement(
|
91
|
-
"select",
|
92
|
-
{
|
93
|
-
style: {
|
94
|
-
appearance: "none",
|
95
|
-
border: "none",
|
96
|
-
background: "none"
|
97
|
-
},
|
98
|
-
value: entry,
|
99
|
-
onChange: (e) => push(`${pkgName}/${e.target.value}`)
|
100
|
-
},
|
101
|
-
/* @__PURE__ */ React.createElement("option", { value: "" }, "All"),
|
102
|
-
analyzeModule.filter((m) => m.filename.startsWith(`${pkgName}/`)).map((m) => m.filename.replace(`${pkgName}/`, "")).filter((v, i, a) => a.indexOf(v) === i).map((v) => /* @__PURE__ */ React.createElement("option", { key: v, value: v }, v))
|
103
|
-
))
|
104
|
-
);
|
105
|
-
}
|
106
|
-
|
107
|
-
function render() {
|
108
|
-
CUSTOM_SIDE_BAR = true;
|
109
|
-
window.addEventListener("client:ready", () => window.dispatchEvent(
|
110
|
-
new CustomEvent("send:ui", {
|
111
|
-
detail: { type: "Main", Component: __REPLACE_INJECT__ }
|
112
|
-
})
|
113
|
-
));
|
114
|
-
}
|
115
|
-
const CLIENT_CUSTOM_RENDER_SCRIPT = [
|
116
|
-
Main.toString(),
|
117
|
-
render.toString().replace("__REPLACE_INJECT__", Main.name),
|
118
|
-
`(${render.name})()`
|
119
|
-
].join("\n");
|
120
|
-
|
121
|
-
const registerAnalyzerCommandOptions = (command) => command.option("--ana", "Enable the bundle analyzer.", optionParser.parseBoolean).option("--ana.dir <DIR>", "The directory of the bundle analyzer.", ".jk-analyses").option(
|
122
|
-
"--ana.mode <MODE>",
|
123
|
-
'The mode of the bundle analyzer, support "static", "json" and "server".',
|
124
|
-
"server"
|
125
|
-
).option("--ana.open", "Open the bundle analyzer in the browser.", optionParser.parseBoolean).option(
|
126
|
-
"--ana.size <SIZE>",
|
127
|
-
'The default size of the bundle analyzer, support "stat", "parsed" and "gzip".',
|
128
|
-
"parsed"
|
129
|
-
);
|
130
|
-
const useAnalyzer = async (options, server) => {
|
131
|
-
const modules = [];
|
132
|
-
let bundleAnalyzerModule;
|
133
|
-
const analyzer = options.ana ? {
|
134
|
-
dir: options["ana.dir"],
|
135
|
-
mode: options["ana.mode"],
|
136
|
-
open: options["ana.open"],
|
137
|
-
size: options["ana.size"]
|
138
|
-
} : void 0;
|
139
|
-
if (options.ana && ![
|
140
|
-
"stat",
|
141
|
-
"parsed",
|
142
|
-
"gzip"
|
143
|
-
].includes(analyzer?.size ?? "")) {
|
144
|
-
throw new Error('The value of `ana.size` must be "stat", "parsed" or "gzip"');
|
145
|
-
}
|
146
|
-
if (analyzer) {
|
147
|
-
await checkDependency.checkDependency("vite-bundle-analyzer");
|
148
|
-
bundleAnalyzerModule = await import('vite-bundle-analyzer');
|
149
|
-
}
|
150
|
-
const refreshAnalyzer = async (cwd, applyModules) => {
|
151
|
-
if (!(analyzer && server && bundleAnalyzerModule)) return;
|
152
|
-
if (analyzer.mode === "json") {
|
153
|
-
const anaDir = path__default.default.resolve(cwd, analyzer.dir);
|
154
|
-
if (!fs.existsSync(anaDir)) {
|
155
|
-
fs.mkdirSync(anaDir, { recursive: true });
|
156
|
-
}
|
157
|
-
const gitIgnorePath = path__default.default.resolve(anaDir, ".gitignore");
|
158
|
-
if (!fs.existsSync(gitIgnorePath)) {
|
159
|
-
fs.writeFileSync(gitIgnorePath, "*\n!.gitignore\n");
|
160
|
-
}
|
161
|
-
const npmIgnorePath = path__default.default.resolve(anaDir, ".npmignore");
|
162
|
-
if (!fs.existsSync(npmIgnorePath)) {
|
163
|
-
fs.writeFileSync(npmIgnorePath, "*\n");
|
164
|
-
}
|
165
|
-
if (!fs.statSync(anaDir).isDirectory()) {
|
166
|
-
throw new Error(`The directory '${anaDir}' is not a directory.`);
|
167
|
-
}
|
168
|
-
}
|
169
|
-
const { renderView, injectHTMLTag } = bundleAnalyzerModule;
|
170
|
-
applyModules.forEach((m) => {
|
171
|
-
const index = modules.findIndex(({ filename }) => filename === m.filename);
|
172
|
-
if (index === -1) {
|
173
|
-
modules.push(m);
|
174
|
-
} else {
|
175
|
-
modules[index] = m;
|
176
|
-
}
|
177
|
-
});
|
178
|
-
let html = await renderView(modules, {
|
179
|
-
title: `Jiek Analyzer`,
|
180
|
-
mode: analyzer.size
|
181
|
-
});
|
182
|
-
html = injectHTMLTag({
|
183
|
-
html,
|
184
|
-
injectTo: "body",
|
185
|
-
descriptors: [
|
186
|
-
{ kind: "script", text: CLIENT_CUSTOM_RENDER_SCRIPT }
|
187
|
-
]
|
188
|
-
});
|
189
|
-
void server.renderTo("/ana", html);
|
190
|
-
};
|
191
|
-
return {
|
192
|
-
modules,
|
193
|
-
refreshAnalyzer,
|
194
|
-
ANALYZER_ENV: {
|
195
|
-
JIEK_ANALYZER: analyzer ? JSON.stringify(analyzer) : void 0
|
196
|
-
}
|
197
|
-
};
|
198
|
-
};
|
199
|
-
|
200
|
-
exports.registerAnalyzerCommandOptions = registerAnalyzerCommandOptions;
|
201
|
-
exports.useAnalyzer = useAnalyzer;
|
@@ -1,30 +0,0 @@
|
|
1
|
-
import * as vite_bundle_analyzer from 'vite-bundle-analyzer';
|
2
|
-
import { Command } from 'commander';
|
3
|
-
import { createServer } from '../../server.cjs';
|
4
|
-
|
5
|
-
interface AnalyzerBuildOptions {
|
6
|
-
ana?: boolean;
|
7
|
-
/**
|
8
|
-
* @default '.jk-analyses'
|
9
|
-
*/
|
10
|
-
'ana.dir': string;
|
11
|
-
/**
|
12
|
-
* @default 'server'
|
13
|
-
*/
|
14
|
-
'ana.mode': string;
|
15
|
-
'ana.open'?: boolean;
|
16
|
-
/**
|
17
|
-
* @default 'parsed'
|
18
|
-
*/
|
19
|
-
'ana.size': string;
|
20
|
-
}
|
21
|
-
declare const registerAnalyzerCommandOptions: (command: Command) => Command;
|
22
|
-
declare const useAnalyzer: (options: AnalyzerBuildOptions, server?: ReturnType<typeof createServer>) => Promise<{
|
23
|
-
modules: vite_bundle_analyzer.Module[];
|
24
|
-
refreshAnalyzer: (cwd: string, applyModules: vite_bundle_analyzer.Module[]) => Promise<void>;
|
25
|
-
ANALYZER_ENV: {
|
26
|
-
JIEK_ANALYZER: string | undefined;
|
27
|
-
};
|
28
|
-
}>;
|
29
|
-
|
30
|
-
export { type AnalyzerBuildOptions, registerAnalyzerCommandOptions, useAnalyzer };
|
@@ -1,30 +0,0 @@
|
|
1
|
-
import * as vite_bundle_analyzer from 'vite-bundle-analyzer';
|
2
|
-
import { Command } from 'commander';
|
3
|
-
import { createServer } from '../../server.js';
|
4
|
-
|
5
|
-
interface AnalyzerBuildOptions {
|
6
|
-
ana?: boolean;
|
7
|
-
/**
|
8
|
-
* @default '.jk-analyses'
|
9
|
-
*/
|
10
|
-
'ana.dir': string;
|
11
|
-
/**
|
12
|
-
* @default 'server'
|
13
|
-
*/
|
14
|
-
'ana.mode': string;
|
15
|
-
'ana.open'?: boolean;
|
16
|
-
/**
|
17
|
-
* @default 'parsed'
|
18
|
-
*/
|
19
|
-
'ana.size': string;
|
20
|
-
}
|
21
|
-
declare const registerAnalyzerCommandOptions: (command: Command) => Command;
|
22
|
-
declare const useAnalyzer: (options: AnalyzerBuildOptions, server?: ReturnType<typeof createServer>) => Promise<{
|
23
|
-
modules: vite_bundle_analyzer.Module[];
|
24
|
-
refreshAnalyzer: (cwd: string, applyModules: vite_bundle_analyzer.Module[]) => Promise<void>;
|
25
|
-
ANALYZER_ENV: {
|
26
|
-
JIEK_ANALYZER: string | undefined;
|
27
|
-
};
|
28
|
-
}>;
|
29
|
-
|
30
|
-
export { type AnalyzerBuildOptions, registerAnalyzerCommandOptions, useAnalyzer };
|