jiek 1.1.8 → 1.1.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -4150,17 +4150,43 @@ const recusiveListFiles = (dir) => fs__default.default.readdirSync(dir).reduce((
4150
4150
  }, []);
4151
4151
 
4152
4152
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4153
+ const {
4154
+ JIEK_OUT_DIR
4155
+ } = process.env;
4156
+ const OUTDIR = JIEK_OUT_DIR ?? "dist";
4157
+ function getOutDirs({
4158
+ cwd = process.cwd(),
4159
+ defaultOutdir = OUTDIR,
4160
+ config,
4161
+ pkgName
4162
+ }) {
4163
+ const { build = {} } = config ?? {};
4164
+ const outdir = build?.output?.dir;
4165
+ function resolveOutdir(type) {
4166
+ const dir = (typeof outdir === "object" ? outdir[type] ?? outdir[{
4167
+ js: "dts",
4168
+ dts: "js"
4169
+ }[type]] : outdir) ?? defaultOutdir;
4170
+ return (path.isAbsolute(dir) ? dir : `./${path.relative(cwd, path.resolve(cwd, dir))}`).replace("{{PKG_NAME}}", pkgName);
4171
+ }
4172
+ return {
4173
+ js: resolveOutdir("js"),
4174
+ dts: resolveOutdir("dts")
4175
+ };
4176
+ }
4153
4177
  function getExports({
4154
4178
  entrypoints: entrypoints$1,
4179
+ pkgName,
4155
4180
  pkgIsModule,
4156
4181
  entries,
4157
4182
  config,
4158
4183
  dir,
4184
+ defaultOutdir = OUTDIR,
4185
+ // FIXME dts support
4186
+ outdir = getOutDirs({ pkgName, defaultOutdir, config, cwd: dir }).js,
4159
4187
  noFilter,
4160
4188
  isPublish
4161
4189
  }) {
4162
- const dirResolve = (...paths) => path.resolve(dir ?? process.cwd(), ...paths);
4163
- const dirRelative = (path$1) => path.relative(dir ?? process.cwd(), path$1);
4164
4190
  const {
4165
4191
  build = {},
4166
4192
  publish: {
@@ -4171,9 +4197,6 @@ function getExports({
4171
4197
  const {
4172
4198
  crossModuleConvertor = true
4173
4199
  } = build;
4174
- const jsOutdir = `./${dirRelative(dirResolve(
4175
- (typeof build?.output?.dir === "object" ? build.output.dir.js : build?.output?.dir) ?? "dist"
4176
- ))}`;
4177
4200
  const [, resolvedEntrypoints] = entrypoints.resolveEntrypoints(entrypoints$1);
4178
4201
  if (entries) {
4179
4202
  Object.entries(resolvedEntrypoints).forEach(([key]) => {
@@ -4205,13 +4228,14 @@ function getExports({
4205
4228
  return [
4206
4229
  filteredResolvedEntrypoints,
4207
4230
  entrypoints.entrypoints2Exports(filteredResolvedEntrypoints, {
4208
- outdir: jsOutdir,
4231
+ outdir,
4209
4232
  withSuffix: isPublish ? withSuffix : void 0,
4210
4233
  withSource: isPublish ? withSource : void 0,
4211
4234
  withConditional: {
4212
4235
  ...crossModuleWithConditional
4213
4236
  }
4214
- })
4237
+ }),
4238
+ outdir
4215
4239
  ];
4216
4240
  }
4217
4241
 
@@ -4478,9 +4502,13 @@ function externalResolver(jsonOrPath = process.cwd()) {
4478
4502
 
4479
4503
  const {
4480
4504
  JIEK_ROOT,
4505
+ JIEK_NAME,
4481
4506
  JIEK_ENTRIES,
4482
4507
  JIEK_WITHOUT_JS,
4483
- JIEK_WITHOUT_DTS
4508
+ JIEK_WITHOUT_DTS,
4509
+ JIEK_WITHOUT_MINIFY,
4510
+ JIEK_NO_CLEAN,
4511
+ JIEK_ONLY_MINIFY
4484
4512
  } = process.env;
4485
4513
  const WORKSPACE_ROOT = JIEK_ROOT ?? getWorkspaceDir.getWorkspaceDir();
4486
4514
  const COMMON_OPTIONS = {};
@@ -4489,16 +4517,22 @@ const COMMON_PLUGINS = [
4489
4517
  ];
4490
4518
  const WITHOUT_JS = JIEK_WITHOUT_JS === "true";
4491
4519
  const WITHOUT_DTS = JIEK_WITHOUT_DTS === "true";
4520
+ const WITHOUT_MINIFY = JIEK_WITHOUT_MINIFY === "true";
4521
+ const ONLY_MINIFY = JIEK_ONLY_MINIFY === "true";
4522
+ const CLEAN = JIEK_NO_CLEAN !== "true";
4523
+ const MINIFY_DEFAULT_VALUE = WITHOUT_MINIFY ? false : ONLY_MINIFY ? "only-minify" : true;
4492
4524
  const config = loadConfig({
4493
4525
  root: WORKSPACE_ROOT
4494
4526
  }) ?? {};
4495
4527
  const { build = {} } = config;
4496
- const jsOutdir = `./${path.relative(
4497
- process.cwd(),
4498
- path.resolve(
4499
- (typeof build?.output?.dir === "object" ? build.output.dir.js : build?.output?.dir) ?? "dist"
4500
- )
4501
- )}`;
4528
+ const { js: jsOutdir, dts: dtsOutdir } = getOutDirs({
4529
+ config,
4530
+ pkgName: JIEK_NAME
4531
+ });
4532
+ if (CLEAN) {
4533
+ fs__default.default.existsSync(jsOutdir) && fs__default.default.rmdirSync(jsOutdir, { recursive: true });
4534
+ fs__default.default.existsSync(dtsOutdir) && fs__default.default.rmdirSync(dtsOutdir, { recursive: true });
4535
+ }
4502
4536
  const STYLE_REGEXP = /\.(css|s[ac]ss|less|styl)$/;
4503
4537
  const resolveBuildPlugins = (context, plugins) => {
4504
4538
  if (plugins === false || plugins === void 0 || plugins === null) {
@@ -4536,11 +4570,11 @@ const reveal = (obj, keys) => keys.reduce((acc, key) => {
4536
4570
  throw new Error(`key ${key} not found in exports`);
4537
4571
  return acc[key];
4538
4572
  }, obj);
4539
- const withMinify = (output, minify = build?.output?.minify) => minify === false ? [output] : minify === "only-minify" ? [{
4573
+ const withMinify = (output, minify = build?.output?.minify ?? MINIFY_DEFAULT_VALUE) => minify === false ? [output] : minify === "only-minify" ? [{
4540
4574
  ...output,
4541
4575
  // TODO replace suffix when pubish to npm and the `build.output.minify` is 'only-minify'
4542
4576
  // TODO resolve dts output file name
4543
- entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo).replace(/(\.[cm]?js)$/, ".min$1") : (() => {
4577
+ entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo) : (() => {
4544
4578
  throw new Error("entryFileNames must be a function");
4545
4579
  })(),
4546
4580
  plugins: [
@@ -4602,7 +4636,6 @@ const generateConfigs = (context, options = {}) => {
4602
4636
  type: "progress",
4603
4637
  data: { name, path: path$1, exportConditions, input }
4604
4638
  };
4605
- const outdir = options?.output?.dir;
4606
4639
  const { js: jsPlugins, dts: dtsPlugins } = resolveBuildPlugins(context, build.plugins);
4607
4640
  if (input.includes("**")) {
4608
4641
  throw new Error(
@@ -4664,7 +4697,7 @@ const generateConfigs = (context, options = {}) => {
4664
4697
  external,
4665
4698
  output: [
4666
4699
  {
4667
- dir: path.resolve((typeof outdir === "object" ? outdir.dts : outdir) ?? "dist"),
4700
+ dir: dtsOutdir,
4668
4701
  sourcemap: typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.dts : options?.output?.sourcemap,
4669
4702
  entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, tsOutputSuffix) : output.replace(`${jsOutdir}/`, "").replace(/(\.[cm]?)js$/, tsOutputSuffix),
4670
4703
  strict: typeof options?.output?.strict === "object" ? options.output.strict.dts : options?.output?.strict
@@ -4718,6 +4751,8 @@ function template(packageJSON) {
4718
4751
  entrypoints: entrypoints$1,
4719
4752
  pkgIsModule,
4720
4753
  entries,
4754
+ pkgName: JIEK_NAME,
4755
+ outdir: jsOutdir,
4721
4756
  config
4722
4757
  });
4723
4758
  const leafMap = /* @__PURE__ */ new Map();
@@ -1,5 +1,5 @@
1
1
  import fs from 'node:fs';
2
- import path, { resolve, relative, dirname, extname } from 'node:path';
2
+ import path, { resolve, isAbsolute, relative, dirname, extname } from 'node:path';
3
3
  import { resolveEntrypoints, filterLeafs, DEFAULT_SKIP_VALUES, entrypoints2Exports, getAllLeafs } from '@jiek/pkger/entrypoints';
4
4
  import { dts } from '@jiek/rollup-plugin-dts';
5
5
  import { isWorkspaceDir, getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
@@ -4135,17 +4135,43 @@ const recusiveListFiles = (dir) => fs.readdirSync(dir).reduce((acc, file) => {
4135
4135
  }, []);
4136
4136
 
4137
4137
  const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4138
+ const {
4139
+ JIEK_OUT_DIR
4140
+ } = process.env;
4141
+ const OUTDIR = JIEK_OUT_DIR ?? "dist";
4142
+ function getOutDirs({
4143
+ cwd = process.cwd(),
4144
+ defaultOutdir = OUTDIR,
4145
+ config,
4146
+ pkgName
4147
+ }) {
4148
+ const { build = {} } = config ?? {};
4149
+ const outdir = build?.output?.dir;
4150
+ function resolveOutdir(type) {
4151
+ const dir = (typeof outdir === "object" ? outdir[type] ?? outdir[{
4152
+ js: "dts",
4153
+ dts: "js"
4154
+ }[type]] : outdir) ?? defaultOutdir;
4155
+ return (isAbsolute(dir) ? dir : `./${relative(cwd, resolve(cwd, dir))}`).replace("{{PKG_NAME}}", pkgName);
4156
+ }
4157
+ return {
4158
+ js: resolveOutdir("js"),
4159
+ dts: resolveOutdir("dts")
4160
+ };
4161
+ }
4138
4162
  function getExports({
4139
4163
  entrypoints,
4164
+ pkgName,
4140
4165
  pkgIsModule,
4141
4166
  entries,
4142
4167
  config,
4143
4168
  dir,
4169
+ defaultOutdir = OUTDIR,
4170
+ // FIXME dts support
4171
+ outdir = getOutDirs({ pkgName, defaultOutdir, config, cwd: dir }).js,
4144
4172
  noFilter,
4145
4173
  isPublish
4146
4174
  }) {
4147
- const dirResolve = (...paths) => resolve(dir ?? process.cwd(), ...paths);
4148
- const dirRelative = (path) => relative(dir ?? process.cwd(), path);
4149
4175
  const {
4150
4176
  build = {},
4151
4177
  publish: {
@@ -4156,9 +4182,6 @@ function getExports({
4156
4182
  const {
4157
4183
  crossModuleConvertor = true
4158
4184
  } = build;
4159
- const jsOutdir = `./${dirRelative(dirResolve(
4160
- (typeof build?.output?.dir === "object" ? build.output.dir.js : build?.output?.dir) ?? "dist"
4161
- ))}`;
4162
4185
  const [, resolvedEntrypoints] = resolveEntrypoints(entrypoints);
4163
4186
  if (entries) {
4164
4187
  Object.entries(resolvedEntrypoints).forEach(([key]) => {
@@ -4190,13 +4213,14 @@ function getExports({
4190
4213
  return [
4191
4214
  filteredResolvedEntrypoints,
4192
4215
  entrypoints2Exports(filteredResolvedEntrypoints, {
4193
- outdir: jsOutdir,
4216
+ outdir,
4194
4217
  withSuffix: isPublish ? withSuffix : void 0,
4195
4218
  withSource: isPublish ? withSource : void 0,
4196
4219
  withConditional: {
4197
4220
  ...crossModuleWithConditional
4198
4221
  }
4199
- })
4222
+ }),
4223
+ outdir
4200
4224
  ];
4201
4225
  }
4202
4226
 
@@ -4463,9 +4487,13 @@ function externalResolver(jsonOrPath = process.cwd()) {
4463
4487
 
4464
4488
  const {
4465
4489
  JIEK_ROOT,
4490
+ JIEK_NAME,
4466
4491
  JIEK_ENTRIES,
4467
4492
  JIEK_WITHOUT_JS,
4468
- JIEK_WITHOUT_DTS
4493
+ JIEK_WITHOUT_DTS,
4494
+ JIEK_WITHOUT_MINIFY,
4495
+ JIEK_NO_CLEAN,
4496
+ JIEK_ONLY_MINIFY
4469
4497
  } = process.env;
4470
4498
  const WORKSPACE_ROOT = JIEK_ROOT ?? getWorkspaceDir();
4471
4499
  const COMMON_OPTIONS = {};
@@ -4474,16 +4502,22 @@ const COMMON_PLUGINS = [
4474
4502
  ];
4475
4503
  const WITHOUT_JS = JIEK_WITHOUT_JS === "true";
4476
4504
  const WITHOUT_DTS = JIEK_WITHOUT_DTS === "true";
4505
+ const WITHOUT_MINIFY = JIEK_WITHOUT_MINIFY === "true";
4506
+ const ONLY_MINIFY = JIEK_ONLY_MINIFY === "true";
4507
+ const CLEAN = JIEK_NO_CLEAN !== "true";
4508
+ const MINIFY_DEFAULT_VALUE = WITHOUT_MINIFY ? false : ONLY_MINIFY ? "only-minify" : true;
4477
4509
  const config = loadConfig({
4478
4510
  root: WORKSPACE_ROOT
4479
4511
  }) ?? {};
4480
4512
  const { build = {} } = config;
4481
- const jsOutdir = `./${relative(
4482
- process.cwd(),
4483
- resolve(
4484
- (typeof build?.output?.dir === "object" ? build.output.dir.js : build?.output?.dir) ?? "dist"
4485
- )
4486
- )}`;
4513
+ const { js: jsOutdir, dts: dtsOutdir } = getOutDirs({
4514
+ config,
4515
+ pkgName: JIEK_NAME
4516
+ });
4517
+ if (CLEAN) {
4518
+ fs.existsSync(jsOutdir) && fs.rmdirSync(jsOutdir, { recursive: true });
4519
+ fs.existsSync(dtsOutdir) && fs.rmdirSync(dtsOutdir, { recursive: true });
4520
+ }
4487
4521
  const STYLE_REGEXP = /\.(css|s[ac]ss|less|styl)$/;
4488
4522
  const resolveBuildPlugins = (context, plugins) => {
4489
4523
  if (plugins === false || plugins === void 0 || plugins === null) {
@@ -4521,11 +4555,11 @@ const reveal = (obj, keys) => keys.reduce((acc, key) => {
4521
4555
  throw new Error(`key ${key} not found in exports`);
4522
4556
  return acc[key];
4523
4557
  }, obj);
4524
- const withMinify = (output, minify = build?.output?.minify) => minify === false ? [output] : minify === "only-minify" ? [{
4558
+ const withMinify = (output, minify = build?.output?.minify ?? MINIFY_DEFAULT_VALUE) => minify === false ? [output] : minify === "only-minify" ? [{
4525
4559
  ...output,
4526
4560
  // TODO replace suffix when pubish to npm and the `build.output.minify` is 'only-minify'
4527
4561
  // TODO resolve dts output file name
4528
- entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo).replace(/(\.[cm]?js)$/, ".min$1") : (() => {
4562
+ entryFileNames: (chunkInfo) => typeof output.entryFileNames === "function" ? output.entryFileNames(chunkInfo) : (() => {
4529
4563
  throw new Error("entryFileNames must be a function");
4530
4564
  })(),
4531
4565
  plugins: [
@@ -4587,7 +4621,6 @@ const generateConfigs = (context, options = {}) => {
4587
4621
  type: "progress",
4588
4622
  data: { name, path, exportConditions, input }
4589
4623
  };
4590
- const outdir = options?.output?.dir;
4591
4624
  const { js: jsPlugins, dts: dtsPlugins } = resolveBuildPlugins(context, build.plugins);
4592
4625
  if (input.includes("**")) {
4593
4626
  throw new Error(
@@ -4649,7 +4682,7 @@ const generateConfigs = (context, options = {}) => {
4649
4682
  external,
4650
4683
  output: [
4651
4684
  {
4652
- dir: resolve((typeof outdir === "object" ? outdir.dts : outdir) ?? "dist"),
4685
+ dir: dtsOutdir,
4653
4686
  sourcemap: typeof options?.output?.sourcemap === "object" ? options.output.sourcemap.dts : options?.output?.sourcemap,
4654
4687
  entryFileNames: (chunkInfo) => Array.isArray(inputObj) ? chunkInfo.facadeModuleId.replace(`${process.cwd()}/`, "").replace(globCommonDir, pathCommonDir).replace(/(\.[cm]?)ts$/, tsOutputSuffix) : output.replace(`${jsOutdir}/`, "").replace(/(\.[cm]?)js$/, tsOutputSuffix),
4655
4688
  strict: typeof options?.output?.strict === "object" ? options.output.strict.dts : options?.output?.strict
@@ -4703,6 +4736,8 @@ function template(packageJSON) {
4703
4736
  entrypoints,
4704
4737
  pkgIsModule,
4705
4738
  entries,
4739
+ pkgName: JIEK_NAME,
4740
+ outdir: jsOutdir,
4706
4741
  config
4707
4742
  });
4708
4743
  const leafMap = /* @__PURE__ */ new Map();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "jiek",
3
3
  "type": "module",
4
- "version": "1.1.8",
4
+ "version": "1.1.9",
5
5
  "description": "YiJie's personal kits.",
6
6
  "bin": {
7
7
  "jiek": "bin/jiek.js",
@@ -14,15 +14,6 @@
14
14
  "LICENSE",
15
15
  "README.md"
16
16
  ],
17
- "typesVersions": {
18
- "<5.0": {
19
- "*": [
20
- "*",
21
- "./dist/*",
22
- "./dist/*/index.d.ts"
23
- ]
24
- }
25
- },
26
17
  "exports": {
27
18
  "./package.json": "./package.json",
28
19
  ".": {
@@ -62,7 +53,7 @@
62
53
  "rollup-plugin-esbuild": "^6.1.0",
63
54
  "typescript": "^5.0.0",
64
55
  "@jiek/pkger": "^0.2.0",
65
- "@jiek/utils": "^0.2.2"
56
+ "@jiek/utils": "^0.2.3"
66
57
  },
67
58
  "optionalDependencies": {
68
59
  "@pnpm/filter-workspace-packages": "^7.2.13",
@@ -85,8 +76,19 @@
85
76
  "rollup-plugin-postcss": "^4.0.2"
86
77
  },
87
78
  "scripts": {
88
- "prepublish": "jk build"
79
+ "prepublish": "jk build --noMin"
89
80
  },
90
81
  "main": "./dist/index.cjs",
91
- "module": "./dist/index.js"
82
+ "module": "./dist/index.js",
83
+ "typesVersions": {
84
+ "<5.0": {
85
+ "*": [
86
+ "*",
87
+ "./dist/*",
88
+ "./dist/*/index.d.ts",
89
+ "./dist/*/index.d.mts",
90
+ "./dist/*/index.d.cts"
91
+ ]
92
+ }
93
+ }
92
94
  }
@@ -8,10 +8,11 @@ import { execaCommand } from 'execa'
8
8
 
9
9
  import { actionDone, actionRestore } from '../inner'
10
10
  import type { RollupProgressEvent, TemplateOptions } from '../rollup/base'
11
- import { getSelectedProjectsGraph, ProjectsGraph } from '../utils/filterSupport'
12
- import { filterPackagesGraph } from '../utils/filterSupport'
11
+ import type { ProjectsGraph } from '../utils/filterSupport'
12
+ import { filterPackagesGraph, getSelectedProjectsGraph } from '../utils/filterSupport'
13
13
  import { loadConfig } from '../utils/loadConfig'
14
14
  import { tsRegisterName } from '../utils/tsRegister'
15
+ import { outdirDescription } from './descriptions'
15
16
 
16
17
  declare module 'jiek' {
17
18
  export interface Config {
@@ -36,31 +37,82 @@ const description = `
36
37
  Build the package according to the 'exports' field in the package.json.
37
38
  `.trim()
38
39
 
40
+ interface BuildOptions extends Record<string, unknown> {
41
+ /**
42
+ * The output directory of the build, which relative to the target subpackage root directory.
43
+ * Support with variables: 'PKG_NAME',
44
+ * .e.g. 'dist/{{PKG_NAME}}'.
45
+ *
46
+ * @default 'dist'
47
+ */
48
+ outdir: string
49
+ silent: boolean
50
+ entries: string
51
+ verbose: boolean
52
+ noJs: boolean
53
+ noDts: boolean
54
+ noMin: boolean
55
+ /**
56
+ * Do not clean the output directory before building.
57
+ */
58
+ noClean: boolean
59
+ onlyMin: boolean
60
+ }
61
+
62
+ function parseBoolean(v?: unknown) {
63
+ if (v === undefined) return true
64
+ return Boolean(v)
65
+ }
66
+
39
67
  program
40
68
  .command('build')
41
69
  .description(description)
42
- .option('-s, --silent', "Don't display logs.")
70
+ .option('-o, --outdir <OUTDIR>', outdirDescription, String, 'dist')
43
71
  .option('-e, --entries <ENTRIES>', "Specify the entries of the package.json's 'exports' field.(support glob)")
44
- .option('--without-js', 'Do not output js files.')
45
- .option('--without-dts', 'Do not output dts files.')
46
- .option('-v, --verbose', 'Display debug logs.')
72
+ .option('-nj, --noJs', 'Do not output js files.', parseBoolean)
73
+ .option('-nd, --noDts', 'Do not output dts files.', parseBoolean)
74
+ .option('-nm, --noMin', 'Do not output minify files.', parseBoolean)
75
+ .option('-nc, --noClean', 'Do not clean the output directory before building.', parseBoolean)
76
+ .option(
77
+ '-om, --onlyMin',
78
+ 'Only output minify files, but dts files will still be output, it only replaces the js files.',
79
+ parseBoolean
80
+ )
81
+ .option('-s, --silent', "Don't display logs.", parseBoolean)
82
+ .option('-v, --verbose', 'Display debug logs.', parseBoolean)
47
83
  .action(async ({
84
+ outdir,
48
85
  silent,
49
86
  entries,
50
87
  verbose,
51
- withoutJs,
52
- withoutDts
53
- }: {
54
- silent: boolean
55
- entries: string
56
- verbose: boolean
57
- withoutJs: boolean
58
- withoutDts: boolean
59
- }) => {
88
+ noJs: withoutJs,
89
+ noDts: withoutDts,
90
+ noMin: withoutMin,
91
+ noClean,
92
+ onlyMin: onlyMin
93
+ }: BuildOptions) => {
60
94
  actionRestore()
61
95
  const { build } = loadConfig()
62
96
  silent = silent ?? build?.silent ?? false
63
97
 
98
+ if (withoutMin && onlyMin) {
99
+ throw new Error('Cannot use both --without-minify and --only-minify')
100
+ }
101
+ if (onlyMin && withoutJs) {
102
+ throw new Error('Cannot use --without-js and --only-minify at the same time')
103
+ }
104
+
105
+ const env = {
106
+ ...process.env,
107
+ JIEK_OUT_DIR: outdir,
108
+ JIEK_CLEAN: String(!noClean),
109
+ JIEK_ENTRIES: entries,
110
+ JIEK_WITHOUT_JS: String(withoutJs),
111
+ JIEK_WITHOUT_DTS: String(withoutDts),
112
+ JIEK_WITHOUT_MINIFY: String(withoutMin),
113
+ JIEK_ONLY_MINIFY: String(onlyMin)
114
+ }
115
+
64
116
  const multiBars = new MultiBar({
65
117
  clearOnComplete: false,
66
118
  hideCursor: true,
@@ -88,8 +140,12 @@ program
88
140
  let i = 0
89
141
  await Promise.all(
90
142
  Object.entries(value).map(async ([dir, manifest]) => {
143
+ if (!manifest.name) {
144
+ throw new Error('package.json must have a name field')
145
+ }
146
+
91
147
  // TODO support auto build child packages in workspaces
92
- const escapeManifestName = manifest.name?.replace(/^@/g, '').replace(/\//g, '+')
148
+ const escapeManifestName = manifest.name.replace(/^@/g, '').replace(/\//g, '+')
93
149
  const configFile = jiekTempDir(
94
150
  `${escapeManifestName ?? `anonymous-${i++}`}.rollup.config.js`
95
151
  )
@@ -103,11 +159,9 @@ program
103
159
  ipc: true,
104
160
  cwd: dir,
105
161
  env: {
106
- ...process.env,
107
- JIEK_ROOT: wd,
108
- JIEK_ENTRIES: entries,
109
- JIEK_WITHOUT_JS: String(withoutJs),
110
- JIEK_WITHOUT_DTS: String(withoutDts)
162
+ ...env,
163
+ JIEK_NAME: manifest.name,
164
+ JIEK_ROOT: wd
111
165
  }
112
166
  })
113
167
  const bars: Record<string, ReturnType<typeof multiBars.create>> = {}
@@ -0,0 +1,5 @@
1
+ export const outdirDescription = `
2
+ The output directory of the build, which relative to the target subpackage root directory.
3
+ Support with variables: 'PKG_NAME',
4
+ .e.g. 'dist/{{PKG_NAME}}'.
5
+ `.trim()
@@ -11,6 +11,7 @@ import { actionDone, actionRestore } from '../inner'
11
11
  import { getSelectedProjectsGraph } from '../utils/filterSupport'
12
12
  import { getExports } from '../utils/getExports'
13
13
  import { loadConfig } from '../utils/loadConfig'
14
+ import { outdirDescription } from './descriptions'
14
15
 
15
16
  declare module 'jiek' {
16
17
  export interface Config {
@@ -32,9 +33,11 @@ program
32
33
  .aliases(['pub', 'p'])
33
34
  .option('-b, --bumper <bumper>', 'bump version', 'patch')
34
35
  .option('-no-b, --no-bumper', 'no bump version')
36
+ .option('-o, --outdir <OUTDIR>', outdirDescription, String, 'dist')
35
37
  .option('-s, --silent', 'no output')
36
38
  .option('-p, --preview', 'preview publish')
37
- .action(async ({ preview, silent, bumper, ...options }: {
39
+ .action(async ({ outdir, preview, silent, bumper, ...options }: {
40
+ outdir?: string
38
41
  preview?: boolean
39
42
  silent?: boolean
40
43
  bumper: false | BumperType
@@ -48,14 +51,20 @@ program
48
51
  }
49
52
  const manifests = selectedProjectsGraphEntries
50
53
  .map(([dir, manifest]) => {
51
- const { type, exports: entrypoints = {} } = manifest
54
+ const { name, type, exports: entrypoints = {} } = manifest
55
+ if (!name) {
56
+ throw new Error(`package.json in ${dir} must have a name field`)
57
+ }
58
+
52
59
  const pkgIsModule = type === 'module'
53
60
  const newManifest = { ...manifest }
54
- const [resolvedEntrypoints, exports] = getExports({
61
+ const [resolvedEntrypoints, exports, resolvedOutdir] = getExports({
55
62
  entrypoints,
56
63
  pkgIsModule,
64
+ pkgName: name,
57
65
  config: loadConfig(dir),
58
66
  dir,
67
+ defaultOutdir: outdir,
59
68
  noFilter: true,
60
69
  isPublish: true
61
70
  })
@@ -63,7 +72,7 @@ program
63
72
  ...resolvedEntrypoints,
64
73
  ...exports
65
74
  }
66
- return [dir, newManifest] as const
75
+ return [dir, newManifest, resolvedOutdir] as const
67
76
  })
68
77
  const passArgs = Object
69
78
  .entries(options)
@@ -73,7 +82,7 @@ program
73
82
  }
74
83
  return acc
75
84
  }, [] as string[])
76
- for (const [dir, manifest] of manifests) {
85
+ for (const [dir, manifest, resolvedOutdir] of manifests) {
77
86
  const oldJSONString = fs.readFileSync(path.join(dir, 'package.json'), 'utf-8')
78
87
  const oldJSON = JSON.parse(oldJSONString) ?? '0.0.0'
79
88
  const newVersion = bumper ? bump(oldJSON.version, bumper) : oldJSON.version
@@ -150,12 +159,30 @@ program
150
159
  }
151
160
  }
152
161
  }
162
+ newJSONString = applyEdits(
163
+ newJSONString,
164
+ modify(
165
+ newJSONString,
166
+ ['publishConfig', 'typesVersions'],
167
+ {
168
+ '<5.0': {
169
+ '*': [
170
+ '*',
171
+ `${resolvedOutdir}/*`,
172
+ `${resolvedOutdir}/*/index.d.ts`,
173
+ `${resolvedOutdir}/*/index.d.mts`,
174
+ `${resolvedOutdir}/*/index.d.cts`
175
+ ]
176
+ }
177
+ },
178
+ { formattingOptions }
179
+ )
180
+ )
153
181
  try {
154
182
  fs.renameSync(path.join(dir, 'package.json'), path.join(dir, 'package.json.bak'))
155
183
  fs.writeFileSync(path.join(dir, 'package.json'), newJSONString)
156
184
  !silent && console.log(newJSONString)
157
185
  if (preview) {
158
- !silent && console.warn('preview mode')
159
186
  continue
160
187
  }
161
188
  const args = ['pnpm', 'publish', '--access', 'public', '--no-git-checks', ...passArgs]