jiek 2.2.7 → 2.3.0

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.
Files changed (100) hide show
  1. package/bin/build.cjs +2 -0
  2. package/bin/index.cjs +2 -0
  3. package/bin-helper/index.cjs +19 -31
  4. package/dist/.internal/.chunks/filterSupport.4rM7f6jB.cjs +114 -0
  5. package/dist/.internal/.chunks/filterSupport.BXWpLBpT.js +104 -0
  6. package/dist/{cli.js → .internal/.chunks/index.B6RQz1DZ.js} +1 -737
  7. package/dist/.internal/.chunks/index.BHuJRlvZ.js +9059 -0
  8. package/dist/.internal/.chunks/index.Daihq2aI.cjs +9071 -0
  9. package/dist/{cli.cjs → .internal/.chunks/index.DlHFuTjM.cjs} +1 -759
  10. package/dist/.internal/.chunks/loadConfig.CFfzkm_p.js +110 -0
  11. package/dist/.internal/.chunks/loadConfig.OOKddvHF.cjs +117 -0
  12. package/dist/{cli-only-build.cjs → .internal/bin/common.cjs} +225 -444
  13. package/dist/.internal/bin/common.d.cts +18 -0
  14. package/dist/.internal/bin/common.d.ts +18 -0
  15. package/dist/{cli-only-build.js → .internal/bin/common.js} +220 -438
  16. package/dist/.internal/bin/parseArgv.cjs +33 -0
  17. package/dist/.internal/bin/parseArgv.d.cts +5 -0
  18. package/dist/.internal/bin/parseArgv.d.ts +5 -0
  19. package/dist/.internal/bin/parseArgv.js +27 -0
  20. package/dist/.internal/bridge.cjs +30 -0
  21. package/dist/.internal/bridge.d.cts +39 -0
  22. package/dist/.internal/bridge.d.ts +39 -0
  23. package/dist/.internal/bridge.js +27 -0
  24. package/dist/.internal/rollup/base.cjs +10 -0
  25. package/dist/{cli-only-build.d.cts → .internal/rollup/base.d.cts} +8 -15
  26. package/dist/{cli-only-build.d.ts → .internal/rollup/base.d.ts} +8 -15
  27. package/dist/.internal/rollup/base.js +7 -0
  28. package/dist/.internal/rollup/bundle-analyzer.cjs +51 -0
  29. package/dist/.internal/rollup/bundle-analyzer.d.cts +92 -0
  30. package/dist/.internal/rollup/bundle-analyzer.d.ts +92 -0
  31. package/dist/.internal/rollup/bundle-analyzer.js +45 -0
  32. package/dist/.internal/utils/filterSupport.cjs +18 -0
  33. package/dist/.internal/utils/filterSupport.d.cts +15 -0
  34. package/dist/.internal/utils/filterSupport.d.ts +15 -0
  35. package/dist/.internal/utils/filterSupport.js +8 -0
  36. package/dist/.internal/utils/getInternalModuleName.cjs +5 -0
  37. package/dist/.internal/utils/getInternalModuleName.d.cts +3 -0
  38. package/dist/.internal/utils/getInternalModuleName.d.ts +3 -0
  39. package/dist/.internal/utils/getInternalModuleName.js +3 -0
  40. package/dist/.internal/utils/intersection.cjs +5 -0
  41. package/dist/.internal/utils/intersection.d.cts +3 -0
  42. package/dist/.internal/utils/intersection.d.ts +3 -0
  43. package/dist/.internal/utils/intersection.js +3 -0
  44. package/dist/.internal/utils/loadConfig.cjs +14 -0
  45. package/dist/.internal/utils/loadConfig.d.cts +10 -0
  46. package/dist/.internal/utils/loadConfig.d.ts +10 -0
  47. package/dist/.internal/utils/loadConfig.js +9 -0
  48. package/dist/.internal/utils/recursiveListFiles.cjs +19 -0
  49. package/dist/.internal/utils/recursiveListFiles.d.cts +3 -0
  50. package/dist/.internal/utils/recursiveListFiles.d.ts +3 -0
  51. package/dist/.internal/utils/recursiveListFiles.js +13 -0
  52. package/dist/.internal/utils/resolveExports.cjs +118 -0
  53. package/dist/.internal/utils/resolveExports.d.cts +26 -0
  54. package/dist/.internal/utils/resolveExports.d.ts +26 -0
  55. package/dist/.internal/utils/resolveExports.js +111 -0
  56. package/dist/.internal/utils/ts.cjs +68 -0
  57. package/dist/.internal/utils/ts.d.cts +3 -0
  58. package/dist/.internal/utils/ts.d.ts +3 -0
  59. package/dist/.internal/utils/ts.js +62 -0
  60. package/dist/bin/build.cjs +10 -0
  61. package/dist/bin/index.cjs +501 -0
  62. package/dist/index.d.cts +12 -114
  63. package/dist/index.d.ts +12 -114
  64. package/dist/rollup/index.cjs +280 -4573
  65. package/dist/rollup/index.d.cts +7 -1
  66. package/dist/rollup/index.d.ts +7 -1
  67. package/dist/rollup/index.js +268 -4558
  68. package/package.json +15 -23
  69. package/src/bin/build.cts +5 -0
  70. package/src/bin/common.ts +3 -0
  71. package/src/bin/index.cts +7 -0
  72. package/src/bridge.ts +1 -1
  73. package/src/commands/base.ts +3 -3
  74. package/src/commands/build/analyzer.ts +5 -5
  75. package/src/commands/build/client/analyzer.tsx +1 -1
  76. package/src/commands/build/client/index.ts +5 -7
  77. package/src/commands/build.ts +226 -211
  78. package/src/commands/meta.ts +1 -1
  79. package/src/commands/publish.ts +113 -32
  80. package/src/index.ts +6 -1
  81. package/src/rollup/base.ts +2 -2
  82. package/src/rollup/index.ts +321 -124
  83. package/src/rollup/plugins/with-external.ts +23 -0
  84. package/src/rollup/utils/externalResolver.ts +20 -8
  85. package/src/utils/checkDependency.ts +1 -1
  86. package/src/utils/filterSupport.ts +17 -16
  87. package/src/utils/getInternalModuleName.ts +5 -0
  88. package/src/utils/intersection.ts +1 -0
  89. package/src/utils/{recusiveListFiles.ts → recursiveListFiles.ts} +2 -2
  90. package/src/utils/{getExports.ts → resolveExports.ts} +16 -14
  91. package/bin/jiek-build.js +0 -16
  92. package/bin/jiek.js +0 -13
  93. package/cli/package.json +0 -1
  94. package/cli-only-build/package.json +0 -1
  95. package/dist/cli.d.cts +0 -14
  96. package/dist/cli.d.ts +0 -14
  97. package/src/cli-only-build.ts +0 -11
  98. package/src/cli.ts +0 -6
  99. /package/{src/bin/build.ts → .jiek-production-tag} +0 -0
  100. /package/src/{parseArgv.ts → bin/parseArgv.ts} +0 -0
