Skip to content

Commit 7cf7dfa

Browse files
authored
feat(cli): improve UX when throw error (#431)
1 parent d13f53a commit 7cf7dfa

7 files changed

Lines changed: 86 additions & 187 deletions

File tree

apps/cli/node-sea.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
{
22
"main": "dist/apps/cli/main.cjs",
3+
"assets": {
4+
"main.js.map": "dist/apps/cli/main.cjs.map"
5+
},
36
"output": "sea-prep.blob",
47
"disableExperimentalSEAWarning": true
58
}

apps/cli/package.json

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,39 +6,41 @@
66
"@types/express": "^5.0.3",
77
"@types/js-yaml": "^4.0.9",
88
"@types/lodash-es": "catalog:",
9-
"@types/supertest": "^7.2.0",
109
"@types/pluralize": "^0.0.33",
1110
"@types/qs": "^6.9.15",
12-
"@types/signale": "^1.4.7",
1311
"@types/semver": "catalog:",
12+
"@types/signale": "^1.4.7",
13+
"@types/supertest": "^7.2.0",
14+
"@types/source-map-support": "^0.5.10",
15+
"semver": "catalog:",
1416
"supertest": "^7.1.4",
15-
"vitest": "catalog:",
16-
"semver": "catalog:"
17+
"vitest": "catalog:"
1718
},
1819
"dependencies": {
19-
"@api7/adc-sdk": "workspace:*",
2020
"@api7/adc-backend-api7": "workspace:*",
2121
"@api7/adc-backend-apisix": "workspace:*",
2222
"@api7/adc-backend-apisix-standalone": "workspace:*",
2323
"@api7/adc-converter-openapi": "workspace:*",
2424
"@api7/adc-differ": "workspace:*",
25-
"express": "^5.1.0",
26-
"winston": "^3.17.0",
25+
"@api7/adc-sdk": "workspace:*",
26+
"agentkeepalive": "^4.6.0",
2727
"axios": "catalog:",
28-
"rxjs": "catalog:",
29-
"lodash-es": "catalog:",
30-
"zod": "catalog:",
31-
"pluralize": "^8.0.0",
32-
"listr2": "catalog:",
33-
"commander": "^14.0.3",
3428
"chalk": "^5.6.2",
29+
"commander": "^14.0.3",
30+
"dotenv": "^17.3.1",
31+
"express": "^5.1.0",
32+
"glob": "^13.0.0",
33+
"js-yaml": "catalog:",
34+
"listr2": "catalog:",
35+
"lodash-es": "catalog:",
3536
"parse-duration": "^2.1.5",
37+
"pluralize": "^8.0.0",
3638
"qs": "^6.14.1",
37-
"dotenv": "^17.3.1",
38-
"agentkeepalive": "^4.6.0",
39+
"rxjs": "catalog:",
3940
"signale": "^1.4.0",
40-
"glob": "^13.0.0",
41-
"js-yaml": "catalog:"
41+
"source-map-support": "catalog:",
42+
"winston": "^3.17.0",
43+
"zod": "catalog:"
4244
},
4345
"nx": {
4446
"name": "cli",
@@ -65,15 +67,11 @@
6567
"declarationRootDir": "apps/cli/src",
6668
"bundle": true,
6769
"thirdParty": true,
68-
"sourcemap": "inline"
70+
"sourcemap": "linked"
6971
},
7072
"configurations": {
71-
"development": {
72-
"minify": false
73-
},
74-
"production": {
75-
"minify": true
76-
}
73+
"development": {},
74+
"production": {}
7775
}
7876
},
7977
"lint": {

apps/cli/src/command/index.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ import { configurePluralize } from './utils';
1515

1616
const versionCode = '0.24.3';
1717

18-
// initialize dotenv
19-
dotenv.config({ quiet: true });
18+
function setupInternal() {
19+
// initialize dotenv
20+
dotenv.config({ quiet: true });
2021

21-
// initialize pluralize
22-
configurePluralize();
22+
// initialize pluralize
23+
configurePluralize();
24+
}
2325

2426
export const setupCommands = (): Command => {
27+
setupInternal();
28+
2529
const program = new Command('adc');
2630

2731
program
@@ -56,6 +60,8 @@ export const setupCommands = (): Command => {
5660
};
5761

5862
export const setupIngressCommands = (): Command => {
63+
setupInternal();
64+
5965
const program = new Command('adc-ingress');
6066

6167
program

apps/cli/src/main.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,35 @@
1+
import { getAsset, isSea } from 'node:sea';
2+
import sourceMapSupport from 'source-map-support';
3+
14
import { setupCommands, setupIngressCommands } from './command';
25

6+
function setupSourceMap() {
7+
if (!isSea()) {
8+
sourceMapSupport.install();
9+
return;
10+
}
11+
12+
try {
13+
const sourceMapFile = getAsset('main.js.map', 'utf-8');
14+
const map = JSON.parse(sourceMapFile);
15+
sourceMapSupport.install({
16+
environment: 'node',
17+
retrieveSourceMap: (source) => {
18+
if (source.startsWith('node:') || source.startsWith('internal'))
19+
return null;
20+
return { url: source, map };
21+
},
22+
});
23+
} catch (err) {
24+
console.warn(
25+
`Failed to load source map for SEA: ${err instanceof Error ? err.message : String(err)}`,
26+
);
27+
}
28+
}
29+
330
async function bootstrap() {
31+
setupSourceMap();
32+
433
await (
534
process.env.ADC_RUNNING_MODE === 'ingress'
635
? setupIngressCommands()

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"@nx/eslint-plugin": "22.6.3",
1111
"@nx/js": "22.6.3",
1212
"@nx/vitest": "22.6.3",
13-
"@nx/web": "22.6.3",
1413
"@nx/workspace": "22.6.3",
1514
"@swc-node/register": "1.11.1",
1615
"@swc/core": "1.15.8",

0 commit comments

Comments
 (0)