zshy 0.0.6 → 0.0.7

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.
@@ -62,6 +62,7 @@ async function main() {
62
62
  "--verbose": Boolean,
63
63
  "--project": String,
64
64
  "--dry-run": Boolean,
65
+ // "--attw": Boolean,
65
66
  // Aliases
66
67
  "-h": "--help",
67
68
  "-p": "--project",
@@ -69,7 +70,7 @@ async function main() {
69
70
  }
70
71
  catch (error) {
71
72
  if (error instanceof Error) {
72
- console.error(`❌ ${error.message}`);
73
+ (0, utils_1.emojiLog)("❌", error.message, "error");
73
74
  }
74
75
  console.error(`Use --help for usage information`);
75
76
  process.exit(1);
@@ -93,14 +94,27 @@ Examples:
93
94
  `);
94
95
  process.exit(0);
95
96
  }
96
- console.log("💎 Starting zshy build...");
97
+ const userAgent = process.env.npm_config_user_agent;
98
+ let pmExec;
99
+ if (userAgent?.startsWith("pnpm")) {
100
+ pmExec = "pnpm exec";
101
+ }
102
+ else if (userAgent?.startsWith("yarn")) {
103
+ pmExec = "yarn exec";
104
+ }
105
+ else {
106
+ pmExec = "npx";
107
+ }
108
+ (0, utils_1.emojiLog)("💎", "Starting build... 🐒");
97
109
  const isVerbose = args["--verbose"];
98
110
  const isDryRun = args["--dry-run"];
111
+ const isAttw = false; // args["--attw"];
99
112
  if (isVerbose) {
100
- console.log("🗣️ Verbose mode enabled");
113
+ (0, utils_1.emojiLog)("ℹ️", "Verbose mode enabled");
114
+ (0, utils_1.emojiLog)("📦", `Detected package manager: ${pmExec}`);
101
115
  }
102
116
  if (isDryRun) {
103
- console.log("🔍 Dry run mode enabled - no files will be written");
117
+ (0, utils_1.emojiLog)("🔍", "Dry run mode enabled - no files will be written");
104
118
  }
105
119
  ///////////////////////////////////
106
120
  /// find and read pkg json ///
@@ -117,7 +131,7 @@ Examples:
117
131
  currentDir = path.dirname(currentDir);
118
132
  }
119
133
  if (!fs.existsSync(packageJsonPath)) {
120
- console.error("❌ package.json not found in current directory or any parent directories");
134
+ (0, utils_1.emojiLog)("❌", "package.json not found in current directory or any parent directories", "error");
121
135
  process.exit(1);
122
136
  }
123
137
  // read package.json and extract the "zshy" exports config
@@ -125,8 +139,8 @@ Examples:
125
139
  const pkgJson = JSON.parse(fs.readFileSync(packageJsonPath, "utf-8"));
126
140
  const pkgJsonDir = path.dirname(packageJsonPath);
127
141
  // print project root
128
- console.log(`⚙️ Detected project root: ${pkgJsonDir}`);
129
- console.log(`📦 Reading package.json from ./${path.relative(pkgJsonDir, packageJsonPath)}`);
142
+ (0, utils_1.emojiLog)("⚙️", `Detected project root: ${pkgJsonDir}`);
143
+ (0, utils_1.emojiLog)("📦", `Reading package.json from ./${path.relative(pkgJsonDir, packageJsonPath)}`);
130
144
  /////////////////////////////////
131
145
  /// parse zshy config ///
132
146
  /////////////////////////////////
@@ -134,7 +148,7 @@ Examples:
134
148
  const CONFIG_KEY = "zshy";
135
149
  let config;
136
150
  if (!pkgJson[CONFIG_KEY]) {
137
- console.error(`❌ No "${CONFIG_KEY}" key found in package.json`);
151
+ (0, utils_1.emojiLog)("❌", `No "${CONFIG_KEY}" key found in package.json`, "error");
138
152
  process.exit(1);
139
153
  }
140
154
  if (typeof pkgJson[CONFIG_KEY] === "string") {
@@ -148,11 +162,11 @@ Examples:
148
162
  config.exports = { ".": config.exports };
149
163
  }
150
164
  else if (typeof config.exports === "undefined") {
151
- console.error(`❌ Missing "exports" key in package.json#/${CONFIG_KEY}`);
165
+ (0, utils_1.emojiLog)("❌", `Missing "exports" key in package.json#/${CONFIG_KEY}`, "error");
152
166
  process.exit(1);
153
167
  }
154
168
  else if (typeof config.exports !== "object") {
155
- console.error(`❌ Invalid "exports" key in package.json#/${CONFIG_KEY}`);
169
+ (0, utils_1.emojiLog)("❌", `Invalid "exports" key in package.json#/${CONFIG_KEY}`, "error");
156
170
  process.exit(1);
157
171
  }
158
172
  // Validate bin field if present
@@ -164,7 +178,7 @@ Examples:
164
178
  // Object format is valid
165
179
  }
