jiek 1.1.8 → 1.1.9

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.8";
152
+ var version = "1.1.9";
153
153
  var description$1 = "YiJie's personal kits.";
154
154
  var bin = {
155
155
  jiek: "bin/jiek.js",
@@ -162,17 +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
- }
173
- };
174
165
  var scripts = {
175
- prepublish: "jk build"
166
+ prepublish: "jk build --noMin"
176
167
  };
177
168
  var exports$1 = {
178
169
  "./package.json": "./package.json",
@@ -243,7 +234,18 @@ var publishConfig = {
243
234
  }
244
235
  },
245
236
  main: "./dist/index.cjs",
246
- module: "./dist/index.js"
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
+ }
247
249
  };
248
250
  var pkg = {
249
251
  name: name,
@@ -252,7 +254,6 @@ var pkg = {
252
254
  description: description$1,
253
255
  bin: bin,
254
256
  files: files,
255
- typesVersions: typesVersions,
256
257
  scripts: scripts,
257
258
  exports: exports$1,
258
259
  imports: imports,
@@ -378,6 +379,12 @@ function loadConfig(dirOrOptions) {
378
379
  return module.default ?? module;
379
380
  }
380
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
+
381
388
  const FILE_TEMPLATE = (manifest) => `
382
389
  module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
383
390
  `.trimStart();
@@ -385,16 +392,45 @@ const require$1 = node_module.createRequire((typeof document === 'undefined' ? r
385
392
  const description = `
386
393
  Build the package according to the 'exports' field in the package.json.
387
394
  `.trim();
388
- 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,
389
406
  silent,
390
407
  entries,
391
408
  verbose,
392
- withoutJs,
393
- withoutDts
409
+ noJs: withoutJs,
410
+ noDts: withoutDts,
411
+ noMin: withoutMin,
412
+ noClean,
413
+ onlyMin
394
414
  }) => {
395
415
  actionRestore();
396
416
  const { build } = loadConfig();
397
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
+ };
398
434
  const multiBars = new cliProgress.MultiBar({
399
435
  clearOnComplete: false,
400
436
  hideCursor: true,
@@ -419,7 +455,10 @@ commander.program.command("build").description(description).option("-s, --silent
419
455
  let i = 0;
420
456
  await Promise.all(
421
457
  Object.entries(value).map(async ([dir, manifest]) => {
422
- 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, "+");
423
462
  const configFile = jiekTempDir(
424
463
  `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
425
464
  );
@@ -433,11 +472,9 @@ commander.program.command("build").description(description).option("-s, --silent
433
472
  ipc: true,
434
473
  cwd: dir,
435
474
  env: {
436
- ...process.env,
437
- JIEK_ROOT: wd,
438
- JIEK_ENTRIES: entries,
439
- JIEK_WITHOUT_JS: String(withoutJs),
440
- JIEK_WITHOUT_DTS: String(withoutDts)
475
+ ...env,
476
+ JIEK_NAME: manifest.name,
477
+ JIEK_ROOT: wd
441
478
  }
442
479
  });
443
480
  const bars = {};
@@ -4908,17 +4945,43 @@ commander.program.command("init [name]").option("-t, --template <template>", "th
4908
4945
  });
4909
4946
 
4910
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
+ }
4911
4972
  function getExports({
4912
4973
  entrypoints: entrypoints$1,
4974
+ pkgName,
4913
4975
  pkgIsModule,
4914
4976
  entries,
4915
4977
  config,
4916
4978
  dir,
4979
+ defaultOutdir = OUTDIR,
4980
+ // FIXME dts support
4981
+ outdir = getOutDirs({ pkgName, defaultOutdir, config, cwd: dir }).js,
4917
4982
  noFilter,
4918
4983
  isPublish
4919
4984
  }) {
4920
- const dirResolve = (...paths) => path.resolve(dir ?? process.cwd(), ...paths);
4921
- const dirRelative = (path$1) => path.relative(dir ?? process.cwd(), path$1);
4922
4985
  const {
4923
4986
  build = {},
4924
4987
  publish: {
@@ -4929,9 +4992,6 @@ function getExports({
4929
4992
  const {
4930
4993
  crossModuleConvertor = true
4931
4994
  } = build;
4932
- const jsOutdir = `./${dirRelative(dirResolve(
4933
- (typeof build?.output?.dir === "object" ? build.output.dir.js : build?.output?.dir) ?? "dist"
4934
- ))}`;
4935
4995
  const [, resolvedEntrypoints] = entrypoints.resolveEntrypoints(entrypoints$1);
4936
4996
  if (entries) {
4937
4997
  Object.entries(resolvedEntrypoints).forEach(([key]) => {
@@ -4963,17 +5023,18 @@ function getExports({
4963
5023
  return [
4964
5024
  filteredResolvedEntrypoints,
4965
5025
  entrypoints.entrypoints2Exports(filteredResolvedEntrypoints, {
4966
- outdir: jsOutdir,
5026
+ outdir,
4967
5027
  withSuffix: isPublish ? withSuffix : void 0,
4968
5028
  withSource: isPublish ? withSource : void 0,
4969
5029
  withConditional: {
4970
5030
  ...crossModuleWithConditional
4971
5031
  }
4972
- })
5032
+ }),
5033
+ outdir
4973
5034
  ];
4974
5035
  }
4975
5036
 
4976
- commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>", "bump version", "patch").option("-no-b, --no-bumper", "no bump version").option("-s, --silent", "no output").option("-p, --preview", "preview publish").action(async ({ preview, silent, 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 }) => {
4977
5038
  actionRestore();
4978
5039
  const { value = {} } = await getSelectedProjectsGraph() ?? {};
4979
5040
  const selectedProjectsGraphEntries = Object.entries(value);
@@ -4981,14 +5042,19 @@ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper
4981
5042
  throw new Error("no packages selected");
4982
5043
  }
4983
5044
  const manifests = selectedProjectsGraphEntries.map(([dir, manifest]) => {
4984
- 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
+ }
4985
5049
  const pkgIsModule = type === "module";
4986
5050
  const newManifest = { ...manifest };
4987
- const [resolvedEntrypoints, exports] = getExports({
5051
+ const [resolvedEntrypoints, exports, resolvedOutdir] = getExports({
4988
5052
  entrypoints,
4989
5053
  pkgIsModule,
5054
+ pkgName: name,
4990
5055
  config: loadConfig(dir),
4991
5056
  dir,
5057
+ defaultOutdir: outdir,
4992
5058
  noFilter: true,
4993
5059
  isPublish: true
4994
5060
  });
@@ -4996,7 +5062,7 @@ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper
4996
5062
  ...resolvedEntrypoints,
4997
5063
  ...exports
4998
5064
  };
4999
- return [dir, newManifest];
5065
+ return [dir, newManifest, resolvedOutdir];
5000
5066
  });
5001
5067
  const passArgs = Object.entries(options).reduce((acc, [key, value2]) => {
5002
5068
  if (value2) {
@@ -5004,7 +5070,7 @@ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper
5004
5070
  }
5005
5071
  return acc;
5006
5072
  }, []);
5007
- for (const [dir, manifest] of manifests) {
5073
+ for (const [dir, manifest, resolvedOutdir] of manifests) {
5008
5074
  const oldJSONString = fs__default.default.readFileSync(path__default.default.join(dir, "package.json"), "utf-8");
5009
5075
  const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
5010
5076
  const newVersion = bumper$1 ? bumper.bump(oldJSON.version, bumper$1) : oldJSON.version;
@@ -5079,12 +5145,30 @@ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper
5079
5145
  }
5080
5146
  }
5081
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
+ );
5082
5167
  try {
5083
5168
  fs__default.default.renameSync(path__default.default.join(dir, "package.json"), path__default.default.join(dir, "package.json.bak"));
5084
5169
  fs__default.default.writeFileSync(path__default.default.join(dir, "package.json"), newJSONString);
5085
5170
  !silent && console.log(newJSONString);
5086
5171
  if (preview) {
5087
- !silent && console.warn("preview mode");
5088
5172
  continue;
5089
5173
  }
5090
5174
  const args = ["pnpm", "publish", "--access", "public", "--no-git-checks", ...passArgs];
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';
@@ -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.8";
121
+ var version = "1.1.9";
122
122
  var description$1 = "YiJie's personal kits.";
123
123
  var bin = {
124
124
  jiek: "bin/jiek.js",
@@ -131,17 +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
- }
142
- };
143
134
  var scripts = {
144
- prepublish: "jk build"
135
+ prepublish: "jk build --noMin"
145
136
  };
146
137
  var exports = {
147
138
  "./package.json": "./package.json",
@@ -212,7 +203,18 @@ var publishConfig = {
212
203
  }
213
204
  },
214
205
  main: "./dist/index.cjs",
215
- module: "./dist/index.js"
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
+ }
216
218
  };
217
219
  var pkg = {
218
220
  name: name,
@@ -221,7 +223,6 @@ var pkg = {
221
223
  description: description$1,
222
224
  bin: bin,
223
225
  files: files,
224
- typesVersions: typesVersions,
225
226
  scripts: scripts,
226
227
  exports: exports,
227
228
  imports: imports,
@@ -347,6 +348,12 @@ function loadConfig(dirOrOptions) {
347
348
  return module.default ?? module;
348
349
  }
349
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
+
350
357
  const FILE_TEMPLATE = (manifest) => `
351
358
  module.exports = require('jiek/rollup').template(${JSON.stringify(manifest, null, 2)})
352
359
  `.trimStart();
@@ -354,16 +361,45 @@ const require = createRequire(import.meta.url);
354
361
  const description = `
355
362
  Build the package according to the 'exports' field in the package.json.
356
363
  `.trim();
357
- 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,
358
375
  silent,
359
376
  entries,
360
377
  verbose,
361
- withoutJs,
362
- withoutDts
378
+ noJs: withoutJs,
379
+ noDts: withoutDts,
380
+ noMin: withoutMin,
381
+ noClean,
382
+ onlyMin
363
383
  }) => {
364
384
  actionRestore();
365
385
  const { build } = loadConfig();
366
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
+ };
367
403
  const multiBars = new MultiBar({
368
404
  clearOnComplete: false,
369
405
  hideCursor: true,
@@ -388,7 +424,10 @@ program.command("build").description(description).option("-s, --silent", "Don't
388
424
  let i = 0;
389
425
  await Promise.all(
390
426
  Object.entries(value).map(async ([dir, manifest]) => {
391
- 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, "+");
392
431
  const configFile = jiekTempDir(
393
432
  `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
394
433
  );
@@ -402,11 +441,9 @@ program.command("build").description(description).option("-s, --silent", "Don't
402
441
  ipc: true,
403
442
  cwd: dir,
404
443
  env: {
405
- ...process.env,
406
- JIEK_ROOT: wd,
407
- JIEK_ENTRIES: entries,
408
- JIEK_WITHOUT_JS: String(withoutJs),
409
- JIEK_WITHOUT_DTS: String(withoutDts)
444
+ ...env,
445
+ JIEK_NAME: manifest.name,
446
+ JIEK_ROOT: wd
410
447
  }
411
448
  });
412
449
  const bars = {};
@@ -4877,17 +4914,43 @@ program.command("init [name]").option("-t, --template <template>", "the package.
4877
4914
  });
4878
4915
 
4879
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
+ }
4880
4941
  function getExports({
4881
4942
  entrypoints,
4943
+ pkgName,
4882
4944
  pkgIsModule,
4883
4945
  entries,
4884
4946
  config,
4885
4947
  dir,
4948
+ defaultOutdir = OUTDIR,
4949
+ // FIXME dts support
4950
+ outdir = getOutDirs({ pkgName, defaultOutdir, config, cwd: dir }).js,
4886
4951
  noFilter,
4887
4952
  isPublish
4888
4953
  }) {
4889
- const dirResolve = (...paths) => resolve$1(dir ?? process.cwd(), ...paths);
4890
- const dirRelative = (path) => relative(dir ?? process.cwd(), path);
4891
4954
  const {
4892
4955
  build = {},
4893
4956
  publish: {
@@ -4898,9 +4961,6 @@ function getExports({
4898
4961
  const {
4899
4962
  crossModuleConvertor = true
4900
4963
  } = build;
4901
- const jsOutdir = `./${dirRelative(dirResolve(
4902
- (typeof build?.output?.dir === "object" ? build.output.dir.js : build?.output?.dir) ?? "dist"
4903
- ))}`;
4904
4964
  const [, resolvedEntrypoints] = resolveEntrypoints(entrypoints);
4905
4965
  if (entries) {
4906
4966
  Object.entries(resolvedEntrypoints).forEach(([key]) => {
@@ -4932,17 +4992,18 @@ function getExports({
4932
4992
  return [
4933
4993
  filteredResolvedEntrypoints,
4934
4994
  entrypoints2Exports(filteredResolvedEntrypoints, {
4935
- outdir: jsOutdir,
4995
+ outdir,
4936
4996
  withSuffix: isPublish ? withSuffix : void 0,
4937
4997
  withSource: isPublish ? withSource : void 0,
4938
4998
  withConditional: {
4939
4999
  ...crossModuleWithConditional
4940
5000
  }
4941
- })
5001
+ }),
5002
+ outdir
4942
5003
  ];
4943
5004
  }
4944
5005
 
4945
- program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>", "bump version", "patch").option("-no-b, --no-bumper", "no bump version").option("-s, --silent", "no output").option("-p, --preview", "preview publish").action(async ({ preview, silent, 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 }) => {
4946
5007
  actionRestore();
4947
5008
  const { value = {} } = await getSelectedProjectsGraph() ?? {};
4948
5009
  const selectedProjectsGraphEntries = Object.entries(value);
@@ -4950,14 +5011,19 @@ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>",
4950
5011
  throw new Error("no packages selected");
4951
5012
  }
4952
5013
  const manifests = selectedProjectsGraphEntries.map(([dir, manifest]) => {
4953
- 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
+ }
4954
5018
  const pkgIsModule = type === "module";
4955
5019
  const newManifest = { ...manifest };
4956
- const [resolvedEntrypoints, exports] = getExports({
5020
+ const [resolvedEntrypoints, exports, resolvedOutdir] = getExports({
4957
5021
  entrypoints,
4958
5022
  pkgIsModule,
5023
+ pkgName: name,
4959
5024
  config: loadConfig(dir),
4960
5025
  dir,
5026
+ defaultOutdir: outdir,
4961
5027
  noFilter: true,
4962
5028
  isPublish: true
4963
5029
  });
@@ -4965,7 +5031,7 @@ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>",
4965
5031
  ...resolvedEntrypoints,
4966
5032
  ...exports
4967
5033
  };
4968
- return [dir, newManifest];
5034
+ return [dir, newManifest, resolvedOutdir];
4969
5035
  });
4970
5036
  const passArgs = Object.entries(options).reduce((acc, [key, value2]) => {
4971
5037
  if (value2) {
@@ -4973,7 +5039,7 @@ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>",
4973
5039
  }
4974
5040
  return acc;
4975
5041
  }, []);
4976
- for (const [dir, manifest] of manifests) {
5042
+ for (const [dir, manifest, resolvedOutdir] of manifests) {
4977
5043
  const oldJSONString = fs.readFileSync(path.join(dir, "package.json"), "utf-8");
4978
5044
  const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
4979
5045
  const newVersion = bumper ? bump(oldJSON.version, bumper) : oldJSON.version;
@@ -5048,12 +5114,30 @@ program.command("publish").aliases(["pub", "p"]).option("-b, --bumper <bumper>",
5048
5114
  }
5049
5115
  }
5050
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
+ );
5051
5136
  try {
5052
5137
  fs.renameSync(path.join(dir, "package.json"), path.join(dir, "package.json.bak"));
5053
5138
  fs.writeFileSync(path.join(dir, "package.json"), newJSONString);
5054
5139
  !silent && console.log(newJSONString);
5055
5140
  if (preview) {
5056
- !silent && console.warn("preview mode");
5057
5141
  continue;
5058
5142
  }
5059
5143
  const args = ["pnpm", "publish", "--access", "public", "--no-git-checks", ...passArgs];