jiek 0.4.5 → 0.4.7-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (164) hide show
  1. package/README.md +22 -1
  2. package/bin/jiek.js +2 -1
  3. package/dist/cli.d.mts +97 -0
  4. package/dist/cli.d.mts.map +1 -0
  5. package/dist/cli.d.ts +96 -1
  6. package/dist/cli.d.ts.map +1 -0
  7. package/dist/{cli.cjs → cli.js} +361 -226
  8. package/dist/cli.js.map +1 -0
  9. package/dist/cli.min.js +1 -0
  10. package/dist/cli.min.js.map +1 -0
  11. package/dist/cli.min.mjs +1 -0
  12. package/dist/cli.min.mjs.map +1 -0
  13. package/dist/cli.mjs +803 -0
  14. package/dist/cli.mjs.map +1 -0
  15. package/dist/index.d.mts +58 -0
  16. package/dist/index.d.mts.map +1 -0
  17. package/dist/index.d.ts +47 -46
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/{index.cjs → index.js} +0 -1
  20. package/dist/index.js.map +1 -0
  21. package/dist/{index.min.cjs → index.min.js} +0 -1
  22. package/dist/index.min.js.map +1 -0
  23. package/dist/index.min.mjs +1 -0
  24. package/dist/index.min.mjs.map +1 -0
  25. package/dist/{index.esm.js → index.mjs} +0 -1
  26. package/dist/index.mjs.map +1 -0
  27. package/dist/rollup/index.d.mts +53 -0
  28. package/dist/rollup/index.d.mts.map +1 -0
  29. package/dist/rollup/index.d.ts +53 -0
  30. package/dist/rollup/index.d.ts.map +1 -0
  31. package/dist/rollup/index.js +553 -0
  32. package/dist/rollup/index.js.map +1 -0
  33. package/dist/rollup/index.min.js +1 -0
  34. package/dist/rollup/index.min.js.map +1 -0
  35. package/dist/rollup/index.min.mjs +1 -0
  36. package/dist/rollup/index.min.mjs.map +1 -0
  37. package/dist/rollup/index.mjs +551 -0
  38. package/dist/rollup/index.mjs.map +1 -0
  39. package/package.json +52 -35
  40. package/src/cli.ts +9 -0
  41. package/src/commands/base.ts +9 -0
  42. package/src/commands/build.ts +156 -0
  43. package/src/commands/init.ts +373 -0
  44. package/src/commands/publish.ts +156 -0
  45. package/src/index.ts +8 -0
  46. package/src/inner.ts +11 -0
  47. package/src/merge-package-json.ts +75 -0
  48. package/src/pkg.ts +1 -0
  49. package/src/rollup/base.ts +72 -0
  50. package/src/rollup/index.ts +420 -0
  51. package/src/rollup/plugins/globals.ts +34 -0
  52. package/src/rollup/plugins/progress.ts +26 -0
  53. package/src/rollup/plugins/skip.ts +23 -0
  54. package/src/rollup/utils/commonOptions.ts +9 -0
  55. package/src/rollup/utils/externalResolver.ts +21 -0
  56. package/src/rollup/utils/globalResolver.ts +13 -0
  57. package/src/rollup/utils/withMinify.ts +18 -0
  58. package/src/utils/filterSupport.ts +82 -0
  59. package/src/utils/getExports.ts +100 -0
  60. package/src/utils/getRoot.ts +16 -0
  61. package/src/utils/getWD.ts +31 -0
  62. package/src/utils/loadConfig.ts +93 -0
  63. package/src/utils/tsRegister.ts +22 -0
  64. package/dist/base.esm.d.ts +0 -55
  65. package/dist/cli.cjs.map +0 -1
  66. package/dist/cli.esm.d.ts +0 -2
  67. package/dist/cli.esm.js +0 -9
  68. package/dist/cli.esm.js.map +0 -1
  69. package/dist/cli.esm.min.js +0 -2
  70. package/dist/cli.esm.min.js.map +0 -1
  71. package/dist/cli.min.cjs +0 -2
  72. package/dist/cli.min.cjs.map +0 -1
  73. package/dist/commands/base.esm.js +0 -5
  74. package/dist/commands/base.esm.js.map +0 -1
  75. package/dist/commands/base.esm.min.js +0 -2
  76. package/dist/commands/base.esm.min.js.map +0 -1
  77. package/dist/commands/build.esm.js +0 -58
  78. package/dist/commands/build.esm.js.map +0 -1
  79. package/dist/commands/build.esm.min.js +0 -2
  80. package/dist/commands/build.esm.min.js.map +0 -1
  81. package/dist/commands/init.esm.js +0 -271
  82. package/dist/commands/init.esm.js.map +0 -1
  83. package/dist/commands/init.esm.min.js +0 -2
  84. package/dist/commands/init.esm.min.js.map +0 -1
  85. package/dist/commands/publish.esm.js +0 -76
  86. package/dist/commands/publish.esm.js.map +0 -1
  87. package/dist/commands/publish.esm.min.js +0 -2
  88. package/dist/commands/publish.esm.min.js.map +0 -1
  89. package/dist/index.cjs.map +0 -1
  90. package/dist/index.esm.d.ts +0 -6
  91. package/dist/index.esm.js.map +0 -1
  92. package/dist/index.esm.min.js +0 -2
  93. package/dist/index.esm.min.js.map +0 -1
  94. package/dist/index.min.cjs.map +0 -1
  95. package/dist/inner.esm.js +0 -10
  96. package/dist/inner.esm.js.map +0 -1
  97. package/dist/inner.esm.min.js +0 -2
  98. package/dist/inner.esm.min.js.map +0 -1
  99. package/dist/merge-package-json.esm.js +0 -64
  100. package/dist/merge-package-json.esm.js.map +0 -1
  101. package/dist/merge-package-json.esm.min.js +0 -2
  102. package/dist/merge-package-json.esm.min.js.map +0 -1
  103. package/dist/pkg.esm.js +0 -4
  104. package/dist/pkg.esm.js.map +0 -1
  105. package/dist/pkg.esm.min.js +0 -2
  106. package/dist/pkg.esm.min.js.map +0 -1
  107. package/dist/rollup/plugins/globals.esm.js +0 -31
  108. package/dist/rollup/plugins/globals.esm.js.map +0 -1
  109. package/dist/rollup/plugins/globals.esm.min.js +0 -2
  110. package/dist/rollup/plugins/globals.esm.min.js.map +0 -1
  111. package/dist/rollup/plugins/skip.esm.js +0 -16
  112. package/dist/rollup/plugins/skip.esm.js.map +0 -1
  113. package/dist/rollup/plugins/skip.esm.min.js +0 -2
  114. package/dist/rollup/plugins/skip.esm.min.js.map +0 -1
  115. package/dist/rollup/utils/commonOptions.esm.js +0 -9
  116. package/dist/rollup/utils/commonOptions.esm.js.map +0 -1
  117. package/dist/rollup/utils/commonOptions.esm.min.js +0 -2
  118. package/dist/rollup/utils/commonOptions.esm.min.js.map +0 -1
  119. package/dist/rollup/utils/externalResolver.esm.js +0 -12
  120. package/dist/rollup/utils/externalResolver.esm.js.map +0 -1
  121. package/dist/rollup/utils/externalResolver.esm.min.js +0 -2
  122. package/dist/rollup/utils/externalResolver.esm.min.js.map +0 -1
  123. package/dist/rollup/utils/globalResolver.esm.js +0 -9
  124. package/dist/rollup/utils/globalResolver.esm.js.map +0 -1
  125. package/dist/rollup/utils/globalResolver.esm.min.js +0 -2
  126. package/dist/rollup/utils/globalResolver.esm.min.js.map +0 -1
  127. package/dist/rollup/utils/withMinify.esm.js +0 -15
  128. package/dist/rollup/utils/withMinify.esm.js.map +0 -1
  129. package/dist/rollup/utils/withMinify.esm.min.js +0 -2
  130. package/dist/rollup/utils/withMinify.esm.min.js.map +0 -1
  131. package/dist/rollup.cjs +0 -330
  132. package/dist/rollup.cjs.map +0 -1
  133. package/dist/rollup.d.ts +0 -23
  134. package/dist/rollup.esm.d.ts +0 -23
  135. package/dist/rollup.esm.js +0 -248
  136. package/dist/rollup.esm.js.map +0 -1
  137. package/dist/rollup.esm.min.js +0 -2
  138. package/dist/rollup.esm.min.js.map +0 -1
  139. package/dist/rollup.min.cjs +0 -2
  140. package/dist/rollup.min.cjs.map +0 -1
  141. package/dist/utils/commondir.esm.js +0 -25
  142. package/dist/utils/commondir.esm.js.map +0 -1
  143. package/dist/utils/commondir.esm.min.js +0 -2
  144. package/dist/utils/commondir.esm.min.js.map +0 -1
  145. package/dist/utils/filterSupport.esm.js +0 -67
  146. package/dist/utils/filterSupport.esm.js.map +0 -1
  147. package/dist/utils/filterSupport.esm.min.js +0 -2
  148. package/dist/utils/filterSupport.esm.min.js.map +0 -1
  149. package/dist/utils/getRoot.esm.js +0 -14
  150. package/dist/utils/getRoot.esm.js.map +0 -1
  151. package/dist/utils/getRoot.esm.min.js +0 -2
  152. package/dist/utils/getRoot.esm.min.js.map +0 -1
  153. package/dist/utils/getWD.esm.js +0 -31
  154. package/dist/utils/getWD.esm.js.map +0 -1
  155. package/dist/utils/getWD.esm.min.js +0 -2
  156. package/dist/utils/getWD.esm.min.js.map +0 -1
  157. package/dist/utils/loadConfig.esm.js +0 -75
  158. package/dist/utils/loadConfig.esm.js.map +0 -1
  159. package/dist/utils/loadConfig.esm.min.js +0 -2
  160. package/dist/utils/loadConfig.esm.min.js.map +0 -1
  161. package/dist/utils/tsRegister.esm.js +0 -24
  162. package/dist/utils/tsRegister.esm.js.map +0 -1
  163. package/dist/utils/tsRegister.esm.min.js +0 -2
  164. package/dist/utils/tsRegister.esm.min.js.map +0 -1