166
180
  else {
167
- console.error(`❌ Invalid "bin" key in package.json#/${CONFIG_KEY}, expected string or object`);
181
+ (0, utils_1.emojiLog)("❌", `Invalid "bin" key in package.json#/${CONFIG_KEY}, expected string or object`, "error");
168
182
  process.exit(1);
169
183
  }
170
184
  }
@@ -173,15 +187,15 @@ Examples:
173
187
  // };
174
188
  }
175
189
  else if (typeof pkgJson[CONFIG_KEY] === "undefined") {
176
- console.error(`❌ Missing "${CONFIG_KEY}" key in package.json`);
190
+ (0, utils_1.emojiLog)("❌", `Missing "${CONFIG_KEY}" key in package.json`, "error");
177
191
  process.exit(1);
178
192
  }
179
193
  else {
180
- console.error(`❌ Invalid "${CONFIG_KEY}" key in package.json, expected string or object`);
194
+ (0, utils_1.emojiLog)("❌", `Invalid "${CONFIG_KEY}" key in package.json, expected string or object`, "error");
181
195
  process.exit(1);
182
196
  }
183
197
  if (isVerbose) {
184
- console.log("🔧 Parsed zshy config:", (0, utils_1.formatForLog)(config));
198
+ (0, utils_1.emojiLog)("🔧", `Parsed zshy config: ${(0, utils_1.formatForLog)(config)}`);
185
199
  }
186
200
  ///////////////////////////
187
201
  /// read tsconfig ///
@@ -193,7 +207,7 @@ Examples:
193
207
  const resolvedProjectPath = path.resolve(process.cwd(), args["--project"]);
194
208
  if (fs.existsSync(resolvedProjectPath)) {
195
209
  if (fs.statSync(resolvedProjectPath).isDirectory()) {
196
- console.error(`❌ --project must point to a tsconfig.json file, not a directory: ${resolvedProjectPath}`);
210
+ (0, utils_1.emojiLog)("❌", `--project must point to a tsconfig.json file, not a directory: ${resolvedProjectPath}`, "error");
197
211
  process.exit(1);
198
212
  }
199
213
  else {
@@ -202,7 +216,7 @@ Examples:
202
216
  }
203
217
  }
204
218
  else {
205
- console.error(`❌ tsconfig.json file not found: ${resolvedProjectPath}`);
219
+ (0, utils_1.emojiLog)("❌", `tsconfig.json file not found: ${resolvedProjectPath}`, "error");
206
220
  process.exit(1);
207
221
  }
208
222
  }
@@ -211,7 +225,7 @@ Examples:
211
225
  const resolvedProjectPath = path.resolve(pkgJsonDir, config.tsconfig);
212
226
  if (fs.existsSync(resolvedProjectPath)) {
213
227
  if (fs.statSync(resolvedProjectPath).isDirectory()) {
214
- console.error(`❌ zshy.tsconfig must point to a tsconfig.json file, not a directory: ${resolvedProjectPath}`);
228
+ (0, utils_1.emojiLog)("❌", `zshy.tsconfig must point to a tsconfig.json file, not a directory: ${resolvedProjectPath}`, "error");
215
229
  process.exit(1);
216
230
  }
217
231
  else {
@@ -220,7 +234,7 @@ Examples:
220
234
  }
221
235
  }
