@modern-js/plugin-bff 2.31.1 → 2.31.3-alpha.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/CHANGELOG.md +10 -0
- package/LICENSE +1 -1
- package/dist/cjs/cli.js +1 -0
- package/dist/esm/cli.js +1 -0
- package/dist/esm-node/cli.js +1 -0
- package/dist/js/modern/cli.js +156 -0
- package/dist/js/modern/constants.js +14 -0
- package/dist/js/modern/helper.js +14 -0
- package/dist/js/modern/index.js +1 -0
- package/dist/js/modern/loader.js +67 -0
- package/dist/js/modern/server.js +88 -0
- package/dist/js/node/cli.js +176 -0
- package/dist/js/node/constants.js +38 -0
- package/dist/js/node/helper.js +43 -0
- package/dist/js/node/index.js +17 -0
- package/dist/js/node/loader.js +88 -0
- package/dist/js/node/server.js +113 -0
- package/dist/js/treeshaking/cli.js +309 -0
- package/dist/js/treeshaking/constants.js +11 -0
- package/dist/js/treeshaking/helper.js +23 -0
- package/dist/js/treeshaking/index.js +1 -0
- package/dist/js/treeshaking/loader.js +191 -0
- package/dist/js/treeshaking/server.js +151 -0
- package/package.json +15 -16
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @modern-js/plugin-bff
|
|
2
2
|
|
|
3
|
+
## 2.31.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [15d30abdc66]
|
|
8
|
+
- @modern-js/utils@2.31.2
|
|
9
|
+
- @modern-js/bff-core@2.31.2
|
|
10
|
+
- @modern-js/create-request@2.31.2
|
|
11
|
+
- @modern-js/server-utils@2.31.2
|
|
12
|
+
|
|
3
13
|
## 2.31.1
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
package/LICENSE
CHANGED
package/dist/cjs/cli.js
CHANGED
package/dist/esm/cli.js
CHANGED
package/dist/esm-node/cli.js
CHANGED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import path from "path";
|
|
22
|
+
import {
|
|
23
|
+
fs,
|
|
24
|
+
API_DIR,
|
|
25
|
+
PLUGIN_SCHEMAS,
|
|
26
|
+
normalizeOutputPath,
|
|
27
|
+
SHARED_DIR,
|
|
28
|
+
isProd
|
|
29
|
+
} from "@modern-js/utils";
|
|
30
|
+
import { compile } from "@modern-js/server-utils";
|
|
31
|
+
import { ApiRouter } from "@modern-js/bff-core";
|
|
32
|
+
import { registerModernRuntimePath } from "./helper";
|
|
33
|
+
const DEFAULT_API_PREFIX = "/api";
|
|
34
|
+
const TS_CONFIG_FILENAME = "tsconfig.json";
|
|
35
|
+
var cli_default = () => ({
|
|
36
|
+
name: "@modern-js/plugin-bff",
|
|
37
|
+
setup: (api) => {
|
|
38
|
+
let unRegisterResolveRuntimePath = null;
|
|
39
|
+
return {
|
|
40
|
+
validateSchema() {
|
|
41
|
+
return PLUGIN_SCHEMAS["@modern-js/plugin-bff"];
|
|
42
|
+
},
|
|
43
|
+
config() {
|
|
44
|
+
return {
|
|
45
|
+
tools: {
|
|
46
|
+
webpackChain: (chain, { name, CHAIN_ID }) => {
|
|
47
|
+
const { appDirectory, port } = api.useAppContext();
|
|
48
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
49
|
+
const { bff } = modernConfig || {};
|
|
50
|
+
const prefix = (bff == null ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
51
|
+
const rootDir = path.resolve(appDirectory, API_DIR);
|
|
52
|
+
chain.resolve.alias.set("@api", rootDir);
|
|
53
|
+
const apiRouter = new ApiRouter({
|
|
54
|
+
apiDir: rootDir,
|
|
55
|
+
prefix
|
|
56
|
+
});
|
|
57
|
+
const lambdaDir = apiRouter.getLambdaDir();
|
|
58
|
+
const existLambda = apiRouter.isExistLambda();
|
|
59
|
+
const apiRegexp = new RegExp(
|
|
60
|
+
normalizeOutputPath(`${rootDir}${path.sep}.*(.[tj]s)$`)
|
|
61
|
+
);
|
|
62
|
+
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
|
|
63
|
+
chain.module.rule(CHAIN_ID.RULE.JS_BFF_API).test(apiRegexp).use("custom-loader").loader(require.resolve("./loader").replace(/\\/g, "/")).options({
|
|
64
|
+
prefix,
|
|
65
|
+
apiDir: rootDir,
|
|
66
|
+
lambdaDir,
|
|
67
|
+
existLambda,
|
|
68
|
+
port,
|
|
69
|
+
target: name
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
source: {
|
|
74
|
+
moduleScopes: [`./${API_DIR}`, /create-request/]
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
},
|
|
78
|
+
modifyServerRoutes({ routes }) {
|
|
79
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
80
|
+
const { bff } = modernConfig || {};
|
|
81
|
+
const prefix = (bff == null ? void 0 : bff.prefix) || "/api";
|
|
82
|
+
const prefixList = [];
|
|
83
|
+
if (Array.isArray(prefix)) {
|
|
84
|
+
prefixList.push(...prefix);
|
|
85
|
+
} else {
|
|
86
|
+
prefixList.push(prefix);
|
|
87
|
+
}
|
|
88
|
+
const apiServerRoutes = prefixList.map((pre) => ({
|
|
89
|
+
urlPath: pre,
|
|
90
|
+
isApi: true,
|
|
91
|
+
entryPath: "",
|
|
92
|
+
isSPA: false,
|
|
93
|
+
isSSR: false
|
|
94
|
+
}));
|
|
95
|
+
return { routes: routes.concat(apiServerRoutes) };
|
|
96
|
+
},
|
|
97
|
+
collectServerPlugins({ plugins }) {
|
|
98
|
+
plugins.push({
|
|
99
|
+
"@modern-js/plugin-bff": "@modern-js/plugin-bff/server"
|
|
100
|
+
});
|
|
101
|
+
return { plugins };
|
|
102
|
+
},
|
|
103
|
+
beforeBuild() {
|
|
104
|
+
return __async(this, null, function* () {
|
|
105
|
+
if (isProd()) {
|
|
106
|
+
const { internalDirectory } = api.useAppContext();
|
|
107
|
+
unRegisterResolveRuntimePath = registerModernRuntimePath(internalDirectory);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
afterBuild() {
|
|
112
|
+
return __async(this, null, function* () {
|
|
113
|
+
if (unRegisterResolveRuntimePath) {
|
|
114
|
+
unRegisterResolveRuntimePath();
|
|
115
|
+
}
|
|
116
|
+
const { appDirectory, distDirectory } = api.useAppContext();
|
|
117
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
118
|
+
const distDir = path.resolve(distDirectory);
|
|
119
|
+
const apiDir = path.resolve(appDirectory, API_DIR);
|
|
120
|
+
const sharedDir = path.resolve(appDirectory, SHARED_DIR);
|
|
121
|
+
const tsconfigPath = path.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
122
|
+
const sourceDirs = [];
|
|
123
|
+
if (fs.existsSync(apiDir)) {
|
|
124
|
+
sourceDirs.push(apiDir);
|
|
125
|
+
}
|
|
126
|
+
if (fs.existsSync(sharedDir)) {
|
|
127
|
+
sourceDirs.push(sharedDir);
|
|
128
|
+
}
|
|
129
|
+
const { server } = modernConfig;
|
|
130
|
+
const { alias, define, globalVars } = modernConfig.source;
|
|
131
|
+
const { babel } = modernConfig.tools;
|
|
132
|
+
if (sourceDirs.length > 0) {
|
|
133
|
+
yield compile(
|
|
134
|
+
appDirectory,
|
|
135
|
+
{
|
|
136
|
+
server,
|
|
137
|
+
alias,
|
|
138
|
+
define,
|
|
139
|
+
globalVars,
|
|
140
|
+
babelConfig: babel
|
|
141
|
+
},
|
|
142
|
+
{
|
|
143
|
+
sourceDirs,
|
|
144
|
+
distDir,
|
|
145
|
+
tsconfigPath
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
export {
|
|
155
|
+
cli_default as default
|
|
156
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const API_APP_NAME = "_app";
|
|
2
|
+
const BUILD_FILES = [
|
|
3
|
+
"**/*.[tj]sx?",
|
|
4
|
+
"!**/*.test.jsx?",
|
|
5
|
+
"!**/*.test.tsx?",
|
|
6
|
+
"!**/*.spec.jsx?",
|
|
7
|
+
"!**/*.spec.tsx?",
|
|
8
|
+
"!__tests__/*.tsx?",
|
|
9
|
+
"!__tests__/*.jsx?"
|
|
10
|
+
];
|
|
11
|
+
export {
|
|
12
|
+
API_APP_NAME,
|
|
13
|
+
BUILD_FILES
|
|
14
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import { registerPaths } from "@modern-js/bff-core";
|
|
3
|
+
const serverRuntimeAlias = "@modern-js/runtime/server";
|
|
4
|
+
const serverRuntimePath = ".runtime-exports/server";
|
|
5
|
+
const registerModernRuntimePath = (internalDirectory) => {
|
|
6
|
+
const paths = {
|
|
7
|
+
[serverRuntimeAlias]: path.join(internalDirectory, serverRuntimePath)
|
|
8
|
+
};
|
|
9
|
+
const unRegister = registerPaths(paths);
|
|
10
|
+
return unRegister;
|
|
11
|
+
};
|
|
12
|
+
export {
|
|
13
|
+
registerModernRuntimePath
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./constants";
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
var __async = (__this, __arguments, generator) => {
|
|
2
|
+
return new Promise((resolve, reject) => {
|
|
3
|
+
var fulfilled = (value) => {
|
|
4
|
+
try {
|
|
5
|
+
step(generator.next(value));
|
|
6
|
+
} catch (e) {
|
|
7
|
+
reject(e);
|
|
8
|
+
}
|
|
9
|
+
};
|
|
10
|
+
var rejected = (value) => {
|
|
11
|
+
try {
|
|
12
|
+
step(generator.throw(value));
|
|
13
|
+
} catch (e) {
|
|
14
|
+
reject(e);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
18
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
import { generateClient } from "@modern-js/bff-core";
|
|
22
|
+
import { logger } from "@modern-js/utils";
|
|
23
|
+
function loader(source) {
|
|
24
|
+
return __async(this, null, function* () {
|
|
25
|
+
this.cacheable();
|
|
26
|
+
const callback = this.async();
|
|
27
|
+
const draftOptions = this.getOptions();
|
|
28
|
+
const { resourcePath } = this;
|
|
29
|
+
const warning = `The file ${resourcePath} is not allowd to be imported in src directory, only API definition files are allowed.`;
|
|
30
|
+
if (!draftOptions.existLambda) {
|
|
31
|
+
logger.warn(warning);
|
|
32
|
+
callback(null, `throw new Error('${warning}')`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const options = {
|
|
36
|
+
prefix: Array.isArray(draftOptions.prefix) ? draftOptions.prefix[0] : draftOptions.prefix,
|
|
37
|
+
apiDir: draftOptions.apiDir,
|
|
38
|
+
target: draftOptions.target,
|
|
39
|
+
port: Number(draftOptions.port),
|
|
40
|
+
source,
|
|
41
|
+
resourcePath
|
|
42
|
+
};
|
|
43
|
+
const { lambdaDir } = draftOptions;
|
|
44
|
+
if (!resourcePath.startsWith(lambdaDir)) {
|
|
45
|
+
logger.warn(warning);
|
|
46
|
+
callback(null, `throw new Error('${warning}')`);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (draftOptions.fetcher) {
|
|
50
|
+
options.fetcher = draftOptions.fetcher;
|
|
51
|
+
}
|
|
52
|
+
if (draftOptions.requestCreator) {
|
|
53
|
+
options.requestCreator = draftOptions.requestCreator;
|
|
54
|
+
}
|
|
55
|
+
options.requireResolve = require.resolve;
|
|
56
|
+
const result = yield generateClient(options);
|
|
57
|
+
if (result.isOk) {
|
|
58
|
+
callback(void 0, result.value);
|
|
59
|
+
} else {
|
|
60
|
+
callback(void 0, `throw new Error('${result.value}')`);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
var loader_default = loader;
|
|
65
|
+
export {
|
|
66
|
+
loader_default as default
|
|
67
|
+
};
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import path from "path";
|
|
21
|
+
import { ApiRouter } from "@modern-js/bff-core";
|
|
22
|
+
import { API_DIR, isProd, requireExistModule } from "@modern-js/utils";
|
|
23
|
+
import { API_APP_NAME } from "./constants";
|
|
24
|
+
class Storage {
|
|
25
|
+
constructor() {
|
|
26
|
+
this.middlewares = [];
|
|
27
|
+
}
|
|
28
|
+
reset() {
|
|
29
|
+
this.middlewares = [];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
const createTransformAPI = (storage) => ({
|
|
33
|
+
addMiddleware(fn) {
|
|
34
|
+
storage.middlewares.push(fn);
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
var server_default = () => ({
|
|
38
|
+
name: "@modern-js/plugin-bff",
|
|
39
|
+
setup: (api) => {
|
|
40
|
+
const storage = new Storage();
|
|
41
|
+
const transformAPI = createTransformAPI(storage);
|
|
42
|
+
let apiAppPath = "";
|
|
43
|
+
return {
|
|
44
|
+
prepare() {
|
|
45
|
+
const { appDirectory, distDirectory } = api.useAppContext();
|
|
46
|
+
const root = isProd() ? distDirectory : appDirectory;
|
|
47
|
+
const apiPath = path.resolve(root || process.cwd(), API_DIR);
|
|
48
|
+
apiAppPath = path.resolve(apiPath, API_APP_NAME);
|
|
49
|
+
const apiMod = requireExistModule(apiAppPath);
|
|
50
|
+
if (apiMod && typeof apiMod === "function") {
|
|
51
|
+
apiMod(transformAPI);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
reset() {
|
|
55
|
+
storage.reset();
|
|
56
|
+
const newApiModule = requireExistModule(apiAppPath);
|
|
57
|
+
if (newApiModule && typeof newApiModule === "function") {
|
|
58
|
+
newApiModule(transformAPI);
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
gather({ addAPIMiddleware }) {
|
|
62
|
+
storage.middlewares.forEach((mid) => {
|
|
63
|
+
addAPIMiddleware(mid);
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
prepareApiServer(props, next) {
|
|
67
|
+
const { pwd, prefix } = props;
|
|
68
|
+
const apiDir = path.resolve(pwd, API_DIR);
|
|
69
|
+
const appContext = api.useAppContext();
|
|
70
|
+
const apiRouter = new ApiRouter({
|
|
71
|
+
apiDir,
|
|
72
|
+
prefix
|
|
73
|
+
});
|
|
74
|
+
const apiMode = apiRouter.getApiMode();
|
|
75
|
+
const apiHandlerInfos = apiRouter.getApiHandlers();
|
|
76
|
+
api.setAppContext(__spreadProps(__spreadValues({}, appContext), {
|
|
77
|
+
apiRouter,
|
|
78
|
+
apiHandlerInfos,
|
|
79
|
+
apiMode
|
|
80
|
+
}));
|
|
81
|
+
return next(props);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
export {
|
|
87
|
+
server_default as default
|
|
88
|
+
};
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var __async = (__this, __arguments, generator) => {
|
|
25
|
+
return new Promise((resolve, reject) => {
|
|
26
|
+
var fulfilled = (value) => {
|
|
27
|
+
try {
|
|
28
|
+
step(generator.next(value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
reject(e);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
var rejected = (value) => {
|
|
34
|
+
try {
|
|
35
|
+
step(generator.throw(value));
|
|
36
|
+
} catch (e) {
|
|
37
|
+
reject(e);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
41
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
var cli_exports = {};
|
|
45
|
+
__export(cli_exports, {
|
|
46
|
+
default: () => cli_default
|
|
47
|
+
});
|
|
48
|
+
module.exports = __toCommonJS(cli_exports);
|
|
49
|
+
var import_path = __toESM(require("path"));
|
|
50
|
+
var import_utils = require("@modern-js/utils");
|
|
51
|
+
var import_server_utils = require("@modern-js/server-utils");
|
|
52
|
+
var import_bff_core = require("@modern-js/bff-core");
|
|
53
|
+
var import_helper = require("./helper");
|
|
54
|
+
const DEFAULT_API_PREFIX = "/api";
|
|
55
|
+
const TS_CONFIG_FILENAME = "tsconfig.json";
|
|
56
|
+
var cli_default = () => ({
|
|
57
|
+
name: "@modern-js/plugin-bff",
|
|
58
|
+
setup: (api) => {
|
|
59
|
+
let unRegisterResolveRuntimePath = null;
|
|
60
|
+
return {
|
|
61
|
+
validateSchema() {
|
|
62
|
+
return import_utils.PLUGIN_SCHEMAS["@modern-js/plugin-bff"];
|
|
63
|
+
},
|
|
64
|
+
config() {
|
|
65
|
+
return {
|
|
66
|
+
tools: {
|
|
67
|
+
webpackChain: (chain, { name, CHAIN_ID }) => {
|
|
68
|
+
const { appDirectory, port } = api.useAppContext();
|
|
69
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
70
|
+
const { bff } = modernConfig || {};
|
|
71
|
+
const prefix = (bff == null ? void 0 : bff.prefix) || DEFAULT_API_PREFIX;
|
|
72
|
+
const rootDir = import_path.default.resolve(appDirectory, import_utils.API_DIR);
|
|
73
|
+
chain.resolve.alias.set("@api", rootDir);
|
|
74
|
+
const apiRouter = new import_bff_core.ApiRouter({
|
|
75
|
+
apiDir: rootDir,
|
|
76
|
+
prefix
|
|
77
|
+
});
|
|
78
|
+
const lambdaDir = apiRouter.getLambdaDir();
|
|
79
|
+
const existLambda = apiRouter.isExistLambda();
|
|
80
|
+
const apiRegexp = new RegExp(
|
|
81
|
+
(0, import_utils.normalizeOutputPath)(`${rootDir}${import_path.default.sep}.*(.[tj]s)$`)
|
|
82
|
+
);
|
|
83
|
+
chain.module.rule(CHAIN_ID.RULE.JS).exclude.add(apiRegexp);
|
|
84
|
+
chain.module.rule(CHAIN_ID.RULE.JS_BFF_API).test(apiRegexp).use("custom-loader").loader(require.resolve("./loader").replace(/\\/g, "/")).options({
|
|
85
|
+
prefix,
|
|
86
|
+
apiDir: rootDir,
|
|
87
|
+
lambdaDir,
|
|
88
|
+
existLambda,
|
|
89
|
+
port,
|
|
90
|
+
target: name
|
|
91
|
+
});
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
source: {
|
|
95
|
+
moduleScopes: [`./${import_utils.API_DIR}`, /create-request/]
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
},
|
|
99
|
+
modifyServerRoutes({ routes }) {
|
|
100
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
101
|
+
const { bff } = modernConfig || {};
|
|
102
|
+
const prefix = (bff == null ? void 0 : bff.prefix) || "/api";
|
|
103
|
+
const prefixList = [];
|
|
104
|
+
if (Array.isArray(prefix)) {
|
|
105
|
+
prefixList.push(...prefix);
|
|
106
|
+
} else {
|
|
107
|
+
prefixList.push(prefix);
|
|
108
|
+
}
|
|
109
|
+
const apiServerRoutes = prefixList.map((pre) => ({
|
|
110
|
+
urlPath: pre,
|
|
111
|
+
isApi: true,
|
|
112
|
+
entryPath: "",
|
|
113
|
+
isSPA: false,
|
|
114
|
+
isSSR: false
|
|
115
|
+
}));
|
|
116
|
+
return { routes: routes.concat(apiServerRoutes) };
|
|
117
|
+
},
|
|
118
|
+
collectServerPlugins({ plugins }) {
|
|
119
|
+
plugins.push({
|
|
120
|
+
"@modern-js/plugin-bff": "@modern-js/plugin-bff/server"
|
|
121
|
+
});
|
|
122
|
+
return { plugins };
|
|
123
|
+
},
|
|
124
|
+
beforeBuild() {
|
|
125
|
+
return __async(this, null, function* () {
|
|
126
|
+
if ((0, import_utils.isProd)()) {
|
|
127
|
+
const { internalDirectory } = api.useAppContext();
|
|
128
|
+
unRegisterResolveRuntimePath = (0, import_helper.registerModernRuntimePath)(internalDirectory);
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
},
|
|
132
|
+
afterBuild() {
|
|
133
|
+
return __async(this, null, function* () {
|
|
134
|
+
if (unRegisterResolveRuntimePath) {
|
|
135
|
+
unRegisterResolveRuntimePath();
|
|
136
|
+
}
|
|
137
|
+
const { appDirectory, distDirectory } = api.useAppContext();
|
|
138
|
+
const modernConfig = api.useResolvedConfigContext();
|
|
139
|
+
const distDir = import_path.default.resolve(distDirectory);
|
|
140
|
+
const apiDir = import_path.default.resolve(appDirectory, import_utils.API_DIR);
|
|
141
|
+
const sharedDir = import_path.default.resolve(appDirectory, import_utils.SHARED_DIR);
|
|
142
|
+
const tsconfigPath = import_path.default.resolve(appDirectory, TS_CONFIG_FILENAME);
|
|
143
|
+
const sourceDirs = [];
|
|
144
|
+
if (import_utils.fs.existsSync(apiDir)) {
|
|
145
|
+
sourceDirs.push(apiDir);
|
|
146
|
+
}
|
|
147
|
+
if (import_utils.fs.existsSync(sharedDir)) {
|
|
148
|
+
sourceDirs.push(sharedDir);
|
|
149
|
+
}
|
|
150
|
+
const { server } = modernConfig;
|
|
151
|
+
const { alias, define, globalVars } = modernConfig.source;
|
|
152
|
+
const { babel } = modernConfig.tools;
|
|
153
|
+
if (sourceDirs.length > 0) {
|
|
154
|
+
yield (0, import_server_utils.compile)(
|
|
155
|
+
appDirectory,
|
|
156
|
+
{
|
|
157
|
+
server,
|
|
158
|
+
alias,
|
|
159
|
+
define,
|
|
160
|
+
globalVars,
|
|
161
|
+
babelConfig: babel
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
sourceDirs,
|
|
165
|
+
distDir,
|
|
166
|
+
tsconfigPath
|
|
167
|
+
}
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
176
|
+
0 && (module.exports = {});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var constants_exports = {};
|
|
19
|
+
__export(constants_exports, {
|
|
20
|
+
API_APP_NAME: () => API_APP_NAME,
|
|
21
|
+
BUILD_FILES: () => BUILD_FILES
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(constants_exports);
|
|
24
|
+
const API_APP_NAME = "_app";
|
|
25
|
+
const BUILD_FILES = [
|
|
26
|
+
"**/*.[tj]sx?",
|
|
27
|
+
"!**/*.test.jsx?",
|
|
28
|
+
"!**/*.test.tsx?",
|
|
29
|
+
"!**/*.spec.jsx?",
|
|
30
|
+
"!**/*.spec.tsx?",
|
|
31
|
+
"!__tests__/*.tsx?",
|
|
32
|
+
"!__tests__/*.jsx?"
|
|
33
|
+
];
|
|
34
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
35
|
+
0 && (module.exports = {
|
|
36
|
+
API_APP_NAME,
|
|
37
|
+
BUILD_FILES
|
|
38
|
+
});
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var helper_exports = {};
|
|
25
|
+
__export(helper_exports, {
|
|
26
|
+
registerModernRuntimePath: () => registerModernRuntimePath
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(helper_exports);
|
|
29
|
+
var path = __toESM(require("path"));
|
|
30
|
+
var import_bff_core = require("@modern-js/bff-core");
|
|
31
|
+
const serverRuntimeAlias = "@modern-js/runtime/server";
|
|
32
|
+
const serverRuntimePath = ".runtime-exports/server";
|
|
33
|
+
const registerModernRuntimePath = (internalDirectory) => {
|
|
34
|
+
const paths = {
|
|
35
|
+
[serverRuntimeAlias]: path.join(internalDirectory, serverRuntimePath)
|
|
36
|
+
};
|
|
37
|
+
const unRegister = (0, import_bff_core.registerPaths)(paths);
|
|
38
|
+
return unRegister;
|
|
39
|
+
};
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
registerModernRuntimePath
|
|
43
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var src_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(src_exports);
|
|
17
|
+
__reExport(src_exports, require("./constants"), module.exports);
|