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.
Files changed (136) hide show
  1. package/bin/build.cjs +2 -0
  2. package/bin/index.cjs +2 -0
  3. package/bin-helper/index.cjs +31 -0
  4. package/bin-helper/index.d.cts +1 -0
  5. package/bin-helper/index.d.ts +1 -0
  6. package/bin-helper/package.json +5 -1
  7. package/dist/.internal/+/bin/parseArgv.cjs +33 -0
  8. package/dist/.internal/+/bin/parseArgv.d.cts +5 -0
  9. package/dist/.internal/+/bin/parseArgv.d.ts +5 -0
  10. package/dist/.internal/+/bin/parseArgv.js +27 -0
  11. package/dist/.internal/+/bridge.cjs +12 -0
  12. package/dist/.internal/+/bridge.d.cts +39 -0
  13. package/dist/.internal/+/bridge.d.ts +39 -0
  14. package/dist/.internal/+/bridge.js +9 -0
  15. package/dist/.internal/+/commands/build/analyzer.cjs +201 -0
  16. package/dist/.internal/+/commands/build/analyzer.d.cts +30 -0
  17. package/dist/.internal/+/commands/build/analyzer.d.ts +30 -0
  18. package/dist/.internal/+/commands/build/analyzer.js +195 -0
  19. package/dist/.internal/+/commands/descriptions.cjs +21 -0
  20. package/dist/.internal/+/commands/descriptions.d.cts +5 -0
  21. package/dist/.internal/+/commands/descriptions.d.ts +5 -0
  22. package/dist/.internal/+/commands/descriptions.js +17 -0
  23. package/dist/.internal/+/commands/meta.cjs +16 -0
  24. package/dist/.internal/+/commands/meta.d.cts +3 -0
  25. package/dist/.internal/+/commands/meta.d.ts +3 -0
  26. package/dist/.internal/+/commands/meta.js +15 -0
  27. package/dist/.internal/+/commands/utils/optionParser.cjs +8 -0
  28. package/dist/.internal/+/commands/utils/optionParser.d.cts +3 -0
  29. package/dist/.internal/+/commands/utils/optionParser.d.ts +3 -0
  30. package/dist/.internal/+/commands/utils/optionParser.js +6 -0
  31. package/dist/.internal/+/rollup/base.cjs +10 -0
  32. package/dist/{cli-only-build.d.cts → .internal/+/rollup/base.d.cts} +8 -15
  33. package/dist/{cli-only-build.d.ts → .internal/+/rollup/base.d.ts} +8 -15
  34. package/dist/.internal/+/rollup/base.js +7 -0
  35. package/dist/.internal/+/rollup/bundle-analyzer.cjs +51 -0
  36. package/dist/.internal/+/rollup/bundle-analyzer.d.cts +92 -0
  37. package/dist/.internal/+/rollup/bundle-analyzer.d.ts +92 -0
  38. package/dist/.internal/+/rollup/bundle-analyzer.js +45 -0
  39. package/dist/.internal/+/server.cjs +33 -0
  40. package/dist/.internal/+/server.d.cts +8 -0
  41. package/dist/.internal/+/server.d.ts +8 -0
  42. package/dist/.internal/+/server.js +27 -0
  43. package/dist/.internal/+/utils/checkDependency.cjs +39 -0
  44. package/dist/.internal/+/utils/checkDependency.d.cts +3 -0
  45. package/dist/.internal/+/utils/checkDependency.d.ts +3 -0
  46. package/dist/.internal/+/utils/checkDependency.js +34 -0
  47. package/dist/.internal/+/utils/filterSupport.cjs +20 -0
  48. package/dist/.internal/+/utils/filterSupport.d.cts +15 -0
  49. package/dist/.internal/+/utils/filterSupport.d.ts +15 -0
  50. package/dist/.internal/+/utils/filterSupport.js +10 -0
  51. package/dist/.internal/+/utils/getInternalModuleName.cjs +5 -0
  52. package/dist/.internal/+/utils/getInternalModuleName.d.cts +3 -0
  53. package/dist/.internal/+/utils/getInternalModuleName.d.ts +3 -0
  54. package/dist/.internal/+/utils/getInternalModuleName.js +3 -0
  55. package/dist/.internal/+/utils/getRoot.cjs +17 -0
  56. package/dist/.internal/+/utils/getRoot.d.cts +3 -0
  57. package/dist/.internal/+/utils/getRoot.d.ts +3 -0
  58. package/dist/.internal/+/utils/getRoot.js +11 -0
  59. package/dist/.internal/+/utils/getWD.cjs +15 -0
  60. package/dist/.internal/+/utils/getWD.d.cts +6 -0
  61. package/dist/.internal/+/utils/getWD.d.ts +6 -0
  62. package/dist/.internal/+/utils/getWD.js +10 -0
  63. package/dist/.internal/+/utils/intersection.cjs +5 -0
  64. package/dist/.internal/+/utils/intersection.d.cts +3 -0
  65. package/dist/.internal/+/utils/intersection.d.ts +3 -0
  66. package/dist/.internal/+/utils/intersection.js +3 -0
  67. package/dist/.internal/+/utils/loadConfig.cjs +100 -0
  68. package/dist/.internal/+/utils/loadConfig.d.cts +10 -0
  69. package/dist/.internal/+/utils/loadConfig.d.ts +10 -0
  70. package/dist/.internal/+/utils/loadConfig.js +94 -0
  71. package/dist/.internal/+/utils/recursiveListFiles.cjs +19 -0
  72. package/dist/.internal/+/utils/recursiveListFiles.d.cts +3 -0
  73. package/dist/.internal/+/utils/recursiveListFiles.d.ts +3 -0
  74. package/dist/.internal/+/utils/recursiveListFiles.js +13 -0
  75. package/dist/.internal/+/utils/resolveExports.cjs +118 -0
  76. package/dist/.internal/+/utils/resolveExports.d.cts +26 -0
  77. package/dist/.internal/+/utils/resolveExports.d.ts +26 -0
  78. package/dist/.internal/+/utils/resolveExports.js +111 -0
  79. package/dist/.internal/+/utils/ts.cjs +68 -0
  80. package/dist/.internal/+/utils/ts.d.cts +3 -0
  81. package/dist/.internal/+/utils/ts.d.ts +3 -0
  82. package/dist/.internal/+/utils/ts.js +62 -0
  83. package/dist/.internal/+/utils/tsRegister.cjs +25 -0
  84. package/dist/.internal/+/utils/tsRegister.d.cts +3 -0
  85. package/dist/.internal/+/utils/tsRegister.d.ts +3 -0
  86. package/dist/.internal/+/utils/tsRegister.js +26 -0
  87. package/dist/.internal/getWD-BRJ3PK1S.js +105 -0
  88. package/dist/.internal/getWD-Cmxzjf-f.js +95 -0
  89. package/dist/{cli.js → .internal/index-B6RQz1DZ.js} +1 -735
  90. package/dist/{cli.cjs → .internal/index-DlHFuTjM.js} +1 -757
  91. package/dist/.internal/jiek_create-require-CWFWNQHj.js +5 -0
  92. package/dist/.internal/jiek_create-require-CxSGbkTB.js +5 -0
  93. package/dist/.internal/package.json +10 -0
  94. package/dist/bin/build.cjs +505 -0
  95. package/dist/bin/index.cjs +488 -0
  96. package/dist/index.d.cts +1 -113
  97. package/dist/index.d.ts +1 -113
  98. package/dist/rollup/index.cjs +282 -4569
  99. package/dist/rollup/index.d.cts +7 -1
  100. package/dist/rollup/index.d.ts +7 -1
  101. package/dist/rollup/index.js +270 -4554
  102. package/package.json +25 -28
  103. package/src/bin/build.cts +11 -0
  104. package/src/bin/index.cts +6 -0
  105. package/src/bridge.ts +1 -1
  106. package/src/commands/base.ts +3 -3
  107. package/src/commands/build/analyzer.ts +5 -5
  108. package/src/commands/build/client/analyzer.tsx +1 -1
  109. package/src/commands/build/client/index.ts +5 -7
  110. package/src/commands/build.ts +218 -209
  111. package/src/commands/meta.ts +1 -1
  112. package/src/commands/publish.ts +87 -25
  113. package/src/rollup/base.ts +2 -2
  114. package/src/rollup/index.ts +309 -115
  115. package/src/rollup/plugins/with-external.ts +23 -0
  116. package/src/rollup/utils/externalResolver.ts +20 -8
  117. package/src/utils/checkDependency.ts +1 -1
  118. package/src/utils/filterSupport.ts +17 -16
  119. package/src/utils/getInternalModuleName.ts +5 -0
  120. package/src/utils/intersection.ts +1 -0
  121. package/src/utils/{recusiveListFiles.ts → recursiveListFiles.ts} +2 -2
  122. package/src/utils/{getExports.ts → resolveExports.ts} +16 -14
  123. package/bin/jiek-build.js +0 -16
  124. package/bin/jiek.js +0 -13
  125. package/bin-helper.cjs +0 -43
  126. package/cli/package.json +0 -1
  127. package/cli-only-build/package.json +0 -1
  128. package/dist/cli-only-build.cjs +0 -977
  129. package/dist/cli-only-build.js +0 -969
  130. package/dist/cli.d.cts +0 -14
  131. package/dist/cli.d.ts +0 -14
  132. package/src/bin/build.ts +0 -0
  133. package/src/cli-only-build.ts +0 -11
  134. package/src/cli.ts +0 -6
  135. /package/{bin-helper.js → bin-helper/index.js} +0 -0
  136. /package/src/{parseArgv.ts → bin/parseArgv.ts} +0 -0