222
236
  else {
223
- console.error(`❌ Tsconfig file not found: ${resolvedProjectPath}`);
237
+ (0, utils_1.emojiLog)("❌", `Tsconfig file not found: ${resolvedProjectPath}`, "error");
224
238
  process.exit(1);
225
239
  }
226
240
  }
@@ -231,10 +245,10 @@ Examples:
231
245
  const _parsedConfig = (0, utils_1.readTsconfig)(tsconfigPath);
232
246
  if (!fs.existsSync(tsconfigPath)) {
233
247
  // Check if tsconfig.json exists
234
- console.error(`❌ tsconfig.json not found at ${path.resolve(tsconfigPath)}`);
248
+ (0, utils_1.emojiLog)("❌", `tsconfig.json not found at ${path.resolve(tsconfigPath)}`, "error");
235
249
  process.exit(1);
236
250
  }
237
- console.log(`📁 Reading tsconfig from ./${path.relative(pkgJsonDir, tsconfigPath)}`);
251
+ (0, utils_1.emojiLog)("📁", `Reading tsconfig from ./${path.relative(pkgJsonDir, tsconfigPath)}`);
238
252
  // if (_parsedConfig.rootDir) {
239
253
  // console.error(
240
254
  // `❌ rootDir is determined from your set of entrypoints; you can remove it from your tsconfig.json.`,
@@ -255,31 +269,31 @@ Examples:
255
269
  const relDeclarationDir = path.relative(pkgJsonDir, declarationDir);
256
270
  // clean up outDir and declarationDir
257
271
  if (relOutDir !== "") {
258
- console.log(`🗑️ Cleaning up outDir...`);
272
+ (0, utils_1.emojiLog)("🗑️", `Cleaning up outDir...`);
259
273
  fs.rmSync(outDir, { recursive: true, force: true });
260
274
  // // print success mesage in verbose mode
261
275
  if (isVerbose) {
262
276
  if (fs.existsSync(outDir)) {
263
- console.error(`❌ Failed to clean up outDir: ${relOutDir}. Directory still exists.`);
277
+ (0, utils_1.emojiLog)("❌", `Failed to clean up outDir: ${relOutDir}. Directory still exists.`, "error");
264
278
  }
265
279
  }
266
280
  }
267
281
  else {
268
- console.log(`🗑️ Skipping cleanup of outDir as it contains source files`);
282
+ (0, utils_1.emojiLog)("🗑️", `Skipping cleanup of outDir as it contains source files`);
269
283
  }
270
284
  if (relDeclarationDir !== relOutDir && relDeclarationDir !== "") {
271
- console.log(`🗑️ Cleaning up declarationDir...`);
285
+ (0, utils_1.emojiLog)("🗑️", `Cleaning up declarationDir...`);
272
286
  fs.rmSync(declarationDir, { recursive: true, force: true });
273
287
  // // print success mesage in verbose mode
274
288
  if (isVerbose) {
275
289
  if (fs.existsSync(declarationDir)) {
276
- console.error(`❌ Failed to clean up declarationDir: ${relDeclarationDir}. Directory still exists.`);
290
+ (0, utils_1.emojiLog)("❌", `Failed to clean up declarationDir: ${relDeclarationDir}. Directory still exists.`, "error");
277
291
  }
278
292
  }
279
293
  }
280
294
  else {
281
295
  if (isVerbose)
282
- console.log(`🗑️ Skipping cleanup of declarationDir as it contains source files`);
296
+ (0, utils_1.emojiLog)("🗑️", `Skipping cleanup of declarationDir as it contains source files`);
283
297
  }
284
298
  const tsconfigJson = {
285
299
  ..._parsedConfig,
@@ -294,11 +308,11 @@ Examples:
294
308
  };
