jiek 2.0.2 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -116,7 +116,7 @@ async function getSelectedProjectsGraph(filter = commander.program.getOptionValu
116
116
 
117
117
  var name = "jiek";
118
118
  var type = "module";
119
- var version = "2.0.2";
119
+ var version = "2.0.2-alpha.17";
120
120
  var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
121
121
  var author = "YiJie <yijie4188@gmail.com>";
122
122
  var repository = {
@@ -139,7 +139,8 @@ var files = [
139
139
  "README.md"
140
140
  ];
141
141
  var scripts = {
142
- prepublish: "jb --noMin"
142
+ prepublish: "jb -nm && jk",
143
+ postpublish: "jk"
143
144
  };
144
145
  var exports$1 = {
145
146
  "./package.json": "./package.json",
@@ -177,32 +178,6 @@ var peerDependencies = {
177
178
  "rollup-plugin-swc3": "^0.12.1",
178
179
  typescript: "^4.0.0||^5.0.0"
179
180
  };
180
- var peerDependenciesMeta = {
181
- "@rollup/plugin-terser": {
182
- optional: true
183
- },
184
- "@pnpm/filter-workspace-packages": {
185
- optional: true
186
- },
187
- "esbuild-register": {
188
- optional: true
189
- },
190
- postcss: {
191
- optional: true
192
- },
193
- "rollup-plugin-postcss": {
194
- optional: true
195
- },
196
- "rollup-plugin-esbuild": {
197
- optional: true
198
- },
199
- "rollup-plugin-swc3": {
200
- optional: true
201
- },
202
- typescript: {
203
- optional: true
204
- }
205
- };
206
181
  var devDependencies = {
207
182
  "@npm/types": "^1.0.2",
208
183
  "@pnpm/filter-workspace-packages": "^7.2.13",
@@ -220,44 +195,6 @@ var devDependencies = {
220
195
  "rollup-plugin-esbuild": "^6.1.0",
221
196
  "rollup-plugin-swc3": "^0.12.1"
222
197
  };
223
- var publishConfig = {
224
- exports: {
225
- "./package.json": "./package.json",
226
- ".": {
227
- source: "./src/index.ts",
228
- require: "./dist/index.cjs",
229
- "default": "./dist/index.js"
230
- },
231
- "./cli": {
232
- source: "./src/cli.ts",
233
- require: "./dist/cli.cjs",
234
- "default": "./dist/cli.js"
235
- },
236
- "./cli-only-build": {
237
- source: "./src/cli-only-build.ts",
238
- require: "./dist/cli-only-build.cjs",
239
- "default": "./dist/cli-only-build.js"
240
- },
241
- "./rollup": {
242
- source: "./src/rollup/index.ts",
243
- require: "./dist/rollup/index.cjs",
244
- "default": "./dist/rollup/index.js"
245
- }
246
- },
247
- main: "./dist/index.cjs",
248
- module: "./dist/index.js",
249
- typesVersions: {
250
- "<5.0": {
251
- "*": [
252
- "*",
253
- "./dist/*",
254
- "./dist/*/index.d.ts",
255
- "./dist/*/index.d.mts",
256
- "./dist/*/index.d.cts"
257
- ]
258
- }
259
- }
260
- };
261
198
  var pkg = {
262
199
  name: name,
263
200
  type: type,
@@ -274,9 +211,7 @@ var pkg = {
274
211
  imports: imports,
275
212
  dependencies: dependencies,
276
213
  peerDependencies: peerDependencies,
277
- peerDependenciesMeta: peerDependenciesMeta,
278
- devDependencies: devDependencies,
279
- publishConfig: publishConfig
214
+ devDependencies: devDependencies
280
215
  };
281
216
 
282
217
  const entriesDescription = `
@@ -422,7 +357,7 @@ const require$1 = node_module.createRequire((typeof document === 'undefined' ? r
422
357
  const isDefault = process.env.JIEK_IS_ONLY_BUILD === "true";
423
358
  const description = `
424
359
  Build the package according to the 'exports' field from the package.json.
425
- If you want to rewrite the \`rollup\` command options, you can pass the options after '--'.
360
+ If you want to through the options to the \`rollup\` command, you can pass the options after '--'.
426
361
  ${isDefault ? "This command is the default command." : ""}
427
362
  `.trim();
428
363
  async function checkDependency(dependency) {
@@ -464,20 +399,15 @@ const buildEntriesDescription = `
464
399
  ${entriesDescription}
465
400
  If you pass the --entries option, it will merge into the entries of the command.
466
401
  `.trim();
467
- const command = isDefault ? commander.program.name("jb/jiek-build").helpCommand(false) : commander.program;
468
- if (IS_WORKSPACE) {
469
- if (isDefault) {
470
- command.argument("[filters]", buildFilterDescription);
402
+ const command = isDefault ? (() => {
403
+ const c = commander.program.name("jb/jiek-build").helpCommand(false);
404
+ if (IS_WORKSPACE) {
405
+ c.argument("[filters]", buildFilterDescription);
471
406
  } else {
472
- command.command("build [filters]");
407
+ c.argument("[entries]", buildEntriesDescription);
473
408
  }
474
- } else {
475
- if (isDefault) {
476
- command.argument("[entries]", buildEntriesDescription);
477
- } else {
478
- command.command("build [entries]");
479
- }
480
- }
409
+ return c;
410
+ })() : commander.program.command(`build [${IS_WORKSPACE ? "filters" : "entries"}]`);
481
411
  command.description(description).option("-t, --type <TYPE>", `The type of build, support ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}.`, (v) => {
482
412
  if (!BUILDER_TYPES.includes(v)) {
483
413
  throw new Error(`The value of 'type' must be ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}`);
@@ -108,7 +108,7 @@ async function getSelectedProjectsGraph(filter = program.getOptionValue("filter"
108
108
 
109
109
  var name = "jiek";
110
110
  var type = "module";
111
- var version = "2.0.2";
111
+ var version = "2.0.2-alpha.17";
112
112
  var description$1 = "A lightweight toolkit for compiling and managing libraries based on `package.json` metadata and suitable for `Monorepo`.";
113
113
  var author = "YiJie <yijie4188@gmail.com>";
114
114
  var repository = {
@@ -131,7 +131,8 @@ var files = [
131
131
  "README.md"
132
132
  ];
133
133
  var scripts = {
134
- prepublish: "jb --noMin"
134
+ prepublish: "jb -nm && jk",
135
+ postpublish: "jk"
135
136
  };
136
137
  var exports = {
137
138
  "./package.json": "./package.json",
@@ -169,32 +170,6 @@ var peerDependencies = {
169
170
  "rollup-plugin-swc3": "^0.12.1",
170
171
  typescript: "^4.0.0||^5.0.0"
171
172
  };
172
- var peerDependenciesMeta = {
173
- "@rollup/plugin-terser": {
174
- optional: true
175
- },
176
- "@pnpm/filter-workspace-packages": {
177
- optional: true
178
- },
179
- "esbuild-register": {
180
- optional: true
181
- },
182
- postcss: {
183
- optional: true
184
- },
185
- "rollup-plugin-postcss": {
186
- optional: true
187
- },
188
- "rollup-plugin-esbuild": {
189
- optional: true
190
- },
191
- "rollup-plugin-swc3": {
192
- optional: true
193
- },
194
- typescript: {
195
- optional: true
196
- }
197
- };
198
173
  var devDependencies = {
199
174
  "@npm/types": "^1.0.2",
200
175
  "@pnpm/filter-workspace-packages": "^7.2.13",
@@ -212,44 +187,6 @@ var devDependencies = {
212
187
  "rollup-plugin-esbuild": "^6.1.0",
213
188
  "rollup-plugin-swc3": "^0.12.1"
214
189
  };
215
- var publishConfig = {
216
- exports: {
217
- "./package.json": "./package.json",
218
- ".": {
219
- source: "./src/index.ts",
220
- require: "./dist/index.cjs",
221
- "default": "./dist/index.js"
222
- },
223
- "./cli": {
224
- source: "./src/cli.ts",
225
- require: "./dist/cli.cjs",
226
- "default": "./dist/cli.js"
227
- },
228
- "./cli-only-build": {
229
- source: "./src/cli-only-build.ts",
230
- require: "./dist/cli-only-build.cjs",
231
- "default": "./dist/cli-only-build.js"
232
- },
233
- "./rollup": {
234
- source: "./src/rollup/index.ts",
235
- require: "./dist/rollup/index.cjs",
236
- "default": "./dist/rollup/index.js"
237
- }
238
- },
239
- main: "./dist/index.cjs",
240
- module: "./dist/index.js",
241
- typesVersions: {
242
- "<5.0": {
243
- "*": [
244
- "*",
245
- "./dist/*",
246
- "./dist/*/index.d.ts",
247
- "./dist/*/index.d.mts",
248
- "./dist/*/index.d.cts"
249
- ]
250
- }
251
- }
252
- };
253
190
  var pkg = {
254
191
  name: name,
255
192
  type: type,
@@ -266,9 +203,7 @@ var pkg = {
266
203
  imports: imports,
267
204
  dependencies: dependencies,
268
205
  peerDependencies: peerDependencies,
269
- peerDependenciesMeta: peerDependenciesMeta,
270
- devDependencies: devDependencies,
271
- publishConfig: publishConfig
206
+ devDependencies: devDependencies
272
207
  };
273
208
 
274
209
  const entriesDescription = `
@@ -414,7 +349,7 @@ const require = createRequire(import.meta.url);
414
349
  const isDefault = process.env.JIEK_IS_ONLY_BUILD === "true";
415
350
  const description = `
416
351
  Build the package according to the 'exports' field from the package.json.
417
- If you want to rewrite the \`rollup\` command options, you can pass the options after '--'.
352
+ If you want to through the options to the \`rollup\` command, you can pass the options after '--'.
418
353
  ${isDefault ? "This command is the default command." : ""}
419
354
  `.trim();
420
355
  async function checkDependency(dependency) {
@@ -456,20 +391,15 @@ const buildEntriesDescription = `
456
391
  ${entriesDescription}
457
392
  If you pass the --entries option, it will merge into the entries of the command.
458
393
  `.trim();
459
- const command = isDefault ? program.name("jb/jiek-build").helpCommand(false) : program;
460
- if (IS_WORKSPACE) {
461
- if (isDefault) {
462
- command.argument("[filters]", buildFilterDescription);
394
+ const command = isDefault ? (() => {
395
+ const c = program.name("jb/jiek-build").helpCommand(false);
396
+ if (IS_WORKSPACE) {
397
+ c.argument("[filters]", buildFilterDescription);
463
398
  } else {
464
- command.command("build [filters]");
399
+ c.argument("[entries]", buildEntriesDescription);
465
400
  }
466
- } else {
467
- if (isDefault) {
468
- command.argument("[entries]", buildEntriesDescription);
469
- } else {
470
- command.command("build [entries]");
471
- }
472
- }
401
+ return c;
402
+ })() : program.command(`build [${IS_WORKSPACE ? "filters" : "entries"}]`);
473
403
  command.description(description).option("-t, --type <TYPE>", `The type of build, support ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}.`, (v) => {
474
404
  if (!BUILDER_TYPES.includes(v)) {
475
405
  throw new Error(`The value of 'type' must be ${BUILDER_TYPES.map((s) => `"${s}"`).join(", ")}`);
package/dist/cli.cjs CHANGED
@@ -44,14 +44,6 @@ var detectIndent__default = /*#__PURE__*/_interopDefault(detectIndent);
44
44
  var require$$0__default = /*#__PURE__*/_interopDefault(require$$0);
45
45
  var require$$0__default$1 = /*#__PURE__*/_interopDefault(require$$0$1);
46
46
 
47
- let resolve;
48
- function actionDone() {
49
- resolve();
50
- }
51
- function actionRestore() {
52
- new Promise((r) => resolve = r);
53
- }
54
-
55
47
  let root;
56
48
  function getRoot() {
57
49
  if (root)
@@ -4454,14 +4446,59 @@ Support with variables: 'PKG_NAME',
4454
4446
  .e.g. 'dist/{{PKG_NAME}}'.
4455
4447
  `.trim();
4456
4448
 
4457
- 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 }) => {
4458
- actionRestore();
4449
+ const description = `
4450
+ Publish package to npm registry, and auto generate exports field and other fields in published package.json.
4451
+ If you want to through the options to the \`pnpm publish\` command, you can pass the options after '--'.
4452
+ `.trim();
4453
+ async function forEachSelectedProjectsGraphEntries(callback) {
4459
4454
  const { value = {} } = await getSelectedProjectsGraph() ?? {};
4460
4455
  const selectedProjectsGraphEntries = Object.entries(value);
4461
4456
  if (selectedProjectsGraphEntries.length === 0) {
4462
4457
  throw new Error("no packages selected");
4463
4458
  }
4464
- const manifests = selectedProjectsGraphEntries.map(([dir, manifest]) => {
4459
+ for (const [dir, manifest] of selectedProjectsGraphEntries) {
4460
+ callback(dir, manifest);
4461
+ }
4462
+ }
4463
+ commander.program.command("publish").description(description).aliases(["pub", "p"]).option("-b, --bumper <bumper>", "bump version", "patch").option("-no-b, --no-bumper", "no bump version").option("-o, --outdir <OUTDIR>", outdirDescription, String, "dist").action(async ({ outdir, bumper: bumper$1 }) => {
4464
+ let shouldPassThrough = false;
4465
+ const passThroughOptions = process.argv.reduce(
4466
+ (acc, value) => {
4467
+ if (shouldPassThrough) {
4468
+ acc.push(value);
4469
+ }
4470
+ if (value === "--") {
4471
+ shouldPassThrough = true;
4472
+ }
4473
+ return acc;
4474
+ },
4475
+ []
4476
+ );
4477
+ await forEachSelectedProjectsGraphEntries((dir) => {
4478
+ const args = ["pnpm", "publish", "--access", "public", "--no-git-checks"];
4479
+ if (bumper$1 && bumper.TAGS.includes(bumper$1)) {
4480
+ args.push("--tag", bumper$1);
4481
+ }
4482
+ args.push(...passThroughOptions);
4483
+ childProcess__namespace.execSync(args.join(" "), {
4484
+ cwd: dir,
4485
+ stdio: "inherit",
4486
+ env: {
4487
+ ...process.env,
4488
+ JIEK_PUBLISH_OUTDIR: JSON.stringify(outdir),
4489
+ JIEK_PUBLISH_BUMPER: JSON.stringify(bumper$1)
4490
+ }
4491
+ });
4492
+ });
4493
+ });
4494
+ async function prepublish() {
4495
+ const {
4496
+ JIEK_PUBLISH_OUTDIR: outdirEnv,
4497
+ JIEK_PUBLISH_BUMPER: bumperEnv
4498
+ } = process.env;
4499
+ const outdir = outdirEnv ? JSON.parse(outdirEnv) : "dist";
4500
+ const bumper$1 = bumperEnv ? JSON.parse(bumperEnv) : false;
4501
+ const generateNewManifest = (dir, manifest) => {
4465
4502
  const { name, type, exports: entrypoints = {} } = manifest;
4466
4503
  if (!name) {
4467
4504
  throw new Error(`package.json in ${dir} must have a name field`);
@@ -4482,35 +4519,38 @@ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper
4482
4519
  ...resolvedEntrypoints,
4483
4520
  ...exports
4484
4521
  };
4485
- return [dir, newManifest, resolvedOutdir];
4486
- });
4487
- const passArgs = Object.entries(options).reduce((acc, [key, value2]) => {
4488
- if (value2) {
4489
- acc.push(`--${key}`, value2);
4490
- }
4491
- return acc;
4492
- }, []);
4493
- for (const [dir, manifest, resolvedOutdir] of manifests) {
4494
- const oldJSONString = fs__default.default.readFileSync(path__default.default.join(dir, "package.json"), "utf-8");
4495
- const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
4496
- const newVersion = bumper$1 ? bumper.bump(oldJSON.version, bumper$1) : oldJSON.version;
4497
- const { indent = " " } = detectIndent__default.default(oldJSONString);
4498
- const formattingOptions = {
4499
- tabSize: indent.length,
4500
- insertSpaces: true
4501
- };
4522
+ return [newManifest, resolvedOutdir];
4523
+ };
4524
+ const generateNewPackageJSONString = ({
4525
+ oldJSONString,
4526
+ oldJSON,
4527
+ manifest,
4528
+ formattingOptions
4529
+ }) => {
4502
4530
  let newJSONString = oldJSONString;
4503
4531
  newJSONString = jsoncParser.applyEdits(
4504
4532
  newJSONString,
4505
4533
  jsoncParser.modify(
4506
4534
  newJSONString,
4507
- ["version"],
4508
- newVersion,
4535
+ ["publishConfig", "typesVersions"],
4536
+ {
4537
+ "<5.0": {
4538
+ "*": [
4539
+ "*",
4540
+ `./*`,
4541
+ `./*/index.d.ts`,
4542
+ `./*/index.d.mts`,
4543
+ `./*/index.d.cts`
4544
+ ]
4545
+ }
4546
+ },
4509
4547
  { formattingOptions }
4510
4548
  )
4511
4549
  );
4512
- for (const [key, value2] of Object.entries(manifest)) {
4513
- if (JSON.stringify(value2) === JSON.stringify(oldJSON[key]))
4550
+ for (const [key, value] of Object.entries(manifest)) {
4551
+ if (key === "version")
4552
+ continue;
4553
+ if (JSON.stringify(value) === JSON.stringify(oldJSON[key]))
4514
4554
  continue;
4515
4555
  if (key !== "exports") {
4516
4556
  newJSONString = jsoncParser.applyEdits(
@@ -4518,12 +4558,12 @@ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper
4518
4558
  jsoncParser.modify(
4519
4559
  newJSONString,
4520
4560
  ["publishConfig", key],
4521
- value2,
4561
+ value,
4522
4562
  { formattingOptions }
4523
4563
  )
4524
4564
  );
4525
4565
  } else {
4526
- const exports = value2;
4566
+ const exports = value;
4527
4567
  for (const [k, v] of Object.entries(exports)) {
4528
4568
  newJSONString = jsoncParser.applyEdits(
4529
4569
  newJSONString,
@@ -4565,46 +4605,180 @@ commander.program.command("publish").aliases(["pub", "p"]).option("-b, --bumper
4565
4605
  }
4566
4606
  }
4567
4607
  }
4568
- newJSONString = jsoncParser.applyEdits(
4569
- newJSONString,
4570
- jsoncParser.modify(
4571
- newJSONString,
4572
- ["publishConfig", "typesVersions"],
4573
- {
4574
- "<5.0": {
4575
- "*": [
4576
- "*",
4577
- `${resolvedOutdir}/*`,
4578
- `${resolvedOutdir}/*/index.d.ts`,
4579
- `${resolvedOutdir}/*/index.d.mts`,
4580
- `${resolvedOutdir}/*/index.d.cts`
4581
- ]
4582
- }
4608
+ if (oldJSON["peerDependencies"]) {
4609
+ const peerDependenciesMeta = Object.keys(oldJSON["peerDependencies"]).reduce(
4610
+ (acc, key) => {
4611
+ acc[key] = { optional: true };
4612
+ return acc;
4583
4613
  },
4584
- { formattingOptions }
4585
- )
4614
+ {}
4615
+ );
4616
+ newJSONString = jsoncParser.applyEdits(
4617
+ newJSONString,
4618
+ jsoncParser.modify(
4619
+ newJSONString,
4620
+ ["peerDependenciesMeta"],
4621
+ peerDependenciesMeta,
4622
+ { formattingOptions }
4623
+ )
4624
+ );
4625
+ }
4626
+ if (oldJSON["files"]) {
4627
+ newJSONString = jsoncParser.applyEdits(
4628
+ newJSONString,
4629
+ jsoncParser.modify(
4630
+ newJSONString,
4631
+ ["files"],
4632
+ void 0,
4633
+ { formattingOptions }
4634
+ )
4635
+ );
4636
+ }
4637
+ return newJSONString;
4638
+ };
4639
+ await forEachSelectedProjectsGraphEntries((dir, originalManifest) => {
4640
+ const [manifest, resolvedOutdir] = generateNewManifest(dir, originalManifest);
4641
+ const resolveByDir = (...paths) => path__default.default.resolve(dir, ...paths);
4642
+ const oldJSONString = fs__default.default.readFileSync(resolveByDir("package.json"), "utf-8");
4643
+ const oldJSON = JSON.parse(oldJSONString) ?? "0.0.0";
4644
+ if (typeof oldJSON.version !== "string") {
4645
+ throw new Error(`${dir}/package.json must have a version field with a string value`);
4646
+ }
4647
+ const { indent = " " } = detectIndent__default.default(oldJSONString);
4648
+ const formattingOptions = {
4649
+ tabSize: indent.length,
4650
+ insertSpaces: true
4651
+ };
4652
+ const newVersion = bumper$1 ? bumper.bump(oldJSON.version, bumper$1) : oldJSON.version;
4653
+ const modifyVersionPackageJSON = jsoncParser.applyEdits(
4654
+ oldJSONString,
4655
+ jsoncParser.modify(oldJSONString, ["version"], newVersion, { formattingOptions })
4586
4656
  );
4587
- try {
4588
- fs__default.default.renameSync(path__default.default.join(dir, "package.json"), path__default.default.join(dir, "package.json.bak"));
4589
- fs__default.default.writeFileSync(path__default.default.join(dir, "package.json"), newJSONString);
4590
- !silent && console.log(newJSONString);
4591
- if (preview) {
4657
+ const newJSONString = generateNewPackageJSONString({
4658
+ oldJSONString: modifyVersionPackageJSON,
4659
+ oldJSON: {
4660
+ ...oldJSON,
4661
+ version: newVersion
4662
+ },
4663
+ manifest,
4664
+ formattingOptions
4665
+ });
4666
+ const withPublishConfigDirectoryOldJSONString = jsoncParser.applyEdits(
4667
+ modifyVersionPackageJSON,
4668
+ jsoncParser.modify(modifyVersionPackageJSON, ["publishConfig", "directory"], resolvedOutdir, { formattingOptions })
4669
+ );
4670
+ if (!fs__default.default.existsSync(resolveByDir(resolvedOutdir))) {
4671
+ fs__default.default.mkdirSync(resolveByDir(resolvedOutdir));
4672
+ }
4673
+ const jiekTempDir = resolveByDir("node_modules/.jiek/.tmp");
4674
+ if (!fs__default.default.existsSync(resolveByDir(jiekTempDir))) {
4675
+ fs__default.default.mkdirSync(resolveByDir(jiekTempDir), { recursive: true });
4676
+ }
4677
+ fs__default.default.writeFileSync(resolveByDir(resolvedOutdir, "package.json"), newJSONString);
4678
+ fs__default.default.writeFileSync(resolveByDir(jiekTempDir, "package.json"), modifyVersionPackageJSON);
4679
+ fs__default.default.writeFileSync(resolveByDir("package.json"), withPublishConfigDirectoryOldJSONString);
4680
+ const allBuildFiles = fs__default.default.readdirSync(resolveByDir(resolvedOutdir), { recursive: true }).filter((file) => typeof file === "string").filter((file) => file !== "package.json");
4681
+ for (const file of allBuildFiles) {
4682
+ const filepath = resolveByDir(resolvedOutdir, file);
4683
+ const stat = fs__default.default.statSync(filepath);
4684
+ if (stat.isDirectory()) {
4685
+ const existsIndexFile = allBuildFiles.some(
4686
+ (f) => [
4687
+ path__default.default.join(file, "index.js"),
4688
+ path__default.default.join(file, "index.mjs"),
4689
+ path__default.default.join(file, "index.cjs")
4690
+ ].includes(f)
4691
+ );
4692
+ if (existsIndexFile) {
4693
+ const cpDistPath = resolveByDir(resolvedOutdir, resolvedOutdir, file);
4694
+ const pkgJSONPath = resolveByDir(resolvedOutdir, file, "package.json");
4695
+ const relativePath = path__default.default.relative(filepath, cpDistPath);
4696
+ const { type } = manifest;
4697
+ fs__default.default.writeFileSync(
4698
+ pkgJSONPath,
4699
+ JSON.stringify({
4700
+ type,
4701
+ main: [relativePath, `index.${type === "module" ? "c" : ""}js`].join("/"),
4702
+ module: [relativePath, `index.${type === "module" ? "" : "m"}js`].join("/")
4703
+ })
4704
+ );
4705
+ }
4706
+ }
4707
+ }
4708
+ fs__default.default.mkdirSync(resolveByDir(resolvedOutdir, resolvedOutdir));
4709
+ for (const file of allBuildFiles) {
4710
+ const filepath = resolveByDir(resolvedOutdir, file);
4711
+ const newFilepath = resolveByDir(resolvedOutdir, resolvedOutdir, file);
4712
+ const stat = fs__default.default.statSync(filepath);
4713
+ if (stat.isDirectory()) {
4714
+ fs__default.default.mkdirSync(newFilepath, { recursive: true });
4592
4715
  continue;
4593
4716
  }
4594
- const args = ["pnpm", "publish", "--access", "public", "--no-git-checks", ...passArgs];
4595
- if (bumper$1 && bumper.TAGS.includes(bumper$1)) {
4596
- args.push("--tag", bumper$1);
4717
+ if (stat.isFile()) {
4718
+ fs__default.default.cpSync(filepath, newFilepath);
4719
+ fs__default.default.rmSync(filepath);
4720
+ }
4721
+ }
4722
+ if (oldJSON.files) {
4723
+ if (!Array.isArray(oldJSON.files)) {
4724
+ throw new Error(`${dir}/package.json files field must be an array`);
4725
+ }
4726
+ if (Array.isArray(oldJSON.files) && oldJSON.files.every((file) => typeof file !== "string")) {
4727
+ throw new Error(`${dir}/package.json files field must be an array of string`);
4597
4728
  }
4598
- childProcess__namespace.execSync(args.join(" "), {
4599
- cwd: dir,
4600
- stdio: "inherit"
4601
- });
4602
- const modifyVersionPackageJSON = jsoncParser.applyEdits(oldJSONString, jsoncParser.modify(oldJSONString, ["version"], newVersion, {}));
4603
- fs__default.default.writeFileSync(path__default.default.join(dir, "package.json.bak"), modifyVersionPackageJSON);
4604
- } finally {
4605
- fs__default.default.unlinkSync(path__default.default.join(dir, "package.json"));
4606
- fs__default.default.renameSync(path__default.default.join(dir, "package.json.bak"), path__default.default.join(dir, "package.json"));
4607
4729
  }
4730
+ const resolvedOutdirAbs = resolveByDir(resolvedOutdir);
4731
+ const files = (oldJSON.files ?? fs__default.default.readdirSync(resolveByDir("."))).filter((file) => file === "node_modules" || resolveByDir(file) !== resolvedOutdirAbs);
4732
+ for (const file of files) {
4733
+ const path2 = resolveByDir(file);
4734
+ try {
4735
+ const stat = fs__default.default.statSync(path2);
4736
+ if (stat.isDirectory()) {
4737
+ fs__default.default.cpSync(path2, resolveByDir(resolvedOutdir, file), { recursive: true });
4738
+ continue;
4739
+ }
4740
+ if (stat.isFile()) {
4741
+ fs__default.default.cpSync(path2, resolveByDir(resolvedOutdir, file));
4742
+ continue;
4743
+ }
4744
+ } catch (e) {
4745
+ console.warn(String(e));
4746
+ continue;
4747
+ }
4748
+ throw new Error(`file type of ${path2} is not supported`);
4749
+ }
4750
+ });
4751
+ }
4752
+ async function postpublish() {
4753
+ await forEachSelectedProjectsGraphEntries((dir) => {
4754
+ const jiekTempDir = path__default.default.resolve(dir, "node_modules/.jiek/.tmp");
4755
+ const packageJSON = path__default.default.resolve(dir, "package.json");
4756
+ const jiekTempPackageJSON = path__default.default.resolve(jiekTempDir, "package.json");
4757
+ if (fs__default.default.existsSync(jiekTempPackageJSON)) {
4758
+ fs__default.default.copyFileSync(jiekTempPackageJSON, packageJSON);
4759
+ fs__default.default.rmSync(jiekTempPackageJSON);
4760
+ console.log(`${dir}/package.json has been restored`);
4761
+ } else {
4762
+ throw new Error(
4763
+ `jiek temp \`${dir}/package.json\` not found, please confirm the jiek pre-publish command has been executed`
4764
+ );
4765
+ }
4766
+ });
4767
+ }
4768
+ commander.program.action(async () => {
4769
+ const {
4770
+ npm_lifecycle_event: NPM_LIFECYCLE_EVENT
4771
+ } = process.env;
4772
+ switch (NPM_LIFECYCLE_EVENT) {
4773
+ case "prepublish":
4774
+ await prepublish();
4775
+ break;
4776
+ case "postpublish":
4777
+ await postpublish();
4778
+ break;
4779
+ default:
4780
+ commander.program.help();
4608
4781
  }
4609
- actionDone();
4610
4782
  });
4783
+ commander.program.command("prepublish").action(prepublish);
4784
+ commander.program.command("postpublish").action(postpublish);