zshy 0.2.5 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -73,7 +73,6 @@ Examples:
73
73
  const isVerbose = !!args["--verbose"];
74
74
  const isDryRun = !!args["--dry-run"];
75
75
  const failThreshold = args["--fail-threshold"] || "error"; // Default to 'error'
76
- const dryRunPrefix = isDryRun ? "[dryrun] " : "";
77
76
  const isCjsInterop = true; // Enable CJS interop for testing
78
77
  // Validate that the threshold value is one of the allowed values
79
78
  if (failThreshold !== "never" && failThreshold !== "warn" && failThreshold !== "error") {
@@ -141,35 +140,35 @@ Examples:
141
140
  /////////////////////////////////
142
141
  // const pkgJson = JSON.parse(fs.readFileSync("./package.json", "utf-8"));
143
142
  const CONFIG_KEY = "zshy";
144
- let config;
143
+ let rawConfig;
145
144
  if (!pkgJson[CONFIG_KEY]) {
146
145
  emojiLog("❌", `No "${CONFIG_KEY}" key found in package.json`, "error");
147
146
  process.exit(1);
148
147
  }
149
148
  if (typeof pkgJson[CONFIG_KEY] === "string") {
150
- config = {
149
+ rawConfig = {
151
150
  exports: { ".": pkgJson[CONFIG_KEY] },
152
151
  };
153
152
  }
154
153
  else if (typeof pkgJson[CONFIG_KEY] === "object") {
155
- config = { ...pkgJson[CONFIG_KEY] };
156
- if (typeof config.exports === "string") {
157
- config.exports = { ".": config.exports };
154
+ rawConfig = { ...pkgJson[CONFIG_KEY] };
155
+ if (typeof rawConfig.exports === "string") {
156
+ rawConfig.exports = { ".": rawConfig.exports };
158
157
  }
159
- else if (typeof config.exports === "undefined") {
158
+ else if (typeof rawConfig.exports === "undefined") {
160
159
  emojiLog("❌", `Missing "exports" key in package.json#/${CONFIG_KEY}`, "error");
161
160
  process.exit(1);
162
161
  }
163
- else if (typeof config.exports !== "object") {
162
+ else if (typeof rawConfig.exports !== "object") {
164
163
  emojiLog("❌", `Invalid "exports" key in package.json#/${CONFIG_KEY}`, "error");
165
164
  process.exit(1);
166
165
  }
167
166
  // Validate bin field if present
168
- if (config.bin !== undefined) {
169
- if (typeof config.bin === "string") {
167
+ if (rawConfig.bin !== undefined) {
168
+ if (typeof rawConfig.bin === "string") {
170
169
  // Keep string format - we'll handle this in entry point extraction
171
170
  }
172
- else if (typeof config.bin === "object" && config.bin !== null) {
171
+ else if (typeof rawConfig.bin === "object" && rawConfig.bin !== null) {
173
172
  // Object format is valid
174
173
  }
175
174
  else {
@@ -177,9 +176,22 @@ Examples:
177
176
  process.exit(1);
178
177
  }
179
178
  }
180
- // {
181
- // exports: { ".": pkgJson[CONFIG_KEY].exports },
182
- // };
179
+ // Validate conditions field if present
180
+ if (rawConfig.conditions !== undefined) {
181
+ if (typeof rawConfig.conditions === "object" && rawConfig.conditions !== null) {
182
+ // const { import: importCondition, require: requireCondition, ...rest } = config.conditions;
183
+ for (const [condition, value] of Object.entries(rawConfig.conditions)) {
184
+ if (value !== "esm" && value !== "cjs" && value !== "src") {
185
+ emojiLog("❌", `Invalid condition value "${value}" for "${condition}" in package.json#/${CONFIG_KEY}/conditions. Valid values are "esm", "cjs", "src", or null`, "error");
186
+ process.exit(1);
187
+ }
188
+ }
189
+ }
190
+ else {
191
+ emojiLog("❌", `Invalid "conditions" key in package.json#/${CONFIG_KEY}, expected object`, "error");
192
+ process.exit(1);
193
+ }
194
+ }
183
195
  }
184
196
  else if (typeof pkgJson[CONFIG_KEY] === "undefined") {
185
197
  emojiLog("❌", `Missing "${CONFIG_KEY}" key in package.json`, "error");
@@ -190,7 +202,32 @@ Examples:
190
202
  process.exit(1);
191
203
  }
192
204
  if (isVerbose) {
193
- emojiLog("🔧", `Parsed zshy config: ${formatForLog(config)}`);
205
+ emojiLog("🔧", `Parsed zshy config: ${formatForLog(rawConfig)}`);
206
+ }
207
+ // Check for deprecated sourceDialects
208
+ if ("sourceDialects" in rawConfig) {
209
+ emojiLog("❌", 'The "sourceDialects" option is no longer supported. Use "conditions" instead to configure custom export conditions.', "error");
210
+ process.exit(1);
211
+ }
212
+ const config = { ...rawConfig };
213
+ // Normalize cjs property
214
+ if (config.cjs === undefined) {
215
+ config.cjs = true; // Default to true if not specified
216
+ }
217
+ config.noEdit ?? (config.noEdit = false);
218
+ // Validate that if cjs is disabled, no conditions are set to "cjs"
219
+ if (config.cjs === false && config.conditions) {
220
+ const cjsConditions = Object.entries(config.conditions).filter(([_, value]) => value === "cjs");
221
+ if (cjsConditions.length > 0) {
222
+ const conditionNames = cjsConditions.map(([name]) => name).join(", ");
223
+ emojiLog("❌", `CJS is disabled (cjs: false) but the following conditions are set to "cjs": ${conditionNames}. Either enable CJS or change these conditions.`, "error");
224
+ process.exit(1);
225
+ }
226
+ }
227
+ // Validate that if cjs is disabled, package.json type must be "module"
228
+ if (config.cjs === false && pkgJson.type !== "module") {
229
+ emojiLog("❌", `CJS is disabled (cjs: false) but package.json#/type is not set to "module". When disabling CommonJS builds, you must set "type": "module" in your package.json.`, "error");
230
+ process.exit(1);
194
231
  }
195
232
  ///////////////////////////
196
233
  /// read tsconfig ///
@@ -301,7 +338,7 @@ Examples:
301
338
  emojiLog("➡️", "Determining entrypoints...");
302
339
  const entryPoints = [];
303
340
  const rows = [["Subpath", "Entrypoint"]];
304
- for (const [exportPath, sourcePath] of Object.entries(config.exports)) {
341
+ for (const [exportPath, sourcePath] of Object.entries(config.exports ?? {})) {
305
342
  if (exportPath.includes("package.json"))
306
343
  continue;
307
344
  let cleanExportPath;
@@ -387,7 +424,7 @@ Examples:
387
424
  // process.exit(1);
388
425
  // }
389
426
  if (entryPoints.length === 0) {
390
- emojiLog("❌", "No entry points found matching the specified patterns in package.json#/zshy exports", "error");
427
+ emojiLog("❌", "No entry points found matching the specified patterns in package.json#/zshy exports or bin", "error");
391
428
  process.exit(1);
392
429
  }
393
430
  ///////////////////////////////
@@ -449,13 +486,14 @@ Examples:
449
486
  //////////////////////////////////////////////
450
487
  /// clean up outDir and declarationDir ///
451
488
  //////////////////////////////////////////////
489
+ const prefix = isDryRun ? "[dryrun] " : "";
452
490
  if (relRootDir.startsWith(relOutDir)) {
453
- emojiLog("🗑️", `${dryRunPrefix}Skipping cleanup of outDir as it contains source files`);
491
+ emojiLog("🗑️", `${prefix}Skipping cleanup of outDir as it contains source files`);
454
492
  }
455
493
  else {
456
494
  // source files are in the outDir, so skip cleanup
457
495
  // clean up outDir and declarationDir
458
- emojiLog("🗑️", `${dryRunPrefix}Cleaning up outDir...`);
496
+ emojiLog("🗑️", `${prefix}Cleaning up outDir...`);
459
497
  if (!isDryRun) {
460
498
  fs.rmSync(outDir, { recursive: true, force: true });
461
499
  // // print success message in verbose mode
@@ -470,10 +508,10 @@ Examples:
470
508
  // already done
471
509
  }
472
510
  else if (relRootDir.startsWith(relDeclarationDir)) {
473
- emojiLog("🗑️", `${dryRunPrefix}Skipping cleanup of declarationDir as it contains source files`);
511
+ emojiLog("🗑️", `${prefix}Skipping cleanup of declarationDir as it contains source files`);
474
512
  }
475
513
  else {
476
- emojiLog("🗑️", `${dryRunPrefix}Cleaning up declarationDir...`);
514
+ emojiLog("🗑️", `${prefix}Cleaning up declarationDir...`);
477
515
  if (!isDryRun) {
478
516
  fs.rmSync(declarationDir, { recursive: true, force: true });
479
517
  // // print success message in verbose mode
@@ -488,24 +526,27 @@ Examples:
488
526
  /// compile tsc ///
489
527
  ///////////////////////////////
490
528
  const uniqueEntryPoints = [...new Set(entryPoints)];
491
- try {
492
- if (isVerbose) {
493
- emojiLog("→", `Resolved entrypoints: ${formatForLog(uniqueEntryPoints)}`);
494
- emojiLog("→", `Resolved compilerOptions: ${formatForLog({
495
- ...tsconfigJson,
496
- module: ts.ModuleKind[tsconfigJson.module],
497
- moduleResolution: ts.ModuleResolutionKind[tsconfigJson.moduleResolution],
498
- target: ts.ScriptTarget[tsconfigJson.target],
499
- })}`);
500
- }
501
- // Create a build context to track written files, copied assets, and compilation errors/warnings
502
- const buildContext = {
503
- writtenFiles: new Set(),
504
- copiedAssets: new Set(),
505
- errorCount: 0,
506
- warningCount: 0,
507
- };
508
- // CJS
529
+ // try {
530
+ if (isVerbose) {
531
+ emojiLog("→", `Resolved entrypoints: ${formatForLog(uniqueEntryPoints)}`);
532
+ emojiLog("→", `Resolved compilerOptions: ${formatForLog({
533
+ ...tsconfigJson,
534
+ module: ts.ModuleKind[tsconfigJson.module],
535
+ moduleResolution: ts.ModuleResolutionKind[tsconfigJson.moduleResolution],
536
+ target: ts.ScriptTarget[tsconfigJson.target],
537
+ })}`);
538
+ }
539
+ // Create a build context to track written files, copied assets, and compilation errors/warnings
540
+ const buildContext = {
541
+ writtenFiles: new Set(),
542
+ copiedAssets: new Set(),
543
+ errorCount: 0,
544
+ warningCount: 0,
545
+ };
546
+ // Check if CJS should be skipped
547
+ const skipCjs = config.cjs === false;
548
+ // CJS
549
+ if (!skipCjs) {
509
550
  emojiLog("🧱", `Building CJS...${isTypeModule ? ` (rewriting .ts -> .cjs/.d.cts)` : ``}`);
510
551
  await compileProject({
511
552
  configPath: tsconfigPath,
@@ -523,124 +564,167 @@ Examples:
523
564
  outDir,
524
565
  },
525
566
  }, uniqueEntryPoints, buildContext);
526
- // ESM
527
- emojiLog("🧱", `Building ESM...${isTypeModule ? `` : ` (rewriting .ts -> .mjs/.d.mts)`}`);
528
- await compileProject({
529
- configPath: tsconfigPath,
530
- ext: isTypeModule ? "js" : "mjs",
531
- format: "esm",
532
- verbose: isVerbose,
533
- dryRun: isDryRun,
534
- pkgJsonDir,
535
- rootDir,
536
- cjsInterop: isCjsInterop,
537
- compilerOptions: {
538
- ...tsconfigJson,
539
- module: ts.ModuleKind.ESNext,
540
- moduleResolution: ts.ModuleResolutionKind.Bundler,
541
- outDir,
542
- },
543
- }, uniqueEntryPoints, buildContext);
544
- ///////////////////////////////////
545
- /// display written files ///
546
- ///////////////////////////////////
547
- // Display files that were written or would be written (only in verbose mode)
548
- if (isVerbose && buildContext.writtenFiles.size > 0) {
549
- emojiLog("📜", `${dryRunPrefix}Writing files (${buildContext.writtenFiles.size} total)...`);
550
- // Sort files by relative path for consistent display
551
- const sortedFiles = [...buildContext.writtenFiles]
552
- .map((file) => relativePosix(pkgJsonDir, file))
553
- .sort()
554
- .map((relPath) => (relPath.startsWith(".") ? relPath : `./${relPath}`));
555
- sortedFiles.forEach((file) => {
556
- console.log(` ${file}`);
557
- });
558
- }
559
- ///////////////////////////////
560
- /// generate exports ///
561
- ///////////////////////////////
562
- // generate package.json exports
563
- emojiLog("📦", `${dryRunPrefix}Updating package.json#/exports...`);
567
+ }
568
+ else {
569
+ emojiLog("⏭️", "Skipping CJS build (cjs: false)");
570
+ }
571
+ // ESM
572
+ emojiLog("🧱", `Building ESM...${isTypeModule ? `` : ` (rewriting .ts -> .mjs/.d.mts)`}`);
573
+ await compileProject({
574
+ configPath: tsconfigPath,
575
+ ext: isTypeModule ? "js" : "mjs",
576
+ format: "esm",
577
+ verbose: isVerbose,
578
+ dryRun: isDryRun,
579
+ pkgJsonDir,
580
+ rootDir,
581
+ cjsInterop: isCjsInterop,
582
+ compilerOptions: {
583
+ ...tsconfigJson,
584
+ module: ts.ModuleKind.ESNext,
585
+ moduleResolution: ts.ModuleResolutionKind.Bundler,
586
+ outDir,
587
+ },
588
+ }, uniqueEntryPoints, buildContext);
589
+ ///////////////////////////////////
590
+ /// display written files ///
591
+ ///////////////////////////////////
592
+ // Display files that were written or would be written (only in verbose mode)
593
+ if (isVerbose && buildContext.writtenFiles.size > 0) {
594
+ emojiLog("📜", `${prefix}Writing files (${buildContext.writtenFiles.size} total)...`);
595
+ // Sort files by relative path for consistent display
596
+ const sortedFiles = [...buildContext.writtenFiles]
597
+ .map((file) => relativePosix(pkgJsonDir, file))
598
+ .sort()
599
+ .map((relPath) => (relPath.startsWith(".") ? relPath : `./${relPath}`));
600
+ sortedFiles.forEach((file) => {
601
+ console.log(` ${file}`);
602
+ });
603
+ }
604
+ ///////////////////////////////
605
+ /// generate exports ///
606
+ ///////////////////////////////
607
+ // generate package.json exports
608
+ if (config.noEdit) {
609
+ emojiLog("📦", "[noedit] Skipping modification of package.json");
610
+ }
611
+ else {
564
612
  // Generate exports based on zshy config
613
+ emojiLog("📦", `${prefix}Updating package.json...`);
565
614
  const newExports = {};
566
- const sourceDialects = config.sourceDialects || [];
567
- for (const [exportPath, sourcePath] of Object.entries(config.exports)) {
568
- if (exportPath.includes("package.json")) {
569
- newExports[exportPath] = sourcePath;
570
- continue;
571
- }
572
- const absSourcePath = path.resolve(pkgJsonDir, sourcePath);
573
- const relSourcePath = path.relative(rootDir, absSourcePath);
574
- const absJsPath = path.resolve(outDir, relSourcePath);
575
- const absDtsPath = path.resolve(declarationDir, relSourcePath);
576
- let relJsPath = "./" + relativePosix(pkgJsonDir, absJsPath);
577
- let relDtsPath = "./" + relativePosix(pkgJsonDir, absDtsPath);
578
- if (typeof sourcePath === "string") {
579
- if (sourcePath.endsWith("/*") || sourcePath.endsWith("/**/*")) {
580
- // Handle wildcard exports
581
- const finalExportPath = exportPath;
582
- if (finalExportPath.includes("**")) {
583
- emojiLog("❌", `Export keys cannot contain "**": ${finalExportPath}`, "error");
584
- process.exit(1);
585
- }
586
- // Convert deep glob patterns to simple wildcard patterns in the final export
587
- if (sourcePath.endsWith("/**/*")) {
588
- // Also convert the output paths from /**/* to /*
589
- if (relJsPath.endsWith("/**/*")) {
590
- relJsPath = relJsPath.slice(0, -5) + "/*";
615
+ if (config.exports) {
616
+ for (const [exportPath, sourcePath] of Object.entries(config.exports)) {
617
+ if (exportPath.includes("package.json")) {
618
+ newExports[exportPath] = sourcePath;
619
+ continue;
620
+ }
621
+ const absSourcePath = path.resolve(pkgJsonDir, sourcePath);
622
+ const relSourcePath = path.relative(rootDir, absSourcePath);
623
+ const absJsPath = path.resolve(outDir, relSourcePath);
624
+ const absDtsPath = path.resolve(declarationDir, relSourcePath);
625
+ let relJsPath = "./" + relativePosix(pkgJsonDir, absJsPath);
626
+ let relDtsPath = "./" + relativePosix(pkgJsonDir, absDtsPath);
627
+ if (typeof sourcePath === "string") {
628
+ if (sourcePath.endsWith("/*") || sourcePath.endsWith("/**/*")) {
629
+ // Handle wildcard exports
630
+ const finalExportPath = exportPath;
631
+ if (finalExportPath.includes("**")) {
632
+ emojiLog("❌", `Export keys cannot contain "**": ${finalExportPath}`, "error");
633
+ process.exit(1);
591
634
  }
592
- if (relDtsPath.endsWith("/**/*")) {
593
- relDtsPath = relDtsPath.slice(0, -5) + "/*";
635
+ // Convert deep glob patterns to simple wildcard patterns in the final export
636
+ if (sourcePath.endsWith("/**/*")) {
637
+ // Also convert the output paths from /**/* to /*
638
+ if (relJsPath.endsWith("/**/*")) {
639
+ relJsPath = relJsPath.slice(0, -5) + "/*";
640
+ }
641
+ if (relDtsPath.endsWith("/**/*")) {
642
+ relDtsPath = relDtsPath.slice(0, -5) + "/*";
643
+ }
594
644
  }
645
+ // Build exports object with proper condition ordering
646
+ const exportObj = {};
647
+ // Add custom conditions first in their original order
648
+ if (config.conditions) {
649
+ for (const [condition, value] of Object.entries(config.conditions)) {
650
+ if (value === "src") {
651
+ exportObj[condition] = sourcePath;
652
+ }
653
+ else if (value === "esm") {
654
+ exportObj[condition] = relJsPath;
655
+ }
656
+ else if (value === "cjs") {
657
+ exportObj[condition] = relJsPath;
658
+ }
659
+ }
660
+ }
661
+ // Add standard conditions
662
+ exportObj.types = relDtsPath;
663
+ exportObj.import = relJsPath;
664
+ if (!skipCjs) {
665
+ exportObj.require = relJsPath;
666
+ }
667
+ newExports[finalExportPath] = exportObj;
595
668
  }
596
- newExports[finalExportPath] = {
597
- types: relDtsPath,
598
- import: relJsPath,
599
- require: relJsPath,
600
- };
601
- for (const sd of sourceDialects) {
602
- newExports[finalExportPath] = {
603
- [sd]: sourcePath,
604
- ...newExports[finalExportPath],
605
- };
606
- }
607
- }
608
- else if (isSourceFile(sourcePath)) {
609
- const esmPath = removeExtension(relJsPath) + (isTypeModule ? `.js` : `.mjs`);
610
- const cjsPath = removeExtension(relJsPath) + (isTypeModule ? `.cjs` : `.js`);
611
- const dtsPath = removeExtension(relDtsPath) + (isTypeModule ? `.d.cts` : `.d.ts`);
612
- newExports[exportPath] = {
613
- types: dtsPath,
614
- import: esmPath,
615
- require: cjsPath,
616
- };
617
- if (exportPath === ".") {
618
- pkgJson.main = cjsPath;
619
- pkgJson.module = esmPath;
620
- pkgJson.types = dtsPath;
621
- }
622
- for (const sd of sourceDialects) {
623
- newExports[exportPath] = {
624
- [sd]: sourcePath,
625
- ...newExports[exportPath],
626
- };
669
+ else if (isSourceFile(sourcePath)) {
670
+ const esmPath = removeExtension(relJsPath) + (isTypeModule ? `.js` : `.mjs`);
671
+ const cjsPath = removeExtension(relJsPath) + (isTypeModule ? `.cjs` : `.js`);
672
+ // Use ESM type declarations when CJS is skipped, otherwise use CJS declarations
673
+ const dtsExt = skipCjs ? (isTypeModule ? ".d.ts" : ".d.mts") : isTypeModule ? ".d.cts" : ".d.ts";
674
+ const dtsPath = removeExtension(relDtsPath) + dtsExt;
675
+ // Build exports object with proper condition ordering
676
+ const exportObj = {};
677
+ // Add custom conditions first in their original order
678
+ if (config.conditions) {
679
+ for (const [condition, value] of Object.entries(config.conditions)) {
680
+ if (value === "src") {
681
+ exportObj[condition] = sourcePath;
682
+ }
683
+ else if (value === "esm") {
684
+ exportObj[condition] = esmPath;
685
+ }
686
+ else if (value === "cjs") {
687
+ exportObj[condition] = cjsPath;
688
+ }
689
+ }
690
+ }
691
+ // Add standard conditions
692
+ exportObj.types = dtsPath;
693
+ exportObj.import = esmPath;
694
+ if (!skipCjs) {
695
+ exportObj.require = cjsPath;
696
+ }
697
+ newExports[exportPath] = exportObj;
698
+ if (exportPath === ".") {
699
+ if (!skipCjs) {
700
+ pkgJson.main = cjsPath;
701
+ pkgJson.module = esmPath;
702
+ pkgJson.types = dtsPath;
703
+ }
704
+ else {
705
+ // Only set module and types, not main
706
+ pkgJson.module = esmPath;
707
+ pkgJson.types = dtsPath;
708
+ }
709
+ if (isVerbose) {
710
+ emojiLog("🔧", `Setting "main": ${formatForLog(cjsPath)}`);
711
+ emojiLog("🔧", `Setting "module": ${formatForLog(esmPath)}`);
712
+ emojiLog("🔧", `Setting "types": ${formatForLog(dtsPath)}`);
713
+ }
714
+ }
627
715
  }
628
716
  }
629
- else {
630
- emojiLog("❌", `Invalid entrypoint: ${sourcePath}`, "error");
631
- process.exit();
632
- }
633
717
  }
634
- }
635
- if (isVerbose) {
636
- emojiLog("🔧", `Generated "exports": ${formatForLog(newExports)}`);
718
+ pkgJson.exports = newExports;
719
+ if (isVerbose) {
720
+ emojiLog("🔧", `Setting "exports": ${formatForLog(newExports)}`);
721
+ }
637
722
  }
638
723
  ///////////////////////////////
639
724
  /// generate bin ///
640
725
  ///////////////////////////////
641
726
  // Generate bin field based on zshy bin config
642
727
  if (config.bin) {
643
- emojiLog("📦", `${dryRunPrefix}Updating package.json#/bin...`);
644
728
  const newBin = {};
645
729
  // Convert config.bin to object format for processing
646
730
  const binEntries = typeof config.bin === "string" ? [[pkgJson.name, config.bin]] : Object.entries(config.bin);
@@ -650,8 +734,9 @@ Examples:
650
734
  const relSourcePath = path.relative(rootDir, absSourcePath);
651
735
  const absJsPath = path.resolve(outDir, relSourcePath);
652
736
  const relJsPath = "./" + relativePosix(pkgJsonDir, absJsPath);
653
- // Use CommonJS entrypoint for bin
654
- const binPath = removeExtension(relJsPath) + (isTypeModule ? `.cjs` : `.js`);
737
+ // Use ESM files for bin when CJS is skipped, otherwise use CJS
738
+ const binExt = skipCjs ? (isTypeModule ? ".js" : ".mjs") : isTypeModule ? ".cjs" : ".js";
739
+ const binPath = removeExtension(relJsPath) + binExt;
655
740
  newBin[binName] = binPath;
656
741
  }
657
742
  }
@@ -664,89 +749,83 @@ Examples:
664
749
  pkgJson.bin = newBin;
665
750
  }
666
751
  if (isVerbose) {
667
- emojiLog("🔧", `Generated "bin": ${formatForLog(pkgJson.bin)}`);
752
+ emojiLog("🔧", `Setting "bin": ${formatForLog(pkgJson.bin)}`);
668
753
  }
669
754
  }
670
- ///////////////////////////////
671
- /// write pkg json ///
672
- ///////////////////////////////
673
- // Update package.json with new exports
674
- pkgJson.exports = newExports;
675
755
  if (isDryRun) {
756
+ ///////////////////////////////
757
+ /// write pkg json ///
758
+ ///////////////////////////////
676
759
  emojiLog("📦", "[dryrun] Skipping package.json modification");
677
760
  }
678
761
  else {
679
762
  fs.writeFileSync(packageJsonPath, JSON.stringify(pkgJson, null, indent) + "\n");
680
763
  }
681
- if (isAttw) {
682
- // run `@arethetypeswrong/cli --pack .` to check types
683
- emojiLog("🔍", "Checking types with @arethetypeswrong/cli...");
684
- const { execFile } = await import("node:child_process");
685
- const { promisify } = await import("node:util");
686
- const execFileAsync = promisify(execFile);
687
- const [cmd, ...args] = `${pmExec} @arethetypeswrong/cli --pack ${pkgJsonDir} --format table-flipped`.split(" ");
688
- console.dir([cmd, ...args], { depth: null });
689
- let stdout = "";
690
- let stderr = "";
691
- let exitCode = 0;
692
- try {
693
- const result = await execFileAsync(cmd, args, {
694
- cwd: pkgJsonDir,
695
- encoding: "utf-8",
696
- });
697
- stdout = result.stdout;
698
- stderr = result.stderr;
699
- }
700
- catch (error) {
701
- stdout = error.stdout || "";
702
- stderr = error.stderr || "";
703
- exitCode = error.code || 1;
704
- }
705
- const output = stdout || stderr;
706
- if (output) {
707
- const indentedOutput = output
708
- .split("\n")
709
- .map((line) => ` ${line}`)
710
- .join("\n");
711
- if (exitCode === 0) {
712
- console.log(indentedOutput);
713
- }
714
- else {
715
- console.error(indentedOutput);
716
- emojiLog("⚠️", "ATTW found issues, but the build was not affected.", "warn");
717
- }
718
- }
719
- }
720
- // Report total compilation results
721
- if (buildContext.errorCount > 0 || buildContext.warningCount > 0) {
722
- emojiLog("📊", `Compilation finished with ${buildContext.errorCount} error(s) and ${buildContext.warningCount} warning(s)`);
723
- // Apply threshold rules for exit code
724
- if (failThreshold !== "never" && buildContext.errorCount > 0) {
725
- // Both 'warn' and 'error' thresholds cause failure on errors
726
- emojiLog("❌", `Build completed with errors`, "error");
727
- process.exit(1);
728
- }
729
- else if (failThreshold === "warn" && buildContext.warningCount > 0) {
730
- // Only 'warn' threshold causes failure on warnings
731
- emojiLog("⚠️", `Build completed with warnings (exiting with error due to --fail-threshold=warn)`, "warn");
732
- process.exit(1);
733
- }
734
- else if (buildContext.errorCount > 0) {
735
- // If we got here with errors, we're in 'never' mode
736
- emojiLog("⚠️", `Build completed with errors (continuing due to --fail-threshold=never)`, "warn");
764
+ }
765
+ if (isAttw) {
766
+ // run `@arethetypeswrong/cli --pack .` to check types
767
+ emojiLog("🔍", "Checking types with @arethetypeswrong/cli...");
768
+ const { execFile } = await import("node:child_process");
769
+ const { promisify } = await import("node:util");
770
+ const execFileAsync = promisify(execFile);
771
+ const [cmd, ...args] = `${pmExec} @arethetypeswrong/cli --pack ${pkgJsonDir} --format table-flipped`.split(" ");
772
+ console.dir([cmd, ...args], { depth: null });
773
+ let stdout = "";
774
+ let stderr = "";
775
+ let exitCode = 0;
776
+ try {
777
+ const result = await execFileAsync(cmd, args, {
778
+ cwd: pkgJsonDir,
779
+ encoding: "utf-8",
780
+ });
781
+ stdout = result.stdout;
782
+ stderr = result.stderr;
783
+ }
784
+ catch (error) {
785
+ stdout = error.stdout || "";
786
+ stderr = error.stderr || "";
787
+ exitCode = error.code || 1;
788
+ }
789
+ const output = stdout || stderr;
790
+ if (output) {
791
+ const indentedOutput = output
792
+ .split("\n")
793
+ .map((line) => ` ${line}`)
794
+ .join("\n");
795
+ if (exitCode === 0) {
796
+ console.log(indentedOutput);
737
797
  }
738
798
  else {
739
- // Just warnings and not failing on them
740
- emojiLog("🎉", `Build complete with warnings`);
799
+ console.error(indentedOutput);
800
+ emojiLog("⚠️", "ATTW found issues, but the build was not affected.", "warn");
741
801
  }
742
802
  }
803
+ }
804
+ // Report total compilation results
805
+ if (buildContext.errorCount > 0 || buildContext.warningCount > 0) {
806
+ emojiLog("📊", `Compilation finished with ${buildContext.errorCount} error(s) and ${buildContext.warningCount} warning(s)`);
807
+ // Apply threshold rules for exit code
808
+ if (failThreshold !== "never" && buildContext.errorCount > 0) {
809
+ // Both 'warn' and 'error' thresholds cause failure on errors
810
+ emojiLog("❌", `Build completed with errors`, "error");
811
+ process.exit(1);
812
+ }
813
+ else if (failThreshold === "warn" && buildContext.warningCount > 0) {
814
+ // Only 'warn' threshold causes failure on warnings
815
+ emojiLog("⚠️", `Build completed with warnings (exiting with error due to --fail-threshold=warn)`, "warn");
816
+ process.exit(1);
817
+ }
818
+ else if (buildContext.errorCount > 0) {
819
+ // If we got here with errors, we're in 'never' mode
820
+ emojiLog("⚠️", `Build completed with errors (continuing due to --fail-threshold=never)`, "warn");
821
+ }
743
822
  else {
744
- emojiLog("🎉", "Build complete! ✅");
823
+ // Just warnings and not failing on them
824
+ emojiLog("🎉", `Build complete with warnings`);
745
825
  }
746
826
  }
747
- catch (error) {
748
- emojiLog("❌", `Build failed: ${error}`, "error");
749
- process.exit(1);
827
+ else {
828
+ emojiLog("🎉", "Build complete! ✅");
750
829
  }
751
830
  }
752
831
  //# sourceMappingURL=main.js.map