zshy 0.2.4 → 0.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.
- package/README.md +76 -25
- package/dist/main.cjs +322 -239
- package/dist/main.cjs.map +1 -1
- package/dist/main.d.cts.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +322 -239
- package/dist/main.js.map +1 -1
- package/dist/tx-extension-rewrite.cjs +15 -1
- package/dist/tx-extension-rewrite.cjs.map +1 -1
- package/dist/tx-extension-rewrite.d.cts.map +1 -1
- package/dist/tx-extension-rewrite.d.ts.map +1 -1
- package/dist/tx-extension-rewrite.js +15 -1
- package/dist/tx-extension-rewrite.js.map +1 -1
- package/package.json +4 -4
package/dist/main.cjs
CHANGED
|
@@ -112,7 +112,6 @@ Examples:
|
|
|
112
112
|
const isVerbose = !!args["--verbose"];
|
|
113
113
|
const isDryRun = !!args["--dry-run"];
|
|
114
114
|
const failThreshold = args["--fail-threshold"] || "error"; // Default to 'error'
|
|
115
|
-
const dryRunPrefix = isDryRun ? "[dryrun] " : "";
|
|
116
115
|
const isCjsInterop = true; // Enable CJS interop for testing
|
|
117
116
|
// Validate that the threshold value is one of the allowed values
|
|
118
117
|
if (failThreshold !== "never" && failThreshold !== "warn" && failThreshold !== "error") {
|
|
@@ -180,35 +179,35 @@ Examples:
|
|
|
180
179
|
/////////////////////////////////
|
|
181
180
|
// const pkgJson = JSON.parse(fs.readFileSync("./package.json", "utf-8"));
|
|
182
181
|
const CONFIG_KEY = "zshy";
|
|
183
|
-
let
|
|
182
|
+
let rawConfig;
|
|
184
183
|
if (!pkgJson[CONFIG_KEY]) {
|
|
185
184
|
(0, utils_js_1.emojiLog)("❌", `No "${CONFIG_KEY}" key found in package.json`, "error");
|
|
186
185
|
process.exit(1);
|
|
187
186
|
}
|
|
188
187
|
if (typeof pkgJson[CONFIG_KEY] === "string") {
|
|
189
|
-
|
|
188
|
+
rawConfig = {
|
|
190
189
|
exports: { ".": pkgJson[CONFIG_KEY] },
|
|
191
190
|
};
|
|
192
191
|
}
|
|
193
192
|
else if (typeof pkgJson[CONFIG_KEY] === "object") {
|
|
194
|
-
|
|
195
|
-
if (typeof
|
|
196
|
-
|
|
193
|
+
rawConfig = { ...pkgJson[CONFIG_KEY] };
|
|
194
|
+
if (typeof rawConfig.exports === "string") {
|
|
195
|
+
rawConfig.exports = { ".": rawConfig.exports };
|
|
197
196
|
}
|
|
198
|
-
else if (typeof
|
|
197
|
+
else if (typeof rawConfig.exports === "undefined") {
|
|
199
198
|
(0, utils_js_1.emojiLog)("❌", `Missing "exports" key in package.json#/${CONFIG_KEY}`, "error");
|
|
200
199
|
process.exit(1);
|
|
201
200
|
}
|
|
202
|
-
else if (typeof
|
|
201
|
+
else if (typeof rawConfig.exports !== "object") {
|
|
203
202
|
(0, utils_js_1.emojiLog)("❌", `Invalid "exports" key in package.json#/${CONFIG_KEY}`, "error");
|
|
204
203
|
process.exit(1);
|
|
205
204
|
}
|
|
206
205
|
// Validate bin field if present
|
|
207
|
-
if (
|
|
208
|
-
if (typeof
|
|
206
|
+
if (rawConfig.bin !== undefined) {
|
|
207
|
+
if (typeof rawConfig.bin === "string") {
|
|
209
208
|
// Keep string format - we'll handle this in entry point extraction
|
|
210
209
|
}
|
|
211
|
-
else if (typeof
|
|
210
|
+
else if (typeof rawConfig.bin === "object" && rawConfig.bin !== null) {
|
|
212
211
|
// Object format is valid
|
|
213
212
|
}
|
|
214
213
|
else {
|
|
@@ -216,9 +215,22 @@ Examples:
|
|
|
216
215
|
process.exit(1);
|
|
217
216
|
}
|
|
218
217
|
}
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
|
|
218
|
+
// Validate conditions field if present
|
|
219
|
+
if (rawConfig.conditions !== undefined) {
|
|
220
|
+
if (typeof rawConfig.conditions === "object" && rawConfig.conditions !== null) {
|
|
221
|
+
// const { import: importCondition, require: requireCondition, ...rest } = config.conditions;
|
|
222
|
+
for (const [condition, value] of Object.entries(rawConfig.conditions)) {
|
|
223
|
+
if (value !== "esm" && value !== "cjs" && value !== "src") {
|
|
224
|
+
(0, utils_js_1.emojiLog)("❌", `Invalid condition value "${value}" for "${condition}" in package.json#/${CONFIG_KEY}/conditions. Valid values are "esm", "cjs", "src", or null`, "error");
|
|
225
|
+
process.exit(1);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
(0, utils_js_1.emojiLog)("❌", `Invalid "conditions" key in package.json#/${CONFIG_KEY}, expected object`, "error");
|
|
231
|
+
process.exit(1);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
222
234
|
}
|
|
223
235
|
else if (typeof pkgJson[CONFIG_KEY] === "undefined") {
|
|
224
236
|
(0, utils_js_1.emojiLog)("❌", `Missing "${CONFIG_KEY}" key in package.json`, "error");
|
|
@@ -229,7 +241,32 @@ Examples:
|
|
|
229
241
|
process.exit(1);
|
|
230
242
|
}
|
|
231
243
|
if (isVerbose) {
|
|
232
|
-
(0, utils_js_1.emojiLog)("🔧", `Parsed zshy config: ${(0, utils_js_1.formatForLog)(
|
|
244
|
+
(0, utils_js_1.emojiLog)("🔧", `Parsed zshy config: ${(0, utils_js_1.formatForLog)(rawConfig)}`);
|
|
245
|
+
}
|
|
246
|
+
// Check for deprecated sourceDialects
|
|
247
|
+
if ("sourceDialects" in rawConfig) {
|
|
248
|
+
(0, utils_js_1.emojiLog)("❌", 'The "sourceDialects" option is no longer supported. Use "conditions" instead to configure custom export conditions.', "error");
|
|
249
|
+
process.exit(1);
|
|
250
|
+
}
|
|
251
|
+
const config = { ...rawConfig };
|
|
252
|
+
// Normalize cjs property
|
|
253
|
+
if (config.cjs === undefined) {
|
|
254
|
+
config.cjs = true; // Default to true if not specified
|
|
255
|
+
}
|
|
256
|
+
config.noEdit ?? (config.noEdit = false);
|
|
257
|
+
// Validate that if cjs is disabled, no conditions are set to "cjs"
|
|
258
|
+
if (config.cjs === false && config.conditions) {
|
|
259
|
+
const cjsConditions = Object.entries(config.conditions).filter(([_, value]) => value === "cjs");
|
|
260
|
+
if (cjsConditions.length > 0) {
|
|
261
|
+
const conditionNames = cjsConditions.map(([name]) => name).join(", ");
|
|
262
|
+
(0, utils_js_1.emojiLog)("❌", `CJS is disabled (cjs: false) but the following conditions are set to "cjs": ${conditionNames}. Either enable CJS or change these conditions.`, "error");
|
|
263
|
+
process.exit(1);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
// Validate that if cjs is disabled, package.json type must be "module"
|
|
267
|
+
if (config.cjs === false && pkgJson.type !== "module") {
|
|
268
|
+
(0, utils_js_1.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");
|
|
269
|
+
process.exit(1);
|
|
233
270
|
}
|
|
234
271
|
///////////////////////////
|
|
235
272
|
/// read tsconfig ///
|
|
@@ -340,7 +377,7 @@ Examples:
|
|
|
340
377
|
(0, utils_js_1.emojiLog)("➡️", "Determining entrypoints...");
|
|
341
378
|
const entryPoints = [];
|
|
342
379
|
const rows = [["Subpath", "Entrypoint"]];
|
|
343
|
-
for (const [exportPath, sourcePath] of Object.entries(config.exports)) {
|
|
380
|
+
for (const [exportPath, sourcePath] of Object.entries(config.exports ?? {})) {
|
|
344
381
|
if (exportPath.includes("package.json"))
|
|
345
382
|
continue;
|
|
346
383
|
let cleanExportPath;
|
|
@@ -426,7 +463,7 @@ Examples:
|
|
|
426
463
|
// process.exit(1);
|
|
427
464
|
// }
|
|
428
465
|
if (entryPoints.length === 0) {
|
|
429
|
-
(0, utils_js_1.emojiLog)("❌", "No entry points found matching the specified patterns in package.json#/zshy exports", "error");
|
|
466
|
+
(0, utils_js_1.emojiLog)("❌", "No entry points found matching the specified patterns in package.json#/zshy exports or bin", "error");
|
|
430
467
|
process.exit(1);
|
|
431
468
|
}
|
|
432
469
|
///////////////////////////////
|
|
@@ -488,13 +525,14 @@ Examples:
|
|
|
488
525
|
//////////////////////////////////////////////
|
|
489
526
|
/// clean up outDir and declarationDir ///
|
|
490
527
|
//////////////////////////////////////////////
|
|
528
|
+
const prefix = isDryRun ? "[dryrun] " : "";
|
|
491
529
|
if (relRootDir.startsWith(relOutDir)) {
|
|
492
|
-
(0, utils_js_1.emojiLog)("🗑️", `${
|
|
530
|
+
(0, utils_js_1.emojiLog)("🗑️", `${prefix}Skipping cleanup of outDir as it contains source files`);
|
|
493
531
|
}
|
|
494
532
|
else {
|
|
495
533
|
// source files are in the outDir, so skip cleanup
|
|
496
534
|
// clean up outDir and declarationDir
|
|
497
|
-
(0, utils_js_1.emojiLog)("🗑️", `${
|
|
535
|
+
(0, utils_js_1.emojiLog)("🗑️", `${prefix}Cleaning up outDir...`);
|
|
498
536
|
if (!isDryRun) {
|
|
499
537
|
fs.rmSync(outDir, { recursive: true, force: true });
|
|
500
538
|
// // print success message in verbose mode
|
|
@@ -509,10 +547,10 @@ Examples:
|
|
|
509
547
|
// already done
|
|
510
548
|
}
|
|
511
549
|
else if (relRootDir.startsWith(relDeclarationDir)) {
|
|
512
|
-
(0, utils_js_1.emojiLog)("🗑️", `${
|
|
550
|
+
(0, utils_js_1.emojiLog)("🗑️", `${prefix}Skipping cleanup of declarationDir as it contains source files`);
|
|
513
551
|
}
|
|
514
552
|
else {
|
|
515
|
-
(0, utils_js_1.emojiLog)("🗑️", `${
|
|
553
|
+
(0, utils_js_1.emojiLog)("🗑️", `${prefix}Cleaning up declarationDir...`);
|
|
516
554
|
if (!isDryRun) {
|
|
517
555
|
fs.rmSync(declarationDir, { recursive: true, force: true });
|
|
518
556
|
// // print success message in verbose mode
|
|
@@ -527,24 +565,27 @@ Examples:
|
|
|
527
565
|
/// compile tsc ///
|
|
528
566
|
///////////////////////////////
|
|
529
567
|
const uniqueEntryPoints = [...new Set(entryPoints)];
|
|
530
|
-
try {
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
568
|
+
// try {
|
|
569
|
+
if (isVerbose) {
|
|
570
|
+
(0, utils_js_1.emojiLog)("→", `Resolved entrypoints: ${(0, utils_js_1.formatForLog)(uniqueEntryPoints)}`);
|
|
571
|
+
(0, utils_js_1.emojiLog)("→", `Resolved compilerOptions: ${(0, utils_js_1.formatForLog)({
|
|
572
|
+
...tsconfigJson,
|
|
573
|
+
module: ts.ModuleKind[tsconfigJson.module],
|
|
574
|
+
moduleResolution: ts.ModuleResolutionKind[tsconfigJson.moduleResolution],
|
|
575
|
+
target: ts.ScriptTarget[tsconfigJson.target],
|
|
576
|
+
})}`);
|
|
577
|
+
}
|
|
578
|
+
// Create a build context to track written files, copied assets, and compilation errors/warnings
|
|
579
|
+
const buildContext = {
|
|
580
|
+
writtenFiles: new Set(),
|
|
581
|
+
copiedAssets: new Set(),
|
|
582
|
+
errorCount: 0,
|
|
583
|
+
warningCount: 0,
|
|
584
|
+
};
|
|
585
|
+
// Check if CJS should be skipped
|
|
586
|
+
const skipCjs = config.cjs === false;
|
|
587
|
+
// CJS
|
|
588
|
+
if (!skipCjs) {
|
|
548
589
|
(0, utils_js_1.emojiLog)("🧱", `Building CJS...${isTypeModule ? ` (rewriting .ts -> .cjs/.d.cts)` : ``}`);
|
|
549
590
|
await (0, compile_js_1.compileProject)({
|
|
550
591
|
configPath: tsconfigPath,
|
|
@@ -562,230 +603,272 @@ Examples:
|
|
|
562
603
|
outDir,
|
|
563
604
|
},
|
|
564
605
|
}, uniqueEntryPoints, buildContext);
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
606
|
+
}
|
|
607
|
+
else {
|
|
608
|
+
(0, utils_js_1.emojiLog)("⏭️", "Skipping CJS build (cjs: false)");
|
|
609
|
+
}
|
|
610
|
+
// ESM
|
|
611
|
+
(0, utils_js_1.emojiLog)("🧱", `Building ESM...${isTypeModule ? `` : ` (rewriting .ts -> .mjs/.d.mts)`}`);
|
|
612
|
+
await (0, compile_js_1.compileProject)({
|
|
613
|
+
configPath: tsconfigPath,
|
|
614
|
+
ext: isTypeModule ? "js" : "mjs",
|
|
615
|
+
format: "esm",
|
|
616
|
+
verbose: isVerbose,
|
|
617
|
+
dryRun: isDryRun,
|
|
618
|
+
pkgJsonDir,
|
|
619
|
+
rootDir,
|
|
620
|
+
cjsInterop: isCjsInterop,
|
|
621
|
+
compilerOptions: {
|
|
622
|
+
...tsconfigJson,
|
|
623
|
+
module: ts.ModuleKind.ESNext,
|
|
624
|
+
moduleResolution: ts.ModuleResolutionKind.Bundler,
|
|
625
|
+
outDir,
|
|
626
|
+
},
|
|
627
|
+
}, uniqueEntryPoints, buildContext);
|
|
628
|
+
///////////////////////////////////
|
|
629
|
+
/// display written files ///
|
|
630
|
+
///////////////////////////////////
|
|
631
|
+
// Display files that were written or would be written (only in verbose mode)
|
|
632
|
+
if (isVerbose && buildContext.writtenFiles.size > 0) {
|
|
633
|
+
(0, utils_js_1.emojiLog)("📜", `${prefix}Writing files (${buildContext.writtenFiles.size} total)...`);
|
|
634
|
+
// Sort files by relative path for consistent display
|
|
635
|
+
const sortedFiles = [...buildContext.writtenFiles]
|
|
636
|
+
.map((file) => (0, utils_js_1.relativePosix)(pkgJsonDir, file))
|
|
637
|
+
.sort()
|
|
638
|
+
.map((relPath) => (relPath.startsWith(".") ? relPath : `./${relPath}`));
|
|
639
|
+
sortedFiles.forEach((file) => {
|
|
640
|
+
console.log(` ${file}`);
|
|
641
|
+
});
|
|
642
|
+
}
|
|
643
|
+
///////////////////////////////
|
|
644
|
+
/// generate exports ///
|
|
645
|
+
///////////////////////////////
|
|
646
|
+
// generate package.json exports
|
|
647
|
+
if (config.noEdit) {
|
|
648
|
+
(0, utils_js_1.emojiLog)("📦", "[noedit] Skipping modification of package.json");
|
|
649
|
+
}
|
|
650
|
+
else {
|
|
603
651
|
// Generate exports based on zshy config
|
|
604
652
|
const newExports = {};
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
if (sourcePath.endsWith("/**/*")) {
|
|
627
|
-
// Also convert the output paths from /**/* to /*
|
|
628
|
-
if (relJsPath.endsWith("/**/*")) {
|
|
629
|
-
relJsPath = relJsPath.slice(0, -5) + "/*";
|
|
653
|
+
if (config.exports) {
|
|
654
|
+
// const newExports: Record<string, any> = {};
|
|
655
|
+
(0, utils_js_1.emojiLog)("📦", `${prefix}Updating package.json...`);
|
|
656
|
+
for (const [exportPath, sourcePath] of Object.entries(config.exports)) {
|
|
657
|
+
if (exportPath.includes("package.json")) {
|
|
658
|
+
newExports[exportPath] = sourcePath;
|
|
659
|
+
continue;
|
|
660
|
+
}
|
|
661
|
+
const absSourcePath = path.resolve(pkgJsonDir, sourcePath);
|
|
662
|
+
const relSourcePath = path.relative(rootDir, absSourcePath);
|
|
663
|
+
const absJsPath = path.resolve(outDir, relSourcePath);
|
|
664
|
+
const absDtsPath = path.resolve(declarationDir, relSourcePath);
|
|
665
|
+
let relJsPath = "./" + (0, utils_js_1.relativePosix)(pkgJsonDir, absJsPath);
|
|
666
|
+
let relDtsPath = "./" + (0, utils_js_1.relativePosix)(pkgJsonDir, absDtsPath);
|
|
667
|
+
if (typeof sourcePath === "string") {
|
|
668
|
+
if (sourcePath.endsWith("/*") || sourcePath.endsWith("/**/*")) {
|
|
669
|
+
// Handle wildcard exports
|
|
670
|
+
const finalExportPath = exportPath;
|
|
671
|
+
if (finalExportPath.includes("**")) {
|
|
672
|
+
(0, utils_js_1.emojiLog)("❌", `Export keys cannot contain "**": ${finalExportPath}`, "error");
|
|
673
|
+
process.exit(1);
|
|
630
674
|
}
|
|
631
|
-
|
|
632
|
-
|
|
675
|
+
// Convert deep glob patterns to simple wildcard patterns in the final export
|
|
676
|
+
if (sourcePath.endsWith("/**/*")) {
|
|
677
|
+
// Also convert the output paths from /**/* to /*
|
|
678
|
+
if (relJsPath.endsWith("/**/*")) {
|
|
679
|
+
relJsPath = relJsPath.slice(0, -5) + "/*";
|
|
680
|
+
}
|
|
681
|
+
if (relDtsPath.endsWith("/**/*")) {
|
|
682
|
+
relDtsPath = relDtsPath.slice(0, -5) + "/*";
|
|
683
|
+
}
|
|
633
684
|
}
|
|
685
|
+
// Build exports object with proper condition ordering
|
|
686
|
+
const exportObj = {};
|
|
687
|
+
// Add custom conditions first in their original order
|
|
688
|
+
if (config.conditions) {
|
|
689
|
+
for (const [condition, value] of Object.entries(config.conditions)) {
|
|
690
|
+
if (value === "src") {
|
|
691
|
+
exportObj[condition] = sourcePath;
|
|
692
|
+
}
|
|
693
|
+
else if (value === "esm") {
|
|
694
|
+
exportObj[condition] = relJsPath;
|
|
695
|
+
}
|
|
696
|
+
else if (value === "cjs") {
|
|
697
|
+
exportObj[condition] = relJsPath;
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
// Add standard conditions
|
|
702
|
+
exportObj.types = relDtsPath;
|
|
703
|
+
exportObj.import = relJsPath;
|
|
704
|
+
if (!skipCjs) {
|
|
705
|
+
exportObj.require = relJsPath;
|
|
706
|
+
}
|
|
707
|
+
newExports[finalExportPath] = exportObj;
|
|
634
708
|
}
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
709
|
+
else if ((0, utils_js_1.isSourceFile)(sourcePath)) {
|
|
710
|
+
const esmPath = (0, utils_js_1.removeExtension)(relJsPath) + (isTypeModule ? `.js` : `.mjs`);
|
|
711
|
+
const cjsPath = (0, utils_js_1.removeExtension)(relJsPath) + (isTypeModule ? `.cjs` : `.js`);
|
|
712
|
+
// Use ESM type declarations when CJS is skipped, otherwise use CJS declarations
|
|
713
|
+
const dtsExt = skipCjs ? (isTypeModule ? ".d.ts" : ".d.mts") : isTypeModule ? ".d.cts" : ".d.ts";
|
|
714
|
+
const dtsPath = (0, utils_js_1.removeExtension)(relDtsPath) + dtsExt;
|
|
715
|
+
// Build exports object with proper condition ordering
|
|
716
|
+
const exportObj = {};
|
|
717
|
+
// Add custom conditions first in their original order
|
|
718
|
+
if (config.conditions) {
|
|
719
|
+
for (const [condition, value] of Object.entries(config.conditions)) {
|
|
720
|
+
if (value === "src") {
|
|
721
|
+
exportObj[condition] = sourcePath;
|
|
722
|
+
}
|
|
723
|
+
else if (value === "esm") {
|
|
724
|
+
exportObj[condition] = esmPath;
|
|
725
|
+
}
|
|
726
|
+
else if (value === "cjs") {
|
|
727
|
+
exportObj[condition] = cjsPath;
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
// Add standard conditions
|
|
732
|
+
exportObj.types = dtsPath;
|
|
733
|
+
exportObj.import = esmPath;
|
|
734
|
+
if (!skipCjs) {
|
|
735
|
+
exportObj.require = cjsPath;
|
|
736
|
+
}
|
|
737
|
+
newExports[exportPath] = exportObj;
|
|
738
|
+
if (exportPath === ".") {
|
|
739
|
+
if (!skipCjs) {
|
|
740
|
+
pkgJson.main = cjsPath;
|
|
741
|
+
pkgJson.module = esmPath;
|
|
742
|
+
pkgJson.types = dtsPath;
|
|
743
|
+
}
|
|
744
|
+
else {
|
|
745
|
+
// Only set module and types, not main
|
|
746
|
+
pkgJson.module = esmPath;
|
|
747
|
+
pkgJson.types = dtsPath;
|
|
748
|
+
}
|
|
749
|
+
if (isVerbose && !config.noEdit) {
|
|
750
|
+
(0, utils_js_1.emojiLog)("🔧", `Setting "main": ${(0, utils_js_1.formatForLog)(cjsPath)}`);
|
|
751
|
+
(0, utils_js_1.emojiLog)("🔧", `Setting "module": ${(0, utils_js_1.formatForLog)(esmPath)}`);
|
|
752
|
+
(0, utils_js_1.emojiLog)("🔧", `Setting "types": ${(0, utils_js_1.formatForLog)(dtsPath)}`);
|
|
753
|
+
}
|
|
754
|
+
}
|
|
645
755
|
}
|
|
646
756
|
}
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
757
|
+
}
|
|
758
|
+
if (isVerbose && !config.noEdit) {
|
|
759
|
+
(0, utils_js_1.emojiLog)("🔧", `Setting "exports": ${(0, utils_js_1.formatForLog)(newExports)}`);
|
|
760
|
+
}
|
|
761
|
+
///////////////////////////////
|
|
762
|
+
/// generate bin ///
|
|
763
|
+
///////////////////////////////
|
|
764
|
+
// Generate bin field based on zshy bin config
|
|
765
|
+
if (config.bin) {
|
|
766
|
+
(0, utils_js_1.emojiLog)("📦", `${prefix}Updating package.json#/bin...`);
|
|
767
|
+
const newBin = {};
|
|
768
|
+
// Convert config.bin to object format for processing
|
|
769
|
+
const binEntries = typeof config.bin === "string" ? [[pkgJson.name, config.bin]] : Object.entries(config.bin);
|
|
770
|
+
for (const [binName, sourcePath] of binEntries) {
|
|
771
|
+
if (typeof sourcePath === "string" && (0, utils_js_1.isSourceFile)(sourcePath)) {
|
|
772
|
+
const absSourcePath = path.resolve(pkgJsonDir, sourcePath);
|
|
773
|
+
const relSourcePath = path.relative(rootDir, absSourcePath);
|
|
774
|
+
const absJsPath = path.resolve(outDir, relSourcePath);
|
|
775
|
+
const relJsPath = "./" + (0, utils_js_1.relativePosix)(pkgJsonDir, absJsPath);
|
|
776
|
+
// Use ESM files for bin when CJS is skipped, otherwise use CJS
|
|
777
|
+
const binExt = skipCjs ? (isTypeModule ? ".js" : ".mjs") : isTypeModule ? ".cjs" : ".js";
|
|
778
|
+
const binPath = (0, utils_js_1.removeExtension)(relJsPath) + binExt;
|
|
779
|
+
newBin[binName] = binPath;
|
|
666
780
|
}
|
|
667
781
|
}
|
|
782
|
+
// If original config.bin was a string, output as string
|
|
783
|
+
if (typeof config.bin === "string") {
|
|
784
|
+
pkgJson.bin = Object.values(newBin)[0];
|
|
785
|
+
}
|
|
668
786
|
else {
|
|
669
|
-
|
|
670
|
-
|
|
787
|
+
// Output as object
|
|
788
|
+
pkgJson.bin = newBin;
|
|
671
789
|
}
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
if (isVerbose) {
|
|
675
|
-
(0, utils_js_1.emojiLog)("🔧", `Generated "exports": ${(0, utils_js_1.formatForLog)(newExports)}`);
|
|
676
|
-
}
|
|
677
|
-
///////////////////////////////
|
|
678
|
-
/// generate bin ///
|
|
679
|
-
///////////////////////////////
|
|
680
|
-
// Generate bin field based on zshy bin config
|
|
681
|
-
if (config.bin) {
|
|
682
|
-
(0, utils_js_1.emojiLog)("📦", `${dryRunPrefix}Updating package.json#/bin...`);
|
|
683
|
-
const newBin = {};
|
|
684
|
-
// Convert config.bin to object format for processing
|
|
685
|
-
const binEntries = typeof config.bin === "string" ? [[pkgJson.name, config.bin]] : Object.entries(config.bin);
|
|
686
|
-
for (const [binName, sourcePath] of binEntries) {
|
|
687
|
-
if (typeof sourcePath === "string" && (0, utils_js_1.isSourceFile)(sourcePath)) {
|
|
688
|
-
const absSourcePath = path.resolve(pkgJsonDir, sourcePath);
|
|
689
|
-
const relSourcePath = path.relative(rootDir, absSourcePath);
|
|
690
|
-
const absJsPath = path.resolve(outDir, relSourcePath);
|
|
691
|
-
const relJsPath = "./" + (0, utils_js_1.relativePosix)(pkgJsonDir, absJsPath);
|
|
692
|
-
// Use CommonJS entrypoint for bin
|
|
693
|
-
const binPath = (0, utils_js_1.removeExtension)(relJsPath) + (isTypeModule ? `.cjs` : `.js`);
|
|
694
|
-
newBin[binName] = binPath;
|
|
790
|
+
if (isVerbose && !config.noEdit) {
|
|
791
|
+
(0, utils_js_1.emojiLog)("🔧", `Setting "bin": ${(0, utils_js_1.formatForLog)(pkgJson.bin)}`);
|
|
695
792
|
}
|
|
696
793
|
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
// Output as object
|
|
703
|
-
pkgJson.bin = newBin;
|
|
704
|
-
}
|
|
705
|
-
if (isVerbose) {
|
|
706
|
-
(0, utils_js_1.emojiLog)("🔧", `Generated "bin": ${(0, utils_js_1.formatForLog)(pkgJson.bin)}`);
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
///////////////////////////////
|
|
710
|
-
/// write pkg json ///
|
|
711
|
-
///////////////////////////////
|
|
712
|
-
// Update package.json with new exports
|
|
713
|
-
pkgJson.exports = newExports;
|
|
714
|
-
if (isDryRun) {
|
|
715
|
-
(0, utils_js_1.emojiLog)("📦", "[dryrun] Skipping package.json modification");
|
|
716
|
-
}
|
|
717
|
-
else {
|
|
718
|
-
fs.writeFileSync(packageJsonPath, JSON.stringify(pkgJson, null, indent) + "\n");
|
|
719
|
-
}
|
|
720
|
-
if (isAttw) {
|
|
721
|
-
// run `@arethetypeswrong/cli --pack .` to check types
|
|
722
|
-
(0, utils_js_1.emojiLog)("🔍", "Checking types with @arethetypeswrong/cli...");
|
|
723
|
-
const { execFile } = await Promise.resolve().then(() => __importStar(require("node:child_process")));
|
|
724
|
-
const { promisify } = await Promise.resolve().then(() => __importStar(require("node:util")));
|
|
725
|
-
const execFileAsync = promisify(execFile);
|
|
726
|
-
const [cmd, ...args] = `${pmExec} @arethetypeswrong/cli --pack ${pkgJsonDir} --format table-flipped`.split(" ");
|
|
727
|
-
console.dir([cmd, ...args], { depth: null });
|
|
728
|
-
let stdout = "";
|
|
729
|
-
let stderr = "";
|
|
730
|
-
let exitCode = 0;
|
|
731
|
-
try {
|
|
732
|
-
const result = await execFileAsync(cmd, args, {
|
|
733
|
-
cwd: pkgJsonDir,
|
|
734
|
-
encoding: "utf-8",
|
|
735
|
-
});
|
|
736
|
-
stdout = result.stdout;
|
|
737
|
-
stderr = result.stderr;
|
|
794
|
+
///////////////////////////////
|
|
795
|
+
/// write pkg json ///
|
|
796
|
+
///////////////////////////////
|
|
797
|
+
if (isDryRun) {
|
|
798
|
+
(0, utils_js_1.emojiLog)("📦", "[dryrun] Skipping package.json modification");
|
|
738
799
|
}
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
stderr = error.stderr || "";
|
|
742
|
-
exitCode = error.code || 1;
|
|
800
|
+
else if (config.noEdit) {
|
|
801
|
+
(0, utils_js_1.emojiLog)("📦", "[noedit] Skipping package.json modification");
|
|
743
802
|
}
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
const indentedOutput = output
|
|
747
|
-
.split("\n")
|
|
748
|
-
.map((line) => ` ${line}`)
|
|
749
|
-
.join("\n");
|
|
750
|
-
if (exitCode === 0) {
|
|
751
|
-
console.log(indentedOutput);
|
|
752
|
-
}
|
|
753
|
-
else {
|
|
754
|
-
console.error(indentedOutput);
|
|
755
|
-
(0, utils_js_1.emojiLog)("⚠️", "ATTW found issues, but the build was not affected.", "warn");
|
|
756
|
-
}
|
|
803
|
+
else {
|
|
804
|
+
fs.writeFileSync(packageJsonPath, JSON.stringify(pkgJson, null, indent) + "\n");
|
|
757
805
|
}
|
|
758
806
|
}
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
807
|
+
}
|
|
808
|
+
if (isAttw) {
|
|
809
|
+
// run `@arethetypeswrong/cli --pack .` to check types
|
|
810
|
+
(0, utils_js_1.emojiLog)("🔍", "Checking types with @arethetypeswrong/cli...");
|
|
811
|
+
const { execFile } = await Promise.resolve().then(() => __importStar(require("node:child_process")));
|
|
812
|
+
const { promisify } = await Promise.resolve().then(() => __importStar(require("node:util")));
|
|
813
|
+
const execFileAsync = promisify(execFile);
|
|
814
|
+
const [cmd, ...args] = `${pmExec} @arethetypeswrong/cli --pack ${pkgJsonDir} --format table-flipped`.split(" ");
|
|
815
|
+
console.dir([cmd, ...args], { depth: null });
|
|
816
|
+
let stdout = "";
|
|
817
|
+
let stderr = "";
|
|
818
|
+
let exitCode = 0;
|
|
819
|
+
try {
|
|
820
|
+
const result = await execFileAsync(cmd, args, {
|
|
821
|
+
cwd: pkgJsonDir,
|
|
822
|
+
encoding: "utf-8",
|
|
823
|
+
});
|
|
824
|
+
stdout = result.stdout;
|
|
825
|
+
stderr = result.stderr;
|
|
826
|
+
}
|
|
827
|
+
catch (error) {
|
|
828
|
+
stdout = error.stdout || "";
|
|
829
|
+
stderr = error.stderr || "";
|
|
830
|
+
exitCode = error.code || 1;
|
|
831
|
+
}
|
|
832
|
+
const output = stdout || stderr;
|
|
833
|
+
if (output) {
|
|
834
|
+
const indentedOutput = output
|
|
835
|
+
.split("\n")
|
|
836
|
+
.map((line) => ` ${line}`)
|
|
837
|
+
.join("\n");
|
|
838
|
+
if (exitCode === 0) {
|
|
839
|
+
console.log(indentedOutput);
|
|
776
840
|
}
|
|
777
841
|
else {
|
|
778
|
-
|
|
779
|
-
(0, utils_js_1.emojiLog)("
|
|
842
|
+
console.error(indentedOutput);
|
|
843
|
+
(0, utils_js_1.emojiLog)("⚠️", "ATTW found issues, but the build was not affected.", "warn");
|
|
780
844
|
}
|
|
781
845
|
}
|
|
846
|
+
}
|
|
847
|
+
// Report total compilation results
|
|
848
|
+
if (buildContext.errorCount > 0 || buildContext.warningCount > 0) {
|
|
849
|
+
(0, utils_js_1.emojiLog)("📊", `Compilation finished with ${buildContext.errorCount} error(s) and ${buildContext.warningCount} warning(s)`);
|
|
850
|
+
// Apply threshold rules for exit code
|
|
851
|
+
if (failThreshold !== "never" && buildContext.errorCount > 0) {
|
|
852
|
+
// Both 'warn' and 'error' thresholds cause failure on errors
|
|
853
|
+
(0, utils_js_1.emojiLog)("❌", `Build completed with errors`, "error");
|
|
854
|
+
process.exit(1);
|
|
855
|
+
}
|
|
856
|
+
else if (failThreshold === "warn" && buildContext.warningCount > 0) {
|
|
857
|
+
// Only 'warn' threshold causes failure on warnings
|
|
858
|
+
(0, utils_js_1.emojiLog)("⚠️", `Build completed with warnings (exiting with error due to --fail-threshold=warn)`, "warn");
|
|
859
|
+
process.exit(1);
|
|
860
|
+
}
|
|
861
|
+
else if (buildContext.errorCount > 0) {
|
|
862
|
+
// If we got here with errors, we're in 'never' mode
|
|
863
|
+
(0, utils_js_1.emojiLog)("⚠️", `Build completed with errors (continuing due to --fail-threshold=never)`, "warn");
|
|
864
|
+
}
|
|
782
865
|
else {
|
|
783
|
-
|
|
866
|
+
// Just warnings and not failing on them
|
|
867
|
+
(0, utils_js_1.emojiLog)("🎉", `Build complete with warnings`);
|
|
784
868
|
}
|
|
785
869
|
}
|
|
786
|
-
|
|
787
|
-
(0, utils_js_1.emojiLog)("
|
|
788
|
-
process.exit(1);
|
|
870
|
+
else {
|
|
871
|
+
(0, utils_js_1.emojiLog)("🎉", "Build complete! ✅");
|
|
789
872
|
}
|
|
790
873
|
}
|
|
791
874
|
//# sourceMappingURL=main.js.map
|