@@ -1,112 +1,5 @@
1
- import * as childProcess from 'node:child_process';
2
- import fs from 'node:fs';
3
- import path, { isAbsolute, relative, resolve } from 'node:path';
4
- import process$1 from 'node:process';
5
- import { TAGS, bump } from '@jiek/utils/bumper';
6
- import { program } from 'commander';
7
- import detectIndent from 'detect-indent';
8
- import { applyEdits, modify } from 'jsonc-parser';
9
- import { createRequire } from 'node:module';
10
- import { load } from 'js-yaml';
11
- import { isWorkspaceDir, getWorkspaceDir } from '@jiek/utils/getWorkspaceDir';
12
- import { resolveEntrypoints, filterLeafs, DEFAULT_SKIP_VALUES, entrypoints2Exports } from '@jiek/pkger/entrypoints';
13
1
  import require$$0 from 'util';
14
2
  import require$$0$1 from 'path';
15
- import 'jiek/cli-only-build';
16
-
17
- var require = /* @__PURE__ */ createRequire(import.meta.url);
18
-
19
- let root;
20
- function getRoot() {
21
- if (root) return root;
22
- const rootOption = process.env.JIEK_ROOT;
23
- root = rootOption ? path.isAbsolute(rootOption) ? rootOption : path.resolve(process.cwd(), rootOption) : void 0;
24
- return root;
25
- }
26
-
27
- let wd;
28
- let notWorkspace = false;
29
- function getWD() {
30
- if (wd) return { wd, notWorkspace };
31
- const root = getRoot();
32
- if (root !== void 0) {
33
- const isWorkspace = isWorkspaceDir(root, type);
34
- notWorkspace = !isWorkspace;
35
- wd = root;
36
- return { wd, notWorkspace };
37
- }
38
- try {
39
- wd = getWorkspaceDir(type);
40
- } catch (e) {
41
- if ("message" in e && e.message === "workspace root not found") {
42
- wd = root ?? process.cwd();
43
- notWorkspace = true;
44
- } else {
45
- throw e;
46
- }
47
- }
48
- return { wd, notWorkspace };
49
- }
50
-
51
- let type = "";
52
- try {
53
- require.resolve("@pnpm/filter-workspace-packages");
54
- type = "pnpm";
55
- } catch {
56
- }
57
- async function getSelectedProjectsGraph(filter = program.getOptionValue("filter")) {
58
- const { wd, notWorkspace } = getWD();
59
- let root = getRoot();
60
- if (notWorkspace) {
61
- return {
62
- wd,
63
- root,
64
- value: {
65
- [wd]: JSON.parse(fs.readFileSync(path.resolve(wd, "package.json"), "utf-8"))
66
- }
67
- };
68
- }
69
- if (type === "pnpm") {
70
- const pnpmWorkspaceFilePath = path.resolve(wd, "pnpm-workspace.yaml");
71
- const pnpmWorkspaceFileContent = fs.readFileSync(pnpmWorkspaceFilePath, "utf-8");
72
- const pnpmWorkspace = load(pnpmWorkspaceFileContent);
73
- if (root === wd && !filter) {
74
- throw new Error("root path is workspace root, please provide a filter");
75
- }
76
- if (root === void 0) {
77
- root = process.cwd();
78
- }
79
- if (root !== wd && !filter) {
80
- const packageJSONIsExist = fs.existsSync(path.resolve(root, "package.json"));
81
- if (!packageJSONIsExist) {
82
- throw new Error("root path is not workspace root, please provide a filter");
83
- }
84
- const packageJSON = JSON.parse(fs.readFileSync(path.resolve(root, "package.json"), "utf-8"));
85
- if (!packageJSON.name) {
86
- throw new Error("root path is not workspace root, please provide a filter");
87
- }
88
- filter = packageJSON.name;
89
- }
90
- const { filterPackagesFromDir } = await import('@pnpm/filter-workspace-packages');
91
- const { selectedProjectsGraph } = await filterPackagesFromDir(wd, [{
92
- filter: filter ?? "",
93
- followProdDepsOnly: true
94
- }], {
95
- prefix: root,
96
- workspaceDir: wd,
97
- patterns: pnpmWorkspace.packages
98
- });
99
- return {
100
- wd,
101
- root,
102
- value: Object.entries(selectedProjectsGraph).reduce((acc, [key, value]) => {
103
- acc[key] = value.package.manifest;
104
- return acc;
105
- }, {})
106
- };
107
- }
108
- throw new Error(`not supported package manager ${type}`);
109
- }
110
3
 