295
309
  if (relOutDir === "") {
296
310
  if (!pkgJson.files) {
297
- console.log('⚠️ You\'re building your code to the project root. This means your compiled files will be generated alongside your source files.\n ➜ Setting "files" in package.json to exclude TypeScript source from the published package.');
311
+ (0, utils_1.emojiLog)("⚠️", 'You\'re building your code to the project root. This means your compiled files will be generated alongside your source files.\n ➜ Setting "files" in package.json to exclude TypeScript source from the published package.');
298
312
  pkgJson.files = ["**/*.js", "**/*.mjs", "**/*.cjs", "**/*.d.ts", "**/*.d.mts", "**/*.d.cts"];
299
313
  }
300
314
  else {
301
- console.warn(`⚠️ You're building your code to the project root. This means your compiled files will be generated alongside your source files.
315
+ console.warn(`⚠️ You\'re building your code to the project root. This means your compiled files will be generated alongside your source files.
302
316
  ➜ Ensure that your "files" in package.json excludes TypeScript source files, or your users may experience .d.ts resolution issues in some environments:
303
317
 
304
318
  "files": ["**/*.js", "**/*.mjs", "**/*.cjs", "**/*.d.ts", "**/*.d.mts", "**/*.d.cts"],
@@ -307,7 +321,7 @@ Examples:
307
321
  }
308
322
  else {
309
323
  if (!pkgJson.files) {
310
- console.log(`⚠️ The "files" key is missing in package.json. Setting to "${relOutDir}".`);
324
+ (0, utils_1.emojiLog)("⚠️", `The "files" key is missing in package.json. Setting to "${relOutDir}".`);
311
325
  pkgJson.files = [relOutDir];
312
326
  if (relOutDir !== relDeclarationDir) {
313
327
  pkgJson.files.push(relDeclarationDir);
@@ -318,7 +332,7 @@ Examples:
318
332
  /// extract entry points ///
319
333
  /////////////////////////////////
320
334
  // Extract entry points from zshy exports config
321
- console.log("➡️ Determining entrypoints...");
335
+ (0, utils_1.emojiLog)("➡️", "Determining entrypoints...");
322
336
  const entryPatterns = [];
323
337
  const rows = [["Subpath", "Entrypoint"]];
324
338
  for (const [exportPath, sourcePath] of Object.entries(config.exports)) {
@@ -332,13 +346,13 @@ Examples:
332
346
  cleanExportPath = pkgJson.name + "/" + exportPath.slice(2);
333
347
  }
334
348
  else {
335
- console.error(`⚠️ Invalid subpath export "${exportPath}" — should start with "./"`);
349
+ (0, utils_1.emojiLog)("⚠️", `Invalid subpath export "${exportPath}" — should start with "./"`, "warn");
336
350
  process.exit(1);
337
351
  }
338
352
  if (typeof sourcePath === "string") {
339
353
  if (sourcePath.includes("*")) {
340
354
  if (!sourcePath.endsWith("/*")) {
341
- console.error(`❌ Wildcard paths should not contain file extensions: ${sourcePath}`);
355
+ (0, utils_1.emojiLog)("❌", `Wildcard paths should not contain file extensions: ${sourcePath}`, "error");
342
356
  process.exit(1);
343
357
  }
344
358
  const pattern = sourcePath.slice(0, -2) + "/*.{ts,tsx,mts,cts}";
@@ -394,11 +408,11 @@ Examples:
394
408
  const entryPoints = await (0, utils_1.getEntryPoints)(entryPatterns);
395
409
  // disallow .mts and .cts files
396
410
  if (entryPoints.some((ep) => ep.endsWith(".mts") || ep.endsWith(".cts"))) {
397
- console.error("❌ Source files with .mts or .cts extensions are not supported. Please use regular .ts files.");
411
+ (0, utils_1.emojiLog)("❌", "Source files with .mts or .cts extensions are not supported. Please use regular .ts files.", "error");
398
412
  process.exit(1);
399
413
  }
400
414
  if (entryPoints.length === 0) {
401
- console.error("❌ No entry points found matching the specified patterns in package.json#/zshy exports");
415
+ (0, utils_1.emojiLog)("❌", "No entry points found matching the specified patterns in package.json#/zshy exports", "error");
402
416
  process.exit(1);
403
417
  }
404
418
  ///////////////////////////////
@@ -429,7 +443,7 @@ Examples:
429
443
  }
430
444
  const relRootDir = path.relative(pkgJsonDir, rootDir);
431
445
  // Display resolved paths table
432
- console.log("🔧 Resolved build paths:");
446
+ (0, utils_1.emojiLog)("🔧", "Resolved build paths:");
433
447
  const pathRows = [["Location", "Resolved path"]];
434
448
  // pathRows.push([
435
449
  // "package.json",
@@ -455,19 +469,29 @@ Examples:
455
469
  .trim());
456
470
  const isTypeModule = pkgJson.type === "module";
457
471
  if (isTypeModule) {
458
- console.log(`🟨 Package is an ES module (package.json#/type is \"module\")`);
472
+ (0, utils_1.emojiLog)("🟨", `Package is an ES module (package.json#/type is "module")`);
459
473
  }
460
474
  else {
461
- console.log(`🐢 Package is a CommonJS module (${pkgJson.type === "commonjs" ? 'package.json#/type is "commonjs"' : 'package.json#/type not set to "module"'})`);
475
+ (0, utils_1.emojiLog)("🐢", `Package is a CommonJS module (${pkgJson.type === "commonjs" ? 'package.json#/type is "commonjs"' : 'package.json#/type not set to "module"'})`);
462
476
  }
463
477
  ///////////////////////////////
464
478
  /// compile tsc ///
465
479
  ///////////////////////////////
480
+ const uniqueEntryPoints = [...new Set(entryPoints)];
466
481
  try {
482
+ if (isVerbose) {
483
+ (0, utils_1.emojiLog)("→", `Resolved entrypoints: ${(0, utils_1.formatForLog)(uniqueEntryPoints)}`);
484
+ (0, utils_1.emojiLog)("→", `Resolved compilerOptions: ${(0, utils_1.formatForLog)({
485
+ ...tsconfigJson,
486
+ module: ts.ModuleKind[tsconfigJson.module],
487
+ moduleResolution: ts.ModuleResolutionKind[tsconfigJson.moduleResolution],
488
+ target: ts.ScriptTarget[tsconfigJson.target],
489
+ })}`);
490
+ }
467
491
  // Track all written files
468
492
  const allWrittenFiles = [];
469
493
  // CJS
470
- console.log(`🧱 Building CJS...${isTypeModule ? ` (rewriting .ts -> .cjs/.d.cts)` : ``}`);
494
+ (0, utils_1.emojiLog)("🧱", `Building CJS...${isTypeModule ? ` (rewriting .ts -> .cjs/.d.cts)` : ``}`);
471
495
  const cjsFiles = await (0, utils_1.compileProject)({
472
496
  configPath: tsconfigPath,
473
497
  mode: isTypeModule ? "cts" : "ts",
@@ -480,10 +504,10 @@ Examples:
480
504
  moduleResolution: ts.ModuleResolutionKind.Node10,
481
505
  outDir,
482
506
  },
483
- }, entryPoints);
507
+ }, uniqueEntryPoints);
484
508
  allWrittenFiles.push(...cjsFiles);
485
509
  // ESM
486
- console.log(`🧱 Building ESM...${isTypeModule ? `` : ` (rewriting .ts -> .mjs/.d.mts)`}`);
510
+ (0, utils_1.emojiLog)("🧱", `Building ESM...${isTypeModule ? `` : ` (rewriting .ts -> .mjs/.d.mts)`}`);
487
511
  const esmFiles = await (0, utils_1.compileProject)({
488
512
  configPath: tsconfigPath,
489
513
  mode: isTypeModule ? "ts" : "mts",
@@ -496,28 +520,28 @@ Examples:
496
520
  moduleResolution: ts.ModuleResolutionKind.Bundler,
497
521
  outDir,
498
522
  },
499
- }, entryPoints);
523
+ }, uniqueEntryPoints);
500
524
  allWrittenFiles.push(...esmFiles);
