jiek 2.2.7 → 2.3.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.
Files changed (100) hide show
  1. package/bin/build.cjs +2 -0
  2. package/bin/index.cjs +2 -0
  3. package/bin-helper/index.cjs +19 -31
  4. package/dist/.internal/.chunks/filterSupport.4rM7f6jB.cjs +114 -0
  5. package/dist/.internal/.chunks/filterSupport.BXWpLBpT.js +104 -0
  6. package/dist/{cli.js → .internal/.chunks/index.B6RQz1DZ.js} +1 -737
  7. package/dist/.internal/.chunks/index.BHuJRlvZ.js +9059 -0
  8. package/dist/.internal/.chunks/index.Daihq2aI.cjs +9071 -0
  9. package/dist/{cli.cjs → .internal/.chunks/index.DlHFuTjM.cjs} +1 -759
  10. package/dist/.internal/.chunks/loadConfig.CFfzkm_p.js +110 -0
  11. package/dist/.internal/.chunks/loadConfig.OOKddvHF.cjs +117 -0
  12. package/dist/{cli-only-build.cjs → .internal/bin/common.cjs} +229 -445
  13. package/dist/.internal/bin/common.d.cts +22 -0
  14. package/dist/.internal/bin/common.d.ts +22 -0
  15. package/dist/{cli-only-build.js → .internal/bin/common.js} +224 -439
  16. package/dist/.internal/bin/parseArgv.cjs +33 -0
  17. package/dist/.internal/bin/parseArgv.d.cts +5 -0
  18. package/dist/.internal/bin/parseArgv.d.ts +5 -0
  19. package/dist/.internal/bin/parseArgv.js +27 -0
  20. package/dist/.internal/bridge.cjs +30 -0
  21. package/dist/.internal/bridge.d.cts +39 -0
  22. package/dist/.internal/bridge.d.ts +39 -0
  23. package/dist/.internal/bridge.js +27 -0
  24. package/dist/.internal/rollup/base.cjs +10 -0
  25. package/dist/{cli-only-build.d.cts → .internal/rollup/base.d.cts} +8 -15
  26. package/dist/{cli-only-build.d.ts → .internal/rollup/base.d.ts} +8 -15
  27. package/dist/.internal/rollup/base.js +7 -0
  28. package/dist/.internal/rollup/bundle-analyzer.cjs +51 -0
  29. package/dist/.internal/rollup/bundle-analyzer.d.cts +92 -0
  30. package/dist/.internal/rollup/bundle-analyzer.d.ts +92 -0
  31. package/dist/.internal/rollup/bundle-analyzer.js +45 -0
  32. package/dist/.internal/utils/filterSupport.cjs +18 -0
  33. package/dist/.internal/utils/filterSupport.d.cts +15 -0
  34. package/dist/.internal/utils/filterSupport.d.ts +15 -0
  35. package/dist/.internal/utils/filterSupport.js +8 -0
  36. package/dist/.internal/utils/getInternalModuleName.cjs +5 -0
  37. package/dist/.internal/utils/getInternalModuleName.d.cts +3 -0
  38. package/dist/.internal/utils/getInternalModuleName.d.ts +3 -0
  39. package/dist/.internal/utils/getInternalModuleName.js +3 -0
  40. package/dist/.internal/utils/intersection.cjs +5 -0
  41. package/dist/.internal/utils/intersection.d.cts +3 -0
  42. package/dist/.internal/utils/intersection.d.ts +3 -0
  43. package/dist/.internal/utils/intersection.js +3 -0
  44. package/dist/.internal/utils/loadConfig.cjs +14 -0
  45. package/dist/.internal/utils/loadConfig.d.cts +10 -0
  46. package/dist/.internal/utils/loadConfig.d.ts +10 -0
  47. package/dist/.internal/utils/loadConfig.js +9 -0
  48. package/dist/.internal/utils/recursiveListFiles.cjs +19 -0
  49. package/dist/.internal/utils/recursiveListFiles.d.cts +3 -0
  50. package/dist/.internal/utils/recursiveListFiles.d.ts +3 -0
  51. package/dist/.internal/utils/recursiveListFiles.js +13 -0
  52. package/dist/.internal/utils/resolveExports.cjs +124 -0
  53. package/dist/.internal/utils/resolveExports.d.cts +27 -0
  54. package/dist/.internal/utils/resolveExports.d.ts +27 -0
  55. package/dist/.internal/utils/resolveExports.js +117 -0
  56. package/dist/.internal/utils/ts.cjs +68 -0
  57. package/dist/.internal/utils/ts.d.cts +3 -0
  58. package/dist/.internal/utils/ts.d.ts +3 -0
  59. package/dist/.internal/utils/ts.js +62 -0
  60. package/dist/bin/build.cjs +10 -0
  61. package/dist/bin/index.cjs +522 -0
  62. package/dist/index.d.cts +16 -114
  63. package/dist/index.d.ts +16 -114
  64. package/dist/rollup/index.cjs +310 -4573
  65. package/dist/rollup/index.d.cts +7 -1
  66. package/dist/rollup/index.d.ts +7 -1
  67. package/dist/rollup/index.js +298 -4558
  68. package/package.json +16 -24
  69. package/src/bin/build.cts +5 -0
  70. package/src/bin/common.ts +3 -0
  71. package/src/bin/index.cts +7 -0
  72. package/src/bridge.ts +1 -1
  73. package/src/commands/base.ts +3 -3
  74. package/src/commands/build/analyzer.ts +5 -5
  75. package/src/commands/build/client/analyzer.tsx +1 -1
  76. package/src/commands/build/client/index.ts +5 -7
  77. package/src/commands/build.ts +244 -213
  78. package/src/commands/meta.ts +1 -1
  79. package/src/commands/publish.ts +190 -78
  80. package/src/index.ts +6 -1
  81. package/src/rollup/base.ts +2 -2
  82. package/src/rollup/index.ts +361 -124
  83. package/src/rollup/plugins/with-external.ts +23 -0
  84. package/src/rollup/utils/externalResolver.ts +20 -8
  85. package/src/utils/checkDependency.ts +1 -1
  86. package/src/utils/filterSupport.ts +17 -16
  87. package/src/utils/getInternalModuleName.ts +5 -0
  88. package/src/utils/intersection.ts +1 -0
  89. package/src/utils/{recusiveListFiles.ts → recursiveListFiles.ts} +2 -2
  90. package/src/utils/{getExports.ts → resolveExports.ts} +28 -19
  91. package/bin/jiek-build.js +0 -16
  92. package/bin/jiek.js +0 -13
  93. package/cli/package.json +0 -1
  94. package/cli-only-build/package.json +0 -1
  95. package/dist/cli.d.cts +0 -14
  96. package/dist/cli.d.ts +0 -14
  97. package/src/cli-only-build.ts +0 -11
  98. package/src/cli.ts +0 -6
  99. /package/{src/bin/build.ts → .jiek-production-tag} +0 -0
  100. /package/src/{parseArgv.ts → bin/parseArgv.ts} +0 -0
