sprint-es 0.0.117 → 0.0.118

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 CHANGED
@@ -5,6 +5,7 @@ const fs = require("fs");
5
5
  const crypto = require("crypto");
6
6
  const path = require("path");
7
7
  const child_process = require("child_process");
8
+ const module$1 = require("module");
8
9
  function _interopNamespaceDefault(e) {
9
10
  const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
10
11
  if (e) {
@@ -175,6 +176,40 @@ function runCommand(cmd, envVars) {
175
176
  });
176
177
  });
177
178
  }
179
+ function collectEntryPoints(dir) {
180
+ const entries = [];
181
+ if (!fs.existsSync(dir)) return entries;
182
+ for (const file of fs.readdirSync(dir)) {
183
+ const fullPath = path.join(dir, file);
184
+ if (fs.statSync(fullPath).isDirectory()) {
185
+ entries.push(...collectEntryPoints(fullPath));
186
+ } else if (file.endsWith(".ts") && !file.endsWith(".d.ts")) {
187
+ entries.push(fullPath);
188
+ }
189
+ }
190
+ return entries;
191
+ }
192
+ async function buildWithEsbuild(srcPath, distPath, external) {
193
+ const requireFromProject = module$1.createRequire(path.join(projectRoot, "package.json"));
194
+ const esbuild = requireFromProject("esbuild");
195
+ const entryPoints = collectEntryPoints(srcPath);
196
+ await esbuild.build({
197
+ entryPoints,
198
+ outdir: distPath,
199
+ outbase: srcPath,
200
+ platform: "node",
201
+ format: "cjs",
202
+ bundle: true,
203
+ // bundle=true es necesario para que external funcione
204
+ sourcemap: true,
205
+ external,
206
+ // todos los paquetes npm marcados como externos
207
+ treeShaking: false,
208
+ // no eliminar exports, queremos todos los archivos
209
+ packages: "external"
210
+ // cualquier paquete de node_modules es externo automáticamente
211
+ });
212
+ }
178
213
  function generateJWTSecret() {
179
214
  const chars = crypto__namespace.randomBytes(24).toString("hex").split("");
180
215
  const positions = /* @__PURE__ */ new Set();
@@ -406,33 +441,25 @@ async function main() {
406
441
  console.log("[Sprint] Cleaning dist...");
407
442
  fs.rmSync(distPath, { recursive: true, force: true });
408
443
  console.log("[Sprint] dist cleaned ✓");
409
- console.log("[Sprint] Compiling with esbuild...");
410
444
  const packageJson = JSON.parse(fs.readFileSync(path.join(projectRoot, "package.json"), "utf-8"));
411
- const deps = [
445
+ const external = [
412
446
  ...Object.keys(packageJson.dependencies ?? {}),
413
447
  ...Object.keys(packageJson.devDependencies ?? {}),
414
448
  ...Object.keys(packageJson.optionalDependencies ?? {}),
415
449
  ...Object.keys(packageJson.peerDependencies ?? {})
416
450
  ];
417
- const externals = deps.map((d) => `--external:${d}`).join(" ");
418
- await runCommand(
419
- `esbuild "${srcPath}/**/*.ts" --outdir="${distPath}" --platform=node --format=cjs --bundle=false --sourcemap --outbase="${srcPath}" ${externals}`,
420
- { NODE_ENV: "production" }
421
- );
451
+ console.log("[Sprint] Compiling with esbuild...");
452
+ await buildWithEsbuild(srcPath, distPath, external);
422
453
  console.log("[Sprint] Compilation completed ✓");
423
454
  console.log("[Sprint] Type checking...");
424
455
  await runCommand(`tsc --project "${tsconfigPath}" --noEmit`, { NODE_ENV: "production" });
425
456
  console.log("[Sprint] Type check completed ✓");
426
457
  console.log("[Sprint] Resolving aliases...");
427
- const aliasConfig = {
428
- extends: "./tsconfig.json",
429
- compilerOptions: {
430
- outDir: "./dist",
431
- noEmit: false
432
- }
433
- };
434
458
  const aliasConfigPath = path.join(projectRoot, "tsconfig.alias.json");
435
- fs.writeFileSync(aliasConfigPath, JSON.stringify(aliasConfig, null, 4));
459
+ fs.writeFileSync(aliasConfigPath, JSON.stringify({
460
+ extends: "./tsconfig.json",
461
+ compilerOptions: { outDir: "./dist", noEmit: false }
462
+ }, null, 4));
436
463
  try {
437
464
  await runCommand(`tsc-alias --project "${aliasConfigPath}"`, { NODE_ENV: "production" });
438
465
  console.log("[Sprint] Aliases resolved ✓");
@@ -442,7 +469,7 @@ async function main() {
442
469
  if (isTS) {
443
470
  console.log("[Sprint] Compiling sprint.config.ts...");
444
471
  await runCommand(
445
- `esbuild "${path.join(projectRoot, "sprint.config.ts")}" --outfile="${path.join(projectRoot, "dist/sprint.config.js")}" --platform=node --format=cjs --bundle=false`,
472
+ `esbuild "${path.join(projectRoot, "sprint.config.ts")}" --outfile="${path.join(projectRoot, "dist/sprint.config.js")}" --platform=node --format=cjs --bundle=true ${external.map((e) => `--external:${e}`).join(" ")}`,
446
473
  { NODE_ENV: "production" }
447
474
  );
448
475
  console.log("[Sprint] sprint.config.js generated ✓");
package/dist/esm/cli.js CHANGED
@@ -3,6 +3,7 @@ import { existsSync, rmSync, readFileSync, writeFileSync, readdirSync, statSync
3
3
  import * as crypto from "crypto";
4
4
  import { resolve, join } from "path";
5
5
  import { spawn } from "child_process";
6
+ import { createRequire } from "module";
6
7
  const args = process.argv.slice(2);
7
8
  const command = args[0];
8
9
  const pc = {
@@ -156,6 +157,40 @@ function runCommand(cmd, envVars) {
156
157
  });
157
158
  });
158
159
  }
160
+ function collectEntryPoints(dir) {
161
+ const entries = [];
162
+ if (!existsSync(dir)) return entries;
163
+ for (const file of readdirSync(dir)) {
164
+ const fullPath = join(dir, file);
165
+ if (statSync(fullPath).isDirectory()) {
166
+ entries.push(...collectEntryPoints(fullPath));
167
+ } else if (file.endsWith(".ts") && !file.endsWith(".d.ts")) {
168
+ entries.push(fullPath);
169
+ }
170
+ }
171
+ return entries;
172
+ }
173
+ async function buildWithEsbuild(srcPath, distPath, external) {
174
+ const requireFromProject = createRequire(join(projectRoot, "package.json"));
175
+ const esbuild = requireFromProject("esbuild");
176
+ const entryPoints = collectEntryPoints(srcPath);
177
+ await esbuild.build({
178
+ entryPoints,
179
+ outdir: distPath,
180
+ outbase: srcPath,
181
+ platform: "node",
182
+ format: "cjs",
183
+ bundle: true,
184
+ // bundle=true es necesario para que external funcione
185
+ sourcemap: true,
186
+ external,
187
+ // todos los paquetes npm marcados como externos
188
+ treeShaking: false,
189
+ // no eliminar exports, queremos todos los archivos
190
+ packages: "external"
191
+ // cualquier paquete de node_modules es externo automáticamente
192
+ });
193
+ }
159
194
  function generateJWTSecret() {
160
195
  const chars = crypto.randomBytes(24).toString("hex").split("");
161
196
  const positions = /* @__PURE__ */ new Set();
@@ -387,33 +422,25 @@ async function main() {
387
422
  console.log("[Sprint] Cleaning dist...");
388
423
  rmSync(distPath, { recursive: true, force: true });
389
424
  console.log("[Sprint] dist cleaned ✓");
390
- console.log("[Sprint] Compiling with esbuild...");
391
425
  const packageJson = JSON.parse(readFileSync(join(projectRoot, "package.json"), "utf-8"));
392
- const deps = [
426
+ const external = [
393
427
  ...Object.keys(packageJson.dependencies ?? {}),
394
428
  ...Object.keys(packageJson.devDependencies ?? {}),
395
429
  ...Object.keys(packageJson.optionalDependencies ?? {}),
396
430
  ...Object.keys(packageJson.peerDependencies ?? {})
397
431
  ];
398
- const externals = deps.map((d) => `--external:${d}`).join(" ");
399
- await runCommand(
400
- `esbuild "${srcPath}/**/*.ts" --outdir="${distPath}" --platform=node --format=cjs --bundle=false --sourcemap --outbase="${srcPath}" ${externals}`,
401
- { NODE_ENV: "production" }
402
- );
432
+ console.log("[Sprint] Compiling with esbuild...");
433
+ await buildWithEsbuild(srcPath, distPath, external);
403
434
  console.log("[Sprint] Compilation completed ✓");
404
435
  console.log("[Sprint] Type checking...");
405
436
  await runCommand(`tsc --project "${tsconfigPath}" --noEmit`, { NODE_ENV: "production" });
406
437
  console.log("[Sprint] Type check completed ✓");
407
438
  console.log("[Sprint] Resolving aliases...");
408
- const aliasConfig = {
409
- extends: "./tsconfig.json",
410
- compilerOptions: {
411
- outDir: "./dist",
412
- noEmit: false
413
- }
414
- };
415
439
  const aliasConfigPath = join(projectRoot, "tsconfig.alias.json");
416
- writeFileSync(aliasConfigPath, JSON.stringify(aliasConfig, null, 4));
440
+ writeFileSync(aliasConfigPath, JSON.stringify({
441
+ extends: "./tsconfig.json",
442
+ compilerOptions: { outDir: "./dist", noEmit: false }
443
+ }, null, 4));
417
444
  try {
418
445
  await runCommand(`tsc-alias --project "${aliasConfigPath}"`, { NODE_ENV: "production" });
419
446
  console.log("[Sprint] Aliases resolved ✓");
@@ -423,7 +450,7 @@ async function main() {
423
450
  if (isTS) {
424
451
  console.log("[Sprint] Compiling sprint.config.ts...");
425
452
  await runCommand(
426
- `esbuild "${join(projectRoot, "sprint.config.ts")}" --outfile="${join(projectRoot, "dist/sprint.config.js")}" --platform=node --format=cjs --bundle=false`,
453
+ `esbuild "${join(projectRoot, "sprint.config.ts")}" --outfile="${join(projectRoot, "dist/sprint.config.js")}" --platform=node --format=cjs --bundle=true ${external.map((e) => `--external:${e}`).join(" ")}`,
427
454
  { NODE_ENV: "production" }
428
455
  );
429
456
  console.log("[Sprint] sprint.config.js generated ✓");
@@ -1 +1 @@
1
- {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AAqDA,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,EAAE,UAAiB,EAAE,cAAsB,EAAE;;;CAAK,UAoGrD"}
1
+ {"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/cli.ts"],"names":[],"mappings":";AAsDA,MAAM,CAAC,OAAO,UAAU,iBAAiB,CACrC,UAAU,EAAE,MAAM,EAClB,EAAE,UAAiB,EAAE,cAAsB,EAAE;;;CAAK,UAoGrD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sprint-es",
3
- "version": "0.0.117",
3
+ "version": "0.0.118",
4
4
  "description": "Sprint - Quickly API",
5
5
  "main": "dist/cjs/index.js",
6
6
  "module": "dist/esm/index.js",