501
525
  ///////////////////////////////////
502
526
  /// display written files ///
503
527
  ///////////////////////////////////
504
528
  // Display files that were written or would be written (only in verbose mode)
505
529
  if (isVerbose && allWrittenFiles.length > 0) {
506
- console.log(`📜 ${isDryRun ? "[dryrun] " : ""}Writing files... (${allWrittenFiles.length} total):`);
530
+ (0, utils_1.emojiLog)("📜", `${isDryRun ? "[dryrun] " : ""}Writing files (${allWrittenFiles.length} total)...`);
507
531
  // Sort files by relative path for consistent display
508
532
  const sortedFiles = [...allWrittenFiles]
509
533
  .map((file) => path.relative(pkgJsonDir, file))
510
534
  .sort()
511
535
  .map((relPath) => (relPath.startsWith(".") ? relPath : `./${relPath}`));
512
536
  sortedFiles.forEach((file) => {
513
- console.log(` ${file}`);
537
+ console.log(` ${file}`);
514
538
  });
515
539
  }
516
540
  ///////////////////////////////
517
541
  /// generate exports ///
518
542
  ///////////////////////////////
519
543
  // generate package.json exports
520
- console.log("📦 Updating package.json#/exports...");
544
+ (0, utils_1.emojiLog)("📦", `${isDryRun ? "[dryrun] " : ""}Updating package.json#/exports...`);
521
545
  // Generate exports based on zshy config
