zshy 0.4.4 → 0.6.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/dist/compile.cjs +8 -8
- package/dist/compile.cjs.map +1 -1
- package/dist/compile.d.cts.map +1 -1
- package/dist/compile.d.ts.map +1 -1
- package/dist/compile.js +8 -8
- package/dist/compile.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/main.cjs +212 -120
- 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 +213 -121
- package/dist/main.js.map +1 -1
- package/dist/utils.cjs +40 -6
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +8 -1
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.ts +8 -1
- package/dist/utils.d.ts.map +1 -1
- package/dist/utils.js +37 -4
- package/dist/utils.js.map +1 -1
- package/package.json +1 -1
package/dist/main.cjs
CHANGED
|
@@ -46,6 +46,7 @@ const ts = __importStar(require("typescript"));
|
|
|
46
46
|
const compile_js_1 = require("./compile.cjs");
|
|
47
47
|
const utils_js_1 = require("./utils.cjs");
|
|
48
48
|
async function main() {
|
|
49
|
+
utils_js_1.log.prefix = "» ";
|
|
49
50
|
///////////////////////////////////
|
|
50
51
|
/// parse command line args ///
|
|
51
52
|
///////////////////////////////////
|
|
@@ -55,6 +56,7 @@ async function main() {
|
|
|
55
56
|
args = (0, arg_1.default)({
|
|
56
57
|
"--help": Boolean,
|
|
57
58
|
"--verbose": Boolean,
|
|
59
|
+
"--silent": Boolean,
|
|
58
60
|
"--project": String,
|
|
59
61
|
"--dry-run": Boolean,
|
|
60
62
|
"--fail-threshold": String,
|
|
@@ -66,7 +68,7 @@ async function main() {
|
|
|
66
68
|
}
|
|
67
69
|
catch (error) {
|
|
68
70
|
if (error instanceof Error) {
|
|
69
|
-
|
|
71
|
+
utils_js_1.log.error(`❌ ${error.message}`);
|
|
70
72
|
}
|
|
71
73
|
console.error(`Use --help for usage information`);
|
|
72
74
|
process.exit(1);
|
|
@@ -80,6 +82,7 @@ Options:
|
|
|
80
82
|
-h, --help Show this help message
|
|
81
83
|
-p, --project <path> Path to tsconfig.json file
|
|
82
84
|
--verbose Enable verbose output
|
|
85
|
+
--silent Suppress all output
|
|
83
86
|
--dry-run Don't write any files, just log what would be done
|
|
84
87
|
--fail-threshold <threshold> When to exit with non-zero error code
|
|
85
88
|
"error" (default)
|
|
@@ -90,6 +93,7 @@ Examples:
|
|
|
90
93
|
zshy # Run build
|
|
91
94
|
zshy --project ./tsconfig.build.json # Use specific tsconfig file (defaults to tsconfig.json)
|
|
92
95
|
zshy --verbose # Enable verbose logging
|
|
96
|
+
zshy --silent # Suppress all output
|
|
93
97
|
zshy --dry-run # Preview changes without writing files
|
|
94
98
|
`);
|
|
95
99
|
process.exit(0);
|
|
@@ -105,37 +109,50 @@ Examples:
|
|
|
105
109
|
else {
|
|
106
110
|
pmExec = "npx";
|
|
107
111
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
+
// Validate that --verbose and --silent are not both passed
|
|
113
|
+
if (args["--verbose"] && args["--silent"]) {
|
|
114
|
+
utils_js_1.log.error("❌ Cannot use both --verbose and --silent flags together");
|
|
115
|
+
process.exit(1);
|
|
116
|
+
}
|
|
117
|
+
// Set silent mode if --silent flag is passed
|
|
118
|
+
const isSilent = !!args["--silent"];
|
|
112
119
|
const isVerbose = !!args["--verbose"];
|
|
120
|
+
(0, utils_js_1.setSilent)(isSilent);
|
|
121
|
+
if (!isSilent) {
|
|
122
|
+
const originalPrefix = utils_js_1.log.prefix;
|
|
123
|
+
utils_js_1.log.prefix = undefined;
|
|
124
|
+
utils_js_1.log.info(` ╔═══════════════════════════════════════════════╗`);
|
|
125
|
+
utils_js_1.log.info(` ║ zshy » the bundler-free TypeScript build tool ║`);
|
|
126
|
+
utils_js_1.log.info(` ╚═══════════════════════════════════════════════╝`);
|
|
127
|
+
utils_js_1.log.prefix = originalPrefix;
|
|
128
|
+
utils_js_1.log.info("Starting build...");
|
|
129
|
+
}
|
|
113
130
|
const isDryRun = !!args["--dry-run"];
|
|
114
131
|
const failThreshold = args["--fail-threshold"] || "error"; // Default to 'error'
|
|
115
132
|
const isCjsInterop = true; // Enable CJS interop for testing
|
|
116
133
|
// Validate that the threshold value is one of the allowed values
|
|
117
134
|
if (failThreshold !== "never" && failThreshold !== "warn" && failThreshold !== "error") {
|
|
118
|
-
|
|
135
|
+
utils_js_1.log.error(`❌ Invalid value for --fail-threshold: "${failThreshold}". Valid values are "never", "warn", or "error"`);
|
|
119
136
|
process.exit(1);
|
|
120
137
|
}
|
|
121
138
|
const isAttw = false; // args["--attw"];
|
|
122
139
|
if (isVerbose) {
|
|
123
|
-
|
|
124
|
-
|
|
140
|
+
utils_js_1.log.info("Verbose mode enabled");
|
|
141
|
+
utils_js_1.log.info(`Detected package manager: ${pmExec}`);
|
|
125
142
|
}
|
|
126
143
|
if (isDryRun) {
|
|
127
|
-
|
|
144
|
+
utils_js_1.log.info("Dry run mode enabled. No files will be written or modified.");
|
|
128
145
|
}
|
|
129
146
|
// Display message about fail threshold setting
|
|
130
147
|
if (isVerbose) {
|
|
131
148
|
if (failThreshold === "never") {
|
|
132
|
-
|
|
149
|
+
utils_js_1.log.info("Build will always succeed regardless of errors or warnings");
|
|
133
150
|
}
|
|
134
151
|
else if (failThreshold === "warn") {
|
|
135
|
-
|
|
152
|
+
utils_js_1.log.warn("Build will fail on warnings or errors");
|
|
136
153
|
}
|
|
137
154
|
else {
|
|
138
|
-
|
|
155
|
+
utils_js_1.log.info("Build will fail only on errors (default)");
|
|
139
156
|
}
|
|
140
157
|
}
|
|
141
158
|
///////////////////////////////////
|
|
@@ -153,7 +170,7 @@ Examples:
|
|
|
153
170
|
currentDir = path.dirname(currentDir);
|
|
154
171
|
}
|
|
155
172
|
if (!fs.existsSync(packageJsonPath)) {
|
|
156
|
-
|
|
173
|
+
utils_js_1.log.error("❌ package.json not found in current directory or any parent directories");
|
|
157
174
|
process.exit(1);
|
|
158
175
|
}
|
|
159
176
|
// read package.json and extract the "zshy" exports config
|
|
@@ -172,8 +189,10 @@ Examples:
|
|
|
172
189
|
const pkgJsonDir = path.dirname(packageJsonPath);
|
|
173
190
|
const pkgJsonRelPath = (0, utils_js_1.relativePosix)(pkgJsonDir, packageJsonPath);
|
|
174
191
|
// print project root
|
|
175
|
-
(
|
|
176
|
-
|
|
192
|
+
if (!isSilent) {
|
|
193
|
+
utils_js_1.log.info(`Detected project root: ${pkgJsonDir}`);
|
|
194
|
+
utils_js_1.log.info(`Reading package.json from ./${pkgJsonRelPath}`);
|
|
195
|
+
}
|
|
177
196
|
/////////////////////////////////
|
|
178
197
|
/// parse zshy config ///
|
|
179
198
|
/////////////////////////////////
|
|
@@ -181,7 +200,7 @@ Examples:
|
|
|
181
200
|
const CONFIG_KEY = "zshy";
|
|
182
201
|
let rawConfig;
|
|
183
202
|
if (!pkgJson[CONFIG_KEY]) {
|
|
184
|
-
|
|
203
|
+
utils_js_1.log.error(`❌ No "${CONFIG_KEY}" key found in package.json`);
|
|
185
204
|
process.exit(1);
|
|
186
205
|
}
|
|
187
206
|
if (typeof pkgJson[CONFIG_KEY] === "string") {
|
|
@@ -195,11 +214,11 @@ Examples:
|
|
|
195
214
|
rawConfig.exports = { ".": rawConfig.exports };
|
|
196
215
|
}
|
|
197
216
|
else if (typeof rawConfig.exports === "undefined") {
|
|
198
|
-
|
|
217
|
+
utils_js_1.log.error(`❌ Missing "exports" key in package.json#/${CONFIG_KEY}`);
|
|
199
218
|
process.exit(1);
|
|
200
219
|
}
|
|
201
220
|
else if (typeof rawConfig.exports !== "object") {
|
|
202
|
-
|
|
221
|
+
utils_js_1.log.error(`❌ Invalid "exports" key in package.json#/${CONFIG_KEY}`);
|
|
203
222
|
process.exit(1);
|
|
204
223
|
}
|
|
205
224
|
// Validate bin field if present
|
|
@@ -211,7 +230,7 @@ Examples:
|
|
|
211
230
|
// Object format is valid
|
|
212
231
|
}
|
|
213
232
|
else {
|
|
214
|
-
|
|
233
|
+
utils_js_1.log.error(`❌ Invalid "bin" key in package.json#/${CONFIG_KEY}, expected string or object`);
|
|
215
234
|
process.exit(1);
|
|
216
235
|
}
|
|
217
236
|
}
|
|
@@ -221,31 +240,31 @@ Examples:
|
|
|
221
240
|
// const { import: importCondition, require: requireCondition, ...rest } = config.conditions;
|
|
222
241
|
for (const [condition, value] of Object.entries(rawConfig.conditions)) {
|
|
223
242
|
if (value !== "esm" && value !== "cjs" && value !== "src") {
|
|
224
|
-
|
|
243
|
+
utils_js_1.log.error(`❌ Invalid condition value "${value}" for "${condition}" in package.json#/${CONFIG_KEY}/conditions. Valid values are "esm", "cjs", "src", or null`);
|
|
225
244
|
process.exit(1);
|
|
226
245
|
}
|
|
227
246
|
}
|
|
228
247
|
}
|
|
229
248
|
else {
|
|
230
|
-
|
|
249
|
+
utils_js_1.log.error(`❌ Invalid "conditions" key in package.json#/${CONFIG_KEY}, expected object`);
|
|
231
250
|
process.exit(1);
|
|
232
251
|
}
|
|
233
252
|
}
|
|
234
253
|
}
|
|
235
254
|
else if (typeof pkgJson[CONFIG_KEY] === "undefined") {
|
|
236
|
-
|
|
255
|
+
utils_js_1.log.error(`❌ Missing "${CONFIG_KEY}" key in package.json`);
|
|
237
256
|
process.exit(1);
|
|
238
257
|
}
|
|
239
258
|
else {
|
|
240
|
-
|
|
259
|
+
utils_js_1.log.error(`❌ Invalid "${CONFIG_KEY}" key in package.json, expected string or object`);
|
|
241
260
|
process.exit(1);
|
|
242
261
|
}
|
|
243
262
|
if (isVerbose) {
|
|
244
|
-
|
|
263
|
+
utils_js_1.log.info(`Parsed zshy config: ${(0, utils_js_1.formatForLog)(rawConfig)}`);
|
|
245
264
|
}
|
|
246
265
|
// Check for deprecated sourceDialects
|
|
247
266
|
if ("sourceDialects" in rawConfig) {
|
|
248
|
-
|
|
267
|
+
utils_js_1.log.error('❌ The "sourceDialects" option is no longer supported. Use "conditions" instead to configure custom export conditions.');
|
|
249
268
|
process.exit(1);
|
|
250
269
|
}
|
|
251
270
|
const config = { ...rawConfig };
|
|
@@ -259,13 +278,13 @@ Examples:
|
|
|
259
278
|
const cjsConditions = Object.entries(config.conditions).filter(([_, value]) => value === "cjs");
|
|
260
279
|
if (cjsConditions.length > 0) {
|
|
261
280
|
const conditionNames = cjsConditions.map(([name]) => name).join(", ");
|
|
262
|
-
|
|
281
|
+
utils_js_1.log.error(`❌ CJS is disabled (cjs: false) but the following conditions are set to "cjs": ${conditionNames}. Either enable CJS or change these conditions.`);
|
|
263
282
|
process.exit(1);
|
|
264
283
|
}
|
|
265
284
|
}
|
|
266
285
|
// Validate that if cjs is disabled, package.json type must be "module"
|
|
267
286
|
if (config.cjs === false && pkgJson.type !== "module") {
|
|
268
|
-
|
|
287
|
+
utils_js_1.log.error(`❌ 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.`);
|
|
269
288
|
process.exit(1);
|
|
270
289
|
}
|
|
271
290
|
///////////////////////////
|
|
@@ -278,7 +297,7 @@ Examples:
|
|
|
278
297
|
const resolvedProjectPath = path.resolve(process.cwd(), args["--project"]);
|
|
279
298
|
if (fs.existsSync(resolvedProjectPath)) {
|
|
280
299
|
if (fs.statSync(resolvedProjectPath).isDirectory()) {
|
|
281
|
-
|
|
300
|
+
utils_js_1.log.error(`--project must point to a tsconfig.json file, not a directory: ${resolvedProjectPath}`);
|
|
282
301
|
process.exit(1);
|
|
283
302
|
}
|
|
284
303
|
else {
|
|
@@ -287,7 +306,7 @@ Examples:
|
|
|
287
306
|
}
|
|
288
307
|
}
|
|
289
308
|
else {
|
|
290
|
-
|
|
309
|
+
utils_js_1.log.error(`tsconfig.json file not found: ${resolvedProjectPath}`);
|
|
291
310
|
process.exit(1);
|
|
292
311
|
}
|
|
293
312
|
}
|
|
@@ -296,7 +315,7 @@ Examples:
|
|
|
296
315
|
const resolvedProjectPath = path.resolve(pkgJsonDir, config.tsconfig);
|
|
297
316
|
if (fs.existsSync(resolvedProjectPath)) {
|
|
298
317
|
if (fs.statSync(resolvedProjectPath).isDirectory()) {
|
|
299
|
-
|
|
318
|
+
utils_js_1.log.error(`zshy.tsconfig must point to a tsconfig.json file, not a directory: ${resolvedProjectPath}`);
|
|
300
319
|
process.exit(1);
|
|
301
320
|
}
|
|
302
321
|
else {
|
|
@@ -305,7 +324,7 @@ Examples:
|
|
|
305
324
|
}
|
|
306
325
|
}
|
|
307
326
|
else {
|
|
308
|
-
|
|
327
|
+
utils_js_1.log.error(`Tsconfig file not found: ${resolvedProjectPath}`);
|
|
309
328
|
process.exit(1);
|
|
310
329
|
}
|
|
311
330
|
}
|
|
@@ -316,10 +335,12 @@ Examples:
|
|
|
316
335
|
const _parsedConfig = (0, utils_js_1.readTsconfig)(tsconfigPath);
|
|
317
336
|
if (!fs.existsSync(tsconfigPath)) {
|
|
318
337
|
// Check if tsconfig.json exists
|
|
319
|
-
|
|
338
|
+
utils_js_1.log.error(`❌ tsconfig.json not found at ${(0, utils_js_1.toPosix)(path.resolve(tsconfigPath))}`);
|
|
320
339
|
process.exit(1);
|
|
321
340
|
}
|
|
322
|
-
(
|
|
341
|
+
if (!isSilent) {
|
|
342
|
+
utils_js_1.log.info(`Reading tsconfig from ./${(0, utils_js_1.relativePosix)(pkgJsonDir, tsconfigPath)}`);
|
|
343
|
+
}
|
|
323
344
|
// if (_parsedConfig.rootDir) {
|
|
324
345
|
// console.error(
|
|
325
346
|
// `❌ rootDir is determined from your set of entrypoints; you can remove it from your tsconfig.json.`,
|
|
@@ -353,17 +374,17 @@ Examples:
|
|
|
353
374
|
};
|
|
354
375
|
if (relOutDir === "") {
|
|
355
376
|
if (!pkgJson.files) {
|
|
356
|
-
|
|
377
|
+
utils_js_1.log.info('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.');
|
|
357
378
|
pkgJson.files = ["**/*.js", "**/*.mjs", "**/*.cjs", "**/*.d.ts", "**/*.d.mts", "**/*.d.cts"];
|
|
358
379
|
}
|
|
359
380
|
else {
|
|
360
|
-
|
|
361
|
-
Ensure that your "files" in package.json
|
|
381
|
+
utils_js_1.log.info(`You\'re building your code to the project root. This means your compiled files will be generated alongside your source files.
|
|
382
|
+
Ensure that your "files" in package.json does not include TypeScript source files, or your users may experience .d.ts resolution issues in some environments:
|
|
362
383
|
"files": ["**/*.js", "**/*.mjs", "**/*.cjs", "**/*.d.ts", "**/*.d.mts", "**/*.d.cts"]`);
|
|
363
384
|
}
|
|
364
385
|
}
|
|
365
386
|
else if (!pkgJson.files) {
|
|
366
|
-
|
|
387
|
+
utils_js_1.log.warn(`The "files" key is missing in package.json. Setting to "${relOutDir}".`);
|
|
367
388
|
pkgJson.files = [relOutDir];
|
|
368
389
|
if (relOutDir !== relDeclarationDir) {
|
|
369
390
|
pkgJson.files.push(relDeclarationDir);
|
|
@@ -373,7 +394,9 @@ Examples:
|
|
|
373
394
|
/// extract entry points ///
|
|
374
395
|
/////////////////////////////////
|
|
375
396
|
// Extract entry points from zshy exports config
|
|
376
|
-
(
|
|
397
|
+
if (!isSilent) {
|
|
398
|
+
utils_js_1.log.info("Determining entrypoints...");
|
|
399
|
+
}
|
|
377
400
|
const entryPoints = [];
|
|
378
401
|
const assetEntrypoints = [];
|
|
379
402
|
const rows = [["Subpath", "Entrypoint"]];
|
|
@@ -388,13 +411,13 @@ Examples:
|
|
|
388
411
|
cleanExportPath = pkgJson.name + "/" + exportPath.slice(2);
|
|
389
412
|
}
|
|
390
413
|
else {
|
|
391
|
-
|
|
414
|
+
utils_js_1.log.warn(`Invalid subpath export "${exportPath}" — should start with "./"`);
|
|
392
415
|
process.exit(1);
|
|
393
416
|
}
|
|
394
417
|
if (typeof sourcePath === "string") {
|
|
395
418
|
if (sourcePath.includes("*")) {
|
|
396
419
|
if (!sourcePath.endsWith("/*") && !sourcePath.endsWith("/**/*")) {
|
|
397
|
-
|
|
420
|
+
utils_js_1.log.error(`❌ Wildcard paths should end with /* or /**/* (for deep globs): ${sourcePath}`);
|
|
398
421
|
process.exit(1);
|
|
399
422
|
}
|
|
400
423
|
let pattern;
|
|
@@ -407,16 +430,23 @@ Examples:
|
|
|
407
430
|
pattern = sourcePath.slice(0, -2) + "/*.{ts,tsx,mts,cts}";
|
|
408
431
|
}
|
|
409
432
|
if (isVerbose) {
|
|
410
|
-
|
|
433
|
+
utils_js_1.log.info(`Matching glob: ${pattern}`);
|
|
411
434
|
}
|
|
412
435
|
const wildcardFiles = await (0, fast_glob_1.default)(pattern, {
|
|
413
436
|
ignore: ["**/*.d.ts", "**/*.d.mts", "**/*.d.cts"],
|
|
414
437
|
cwd: pkgJsonDir,
|
|
415
438
|
});
|
|
416
|
-
|
|
417
|
-
|
|
439
|
+
// Filter out test files (__tests__ directories, .test.*, .spec.*)
|
|
440
|
+
const filteredFiles = wildcardFiles.filter((file) => !(0, utils_js_1.isTestFile)(file));
|
|
441
|
+
entryPoints.push(...filteredFiles);
|
|
442
|
+
rows.push([`"${cleanExportPath}"`, `${sourcePath} (${filteredFiles.length} matches)`]);
|
|
418
443
|
}
|
|
419
444
|
else if ((0, utils_js_1.isSourceFile)(sourcePath)) {
|
|
445
|
+
// Skip test files even if explicitly specified
|
|
446
|
+
if ((0, utils_js_1.isTestFile)(sourcePath)) {
|
|
447
|
+
utils_js_1.log.warn(`Skipping test file: ${sourcePath}`);
|
|
448
|
+
continue;
|
|
449
|
+
}
|
|
420
450
|
entryPoints.push(sourcePath);
|
|
421
451
|
rows.push([`"${cleanExportPath}"`, sourcePath]);
|
|
422
452
|
}
|
|
@@ -432,32 +462,47 @@ Examples:
|
|
|
432
462
|
if (typeof config.bin === "string") {
|
|
433
463
|
// Single bin entry
|
|
434
464
|
if ((0, utils_js_1.isSourceFile)(config.bin)) {
|
|
435
|
-
|
|
436
|
-
|
|
465
|
+
if ((0, utils_js_1.isTestFile)(config.bin)) {
|
|
466
|
+
utils_js_1.log.warn(`Skipping test file in bin: ${config.bin}`);
|
|
467
|
+
}
|
|
468
|
+
else {
|
|
469
|
+
entryPoints.push(config.bin);
|
|
470
|
+
rows.push([`bin:${pkgJson.name}`, config.bin]);
|
|
471
|
+
}
|
|
437
472
|
}
|
|
438
473
|
}
|
|
439
474
|
else {
|
|
440
475
|
// Multiple bin entries
|
|
441
476
|
for (const [binName, sourcePath] of Object.entries(config.bin)) {
|
|
442
477
|
if (typeof sourcePath === "string" && (0, utils_js_1.isSourceFile)(sourcePath)) {
|
|
443
|
-
|
|
444
|
-
|
|
478
|
+
if ((0, utils_js_1.isTestFile)(sourcePath)) {
|
|
479
|
+
utils_js_1.log.warn(`Skipping test file in bin: ${sourcePath}`);
|
|
480
|
+
}
|
|
481
|
+
else {
|
|
482
|
+
entryPoints.push(sourcePath);
|
|
483
|
+
rows.push([`bin:${binName}`, sourcePath]);
|
|
484
|
+
}
|
|
445
485
|
}
|
|
446
486
|
}
|
|
447
487
|
}
|
|
448
488
|
}
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
lineIndex ===
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
489
|
+
if (!isSilent) {
|
|
490
|
+
const originalPrefix = utils_js_1.log.prefix;
|
|
491
|
+
utils_js_1.log.prefix = undefined;
|
|
492
|
+
utils_js_1.log.info(" " +
|
|
493
|
+
(0, table_1.table)(rows, {
|
|
494
|
+
drawHorizontalLine: (lineIndex, rowCount) => {
|
|
495
|
+
return (lineIndex === 0 ||
|
|
496
|
+
lineIndex === 1 ||
|
|
497
|
+
// lineIndex === rowCount - 1 ||
|
|
498
|
+
lineIndex === rowCount);
|
|
499
|
+
},
|
|
500
|
+
})
|
|
501
|
+
.split("\n")
|
|
502
|
+
.join("\n ")
|
|
503
|
+
.trim());
|
|
504
|
+
utils_js_1.log.prefix = originalPrefix;
|
|
505
|
+
}
|
|
461
506
|
// disallow .mts and .cts files
|
|
462
507
|
// if (entryPoints.some((ep) => ep.endsWith(".mts") || ep.endsWith(".cts"))) {
|
|
463
508
|
// emojiLog(
|
|
@@ -468,7 +513,7 @@ Examples:
|
|
|
468
513
|
// process.exit(1);
|
|
469
514
|
// }
|
|
470
515
|
if (entryPoints.length === 0) {
|
|
471
|
-
|
|
516
|
+
utils_js_1.log.error("❌ No entry points found matching the specified patterns in package.json#/zshy exports or bin");
|
|
472
517
|
process.exit(1);
|
|
473
518
|
}
|
|
474
519
|
///////////////////////////////
|
|
@@ -501,49 +546,62 @@ Examples:
|
|
|
501
546
|
//////////////////////////////////
|
|
502
547
|
/// display resolved paths ///
|
|
503
548
|
//////////////////////////////////
|
|
504
|
-
(
|
|
549
|
+
if (!isSilent) {
|
|
550
|
+
utils_js_1.log.info("Resolved build paths:");
|
|
551
|
+
}
|
|
505
552
|
const pathRows = [["Location", "Resolved path"]];
|
|
506
553
|
pathRows.push(["rootDir", relRootDir ? `./${relRootDir}` : "."]);
|
|
507
554
|
pathRows.push(["outDir", relOutDir ? `./${relOutDir}` : "."]);
|
|
508
555
|
if (relDeclarationDir !== relOutDir) {
|
|
509
556
|
pathRows.push(["declarationDir", relDeclarationDir ? `./${relDeclarationDir}` : "."]);
|
|
510
557
|
}
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
lineIndex ===
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
558
|
+
if (!isSilent) {
|
|
559
|
+
const originalPrefix = utils_js_1.log.prefix;
|
|
560
|
+
utils_js_1.log.prefix = undefined;
|
|
561
|
+
utils_js_1.log.info(" " +
|
|
562
|
+
(0, table_1.table)(pathRows, {
|
|
563
|
+
drawHorizontalLine: (lineIndex, rowCount) => {
|
|
564
|
+
return (lineIndex === 0 ||
|
|
565
|
+
lineIndex === 1 ||
|
|
566
|
+
// lineIndex === rowCount - 1 ||
|
|
567
|
+
lineIndex === rowCount);
|
|
568
|
+
},
|
|
569
|
+
})
|
|
570
|
+
.split("\n")
|
|
571
|
+
.join("\n ")
|
|
572
|
+
.trim());
|
|
573
|
+
utils_js_1.log.prefix = originalPrefix;
|
|
526
574
|
}
|
|
527
|
-
|
|
528
|
-
|
|
575
|
+
const isTypeModule = pkgJson.type === "module";
|
|
576
|
+
if (!isSilent) {
|
|
577
|
+
if (isTypeModule) {
|
|
578
|
+
utils_js_1.log.info(`Package is an ES module (package.json#/type is "module")`);
|
|
579
|
+
}
|
|
580
|
+
else {
|
|
581
|
+
utils_js_1.log.info(`Package is a CommonJS module (${pkgJson.type === "commonjs" ? 'package.json#/type is "commonjs"' : 'package.json#/type not set to "module"'})`);
|
|
582
|
+
}
|
|
529
583
|
}
|
|
530
584
|
//////////////////////////////////////////////
|
|
531
585
|
/// clean up outDir and declarationDir ///
|
|
532
586
|
//////////////////////////////////////////////
|
|
533
587
|
const prefix = isDryRun ? "[dryrun] " : "";
|
|
534
588
|
if (relRootDir.startsWith(relOutDir)) {
|
|
535
|
-
(
|
|
589
|
+
if (!isSilent) {
|
|
590
|
+
utils_js_1.log.info(`${prefix}Skipping cleanup of outDir as it contains source files`);
|
|
591
|
+
}
|
|
536
592
|
}
|
|
537
593
|
else {
|
|
538
594
|
// source files are in the outDir, so skip cleanup
|
|
539
595
|
// clean up outDir and declarationDir
|
|
540
|
-
(
|
|
596
|
+
if (!isSilent) {
|
|
597
|
+
utils_js_1.log.info(`${prefix}Cleaning up outDir...`);
|
|
598
|
+
}
|
|
541
599
|
if (!isDryRun) {
|
|
542
600
|
fs.rmSync(outDir, { recursive: true, force: true });
|
|
543
601
|
// // print success message in verbose mode
|
|
544
602
|
if (isVerbose) {
|
|
545
603
|
if (fs.existsSync(outDir)) {
|
|
546
|
-
|
|
604
|
+
utils_js_1.log.error(`❌ Failed to clean up outDir: ${relOutDir}. Directory still exists.`);
|
|
547
605
|
}
|
|
548
606
|
}
|
|
549
607
|
}
|
|
@@ -552,16 +610,20 @@ Examples:
|
|
|
552
610
|
// already done
|
|
553
611
|
}
|
|
554
612
|
else if (relRootDir.startsWith(relDeclarationDir)) {
|
|
555
|
-
(
|
|
613
|
+
if (!isSilent) {
|
|
614
|
+
utils_js_1.log.info(`${prefix}Skipping cleanup of declarationDir as it contains source files`);
|
|
615
|
+
}
|
|
556
616
|
}
|
|
557
617
|
else {
|
|
558
|
-
(
|
|
618
|
+
if (!isSilent) {
|
|
619
|
+
utils_js_1.log.info(`${prefix}Cleaning up declarationDir...`);
|
|
620
|
+
}
|
|
559
621
|
if (!isDryRun) {
|
|
560
622
|
fs.rmSync(declarationDir, { recursive: true, force: true });
|
|
561
623
|
// // print success message in verbose mode
|
|
562
624
|
if (isVerbose) {
|
|
563
625
|
if (fs.existsSync(declarationDir)) {
|
|
564
|
-
|
|
626
|
+
utils_js_1.log.error(`❌ Failed to clean up declarationDir: ${relDeclarationDir}. Directory still exists.`);
|
|
565
627
|
}
|
|
566
628
|
}
|
|
567
629
|
}
|
|
@@ -572,8 +634,8 @@ Examples:
|
|
|
572
634
|
const uniqueEntryPoints = [...new Set(entryPoints)];
|
|
573
635
|
// try {
|
|
574
636
|
if (isVerbose) {
|
|
575
|
-
|
|
576
|
-
|
|
637
|
+
utils_js_1.log.info(`Resolved entrypoints: ${(0, utils_js_1.formatForLog)(uniqueEntryPoints)}`);
|
|
638
|
+
utils_js_1.log.info(`Resolved compilerOptions: ${(0, utils_js_1.formatForLog)({
|
|
577
639
|
...tsconfigJson,
|
|
578
640
|
module: ts.ModuleKind[tsconfigJson.module],
|
|
579
641
|
moduleResolution: ts.ModuleResolutionKind[tsconfigJson.moduleResolution],
|
|
@@ -591,7 +653,9 @@ Examples:
|
|
|
591
653
|
const skipCjs = config.cjs === false;
|
|
592
654
|
// CJS
|
|
593
655
|
if (!skipCjs) {
|
|
594
|
-
(
|
|
656
|
+
if (!isSilent) {
|
|
657
|
+
utils_js_1.log.info(`Building CJS...${isTypeModule ? ` (rewriting .ts -> .cjs/.d.cts)` : ``}`);
|
|
658
|
+
}
|
|
595
659
|
await (0, compile_js_1.compileProject)({
|
|
596
660
|
configPath: tsconfigPath,
|
|
597
661
|
ext: isTypeModule ? "cjs" : "js",
|
|
@@ -610,10 +674,14 @@ Examples:
|
|
|
610
674
|
}, uniqueEntryPoints, buildContext);
|
|
611
675
|
}
|
|
612
676
|
else {
|
|
613
|
-
(
|
|
677
|
+
if (!isSilent) {
|
|
678
|
+
utils_js_1.log.info("Skipping CJS build (cjs: false)");
|
|
679
|
+
}
|
|
614
680
|
}
|
|
615
681
|
// ESM
|
|
616
|
-
(
|
|
682
|
+
if (!isSilent) {
|
|
683
|
+
utils_js_1.log.info(`Building ESM...${isTypeModule ? `` : ` (rewriting .ts -> .mjs/.d.mts)`}`);
|
|
684
|
+
}
|
|
617
685
|
await (0, compile_js_1.compileProject)({
|
|
618
686
|
configPath: tsconfigPath,
|
|
619
687
|
ext: isTypeModule ? "js" : "mjs",
|
|
@@ -635,14 +703,16 @@ Examples:
|
|
|
635
703
|
///////////////////////////////////
|
|
636
704
|
// Copy asset entrypoints to output directory
|
|
637
705
|
if (assetEntrypoints.length > 0) {
|
|
638
|
-
(
|
|
706
|
+
if (!isSilent) {
|
|
707
|
+
utils_js_1.log.info(`${prefix}Copying ${assetEntrypoints.length} asset${assetEntrypoints.length === 1 ? "" : "s"}...`);
|
|
708
|
+
}
|
|
639
709
|
for (const { sourcePath } of assetEntrypoints) {
|
|
640
710
|
const sourceFile = path.resolve(pkgJsonDir, sourcePath);
|
|
641
711
|
const relativePath = path.relative(rootDir, path.resolve(pkgJsonDir, sourcePath));
|
|
642
712
|
const destFile = path.resolve(outDir, relativePath);
|
|
643
713
|
const destDir = path.dirname(destFile);
|
|
644
714
|
if (!fs.existsSync(sourceFile)) {
|
|
645
|
-
|
|
715
|
+
utils_js_1.log.warn(`Asset not found: ${sourcePath}`);
|
|
646
716
|
continue;
|
|
647
717
|
}
|
|
648
718
|
if (!isDryRun) {
|
|
@@ -654,7 +724,7 @@ Examples:
|
|
|
654
724
|
if (isVerbose) {
|
|
655
725
|
const relativeSource = (0, utils_js_1.toPosix)(path.relative(pkgJsonDir, sourceFile));
|
|
656
726
|
const relativeDest = (0, utils_js_1.toPosix)(path.relative(pkgJsonDir, destFile));
|
|
657
|
-
|
|
727
|
+
utils_js_1.log.info(`${isDryRun ? "[dryrun] " : ""}Copied asset: ./${relativeSource} → ./${relativeDest}`);
|
|
658
728
|
}
|
|
659
729
|
}
|
|
660
730
|
}
|
|
@@ -663,26 +733,34 @@ Examples:
|
|
|
663
733
|
///////////////////////////////////
|
|
664
734
|
// Display files that were written or would be written (only in verbose mode)
|
|
665
735
|
if (isVerbose && buildContext.writtenFiles.size > 0) {
|
|
666
|
-
|
|
736
|
+
utils_js_1.log.info(`${prefix}Writing files (${buildContext.writtenFiles.size} total)...`);
|
|
667
737
|
// Sort files by relative path for consistent display
|
|
668
738
|
const sortedFiles = [...buildContext.writtenFiles]
|
|
669
739
|
.map((file) => (0, utils_js_1.relativePosix)(pkgJsonDir, file))
|
|
670
740
|
.sort()
|
|
671
741
|
.map((relPath) => (relPath.startsWith(".") ? relPath : `./${relPath}`));
|
|
742
|
+
// Temporarily disable prefix for individual file listings
|
|
743
|
+
const originalPrefix = utils_js_1.log.prefix;
|
|
744
|
+
utils_js_1.log.prefix = undefined;
|
|
672
745
|
sortedFiles.forEach((file) => {
|
|
673
|
-
|
|
746
|
+
utils_js_1.log.info(` ${file}`);
|
|
674
747
|
});
|
|
748
|
+
utils_js_1.log.prefix = originalPrefix;
|
|
675
749
|
}
|
|
676
750
|
///////////////////////////////
|
|
677
751
|
/// generate exports ///
|
|
678
752
|
///////////////////////////////
|
|
679
753
|
// generate package.json exports
|
|
680
754
|
if (config.noEdit) {
|
|
681
|
-
(
|
|
755
|
+
if (!isSilent) {
|
|
756
|
+
utils_js_1.log.info("[noedit] Skipping modification of package.json");
|
|
757
|
+
}
|
|
682
758
|
}
|
|
683
759
|
else {
|
|
684
760
|
// Generate exports based on zshy config
|
|
685
|
-
(
|
|
761
|
+
if (!isSilent) {
|
|
762
|
+
utils_js_1.log.info(`${prefix}Updating package.json...`);
|
|
763
|
+
}
|
|
686
764
|
const newExports = {};
|
|
687
765
|
if (config.exports) {
|
|
688
766
|
for (const [exportPath, sourcePath] of Object.entries(config.exports)) {
|
|
@@ -701,7 +779,7 @@ Examples:
|
|
|
701
779
|
// Handle wildcard exports
|
|
702
780
|
const finalExportPath = exportPath;
|
|
703
781
|
if (finalExportPath.includes("**")) {
|
|
704
|
-
|
|
782
|
+
utils_js_1.log.error(`❌ Export keys cannot contain "**": ${finalExportPath}`);
|
|
705
783
|
process.exit(1);
|
|
706
784
|
}
|
|
707
785
|
// Convert deep glob patterns to simple wildcard patterns in the final export
|
|
@@ -732,8 +810,13 @@ Examples:
|
|
|
732
810
|
}
|
|
733
811
|
// Add standard conditions
|
|
734
812
|
exportObj.types = relDtsPath;
|
|
735
|
-
|
|
736
|
-
|
|
813
|
+
if (skipCjs) {
|
|
814
|
+
// ESM-only: use default condition instead of import
|
|
815
|
+
exportObj.default = relJsPath;
|
|
816
|
+
}
|
|
817
|
+
else {
|
|
818
|
+
// Dual CJS/ESM: use import and require
|
|
819
|
+
exportObj.import = relJsPath;
|
|
737
820
|
exportObj.require = relJsPath;
|
|
738
821
|
}
|
|
739
822
|
newExports[finalExportPath] = exportObj;
|
|
@@ -762,8 +845,13 @@ Examples:
|
|
|
762
845
|
}
|
|
763
846
|
// Add standard conditions
|
|
764
847
|
exportObj.types = dtsPath;
|
|
765
|
-
|
|
766
|
-
|
|
848
|
+
if (skipCjs) {
|
|
849
|
+
// ESM-only: use default condition instead of import
|
|
850
|
+
exportObj.default = esmPath;
|
|
851
|
+
}
|
|
852
|
+
else {
|
|
853
|
+
// Dual CJS/ESM: use import and require
|
|
854
|
+
exportObj.import = esmPath;
|
|
767
855
|
exportObj.require = cjsPath;
|
|
768
856
|
}
|
|
769
857
|
newExports[exportPath] = exportObj;
|
|
@@ -779,9 +867,9 @@ Examples:
|
|
|
779
867
|
pkgJson.types = dtsPath;
|
|
780
868
|
}
|
|
781
869
|
if (isVerbose) {
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
870
|
+
utils_js_1.log.info(`Setting "main": ${(0, utils_js_1.formatForLog)(cjsPath)}`);
|
|
871
|
+
utils_js_1.log.info(`Setting "module": ${(0, utils_js_1.formatForLog)(esmPath)}`);
|
|
872
|
+
utils_js_1.log.info(`Setting "types": ${(0, utils_js_1.formatForLog)(dtsPath)}`);
|
|
785
873
|
}
|
|
786
874
|
}
|
|
787
875
|
}
|
|
@@ -811,15 +899,15 @@ Examples:
|
|
|
811
899
|
pkgJson.types = relAssetPath;
|
|
812
900
|
}
|
|
813
901
|
if (isVerbose) {
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
902
|
+
utils_js_1.log.info(`Setting "main": ${(0, utils_js_1.formatForLog)(relAssetPath)}`);
|
|
903
|
+
utils_js_1.log.info(`Setting "module": ${(0, utils_js_1.formatForLog)(relAssetPath)}`);
|
|
904
|
+
utils_js_1.log.info(`Setting "types": ${(0, utils_js_1.formatForLog)(relAssetPath)}`);
|
|
817
905
|
}
|
|
818
906
|
}
|
|
819
907
|
}
|
|
820
908
|
pkgJson.exports = newExports;
|
|
821
909
|
if (isVerbose) {
|
|
822
|
-
|
|
910
|
+
utils_js_1.log.info(`Setting "exports": ${(0, utils_js_1.formatForLog)(newExports)}`);
|
|
823
911
|
}
|
|
824
912
|
}
|
|
825
913
|
///////////////////////////////
|
|
@@ -851,14 +939,14 @@ Examples:
|
|
|
851
939
|
pkgJson.bin = newBin;
|
|
852
940
|
}
|
|
853
941
|
if (isVerbose) {
|
|
854
|
-
|
|
942
|
+
utils_js_1.log.info(`Setting "bin": ${(0, utils_js_1.formatForLog)(pkgJson.bin)}`);
|
|
855
943
|
}
|
|
856
944
|
}
|
|
857
945
|
if (isDryRun) {
|
|
858
946
|
///////////////////////////////
|
|
859
947
|
/// write pkg json ///
|
|
860
948
|
///////////////////////////////
|
|
861
|
-
|
|
949
|
+
utils_js_1.log.info("[dryrun] Skipping package.json modification");
|
|
862
950
|
}
|
|
863
951
|
else {
|
|
864
952
|
fs.writeFileSync(packageJsonPath, JSON.stringify(pkgJson, null, indent) + "\n");
|
|
@@ -866,7 +954,9 @@ Examples:
|
|
|
866
954
|
}
|
|
867
955
|
if (isAttw) {
|
|
868
956
|
// run `@arethetypeswrong/cli --pack .` to check types
|
|
869
|
-
(
|
|
957
|
+
if (!isSilent) {
|
|
958
|
+
utils_js_1.log.info("Checking types with @arethetypeswrong/cli...");
|
|
959
|
+
}
|
|
870
960
|
const { execFile } = await Promise.resolve().then(() => __importStar(require("node:child_process")));
|
|
871
961
|
const { promisify } = await Promise.resolve().then(() => __importStar(require("node:util")));
|
|
872
962
|
const execFileAsync = promisify(execFile);
|
|
@@ -895,39 +985,41 @@ Examples:
|
|
|
895
985
|
.map((line) => ` ${line}`)
|
|
896
986
|
.join("\n");
|
|
897
987
|
if (exitCode === 0) {
|
|
898
|
-
|
|
988
|
+
utils_js_1.log.info(indentedOutput);
|
|
899
989
|
}
|
|
900
990
|
else {
|
|
901
|
-
|
|
902
|
-
|
|
991
|
+
utils_js_1.log.error(indentedOutput);
|
|
992
|
+
utils_js_1.log.warn("ATTW found issues, but the build was not affected.");
|
|
903
993
|
}
|
|
904
994
|
}
|
|
905
995
|
}
|
|
906
996
|
// Report total compilation results
|
|
907
997
|
if (buildContext.errorCount > 0 || buildContext.warningCount > 0) {
|
|
908
|
-
|
|
998
|
+
utils_js_1.log.info(`Compilation finished with ${buildContext.errorCount} error${buildContext.errorCount === 1 ? "" : "s"} and ${buildContext.warningCount} warning${buildContext.warningCount === 1 ? "" : "s"}`);
|
|
909
999
|
// Apply threshold rules for exit code
|
|
910
1000
|
if (failThreshold !== "never" && buildContext.errorCount > 0) {
|
|
911
1001
|
// Both 'warn' and 'error' thresholds cause failure on errors
|
|
912
|
-
|
|
1002
|
+
utils_js_1.log.error("❌ Build completed with errors");
|
|
913
1003
|
process.exit(1);
|
|
914
1004
|
}
|
|
915
1005
|
else if (failThreshold === "warn" && buildContext.warningCount > 0) {
|
|
916
1006
|
// Only 'warn' threshold causes failure on warnings
|
|
917
|
-
|
|
1007
|
+
utils_js_1.log.warn(`Build completed with warnings (exiting with error due to --fail-threshold=warn)`);
|
|
918
1008
|
process.exit(1);
|
|
919
1009
|
}
|
|
920
1010
|
else if (buildContext.errorCount > 0) {
|
|
921
1011
|
// If we got here with errors, we're in 'never' mode
|
|
922
|
-
|
|
1012
|
+
utils_js_1.log.warn(`Build completed with errors (continuing due to --fail-threshold=never)`);
|
|
923
1013
|
}
|
|
924
1014
|
else {
|
|
925
1015
|
// Just warnings and not failing on them
|
|
926
|
-
|
|
1016
|
+
utils_js_1.log.info(`Build complete with warnings`);
|
|
927
1017
|
}
|
|
928
1018
|
}
|
|
929
1019
|
else {
|
|
930
|
-
|
|
1020
|
+
if (!isSilent) {
|
|
1021
|
+
utils_js_1.log.info("Build complete! ✅");
|
|
1022
|
+
}
|
|
931
1023
|
}
|
|
932
1024
|
}
|
|
933
1025
|
//# sourceMappingURL=main.js.map
|