zshy 0.0.6 → 0.0.8

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,20 +308,18 @@ 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.
302
- ➜ Ensure that your "files" in package.json excludes TypeScript source files, or your users may experience .d.ts resolution issues in some environments:
303
-
304
- "files": ["**/*.js", "**/*.mjs", "**/*.cjs", "**/*.d.ts", "**/*.d.mts", "**/*.d.cts"],
305
- `);
315
+ (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.
316
+ Ensure that your "files" in package.json excludes TypeScript source files, or your users may experience .d.ts resolution issues in some environments:
317
+ "files": ["**/*.js", "**/*.mjs", "**/*.cjs", "**/*.d.ts", "**/*.d.mts", "**/*.d.cts"]`);
306
318
  }
307
319
  }
308
320
  else {
309
321
  if (!pkgJson.files) {
310
- console.log(`⚠️ The "files" key is missing in package.json. Setting to "${relOutDir}".`);
322
+ (0, utils_1.emojiLog)("⚠️", `The "files" key is missing in package.json. Setting to "${relOutDir}".`);
311
323
  pkgJson.files = [relOutDir];
312
324
  if (relOutDir !== relDeclarationDir) {
313
325
  pkgJson.files.push(relDeclarationDir);
@@ -318,7 +330,7 @@ Examples:
318
330
  /// extract entry points ///
319
331
  /////////////////////////////////
320
332
  // Extract entry points from zshy exports config
321
- console.log("➡️ Determining entrypoints...");
333
+ (0, utils_1.emojiLog)("➡️", "Determining entrypoints...");
322
334
  const entryPatterns = [];
323
335
  const rows = [["Subpath", "Entrypoint"]];
324
336
  for (const [exportPath, sourcePath] of Object.entries(config.exports)) {
@@ -332,13 +344,13 @@ Examples:
332
344
  cleanExportPath = pkgJson.name + "/" + exportPath.slice(2);
333
345
  }
334
346
  else {
335
- console.error(`⚠️ Invalid subpath export "${exportPath}" — should start with "./"`);
347
+ (0, utils_1.emojiLog)("⚠️", `Invalid subpath export "${exportPath}" — should start with "./"`, "warn");
336
348
  process.exit(1);
337
349
  }
338
350
  if (typeof sourcePath === "string") {
339
351
  if (sourcePath.includes("*")) {
340
352
  if (!sourcePath.endsWith("/*")) {
341
- console.error(`❌ Wildcard paths should not contain file extensions: ${sourcePath}`);
353
+ (0, utils_1.emojiLog)("❌", `Wildcard paths should not contain file extensions: ${sourcePath}`, "error");
342
354
  process.exit(1);
343
355
  }
344
356
  const pattern = sourcePath.slice(0, -2) + "/*.{ts,tsx,mts,cts}";
@@ -394,11 +406,11 @@ Examples:
394
406
  const entryPoints = await (0, utils_1.getEntryPoints)(entryPatterns);
395
407
  // disallow .mts and .cts files
396
408
  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.");
409
+ (0, utils_1.emojiLog)("❌", "Source files with .mts or .cts extensions are not supported. Please use regular .ts files.", "error");
398
410
  process.exit(1);
399
411
  }
400
412
  if (entryPoints.length === 0) {
401
- console.error("❌ No entry points found matching the specified patterns in package.json#/zshy exports");
413
+ (0, utils_1.emojiLog)("❌", "No entry points found matching the specified patterns in package.json#/zshy exports", "error");
402
414
  process.exit(1);
403
415
  }
404
416
  ///////////////////////////////
@@ -429,7 +441,7 @@ Examples:
429
441
  }
430
442
  const relRootDir = path.relative(pkgJsonDir, rootDir);
431
443
  // Display resolved paths table
432
- console.log("🔧 Resolved build paths:");
444
+ (0, utils_1.emojiLog)("🔧", "Resolved build paths:");
433
445
  const pathRows = [["Location", "Resolved path"]];
434
446
  // pathRows.push([
435
447
  // "package.json",
@@ -455,19 +467,29 @@ Examples:
455
467
  .trim());
456
468
  const isTypeModule = pkgJson.type === "module";
457
469
  if (isTypeModule) {
458
- console.log(`🟨 Package is an ES module (package.json#/type is \"module\")`);
470
+ (0, utils_1.emojiLog)("🟨", `Package is an ES module (package.json#/type is "module")`);
459
471
  }
460
472
  else {
461
- console.log(`🐢 Package is a CommonJS module (${pkgJson.type === "commonjs" ? 'package.json#/type is "commonjs"' : 'package.json#/type not set to "module"'})`);
473
+ (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
474
  }
463
475
  ///////////////////////////////
464
476
  /// compile tsc ///
465
477
  ///////////////////////////////
478
+ const uniqueEntryPoints = [...new Set(entryPoints)];
466
479
  try {
480
+ if (isVerbose) {
481
+ (0, utils_1.emojiLog)("→", `Resolved entrypoints: ${(0, utils_1.formatForLog)(uniqueEntryPoints)}`);
482
+ (0, utils_1.emojiLog)("→", `Resolved compilerOptions: ${(0, utils_1.formatForLog)({
483
+ ...tsconfigJson,
484
+ module: ts.ModuleKind[tsconfigJson.module],
485
+ moduleResolution: ts.ModuleResolutionKind[tsconfigJson.moduleResolution],
486
+ target: ts.ScriptTarget[tsconfigJson.target],
487
+ })}`);
488
+ }
467
489
  // Track all written files
468
490
  const allWrittenFiles = [];
469
491
  // CJS
470
- console.log(`🧱 Building CJS...${isTypeModule ? ` (rewriting .ts -> .cjs/.d.cts)` : ``}`);
492
+ (0, utils_1.emojiLog)("🧱", `Building CJS...${isTypeModule ? ` (rewriting .ts -> .cjs/.d.cts)` : ``}`);
471
493
  const cjsFiles = await (0, utils_1.compileProject)({
472
494
  configPath: tsconfigPath,
473
495
  mode: isTypeModule ? "cts" : "ts",
@@ -480,10 +502,10 @@ Examples:
480
502
  moduleResolution: ts.ModuleResolutionKind.Node10,
481
503
  outDir,
482
504
  },
483
- }, entryPoints);
505
+ }, uniqueEntryPoints);
484
506
  allWrittenFiles.push(...cjsFiles);
485
507
  // ESM
486
- console.log(`🧱 Building ESM...${isTypeModule ? `` : ` (rewriting .ts -> .mjs/.d.mts)`}`);
508
+ (0, utils_1.emojiLog)("🧱", `Building ESM...${isTypeModule ? `` : ` (rewriting .ts -> .mjs/.d.mts)`}`);
487
509
  const esmFiles = await (0, utils_1.compileProject)({
488
510
  configPath: tsconfigPath,
489
511
  mode: isTypeModule ? "ts" : "mts",
@@ -496,28 +518,28 @@ Examples:
496
518
  moduleResolution: ts.ModuleResolutionKind.Bundler,
497
519
  outDir,
498
520
  },
499
- }, entryPoints);
521
+ }, uniqueEntryPoints);
500
522
  allWrittenFiles.push(...esmFiles);