@@ -5,17 +5,29 @@ import path from 'node:path'
5
5
  import process from 'node:process'
6
6
 
7
7
  import { type BumperType, TAGS, bump } from '@jiek/utils/bumper'
8
- import { program } from 'commander'
8
+ import { type Command, program } from 'commander'
9
9
  import detectIndent from 'detect-indent'
10
+ import type { Config } from 'jiek'
11
+ import type { JSONPath } from 'jsonc-parser'
10
12
  import { applyEdits, modify } from 'jsonc-parser'
11
13
 
12
- import type { ProjectsGraph } from '../utils/filterSupport'
13
- import { getSelectedProjectsGraph } from '../utils/filterSupport'
14
- import { getExports } from '../utils/getExports'
15
- import { loadConfig } from '../utils/loadConfig'
14
+ import type { ProjectsGraph } from '#~/utils/filterSupport'
15
+ import { getSelectedProjectsGraph } from '#~/utils/filterSupport'
16
+ import { loadConfig } from '#~/utils/loadConfig'
17
+ import type { ResolveExportsOptions } from '#~/utils/resolveExports'
18
+ import { resolveExports } from '#~/utils/resolveExports'
19
+
20
+ import { getInternalModuleName } from '#~/utils/getInternalModuleName'
16
21
  import { outdirDescription } from './descriptions'
17
22
 