522
546
  const newExports = {};
523
547
  const sourceDialects = config.sourceDialects || [];
@@ -535,13 +559,6 @@ Examples:
535
559
  if (typeof sourcePath === "string") {
536
560
  if (sourcePath.endsWith("/*")) {
537
561
  // Handle wildcard exports
538
- // const relSourcePath =
539
- // "./" +
540
- // path.relative(
541
- // pkgJsonDir,
542
- // path.resolve(outDir, sourcePath.slice(0, -2)),
543
- // ) +
544
- // "/*";
545
562
  newExports[exportPath] = {
546
563
  types: relDtsPath,
547
564
  import: relJsPath,
@@ -555,7 +572,7 @@ Examples:
555
572
  }
556
573
  }
557
574
  else if (isSourceFile(sourcePath)) {
558
- const esmPath = removeExtension(relJsPath) + (isTypeModule ? `.js` : `.mjs`); // ./v4/index.js or ./v4/index.mjs
575
+ const esmPath = removeExtension(relJsPath) + (isTypeModule ? `.js` : `.mjs`);
559
576
  const cjsPath = removeExtension(relJsPath) + (isTypeModule ? `.cjs` : `.js`);
560
577
  const dtsPath = removeExtension(relDtsPath) + (isTypeModule ? `.d.cts` : `.d.ts`); // ./
561
578
  newExports[exportPath] = {
@@ -576,17 +593,20 @@ Examples:
576
593
  }
577
594
  }
578
595
  else {
579
- console.error(`❌ Invalid entrypoint: ${sourcePath}`);
596
+ (0, utils_1.emojiLog)("❌", `Invalid entrypoint: ${sourcePath}`, "error");
580
597
  process.exit();
581
598
  }
582
599
  }
583
600
  }
601
+ if (isVerbose) {
602
+ (0, utils_1.emojiLog)("🔧", `Generated "exports": ${(0, utils_1.formatForLog)(newExports)}`);
603
+ }
584
604
  ///////////////////////////////
585
605
  /// generate bin ///
586
606
  ///////////////////////////////
587
607
  // Generate bin field based on zshy bin config
588
608
  if (config.bin) {
589
- console.log("📦 Updating package.json#/bin...");
609
+ (0, utils_1.emojiLog)("📦", `${isDryRun ? "[dryrun] " : ""}Updating package.json#/bin...`);
590
610
  const newBin = {};
591
611
  // Convert config.bin to object format for processing
592
612
  const binEntries = typeof config.bin === "string" ? [[pkgJson.name, config.bin]] : Object.entries(config.bin);
@@ -604,49 +624,74 @@ Examples:
604
624
  // If original config.bin was a string, output as string
605
625
  if (typeof config.bin === "string") {
606
626
  pkgJson.bin = Object.values(newBin)[0];
607
- if (isVerbose) {
608
- console.log(`🗣️ Updated package.json#/bin: "${Object.values(newBin)[0]}"`);
609
- }
610
627
  }
611
628
  else {
612
629
  // Output as object
613
630
  pkgJson.bin = newBin;
614
- if (isVerbose) {
615
- console.log("🗣️ Updated package.json#/bin: " + (0, utils_1.formatForLog)(newBin));
616
- }
617
631
  }
618
632
  }
