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
@@ -0,0 +1,522 @@
1
+ 'use strict';
2
+
3
+ require('#~/bin/common');
4
+ var childProcess = require('node:child_process');
5
+ var fs = require('node:fs');
6
+ var path = require('node:path');
7
+ var process = require('node:process');
8
+ var bumper = require('@jiek/utils/bumper');
9
+ var commander = require('commander');
10
+ var detectIndent = require('detect-indent');
11
+ var jsoncParser = require('jsonc-parser');
12
+ var filterSupport = require('#~/utils/filterSupport');
13
+ var loadConfig = require('#~/utils/loadConfig');
14
+ var resolveExports = require('#~/utils/resolveExports');
15
+ var getInternalModuleName = require('#~/utils/getInternalModuleName');
16
+ var parseArgv = require('#~/bin/parseArgv');
17
+
18
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
19
+
20
+ function _interopNamespace(e) {
21
+ if (e && e.__esModule) return e;
22
+ var n = Object.create(null);
23
+ if (e) {
24
+ Object.keys(e).forEach(function (k) {
25
+ if (k !== 'default') {
26
+ var d = Object.getOwnPropertyDescriptor(e, k);
27
+ Object.defineProperty(n, k, d.get ? d : {
28
+ enumerable: true,
29
+ get: function () { return e[k]; }
30
+ });
31
+ }
32
+ });
33
+ }
34
+ n.default = e;
35
+ return Object.freeze(n);
36
+ }
37
+
38
+ var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
39
+ var fs__default = /*#__PURE__*/_interopDefault(fs);
40
+ var path__default = /*#__PURE__*/_interopDefault(path);
41
+ var process__default = /*#__PURE__*/_interopDefault(process);
42
+ var detectIndent__default = /*#__PURE__*/_interopDefault(detectIndent);
43
+ var parseArgv__default = /*#__PURE__*/_interopDefault(parseArgv);
44
+
45
+ const outdirDescription = `
46
+ The output directory of the build, which relative to the target subpackage root directory.
47
+ Support with variables: 'PKG_NAME',
48
+ .e.g. 'dist/{{PKG_NAME}}'.
49
+ `.trim();
50
+
51
+ const description = `
52
+ Publish package to npm registry, and auto generate exports field and other fields in published package.json.
53
+ If you want to through the options to the \`pnpm publish\` command, you can pass the options after '--'.
54
+ `.trim();
55
+ async function forEachSelectedProjectsGraphEntries(callback) {
56
+ const { value = {} } = await filterSupport.getSelectedProjectsGraph() ?? {};
57
+ const selectedProjectsGraphEntries = Object.entries(value);
58
+ if (selectedProjectsGraphEntries.length === 0) {
59
+ throw new Error("no packages selected");
60
+ }
61
+ for (const [dir, manifest] of selectedProjectsGraphEntries) {
62
+ callback(dir, manifest);
63
+ }
64
+ }
65
+ const attachPublishOptions = (command) => command.option("-b, --bumper <bumper>", "bump version", "patch").option("-no-b, --no-bumper", "no bump version").option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option("--skipJS", 'skip entries which end with ".js"');
66
+ attachPublishOptions(
67
+ commander.program.command("publish").description(description).aliases(["pub", "p"])
68
+ ).action(async ({
69
+ outdir,
70
+ bumper: bumper$1,
71
+ skipJS
72
+ }) => {
73
+ let shouldPassThrough = false;
74
+ const passThroughOptions = process__default.default.argv.reduce(
75
+ (acc, value) => {
76
+ if (shouldPassThrough) {
77
+ acc.push(value);
78
+ }
79
+ if (value === "--") {
80
+ shouldPassThrough = true;
81
+ }
82
+ return acc;
83
+ },
84
+ []
85
+ );
86
+ await forEachSelectedProjectsGraphEntries((dir) => {
87
+ const args = ["pnpm", "publish", "--access", "public", "--no-git-checks"];
88
+ if (bumper$1 && bumper.TAGS.includes(bumper$1)) {
89
+ args.push("--tag", bumper$1);
90
+ }
91
+ args.push(...passThroughOptions);
92
+ childProcess__namespace.execSync(args.join(" "), {
93
+ cwd: dir,
94
+ stdio: "inherit",
95
+ env: {
96
+ ...process__default.default.env,
97
+ JIEK_PUBLISH_OUTDIR: JSON.stringify(outdir),
98
+ JIEK_PUBLISH_BUMPER: JSON.stringify(bumper$1),
99
+ JIEK_PUBLISH_SKIP_JS: JSON.stringify(skipJS)
100
+ }
101
+ });
102
+ });
103
+ });
104
+ async function prepublish({
105
+ bumper: bumper$1,
106
+ skipJS
107
+ }) {
108
+ const {
109
+ JIEK_PUBLISH_OUTDIR: outdirEnv,
110
+ JIEK_PUBLISH_BUMPER: bumperEnv,
111
+ JIEK_PUBLISH_SKIP_JS: skipJSEnv
112
+ } = process__default.default.env;
113
+ const outdir = outdirEnv ? JSON.parse(outdirEnv) : "dist";
114
+ bumper$1 = bumper$1 ?? (bumperEnv ? JSON.parse(bumperEnv) : false);
115
+ skipJS = skipJS ?? (skipJSEnv ? JSON.parse(skipJSEnv) : void 0);
116
+ const generateNewManifest = (dir, manifest, config) => {
117
+ const {
118
+ name,
119
+ type,
120
+ exports: entrypoints,
121
+ imports: internalEntrypoints
122
+ } = manifest;
123
+ if (!name) {
124
+ throw new Error(`package.json in ${dir} must have a name field`);
125
+ }
126
+ const pkgIsModule = type === "module";
127
+ const newManifest = { ...manifest };
128
+ const commonOptions = {
129
+ pkgIsModule,
130
+ pkgName: name,
131
+ config,
132
+ dir,
133
+ noFilter: true,
134
+ isPublish: true,
135
+ skipJS: skipJS ?? config.skipJS
136
+ };
137
+ let resolvedOutdir = outdir;
138
+ if (entrypoints) {
139
+ const [resolvedEntrypoints, exports, _resolvedOutdir] = resolveExports.resolveExports({
140
+ entrypoints,
141
+ defaultOutdir: outdir,
142
+ ...commonOptions
143
+ });
144
+ newManifest.exports = {
145
+ ...resolvedEntrypoints,
146
+ ...exports
147
+ };
148
+ if (resolvedOutdir === outdir) {
149
+ resolvedOutdir = _resolvedOutdir;
150
+ }
151
+ }
152
+ if (internalEntrypoints) {
153
+ const [resolvedInternalEntrypoints, imports, _resolvedOutdir] = resolveExports.resolveExports({
154
+ entrypoints: internalEntrypoints,
155
+ defaultOutdir: `${outdir}/.internal`,
156
+ ...commonOptions
157
+ });
158
+ newManifest.imports = {
159
+ ...resolvedInternalEntrypoints,
160
+ ...imports
161
+ };
162
+ if (resolvedOutdir === outdir) {
163
+ resolvedOutdir = _resolvedOutdir;
164
+ }
165
+ }
166
+ return [newManifest, resolvedOutdir];
167
+ };
168
+ const generateNewPackageJSONString = ({
169
+ config,
170
+ oldJSONString,
171
+ oldJSON,
172
+ manifest,
173
+ formattingOptions
174
+ }) => {
175
+ const internalModuleName = getInternalModuleName.getInternalModuleName(manifest.name);
176
+ let newJSONString = oldJSONString;
177
+ const update = (path2, value) => {
178
+ newJSONString = jsoncParser.applyEdits(
179
+ newJSONString,
180
+ jsoncParser.modify(newJSONString, path2, value, { formattingOptions })
181
+ );
182
+ };
183
+ update(["publishConfig", "typesVersions"], {
184
+ "<5.0": {
185
+ "*": [
186
+ "*",
187
+ "./*",
188
+ "./*/index.d.ts",
189
+ "./*/index.d.mts",
190
+ "./*/index.d.cts"
191
+ ]
192
+ }
193
+ });
194
+ if (config.experimental?.importsDowngrade) {
195
+ update(["dependencies", internalModuleName], `file:./${outdir}/.internal`);
196
+ update(["dependenciesMeta", internalModuleName], {
197
+ "injected": true
198
+ });
199
+ update(["imports"], void 0);
200
+ }
201
+ for (const [key, value] of Object.entries(manifest)) {
202
+ if (key === "version") continue;
203
+ if (JSON.stringify(value) === JSON.stringify(oldJSON[key])) continue;
204
+ if (key !== "exports") {
205
+ newJSONString = jsoncParser.applyEdits(
206
+ newJSONString,
207
+ jsoncParser.modify(
208
+ newJSONString,
209
+ ["publishConfig", key],
210
+ value,
211
+ { formattingOptions }
212
+ )
213
+ );
214
+ } else {
215
+ const exports = value;
216
+ for (const [k, v] of Object.entries(exports)) {
217
+ newJSONString = jsoncParser.applyEdits(
218
+ newJSONString,
219
+ jsoncParser.modify(
220
+ newJSONString,
221
+ ["publishConfig", "exports", k],
222
+ v,
223
+ { formattingOptions }
224
+ )
225
+ );
226
+ }
227
+ const index = exports?.["."];
228
+ const indexPublishConfig = {};
229
+ if (index) {
230
+ switch (typeof index) {
231
+ case "string":
232
+ indexPublishConfig[manifest?.type === "module" ? "module" : "main"] = index;
233
+ break;
234
+ case "object": {
235
+ const indexExports = index;
236
+ indexPublishConfig.main = indexExports.require ?? indexExports.default;
237
+ indexPublishConfig.module = indexExports.import ?? indexExports.module ?? indexExports.default;
238
+ indexPublishConfig.types = indexExports.types;
239
+ break;
240
+ }
241
+ }
242
+ indexPublishConfig.types = indexPublishConfig[manifest?.type === "module" ? "module" : "main"].replace(/\.([cm]?)js$/, ".d.$1ts");
243
+ for (const [k, v] of Object.entries(indexPublishConfig)) {
244
+ if (v === void 0) continue;
245
+ newJSONString = jsoncParser.applyEdits(
246
+ newJSONString,
247
+ jsoncParser.modify(
248
+ newJSONString,
249
+ ["publishConfig", k],
250
+ v,
251
+ { formattingOptions }
252
+ )
253
+ );
254
+ }
255
+ }
256
+ }
257
+ }
258
+ if (oldJSON.devDependencies) {
259
+ newJSONString = jsoncParser.applyEdits(
260
+ newJSONString,
261
+ jsoncParser.modify(
262
+ newJSONString,
263
+ ["devDependencies"],
264
+ void 0,
265
+ { formattingOptions }
266
+ )
267
+ );
268
+ }
269
+ if (oldJSON.peerDependencies) {
270
+ const peerDependenciesMeta = Object.keys(oldJSON.peerDependencies).reduce(
271
+ (acc, key) => {
272
+ acc[key] = { optional: true };
273
+ return acc;
274
+ },
275
+ {}
276
+ );
277
+ newJSONString = jsoncParser.applyEdits(
278
+ newJSONString,
279
+ jsoncParser.modify(
280
+ newJSONString,
281
+ ["peerDependenciesMeta"],
282
+ peerDependenciesMeta,
283
+ { formattingOptions }
284
+ )
285
+ );
286
+ }
287
+ if (oldJSON.files) {
288
+ newJSONString = jsoncParser.applyEdits(
289
+ newJSONString,
290
+ jsoncParser.modify(
291
+ newJSONString,
292
+ ["files"],
293
+ void 0,
294
+ { formattingOptions }
295
+ )
296
+ );
297
+ }
298
+ return newJSONString;
299
+ };
300
+ await forEachSelectedProjectsGraphEntries((dir, originalManifest) => {
301
+ const config = loadConfig.loadConfig(dir);
302
+ const [manifest, resolvedOutdir] = generateNewManifest(dir, originalManifest, config);
303
+ const resolveByDir = (...paths) => path__default.default.resolve(dir, ...paths);
304
+ const oldJSONString = fs__default.default.readFileSync(resolveByDir("package.json"), "utf-8");
305
+ const oldJSON = JSON.parse(oldJSONString);
306
+ if (typeof oldJSON.version !== "string") {
307
+ throw new TypeError(`${dir}/package.json must have a version field with a string value`);
308
+ }
309
+ const { indent = " " } = detectIndent__default.default(oldJSONString);
310
+ const formattingOptions = {
311
+ tabSize: indent.length,
312
+ insertSpaces: true
313
+ };
314
+ const newVersion = bumper$1 ? bumper.bump(oldJSON.version, bumper$1) : oldJSON.version;
315
+ const modifyVersionPackageJSON = jsoncParser.applyEdits(
316
+ oldJSONString,
317
+ jsoncParser.modify(oldJSONString, ["version"], newVersion, { formattingOptions })
318
+ );
319
+ const newJSONString = generateNewPackageJSONString({
320
+ config,
321
+ oldJSONString: modifyVersionPackageJSON,
322
+ oldJSON: {
323
+ ...oldJSON,
324
+ version: newVersion
325
+ },
326
+ manifest,
327
+ formattingOptions
328
+ });
329
+ const withPublishConfigDirectoryOldJSONString = jsoncParser.applyEdits(
330
+ modifyVersionPackageJSON,
331
+ jsoncParser.modify(modifyVersionPackageJSON, ["publishConfig", "directory"], resolvedOutdir, { formattingOptions })
332
+ );
333
+ if (!fs__default.default.existsSync(resolveByDir(resolvedOutdir))) {
334
+ fs__default.default.mkdirSync(resolveByDir(resolvedOutdir));
335
+ }
336
+ const jiekTempDir = resolveByDir("node_modules/.jiek/.tmp");
337
+ if (!fs__default.default.existsSync(resolveByDir(jiekTempDir))) {
338
+ fs__default.default.mkdirSync(resolveByDir(jiekTempDir), { recursive: true });
339
+ }
340
+ fs__default.default.writeFileSync(resolveByDir(resolvedOutdir, "package.json"), newJSONString);
341
+ fs__default.default.writeFileSync(resolveByDir(jiekTempDir, "package.json"), modifyVersionPackageJSON);
342
+ fs__default.default.writeFileSync(resolveByDir("package.json"), withPublishConfigDirectoryOldJSONString);
343
+ const allBuildFiles = fs__default.default.readdirSync(resolveByDir(resolvedOutdir), { recursive: true }).filter((file) => typeof file === "string").filter((file) => file !== "package.json");
344
+ const resolvedExports = manifest.exports;
345
+ Object.keys(resolvedExports).forEach((key) => {
346
+ if (key === ".") return;
347
+ if (/\.[cm]?js$/.test(key)) return;
348
+ const resourceFileSuffixes = [
349
+ ".d.ts",
350
+ ".d.mts",
351
+ ".d.cts",
352
+ ".css",
353
+ ".scss",
354
+ ".sass",
355
+ ".less",
356
+ ".styl",
357
+ ".stylus",
358
+ ".json",
359
+ ".json5"
360
+ ];
361
+ if (resourceFileSuffixes.find((suffix) => key.endsWith(suffix))) return;
362
+ const value = resolvedExports[key];
363
+ const filepath = resolveByDir(resolvedOutdir, key);
364
+ fs__default.default.mkdirSync(filepath, { recursive: true });
365
+ const pkgJSONPath = resolveByDir(resolvedOutdir, key, "package.json");
366
+ const relativePath = Array.from({ length: key.split("/").length - 1 }, () => "..").join("/");
367
+ const { type } = manifest;
368
+ const pkgJSON = { type };
369
+ if ("default" in value) {
370
+ pkgJSON[type === "module" ? "module" : "main"] = [
371
+ relativePath,
372
+ value.default?.replace(/^\.\//, "")
373
+ ].join("/");
374
+ }
375
+ if ("import" in value) {
376
+ pkgJSON.module = [
377
+ relativePath,
378
+ value.import?.replace(/^\.\//, "")
379
+ ].join("/");
380
+ }
381
+ if ("require" in value) {
382
+ pkgJSON.main = [
383
+ relativePath,
384
+ value.require?.replace(/^\.\//, "")
385
+ ].join("/");
386
+ }
387
+ fs__default.default.writeFileSync(pkgJSONPath, JSON.stringify(pkgJSON));
388
+ });
389
+ fs__default.default.mkdirSync(resolveByDir(resolvedOutdir, resolvedOutdir));
390
+ for (const file of allBuildFiles) {
391
+ const filepath = resolveByDir(resolvedOutdir, file);
392
+ const newFilepath = resolveByDir(resolvedOutdir, resolvedOutdir, file);
393
+ const stat = fs__default.default.statSync(filepath);
394
+ if (stat.isDirectory()) {
395
+ fs__default.default.mkdirSync(newFilepath, { recursive: true });
396
+ continue;
397
+ }
398
+ if (stat.isFile()) {
399
+ fs__default.default.cpSync(filepath, newFilepath);
400
+ fs__default.default.rmSync(filepath);
401
+ }
402
+ }
403
+ if (oldJSON.files) {
404
+ if (Array.isArray(oldJSON.files)) {
405
+ if (oldJSON.files.every((file) => typeof file !== "string")) {
406
+ throw new TypeError(`${dir}/package.json files field must be an array of string`);
407
+ }
408
+ } else {
409
+ throw new TypeError(`${dir}/package.json files field must be an array`);
410
+ }
411
+ }
412
+ const resolvedOutdirAbs = resolveByDir(resolvedOutdir);
413
+ const files = (oldJSON.files ?? fs__default.default.readdirSync(resolveByDir("."))).filter(
414
+ (file) => ![
415
+ "node_modules",
416
+ "package.json",
417
+ "pnpm-lock.yaml"
418
+ ].includes(file) && resolveByDir(file) !== resolvedOutdirAbs
419
+ );
420
+ for (const file of files) {
421
+ const path2 = resolveByDir(file);
422
+ try {
423
+ const stat = fs__default.default.statSync(path2);
424
+ if (stat.isDirectory()) {
425
+ fs__default.default.cpSync(path2, resolveByDir(resolvedOutdir, file), { recursive: true });
426
+ continue;
427
+ }
428
+ if (stat.isFile()) {
429
+ fs__default.default.cpSync(path2, resolveByDir(resolvedOutdir, file));
430
+ continue;
431
+ }
432
+ } catch (e) {
433
+ console.warn(String(e));
434
+ continue;
435
+ }
436
+ throw new Error(`file type of ${path2} is not supported`);
437
+ }
438
+ if (config.experimental?.importsDowngrade && "imports" in manifest && manifest.imports) {
439
+ fs__default.default.writeFileSync(
440
+ resolveByDir(resolvedOutdir, resolvedOutdir, ".internal", "package.json"),
441
+ JSON.stringify(
442
+ {
443
+ name: getInternalModuleName.getInternalModuleName(manifest.name),
444
+ exports: JSON.parse(
445
+ JSON.stringify(manifest.imports).replaceAll("#", "./").replaceAll("~", "")
446
+ )
447
+ },
448
+ null,
449
+ 2
450
+ )
451
+ );
452
+ }
453
+ const jiekProductionTag = path__default.default.resolve(resolvedOutdir, ".jiek-production-tag");
454
+ if (!fs__default.default.existsSync(jiekProductionTag)) {
455
+ fs__default.default.writeFileSync(jiekProductionTag, "");
456
+ }
457
+ });
458
+ }
459
+ async function postpublish({}) {
460
+ await forEachSelectedProjectsGraphEntries((dir) => {
461
+ const jiekTempDir = path__default.default.resolve(dir, "node_modules/.jiek/.tmp");
462
+ const packageJSONPath = path__default.default.resolve(dir, "package.json");
463
+ const { name, version } = JSON.parse(fs__default.default.readFileSync(packageJSONPath, "utf-8"));
464
+ const jiekTempPackageJSONPath = path__default.default.resolve(jiekTempDir, "package.json");
465
+ if (fs__default.default.existsSync(jiekTempPackageJSONPath)) {
466
+ fs__default.default.copyFileSync(jiekTempPackageJSONPath, packageJSONPath);
467
+ fs__default.default.rmSync(jiekTempPackageJSONPath);
468
+ console.log(`${dir}/package.json has been restored`);
469
+ console.log(
470
+ `if you want to check the compatibility of the package, you can visit: https://arethetypeswrong.github.io/?p=${name}%40${version}`
471
+ );
472
+ } else {
473
+ throw new Error(
474
+ `jiek temp \`${dir}/package.json\` not found, please confirm the jiek pre-publish command has been executed`
475
+ );
476
+ }
477
+ });
478
+ }
479
+ const prepublishDescription = `
480
+ Prepare package.json for publish, you can add \`jk\` to the \`prepublish\` script in package.json, the command will automatically run \`jk prepublish\`.
481
+ .e.g
482
+ {
483
+ "scripts": {
484
+ "prepublish": "jk"
485
+ }
486
+ }
487
+ `.trim();
488
+ attachPublishOptions(
489
+ commander.program.command("prepublish").description(prepublishDescription)
490
+ ).action(prepublish);
491
+ const postpublishDescription = `
492
+ Restore package.json after publish, you can add \`jk\` to the \`postpublish\` script in package.json, the command will automatically run \`jk postpublish\`.
493
+ .e.g
494
+ {
495
+ "scripts": {
496
+ "postpublish": "jk"
497
+ }
498
+ }
499
+ `.trim();
500
+ attachPublishOptions(
501
+ commander.program.command("postpublish").description(postpublishDescription)
502
+ ).action(postpublish);
503
+ const {
504
+ npm_lifecycle_event: NPM_LIFECYCLE_EVENT
505
+ } = process__default.default.env;
506
+ if (NPM_LIFECYCLE_EVENT && [
507
+ "prepublish",
508
+ "postpublish"
509
+ ].includes(NPM_LIFECYCLE_EVENT)) {
510
+ attachPublishOptions(commander.program).action(async (options) => {
511
+ switch (NPM_LIFECYCLE_EVENT) {
512
+ case "prepublish":
513
+ await prepublish(options);
514
+ break;
515
+ case "postpublish":
516
+ await postpublish(options);
517
+ break;
518
+ }
519
+ });
520
+ }
521
+
522
+ parseArgv__default.default();
package/dist/index.d.cts CHANGED
@@ -1,119 +1,11 @@
1
- import * as _rollup_plugin_terser from '@rollup/plugin-terser';
2
- import * as rollup_plugin_swc3 from 'rollup-plugin-swc3';
3
- import * as rollup_plugin_esbuild from 'rollup-plugin-esbuild';
4
- import { InputPluginOption, OutputOptions } from 'rollup';
5
-
6
- type Mapping2ROO<K extends keyof OutputOptions> = OutputOptions[K] | {
7
- js?: OutputOptions[K];
8
- dts?: OutputOptions[K];
9
- };
10
- interface ConfigGenerateContext {
11
- path: string;
12
- name: string;
13
- input: string;
14
- output: string;
15
- external: (string | RegExp)[];
16
- pkgIsModule: boolean;
17
- conditionals: string[];
18
- }
19
- type OutputControl = boolean | ((context: ConfigGenerateContext) => boolean);
20
- declare const BUILDER_TYPES: readonly ["esbuild", "swc"];
21
- interface TemplateOptions {
22
- /**
23
- * When the user configures type: module, the generated output from entry points that don't
24
- * have cts as a suffix will automatically include the CJS version.
25
- * if it is not configured, and the generated output from entry points that do not have mts
26
- * as a suffix will automatically include the ESM version.
27
- *
28
- * @default true
29
- */
30
- crossModuleConvertor?: boolean;
31
- /**
32
- * Auto-detect the builder from the installed dependencies.
33
- * If the builder is not installed, it will prompt the user to install it.
34
- * If exists multiple builders, it will fall back to the 'esbuild'.
35
- *
36
- * @default 'esbuild'
37
- */
38
- builder?: typeof BUILDER_TYPES[number] | ({
39
- type: 'esbuild';
40
- } & rollup_plugin_esbuild.Options) | ({
41
- type: 'swc';
42
- } & rollup_plugin_swc3.PluginOptions);
43
- features?: {
44
- /**
45
- * When use esbuild type builder, it will inject `supported.import-attributes` option.
46
- * When use swc type builder, it will inject `jsc.experimental.keepImportAttributes` option.
47
- *
48
- * And it will auto set the rollup output externalImportAttributes and importAttributesKey options.
49
- *
50
- * @default true
51
- */
52
- keepImportAttributes?: boolean | 'assert';
53
- };
54
- output?: {
55
- /**
56
- * @default true
57
- *
58
- * When minify is set to true, the output will with minified files.
59
- * When minify is set to 'only-minify', the output will direct output minified files.
60
- */
61
- minify?: boolean | 'only-minify';
62
- minifyOptions?: typeof BUILDER_TYPES[number] | 'terser' | ({
63
- type: 'terser';
64
- } & _rollup_plugin_terser.Options) | ({
65
- type: 'esbuild';
66
- } & Parameters<typeof rollup_plugin_esbuild.minify>[0]) | ({
67
- type: 'swc';
68
- } & Parameters<typeof rollup_plugin_swc3.minify>[0]);
69
- /**
70
- * @default 'dist'
71
- */
72
- dir?: Mapping2ROO<'dir'>;
73
- sourcemap?: Mapping2ROO<'sourcemap'>;
74
- strict?: Mapping2ROO<'strict'>;
75
- js?: OutputControl;
76
- dts?: OutputControl;
77
- };
78
- /**
79
- * Set the external dependencies of the package.
80
- */
81
- external?: (string | RegExp)[];
82
- plugins?: InputPluginOption | ((type: 'js' | 'dts', context: ConfigGenerateContext) => InputPluginOption) | {
83
- js: InputPluginOption;
84
- dts?: InputPluginOption;
85
- } | {
86
- js?: InputPluginOption;
87
- dts: InputPluginOption;
88
- };
89
- /**
90
- * https://www.npmjs.com/package/@rollup/plugin-inject#usage
91
- *
92
- * @example
93
- * ```js
94
- * {
95
- * // import { Promise } from 'es6-promise'
96
- * Promise: [ 'es6-promise', 'Promise' ],
97
- *
98
- * // import { Promise as P } from 'es6-promise'
99
- * P: [ 'es6-promise', 'Promise' ],
100
- *
101
- * // import $ from 'jquery'
102
- * $: 'jquery',
103
- *
104
- * // import * as fs from 'fs'
105
- * fs: [ 'fs', '*' ],
106
- *
107
- * // use a local module instead of a third-party one
108
- * 'Object.assign': path.resolve( 'src/helpers/object-assign.js' ),
109
- * }
110
- * ```
111
- */
112
- injects?: Record<string, string | [string, string]>;
113
- }
1
+ import { TemplateOptions } from '#~/rollup/base';
114
2
 
115
3
  declare module 'jiek' {
116
4
  interface Config {
5
+ /**
6
+ * Skip entries which end with '.js'.
7
+ */
8
+ skipJS?: boolean;
117
9
  build?: TemplateOptions & {
118
10
  /**
119
11
  * Whether to run in silent mode, only active when configured in the workspace root or cwd.
@@ -126,6 +18,13 @@ declare module 'jiek' {
126
18
  }
127
19
 
128
20
  declare module 'jiek' {
21
+ interface ConfigExperimental {
22
+ /**
23
+ * Polyfill `imports` fields in package.json to local dependencies and exports fields.
24
+ * @default false
25
+ */
26
+ importsDowngrade?: boolean;
27
+ }
129
28
  interface Config {
130
29
  publish?: {
131
30
  /**
@@ -140,8 +39,11 @@ declare module 'jiek' {
140
39
  }
141
40
  }
142
41
 
42
+ interface ConfigExperimental {
43
+ }
143
44
  interface Config {
45
+ experimental?: ConfigExperimental;
144
46
  }
145
47
  declare const defineConfig: (config: Config) => Config;
146
48
 
147
- export { type Config, defineConfig };
49
+ export { type Config, type ConfigExperimental, defineConfig };