@@ -6,18 +6,17 @@ var filterWorkspacePackages = require('@pnpm/filter-workspace-packages');
6
6
  var commander = require('commander');
7
7
  var jsYaml = require('js-yaml');
8
8
  var getWorkspaceDir = require('@jiek/utils/getWorkspaceDir');
9
- var childProcess = require('node:child_process');
10
- var pkger = require('@jiek/pkger');
9
+ var cliProgress = require('cli-progress');
10
+ var execa = require('execa');
11
11
  var detectIndent = require('detect-indent');
12
12
  var inquirer = require('inquirer');
13
13
  var jsoncParser = require('jsonc-parser');
14
14
  var micromatch = require('micromatch');
15
+ var childProcess = require('node:child_process');
15
16
  var bumper = require('@jiek/utils/bumper');
17
+ var entrypoints = require('@jiek/pkger/entrypoints');
16
18
 
17
- function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
18
-
19
- function _interopNamespace(e) {
20
- if (e && e.__esModule) return e;
19
+ function _interopNamespaceDefault(e) {
21
20
  var n = Object.create(null);
22
21
  if (e) {
23
22
  Object.keys(e).forEach(function (k) {
@@ -34,18 +33,14 @@ function _interopNamespace(e) {
34
33
  return Object.freeze(n);
35
34
  }
36
35
 
37
- var fs__default = /*#__PURE__*/_interopDefault(fs);
38
- var path__default = /*#__PURE__*/_interopDefault(path);
39
- var childProcess__namespace = /*#__PURE__*/_interopNamespace(childProcess);
40
- var detectIndent__default = /*#__PURE__*/_interopDefault(detectIndent);
41
- var inquirer__default = /*#__PURE__*/_interopDefault(inquirer);
36
+ var childProcess__namespace = /*#__PURE__*/_interopNamespaceDefault(childProcess);
42
37
 
43
38
  let root;
44
39
  function getRoot() {
45
40
  if (root)
46
41
  return root;
47
42
  const rootOption = commander.program.getOptionValue("root");
48
- root = rootOption ? path__default.default.isAbsolute(rootOption) ? rootOption : path__default.default.resolve(process.cwd(), rootOption) : void 0;
43
+ root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : void 0;
49
44
  return root;
50
45
  }
51
46
 
@@ -88,18 +83,18 @@ async function getSelectedProjectsGraph() {
88
83
  const root = getRoot();
89
84
  const { wd, notWorkspace } = getWD();
90
85
  if (!notWorkspace && type === "pnpm") {
91
- const pnpmWorkspaceFilePath = path__default.default.resolve(wd, "pnpm-workspace.yaml");
92
- const pnpmWorkspaceFileContent = fs__default.default.readFileSync(pnpmWorkspaceFilePath, "utf-8");
86
+ const pnpmWorkspaceFilePath = path.resolve(wd, "pnpm-workspace.yaml");
87
+ const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, "utf-8");
93
88
  const pnpmWorkspace = jsYaml.load(pnpmWorkspaceFileContent);
94
89
  if (root === wd && !filter) {
95
90
  throw new Error("root path is workspace root, please provide a filter");
96
91
  }
97
92
  if (root !== wd && !filter) {
98
- const packageJSONIsExist = fs__default.default.existsSync(path__default.default.resolve(root, "package.json"));
93
+ const packageJSONIsExist = fs.existsSync(path.resolve(root, "package.json"));
99
94
  if (!packageJSONIsExist) {
100
95
  throw new Error("root path is not workspace root, please provide a filter");
101
96
  }
102
- const packageJSON = JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(root, "package.json"), "utf-8"));
97
+ const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, "package.json"), "utf-8"));
103
98
  if (!packageJSON.name) {
104
99
  throw new Error("root path is not workspace root, please provide a filter");
105
100
  }
@@ -126,7 +121,7 @@ async function getSelectedProjectsGraph() {
126
121
  wd,
127
122
  root,
128
123
  value: {
129
- [wd]: JSON.parse(fs__default.default.readFileSync(path__default.default.resolve(wd, "package.json"), "utf-8"))
124
+ [wd]: JSON.parse(fs.readFileSync(path.resolve(wd, "package.json"), "utf-8"))
130
125
  }
131
126
  };
132
127
  }
@@ -143,85 +138,6 @@ function actionRestore() {
143
138
  new Promise((r) => resolve = r);
144
139
  }
145
140
 
146
- function commondir(files, cwd = process.cwd()) {
147
- const resolvedFiles = files.map((file) => {
148
- if (path__default.default.isAbsolute(file))
149
- return file;
150
- return path__default.default.resolve(cwd, file);
151
- });
152
- const sep = "/";
153
- const [first = ""] = resolvedFiles;
154
- const parts = first.split(sep);
155
- let common = "";
156
- for (let i = 0; i < parts.length; i++) {
157
- const segment = parts[i];
158
- if (resolvedFiles.every((file) => file.startsWith(common + segment))) {
159
- common += segment + sep;
160
- } else {
161
- break;
162
- }
163
- }
164
- return common;
165
- }
166
-
167
- function mergePackageJson(manifest, cwd, options = {}) {
168
- const {
169
- excludeDistInExports = false
170
- } = options;
171
- const {
172
- jiek: { cwd: _, ...jiek } = {}
173
- } = manifest;
174
- const { outdir = "dist" } = jiek;
175
- let { exports } = manifest;
176
- let includeIndex = false;
177
- if (typeof exports === "string") {
178
- includeIndex = true;
179
- exports = { ".": exports };
180
- }
181
- if (exports === void 0) {
182
- exports = { ".": "./src/index.ts" };
183
- }
184
- if (typeof exports === "object") {
185
- if (Array.isArray(exports) && exports.length > 0) {
186
- includeIndex = true;
187
- } else {
188
- includeIndex = !!exports["."];
189
- }
190
- }
191
- let inputs = Array.isArray(exports) ? exports : Object.entries(exports).reduce((acc, [key, value]) => {
192
- if (typeof value === "string")
193
- return key === "." ? [value, ...acc] : acc.concat(value);
194
- if (Array.isArray(value))
195
- return acc.concat(value);
196
- throw new TypeError(`Unexpected value type for key "${key}" in exports, expected string, got ${typeof value}`);
197
- }, []);
198
- if (excludeDistInExports) {
199
- inputs = inputs.filter((input) => !input.startsWith(`./${outdir}`) && !input.startsWith(outdir));
200
- }
201
- if (inputs.length === 0)
202
- throw new Error("No inputs found");
203
- const absoluteInputs = inputs.map(
204
- (input) => path__default.default.isAbsolute(input) ? input : path__default.default.resolve(cwd, input)
205
- );
206
- let cDir = path__default.default.dirname(absoluteInputs[0]);
207
- if (absoluteInputs.length > 1) {
208
- cDir = commondir(absoluteInputs, cwd);
209
- }
210
- const resolvedInputs = absoluteInputs.map((input) => {
211
- return path__default.default.relative(cDir, input);
212
- });
213
- return {
214
- ...manifest,
215
- ...pkger.pkger({
216
- cwd,
217
- noIndex: !includeIndex,
218
- source: path__default.default.relative(cwd, cDir),
219
- inputs: resolvedInputs,
220
- ...jiek
221
- })
222
- };
223
- }
224
-
225
141
  function packageIsExist(name) {
226
142
  try {
227
143
  require.resolve(name);
@@ -244,65 +160,24 @@ for (const register of registers) {
244
160
  }
245
161
  }
246
162
 
247
- const FILE_TEMPLATE = (manifest) => `
248
- const pkg = ${JSON.stringify(manifest, null, 2)}
249
- const { jiek = {} } = pkg
250
- const templateArg = jiek.templateArgFilePath
251
- ? require.resolve(jiek.templateArgFilePath)
252
- : {
253
- styled: jiek.styled
254
- }
255
- module.exports = require('jiek/rollup').template(templateArg, pkg)
256
- `.trimStart();
257
- commander.program.command("build").option("-t, --target <type>", "target flow: esm|umd|dts, default esm,umd,dts").option("-s, --silent", "silent mode").action(async ({ target, silent }) => {
258
- actionRestore();
259
- const {
260
- wd,
261
- value = {}
262
- } = await getSelectedProjectsGraph() ?? {};
263
- if (Object.keys(value).length === 0) {
264
- throw new Error("no package found");
265
- }
266
- const jiekTempDir = (...paths) => path__default.default.resolve(wd, "node_modules/.jiek", ...paths);
267
- if (!fs__default.default.existsSync(jiekTempDir()))
268
- fs__default.default.mkdirSync(jiekTempDir());
269
- const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
270
- let i = 0;
271
- for (const [dir, manifest] of Object.entries(value)) {
272
- const newManifest = mergePackageJson(manifest, dir, { excludeDistInExports: true });
273
- const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
274
- const configFile = jiekTempDir(
275
- `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
276
- );
277
- fs__default.default.writeFileSync(configFile, FILE_TEMPLATE(newManifest));
278
- let prefix = "";
279
- if (tsRegisterName) {
280
- prefix = `node -r ${tsRegisterName} `;
281
- }
282
- const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`;
283
- childProcess__namespace.execSync(command, {
284
- cwd: dir,
285
- stdio: "inherit",
286
- env: {
287
- JIEK_TARGET: target ?? process.env.JIEK_TARGET ?? "esm,umd,dts",
288
- JIEK_SILENT: `${silent}` ?? process.env.JIEK_SILENT,
289
- JIEK_ROOT: wd
290
- }
291
- });
292
- }
293
- actionDone();
294
- });
295
-
296
163
  let configName = "jiek.config";
297
- function getConfigPath(root) {
164
+ function getConfigPath(root, dir) {
298
165
  const isSupportTsLoader = !!tsRegisterName;
299
166
  function configWithExtIsExist(ext) {
300
167
  const filenames = [
301
- path__default.default.resolve(root, `${configName}.${ext}`),
302
- path__default.default.resolve(root, `.${configName}.${ext}`)
168
+ path.resolve(process.cwd(), `${configName}.${ext}`),
169
+ path.resolve(process.cwd(), `.${configName}.${ext}`),
170
+ path.resolve(root, `${configName}.${ext}`),
171
+ path.resolve(root, `.${configName}.${ext}`)
303
172
  ];
173
+ if (dir) {
174
+ filenames.unshift(...[
175
+ path.resolve(dir, `${configName}.${ext}`),
176
+ path.resolve(dir, `.${configName}.${ext}`)
177
+ ]);
178
+ }
304
179
  for (const filename of filenames) {
305
- if (fs__default.default.existsSync(filename) && fs__default.default.lstatSync(filename).isFile()) {
180
+ if (fs.existsSync(filename) && fs.lstatSync(filename).isFile()) {
306
181
  return filename;
307
182
  }
308
183
  }
@@ -314,22 +189,22 @@ function getConfigPath(root) {
314
189
  if (isSupportTsLoader) {
315
190
  configName = configWithExtIsExist("ts") ?? configName;
316
191
  }
317
- return path__default.default.resolve(root, configName);
192
+ return path.resolve(root, configName);
318
193
  }
319
- function loadConfig() {
320
- const { wd: root, notWorkspace } = getWD();
321
- if (notWorkspace)
322
- throw new Error("not in workspace");
194
+ function loadConfig(dir) {
195
+ const { wd: root } = getWD();
323
196
  let configPath = commander.program.getOptionValue("configPath");
324
197
  if (!configPath) {
325
- configPath = getConfigPath(root);
198
+ configPath = getConfigPath(root, dir);
326
199
  } else {
327
- if (!fs__default.default.existsSync(configPath))
200
+ if (!fs.existsSync(configPath)) {
328
201
  throw new Error(`config file not found: ${configPath}`);
329
- if (!path__default.default.isAbsolute(configPath))
330
- configPath = path__default.default.resolve(root, configPath);
202
+ }
203
+ if (!path.isAbsolute(configPath)) {
204
+ configPath = path.resolve(root, configPath);
205
+ }
331
206
  }
332
- const ext = path__default.default.extname(configPath);
207
+ const ext = path.extname(configPath);
333
208
  let module;
334
209
  switch (ext) {
335
210
  case ".js":
@@ -338,7 +213,7 @@ function loadConfig() {
338
213
  case ".json":
339
214
  return require(configPath);
340
215
  case ".yaml":
341
- return jsYaml.load(fs__default.default.readFileSync(configPath, "utf-8"));
216
+ return jsYaml.load(fs.readFileSync(configPath, "utf-8"));
342
217
  case ".ts":
343
218
  if (tsRegisterName) {
344
219
  require(tsRegisterName);
@@ -359,6 +234,133 @@ function loadConfig() {
359
234
  return module.default ?? module;
360
235
  }
361
236
 
237
+ const FILE_TEMPLATE = (manifest) => `
238
+ const manifest = ${JSON.stringify(manifest, null, 2)}
239
+ module.exports = require('jiek/rollup').template(manifest)
240
+ `.trimStart();
241
+ commander.program.command("build").option("-s, --silent", "Don't display logs.").option("-e, --entries <ENTRIES>", "Specify the entries of the package.json's 'exports' field.(support glob)").action(async ({
242
+ silent,
243
+ entries
244
+ }) => {
245
+ actionRestore();
246
+ const { build } = loadConfig();
247
+ silent = silent ?? build?.silent ?? false;
248
+ const {
249
+ wd,
250
+ value = {}
251
+ } = await getSelectedProjectsGraph() ?? {};
252
+ if (Object.keys(value).length === 0) {
253
+ throw new Error("no package found");
254
+ }
255
+ const wdNodeModules = path.resolve(wd, "node_modules");
256
+ if (!fs.existsSync(wdNodeModules)) {
257
+ fs.mkdirSync(wdNodeModules);
258
+ }
259
+ const jiekTempDir = (...paths) => path.resolve(wdNodeModules, ".jiek", ...paths);
260
+ if (!fs.existsSync(jiekTempDir())) {
261
+ fs.mkdirSync(jiekTempDir());
262
+ }
263
+ const rollupBinaryPath = require.resolve("rollup").replace(/dist\/rollup.js$/, "dist/bin/rollup");
264
+ const multiBars = new cliProgress.MultiBar({
265
+ clearOnComplete: false,
266
+ hideCursor: true,
267
+ format: "- {bar} | {status} | {input} | {message}"
268
+ }, cliProgress.Presets.shades_classic);
269
+ let i = 0;
270
+ await Promise.all(
271
+ Object.entries(value).map(async ([dir, manifest]) => {
272
+ const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
273
+ const configFile = jiekTempDir(
274
+ `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
275
+ );
276
+ fs.writeFileSync(configFile, FILE_TEMPLATE(manifest));
277
+ let prefix = "";
278
+ if (tsRegisterName) {
279
+ prefix = `node -r ${tsRegisterName} `;
280
+ }
281
+ const command = `${prefix}${rollupBinaryPath} --silent -c ${configFile}`;
282
+ const child = execa.execaCommand(command, {
283
+ ipc: true,
284
+ cwd: dir,
285
+ env: {
286
+ ...process.env,
287
+ JIEK_ROOT: wd,
288
+ JIEK_ENTRIES: entries
289
+ }
290
+ });
291
+ const bars = {};
292
+ let inputMaxLen = 10;
293
+ child.on("message", (e) => {
294
+ if (e.type === "debug")
295
+ console.log(...Array.isArray(e.data) ? e.data : [e.data]);
296
+ });
297
+ !silent && child.on("message", (e) => {
298
+ if (e.type === "init") {
299
+ const { leafMap, targetsLength } = e.data;
300
+ const leafs = Array.from(leafMap.entries()).flatMap(
301
+ ([input, pathAndCondiions]) => pathAndCondiions.map(([path2, ...conditions]) => ({
302
+ input,
303
+ path: path2,
304
+ conditions
305
+ }))
306
+ );
307
+ console.log(`Package '${manifest.name}' has ${targetsLength} targets to build`);
308
+ leafs.forEach(({ input }) => {
309
+ inputMaxLen = Math.max(inputMaxLen, input.length);
310
+ });
311
+ leafs.forEach(({ input, path: path2 }) => {
312
+ const key = `${input}:${path2}`;
313
+ if (bars[key])
314
+ return;
315
+ bars[key] = multiBars.create(50, 0, {
316
+ input: input.padEnd(inputMaxLen),
317
+ status: "waiting".padEnd(10)
318
+ }, {
319
+ barsize: 20,
320
+ linewrap: true
321
+ });
322
+ });
323
+ }
324
+ if (e.type === "progress") {
325
+ const {
326
+ path: path2,
327
+ tags,
328
+ input,
329
+ event,
330
+ message
331
+ } = e.data;
332
+ const bar = bars[`${input}:${path2}`];
333
+ if (!bar)
334
+ return;
335
+ bar.update(
336
+ {
337
+ start: 0,
338
+ resolve: 20,
339
+ end: 50
340
+ }[event ?? "start"] ?? 0,
341
+ {
342
+ input: input.padEnd(inputMaxLen),
343
+ status: event?.padEnd(10),
344
+ message: `${tags?.join(", ")}: ${message}`
345
+ }
346
+ );
347
+ }
348
+ });
349
+ await new Promise((resolve, reject) => {
350
+ let errorStr = "";
351
+ child.stderr?.on("data", (data) => {
352
+ errorStr += data;
353
+ });
354
+ child.once("exit", (code) => code === 0 ? resolve() : reject(new Error(`rollup build failed:
355
+ ${errorStr}`)));
356
+ });
357
+ })
358
+ ).finally(() => {
359
+ multiBars.stop();
360
+ });
361
+ actionDone();
362
+ });
363
+
362
364
  const PACKAGE_JSON_TEMPLATE = `{
363
365
  "name": "",
364
366
  "version": "0.0.1",
@@ -404,8 +406,8 @@ function getTemplateStr(wd, template) {
404
406
  isTemplateFile = true;
405
407
  }
406
408
  if (isTemplateFile) {
407
- const templatePath = path__default.default.resolve(wd, template);
408
- templateString = fs__default.default.readFileSync(templatePath, "utf-8");
409
+ const templatePath = path.resolve(wd, template);
410
+ templateString = fs.readFileSync(templatePath, "utf-8");
409
411
  }
410
412
  return templateString;
411
413
  }
@@ -414,8 +416,8 @@ function getWDPackageJSONFiled(wd, field) {
414
416
  if (wdCache.has(wd)) {
415
417
  return wdCache.get(wd)[field];
416
418
  }
417
- const packageJSONPath = path__default.default.resolve(wd, "package.json");
418
- const packageJSON = JSON.parse(fs__default.default.readFileSync(packageJSONPath, "utf-8"));
419
+ const packageJSONPath = path.resolve(wd, "package.json");
420
+ const packageJSON = JSON.parse(fs.readFileSync(packageJSONPath, "utf-8"));
419
421
  wdCache.set(wd, packageJSON);
420
422
  return packageJSON[field];
421
423
  }
@@ -425,7 +427,7 @@ async function getName(named, name, {
425
427
  workspaceName
426
428
  }) {
427
429
  const relativePath = cwd.replace(`${wd}/`, "");
428
- let basename = path__default.default.basename(cwd);
430
+ let basename = path.basename(cwd);
429
431
  if (typeof named === "function") {
430
432
  return named(name, {
431
433
  full: wd,
@@ -438,7 +440,7 @@ async function getName(named, name, {
438
440
  if (typeof named === "object") {
439
441
  const isWD = cwd === wd;
440
442
  if (isWD) {
441
- const { rule } = await inquirer__default.default.prompt({
443
+ const { rule } = await inquirer.prompt({
442
444
  type: "list",
443
445
  name: "rule",
444
446
  message: "choose a rule",
@@ -449,7 +451,7 @@ async function getName(named, name, {
449
451
  matchedKey = rule;
450
452
  matchedRule = named[rule];
451
453
  }
452
- } else
454
+ } else {
453
455
  for (const [key, value] of Object.entries(named)) {
454
456
  if (micromatch.isMatch(relativePath, key)) {
455
457
  matchedKey = key;
@@ -463,15 +465,17 @@ async function getName(named, name, {
463
465
  break;
464
466
  }
465
467
  }
468
+ }
466
469
  }
467
470
  if (!matchedRule) {
468
471
  matchedKey = "packages/*";
469
472
  matchedRule = `@${workspaceName}/$basename`;
470
473
  }
471
- if (!matchedRule)
474
+ if (!matchedRule) {
472
475
  throw new Error("no matched rule");
476
+ }
473
477
  if (!name && isParentMatched) {
474
- basename = await inquirer__default.default.prompt({
478
+ basename = await inquirer.prompt({
475
479
  type: "input",
476
480
  name: "name",
477
481
  message: `the matched rule is \`${String(matchedRule)}\`, please input the basename
@@ -499,7 +503,7 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
499
503
  const cwd = process.cwd();
500
504
  const { init = {} } = loadConfig() ?? {};
501
505
  const { wd } = getWD();
502
- const workspaceName = path__default.default.basename(wd);
506
+ const workspaceName = path.basename(wd);
503
507
  const {
504
508
  named,
505
509
  template,
@@ -514,11 +518,11 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
514
518
  };
515
519
  let readme = _readme;
516
520
  if (readmeTemplate) {
517
- const readmeTemplatePath = path__default.default.resolve(wd, readmeTemplate);
518
- readme = fs__default.default.readFileSync(readmeTemplatePath, "utf-8");
521
+ const readmeTemplatePath = path.resolve(wd, readmeTemplate);
522
+ readme = fs.readFileSync(readmeTemplatePath, "utf-8");
519
523
  }
520
524
  const templateString = getTemplateStr(wd, template);
521
- const { indent = " " } = detectIndent__default.default(templateString);
525
+ const { indent = " " } = detectIndent(templateString);
522
526
  const formattingOptions = {
523
527
  tabSize: indent.length,
524
528
  insertSpaces: true
@@ -529,12 +533,15 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
529
533
  ];
530
534
  let newJSONString = templateString;
531
535
  for (const field of passFields) {
532
- newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(
536
+ newJSONString = jsoncParser.applyEdits(
533
537
  newJSONString,
534
- [field],
535
- getWDPackageJSONFiled(wd, field),
536
- { formattingOptions }
537
- ));
538
+ jsoncParser.modify(
539
+ newJSONString,
540
+ [field],
541
+ getWDPackageJSONFiled(wd, field),
542
+ { formattingOptions }
543
+ )
544
+ );
538
545
  }
539
546
  let [pkgName, pkgDir] = await getName(named, name, {
540
547
  wd,
@@ -542,7 +549,7 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
542
549
  workspaceName
543
550
  });
544
551
  if (!pkgDir) {
545
- const { dir } = await inquirer__default.default.prompt({
552
+ const { dir } = await inquirer.prompt({
546
553
  type: "input",
547
554
  name: "dir",
548
555
  message: "package directory",
@@ -551,7 +558,7 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
551
558
  pkgDir = dir;
552
559
  }
553
560
  if (!pkgName) {
554
- const { name: inputName } = await inquirer__default.default.prompt({
561
+ const { name: inputName } = await inquirer.prompt({
555
562
  type: "input",
556
563
  name: "name",
557
564
  message: "package name",
@@ -568,45 +575,55 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
568
575
  directory: pkgDir
569
576
  };
570
577
  }
571
- newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(
578
+ newJSONString = jsoncParser.applyEdits(
572
579
  newJSONString,
573
- ["repository"],
574
- pkgRepo,
575
- { formattingOptions }
576
- ));
580
+ jsoncParser.modify(
581
+ newJSONString,
582
+ ["repository"],
583
+ pkgRepo,
584
+ { formattingOptions }
585
+ )
586
+ );
577
587
  const homepage = `${pkgRepo?.url}/blob/master/${pkgDir}/README.md`;
578
- newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(
588
+ newJSONString = jsoncParser.applyEdits(
579
589
  newJSONString,
580
- ["homepage"],
581
- homepage,
582
- { formattingOptions }
583
- ));
590
+ jsoncParser.modify(
591
+ newJSONString,
592
+ ["homepage"],
593
+ homepage,
594
+ { formattingOptions }
595
+ )
596
+ );
584
597
  let labels = resolvedBug.labels;
585
- if (typeof labels === "function")
598
+ if (typeof labels === "function") {
586
599
  labels = labels({
587
600
  name: pkgName,
588
601
  dir: pkgDir
589
602
  });
603
+ }
590
604
  labels.push(`scope:${pkgName}`);
591
605
  const bugs = `${pkgRepo?.url}/issues/new?template=${resolvedBug.template}&labels=${labels.join(",")}`;
592
- newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(
606
+ newJSONString = jsoncParser.applyEdits(
593
607
  newJSONString,
594
- ["bugs"],
595
- bugs,
596
- { formattingOptions }
597
- ));
608
+ jsoncParser.modify(
609
+ newJSONString,
610
+ ["bugs"],
611
+ bugs,
612
+ { formattingOptions }
613
+ )
614
+ );
598
615
  function pkgDirTo(to) {
599
616
  if (!pkgDir)
600
617
  throw new Error("pkgDir is not defined");
601
- return path__default.default.resolve(pkgDir, to);
618
+ return path.resolve(pkgDir, to);
602
619
  }
603
- if (!fs__default.default.existsSync(pkgDir))
604
- fs__default.default.mkdirSync(pkgDir);
620
+ if (!fs.existsSync(pkgDir))
621
+ fs.mkdirSync(pkgDir);
605
622
  const pkgJSONFilePath = pkgDirTo("package.json");
606
- if (fs__default.default.existsSync(pkgJSONFilePath)) {
623
+ if (fs.existsSync(pkgJSONFilePath)) {
607
624
  throw new Error("package.json already exists");
608
625
  }
609
- fs__default.default.writeFileSync(pkgJSONFilePath, newJSONString);
626
+ fs.writeFileSync(pkgJSONFilePath, newJSONString);
610
627
  console.log(newJSONString, "written to", pkgJSONFilePath);
611
628
  const license = getWDPackageJSONFiled(wd, "license");
612
629
  const readmeFilePath = pkgDirTo("README.md");
@@ -617,9 +634,66 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
617
634
  });
618
635
  }
619
636
  const readmeContent = readme.replace(/\$name/g, pkgName).replace(/\$license/g, license);
620
- fs__default.default.writeFileSync(readmeFilePath, readmeContent);
637
+ fs.writeFileSync(readmeFilePath, readmeContent);
621
638
  });
622
639
 
640
+ const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
641
+ function getExports({
642
+ entrypoints: entrypoints$1,
643
+ pkgIsModule,
644
+ entries,
645
+ config,
646
+ dir,
647
+ noFilter
648
+ }) {
649
+ const dirResolve = (...paths) => path.resolve(dir ?? process.cwd(), ...paths);
650
+ const dirRelative = (path$1) => path.relative(dir ?? process.cwd(), path$1);
651
+ const { build = {} } = config ?? {};
652
+ const {
653
+ crossModuleConvertor = true
654
+ } = build;
655
+ const jsOutdir = `./${dirRelative(dirResolve(
656
+ (typeof build?.output?.dir === "object" ? build.output.dir.js : build?.output?.dir) ?? "dist"
657
+ ))}`;
658
+ const [, resolvedEntrypoints] = entrypoints.resolveEntrypoints(entrypoints$1);
659
+ if (entries) {
660
+ Object.entries(resolvedEntrypoints).forEach(([key]) => {
661
+ if (!entries.some((e) => micromatch.isMatch(key, e, { matchBase: true }))) {
662
+ delete resolvedEntrypoints[key];
663
+ }
664
+ });
665
+ }
666
+ const filteredResolvedEntrypoints = noFilter ? resolvedEntrypoints : entrypoints.filterLeafs(
667
+ resolvedEntrypoints,
668
+ {
669
+ skipValue: [
670
+ // ignore values that filename starts with `.jk-noentry`
671
+ /(^|\/)\.jk-noentry/,
672
+ ...entrypoints.DEFAULT_SKIP_VALUES
673
+ ]
674
+ }
675
+ );
676
+ const crossModuleWithConditional = crossModuleConvertor ? {
677
+ import: (opts) => !pkgIsModule && intersection(
678
+ new Set(opts.conditionals),
679
+ /* @__PURE__ */ new Set(["import", "module"])
680
+ ).size === 0 ? opts.dist.replace(/\.js$/, ".mjs") : false,
681
+ require: (opts) => pkgIsModule && intersection(
682
+ new Set(opts.conditionals),
683
+ /* @__PURE__ */ new Set(["require", "node"])
684
+ ).size === 0 ? opts.dist.replace(/\.js$/, ".cjs") : false
685
+ } : {};
686
+ return [
687
+ filteredResolvedEntrypoints,
688
+ entrypoints.entrypoints2Exports(filteredResolvedEntrypoints, {
689
+ outdir: jsOutdir,
690
+ withConditional: {
691
+ ...crossModuleWithConditional
692
+ }
693
+ })
694
+ ];
695
+ }
696
+
623
697
  commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>", "bump version", "patch").option("-p, --preview", "preview publish").action(async ({ preview, bumper: bumper$1, ...options }) => {
624
698
  actionRestore();
625
699
  const { value = {} } = await getSelectedProjectsGraph() ?? {};
@@ -627,45 +701,107 @@ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper
627
701
  if (selectedProjectsGraphEntries.length === 0) {
628
702
  throw new Error("no packages selected");
629
703
  }
630
- const mainfests = selectedProjectsGraphEntries.map(([dir, manifest]) => [
631
- dir,
632
- mergePackageJson(manifest, dir)
633
- ]);
704
+ const manifests = selectedProjectsGraphEntries.map(([dir, manifest]) => {
705
+ const { type, exports: entrypoints = {} } = manifest;
706
+ const pkgIsModule = type === "module";
707
+ const newManifest = { ...manifest };
708
+ const [resolvedEntrypoints, exports] = getExports({
709
+ entrypoints,
710
+ pkgIsModule,
711
+ config: loadConfig(dir),
712
+ dir,
713
+ noFilter: true
714
+ });
715
+ newManifest.exports = {
716
+ ...resolvedEntrypoints,
717
+ ...exports
718
+ };
719
+ return [dir, newManifest];
720
+ });
634
721
  const passArgs = Object.entries(options).reduce((acc, [key, value2]) => {
635
722
  if (value2) {
636
723
  acc.push(`--${key}`, value2);
637
724
  }
638
725
  return acc;
639
726
  }, []);
640
- for (const [dir, manifest] of mainfests) {
641
- const oldJSONString = fs__default.default.readFileSync(path__default.default.join(dir, "package.json"), "utf-8");
727
+ for (const [dir, manifest] of manifests) {
728
+ const oldJSONString = fs.readFileSync(path.join(dir, "package.json"), "utf-8");
642
729
  const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
643
730
  const newVersion = bumper.bump(oldJSON.version, bumper$1);
644
- const { indent = " " } = detectIndent__default.default(oldJSONString);
731
+ const { indent = " " } = detectIndent(oldJSONString);
645
732
  const formattingOptions = {
646
733
  tabSize: indent.length,
647
734
  insertSpaces: true
648
735
  };
649
736
  let newJSONString = oldJSONString;
650
- newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(
737
+ newJSONString = jsoncParser.applyEdits(
651
738
  newJSONString,
652
- ["version"],
653
- newVersion,
654
- { formattingOptions }
655
- ));
739
+ jsoncParser.modify(
740
+ newJSONString,
741
+ ["version"],
742
+ newVersion,
743
+ { formattingOptions }
744
+ )
745
+ );
656
746
  for (const [key, value2] of Object.entries(manifest)) {
657
747
  if (JSON.stringify(value2) === JSON.stringify(oldJSON[key]))
658
748
  continue;
659
- newJSONString = jsoncParser.applyEdits(newJSONString, jsoncParser.modify(
660
- newJSONString,
661
- ["publishConfig", key],
662
- value2,
663
- { formattingOptions }
664
- ));
749
+ if (key !== "exports") {
750
+ newJSONString = jsoncParser.applyEdits(
751
+ newJSONString,
752
+ jsoncParser.modify(
753
+ newJSONString,
754
+ ["publishConfig", key],
755
+ value2,
756
+ { formattingOptions }
757
+ )
758
+ );
759
+ } else {
760
+ const exports = value2;
761
+ for (const [k, v] of Object.entries(exports)) {
762
+ newJSONString = jsoncParser.applyEdits(
763
+ newJSONString,
764
+ jsoncParser.modify(
765
+ newJSONString,
766
+ ["publishConfig", "exports", k],
767
+ v,
768
+ { formattingOptions }
769
+ )
770
+ );
771
+ }
772
+ const index = exports?.["."];
773
+ const indexPublishConfig = {};
774
+ if (index) {
775
+ switch (typeof index) {
776
+ case "string":
777
+ indexPublishConfig[manifest?.type === "module" ? "module" : "main"] = index;
778
+ break;
779
+ case "object": {
780
+ const indexExports = index;
781
+ indexPublishConfig.main = indexExports["require"] ?? indexExports["default"];
782
+ indexPublishConfig.module = indexExports["import"] ?? indexExports["module"] ?? indexExports["default"];
783
+ break;
784
+ }
785
+ }
786
+ for (const [k, v] of Object.entries(indexPublishConfig)) {
787
+ if (v === void 0)
788
+ continue;
789
+ newJSONString = jsoncParser.applyEdits(
790
+ newJSONString,
791
+ jsoncParser.modify(
792
+ newJSONString,
793
+ ["publishConfig", k],
794
+ v,
795
+ { formattingOptions }
796
+ )
797
+ );
798
+ }
799
+ }
800
+ }
665
801
  }
666
802
  try {
667
- fs__default.default.renameSync(path__default.default.join(dir, "package.json"), path__default.default.join(dir, "package.json.bak"));
668
- fs__default.default.writeFileSync(path__default.default.join(dir, "package.json"), newJSONString);
803
+ fs.renameSync(path.join(dir, "package.json"), path.join(dir, "package.json.bak"));
804
+ fs.writeFileSync(path.join(dir, "package.json"), newJSONString);
669
805
  console.log(newJSONString);
670
806
  if (preview) {
671
807
  console.warn("preview mode");
@@ -676,14 +812,13 @@ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper
676
812
  stdio: "inherit"
677
813
  });
678
814
  const modifyVersionPackageJSON = jsoncParser.applyEdits(oldJSONString, jsoncParser.modify(oldJSONString, ["version"], newVersion, {}));
679
- fs__default.default.writeFileSync(path__default.default.join(dir, "package.json.bak"), modifyVersionPackageJSON);
815
+ fs.writeFileSync(path.join(dir, "package.json.bak"), modifyVersionPackageJSON);
680
816
  } finally {
681
- fs__default.default.unlinkSync(path__default.default.join(dir, "package.json"));
682
- fs__default.default.renameSync(path__default.default.join(dir, "package.json.bak"), path__default.default.join(dir, "package.json"));
817
+ fs.unlinkSync(path.join(dir, "package.json"));
818
+ fs.renameSync(path.join(dir, "package.json.bak"), path.join(dir, "package.json"));
683
819
  }
684
820
  }
685
821
  actionDone();
686
822
  });
687
823
 
688
824
  commander.program.parse(process.argv);
689
- //# sourceMappingURL=cli.cjs.map