sprint-es 0.0.132 → 0.0.134
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/index.cjs +16 -9
- package/dist/esm/index.js +16 -9
- package/dist/types/sprint.d.ts.map +1 -1
- package/package.json +1 -1
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;
|
|
@@ -272,8 +272,15 @@ class Sprint {
|
|
|
272
272
|
async init() {
|
|
273
273
|
const callerDir = process.cwd();
|
|
274
274
|
const normalizePath = (p) => {
|
|
275
|
-
|
|
276
|
-
|
|
275
|
+
const clean = p.replace(/^\.\//, "");
|
|
276
|
+
if (isProd) {
|
|
277
|
+
if (clean.startsWith("dist/")) return clean;
|
|
278
|
+
const callerDir2 = process.cwd();
|
|
279
|
+
const isTsProject = fs.existsSync(path.join(callerDir2, "tsconfig.json")) || fs.existsSync(path.join(callerDir2, "sprint.config.ts"));
|
|
280
|
+
if (isTsProject && clean.startsWith("src/")) return clean.replace("src/", "dist/");
|
|
281
|
+
if (isTsProject && !clean.includes("/")) return path.join("dist", clean);
|
|
282
|
+
}
|
|
283
|
+
return clean;
|
|
277
284
|
};
|
|
278
285
|
const middlewaresCandidate = normalizePath(this.middlewaresPath);
|
|
279
286
|
const routesCandidate = normalizePath(this.routesPath);
|
|
@@ -369,7 +376,7 @@ class Sprint {
|
|
|
369
376
|
* Load all middleware files from the middlewares folder
|
|
370
377
|
*/
|
|
371
378
|
async loadMiddlewares(middlewaresPath) {
|
|
372
|
-
const fileExtensions = isProd ? [".
|
|
379
|
+
const fileExtensions = isProd ? [".mjs", ".js"] : [".ts"];
|
|
373
380
|
const files = await fs.promises.readdir(middlewaresPath);
|
|
374
381
|
for (const file of files) {
|
|
375
382
|
const filePath = path.join(middlewaresPath, file);
|
|
@@ -408,20 +415,20 @@ class Sprint {
|
|
|
408
415
|
});
|
|
409
416
|
}
|
|
410
417
|
async loadRoutes(routesPath) {
|
|
411
|
-
const
|
|
418
|
+
const fileExtensions = isProd ? [".mjs", ".js"] : [".ts"];
|
|
412
419
|
const walkDir = async (dir) => {
|
|
413
420
|
const files = await fs.promises.readdir(dir);
|
|
414
421
|
for (const file of files) {
|
|
415
422
|
const filePath = path.join(dir, file);
|
|
416
423
|
const stat = await fs.promises.stat(filePath);
|
|
417
424
|
if (stat.isDirectory()) await walkDir(filePath);
|
|
418
|
-
else if (stat.isFile() && file.endsWith(
|
|
425
|
+
else if (stat.isFile() && fileExtensions.some((ext) => file.endsWith(ext))) {
|
|
419
426
|
try {
|
|
420
427
|
const moduleUrl = url.pathToFileURL(filePath).href;
|
|
421
428
|
const module2 = await import(moduleUrl);
|
|
422
429
|
const router = module2.default || module2.router;
|
|
423
430
|
if (router && typeof router === "function" && router.stack && Array.isArray(router.stack)) {
|
|
424
|
-
let routePath = "/" + path.relative(routesPath, filePath).replace(/\.(ts|js)$/, "").replace(/\\/g, "/");
|
|
431
|
+
let routePath = "/" + path.relative(routesPath, filePath).replace(/\.(ts|js|mjs)$/, "").replace(/\\/g, "/");
|
|
425
432
|
routePath = stripRouteGroups(routePath);
|
|
426
433
|
if (routePath.endsWith("/index")) routePath = routePath.slice(0, -6) || "/";
|
|
427
434
|
const fullRoute = this.prefix + (routePath === "/" ? "" : routePath);
|
|
@@ -467,12 +474,12 @@ class Sprint {
|
|
|
467
474
|
await walkDir(routesPath);
|
|
468
475
|
}
|
|
469
476
|
async loadCronJobs(cronjobsPath) {
|
|
470
|
-
const
|
|
477
|
+
const fileExtensions = isProd ? [".mjs", ".js"] : [".ts"];
|
|
471
478
|
const files = await fs.promises.readdir(cronjobsPath);
|
|
472
479
|
for (const file of files) {
|
|
473
480
|
const filePath = path.join(cronjobsPath, file);
|
|
474
481
|
const stat = await fs.promises.stat(filePath);
|
|
475
|
-
if (stat.isFile() && file.endsWith(
|
|
482
|
+
if (stat.isFile() && fileExtensions.some((ext) => file.endsWith(ext))) {
|
|
476
483
|
try {
|
|
477
484
|
const moduleUrl = url.pathToFileURL(filePath).href;
|
|
478
485
|
await import(moduleUrl);
|
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;
|
|
@@ -247,8 +247,15 @@ class Sprint {
|
|
|
247
247
|
async init() {
|
|
248
248
|
const callerDir = process.cwd();
|
|
249
249
|
const normalizePath = (p) => {
|
|
250
|
-
|
|
251
|
-
|
|
250
|
+
const clean = p.replace(/^\.\//, "");
|
|
251
|
+
if (isProd) {
|
|
252
|
+
if (clean.startsWith("dist/")) return clean;
|
|
253
|
+
const callerDir2 = process.cwd();
|
|
254
|
+
const isTsProject = fs.existsSync(path.join(callerDir2, "tsconfig.json")) || fs.existsSync(path.join(callerDir2, "sprint.config.ts"));
|
|
255
|
+
if (isTsProject && clean.startsWith("src/")) return clean.replace("src/", "dist/");
|
|
256
|
+
if (isTsProject && !clean.includes("/")) return path.join("dist", clean);
|
|
257
|
+
}
|
|
258
|
+
return clean;
|
|
252
259
|
};
|
|
253
260
|
const middlewaresCandidate = normalizePath(this.middlewaresPath);
|
|
254
261
|
const routesCandidate = normalizePath(this.routesPath);
|
|
@@ -344,7 +351,7 @@ class Sprint {
|
|
|
344
351
|
* Load all middleware files from the middlewares folder
|
|
345
352
|
*/
|
|
346
353
|
async loadMiddlewares(middlewaresPath) {
|
|
347
|
-
const fileExtensions = isProd ? [".
|
|
354
|
+
const fileExtensions = isProd ? [".mjs", ".js"] : [".ts"];
|
|
348
355
|
const files = await fs.promises.readdir(middlewaresPath);
|
|
349
356
|
for (const file of files) {
|
|
350
357
|
const filePath = path.join(middlewaresPath, file);
|
|
@@ -383,20 +390,20 @@ class Sprint {
|
|
|
383
390
|
});
|
|
384
391
|
}
|
|
385
392
|
async loadRoutes(routesPath) {
|
|
386
|
-
const
|
|
393
|
+
const fileExtensions = isProd ? [".mjs", ".js"] : [".ts"];
|
|
387
394
|
const walkDir = async (dir) => {
|
|
388
395
|
const files = await fs.promises.readdir(dir);
|
|
389
396
|
for (const file of files) {
|
|
390
397
|
const filePath = path.join(dir, file);
|
|
391
398
|
const stat = await fs.promises.stat(filePath);
|
|
392
399
|
if (stat.isDirectory()) await walkDir(filePath);
|
|
393
|
-
else if (stat.isFile() && file.endsWith(
|
|
400
|
+
else if (stat.isFile() && fileExtensions.some((ext) => file.endsWith(ext))) {
|
|
394
401
|
try {
|
|
395
402
|
const moduleUrl = pathToFileURL(filePath).href;
|
|
396
403
|
const module = await import(moduleUrl);
|
|
397
404
|
const router = module.default || module.router;
|
|
398
405
|
if (router && typeof router === "function" && router.stack && Array.isArray(router.stack)) {
|
|
399
|
-
let routePath = "/" + path.relative(routesPath, filePath).replace(/\.(ts|js)$/, "").replace(/\\/g, "/");
|
|
406
|
+
let routePath = "/" + path.relative(routesPath, filePath).replace(/\.(ts|js|mjs)$/, "").replace(/\\/g, "/");
|
|
400
407
|
routePath = stripRouteGroups(routePath);
|
|
401
408
|
if (routePath.endsWith("/index")) routePath = routePath.slice(0, -6) || "/";
|
|
402
409
|
const fullRoute = this.prefix + (routePath === "/" ? "" : routePath);
|
|
@@ -442,12 +449,12 @@ class Sprint {
|
|
|
442
449
|
await walkDir(routesPath);
|
|
443
450
|
}
|
|
444
451
|
async loadCronJobs(cronjobsPath) {
|
|
445
|
-
const
|
|
452
|
+
const fileExtensions = isProd ? [".mjs", ".js"] : [".ts"];
|
|
446
453
|
const files = await fs.promises.readdir(cronjobsPath);
|
|
447
454
|
for (const file of files) {
|
|
448
455
|
const filePath = path.join(cronjobsPath, file);
|
|
449
456
|
const stat = await fs.promises.stat(filePath);
|
|
450
|
-
if (stat.isFile() && file.endsWith(
|
|
457
|
+
if (stat.isFile() && fileExtensions.some((ext) => file.endsWith(ext))) {
|
|
451
458
|
try {
|
|
452
459
|
const moduleUrl = pathToFileURL(filePath).href;
|
|
453
460
|
await import(moduleUrl);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sprint.d.ts","sourceRoot":"","sources":["../../src/sprint.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,OAAO,EAA+B,gBAAgB,EAAoB,MAAM,SAAS,CAAC;AACnG,OAAO,OAAO,EAAE,EAAE,WAAW,EAAoD,MAAM,SAAS,CAAC;AAejG,eAAO,MAAM,aAAa,SAAQ,CAAC;AACnC,eAAO,MAAM,YAAY,SAAS,CAAC;AA8CnC,qBAAa,MAAM;IACR,GAAG,EAAE,WAAW,CAAC;IACxB,OAAO,CAAC,IAAI,CAAwD;IACpE,OAAO,CAAC,UAAU,CAAsB;IACxC,OAAO,CAAC,eAAe,CAA2B;IAClD,OAAO,CAAC,YAAY,CAAwB;IAC5C,OAAO,CAAC,SAAS,CAAkB;IACnC,OAAO,CAAC,eAAe,CAAkB;IACzC,OAAO,CAAC,MAAM,CAAc;IAC5B,OAAO,CAAC,YAAY,CAAiB;IACrC,OAAO,CAAC,MAAM,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