18
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
+ }
19
31
  export interface Config {
20
32
  publish?: {
21
33
  /**
@@ -48,17 +60,33 @@ async function forEachSelectedProjectsGraphEntries(
48
60
  }
49
61
  }
50
62
 
51
- program
52
- .command('publish')
53
- .description(description)
54
- .aliases(['pub', 'p'])
55
- .option('-b, --bumper <bumper>', 'bump version', 'patch')
56
- .option('-no-b, --no-bumper', 'no bump version')
57
- .option('-o, --outdir <OUTDIR>', outdirDescription, String, 'dist')
58
- .action(async ({ outdir, bumper }: {
59
- outdir?: string
60
- bumper: false | BumperType
61
- }) => {
63
+ interface PublishOptions {
64
+ outdir?: string
65
+ bumper: false | BumperType
66
+ /**
67
+ * Skip entries which end with '.js'.
68
+ */
69
+ skipJS: boolean
70
+ }
71
+
72
+ const attachPublishOptions = (command: Command) =>
73
+ command
74
+ .option('-b, --bumper <bumper>', 'bump version', 'patch')
75
+ .option('-no-b, --no-bumper', 'no bump version')
76
+ .option('-o, --outdir <OUTDIR>', outdirDescription, String, 'dist')
77
+ .option('--skipJS', 'skip entries which end with ".js"')
78
+
79
+ attachPublishOptions(
80
+ program
81
+ .command('publish')
82
+ .description(description)
83
+ .aliases(['pub', 'p'])
84
+ )
85
+ .action(async ({
86
+ outdir,
87
+ bumper,
88
+ skipJS
89
+ }: PublishOptions) => {
62
90
  let shouldPassThrough = false
63
91
 
64
92
  const passThroughOptions = process.argv
@@ -87,18 +115,21 @@ program
87
115
  env: {
88
116
  ...process.env,
89
117
  JIEK_PUBLISH_OUTDIR: JSON.stringify(outdir),
90
- JIEK_PUBLISH_BUMPER: JSON.stringify(bumper)
118
+ JIEK_PUBLISH_BUMPER: JSON.stringify(bumper),
119
+ JIEK_PUBLISH_SKIP_JS: JSON.stringify(skipJS)
91
120
  }
92
121
  })
93
122
  })
94
123
  })
95
124
 
