sprint-es 0.0.133 → 0.0.135
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 +23 -4
- package/dist/cjs/index.cjs +20 -12
- package/dist/esm/cli.js +23 -4
- package/dist/esm/index.js +20 -12
- package/dist/types/sprint.d.ts +1 -0
- package/dist/types/sprint.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/cjs/cli.cjs
CHANGED
|
@@ -425,10 +425,29 @@ async function main() {
|
|
|
425
425
|
case "start": {
|
|
426
426
|
console.log("🚀 Starting production server...");
|
|
427
427
|
const isTS = fs.existsSync(path.join(projectRoot, "sprint.config.ts"));
|
|
428
|
-
|
|
429
|
-
if (
|
|
430
|
-
|
|
431
|
-
|
|
428
|
+
let entryFile = null;
|
|
429
|
+
if (isTS) {
|
|
430
|
+
const candidates = [
|
|
431
|
+
"dist/app.mjs",
|
|
432
|
+
"dist/app.js",
|
|
433
|
+
"dist/index.mjs",
|
|
434
|
+
"dist/index.js"
|
|
435
|
+
];
|
|
436
|
+
entryFile = candidates.find((f) => fs.existsSync(path.join(projectRoot, f))) ?? null;
|
|
437
|
+
} else {
|
|
438
|
+
const candidates = [
|
|
439
|
+
"src/app.js",
|
|
440
|
+
"src/app.mjs",
|
|
441
|
+
"src/index.js",
|
|
442
|
+
"src/index.mjs"
|
|
443
|
+
];
|
|
444
|
+
entryFile = candidates.find((f) => fs.existsSync(path.join(projectRoot, f))) ?? null;
|
|
445
|
+
}
|
|
446
|
+
if (!entryFile) {
|
|
447
|
+
console.error(`[Sprint] Entry file not found.`);
|
|
448
|
+
console.error(
|
|
449
|
+
isTS ? "[Sprint] Did you run 'sprint-es build' first? Expected dist/app.mjs or dist/index.mjs" : "[Sprint] Expected src/app.js or src/index.js"
|
|
450
|
+
);
|
|
432
451
|
process.exit(1);
|
|
433
452
|
}
|
|
434
453
|
await runCommand(`node "${path.join(projectRoot, entryFile)}"`, { NODE_ENV: "production" });
|
package/dist/cjs/index.cjs
CHANGED
|
@@ -103,7 +103,7 @@ async function loadSprintConfig() {
|
|
|
103
103
|
const callerDir = process.cwd();
|
|
104
104
|
const projectRoot = await findProjectRoot(callerDir);
|
|
105
105
|
if (!projectRoot) return null;
|
|
106
|
-
const configFiles = isProd ? ["sprint.config.js", "dist/sprint.config.
|
|
106
|
+
const configFiles = isProd ? ["dist/sprint.config.js", "sprint.config.js", "dist/sprint.config.mjs"] : ["sprint.config.ts", "sprint.config.js"];
|
|
107
107
|
for (const configFile of configFiles) {
|
|
108
108
|
const configPath = path.join(projectRoot, configFile);
|
|
109
109
|
if (!fs.existsSync(configPath)) continue;
|
|
@@ -127,6 +127,7 @@ class Sprint {
|
|
|
127
127
|
this.urlEncodedLimit = "50mb";
|
|
128
128
|
this.prefix = "";
|
|
129
129
|
this.loadedMiddlewares = [];
|
|
130
|
+
this.counters = { routes: 0, middlewares: 0, cronjobs: 0 };
|
|
130
131
|
this.openapi = {
|
|
131
132
|
generateOnBuild: false,
|
|
132
133
|
path: "/openapi.json",
|
|
@@ -265,16 +266,23 @@ class Sprint {
|
|
|
265
266
|
console.warn("[Sprint] Failed to load graphql-http or ruru:", err);
|
|
266
267
|
}
|
|
267
268
|
}
|
|
269
|
+
this.loadNotFound();
|
|
268
270
|
if (finalConfig.autoListen) this.listen();
|
|
269
271
|
});
|
|
270
272
|
});
|
|
271
273
|
}
|
|
272
274
|
async init() {
|
|
273
275
|
const callerDir = process.cwd();
|
|
274
|
-
console.log("CWD:", process.cwd());
|
|
275
276
|
const normalizePath = (p) => {
|
|
276
|
-
|
|
277
|
-
|
|
277
|
+
const clean = p.replace(/^\.\//, "");
|
|
278
|
+
if (isProd) {
|
|
279
|
+
if (clean.startsWith("dist/")) return clean;
|
|
280
|
+
const callerDir2 = process.cwd();
|
|
281
|
+
const isTsProject = fs.existsSync(path.join(callerDir2, "tsconfig.json")) || fs.existsSync(path.join(callerDir2, "sprint.config.ts"));
|
|
282
|
+
if (isTsProject && clean.startsWith("src/")) return clean.replace("src/", "dist/");
|
|
283
|
+
if (isTsProject && !clean.includes("/")) return path.join("dist", clean);
|
|
284
|
+
}
|
|
285
|
+
return clean;
|
|
278
286
|
};
|
|
279
287
|
const middlewaresCandidate = normalizePath(this.middlewaresPath);
|
|
280
288
|
const routesCandidate = normalizePath(this.routesPath);
|
|
@@ -370,7 +378,7 @@ class Sprint {
|
|
|
370
378
|
* Load all middleware files from the middlewares folder
|
|
371
379
|
*/
|
|
372
380
|
async loadMiddlewares(middlewaresPath) {
|
|
373
|
-
const fileExtensions = isProd ? [".
|
|
381
|
+
const fileExtensions = isProd ? [".mjs", ".js"] : [".ts"];
|
|
374
382
|
const files = await fs.promises.readdir(middlewaresPath);
|
|
375
383
|
for (const file of files) {
|
|
376
384
|
const filePath = path.join(middlewaresPath, file);
|
|
@@ -387,6 +395,7 @@ class Sprint {
|
|
|
387
395
|
name,
|
|
388
396
|
filePath
|
|
389
397
|
});
|
|
398
|
+
this.counters.middlewares++;
|
|
390
399
|
if (isVerbose) console.log(`[Sprint] Loaded middleware: ${name} (priority: ${config.priority ?? 100})`);
|
|
391
400
|
}
|
|
392
401
|
} catch (err) {
|
|
@@ -409,7 +418,7 @@ class Sprint {
|
|
|
409
418
|
});
|
|
410
419
|
}
|
|
411
420
|
async loadRoutes(routesPath) {
|
|
412
|
-
const fileExtensions = isProd ? [".
|
|
421
|
+
const fileExtensions = isProd ? [".mjs", ".js"] : [".ts"];
|
|
413
422
|
const walkDir = async (dir) => {
|
|
414
423
|
const files = await fs.promises.readdir(dir);
|
|
415
424
|
for (const file of files) {
|
|
@@ -422,7 +431,7 @@ class Sprint {
|
|
|
422
431
|
const module2 = await import(moduleUrl);
|
|
423
432
|
const router = module2.default || module2.router;
|
|
424
433
|
if (router && typeof router === "function" && router.stack && Array.isArray(router.stack)) {
|
|
425
|
-
let routePath = "/" + path.relative(routesPath, filePath).replace(/\.(ts|js)$/, "").replace(/\\/g, "/");
|
|
434
|
+
let routePath = "/" + path.relative(routesPath, filePath).replace(/\.(ts|js|mjs)$/, "").replace(/\\/g, "/");
|
|
426
435
|
routePath = stripRouteGroups(routePath);
|
|
427
436
|
if (routePath.endsWith("/index")) routePath = routePath.slice(0, -6) || "/";
|
|
428
437
|
const fullRoute = this.prefix + (routePath === "/" ? "" : routePath);
|
|
@@ -458,6 +467,7 @@ class Sprint {
|
|
|
458
467
|
this.app.use(finalRoute, router);
|
|
459
468
|
if (isVerbose) console.log(`[Sprint] Loaded route: ${finalRoute} -> ${filePath}`);
|
|
460
469
|
}
|
|
470
|
+
this.counters.routes += router.stack.length;
|
|
461
471
|
}
|
|
462
472
|
} catch (err) {
|
|
463
473
|
console.warn(`[Sprint] Failed to load route ${filePath}:`, err);
|
|
@@ -468,7 +478,7 @@ class Sprint {
|
|
|
468
478
|
await walkDir(routesPath);
|
|
469
479
|
}
|
|
470
480
|
async loadCronJobs(cronjobsPath) {
|
|
471
|
-
const fileExtensions = isProd ? [".
|
|
481
|
+
const fileExtensions = isProd ? [".mjs", ".js"] : [".ts"];
|
|
472
482
|
const files = await fs.promises.readdir(cronjobsPath);
|
|
473
483
|
for (const file of files) {
|
|
474
484
|
const filePath = path.join(cronjobsPath, file);
|
|
@@ -478,6 +488,7 @@ class Sprint {
|
|
|
478
488
|
const moduleUrl = url.pathToFileURL(filePath).href;
|
|
479
489
|
await import(moduleUrl);
|
|
480
490
|
if (isVerbose) console.log(`[Sprint] Loaded cronjob: ${file.replace(/\.(ts|js)$/, "")}`);
|
|
491
|
+
this.counters.cronjobs++;
|
|
481
492
|
} catch (err) {
|
|
482
493
|
console.warn(`[Sprint] Failed to load cronjob ${filePath}:`, err);
|
|
483
494
|
}
|
|
@@ -816,10 +827,7 @@ class Sprint {
|
|
|
816
827
|
});
|
|
817
828
|
};
|
|
818
829
|
tryListen(basePort);
|
|
819
|
-
|
|
820
|
-
this.loadNotFound();
|
|
821
|
-
if (callback) callback();
|
|
822
|
-
});
|
|
830
|
+
if (callback) callback();
|
|
823
831
|
}
|
|
824
832
|
}
|
|
825
833
|
function createSchemaValidationMiddleware(schema) {
|
package/dist/esm/cli.js
CHANGED
|
@@ -406,10 +406,29 @@ async function main() {
|
|
|
406
406
|
case "start": {
|
|
407
407
|
console.log("🚀 Starting production server...");
|
|
408
408
|
const isTS = existsSync(join(projectRoot, "sprint.config.ts"));
|
|
409
|
-
|
|
410
|
-
if (
|
|
411
|
-
|
|
412
|
-
|
|
409
|
+
let entryFile = null;
|
|
410
|
+
if (isTS) {
|
|
411
|
+
const candidates = [
|
|
412
|
+
"dist/app.mjs",
|
|
413
|
+
"dist/app.js",
|
|
414
|
+
"dist/index.mjs",
|
|
415
|
+
"dist/index.js"
|
|
416
|
+
];
|
|
417
|
+
entryFile = candidates.find((f) => existsSync(join(projectRoot, f))) ?? null;
|
|
418
|
+
} else {
|
|
419
|
+
const candidates = [
|
|
420
|
+
"src/app.js",
|
|
421
|
+
"src/app.mjs",
|
|
422
|
+
"src/index.js",
|
|
423
|
+
"src/index.mjs"
|
|
424
|
+
];
|
|
425
|
+
entryFile = candidates.find((f) => existsSync(join(projectRoot, f))) ?? null;
|
|
426
|
+
}
|
|
427
|
+
if (!entryFile) {
|
|
428
|
+
console.error(`[Sprint] Entry file not found.`);
|
|
429
|
+
console.error(
|
|
430
|
+
isTS ? "[Sprint] Did you run 'sprint-es build' first? Expected dist/app.mjs or dist/index.mjs" : "[Sprint] Expected src/app.js or src/index.js"
|
|
431
|
+
);
|
|
413
432
|
process.exit(1);
|
|
414
433
|
}
|
|
415
434
|
await runCommand(`node "${join(projectRoot, entryFile)}"`, { NODE_ENV: "production" });
|
package/dist/esm/index.js
CHANGED
|
@@ -78,7 +78,7 @@ async function loadSprintConfig() {
|
|
|
78
78
|
const callerDir = process.cwd();
|
|
79
79
|
const projectRoot = await findProjectRoot(callerDir);
|
|
80
80
|
if (!projectRoot) return null;
|
|
81
|
-
const configFiles = isProd ? ["sprint.config.js", "dist/sprint.config.
|
|
81
|
+
const configFiles = isProd ? ["dist/sprint.config.js", "sprint.config.js", "dist/sprint.config.mjs"] : ["sprint.config.ts", "sprint.config.js"];
|
|
82
82
|
for (const configFile of configFiles) {
|
|
83
83
|
const configPath = path.join(projectRoot, configFile);
|
|
84
84
|
if (!fs.existsSync(configPath)) continue;
|
|
@@ -102,6 +102,7 @@ class Sprint {
|
|
|
102
102
|
this.urlEncodedLimit = "50mb";
|
|
103
103
|
this.prefix = "";
|
|
104
104
|
this.loadedMiddlewares = [];
|
|
105
|
+
this.counters = { routes: 0, middlewares: 0, cronjobs: 0 };
|
|
105
106
|
this.openapi = {
|
|
106
107
|
generateOnBuild: false,
|
|
107
108
|
path: "/openapi.json",
|
|
@@ -240,16 +241,23 @@ class Sprint {
|
|
|
240
241
|
console.warn("[Sprint] Failed to load graphql-http or ruru:", err);
|
|
241
242
|
}
|
|
242
243
|
}
|
|
244
|
+
this.loadNotFound();
|
|
243
245
|
if (finalConfig.autoListen) this.listen();
|
|
244
246
|
});
|
|
245
247
|
});
|
|
246
248
|
}
|
|
247
249
|
async init() {
|
|
248
250
|
const callerDir = process.cwd();
|
|
249
|
-
console.log("CWD:", process.cwd());
|
|
250
251
|
const normalizePath = (p) => {
|
|
251
|
-
|
|
252
|
-
|
|
252
|
+
const clean = p.replace(/^\.\//, "");
|
|
253
|
+
if (isProd) {
|
|
254
|
+
if (clean.startsWith("dist/")) return clean;
|
|
255
|
+
const callerDir2 = process.cwd();
|
|
256
|
+
const isTsProject = fs.existsSync(path.join(callerDir2, "tsconfig.json")) || fs.existsSync(path.join(callerDir2, "sprint.config.ts"));
|
|
257
|
+
if (isTsProject && clean.startsWith("src/")) return clean.replace("src/", "dist/");
|
|
258
|
+
if (isTsProject && !clean.includes("/")) return path.join("dist", clean);
|
|
259
|
+
}
|
|
260
|
+
return clean;
|
|
253
261
|
};
|
|
254
262
|
const middlewaresCandidate = normalizePath(this.middlewaresPath);
|
|
255
263
|
const routesCandidate = normalizePath(this.routesPath);
|
|
@@ -345,7 +353,7 @@ class Sprint {
|
|
|
345
353
|
* Load all middleware files from the middlewares folder
|
|
346
354
|
*/
|
|
347
355
|
async loadMiddlewares(middlewaresPath) {
|
|
348
|
-
const fileExtensions = isProd ? [".
|
|
356
|
+
const fileExtensions = isProd ? [".mjs", ".js"] : [".ts"];
|
|
349
357
|
const files = await fs.promises.readdir(middlewaresPath);
|
|
350
358
|
for (const file of files) {
|
|
351
359
|
const filePath = path.join(middlewaresPath, file);
|
|
@@ -362,6 +370,7 @@ class Sprint {
|
|
|
362
370
|
name,
|
|
363
371
|
filePath
|
|
364
372
|
});
|
|
373
|
+
this.counters.middlewares++;
|
|
365
374
|
if (isVerbose) console.log(`[Sprint] Loaded middleware: ${name} (priority: ${config.priority ?? 100})`);
|
|
366
375
|
}
|
|
367
376
|
} catch (err) {
|
|
@@ -384,7 +393,7 @@ class Sprint {
|
|
|
384
393
|
});
|
|
385
394
|
}
|
|
386
395
|
async loadRoutes(routesPath) {
|
|
387
|
-
const fileExtensions = isProd ? [".
|
|
396
|
+
const fileExtensions = isProd ? [".mjs", ".js"] : [".ts"];
|
|
388
397
|
const walkDir = async (dir) => {
|
|
389
398
|
const files = await fs.promises.readdir(dir);
|
|
390
399
|
for (const file of files) {
|
|
@@ -397,7 +406,7 @@ class Sprint {
|
|
|
397
406
|
const module = await import(moduleUrl);
|
|
398
407
|
const router = module.default || module.router;
|
|
399
408
|
if (router && typeof router === "function" && router.stack && Array.isArray(router.stack)) {
|
|
400
|
-
let routePath = "/" + path.relative(routesPath, filePath).replace(/\.(ts|js)$/, "").replace(/\\/g, "/");
|
|
409
|
+
let routePath = "/" + path.relative(routesPath, filePath).replace(/\.(ts|js|mjs)$/, "").replace(/\\/g, "/");
|
|
401
410
|
routePath = stripRouteGroups(routePath);
|
|
402
411
|
if (routePath.endsWith("/index")) routePath = routePath.slice(0, -6) || "/";
|
|
403
412
|
const fullRoute = this.prefix + (routePath === "/" ? "" : routePath);
|
|
@@ -433,6 +442,7 @@ class Sprint {
|
|
|
433
442
|
this.app.use(finalRoute, router);
|
|
434
443
|
if (isVerbose) console.log(`[Sprint] Loaded route: ${finalRoute} -> ${filePath}`);
|
|
435
444
|
}
|
|
445
|
+
this.counters.routes += router.stack.length;
|
|
436
446
|
}
|
|
437
447
|
} catch (err) {
|
|
438
448
|
console.warn(`[Sprint] Failed to load route ${filePath}:`, err);
|
|
@@ -443,7 +453,7 @@ class Sprint {
|
|
|
443
453
|
await walkDir(routesPath);
|
|
444
454
|
}
|
|
445
455
|
async loadCronJobs(cronjobsPath) {
|
|
446
|
-
const fileExtensions = isProd ? [".
|
|
456
|
+
const fileExtensions = isProd ? [".mjs", ".js"] : [".ts"];
|
|
447
457
|
const files = await fs.promises.readdir(cronjobsPath);
|
|
448
458
|
for (const file of files) {
|
|
449
459
|
const filePath = path.join(cronjobsPath, file);
|
|
@@ -453,6 +463,7 @@ class Sprint {
|
|
|
453
463
|
const moduleUrl = pathToFileURL(filePath).href;
|
|
454
464
|
await import(moduleUrl);
|
|
455
465
|
if (isVerbose) console.log(`[Sprint] Loaded cronjob: ${file.replace(/\.(ts|js)$/, "")}`);
|
|
466
|
+
this.counters.cronjobs++;
|
|
456
467
|
} catch (err) {
|
|
457
468
|
console.warn(`[Sprint] Failed to load cronjob ${filePath}:`, err);
|
|
458
469
|
}
|
|
@@ -791,10 +802,7 @@ class Sprint {
|
|
|
791
802
|
});
|
|
792
803
|
};
|
|
793
804
|
tryListen(basePort);
|
|
794
|
-
|
|
795
|
-
this.loadNotFound();
|
|
796
|
-
if (callback) callback();
|
|
797
|
-
});
|
|
805
|
+
if (callback) callback();
|
|
798
806
|
}
|
|
799
807
|
}
|
|
800
808
|
function createSchemaValidationMiddleware(schema) {
|
package/dist/types/sprint.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sprint.d.ts","sourceRoot":"","sources":["../../src/sprint.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,OAAO,EAA+B,gBAAgB,EAAoB,MAA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