501
523
  ///////////////////////////////////
502
524
  /// display written files ///
503
525
  ///////////////////////////////////
504
526
  // Display files that were written or would be written (only in verbose mode)
505
527
  if (isVerbose && allWrittenFiles.length > 0) {
506
- console.log(`📜 ${isDryRun ? "[dryrun] " : ""}Writing files... (${allWrittenFiles.length} total):`);
528
+ (0, utils_1.emojiLog)("📜", `${isDryRun ? "[dryrun] " : ""}Writing files (${allWrittenFiles.length} total)...`);
507
529
  // Sort files by relative path for consistent display
508
530
  const sortedFiles = [...allWrittenFiles]
509
531
  .map((file) => path.relative(pkgJsonDir, file))
510
532
  .sort()
511
533
  .map((relPath) => (relPath.startsWith(".") ? relPath : `./${relPath}`));
512
534
  sortedFiles.forEach((file) => {
513
- console.log(` ${file}`);
535
+ console.log(` ${file}`);
514
536
  });
515
537
  }
516
538
  ///////////////////////////////
517
539
  /// generate exports ///
518
540
  ///////////////////////////////
519
541
  // generate package.json exports
520
- console.log("📦 Updating package.json#/exports...");
542
+ (0, utils_1.emojiLog)("📦", `${isDryRun ? "[dryrun] " : ""}Updating package.json#/exports...`);
521
543
  // Generate exports based on zshy config
522
544
  const newExports = {};
523
545
  const sourceDialects = config.sourceDialects || [];
@@ -535,13 +557,6 @@ Examples:
535
557
  if (typeof sourcePath === "string") {
536
558
  if (sourcePath.endsWith("/*")) {
537
559
  // Handle wildcard exports
538
- // const relSourcePath =
539
- // "./" +
540
- // path.relative(
541
- // pkgJsonDir,
542
- // path.resolve(outDir, sourcePath.slice(0, -2)),
543
- // ) +
544
- // "/*";
545
560
  newExports[exportPath] = {
546
561
  types: relDtsPath,
547
562
  import: relJsPath,
@@ -555,7 +570,7 @@ Examples:
555
570
  }
556
571
  }
557
572
  else if (isSourceFile(sourcePath)) {
558
- const esmPath = removeExtension(relJsPath) + (isTypeModule ? `.js` : `.mjs`); // ./v4/index.js or ./v4/index.mjs
573
+ const esmPath = removeExtension(relJsPath) + (isTypeModule ? `.js` : `.mjs`);
559
574
  const cjsPath = removeExtension(relJsPath) + (isTypeModule ? `.cjs` : `.js`);
560
575
  const dtsPath = removeExtension(relDtsPath) + (isTypeModule ? `.d.cts` : `.d.ts`); // ./
561
576
  newExports[exportPath] = {
@@ -576,17 +591,20 @@ Examples:
576
591
  }
577
592
  }
578
593
  else {
579
- console.error(`❌ Invalid entrypoint: ${sourcePath}`);
594
+ (0, utils_1.emojiLog)("❌", `Invalid entrypoint: ${sourcePath}`, "error");
580
595
  process.exit();
581
596
  }
582
597
  }