633
+ if (isVerbose) {
634
+ (0, utils_1.emojiLog)("🔧", `Generated "bin": ${(0, utils_1.formatForLog)(pkgJson.bin)}`);
635
+ }
619
636
  ///////////////////////////////
620
637
  /// write pkg json ///
621
638
  ///////////////////////////////
622
639
  // Update package.json with new exports
623
640
  pkgJson.exports = newExports;
624
641
  if (isDryRun) {
625
- console.log("🔍 Skipping package.json modification (dry-run)");
642
+ (0, utils_1.emojiLog)("📦", "[dryrun] Skipping package.json modification");
626
643
  }
627
644
  else {
628
645
  fs.writeFileSync(packageJsonPath, JSON.stringify(pkgJson, null, 2) + "\n");
629
646
  }
630
- // console.log("✅ Updating package.json#/exports");
631
- if (isVerbose) {
632
- console.log(`🗣️ Updated package.json#/exports: ${(0, utils_1.formatForLog)(newExports)}`);
647
+ if (isAttw) {
648
+ // run `@arethetypeswrong/cli --pack .` to check types
649
+ (0, utils_1.emojiLog)("🔍", "Checking types with @arethetypeswrong/cli...");
650
+ const { execFile } = await Promise.resolve().then(() => __importStar(require("node:child_process")));
651
+ const { promisify } = await Promise.resolve().then(() => __importStar(require("node:util")));
652
+ const execFileAsync = promisify(execFile);
653
+ const [cmd, ...args] = `${pmExec} @arethetypeswrong/cli --pack ${pkgJsonDir}`.split(" ");
654
+ console.dir([cmd, ...args], { depth: null });
655
+ let stdout = "";
656
+ let stderr = "";
657
+ let exitCode = 0;
658
+ try {
659
+ const result = await execFileAsync(cmd, args, {
660
+ cwd: pkgJsonDir,
661
+ encoding: "utf-8",
662
+ });
663
+ stdout = result.stdout;
664
+ stderr = result.stderr;
665
+ }
666
+ catch (error) {
667
+ stdout = error.stdout || "";
668
+ stderr = error.stderr || "";
669
+ exitCode = error.code || 1;
670
+ }
671
+ const output = stdout || stderr;
672
+ if (output) {
673
+ const indentedOutput = output
674
+ .split("\n")
675
+ .map((line) => ` ${line}`)
676
+ .join("\n");
677
+ if (exitCode === 0) {
678
+ console.log(indentedOutput);
679
+ }
680
+ else {
681
+ console.error(indentedOutput);
682
+ (0, utils_1.emojiLog)("⚠️", "ATTW found issues, but the build was not affected.", "warn");
683
+ }
684
+ }
633
685
  }
634
- // // run `@arethetypeswrong/cli --pack .` to check types
635
- // console.log("🔍 Checking types with @arethetypeswrong/cli...");
636
- // const { execSync } = await import("node:child_process");
637
- // execSync(`npx @arethetypeswrong/cli --pack ${pkgJsonDir}`, {
638
- // stdio: "inherit",
639
- // cwd: pkgJsonDir,
640
- // });
641
- console.log("🎉 Build complete!");
686
+ (0, utils_1.emojiLog)("🎉", "Build complete! ✅");
642
687
  }
643
688
  catch (error) {
644
- console.error("❌ Build failed:", error);
689
+ (0, utils_1.emojiLog)("❌", `Build failed: ${error}`, "error");
645
690
  process.exit(1);
646
691
  }
647
692
  }
648
693
  // Run the script
649
694
  main().catch((error) => {
650
- console.error("❌ Script failed:", error);
695
+ (0, utils_1.emojiLog)("❌", `Script failed: ${error}`, "error");
651
696
  process.exit(1);
652
697
  });