96
- async function prepublish({ bumper }: {
97
- bumper?: boolean | BumperType
98
- } = {}) {
125
+ async function prepublish({
126
+ bumper,
127
+ skipJS
128
+ }: PublishOptions) {
99
129
  const {
100
130
  JIEK_PUBLISH_OUTDIR: outdirEnv,
101
- JIEK_PUBLISH_BUMPER: bumperEnv
131
+ JIEK_PUBLISH_BUMPER: bumperEnv,
132
+ JIEK_PUBLISH_SKIP_JS: skipJSEnv
102
133
  } = process.env
103
134
  const outdir = outdirEnv
104
135
  ? JSON.parse(outdirEnv) as string
@@ -106,38 +137,76 @@ async function prepublish({ bumper }: {
106
137
  bumper = bumper ?? (
107
138
  bumperEnv ? JSON.parse(bumperEnv) as string | boolean : false
108
139
  )
140
+ skipJS = skipJS ?? (
141
+ skipJSEnv ? JSON.parse(skipJSEnv) as boolean : undefined
142
+ )
109
143
 
110
- const generateNewManifest = (dir: string, manifest: NonNullable<ProjectsGraph['value']>[string]) => {
111
- const { name, type, exports: entrypoints = {} } = manifest
144
+ const generateNewManifest = (
145
+ dir: string,
146
+ manifest: NonNullable<ProjectsGraph['value']>[string],
147
+ config: Config
148
+ ) => {
149
+ const {
150
+ name,
151
+ type,
152
+ exports: entrypoints,
153
+ imports: internalEntrypoints
154
+ } = manifest
112
155
  if (!name) {
113
156
  throw new Error(`package.json in ${dir} must have a name field`)
114
157
  }
115
158
 
116
159
  const pkgIsModule = type === 'module'
117
160
  const newManifest = { ...manifest }
118
- const [resolvedEntrypoints, exports, resolvedOutdir] = getExports({
119
- entrypoints,
161
+ const commonOptions = {
120
162
  pkgIsModule,
121
163
  pkgName: name,
122
- config: loadConfig(dir),
164
+ config,
123
165
  dir,
124
- defaultOutdir: outdir,
125
166
  noFilter: true,
126
- isPublish: true
127
- })
128
- newManifest.exports = {
129
- ...resolvedEntrypoints,
130
- ...exports
167
+ isPublish: true,
168
+ skipJS: skipJS ?? config.skipJS
169
+ } satisfies Partial<ResolveExportsOptions>
170
+ let resolvedOutdir = outdir
171
+ if (entrypoints) {
172
+ const [resolvedEntrypoints, exports, _resolvedOutdir] = resolveExports({
173
+ entrypoints,
174
+ defaultOutdir: outdir,
175
+ ...commonOptions
176
+ })
177
+ newManifest.exports = {
178
+ ...resolvedEntrypoints,
179
+ ...exports
180
+ }
181
+ if (resolvedOutdir === outdir) {
182
+ resolvedOutdir = _resolvedOutdir
183
+ }
184
+ }
185
+ if (internalEntrypoints) {
186
+ const [resolvedInternalEntrypoints, imports, _resolvedOutdir] = resolveExports({
187
+ entrypoints: internalEntrypoints,
188
+ defaultOutdir: `${outdir}/.internal`,
189
+ ...commonOptions
190
+ })
191
+ newManifest.imports = {
192
+ ...resolvedInternalEntrypoints,
193
+ ...imports
194
+ }
195
+ if (resolvedOutdir === outdir) {
196
+ resolvedOutdir = _resolvedOutdir
197
+ }
131
198
  }
132
199
  return [newManifest, resolvedOutdir] as const
133
200
  }
134
201
 
135
202
  const generateNewPackageJSONString = ({
203
+ config,
136
204
  oldJSONString,
137
205
  oldJSON,
138
206
  manifest,
139
207
  formattingOptions
140
208
  }: {
209
+ config: Config
141
210
  oldJSONString: string
142
211
  oldJSON: Record<string, unknown>
143
212
  manifest: NonNullable<ProjectsGraph['value']>[string]
@@ -146,26 +215,35 @@ async function prepublish({ bumper }: {
146
215
  insertSpaces: boolean
147
216
  }
148
217
  }) => {
218
+ const internalModuleName = getInternalModuleName(manifest.name!)
219
+
149
220
  let newJSONString = oldJSONString
150
- newJSONString = applyEdits(
151
- newJSONString,
152
- modify(
221
+ const update = (path: JSONPath, value: unknown) => {
222
+ newJSONString = applyEdits(
153
223
  newJSONString,
154
- ['publishConfig', 'typesVersions'],
155
- {
156
- '<5.0': {
157
- '*': [
158
- '*',
159
- `./*`,
160
- `./*/index.d.ts`,
161
- `./*/index.d.mts`,
162
- `./*/index.d.cts`
163
- ]
164
- }
165
- },
166
- { formattingOptions }
224
+ modify(newJSONString, path, value, { formattingOptions })
167
225
  )
168
- )
226
+ }
227
+
228
+ update(['publishConfig', 'typesVersions'], {
229
+ '<5.0': {
230
+ '*': [
231
+ '*',
232
+ './*',
233
+ './*/index.d.ts',
234
+ './*/index.d.mts',
235
+ './*/index.d.cts'
236
+ ]
237
+ }
238
+ })
239
+ if (config.experimental?.importsDowngrade) {
240
+ update(['dependencies', internalModuleName], `file:./${outdir}/.internal`)
241
+ update(['dependenciesMeta', internalModuleName], {
242
+ 'injected': true
243
+ })
244
+ update(['imports'], undefined)
245
+ }
246
+
169
247
  for (const [key, value] of Object.entries(manifest)) {
170
248
  if (key === 'version') continue
171
249
  if (JSON.stringify(value) === JSON.stringify(oldJSON[key])) continue
@@ -273,7 +351,8 @@ async function prepublish({ bumper }: {
273
351
  }
274
352
 
275
353
  await forEachSelectedProjectsGraphEntries((dir, originalManifest) => {
276
- const [manifest, resolvedOutdir] = generateNewManifest(dir, originalManifest)
354
+ const config = loadConfig(dir)
355
+ const [manifest, resolvedOutdir] = generateNewManifest(dir, originalManifest, config)
277
356
  const resolveByDir = (...paths: string[]) => path.resolve(dir, ...paths)
278
357
 
279
358
  const oldJSONString = fs.readFileSync(resolveByDir('package.json'), 'utf-8')
@@ -290,7 +369,7 @@ async function prepublish({ bumper }: {
290
369
  }
291
370
 
292
371
  const newVersion = bumper
293
- ? bump(oldJSON.version, bumper === true ? 'patch' : bumper)
372
+ ? bump(oldJSON.version, bumper)
294
373
  : oldJSON.version
295
374
  const modifyVersionPackageJSON = applyEdits(
296
375
  oldJSONString,
@@ -298,6 +377,7 @@ async function prepublish({ bumper }: {
298
377
  )
299
378
 
300
379
  const newJSONString = generateNewPackageJSONString({
380
+ config,
301
381
  oldJSONString: modifyVersionPackageJSON,
302
382
  oldJSON: {
303
383
  ...oldJSON,
@@ -438,10 +518,35 @@ async function prepublish({ bumper }: {
438
518
  }
439
519
  throw new Error(`file type of ${path} is not supported`)
440
520
  }
521
+
522
+ if (config.experimental?.importsDowngrade && 'imports' in manifest && manifest.imports) {
523
+ fs.writeFileSync(
524
+ resolveByDir(resolvedOutdir, resolvedOutdir, '.internal', 'package.json'),
525
+ JSON.stringify(
526
+ {
527
+ name: getInternalModuleName(manifest.name!),
528
+ exports: JSON.parse(
529
+ JSON
530
+ .stringify(manifest.imports)
531
+ .replaceAll('#', './')
532
+ .replaceAll('~', '')
533
+ ) as Record<string, unknown>
534
+ },
535
+ null,
536
+ 2
537
+ )
538
+ )
539
+ }
540
+
541
+ const jiekProductionTag = path.resolve(resolvedOutdir, '.jiek-production-tag')
542
+ if (!fs.existsSync(jiekProductionTag)) {
543
+ fs.writeFileSync(jiekProductionTag, '')
544
+ }
441
545
  })
442
546
  }
443
547
 
444
- async function postpublish() {
548
+ // eslint-disable-next-line no-empty-pattern
549
+ async function postpublish({}: PublishOptions) {
445
550
  await forEachSelectedProjectsGraphEntries(dir => {
446
551
  const jiekTempDir = path.resolve(dir, 'node_modules/.jiek/.tmp')
447
552
  const packageJSONPath = path.resolve(dir, 'package.json')
@@ -467,24 +572,6 @@ async function postpublish() {
467
572
  })
468
573
  }
469
574
 
470
- program
471
- .action(async () => {
472
- const {
473
- npm_lifecycle_event: NPM_LIFECYCLE_EVENT
474
- } = process.env
475
- // eslint-disable-next-line ts/switch-exhaustiveness-check
476
- switch (NPM_LIFECYCLE_EVENT) {
477
- case 'prepublish':
478
- await prepublish()
479
- break
480
- case 'postpublish':
481
- await postpublish()
482
- break
483
- default:
484
- program.help()
485
- }
486
- })
487
-
488
575
  const prepublishDescription = `
489
576
  Prepare package.json for publish, you can add \`jk\` to the \`prepublish\` script in package.json, the command will automatically run \`jk prepublish\`.
490
577
  .e.g
@@ -494,11 +581,11 @@ Prepare package.json for publish, you can add \`jk\` to the \`prepublish\` scrip
494
581
  }
495
582
  }
496
583
  `.trim()
497
- program
498
- .command('prepublish')
499
- .description(prepublishDescription)
500
- .option('-b, --bumper <bumper>', 'bump version')
501
- .option('-no-b, --no-bumper', 'no bump version')
584
+ attachPublishOptions(
585
+ program
586
+ .command('prepublish')
587
+ .description(prepublishDescription)
588
+ )
502
589
  .action(prepublish)
503
590
 
504
591
  const postpublishDescription = `
@@ -510,7 +597,32 @@ Restore package.json after publish, you can add \`jk\` to the \`postpublish\` sc
510
597
  }
511
598
  }
512
599
  `.trim()
513
- program
514
- .command('postpublish')
515
- .description(postpublishDescription)
600
+ attachPublishOptions(
601
+ program
602
+ .command('postpublish')
603
+ .description(postpublishDescription)
604
+ )
516
605
  .action(postpublish)
606
+
607
+ const {
608
+ npm_lifecycle_event: NPM_LIFECYCLE_EVENT
609
+ } = process.env
610
+
611
+ if (
612
+ NPM_LIFECYCLE_EVENT && [
613
+ 'prepublish',
614
+ 'postpublish'
615
+ ].includes(NPM_LIFECYCLE_EVENT)
616
+ ) {
617
+ attachPublishOptions(program)
618
+ .action(async (options: PublishOptions) => {
619
+ switch (NPM_LIFECYCLE_EVENT) {
620
+ case 'prepublish':
621
+ await prepublish(options)
622
+ break
623
+ case 'postpublish':
624
+ await postpublish(options)
625
+ break
626
+ }
627
+ })
628
+ }
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 Config {}
5
+ export interface ConfigExperimental {
6
+ }
7
+
8
+ export interface Config {
9
+ experimental?: ConfigExperimental
10
+ }
6
11
 
7
12
  export const defineConfig = (config: Config) => config
@@ -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 true
59
+ * @default false
60
60
  */
61
61
  keepImportAttributes?: boolean | 'assert'
62
62
  }