583
598
  }
599
+ if (isVerbose) {
600
+ (0, utils_1.emojiLog)("🔧", `Generated "exports": ${(0, utils_1.formatForLog)(newExports)}`);
601
+ }
584
602
  ///////////////////////////////
585
603
  /// generate bin ///
586
604
  ///////////////////////////////
587
605
  // Generate bin field based on zshy bin config
588
606
  if (config.bin) {
589
- console.log("📦 Updating package.json#/bin...");
607
+ (0, utils_1.emojiLog)("📦", `${isDryRun ? "[dryrun] " : ""}Updating package.json#/bin...`);
590
608
  const newBin = {};
591
609
  // Convert config.bin to object format for processing
592
610
  const binEntries = typeof config.bin === "string" ? [[pkgJson.name, config.bin]] : Object.entries(config.bin);
@@ -604,49 +622,74 @@ Examples:
604
622
  // If original config.bin was a string, output as string
605
623
  if (typeof config.bin === "string") {
606
624
  pkgJson.bin = Object.values(newBin)[0];
607
- if (isVerbose) {
608
- console.log(`🗣️ Updated package.json#/bin: "${Object.values(newBin)[0]}"`);
609
- }
610
625
  }
611
626
  else {
612
627
  // Output as object
613
628
  pkgJson.bin = newBin;
614
- if (isVerbose) {
615
- console.log("🗣️ Updated package.json#/bin: " + (0, utils_1.formatForLog)(newBin));
616
- }
617
629
  }
618
630
  }
631
+ if (isVerbose) {
632
+ (0, utils_1.emojiLog)("🔧", `Generated "bin": ${(0, utils_1.formatForLog)(pkgJson.bin)}`);
633
+ }
619
634
  ///////////////////////////////
620
635
  /// write pkg json ///
621
636
  ///////////////////////////////
622
637
  // Update package.json with new exports
623
638
  pkgJson.exports = newExports;
624
639
  if (isDryRun) {
625
- console.log("🔍 Skipping package.json modification (dry-run)");
640
+ (0, utils_1.emojiLog)("📦", "[dryrun] Skipping package.json modification");
626
641
  }
627
642
  else {
628
643
  fs.writeFileSync(packageJsonPath, JSON.stringify(pkgJson, null, 2) + "\n");
629
644
  }
630
- // console.log("✅ Updating package.json#/exports");
631
- if (isVerbose) {
632
- console.log(`🗣️ Updated package.json#/exports: ${(0, utils_1.formatForLog)(newExports)}`);
645
+ if (isAttw) {
646
+ // run `@arethetypeswrong/cli --pack .` to check types
647
+ (0, utils_1.emojiLog)("🔍", "Checking types with @arethetypeswrong/cli...");
648
+ const { execFile } = await Promise.resolve().then(() => __importStar(require("node:child_process")));
649
+ const { promisify } = await Promise.resolve().then(() => __importStar(require("node:util")));
650
+ const execFileAsync = promisify(execFile);
651
+ const [cmd, ...args] = `${pmExec} @arethetypeswrong/cli --pack ${pkgJsonDir}`.split(" ");
652
+ console.dir([cmd, ...args], { depth: null });
653
+ let stdout = "";
654
+ let stderr = "";
655
+ let exitCode = 0;
656
+ try {
657
+ const result = await execFileAsync(cmd, args, {
658
+ cwd: pkgJsonDir,
659
+ encoding: "utf-8",
660
+ });
661
+ stdout = result.stdout;
662
+ stderr = result.stderr;
663
+ }
664
+ catch (error) {
665
+ stdout = error.stdout || "";
666
+ stderr = error.stderr || "";
667
+ exitCode = error.code || 1;
668
+ }
669
+ const output = stdout || stderr;
670
+ if (output) {
671
+ const indentedOutput = output
672
+ .split("\n")
673
+ .map((line) => ` ${line}`)
674
+ .join("\n");
675
+ if (exitCode === 0) {
676
+ console.log(indentedOutput);
677
+ }
678
+ else {
679
+ console.error(indentedOutput);
680
+ (0, utils_1.emojiLog)("⚠️", "ATTW found issues, but the build was not affected.", "warn");
681
+ }
682
+ }
633
683
  }
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!");
684
+ (0, utils_1.emojiLog)("🎉", "Build complete! ✅");
642
685
  }
643
686
  catch (error) {
644
- console.error("❌ Build failed:", error);
687
+ (0, utils_1.emojiLog)("❌", `Build failed: ${error}`, "error");
645
688
  process.exit(1);
646
689
  }
647
690
  }
648
691
  // Run the script
649
692
  main().catch((error) => {
650
- console.error("❌ Script failed:", error);
693
+ (0, utils_1.emojiLog)("❌", `Script failed: ${error}`, "error");
651
694
  process.exit(1);
652
695
  });