@@ -0,0 +1,488 @@
1
+ 'use strict';
2
+
3
+ var childProcess = require('node:child_process');
4
+ var fs = require('node:fs');
5
+ var path = require('node:path');
6
+ var process = require('node:process');
7
+ var bumper = require('@jiek/utils/bumper');
8
+ var commander = require('commander');
9
+ var detectIndent = require('detect-indent');
10
+ var jsoncParser = require('jsonc-parser');
11
+ var filterSupport = require('@jiek/__internal__/+/utils/filterSupport');
12
+ var loadConfig = require('@jiek/__internal__/+/utils/loadConfig');
13
+ var resolveExports = require('@jiek/__internal__/+/utils/resolveExports');
14
+ var getInternalModuleName = require('@jiek/__internal__/+/utils/getInternalModuleName');
15
+ require('./build');
16
+ var parseArgv = require('@jiek/__internal__/+/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
+ commander.program.command("publish").description(description).aliases(["pub", "p"]).option("-b, --bumper <bumper>", "bump version", "patch").option("-no-b, --no-bumper", "no bump version").option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").action(async ({ outdir, bumper: bumper$1 }) => {
66
+ let shouldPassThrough = false;
67
+ const passThroughOptions = process__default.default.argv.reduce(
68
+ (acc, value) => {
69
+ if (shouldPassThrough) {
70
+ acc.push(value);
71
+ }
72
+ if (value === "--") {
73
+ shouldPassThrough = true;
74
+ }
75
+ return acc;
76
+ },
77
+ []
78
+ );
79
+ await forEachSelectedProjectsGraphEntries((dir) => {
80
+ const args = ["pnpm", "publish", "--access", "public", "--no-git-checks"];
81
+ if (bumper$1 && bumper.TAGS.includes(bumper$1)) {
82
+ args.push("--tag", bumper$1);
83
+ }
84
+ args.push(...passThroughOptions);
85
+ childProcess__namespace.execSync(args.join(" "), {
86
+ cwd: dir,
87
+ stdio: "inherit",
88
+ env: {
89
+ ...process__default.default.env,
90
+ JIEK_PUBLISH_OUTDIR: JSON.stringify(outdir),
91
+ JIEK_PUBLISH_BUMPER: JSON.stringify(bumper$1)
92
+ }
93
+ });
94
+ });
95
+ });
96
+ async function prepublish({ bumper: bumper$1 } = {}) {
97
+ const {
98
+ JIEK_PUBLISH_OUTDIR: outdirEnv,
99
+ JIEK_PUBLISH_BUMPER: bumperEnv
100
+ } = process__default.default.env;
101
+ const outdir = outdirEnv ? JSON.parse(outdirEnv) : "dist";
102
+ bumper$1 = bumper$1 ?? (bumperEnv ? JSON.parse(bumperEnv) : false);
103
+ const generateNewManifest = (dir, manifest) => {
104
+ const {
105
+ name,
106
+ type,
107
+ exports: entrypoints = {},
108
+ imports: internalEntrypoints = {}
109
+ } = manifest;
110
+ if (!name) {
111
+ throw new Error(`package.json in ${dir} must have a name field`);
112
+ }
113
+ const pkgIsModule = type === "module";
114
+ const newManifest = { ...manifest };
115
+ const commonOptions = {
116
+ pkgIsModule,
117
+ pkgName: name,
118
+ config: loadConfig.loadConfig(dir),
119
+ dir,
120
+ noFilter: true,
121
+ isPublish: true
122
+ };
123
+ const [resolvedEntrypoints, exports, resolvedOutdir] = resolveExports.resolveExports({
124
+ entrypoints,
125
+ defaultOutdir: outdir,
126
+ ...commonOptions
127
+ });
128
+ newManifest.exports = {
129
+ ...resolvedEntrypoints,
130
+ ...exports
131
+ };
132
+ const [resolvedInternalEntrypoints, imports] = resolveExports.resolveExports({
133
+ entrypoints: internalEntrypoints,
134
+ defaultOutdir: `${outdir}/.internal`,
135
+ ...commonOptions
136
+ });
137
+ newManifest.imports = {
138
+ ...resolvedInternalEntrypoints,
139
+ ...imports
140
+ };
141
+ return [newManifest, resolvedOutdir];
142
+ };
143
+ const generateNewPackageJSONString = ({
144
+ oldJSONString,
145
+ oldJSON,
146
+ manifest,
147
+ formattingOptions
148
+ }) => {
149
+ const internalModuleName = getInternalModuleName.getInternalModuleName(manifest.name);
150
+ let newJSONString = oldJSONString;
151
+ const update = (path2, value) => {
152
+ newJSONString = jsoncParser.applyEdits(
153
+ newJSONString,
154
+ jsoncParser.modify(newJSONString, path2, value, { formattingOptions })
155
+ );
156
+ };
157
+ update(["publishConfig", "typesVersions"], {
158
+ "<5.0": {
159
+ "*": [
160
+ "*",
161
+ "./*",
162
+ "./*/index.d.ts",
163
+ "./*/index.d.mts",
164
+ "./*/index.d.cts"
165
+ ]
166
+ }
167
+ });
168
+ update(["dependencies", internalModuleName], `file:./${outdir}/.internal`);
169
+ update(["dependenciesMeta", internalModuleName], {
170
+ "injected": true
171
+ });
172
+ update(["imports"], void 0);
173
+ for (const [key, value] of Object.entries(manifest)) {
174
+ if (key === "version") continue;
175
+ if (JSON.stringify(value) === JSON.stringify(oldJSON[key])) continue;
176
+ if (key !== "exports") {
177
+ newJSONString = jsoncParser.applyEdits(
178
+ newJSONString,
179
+ jsoncParser.modify(
180
+ newJSONString,
181
+ ["publishConfig", key],
182
+ value,
183
+ { formattingOptions }
184
+ )
185
+ );
186
+ } else {
187
+ const exports = value;
188
+ for (const [k, v] of Object.entries(exports)) {
189
+ newJSONString = jsoncParser.applyEdits(
190
+ newJSONString,
191
+ jsoncParser.modify(
192
+ newJSONString,
193
+ ["publishConfig", "exports", k],
194
+ v,
195
+ { formattingOptions }
196
+ )
197
+ );
198
+ }
199
+ const index = exports?.["."];
200
+ const indexPublishConfig = {};
201
+ if (index) {
202
+ switch (typeof index) {
203
+ case "string":
204
+ indexPublishConfig[manifest?.type === "module" ? "module" : "main"] = index;
205
+ break;
206
+ case "object": {
207
+ const indexExports = index;
208
+ indexPublishConfig.main = indexExports.require ?? indexExports.default;
209
+ indexPublishConfig.module = indexExports.import ?? indexExports.module ?? indexExports.default;
210
+ indexPublishConfig.types = indexExports.types;
211
+ break;
212
+ }
213
+ }
214
+ indexPublishConfig.types = indexPublishConfig[manifest?.type === "module" ? "module" : "main"].replace(/\.([cm]?)js$/, ".d.$1ts");
215
+ for (const [k, v] of Object.entries(indexPublishConfig)) {
216
+ if (v === void 0) continue;
217
+ newJSONString = jsoncParser.applyEdits(
218
+ newJSONString,
219
+ jsoncParser.modify(
220
+ newJSONString,
221
+ ["publishConfig", k],
222
+ v,
223
+ { formattingOptions }
224
+ )
225
+ );
226
+ }
227
+ }
228
+ }
229
+ }
230
+ if (oldJSON.devDependencies) {
231
+ newJSONString = jsoncParser.applyEdits(
232
+ newJSONString,
233
+ jsoncParser.modify(
234
+ newJSONString,
235
+ ["devDependencies"],
236
+ void 0,
237
+ { formattingOptions }
238
+ )
239
+ );
240
+ }
241
+ if (oldJSON.peerDependencies) {
242
+ const peerDependenciesMeta = Object.keys(oldJSON.peerDependencies).reduce(
243
+ (acc, key) => {
244
+ acc[key] = { optional: true };
245
+ return acc;
246
+ },
247
+ {}
248
+ );
249
+ newJSONString = jsoncParser.applyEdits(
250
+ newJSONString,
251
+ jsoncParser.modify(
252
+ newJSONString,
253
+ ["peerDependenciesMeta"],
254
+ peerDependenciesMeta,
255
+ { formattingOptions }
256
+ )
257
+ );
258
+ }
259
+ if (oldJSON.files) {
260
+ newJSONString = jsoncParser.applyEdits(
261
+ newJSONString,
262
+ jsoncParser.modify(
263
+ newJSONString,
264
+ ["files"],
265
+ void 0,
266
+ { formattingOptions }
267
+ )
268
+ );
269
+ }
270
+ return newJSONString;
271
+ };
272
+ await forEachSelectedProjectsGraphEntries((dir, originalManifest) => {
273
+ const [manifest, resolvedOutdir] = generateNewManifest(dir, originalManifest);
274
+ const resolveByDir = (...paths) => path__default.default.resolve(dir, ...paths);
275
+ const oldJSONString = fs__default.default.readFileSync(resolveByDir("package.json"), "utf-8");
276
+ const oldJSON = JSON.parse(oldJSONString);
277
+ if (typeof oldJSON.version !== "string") {
278
+ throw new TypeError(`${dir}/package.json must have a version field with a string value`);
279
+ }
280
+ const { indent = " " } = detectIndent__default.default(oldJSONString);
281
+ const formattingOptions = {
282
+ tabSize: indent.length,
283
+ insertSpaces: true
284
+ };
285
+ const newVersion = bumper$1 ? bumper.bump(oldJSON.version, bumper$1 === true ? "patch" : bumper$1) : oldJSON.version;
286
+ const modifyVersionPackageJSON = jsoncParser.applyEdits(
287
+ oldJSONString,
288
+ jsoncParser.modify(oldJSONString, ["version"], newVersion, { formattingOptions })
289
+ );
290
+ const newJSONString = generateNewPackageJSONString({
291
+ oldJSONString: modifyVersionPackageJSON,
292
+ oldJSON: {
293
+ ...oldJSON,
294
+ version: newVersion
295
+ },
296
+ manifest,
297
+ formattingOptions
298
+ });
299
+ const withPublishConfigDirectoryOldJSONString = jsoncParser.applyEdits(
300
+ modifyVersionPackageJSON,
301
+ jsoncParser.modify(modifyVersionPackageJSON, ["publishConfig", "directory"], resolvedOutdir, { formattingOptions })
302
+ );
303
+ if (!fs__default.default.existsSync(resolveByDir(resolvedOutdir))) {
304
+ fs__default.default.mkdirSync(resolveByDir(resolvedOutdir));
305
+ }
306
+ const jiekTempDir = resolveByDir("node_modules/.jiek/.tmp");
307
+ if (!fs__default.default.existsSync(resolveByDir(jiekTempDir))) {
308
+ fs__default.default.mkdirSync(resolveByDir(jiekTempDir), { recursive: true });
309
+ }
310
+ fs__default.default.writeFileSync(resolveByDir(resolvedOutdir, "package.json"), newJSONString);
311
+ fs__default.default.writeFileSync(resolveByDir(jiekTempDir, "package.json"), modifyVersionPackageJSON);
312
+ fs__default.default.writeFileSync(resolveByDir("package.json"), withPublishConfigDirectoryOldJSONString);
313
+ const allBuildFiles = fs__default.default.readdirSync(resolveByDir(resolvedOutdir), { recursive: true }).filter((file) => typeof file === "string").filter((file) => file !== "package.json");
314
+ const resolvedExports = manifest.exports;
315
+ Object.keys(resolvedExports).forEach((key) => {
316
+ if (key === ".") return;
317
+ if (/\.[cm]?js$/.test(key)) return;
318
+ const resourceFileSuffixes = [
319
+ ".d.ts",
320
+ ".d.mts",
321
+ ".d.cts",
322
+ ".css",
323
+ ".scss",
324
+ ".sass",
325
+ ".less",
326
+ ".styl",
327
+ ".stylus",
328
+ ".json",
329
+ ".json5"
330
+ ];
331
+ if (resourceFileSuffixes.find((suffix) => key.endsWith(suffix))) return;
332
+ const value = resolvedExports[key];
333
+ const filepath = resolveByDir(resolvedOutdir, key);
334
+ fs__default.default.mkdirSync(filepath, { recursive: true });
335
+ const pkgJSONPath = resolveByDir(resolvedOutdir, key, "package.json");
336
+ const relativePath = Array.from({ length: key.split("/").length - 1 }, () => "..").join("/");
337
+ const { type } = manifest;
338
+ const pkgJSON = { type };
339
+ if ("default" in value) {
340
+ pkgJSON[type === "module" ? "module" : "main"] = [
341
+ relativePath,
342
+ value.default?.replace(/^\.\//, "")
343
+ ].join("/");
344
+ }
345
+ if ("import" in value) {
346
+ pkgJSON.module = [
347
+ relativePath,
348
+ value.import?.replace(/^\.\//, "")
349
+ ].join("/");
350
+ }
351
+ if ("require" in value) {
352
+ pkgJSON.main = [
353
+ relativePath,
354
+ value.require?.replace(/^\.\//, "")
355
+ ].join("/");
356
+ }
357
+ fs__default.default.writeFileSync(pkgJSONPath, JSON.stringify(pkgJSON));
358
+ });
359
+ fs__default.default.mkdirSync(resolveByDir(resolvedOutdir, resolvedOutdir));
360
+ for (const file of allBuildFiles) {
361
+ const filepath = resolveByDir(resolvedOutdir, file);
362
+ const newFilepath = resolveByDir(resolvedOutdir, resolvedOutdir, file);
363
+ const stat = fs__default.default.statSync(filepath);
364
+ if (stat.isDirectory()) {
365
+ fs__default.default.mkdirSync(newFilepath, { recursive: true });
366
+ continue;
367
+ }
368
+ if (stat.isFile()) {
369
+ fs__default.default.cpSync(filepath, newFilepath);
370
+ fs__default.default.rmSync(filepath);
371
+ }
372
+ }
373
+ if (oldJSON.files) {
374
+ if (Array.isArray(oldJSON.files)) {
375
+ if (oldJSON.files.every((file) => typeof file !== "string")) {
376
+ throw new TypeError(`${dir}/package.json files field must be an array of string`);
377
+ }
378
+ } else {
379
+ throw new TypeError(`${dir}/package.json files field must be an array`);
380
+ }
381
+ }
382
+ const resolvedOutdirAbs = resolveByDir(resolvedOutdir);
383
+ const files = (oldJSON.files ?? fs__default.default.readdirSync(resolveByDir("."))).filter(
384
+ (file) => ![
385
+ "node_modules",
386
+ "package.json",
387
+ "pnpm-lock.yaml"
388
+ ].includes(file) && resolveByDir(file) !== resolvedOutdirAbs
389
+ );
390
+ for (const file of files) {
391
+ const path2 = resolveByDir(file);
392
+ try {
393
+ const stat = fs__default.default.statSync(path2);
394
+ if (stat.isDirectory()) {
395
+ fs__default.default.cpSync(path2, resolveByDir(resolvedOutdir, file), { recursive: true });
396
+ continue;
397
+ }
398
+ if (stat.isFile()) {
399
+ fs__default.default.cpSync(path2, resolveByDir(resolvedOutdir, file));
400
+ continue;
401
+ }
402
+ } catch (e) {
403
+ console.warn(String(e));
404
+ continue;
405
+ }
406
+ throw new Error(`file type of ${path2} is not supported`);
407
+ }
408
+ if ("imports" in manifest && manifest.imports) {
409
+ Object.entries(manifest.imports).forEach(([key, value]) => {
410
+ if (typeof value !== "object") return;
411
+ const [start] = key.split("*");
412
+ manifest.imports[key] = JSON.parse(
413
+ JSON.stringify(value).replaceAll(`${resolvedOutdir}/.internal/`, start)
414
+ );
415
+ });
416
+ fs__default.default.writeFileSync(
417
+ resolveByDir(resolvedOutdir, resolvedOutdir, ".internal", "package.json"),
418
+ JSON.stringify(
419
+ {
420
+ name: getInternalModuleName.getInternalModuleName(manifest.name),
421
+ exports: JSON.parse(
422
+ JSON.stringify(manifest.imports).replaceAll("#", "./").replaceAll("~", "+")
423
+ )
424
+ },
425
+ null,
426
+ 2
427
+ )
428
+ );
429
+ }
430
+ });
431
+ }
432
+ async function postpublish() {
433
+ await forEachSelectedProjectsGraphEntries((dir) => {
434
+ const jiekTempDir = path__default.default.resolve(dir, "node_modules/.jiek/.tmp");
435
+ const packageJSONPath = path__default.default.resolve(dir, "package.json");
436
+ const { name, version } = JSON.parse(fs__default.default.readFileSync(packageJSONPath, "utf-8"));
437
+ const jiekTempPackageJSONPath = path__default.default.resolve(jiekTempDir, "package.json");
438
+ if (fs__default.default.existsSync(jiekTempPackageJSONPath)) {
439
+ fs__default.default.copyFileSync(jiekTempPackageJSONPath, packageJSONPath);
440
+ fs__default.default.rmSync(jiekTempPackageJSONPath);
441
+ console.log(`${dir}/package.json has been restored`);
442
+ console.log(
443
+ `if you want to check the compatibility of the package, you can visit: https://arethetypeswrong.github.io/?p=${name}%40${version}`
444
+ );
445
+ } else {
446
+ throw new Error(
447
+ `jiek temp \`${dir}/package.json\` not found, please confirm the jiek pre-publish command has been executed`
448
+ );
449
+ }
450
+ });
451
+ }
452
+ commander.program.action(async () => {
453
+ const {
454
+ npm_lifecycle_event: NPM_LIFECYCLE_EVENT
455
+ } = process__default.default.env;
456
+ switch (NPM_LIFECYCLE_EVENT) {
457
+ case "prepublish":
458
+ await prepublish();
459
+ break;
460
+ case "postpublish":
461
+ await postpublish();
462
+ break;
463
+ default:
464
+ commander.program.help();
465
+ }
466
+ });
467
+ const prepublishDescription = `
468
+ Prepare package.json for publish, you can add \`jk\` to the \`prepublish\` script in package.json, the command will automatically run \`jk prepublish\`.
469
+ .e.g
470
+ {
471
+ "scripts": {
472
+ "prepublish": "jk"
473
+ }
474
+ }
475
+ `.trim();
476
+ commander.program.command("prepublish").description(prepublishDescription).option("-b, --bumper <bumper>", "bump version").option("-no-b, --no-bumper", "no bump version").action(prepublish);
477
+ const postpublishDescription = `
478
+ Restore package.json after publish, you can add \`jk\` to the \`postpublish\` script in package.json, the command will automatically run \`jk postpublish\`.
479
+ .e.g
480
+ {
481
+ "scripts": {
482
+ "postpublish": "jk"
483
+ }
484
+ }
485
+ `.trim();
486
+ commander.program.command("postpublish").description(postpublishDescription).action(postpublish);
487
+
488
+ parseArgv__default.default();
package/dist/index.d.cts CHANGED
@@ -1,116 +1,4 @@
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 '@jiek/__internal__/+/rollup/base';
114
2
 
115
3
  declare module 'jiek' {
116
4
  interface Config {