jiek 1.1.7 → 1.1.9-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.
package/dist/cli.cjs CHANGED
@@ -149,7 +149,7 @@ async function getSelectedProjectsGraph(filter = commander.program.getOptionValu
149
149
 
150
150
  var name = "jiek";
151
151
  var type = "module";
152
- var version = "1.1.6";
152
+ var version = "1.1.9-alpha.1";
153
153
  var description$1 = "YiJie's personal kits.";
154
154
  var bin = {
155
155
  jiek: "bin/jiek.js",
@@ -162,14 +162,8 @@ var files = [
162
162
  "LICENSE",
163
163
  "README.md"
164
164
  ];
165
- var typesVersions = {
166
- "<5.0": {
167
- "*": [
168
- "*",
169
- "./dist/*",
170
- "./dist/*/index.d.ts"
171
- ]
172
- }
165
+ var scripts = {
166
+ prepublish: "jk build --noMin"
173
167
  };
174
168
  var exports$1 = {
175
169
  "./package.json": "./package.json",
@@ -220,6 +214,39 @@ var devDependencies = {
220
214
  postcss: "^8.4.47",
221
215
  "rollup-plugin-postcss": "^4.0.2"
222
216
  };
217
+ var publishConfig = {
218
+ exports: {
219
+ "./package.json": "./package.json",
220
+ ".": {
221
+ source: "./src/index.ts",
222
+ require: "./dist/index.cjs",
223
+ "default": "./dist/index.js"
224
+ },
225
+ "./cli": {
226
+ source: "./src/cli.ts",
227
+ require: "./dist/cli.cjs",
228
+ "default": "./dist/cli.js"
229
+ },
230
+ "./rollup": {
231
+ source: "./src/rollup/index.ts",
232
+ require: "./dist/rollup/index.cjs",
233
+ "default": "./dist/rollup/index.js"
234
+ }
235
+ },
236
+ main: "./dist/index.cjs",
237
+ module: "./dist/index.js",
238
+ typesVersions: {
239
+ "<5.0": {
240
+ "*": [
241
+ "*",
242
+ "./dist/*",
243
+ "./dist/*/index.d.ts",
244
+ "./dist/*/index.d.mts",
245
+ "./dist/*/index.d.cts"
246
+ ]
247
+ }
248
+ }
249
+ };
223
250
  var pkg = {
224
251
  name: name,
225
252
  type: type,
@@ -227,12 +254,13 @@ var pkg = {
227
254
  description: description$1,
228
255
  bin: bin,
229
256
  files: files,
230
- typesVersions: typesVersions,
257
+ scripts: scripts,
231
258
  exports: exports$1,
232
259
  imports: imports,
233
260
  dependencies: dependencies,
234
261
  optionalDependencies: optionalDependencies,
235
- devDependencies: devDependencies
262
+ devDependencies: devDependencies,
263
+ publishConfig: publishConfig
236
264
  };
237
265
 
238
266
  commander.program.version(pkg.version).description(pkg.description).option("--root <root>", "root path").option("-c, --config-path <configPath>", "config path");
@@ -351,6 +379,12 @@ function loadConfig(dirOrOptions) {
351
379
  return module.default ?? module;
352
380
  }
353
381
 
382
+ const outdirDescription = `
383
+ The output directory of the build, which relative to the target subpackage root directory.
384
+ Support with variables: 'PKG_NAME',
385
+ .e.g. 'dist/{{PKG_NAME}}'.
386
+ `.trim();
387
+
354
388
  const FILE_TEMPLATE = (manifest) => `
355
389
  module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
356
390
  `.trimStart();
@@ -358,16 +392,45 @@ const require$1 = node_module.createRequire((typeof document === 'undefined' ? r
358
392
  const description = `
359
393
  Build the package according to the 'exports' field in the package.json.
360
394
  `.trim();
361
- commander.program.command("build").description(description).option("-s, --silent", "Don't display logs.").option("-e, --entries <ENTRIES>", "Specify the entries of the package.json's 'exports' field.(support glob)").option("--without-js", "Do not output js files.").option("--without-dts", "Do not output dts files.").option("-v, --verbose", "Display debug logs.").action(async ({
395
+ function parseBoolean(v) {
396
+ if (v === void 0)
397
+ return true;
398
+ return Boolean(v);
399
+ }
400
+ commander.program.command("build").description(description).option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option("-e, --entries <ENTRIES>", "Specify the entries of the package.json's 'exports' field.(support glob)").option("-nj, --noJs", "Do not output js files.", parseBoolean).option("-nd, --noDts", "Do not output dts files.", parseBoolean).option("-nm, --noMin", "Do not output minify files.", parseBoolean).option("-nc, --noClean", "Do not clean the output directory before building.", parseBoolean).option(
401
+ "-om, --onlyMin",
402
+ "Only output minify files, but dts files will still be output, it only replaces the js files.",
403
+ parseBoolean
404
+ ).option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean).action(async ({
405
+ outdir,
362
406
  silent,
363
407
  entries,
364
408
  verbose,
365
- withoutJs,
366
- withoutDts
409
+ noJs: withoutJs,
410
+ noDts: withoutDts,
411
+ noMin: withoutMin,
412
+ noClean,
413
+ onlyMin
367
414
  }) => {
368
415
  actionRestore();
369
416
  const { build } = loadConfig();
370
417
  silent = silent ?? build?.silent ?? false;
418
+ if (withoutMin && onlyMin) {
419
+ throw new Error("Cannot use both --without-minify and --only-minify");
420
+ }
421
+ if (onlyMin && withoutJs) {
422
+ throw new Error("Cannot use --without-js and --only-minify at the same time");
423
+ }
424
+ const env = {
425
+ ...process.env,
426
+ JIEK_OUT_DIR: outdir,
427
+ JIEK_CLEAN: String(!noClean),
428
+ JIEK_ENTRIES: entries,
429
+ JIEK_WITHOUT_JS: String(withoutJs),
430
+ JIEK_WITHOUT_DTS: String(withoutDts),
431
+ JIEK_WITHOUT_MINIFY: String(withoutMin),
432
+ JIEK_ONLY_MINIFY: String(onlyMin)
433
+ };
371
434
  const multiBars = new cliProgress.MultiBar({
372
435
  clearOnComplete: false,
373
436
  hideCursor: true,
@@ -392,7 +455,10 @@ commander.program.command("build").description(description).option("-s, --silent
392
455
  let i = 0;
393
456
  await Promise.all(
394
457
  Object.entries(value).map(async ([dir, manifest]) => {
395
- const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
458
+ if (!manifest.name) {
459
+ throw new Error("package.json must have a name field");
460
+ }
461
+ const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
396
462
  const configFile = jiekTempDir(
397
463
  `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
398
464
  );
@@ -406,11 +472,9 @@ commander.program.command("build").description(description).option("-s, --silent
406
472
  ipc: true,
407
473
  cwd: dir,
408
474
  env: {
409
- ...process.env,
410
- JIEK_ROOT: wd,
411
- JIEK_ENTRIES: entries,
412
- JIEK_WITHOUT_JS: String(withoutJs),
413
- JIEK_WITHOUT_DTS: String(withoutDts)
475
+ ...env,
476
+ JIEK_NAME: manifest.name,
477
+ JIEK_ROOT: wd
414
478
  }
415
479
  });
416
480
  const bars = {};
@@ -4881,17 +4945,43 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
4881
4945
  });
4882
4946
 
4883
4947
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4948
+ const {
4949
+ JIEK_OUT_DIR
4950
+ } = process.env;
4951
+ const OUTDIR = JIEK_OUT_DIR ?? "dist";
4952
+ function getOutDirs({
4953
+ cwd = process.cwd(),
4954
+ defaultOutdir = OUTDIR,
4955
+ config,
4956
+ pkgName
4957
+ }) {
4958
+ const { build = {} } = config ?? {};
4959
+ const outdir = build?.output?.dir;
4960
+ function resolveOutdir(type) {
4961
+ const dir = (typeof outdir === "object" ? outdir[type] ?? outdir[{
4962
+ js: "dts",
4963
+ dts: "js"
4964
+ }[type]] : outdir) ?? defaultOutdir;
4965
+ return (path.isAbsolute(dir) ? dir : `./${path.relative(cwd, path.resolve(cwd, dir))}`).replace("{{PKG_NAME}}", pkgName);
4966
+ }
4967
+ return {
4968
+ js: resolveOutdir("js"),
4969
+ dts: resolveOutdir("dts")
4970
+ };
4971
+ }
4884
4972
  function getExports({
4885
4973
  entrypoints: entrypoints$1,
4974
+ pkgName,
4886
4975
  pkgIsModule,
4887
4976
  entries,
4888
4977
  config,
4889
4978
  dir,
4979
+ defaultOutdir = OUTDIR,
4980
+ // FIXME dts support
4981
+ outdir = getOutDirs({ pkgName, defaultOutdir, config, cwd: dir }).js,
4890
4982
  noFilter,
4891
4983
  isPublish
4892
4984
  }) {
4893
- const dirResolve = (...paths) => path.resolve(dir ?? process.cwd(), ...paths);
4894
- const dirRelative = (path$1) => path.relative(dir ?? process.cwd(), path$1);
4895
4985
  const {
4896
4986
  build = {},
4897
4987
  publish: {
@@ -4902,9 +4992,6 @@ function getExports({
4902
4992
  const {
4903
4993
  crossModuleConvertor = true
4904
4994
  } = build;
4905
- const jsOutdir = `./${dirRelative(dirResolve(
4906
- (typeof build?.output?.dir === "object" ? build.output.dir.js : build?.output?.dir) ?? "dist"
4907
- ))}`;
4908
4995
  const [, resolvedEntrypoints] = entrypoints.resolveEntrypoints(entrypoints$1);
4909
4996
  if (entries) {
4910
4997
  Object.entries(resolvedEntrypoints).forEach(([key]) => {
@@ -4936,17 +5023,18 @@ function getExports({
4936
5023
  return [
4937
5024
  filteredResolvedEntrypoints,
4938
5025
  entrypoints.entrypoints2Exports(filteredResolvedEntrypoints, {
4939
- outdir: jsOutdir,
5026
+ outdir,
4940
5027
  withSuffix: isPublish ? withSuffix : void 0,
4941
5028
  withSource: isPublish ? withSource : void 0,
4942
5029
  withConditional: {
4943
5030
  ...crossModuleWithConditional
4944
5031
  }
4945
- })
5032
+ }),
5033
+ outdir
4946
5034
  ];
4947
5035
  }
4948
5036
 
4949
- commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>", "bump version", "patch").option("-no-b, --no-bumper", "no bump version").option("-p, --preview", "preview publish").action(async ({ preview, bumper: bumper$1, ...options }) => {
5037
+ commander.program.command("publish").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").option("-s, --silent", "no output").option("-p, --preview", "preview publish").action(async ({ outdir, preview, silent, bumper: bumper$1, ...options }) => {
4950
5038
  actionRestore();
4951
5039
  const { value = {} } = await getSelectedProjectsGraph() ?? {};
4952
5040
  const selectedProjectsGraphEntries = Object.entries(value);
@@ -4954,14 +5042,19 @@ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper
4954
5042
  throw new Error("no packages selected");
4955
5043
  }
4956
5044
  const manifests = selectedProjectsGraphEntries.map(([dir, manifest]) => {
4957
- const { type, exports: entrypoints = {} } = manifest;
5045
+ const { name, type, exports: entrypoints = {} } = manifest;
5046
+ if (!name) {
5047
+ throw new Error(`package.json in ${dir} must have a name field`);
5048
+ }
4958
5049
  const pkgIsModule = type === "module";
4959
5050
  const newManifest = { ...manifest };
4960
- const [resolvedEntrypoints, exports] = getExports({
5051
+ const [resolvedEntrypoints, exports, resolvedOutdir] = getExports({
4961
5052
  entrypoints,
4962
5053
  pkgIsModule,
5054
+ pkgName: name,
4963
5055
  config: loadConfig(dir),
4964
5056
  dir,
5057
+ defaultOutdir: outdir,
4965
5058
  noFilter: true,
4966
5059
  isPublish: true
4967
5060
  });
@@ -4969,7 +5062,7 @@ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper
4969
5062
  ...resolvedEntrypoints,
4970
5063
  ...exports
4971
5064
  };
4972
- return [dir, newManifest];
5065
+ return [dir, newManifest, resolvedOutdir];
4973
5066
  });
4974
5067
  const passArgs = Object.entries(options).reduce((acc, [key, value2]) => {
4975
5068
  if (value2) {
@@ -4977,7 +5070,7 @@ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper
4977
5070
  }
4978
5071
  return acc;
4979
5072
  }, []);
4980
- for (const [dir, manifest] of manifests) {
5073
+ for (const [dir, manifest, resolvedOutdir] of manifests) {
4981
5074
  const oldJSONString = fs__default.default.readFileSync(path__default.default.join(dir, "package.json"), "utf-8");
4982
5075
  const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
4983
5076
  const newVersion = bumper$1 ? bumper.bump(oldJSON.version, bumper$1) : oldJSON.version;
@@ -5052,15 +5145,37 @@ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper
5052
5145
  }
5053
5146
  }
5054
5147
  }
5148
+ newJSONString = jsoncParser.applyEdits(
5149
+ newJSONString,
5150
+ jsoncParser.modify(
5151
+ newJSONString,
5152
+ ["publishConfig", "typesVersions"],
5153
+ {
5154
+ "<5.0": {
5155
+ "*": [
5156
+ "*",
5157
+ `${resolvedOutdir}/*`,
5158
+ `${resolvedOutdir}/*/index.d.ts`,
5159
+ `${resolvedOutdir}/*/index.d.mts`,
5160
+ `${resolvedOutdir}/*/index.d.cts`
5161
+ ]
5162
+ }
5163
+ },
5164
+ { formattingOptions }
5165
+ )
5166
+ );
5055
5167
  try {
5056
5168
  fs__default.default.renameSync(path__default.default.join(dir, "package.json"), path__default.default.join(dir, "package.json.bak"));
5057
5169
  fs__default.default.writeFileSync(path__default.default.join(dir, "package.json"), newJSONString);
5058
- console.log(newJSONString);
5170
+ !silent && console.log(newJSONString);
5059
5171
  if (preview) {
5060
- console.warn("preview mode");
5061
5172
  continue;
5062
5173
  }
5063
- childProcess__namespace.execSync(["pnpm", "publish", "--access", "public", "--no-git-checks", ...passArgs].join(" "), {
5174
+ const args = ["pnpm", "publish", "--access", "public", "--no-git-checks", ...passArgs];
5175
+ if (bumper$1 && bumper.TAGS.includes(bumper$1)) {
5176
+ args.push("--tag", bumper$1);
5177
+ }
5178
+ childProcess__namespace.execSync(args.join(" "), {
5064
5179
  cwd: dir,
5065
5180
  stdio: "inherit"
5066
5181
  });
package/dist/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import fs from 'node:fs';
2
2
  import { createRequire } from 'node:module';
3
- import path, { resolve as resolve$1, relative } from 'node:path';
3
+ import path, { isAbsolute, relative, resolve as resolve$1 } from 'node:path';
4
4
  import { filterPackagesFromDir } from '@pnpm/filter-workspace-packages';
5
5
  import { program } from 'commander';
6
6
  import { load } from 'js-yaml';
@@ -13,7 +13,7 @@ import { applyEdits, modify } from 'jsonc-parser';
13
13
  import require$$0 from 'util';
14
14
  import require$$0$1 from 'path';
15
15
  import * as childProcess from 'node:child_process';
16
- import { bump } from '@jiek/utils/bumper';
16
+ import { bump, TAGS } from '@jiek/utils/bumper';
17
17
  import { resolveEntrypoints, filterLeafs, DEFAULT_SKIP_VALUES, entrypoints2Exports } from '@jiek/pkger/entrypoints';
18
18
 
19
19
  let root;
@@ -118,7 +118,7 @@ async function getSelectedProjectsGraph(filter = program.getOptionValue("filter"
118
118
 
119
119
  var name = "jiek";
120
120
  var type = "module";
121
- var version = "1.1.6";
121
+ var version = "1.1.9-alpha.1";
122
122
  var description$1 = "YiJie's personal kits.";
123
123
  var bin = {
124
124
  jiek: "bin/jiek.js",
@@ -131,14 +131,8 @@ var files = [
131
131
  "LICENSE",
132
132
  "README.md"
133
133
  ];
134
- var typesVersions = {
135
- "<5.0": {
136
- "*": [
137
- "*",
138
- "./dist/*",
139
- "./dist/*/index.d.ts"
140
- ]
141
- }
134
+ var scripts = {
135
+ prepublish: "jk build --noMin"
142
136
  };
143
137
  var exports = {
144
138
  "./package.json": "./package.json",
@@ -189,6 +183,39 @@ var devDependencies = {
189
183
  postcss: "^8.4.47",
190
184
  "rollup-plugin-postcss": "^4.0.2"
191
185
  };
186
+ var publishConfig = {
187
+ exports: {
188
+ "./package.json": "./package.json",
189
+ ".": {
190
+ source: "./src/index.ts",
191
+ require: "./dist/index.cjs",
192
+ "default": "./dist/index.js"
193
+ },
194
+ "./cli": {
195
+ source: "./src/cli.ts",
196
+ require: "./dist/cli.cjs",
197
+ "default": "./dist/cli.js"
198
+ },
199
+ "./rollup": {
200
+ source: "./src/rollup/index.ts",
201
+ require: "./dist/rollup/index.cjs",
202
+ "default": "./dist/rollup/index.js"
203
+ }
204
+ },
205
+ main: "./dist/index.cjs",
206
+ module: "./dist/index.js",
207
+ typesVersions: {
208
+ "<5.0": {
209
+ "*": [
210
+ "*",
211
+ "./dist/*",
212
+ "./dist/*/index.d.ts",
213
+ "./dist/*/index.d.mts",
214
+ "./dist/*/index.d.cts"
215
+ ]
216
+ }
217
+ }
218
+ };
192
219
  var pkg = {
193
220
  name: name,
194
221
  type: type,
@@ -196,12 +223,13 @@ var pkg = {
196
223
  description: description$1,
197
224
  bin: bin,
198
225
  files: files,
199
- typesVersions: typesVersions,
226
+ scripts: scripts,
200
227
  exports: exports,
201
228
  imports: imports,
202
229
  dependencies: dependencies,
203
230
  optionalDependencies: optionalDependencies,
204
- devDependencies: devDependencies
231
+ devDependencies: devDependencies,
232
+ publishConfig: publishConfig
205
233
  };
206
234
 
207
235
  program.version(pkg.version).description(pkg.description).option("--root <root>", "root path").option("-c, --config-path <configPath>", "config path");
@@ -320,6 +348,12 @@ function loadConfig(dirOrOptions) {
320
348
  return module.default ?? module;
321
349
  }
322
350
 
351
+ const outdirDescription = `
352
+ The output directory of the build, which relative to the target subpackage root directory.
353
+ Support with variables: 'PKG_NAME',
354
+ .e.g. 'dist/{{PKG_NAME}}'.
355
+ `.trim();
356
+
323
357
  const FILE_TEMPLATE = (manifest) => `
324
358
  module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
325
359
  `.trimStart();
@@ -327,16 +361,45 @@ const require = createRequire(import.meta.url);
327
361
  const description = `
328
362
  Build the package according to the 'exports' field in the package.json.
329
363
  `.trim();
330
- program.command("build").description(description).option("-s, --silent", "Don't display logs.").option("-e, --entries <ENTRIES>", "Specify the entries of the package.json's 'exports' field.(support glob)").option("--without-js", "Do not output js files.").option("--without-dts", "Do not output dts files.").option("-v, --verbose", "Display debug logs.").action(async ({
364
+ function parseBoolean(v) {
365
+ if (v === void 0)
366
+ return true;
367
+ return Boolean(v);
368
+ }
369
+ program.command("build").description(description).option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").option("-e, --entries <ENTRIES>", "Specify the entries of the package.json's 'exports' field.(support glob)").option("-nj, --noJs", "Do not output js files.", parseBoolean).option("-nd, --noDts", "Do not output dts files.", parseBoolean).option("-nm, --noMin", "Do not output minify files.", parseBoolean).option("-nc, --noClean", "Do not clean the output directory before building.", parseBoolean).option(
370
+ "-om, --onlyMin",
371
+ "Only output minify files, but dts files will still be output, it only replaces the js files.",
372
+ parseBoolean
373
+ ).option("-s, --silent", "Don't display logs.", parseBoolean).option("-v, --verbose", "Display debug logs.", parseBoolean).action(async ({
374
+ outdir,
331
375
  silent,
332
376
  entries,
333
377
  verbose,
334
- withoutJs,
335
- withoutDts
378
+ noJs: withoutJs,
379
+ noDts: withoutDts,
380
+ noMin: withoutMin,
381
+ noClean,
382
+ onlyMin
336
383
  }) => {
337
384
  actionRestore();
338
385
  const { build } = loadConfig();
339
386
  silent = silent ?? build?.silent ?? false;
387
+ if (withoutMin && onlyMin) {
388
+ throw new Error("Cannot use both --without-minify and --only-minify");
389
+ }
390
+ if (onlyMin && withoutJs) {
391
+ throw new Error("Cannot use --without-js and --only-minify at the same time");
392
+ }
393
+ const env = {
394
+ ...process.env,
395
+ JIEK_OUT_DIR: outdir,
396
+ JIEK_CLEAN: String(!noClean),
397
+ JIEK_ENTRIES: entries,
398
+ JIEK_WITHOUT_JS: String(withoutJs),
399
+ JIEK_WITHOUT_DTS: String(withoutDts),
400
+ JIEK_WITHOUT_MINIFY: String(withoutMin),
401
+ JIEK_ONLY_MINIFY: String(onlyMin)
402
+ };
340
403
  const multiBars = new MultiBar({
341
404
  clearOnComplete: false,
342
405
  hideCursor: true,
@@ -361,7 +424,10 @@ program.command("build").description(description).option("-s, --silent", "Don't
361
424
  let i = 0;
362
425
  await Promise.all(
363
426
  Object.entries(value).map(async ([dir, manifest]) => {
364
- const escapeManifestName = manifest.name?.replace(/^@/g, "").replace(/\//g, "+");
427
+ if (!manifest.name) {
428
+ throw new Error("package.json must have a name field");
429
+ }
430
+ const escapeManifestName = manifest.name.replace(/^@/g, "").replace(/\//g, "+");
365
431
  const configFile = jiekTempDir(
366
432
  `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
367
433
  );
@@ -375,11 +441,9 @@ program.command("build").description(description).option("-s, --silent", "Don't
375
441
  ipc: true,
376
442
  cwd: dir,
377
443
  env: {
378
- ...process.env,
379
- JIEK_ROOT: wd,
380
- JIEK_ENTRIES: entries,
381
- JIEK_WITHOUT_JS: String(withoutJs),
382
- JIEK_WITHOUT_DTS: String(withoutDts)
444
+ ...env,
445
+ JIEK_NAME: manifest.name,
446
+ JIEK_ROOT: wd
383
447
  }
384
448
  });
385
449
  const bars = {};
@@ -4850,17 +4914,43 @@ program.command("init [name]").option("-t, --template <template>", "the package.
4850
4914
  });
4851
4915
 
4852
4916
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4917
+ const {
4918
+ JIEK_OUT_DIR
4919
+ } = process.env;
4920
+ const OUTDIR = JIEK_OUT_DIR ?? "dist";
4921
+ function getOutDirs({
4922
+ cwd = process.cwd(),
4923
+ defaultOutdir = OUTDIR,
4924
+ config,
4925
+ pkgName
4926
+ }) {
4927
+ const { build = {} } = config ?? {};
4928
+ const outdir = build?.output?.dir;
4929
+ function resolveOutdir(type) {
4930
+ const dir = (typeof outdir === "object" ? outdir[type] ?? outdir[{
4931
+ js: "dts",
4932
+ dts: "js"
4933
+ }[type]] : outdir) ?? defaultOutdir;
4934
+ return (isAbsolute(dir) ? dir : `./${relative(cwd, resolve$1(cwd, dir))}`).replace("{{PKG_NAME}}", pkgName);
4935
+ }
4936
+ return {
4937
+ js: resolveOutdir("js"),
4938
+ dts: resolveOutdir("dts")
4939
+ };
4940
+ }
4853
4941
  function getExports({
4854
4942
  entrypoints,
4943
+ pkgName,
4855
4944
  pkgIsModule,
4856
4945
  entries,
4857
4946
  config,
4858
4947
  dir,
4948
+ defaultOutdir = OUTDIR,
4949
+ // FIXME dts support
4950
+ outdir = getOutDirs({ pkgName, defaultOutdir, config, cwd: dir }).js,
4859
4951
  noFilter,
4860
4952
  isPublish
4861
4953
  }) {
4862
- const dirResolve = (...paths) => resolve$1(dir ?? process.cwd(), ...paths);
4863
- const dirRelative = (path) => relative(dir ?? process.cwd(), path);
4864
4954
  const {
4865
4955
  build = {},
4866
4956
  publish: {
@@ -4871,9 +4961,6 @@ function getExports({
4871
4961
  const {
4872
4962
  crossModuleConvertor = true
4873
4963
  } = build;
4874
- const jsOutdir = `./${dirRelative(dirResolve(
4875
- (typeof build?.output?.dir === "object" ? build.output.dir.js : build?.output?.dir) ?? "dist"
4876
- ))}`;
4877
4964
  const [, resolvedEntrypoints] = resolveEntrypoints(entrypoints);
4878
4965
  if (entries) {
4879
4966
  Object.entries(resolvedEntrypoints).forEach(([key]) => {
@@ -4905,17 +4992,18 @@ function getExports({
4905
4992
  return [
4906
4993
  filteredResolvedEntrypoints,
4907
4994
  entrypoints2Exports(filteredResolvedEntrypoints, {
4908
- outdir: jsOutdir,
4995
+ outdir,
4909
4996
  withSuffix: isPublish ? withSuffix : void 0,
4910
4997
  withSource: isPublish ? withSource : void 0,
4911
4998
  withConditional: {
4912
4999
  ...crossModuleWithConditional
4913
5000
  }
4914
- })
5001
+ }),
5002
+ outdir
4915
5003
  ];
4916
5004
  }
4917
5005
 
4918
- program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>", "bump version", "patch").option("-no-b, --no-bumper", "no bump version").option("-p, --preview", "preview publish").action(async ({ preview, bumper, ...options }) => {
5006
+ program.command("publish").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").option("-s, --silent", "no output").option("-p, --preview", "preview publish").action(async ({ outdir, preview, silent, bumper, ...options }) => {
4919
5007
  actionRestore();
4920
5008
  const { value = {} } = await getSelectedProjectsGraph() ?? {};
4921
5009
  const selectedProjectsGraphEntries = Object.entries(value);
@@ -4923,14 +5011,19 @@ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>",
4923
5011
  throw new Error("no packages selected");
4924
5012
  }
4925
5013
  const manifests = selectedProjectsGraphEntries.map(([dir, manifest]) => {
4926
- const { type, exports: entrypoints = {} } = manifest;
5014
+ const { name, type, exports: entrypoints = {} } = manifest;
5015
+ if (!name) {
5016
+ throw new Error(`package.json in ${dir} must have a name field`);
5017
+ }
4927
5018
  const pkgIsModule = type === "module";
4928
5019
  const newManifest = { ...manifest };
4929
- const [resolvedEntrypoints, exports] = getExports({
5020
+ const [resolvedEntrypoints, exports, resolvedOutdir] = getExports({
4930
5021
  entrypoints,
4931
5022
  pkgIsModule,
5023
+ pkgName: name,
4932
5024
  config: loadConfig(dir),
4933
5025
  dir,
5026
+ defaultOutdir: outdir,
4934
5027
  noFilter: true,
4935
5028
  isPublish: true
4936
5029
  });
@@ -4938,7 +5031,7 @@ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>",
4938
5031
  ...resolvedEntrypoints,
4939
5032
  ...exports
4940
5033
  };
4941
- return [dir, newManifest];
5034
+ return [dir, newManifest, resolvedOutdir];
4942
5035
  });
4943
5036
  const passArgs = Object.entries(options).reduce((acc, [key, value2]) => {
4944
5037
  if (value2) {
@@ -4946,7 +5039,7 @@ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>",
4946
5039
  }
4947
5040
  return acc;
4948
5041
  }, []);
4949
- for (const [dir, manifest] of manifests) {
5042
+ for (const [dir, manifest, resolvedOutdir] of manifests) {
4950
5043
  const oldJSONString = fs.readFileSync(path.join(dir, "package.json"), "utf-8");
4951
5044
  const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
4952
5045
  const newVersion = bumper ? bump(oldJSON.version, bumper) : oldJSON.version;
@@ -5021,15 +5114,37 @@ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>",
5021
5114
  }
5022
5115
  }
5023
5116
  }
5117
+ newJSONString = applyEdits(
5118
+ newJSONString,
5119
+ modify(
5120
+ newJSONString,
5121
+ ["publishConfig", "typesVersions"],
5122
+ {
5123
+ "<5.0": {
5124
+ "*": [
5125
+ "*",
5126
+ `${resolvedOutdir}/*`,
5127
+ `${resolvedOutdir}/*/index.d.ts`,
5128
+ `${resolvedOutdir}/*/index.d.mts`,
5129
+ `${resolvedOutdir}/*/index.d.cts`
5130
+ ]
5131
+ }
5132
+ },
5133
+ { formattingOptions }
5134
+ )
5135
+ );
5024
5136
  try {
5025
5137
  fs.renameSync(path.join(dir, "package.json"), path.join(dir, "package.json.bak"));
5026
5138
  fs.writeFileSync(path.join(dir, "package.json"), newJSONString);
5027
- console.log(newJSONString);
5139
+ !silent && console.log(newJSONString);
5028
5140
  if (preview) {
5029
- console.warn("preview mode");
5030
5141
  continue;
5031
5142
  }
5032
- childProcess.execSync(["pnpm", "publish", "--access", "public", "--no-git-checks", ...passArgs].join(" "), {
5143
+ const args = ["pnpm", "publish", "--access", "public", "--no-git-checks", ...passArgs];
5144
+ if (bumper && TAGS.includes(bumper)) {
5145
+ args.push("--tag", bumper);
5146
+ }
5147
+ childProcess.execSync(args.join(" "), {
5033
5148
  cwd: dir,
5034
5149
  stdio: "inherit"
5035
5150
  });