@axiomify/cli 3.0.0 → 3.1.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.
@@ -39,9 +39,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.buildProject = buildProject;
40
40
  const esbuild = __importStar(require("esbuild"));
41
41
  const path_1 = __importDefault(require("path"));
42
+ const externals_1 = require("../utils/externals");
42
43
  async function buildProject(entry) {
43
44
  const entryPath = path_1.default.resolve(process.cwd(), entry);
44
45
  const outPath = path_1.default.resolve(process.cwd(), 'dist/index.js');
46
+ const userExternals = (0, externals_1.getUserExternals)(process.cwd());
45
47
  console.log(`šŸ”Ø Building production bundle from ${entry}...`);
46
48
  try {
47
49
  await esbuild.build({
@@ -51,14 +53,8 @@ async function buildProject(entry) {
51
53
  target: 'node18',
52
54
  outfile: outPath,
53
55
  minify: true,
54
- keepNames: true, // Important for preserving class names in logs
55
- external: [
56
- 'express',
57
- '@axiomify/core',
58
- '@axiomify/express',
59
- // In a real monorepo, these might be bundled or kept external based on preference.
60
- // For Node.js backends, keeping node_modules external is standard practice.
61
- ],
56
+ keepNames: true,
57
+ external: [...new Set([...userExternals, 'node:*'])],
62
58
  });
63
59
  console.log(`āœ… Build successful: ${outPath}`);
64
60
  }
@@ -39,31 +39,27 @@ Object.defineProperty(exports, "__esModule", { value: true });
39
39
  exports.devServer = devServer;
40
40
  const child_process_1 = require("child_process");
41
41
  const esbuild = __importStar(require("esbuild"));
42
- const fs_1 = __importDefault(require("fs"));
43
42
  const path_1 = __importDefault(require("path"));
44
- // šŸš€ THE FIX: Dynamically detect what the user has installed
45
- async function getUserExternals(cwd) {
46
- try {
47
- const pkg = JSON.parse(fs_1.default.readFileSync(path_1.default.join(cwd, 'package.json'), 'utf8'));
48
- return [
49
- ...Object.keys(pkg.dependencies || {}),
50
- ...Object.keys(pkg.devDependencies || {}),
51
- ...Object.keys(pkg.peerDependencies || {}),
52
- ];
53
- }
54
- catch {
55
- return [];
56
- }
57
- }
43
+ const externals_1 = require("../utils/externals");
58
44
  async function devServer(entry) {
59
45
  const entryPath = path_1.default.resolve(process.cwd(), entry);
60
46
  const outPath = path_1.default.resolve(process.cwd(), '.axiomify/dev.js');
61
- let nodeProcess = null;
47
+ let child = null;
62
48
  const restartServer = () => {
63
- if (nodeProcess)
64
- nodeProcess.kill();
65
- console.log(`\nšŸ”„ Restarting server...`);
66
- nodeProcess = (0, child_process_1.spawn)('node', [outPath], { stdio: 'inherit' });
49
+ if (child) {
50
+ // 1. Stop listening to old exit events so we don't accidentally spawn twice
51
+ child.removeAllListeners('exit');
52
+ // 2. ONLY spawn the new server after the old one has completely exited
53
+ child.once('exit', () => {
54
+ child = (0, child_process_1.spawn)('node', [outPath], { stdio: 'inherit' });
55
+ });
56
+ // 3. Ruthlessly kill the old server (bypasses graceful shutdown)
57
+ child.kill('SIGKILL');
58
+ }
59
+ else {
60
+ // First time booting up
61
+ child = (0, child_process_1.spawn)('node', [outPath], { stdio: 'inherit' });
62
+ }
67
63
  };
68
64
  const watchPlugin = {
69
65
  name: 'watch-plugin',
@@ -78,7 +74,7 @@ async function devServer(entry) {
78
74
  });
79
75
  },
80
76
  };
81
- const userExternals = await getUserExternals(process.cwd());
77
+ const userExternals = await (0, externals_1.getUserExternals)(process.cwd());
82
78
  const ctx = await esbuild.context({
83
79
  entryPoints: [entryPath],
84
80
  bundle: true,
@@ -40,9 +40,11 @@ exports.inspectRoutes = inspectRoutes;
40
40
  const esbuild = __importStar(require("esbuild"));
41
41
  const promises_1 = __importDefault(require("fs/promises"));
42
42
  const path_1 = __importDefault(require("path"));
43
+ const externals_1 = require("../utils/externals");
43
44
  async function inspectRoutes(entry) {
44
45
  const entryPath = path_1.default.resolve(process.cwd(), entry);
45
46
  const tempPath = path_1.default.resolve(process.cwd(), '.axiomify/inspect.cjs');
47
+ const userExternals = (0, externals_1.getUserExternals)(process.cwd());
46
48
  try {
47
49
  // 1. Compile the app to a temporary CommonJS file
48
50
  await esbuild.build({
@@ -51,13 +53,19 @@ async function inspectRoutes(entry) {
51
53
  platform: 'node',
52
54
  format: 'cjs',
53
55
  outfile: tempPath,
54
- external: ['express', '@axiomify/core', '@axiomify/express'],
56
+ external: [...new Set([...userExternals, 'node:*'])],
55
57
  });
56
58
  // 2. Clear require cache to ensure fresh load
57
- delete require.cache[require.resolve(tempPath)];
59
+ try {
60
+ delete require.cache[require.resolve(tempPath)];
61
+ }
62
+ catch (e) {
63
+ // Ignore if it's the first time and not yet in cache
64
+ }
58
65
  // 3. Import the compiled app
59
- const fileUrl = `file://${tempPath}?t=${Date.now()}`;
60
- const mod = await Promise.resolve(`${fileUrl}`).then(s => __importStar(require(s)));
66
+ // Since the CLI is CJS, import() becomes require().
67
+ // require() uses raw absolute paths, not file:// URLs.
68
+ const mod = require(tempPath);
61
69
  const app = mod.app || mod.default;
62
70
  if (!app || typeof app.registeredRoutes === 'undefined') {
63
71
  console.error('āŒ Error: Could not find an exported Axiomify instance.');
@@ -77,6 +85,10 @@ async function inspectRoutes(entry) {
77
85
  schemas.push('Query');
78
86
  if (route.schema?.params)
79
87
  schemas.push('Params');
88
+ if (route.schema?.response)
89
+ schemas.push('Response');
90
+ if (route.schema?.files)
91
+ schemas.push('Files');
80
92
  const validationStr = schemas.length > 0 ? schemas.join(', ') : 'None';
81
93
  console.log(`${route.method.padEnd(10)} | ${route.path.padEnd(30)} | ${validationStr}`);
82
94
  });
@@ -0,0 +1 @@
1
+ export declare function getUserExternals(cwd: string): string[];
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getUserExternals = getUserExternals;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ function getUserExternals(cwd) {
10
+ try {
11
+ const pkgPath = path_1.default.join(cwd, 'package.json');
12
+ if (fs_1.default.existsSync(pkgPath)) {
13
+ const pkg = JSON.parse(fs_1.default.readFileSync(pkgPath, 'utf8'));
14
+ const deps = Object.keys(pkg.dependencies || {});
15
+ const devDeps = Object.keys(pkg.devDependencies || {});
16
+ return [...deps, ...devDeps];
17
+ }
18
+ }
19
+ catch (err) {
20
+ console.warn('[Axiomify CLI] Failed to read package.json, defaulting to empty externals.');
21
+ }
22
+ return [];
23
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axiomify/cli",
3
- "version": "3.0.0",
3
+ "version": "3.1.0",
4
4
  "bin": {
5
5
  "axiomify": "./dist/index.js"
6
6
  },