Skip to content

Commit 670dd21

Browse files
authored
fix: corss BFF type prompt (#7635)
1 parent 32d5da8 commit 670dd21

File tree

6 files changed

+31
-1
lines changed

6 files changed

+31
-1
lines changed

.changeset/silver-bars-shave.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@modern-js/plugin-bff': patch
3+
---
4+
5+
fix: corss BFF type prompt
6+
fix: 修复 跨项目 BFF 类型提示问题

packages/cli/plugin-bff/src/cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ export const bffPlugin = (): CliPlugin<AppTools> => ({
7070
distDir,
7171
tsconfigPath,
7272
moduleType,
73+
throwErrorInsteadOfExit: true,
7374
},
7475
);
7576
}

packages/cli/plugin-bff/src/utils/clientGenerator.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ async function setPackage(
157157
};
158158
},
159159
{
160+
[`${API_DIR}/*`]: [
161+
toPosixPath(`./${relativeDistPath}/${CLIENT_DIR}/*.d.ts`),
162+
],
160163
[RUNTIME_DIR]: [
161164
toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.d.ts`),
162165
],
@@ -181,12 +184,18 @@ async function setPackage(
181184
};
182185
},
183186
{
187+
[toPosixPath(`./${API_DIR}/*`)]: {
188+
import: toPosixPath(`./${relativeDistPath}/${CLIENT_DIR}/*.js`),
189+
types: toPosixPath(`./${relativeDistPath}/${CLIENT_DIR}/*.d.ts`),
190+
},
184191
[toPosixPath(`./${PLUGIN_DIR}`)]: {
192+
import: toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.js`),
185193
require: toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.js`),
186194
types: toPosixPath(`./${relativeDistPath}/${PLUGIN_DIR}/index.d.ts`),
187195
},
188196
[toPosixPath(`./${RUNTIME_DIR}`)]: {
189197
import: toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.js`),
198+
require: toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.js`),
190199
types: toPosixPath(`./${relativeDistPath}/${RUNTIME_DIR}/index.d.ts`),
191200
},
192201
},

packages/server/utils/src/common/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export interface CompileOptions {
2424
distDir: string;
2525
tsconfigPath?: string;
2626
moduleType?: 'module' | 'commonjs';
27+
throwErrorInsteadOfExit?: boolean;
2728
}
2829

2930
export type CompileFunc = (

packages/server/utils/src/compilers/typescript/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,11 @@ export const compileByTs: CompileFunc = async (
103103
),
104104
);
105105
if (typeof noEmitOnError === 'undefined' || noEmitOnError === true) {
106-
process.exit(1);
106+
if (compileOptions.throwErrorInsteadOfExit) {
107+
logger.error('TypeScript compilation failed');
108+
} else {
109+
process.exit(1);
110+
}
107111
}
108112
}
109113

tests/integration/bff-corss-project/bff-api-app/package.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,19 @@
3535
},
3636
"exports": {
3737
"./plugin": {
38+
"import": "./dist-1/plugin/index.js",
3839
"require": "./dist-1/plugin/index.js",
3940
"types": "./dist-1/plugin/index.d.ts"
4041
},
4142
"./runtime": {
4243
"import": "./dist-1/runtime/index.js",
44+
"require": "./dist-1/runtime/index.js",
4345
"types": "./dist-1/runtime/index.d.ts"
4446
},
47+
"./api/*": {
48+
"import": "./dist-1/client/*.js",
49+
"types": "./dist-1/client/*.d.ts"
50+
},
4551
"./api/context/index": {
4652
"import": "./dist-1/client/context/index.js",
4753
"types": "./dist-1/client/context/index.d.ts"
@@ -71,6 +77,9 @@
7177
"plugin": [
7278
"./dist-1/plugin/index.d.ts"
7379
],
80+
"api/*": [
81+
"./dist-1/client/*.d.ts"
82+
],
7483
"api/context/index": [
7584
"./dist-1/client/context/index.d.ts"
7685
],

0 commit comments

Comments
 (0)