@axiomify/cli 2.0.1 ā 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.
- package/dist/commands/build.js +4 -8
- package/dist/commands/dev.js +18 -12
- package/dist/commands/routes.js +15 -2
- package/dist/utils/externals.d.ts +1 -0
- package/dist/utils/externals.js +23 -0
- package/package.json +1 -1
package/dist/commands/build.js
CHANGED
|
@@ -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,
|
|
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
|
}
|
package/dist/commands/dev.js
CHANGED
|
@@ -40,15 +40,26 @@ exports.devServer = devServer;
|
|
|
40
40
|
const child_process_1 = require("child_process");
|
|
41
41
|
const esbuild = __importStar(require("esbuild"));
|
|
42
42
|
const path_1 = __importDefault(require("path"));
|
|
43
|
+
const externals_1 = require("../utils/externals");
|
|
43
44
|
async function devServer(entry) {
|
|
44
45
|
const entryPath = path_1.default.resolve(process.cwd(), entry);
|
|
45
46
|
const outPath = path_1.default.resolve(process.cwd(), '.axiomify/dev.js');
|
|
46
|
-
let
|
|
47
|
+
let child = null;
|
|
47
48
|
const restartServer = () => {
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
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
|
+
}
|
|
52
63
|
};
|
|
53
64
|
const watchPlugin = {
|
|
54
65
|
name: 'watch-plugin',
|
|
@@ -63,18 +74,13 @@ async function devServer(entry) {
|
|
|
63
74
|
});
|
|
64
75
|
},
|
|
65
76
|
};
|
|
77
|
+
const userExternals = await (0, externals_1.getUserExternals)(process.cwd());
|
|
66
78
|
const ctx = await esbuild.context({
|
|
67
79
|
entryPoints: [entryPath],
|
|
68
80
|
bundle: true,
|
|
69
81
|
platform: 'node',
|
|
70
82
|
outfile: outPath,
|
|
71
|
-
external: [
|
|
72
|
-
'express',
|
|
73
|
-
'@axiomify/core',
|
|
74
|
-
'@axiomify/express',
|
|
75
|
-
'@axiomify/logger',
|
|
76
|
-
'maskify-ts',
|
|
77
|
-
],
|
|
83
|
+
external: [...new Set([...userExternals, 'node:*'])],
|
|
78
84
|
plugins: [watchPlugin],
|
|
79
85
|
});
|
|
80
86
|
console.log(`š Axiomify Dev Engine watching for changes...`);
|
package/dist/commands/routes.js
CHANGED
|
@@ -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,11 +53,18 @@ async function inspectRoutes(entry) {
|
|
|
51
53
|
platform: 'node',
|
|
52
54
|
format: 'cjs',
|
|
53
55
|
outfile: tempPath,
|
|
54
|
-
external: [
|
|
56
|
+
external: [...new Set([...userExternals, 'node:*'])],
|
|
55
57
|
});
|
|
56
58
|
// 2. Clear require cache to ensure fresh load
|
|
57
|
-
|
|
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
|
|
66
|
+
// Since the CLI is CJS, import() becomes require().
|
|
67
|
+
// require() uses raw absolute paths, not file:// URLs.
|
|
59
68
|
const mod = require(tempPath);
|
|
60
69
|
const app = mod.app || mod.default;
|
|
61
70
|
if (!app || typeof app.registeredRoutes === 'undefined') {
|
|
@@ -76,6 +85,10 @@ async function inspectRoutes(entry) {
|
|
|
76
85
|
schemas.push('Query');
|
|
77
86
|
if (route.schema?.params)
|
|
78
87
|
schemas.push('Params');
|
|
88
|
+
if (route.schema?.response)
|
|
89
|
+
schemas.push('Response');
|
|
90
|
+
if (route.schema?.files)
|
|
91
|
+
schemas.push('Files');
|
|
79
92
|
const validationStr = schemas.length > 0 ? schemas.join(', ') : 'None';
|
|
80
93
|
console.log(`${route.method.padEnd(10)} | ${route.path.padEnd(30)} | ${validationStr}`);
|
|
81
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
|
+
}
|