111
4
  var utils$1 = {};
112
5
 
@@ -4214,633 +4107,4 @@ function requireMicromatch () {
4214
4107
 
4215
4108
  var micromatchExports = requireMicromatch();
4216
4109
 
4217
- const intersection = (a, b) => new Set([...a].filter((i) => b.has(i)));
4218
- const {
4219
- JIEK_OUT_DIR,
4220
- JIEK_CROSS_MODULE_CONVERTOR
4221
- } = process$1.env;
4222
- const OUTDIR = JIEK_OUT_DIR ?? "dist";
4223
- const crossModuleConvertorDefault = JIEK_CROSS_MODULE_CONVERTOR === void 0 ? true : JIEK_CROSS_MODULE_CONVERTOR === "true";
4224
- function getOutDirs({
4225
- cwd = process$1.cwd(),
4226
- defaultOutdir = OUTDIR,
4227
- config,
4228
- pkgName
4229
- }) {
4230
- const { build = {} } = config ?? {};
4231
- const outdir = build?.output?.dir;
4232
- function resolveOutdir(type) {
4233
- const dir = (typeof outdir === "object" ? outdir[type] ?? outdir[{
4234
- js: "dts",
4235
- dts: "js"
4236
- }[type]] : outdir) ?? defaultOutdir;
4237
- return (isAbsolute(dir) ? dir : `./${relative(cwd, resolve(cwd, dir))}`).replace("{{PKG_NAME}}", pkgName);
4238
- }
4239
- return {
4240
- js: resolveOutdir("js"),
4241
- dts: resolveOutdir("dts")
4242
- };
4243
- }
4244
- function getExports({
4245
- entrypoints,
4246
- pkgName,
4247
- pkgIsModule,
4248
- entries,
4249
- config,
4250
- dir,
4251
- defaultOutdir = OUTDIR,
4252
- // FIXME dts support
4253
- outdir = getOutDirs({ pkgName, defaultOutdir, config, cwd: dir }).js,
4254
- noFilter,
4255
- isPublish
4256
- }) {
4257
- const {
4258
- build = {},
4259
- publish: {
4260
- withSuffix = false,
4261
- withSource = true
4262
- } = {}
4263
- } = config ?? {};
4264
- const {
4265
- crossModuleConvertor = crossModuleConvertorDefault
4266
- } = build;
4267
- const [, resolvedEntrypoints] = resolveEntrypoints(entrypoints);
4268
- if (entries) {
4269
- Object.entries(resolvedEntrypoints).forEach(([key]) => {
4270
- if (!entries.some((e) => micromatchExports.isMatch(key, e, { matchBase: true }))) {
4271
- delete resolvedEntrypoints[key];
4272
- }
4273
- });
4274
- }
4275
- const filteredResolvedEntrypoints = noFilter ? resolvedEntrypoints : filterLeafs(
4276
- resolvedEntrypoints,
4277
- {
4278
- skipValue: [
4279
- // ignore values that filename starts with `.jk-noentry`
4280
- /(^|\/)\.jk-noentry/,
4281
- ...DEFAULT_SKIP_VALUES
4282
- ]
4283
- }
4284
- );
4285
- const crossModuleWithConditional = crossModuleConvertor ? {
4286
- import: (opts) => {
4287
- if (pkgIsModule) return false;
4288
- if (opts.src.endsWith(".cts")) return false;
4289
- if (intersection(
4290
- new Set(opts.conditionals),
4291
- /* @__PURE__ */ new Set(["import", "module"])
4292
- ).size !== 0) return false;
4293
- return opts.dist.replace(/\.js$/, ".mjs");
4294
- },
4295
- require: (opts) => {
4296
- if (!pkgIsModule) return false;
4297
- if (opts.src.endsWith(".mts")) return false;
4298
- if (intersection(
4299
- new Set(opts.conditionals),
4300
- /* @__PURE__ */ new Set(["require", "node"])
4301
- ).size !== 0) return false;
4302
- return opts.dist.replace(/\.js$/, ".cjs");
4303
- }
4304
- } : {};
4305
- return [
4306
- filteredResolvedEntrypoints,
4307
- entrypoints2Exports(filteredResolvedEntrypoints, {
4308
- outdir,
4309
- sourceTag: pkgName,
4310
- withSuffix: isPublish ? withSuffix : void 0,
4311
- withSource: isPublish ? withSource : void 0,
4312
- withConditional: {
4313
- ...crossModuleWithConditional
4314
- }
4315
- }),
4316
- outdir
4317
- ];
4318
- }
4319
-
4320
- function packageIsExist(name) {
4321
- try {
4322
- require.resolve(name);
4323
- return true;
4324
- } catch (e) {
4325
- return false;
4326
- }
4327
- }
4328
- let tsRegisterName;
4329
- const registers = [
4330
- process.env.JIEK_TS_REGISTER,
4331
- "esbuild-register",
4332
- "@swc-node/register",
4333
- "ts-node/register"
4334
- ].filter(Boolean);
4335
- for (const register of registers) {
4336
- if (packageIsExist(register)) {
4337
- tsRegisterName = register;
4338
- break;
4339
- }
4340
- }
4341
-
4342
- let configName = "jiek.config";
4343
- function getConfigPath(root, dir) {
4344
- const isSupportTsLoader = !!tsRegisterName;
4345
- function configWithExtIsExist(ext) {
4346
- const filenames = [
4347
- path.resolve(process.cwd(), `${configName}.${ext}`),
4348
- path.resolve(process.cwd(), `.${configName}.${ext}`),
4349
- path.resolve(root, `${configName}.${ext}`),
4350
- path.resolve(root, `.${configName}.${ext}`)
4351
- ];
4352
- if (dir) {
4353
- filenames.unshift(...[
4354
- path.resolve(dir, `${configName}.${ext}`),
4355
- path.resolve(dir, `.${configName}.${ext}`)
4356
- ]);
4357
- }
4358
- for (const filename of filenames) {
4359
- if (fs.existsSync(filename) && fs.lstatSync(filename).isFile()) {
4360
- return filename;
4361
- }
4362
- }
4363
- return;
4364
- }
4365
- configName = configWithExtIsExist("js") ?? configName;
4366
- configName = configWithExtIsExist("json") ?? configName;
4367
- configName = configWithExtIsExist("yaml") ?? configName;
4368
- if (isSupportTsLoader) {
4369
- configName = configWithExtIsExist("ts") ?? configName;
4370
- }
4371
- return path.resolve(root, configName);
4372
- }
4373
- function loadConfig(dirOrOptions) {
4374
- let dir;
4375
- let root;
4376
- if (typeof dirOrOptions === "object") {
4377
- dir = dirOrOptions.dir;
4378
- root = dirOrOptions.root ?? getWD().wd;
4379
- } else {
4380
- dir = dirOrOptions;
4381
- root = getWD().wd;
4382
- }
4383
- let configPath = program.getOptionValue("configPath");
4384
- if (!configPath) {
4385
- configPath = getConfigPath(root, dir);
4386
- } else {
4387
- if (!fs.existsSync(configPath)) {
4388
- throw new Error(`config file not found: ${configPath}`);
4389
- }
4390
- if (!path.isAbsolute(configPath)) {
4391
- configPath = path.resolve(root, configPath);
4392
- }
4393
- }
4394
- const ext = path.extname(configPath);
4395
- let module;
4396
- switch (ext) {
4397
- case ".js":
4398
- module = require(configPath);
4399
- break;
4400
- case ".json":
4401
- return require(configPath);
4402
- case ".yaml":
4403
- return load(fs.readFileSync(configPath, "utf-8"));
4404
- case ".ts":
4405
- if (tsRegisterName) {
4406
- require(tsRegisterName);
4407
- module = require(configPath);
4408
- break;
4409
- }
4410
- throw new Error(
4411
- "ts config file is not supported without ts register, please install esbuild-register or set JIEK_TS_REGISTER env for custom ts register"
4412
- );
4413
- case ".config":
4414
- module = {};
4415
- break;
4416
- default:
4417
- throw new Error(`unsupported config file type: ${ext}`);
4418
- }
4419
- if (!module) throw new Error("config file is empty");
4420
- return module.default ?? module;
4421
- }
4422
-
4423
- const outdirDescription = `
4424
- The output directory of the build, which relative to the target subpackage root directory.
4425
- Support with variables: 'PKG_NAME',
4426
- .e.g. 'dist/{{PKG_NAME}}'.
4427
- `.trim();
4428
-
4429
- const description = `
4430
- Publish package to npm registry, and auto generate exports field and other fields in published package.json.
4431
- If you want to through the options to the \`pnpm publish\` command, you can pass the options after '--'.
4432
- `.trim();
4433
- async function forEachSelectedProjectsGraphEntries(callback) {
4434
- const { value = {} } = await getSelectedProjectsGraph() ?? {};
4435
- const selectedProjectsGraphEntries = Object.entries(value);
4436
- if (selectedProjectsGraphEntries.length === 0) {
4437
- throw new Error("no packages selected");
4438
- }
4439
- for (const [dir, manifest] of selectedProjectsGraphEntries) {
4440
- callback(dir, manifest);
4441
- }
4442
- }
4443
- 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 }) => {
4444
- let shouldPassThrough = false;
4445
- const passThroughOptions = process$1.argv.reduce(
4446
- (acc, value) => {
4447
- if (shouldPassThrough) {
4448
- acc.push(value);
4449
- }
4450
- if (value === "--") {
4451
- shouldPassThrough = true;
4452
- }
4453
- return acc;
4454
- },
4455
- []
4456
- );
4457
- await forEachSelectedProjectsGraphEntries((dir) => {
4458
- const args = ["pnpm", "publish", "--access", "public", "--no-git-checks"];
4459
- if (bumper && TAGS.includes(bumper)) {
4460
- args.push("--tag", bumper);
4461
- }
4462
- args.push(...passThroughOptions);
4463
- childProcess.execSync(args.join(" "), {
4464
- cwd: dir,
4465
- stdio: "inherit",
4466
- env: {
4467
- ...process$1.env,
4468
- JIEK_PUBLISH_OUTDIR: JSON.stringify(outdir),
4469
- JIEK_PUBLISH_BUMPER: JSON.stringify(bumper)
4470
- }
4471
- });
4472
- });
4473
- });
4474
- async function prepublish({ bumper } = {}) {
4475
- const {
4476
- JIEK_PUBLISH_OUTDIR: outdirEnv,
4477
- JIEK_PUBLISH_BUMPER: bumperEnv
4478
- } = process$1.env;
4479
- const outdir = outdirEnv ? JSON.parse(outdirEnv) : "dist";
4480
- bumper = bumper ?? (bumperEnv ? JSON.parse(bumperEnv) : false);
4481
- const generateNewManifest = (dir, manifest) => {
4482
- const { name, type, exports: entrypoints = {} } = manifest;
4483
- if (!name) {
4484
- throw new Error(`package.json in ${dir} must have a name field`);
4485
- }
4486
- const pkgIsModule = type === "module";
4487
- const newManifest = { ...manifest };
4488
- const [resolvedEntrypoints, exports, resolvedOutdir] = getExports({
4489
- entrypoints,
4490
- pkgIsModule,
4491
- pkgName: name,
4492
- config: loadConfig(dir),
4493
- dir,
4494
- defaultOutdir: outdir,
4495
- noFilter: true,
4496
- isPublish: true
4497
- });
4498
- newManifest.exports = {
4499
- ...resolvedEntrypoints,
4500
- ...exports
4501
- };
4502
- return [newManifest, resolvedOutdir];
4503
- };
4504
- const generateNewPackageJSONString = ({
4505
- oldJSONString,
4506
- oldJSON,
4507
- manifest,
4508
- formattingOptions
4509
- }) => {
4510
- let newJSONString = oldJSONString;
4511
- newJSONString = applyEdits(
4512
- newJSONString,
4513
- modify(
4514
- newJSONString,
4515
- ["publishConfig", "typesVersions"],
4516
- {
4517
- "<5.0": {
4518
- "*": [
4519
- "*",
4520
- `./*`,
4521
- `./*/index.d.ts`,
4522
- `./*/index.d.mts`,
4523
- `./*/index.d.cts`
4524
- ]
4525
- }
4526
- },
4527
- { formattingOptions }
4528
- )
4529
- );
4530
- for (const [key, value] of Object.entries(manifest)) {
4531
- if (key === "version") continue;
4532
- if (JSON.stringify(value) === JSON.stringify(oldJSON[key])) continue;
4533
- if (key !== "exports") {
4534
- newJSONString = applyEdits(
4535
- newJSONString,
4536
- modify(
4537
- newJSONString,
4538
- ["publishConfig", key],
4539
- value,
4540
- { formattingOptions }
4541
- )
4542
- );
4543
- } else {
4544
- const exports = value;
4545
- for (const [k, v] of Object.entries(exports)) {
4546
- newJSONString = applyEdits(
4547
- newJSONString,
4548
- modify(
4549
- newJSONString,
4550
- ["publishConfig", "exports", k],
4551
- v,
4552
- { formattingOptions }
4553
- )
4554
- );
4555
- }
4556
- const index = exports?.["."];
4557
- const indexPublishConfig = {};
4558
- if (index) {
4559
- switch (typeof index) {
4560
- case "string":
4561
- indexPublishConfig[manifest?.type === "module" ? "module" : "main"] = index;
4562
- break;
4563
- case "object": {
4564
- const indexExports = index;
4565
- indexPublishConfig.main = indexExports.require ?? indexExports.default;
4566
- indexPublishConfig.module = indexExports.import ?? indexExports.module ?? indexExports.default;
4567
- indexPublishConfig.types = indexExports.types;
4568
- break;
4569
- }
4570
- }
4571
- indexPublishConfig.types = indexPublishConfig[manifest?.type === "module" ? "module" : "main"].replace(/\.([cm]?)js$/, ".d.$1ts");
4572
- for (const [k, v] of Object.entries(indexPublishConfig)) {
4573
- if (v === void 0) continue;
4574
- newJSONString = applyEdits(
4575
- newJSONString,
4576
- modify(
4577
- newJSONString,
4578
- ["publishConfig", k],
4579
- v,
4580
- { formattingOptions }
4581
- )
4582
- );
4583
- }
4584
- }
4585
- }
4586
- }
4587
- if (oldJSON.devDependencies) {
4588
- newJSONString = applyEdits(
4589
- newJSONString,
4590
- modify(
4591
- newJSONString,
4592
- ["devDependencies"],
4593
- void 0,
4594
- { formattingOptions }
4595
- )
4596
- );
4597
- }
4598
- if (oldJSON.peerDependencies) {
4599
- const peerDependenciesMeta = Object.keys(oldJSON.peerDependencies).reduce(
4600
- (acc, key) => {
4601
- acc[key] = { optional: true };
4602
- return acc;
4603
- },
4604
- {}
4605
- );
4606
- newJSONString = applyEdits(
4607
- newJSONString,
4608
- modify(
4609
- newJSONString,
4610
- ["peerDependenciesMeta"],
4611
- peerDependenciesMeta,
4612
- { formattingOptions }
4613
- )
4614
- );
4615
- }
4616
- if (oldJSON.files) {
4617
- newJSONString = applyEdits(
4618
- newJSONString,
4619
- modify(
4620
- newJSONString,
4621
- ["files"],
4622
- void 0,
4623
- { formattingOptions }
4624
- )
4625
- );
4626
- }
4627
- return newJSONString;
4628
- };
4629
- await forEachSelectedProjectsGraphEntries((dir, originalManifest) => {
4630
- const [manifest, resolvedOutdir] = generateNewManifest(dir, originalManifest);
4631
- const resolveByDir = (...paths) => path.resolve(dir, ...paths);
4632
- const oldJSONString = fs.readFileSync(resolveByDir("package.json"), "utf-8");
4633
- const oldJSON = JSON.parse(oldJSONString);
4634
- if (typeof oldJSON.version !== "string") {
4635
- throw new TypeError(`${dir}/package.json must have a version field with a string value`);
4636
- }
4637
- const { indent = " " } = detectIndent(oldJSONString);
4638
- const formattingOptions = {
4639
- tabSize: indent.length,
4640
- insertSpaces: true
4641
- };
4642
- const newVersion = bumper ? bump(oldJSON.version, bumper === true ? "patch" : bumper) : oldJSON.version;
4643
- const modifyVersionPackageJSON = applyEdits(
4644
- oldJSONString,
4645
- modify(oldJSONString, ["version"], newVersion, { formattingOptions })
4646
- );
4647
- const newJSONString = generateNewPackageJSONString({
4648
- oldJSONString: modifyVersionPackageJSON,
4649
- oldJSON: {
4650
- ...oldJSON,
4651
- version: newVersion
4652
- },
4653
- manifest,
4654
- formattingOptions
4655
- });
4656
- const withPublishConfigDirectoryOldJSONString = applyEdits(
4657
- modifyVersionPackageJSON,
4658
- modify(modifyVersionPackageJSON, ["publishConfig", "directory"], resolvedOutdir, { formattingOptions })
4659
- );
4660
- if (!fs.existsSync(resolveByDir(resolvedOutdir))) {
4661
- fs.mkdirSync(resolveByDir(resolvedOutdir));
4662
- }
4663
- const jiekTempDir = resolveByDir("node_modules/.jiek/.tmp");
4664
- if (!fs.existsSync(resolveByDir(jiekTempDir))) {
4665
- fs.mkdirSync(resolveByDir(jiekTempDir), { recursive: true });
4666
- }
4667
- fs.writeFileSync(resolveByDir(resolvedOutdir, "package.json"), newJSONString);
4668
- fs.writeFileSync(resolveByDir(jiekTempDir, "package.json"), modifyVersionPackageJSON);
4669
- fs.writeFileSync(resolveByDir("package.json"), withPublishConfigDirectoryOldJSONString);
4670
- const allBuildFiles = fs.readdirSync(resolveByDir(resolvedOutdir), { recursive: true }).filter((file) => typeof file === "string").filter((file) => file !== "package.json");
4671
- const resolvedExports = manifest.exports;
4672
- Object.keys(resolvedExports).forEach((key) => {
4673
- if (key === ".") return;
4674
- if (/\.[cm]?js$/.test(key)) return;
4675
- const resourceFileSuffixes = [
4676
- ".d.ts",
4677
- ".d.mts",
4678
- ".d.cts",
4679
- ".css",
4680
- ".scss",
4681
- ".sass",
4682
- ".less",
4683
- ".styl",
4684
- ".stylus",
4685
- ".json",
4686
- ".json5"
4687
- ];
4688
- if (resourceFileSuffixes.find((suffix) => key.endsWith(suffix))) return;
4689
- const value = resolvedExports[key];
4690
- const filepath = resolveByDir(resolvedOutdir, key);
4691
- fs.mkdirSync(filepath, { recursive: true });
4692
- const pkgJSONPath = resolveByDir(resolvedOutdir, key, "package.json");
4693
- const relativePath = Array.from({ length: key.split("/").length - 1 }, () => "..").join("/");
4694
- const { type } = manifest;
4695
- const pkgJSON = { type };
4696
- if ("default" in value) {
4697
- pkgJSON[type === "module" ? "module" : "main"] = [
4698
- relativePath,
4699
- value.default?.replace(/^\.\//, "")
4700
- ].join("/");
4701
- }
4702
- if ("import" in value) {
4703
- pkgJSON.module = [
4704
- relativePath,
4705
- value.import?.replace(/^\.\//, "")
4706
- ].join("/");
4707
- }
4708
- if ("require" in value) {
4709
- pkgJSON.main = [
4710
- relativePath,
4711
- value.require?.replace(/^\.\//, "")
4712
- ].join("/");
4713
- }
4714
- fs.writeFileSync(pkgJSONPath, JSON.stringify(pkgJSON));
4715
- });
4716
- fs.mkdirSync(resolveByDir(resolvedOutdir, resolvedOutdir));
4717
- for (const file of allBuildFiles) {
4718
- const filepath = resolveByDir(resolvedOutdir, file);
4719
- const newFilepath = resolveByDir(resolvedOutdir, resolvedOutdir, file);
4720
- const stat = fs.statSync(filepath);
4721
- if (stat.isDirectory()) {
4722
- fs.mkdirSync(newFilepath, { recursive: true });
4723
- continue;
4724
- }
4725
- if (stat.isFile()) {
4726
- fs.cpSync(filepath, newFilepath);
4727
- fs.rmSync(filepath);
4728
- }
4729
- }
4730
- if (oldJSON.files) {
4731
- if (Array.isArray(oldJSON.files)) {
4732
- if (oldJSON.files.every((file) => typeof file !== "string")) {
4733
- throw new TypeError(`${dir}/package.json files field must be an array of string`);
4734
- }
4735
- } else {
4736
- throw new TypeError(`${dir}/package.json files field must be an array`);
4737
- }
4738
- }
4739
- const resolvedOutdirAbs = resolveByDir(resolvedOutdir);
4740
- const files = (oldJSON.files ?? fs.readdirSync(resolveByDir("."))).filter(
4741
- (file) => ![
4742
- "node_modules",
4743
- "package.json",
4744
- "pnpm-lock.yaml"
4745
- ].includes(file) && resolveByDir(file) !== resolvedOutdirAbs
4746
- );
4747
- for (const file of files) {
4748
- const path2 = resolveByDir(file);
4749
- try {
4750
- const stat = fs.statSync(path2);
4751
- if (stat.isDirectory()) {
4752
- fs.cpSync(path2, resolveByDir(resolvedOutdir, file), { recursive: true });
4753
- continue;
4754
- }
4755
- if (stat.isFile()) {
4756
- fs.cpSync(path2, resolveByDir(resolvedOutdir, file));
4757
- continue;
4758
- }
4759
- } catch (e) {
4760
- console.warn(String(e));
4761
- continue;
4762
- }
4763
- throw new Error(`file type of ${path2} is not supported`);
4764
- }
4765
- });
4766
- }
4767
- async function postpublish() {
4768
- await forEachSelectedProjectsGraphEntries((dir) => {
4769
- const jiekTempDir = path.resolve(dir, "node_modules/.jiek/.tmp");
4770
- const packageJSONPath = path.resolve(dir, "package.json");
4771
- const { name, version } = JSON.parse(fs.readFileSync(packageJSONPath, "utf-8"));
4772
- const jiekTempPackageJSONPath = path.resolve(jiekTempDir, "package.json");
4773
- if (fs.existsSync(jiekTempPackageJSONPath)) {
4774
- fs.copyFileSync(jiekTempPackageJSONPath, packageJSONPath);
4775
- fs.rmSync(jiekTempPackageJSONPath);
4776
- console.log(`${dir}/package.json has been restored`);
4777
- console.log(
4778
- `if you want to check the compatibility of the package, you can visit: https://arethetypeswrong.github.io/?p=${name}%40${version}`
4779
- );
4780
- } else {
4781
- throw new Error(
4782
- `jiek temp \`${dir}/package.json\` not found, please confirm the jiek pre-publish command has been executed`
4783
- );
4784
- }
4785
- });
4786
- }
4787
- program.action(async () => {
4788
- const {
4789
- npm_lifecycle_event: NPM_LIFECYCLE_EVENT
4790
- } = process$1.env;
4791
- switch (NPM_LIFECYCLE_EVENT) {
4792
- case "prepublish":
4793
- await prepublish();
4794
- break;
4795
- case "postpublish":
4796
- await postpublish();
4797
- break;
4798
- default:
4799
- program.help();
4800
- }
4801
- });
4802
- const prepublishDescription = `
4803
- Prepare package.json for publish, you can add \`jk\` to the \`prepublish\` script in package.json, the command will automatically run \`jk prepublish\`.
4804
- .e.g
4805
- {
4806
- "scripts": {
4807
- "prepublish": "jk"
4808
- }
4809
- }
4810
- `.trim();
4811
- program.command("prepublish").description(prepublishDescription).option("-b, --bumper <bumper>", "bump version").option("-no-b, --no-bumper", "no bump version").action(prepublish);
4812
- const postpublishDescription = `
4813
- Restore package.json after publish, you can add \`jk\` to the \`postpublish\` script in package.json, the command will automatically run \`jk postpublish\`.
4814
- .e.g
4815
- {
4816
- "scripts": {
4817
- "postpublish": "jk"
4818
- }
4819
- }
4820
- `.trim();
4821
- program.command("postpublish").description(postpublishDescription).action(postpublish);
4822
-
4823
- const { argv } = process$1;
4824
- const env = {};
4825
- let isPassThrough = false;
4826
- const newArgv = argv.filter((arg) => {
4827
- if (isPassThrough) {
4828
- return true;
4829
- }
4830
- if (arg === "--") {
4831
- isPassThrough = true;
4832
- return false;
4833
- }
4834
- const m = /^--env\.(\w+)=(.*)$/.exec(arg);
4835
- if (m) {
4836
- env[m[1]] = m[2];
4837
- return false;
4838
- }
4839
- return true;
4840
- });
4841
- for (const [key, value] of Object.entries(env)) {
4842
- process$1.env[key] = value;
4843
- }
4844
- var parseArgv = () => program.parse(newArgv);
4845
-
4846
- parseArgv();
4110
+ export { micromatchExports as m };