sprint-es 0.0.110 → 0.0.111
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/cjs/cli.cjs +40 -12
- package/dist/esm/cli.js +40 -12
- package/package.json +1 -1
package/dist/cjs/cli.cjs
CHANGED
|
@@ -387,6 +387,30 @@ async function runDoctor() {
|
|
|
387
387
|
}
|
|
388
388
|
logger.break();
|
|
389
389
|
}
|
|
390
|
+
function fixBadRelativeImports(dir, projectRoot2) {
|
|
391
|
+
const nodeModulesPath = path.join(projectRoot2, "node_modules");
|
|
392
|
+
for (const file of fs.readdirSync(dir)) {
|
|
393
|
+
const fullPath = path.join(dir, file);
|
|
394
|
+
if (fs.statSync(fullPath).isDirectory()) fixBadRelativeImports(fullPath, projectRoot2);
|
|
395
|
+
else if (file.endsWith(".js")) {
|
|
396
|
+
const content = fs.readFileSync(fullPath, "utf-8");
|
|
397
|
+
const fixed = content.replace(
|
|
398
|
+
/require\(["'](\.\.?\/)+([^"'./][^"']*?)["']\)/g,
|
|
399
|
+
(match, dots, pkg) => {
|
|
400
|
+
if (fs.existsSync(path.join(nodeModulesPath, pkg))) return `require("${pkg}")`;
|
|
401
|
+
return match;
|
|
402
|
+
}
|
|
403
|
+
).replace(
|
|
404
|
+
/(require\(["'])(\.\.?\/[^"']+?)(["']\))/g,
|
|
405
|
+
(match, before, p, after) => {
|
|
406
|
+
if (/\.[a-z]+$/.test(p)) return match;
|
|
407
|
+
return `${before}${p}.js${after}`;
|
|
408
|
+
}
|
|
409
|
+
);
|
|
410
|
+
if (fixed !== content) fs.writeFileSync(fullPath, fixed);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
}
|
|
390
414
|
async function main() {
|
|
391
415
|
switch (command) {
|
|
392
416
|
case "dev": {
|
|
@@ -400,60 +424,64 @@ async function main() {
|
|
|
400
424
|
case "build": {
|
|
401
425
|
console.log("🚀 Building for production...");
|
|
402
426
|
const isTS = fs.existsSync(path.join(projectRoot, "sprint.config.ts"));
|
|
403
|
-
console.log(`[Sprint] Project type: ${isTS ? "TypeScript" : "JavaScript"}`);
|
|
404
|
-
console.log(`[Sprint] Project root: ${projectRoot}`);
|
|
405
427
|
const distPath = path.join(projectRoot, "dist");
|
|
428
|
+
const tsconfigPath = path.join(projectRoot, "tsconfig.json");
|
|
406
429
|
console.log("[Sprint] Cleaning dist...");
|
|
407
430
|
fs.rmSync(distPath, { recursive: true, force: true });
|
|
408
431
|
console.log("[Sprint] dist cleaned ✓");
|
|
409
432
|
if (isTS) {
|
|
410
|
-
const tsconfigPath = path.join(projectRoot, "tsconfig.json");
|
|
411
433
|
const tsconfig = JSON.parse(stripJsonComments(fs.readFileSync(tsconfigPath, "utf-8")));
|
|
412
434
|
const originalInclude = tsconfig.include ?? [];
|
|
413
435
|
const patched = originalInclude.filter((p) => !p.includes("sprint.config"));
|
|
414
436
|
const needsPatching = patched.length !== originalInclude.length;
|
|
415
|
-
console.log(`[Sprint] needs patching: ${needsPatching}`);
|
|
416
437
|
if (needsPatching) {
|
|
417
|
-
console.log("[Sprint] Patching tsconfig temporarily...");
|
|
418
438
|
fs.writeFileSync(tsconfigPath, JSON.stringify({ ...tsconfig, include: patched }, null, 4));
|
|
419
|
-
console.log("[Sprint] tsconfig patched ✓");
|
|
420
439
|
}
|
|
421
440
|
try {
|
|
422
441
|
console.log("[Sprint] Running tsc...");
|
|
423
442
|
await runCommand(`tsc --project "${tsconfigPath}"`, { NODE_ENV: "production" });
|
|
424
443
|
console.log("[Sprint] tsc completed ✓");
|
|
444
|
+
console.log("[Sprint] Fixing imports...");
|
|
445
|
+
fixBadRelativeImports(distPath, projectRoot);
|
|
446
|
+
console.log("[Sprint] Imports fixed ✓");
|
|
425
447
|
console.log("[Sprint] Running tsc-alias...");
|
|
426
448
|
await runCommand(`tsc-alias --project "${tsconfigPath}"`, { NODE_ENV: "production" });
|
|
427
449
|
console.log("[Sprint] tsc-alias completed ✓");
|
|
428
450
|
} finally {
|
|
429
451
|
if (needsPatching) {
|
|
430
|
-
console.log("[Sprint] Restoring tsconfig...");
|
|
431
452
|
fs.writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 4));
|
|
432
|
-
console.log("[Sprint] tsconfig restored ✓");
|
|
433
453
|
}
|
|
434
454
|
}
|
|
435
|
-
console.log("[Sprint] Compiling sprint.config.ts
|
|
455
|
+
console.log("[Sprint] Compiling sprint.config.ts...");
|
|
436
456
|
await runCommand(
|
|
437
|
-
`esbuild "${path.join(projectRoot, "sprint.config.ts")}" --outfile="${path.join(projectRoot, "dist/sprint.config.js")}" --platform=node --format=
|
|
457
|
+
`esbuild "${path.join(projectRoot, "sprint.config.ts")}" --outfile="${path.join(projectRoot, "dist/sprint.config.js")}" --platform=node --format=cjs --bundle=false`,
|
|
438
458
|
{ NODE_ENV: "production" }
|
|
439
459
|
);
|
|
440
460
|
console.log("[Sprint] sprint.config.js generated ✓");
|
|
441
461
|
} else {
|
|
442
|
-
const tsconfigPath = path.join(projectRoot, "tsconfig.json");
|
|
443
462
|
console.log("[Sprint] Running tsc...");
|
|
444
463
|
await runCommand(`tsc --project "${tsconfigPath}"`, { NODE_ENV: "production" });
|
|
445
464
|
console.log("[Sprint] tsc completed ✓");
|
|
465
|
+
console.log("[Sprint] Fixing imports...");
|
|
466
|
+
fixBadRelativeImports(distPath, projectRoot);
|
|
467
|
+
console.log("[Sprint] Imports fixed ✓");
|
|
446
468
|
console.log("[Sprint] Running tsc-alias...");
|
|
447
469
|
await runCommand(`tsc-alias --project "${tsconfigPath}"`, { NODE_ENV: "production" });
|
|
448
470
|
console.log("[Sprint] tsc-alias completed ✓");
|
|
449
471
|
}
|
|
472
|
+
console.log("✅ Build completed successfully!");
|
|
450
473
|
break;
|
|
451
474
|
}
|
|
452
475
|
case "start": {
|
|
453
476
|
console.log("🚀 Starting production server...");
|
|
454
477
|
const isTS = fs.existsSync(path.join(projectRoot, "sprint.config.ts"));
|
|
455
478
|
const entryFile = isTS ? fs.existsSync(path.join(projectRoot, "dist/app.js")) ? "dist/app.js" : "dist/index.js" : fs.existsSync(path.join(projectRoot, "src/app.js")) ? "src/app.js" : "src/index.js";
|
|
456
|
-
|
|
479
|
+
if (!fs.existsSync(path.join(projectRoot, entryFile))) {
|
|
480
|
+
console.error(`[Sprint] Entry file not found: ${entryFile}`);
|
|
481
|
+
console.error("[Sprint] Did you run 'npm run build' first?");
|
|
482
|
+
process.exit(1);
|
|
483
|
+
}
|
|
484
|
+
await runCommand(`node "${path.join(projectRoot, entryFile)}"`, { NODE_ENV: "production" });
|
|
457
485
|
break;
|
|
458
486
|
}
|
|
459
487
|
case "doctor":
|
package/dist/esm/cli.js
CHANGED
|
@@ -368,6 +368,30 @@ async function runDoctor() {
|
|
|
368
368
|
}
|
|
369
369
|
logger.break();
|
|
370
370
|
}
|
|
371
|
+
function fixBadRelativeImports(dir, projectRoot2) {
|
|
372
|
+
const nodeModulesPath = join(projectRoot2, "node_modules");
|
|
373
|
+
for (const file of readdirSync(dir)) {
|
|
374
|
+
const fullPath = join(dir, file);
|
|
375
|
+
if (statSync(fullPath).isDirectory()) fixBadRelativeImports(fullPath, projectRoot2);
|
|
376
|
+
else if (file.endsWith(".js")) {
|
|
377
|
+
const content = readFileSync(fullPath, "utf-8");
|
|
378
|
+
const fixed = content.replace(
|
|
379
|
+
/require\(["'](\.\.?\/)+([^"'./][^"']*?)["']\)/g,
|
|
380
|
+
(match, dots, pkg) => {
|
|
381
|
+
if (existsSync(join(nodeModulesPath, pkg))) return `require("${pkg}")`;
|
|
382
|
+
return match;
|
|
383
|
+
}
|
|
384
|
+
).replace(
|
|
385
|
+
/(require\(["'])(\.\.?\/[^"']+?)(["']\))/g,
|
|
386
|
+
(match, before, p, after) => {
|
|
387
|
+
if (/\.[a-z]+$/.test(p)) return match;
|
|
388
|
+
return `${before}${p}.js${after}`;
|
|
389
|
+
}
|
|
390
|
+
);
|
|
391
|
+
if (fixed !== content) writeFileSync(fullPath, fixed);
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
}
|
|
371
395
|
async function main() {
|
|
372
396
|
switch (command) {
|
|
373
397
|
case "dev": {
|
|
@@ -381,60 +405,64 @@ async function main() {
|
|
|
381
405
|
case "build": {
|
|
382
406
|
console.log("🚀 Building for production...");
|
|
383
407
|
const isTS = existsSync(join(projectRoot, "sprint.config.ts"));
|
|
384
|
-
console.log(`[Sprint] Project type: ${isTS ? "TypeScript" : "JavaScript"}`);
|
|
385
|
-
console.log(`[Sprint] Project root: ${projectRoot}`);
|
|
386
408
|
const distPath = join(projectRoot, "dist");
|
|
409
|
+
const tsconfigPath = join(projectRoot, "tsconfig.json");
|
|
387
410
|
console.log("[Sprint] Cleaning dist...");
|
|
388
411
|
rmSync(distPath, { recursive: true, force: true });
|
|
389
412
|
console.log("[Sprint] dist cleaned ✓");
|
|
390
413
|
if (isTS) {
|
|
391
|
-
const tsconfigPath = join(projectRoot, "tsconfig.json");
|
|
392
414
|
const tsconfig = JSON.parse(stripJsonComments(readFileSync(tsconfigPath, "utf-8")));
|
|
393
415
|
const originalInclude = tsconfig.include ?? [];
|
|
394
416
|
const patched = originalInclude.filter((p) => !p.includes("sprint.config"));
|
|
395
417
|
const needsPatching = patched.length !== originalInclude.length;
|
|
396
|
-
console.log(`[Sprint] needs patching: ${needsPatching}`);
|
|
397
418
|
if (needsPatching) {
|
|
398
|
-
console.log("[Sprint] Patching tsconfig temporarily...");
|
|
399
419
|
writeFileSync(tsconfigPath, JSON.stringify({ ...tsconfig, include: patched }, null, 4));
|
|
400
|
-
console.log("[Sprint] tsconfig patched ✓");
|
|
401
420
|
}
|
|
402
421
|
try {
|
|
403
422
|
console.log("[Sprint] Running tsc...");
|
|
404
423
|
await runCommand(`tsc --project "${tsconfigPath}"`, { NODE_ENV: "production" });
|
|
405
424
|
console.log("[Sprint] tsc completed ✓");
|
|
425
|
+
console.log("[Sprint] Fixing imports...");
|
|
426
|
+
fixBadRelativeImports(distPath, projectRoot);
|
|
427
|
+
console.log("[Sprint] Imports fixed ✓");
|
|
406
428
|
console.log("[Sprint] Running tsc-alias...");
|
|
407
429
|
await runCommand(`tsc-alias --project "${tsconfigPath}"`, { NODE_ENV: "production" });
|
|
408
430
|
console.log("[Sprint] tsc-alias completed ✓");
|
|
409
431
|
} finally {
|
|
410
432
|
if (needsPatching) {
|
|
411
|
-
console.log("[Sprint] Restoring tsconfig...");
|
|
412
433
|
writeFileSync(tsconfigPath, JSON.stringify(tsconfig, null, 4));
|
|
413
|
-
console.log("[Sprint] tsconfig restored ✓");
|
|
414
434
|
}
|
|
415
435
|
}
|
|
416
|
-
console.log("[Sprint] Compiling sprint.config.ts
|
|
436
|
+
console.log("[Sprint] Compiling sprint.config.ts...");
|
|
417
437
|
await runCommand(
|
|
418
|
-
`esbuild "${join(projectRoot, "sprint.config.ts")}" --outfile="${join(projectRoot, "dist/sprint.config.js")}" --platform=node --format=
|
|
438
|
+
`esbuild "${join(projectRoot, "sprint.config.ts")}" --outfile="${join(projectRoot, "dist/sprint.config.js")}" --platform=node --format=cjs --bundle=false`,
|
|
419
439
|
{ NODE_ENV: "production" }
|
|
420
440
|
);
|
|
421
441
|
console.log("[Sprint] sprint.config.js generated ✓");
|
|
422
442
|
} else {
|
|
423
|
-
const tsconfigPath = join(projectRoot, "tsconfig.json");
|
|
424
443
|
console.log("[Sprint] Running tsc...");
|
|
425
444
|
await runCommand(`tsc --project "${tsconfigPath}"`, { NODE_ENV: "production" });
|
|
426
445
|
console.log("[Sprint] tsc completed ✓");
|
|
446
|
+
console.log("[Sprint] Fixing imports...");
|
|
447
|
+
fixBadRelativeImports(distPath, projectRoot);
|
|
448
|
+
console.log("[Sprint] Imports fixed ✓");
|
|
427
449
|
console.log("[Sprint] Running tsc-alias...");
|
|
428
450
|
await runCommand(`tsc-alias --project "${tsconfigPath}"`, { NODE_ENV: "production" });
|
|
429
451
|
console.log("[Sprint] tsc-alias completed ✓");
|
|
430
452
|
}
|
|
453
|
+
console.log("✅ Build completed successfully!");
|
|
431
454
|
break;
|
|
432
455
|
}
|
|
433
456
|
case "start": {
|
|
434
457
|
console.log("🚀 Starting production server...");
|
|
435
458
|
const isTS = existsSync(join(projectRoot, "sprint.config.ts"));
|
|
436
459
|
const entryFile = isTS ? existsSync(join(projectRoot, "dist/app.js")) ? "dist/app.js" : "dist/index.js" : existsSync(join(projectRoot, "src/app.js")) ? "src/app.js" : "src/index.js";
|
|
437
|
-
|
|
460
|
+
if (!existsSync(join(projectRoot, entryFile))) {
|
|
461
|
+
console.error(`[Sprint] Entry file not found: ${entryFile}`);
|
|
462
|
+
console.error("[Sprint] Did you run 'npm run build' first?");
|
|
463
|
+
process.exit(1);
|
|
464
|
+
}
|
|
465
|
+
await runCommand(`node "${join(projectRoot, entryFile)}"`, { NODE_ENV: "production" });
|
|
438
466
|
break;
|
|
439
467
|
}
|
|
440
468
|
case "doctor":
|