@modern-js/app-tools 2.27.1-alpha.0 → 2.28.1-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 +44 -0
- package/dist/cjs/analyze/generateCode.js +16 -7
- package/dist/cjs/analyze/getFileSystemEntry.js +2 -1
- package/dist/cjs/analyze/getServerRoutes.js +5 -4
- package/dist/cjs/analyze/index.js +209 -211
- package/dist/cjs/analyze/nestedRoutes.js +58 -15
- package/dist/cjs/analyze/templates.js +4 -4
- package/dist/cjs/builder/builder-rspack/adapterCopy.js +41 -43
- package/dist/cjs/builder/builder-webpack/adapterModern.js +23 -25
- package/dist/cjs/builder/generator/createBuilderProviderConfig.js +2 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +12 -15
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +33 -75
- package/dist/cjs/commands/build.js +2 -1
- package/dist/cjs/commands/inspect.js +2 -1
- package/dist/cjs/commands/serve.js +2 -2
- package/dist/cjs/index.js +3 -2
- package/dist/cjs/initialize/index.js +70 -72
- package/dist/esm/analyze/generateCode.js +35 -10
- package/dist/esm/analyze/getFileSystemEntry.js +2 -1
- package/dist/esm/analyze/getServerRoutes.js +5 -4
- package/dist/esm/analyze/nestedRoutes.js +59 -13
- package/dist/esm/analyze/templates.js +4 -4
- package/dist/esm/builder/builder-rspack/adapterCopy.js +1 -1
- package/dist/esm/builder/generator/createBuilderProviderConfig.js +2 -1
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +13 -16
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +41 -101
- package/dist/esm/commands/build.js +2 -2
- package/dist/esm/commands/inspect.js +2 -2
- package/dist/esm/commands/serve.js +2 -2
- package/dist/esm/index.js +3 -2
- package/dist/esm-node/analyze/generateCode.js +16 -7
- package/dist/esm-node/analyze/getFileSystemEntry.js +2 -1
- package/dist/esm-node/analyze/getServerRoutes.js +5 -4
- package/dist/esm-node/analyze/index.js +209 -211
- package/dist/esm-node/analyze/nestedRoutes.js +55 -15
- package/dist/esm-node/analyze/templates.js +4 -4
- package/dist/esm-node/builder/builder-rspack/adapterCopy.js +41 -43
- package/dist/esm-node/builder/builder-webpack/adapterModern.js +23 -25
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +2 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +12 -15
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +33 -75
- package/dist/esm-node/commands/build.js +2 -1
- package/dist/esm-node/commands/inspect.js +2 -1
- package/dist/esm-node/commands/serve.js +2 -2
- package/dist/esm-node/index.js +3 -2
- package/dist/esm-node/initialize/index.js +70 -72
- package/dist/types/analyze/nestedRoutes.d.ts +2 -1
- package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +0 -8
- package/package.json +24 -24
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,49 @@
|
|
|
1
1
|
# @modern-js/app-tools
|
|
2
2
|
|
|
3
|
+
## 2.28.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 6eae1e7: feat: support worker hmr using dev-server
|
|
8
|
+
feat: 借用 dev-server 支持 wokrer hmr
|
|
9
|
+
|
|
10
|
+
### Patch Changes
|
|
11
|
+
|
|
12
|
+
- 4e3ce96: fix: fix type for NestedRoute
|
|
13
|
+
fix: 修复 NestedRoute 的类型
|
|
14
|
+
- Updated dependencies [213089e]
|
|
15
|
+
- Updated dependencies [fb93353]
|
|
16
|
+
- Updated dependencies [4e3ce96]
|
|
17
|
+
- Updated dependencies [d870acd]
|
|
18
|
+
- Updated dependencies [6400d98]
|
|
19
|
+
- Updated dependencies [6eae1e7]
|
|
20
|
+
- Updated dependencies [362416f]
|
|
21
|
+
- Updated dependencies [aa0c0c3]
|
|
22
|
+
- Updated dependencies [9301e46]
|
|
23
|
+
- Updated dependencies [00b58a7]
|
|
24
|
+
- Updated dependencies [820bfe9]
|
|
25
|
+
- Updated dependencies [d3e52e4]
|
|
26
|
+
- Updated dependencies [7d966a1]
|
|
27
|
+
- @modern-js/builder-rspack-provider@2.28.0
|
|
28
|
+
- @modern-js/builder@2.28.0
|
|
29
|
+
- @modern-js/types@2.28.0
|
|
30
|
+
- @modern-js/builder-webpack-provider@2.28.0
|
|
31
|
+
- @modern-js/builder-shared@2.28.0
|
|
32
|
+
- @modern-js/prod-server@2.28.0
|
|
33
|
+
- @modern-js/server@2.28.0
|
|
34
|
+
- @modern-js/utils@2.28.0
|
|
35
|
+
- @modern-js/upgrade@2.28.0
|
|
36
|
+
- @modern-js/builder-plugin-node-polyfill@2.28.0
|
|
37
|
+
- @modern-js/builder-plugin-esbuild@2.28.0
|
|
38
|
+
- @modern-js/core@2.28.0
|
|
39
|
+
- @modern-js/plugin-data-loader@2.28.0
|
|
40
|
+
- @modern-js/server-core@2.28.0
|
|
41
|
+
- @modern-js/plugin-i18n@2.28.0
|
|
42
|
+
- @modern-js/plugin-lint@2.28.0
|
|
43
|
+
- @modern-js/new-action@2.28.0
|
|
44
|
+
- @modern-js/node-bundle-require@2.28.0
|
|
45
|
+
- @modern-js/plugin@2.28.0
|
|
46
|
+
|
|
3
47
|
## 2.27.0
|
|
4
48
|
|
|
5
49
|
### Patch Changes
|
|
@@ -74,11 +74,13 @@ ${initialize || ""}`);
|
|
|
74
74
|
${initialize || ""}`).join("\n");
|
|
75
75
|
};
|
|
76
76
|
const generateCode = async (appContext, config, entrypoints, api) => {
|
|
77
|
+
var _config, _config_runtime_router, _config_runtime, _config1;
|
|
77
78
|
const { internalDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName } = appContext;
|
|
78
79
|
const hookRunners = api.useHookRunners();
|
|
79
80
|
const isV5 = (0, _utils.isRouterV5)(config);
|
|
80
81
|
const getRoutes = isV5 ? _getClientRoutes.getClientRoutesLegacy : _getClientRoutes.getClientRoutes;
|
|
81
82
|
const importsStatemets = /* @__PURE__ */ new Map();
|
|
83
|
+
const oldVersion = typeof ((_config = config) === null || _config === void 0 ? void 0 : _config.runtime.router) === "object" ? Boolean((_config1 = config) === null || _config1 === void 0 ? void 0 : (_config_runtime = _config1.runtime) === null || _config_runtime === void 0 ? void 0 : (_config_runtime_router = _config_runtime.router) === null || _config_runtime_router === void 0 ? void 0 : _config_runtime_router.oldVersion) : false;
|
|
82
84
|
await Promise.all(entrypoints.map(generateEntryCode));
|
|
83
85
|
return {
|
|
84
86
|
importsStatemets
|
|
@@ -87,9 +89,9 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
87
89
|
const { entryName, isMainEntry, isAutoMount, fileSystemRoutes } = entrypoint;
|
|
88
90
|
if (isAutoMount) {
|
|
89
91
|
if (fileSystemRoutes) {
|
|
90
|
-
var _config_output;
|
|
92
|
+
var _config_output, _config2;
|
|
91
93
|
let initialRoutes = [];
|
|
92
|
-
let
|
|
94
|
+
let nestedRoutes = null;
|
|
93
95
|
if (entrypoint.entry) {
|
|
94
96
|
initialRoutes = getRoutes({
|
|
95
97
|
entrypoint,
|
|
@@ -100,12 +102,19 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
100
102
|
});
|
|
101
103
|
}
|
|
102
104
|
if (!isV5 && entrypoint.nestedRoutesEntry) {
|
|
103
|
-
|
|
105
|
+
nestedRoutes = await (0, _nestedRoutes.walk)(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
|
|
104
106
|
name: internalSrcAlias,
|
|
105
107
|
basename: srcDirectory
|
|
106
|
-
}, entrypoint.entryName, entrypoint.isMainEntry);
|
|
107
|
-
if (
|
|
108
|
-
|
|
108
|
+
}, entrypoint.entryName, entrypoint.isMainEntry, oldVersion);
|
|
109
|
+
if (nestedRoutes) {
|
|
110
|
+
if (!Array.isArray(nestedRoutes)) {
|
|
111
|
+
nestedRoutes = [
|
|
112
|
+
nestedRoutes
|
|
113
|
+
];
|
|
114
|
+
}
|
|
115
|
+
for (const route of nestedRoutes) {
|
|
116
|
+
initialRoutes.unshift(route);
|
|
117
|
+
}
|
|
109
118
|
}
|
|
110
119
|
}
|
|
111
120
|
const { routes } = await hookRunners.modifyFileSystemRoutes({
|
|
@@ -134,7 +143,7 @@ const generateCode = async (appContext, config, entrypoints, api) => {
|
|
|
134
143
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
135
144
|
entryName: entrypoint.entryName,
|
|
136
145
|
internalDirectory,
|
|
137
|
-
splitRouteChunks: config2 === null ||
|
|
146
|
+
splitRouteChunks: (_config2 = config2) === null || _config2 === void 0 ? void 0 : (_config_output = _config2.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
|
|
138
147
|
})
|
|
139
148
|
});
|
|
140
149
|
if (entrypoint.nestedRoutesEntry && (0, _utils.isUseSSRBundle)(config2)) {
|
|
@@ -80,7 +80,8 @@ const getFileSystemEntry = (appContext, config) => {
|
|
|
80
80
|
const { source: { entriesDir, disableEntryDirs } } = config;
|
|
81
81
|
let disabledDirs = [];
|
|
82
82
|
if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
|
|
83
|
-
|
|
83
|
+
var _disableEntryDirs;
|
|
84
|
+
disabledDirs = (_disableEntryDirs = disableEntryDirs) === null || _disableEntryDirs === void 0 ? void 0 : _disableEntryDirs.map((dir) => (0, _utils.ensureAbsolutePath)(appDirectory, dir));
|
|
84
85
|
}
|
|
85
86
|
const src = (0, _utils.ensureAbsolutePath)(appDirectory, entriesDir || "");
|
|
86
87
|
if (_fs.default.existsSync(src)) {
|
|
@@ -79,17 +79,18 @@ const applyRouteOptions = (original, routeOptions) => {
|
|
|
79
79
|
return routes;
|
|
80
80
|
};
|
|
81
81
|
const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
82
|
-
var _deploy_worker;
|
|
82
|
+
var _deploy_worker, _deploy;
|
|
83
83
|
const { source: { mainEntryName }, html: { disableHtmlFolder }, output: { distPath: { html: htmlPath } = {} }, server: { baseUrl, routes, ssr, ssrByEntries }, deploy } = config;
|
|
84
84
|
const { packageName } = appContext;
|
|
85
|
-
const workerSSR = deploy === null ||
|
|
85
|
+
const workerSSR = (_deploy = deploy) === null || _deploy === void 0 ? void 0 : (_deploy_worker = _deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
|
|
86
86
|
let htmlRoutes = entrypoints.reduce((previous, { entryName }) => {
|
|
87
|
+
var _routes, _routes1;
|
|
87
88
|
const isMainEntry = entryName === (mainEntryName || _utils.MAIN_ENTRY_NAME);
|
|
88
89
|
const entryOptions = (0, _utils.getEntryOptions)(entryName, isMainEntry, ssr, ssrByEntries, packageName);
|
|
89
90
|
const isSSR = Boolean(entryOptions);
|
|
90
91
|
const isWorker = Boolean(workerSSR);
|
|
91
92
|
const isStream = typeof entryOptions === "object" && entryOptions.mode === "stream";
|
|
92
|
-
const { resHeaders } = (routes === null ||
|
|
93
|
+
const { resHeaders } = ((_routes = routes) === null || _routes === void 0 ? void 0 : _routes[entryName]) || {};
|
|
93
94
|
let route = {
|
|
94
95
|
urlPath: `/${isMainEntry ? "" : entryName}`,
|
|
95
96
|
entryName,
|
|
@@ -101,7 +102,7 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
|
101
102
|
worker: isWorker ? `${_utils.SERVER_WORKER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0,
|
|
102
103
|
bundle: isSSR ? `${_utils.SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : void 0
|
|
103
104
|
};
|
|
104
|
-
if (routes === null ||
|
|
105
|
+
if ((_routes1 = routes) === null || _routes1 === void 0 ? void 0 : _routes1.hasOwnProperty(entryName)) {
|
|
105
106
|
const routeOptions = (0, _utils.isPlainObject)(routes[entryName]) ? routes[entryName] : {
|
|
106
107
|
route: routes[entryName]
|
|
107
108
|
};
|
|
@@ -22,234 +22,232 @@ const _utils1 = require("./utils");
|
|
|
22
22
|
const _constants = require("./constants");
|
|
23
23
|
const _generateCode = require("./generateCode");
|
|
24
24
|
const debug = (0, _utils.createDebugger)("plugin-analyze");
|
|
25
|
-
const _default = ({ bundler }) => {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
_utils.fs.emptydirSync(appContext.internalDirectory);
|
|
41
|
-
}
|
|
42
|
-
} catch {
|
|
43
|
-
}
|
|
44
|
-
const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
|
|
45
|
-
await hookRunners.addRuntimeExports();
|
|
46
|
-
if (apiOnly) {
|
|
47
|
-
const { routes: routes2 } = await hookRunners.modifyServerRoutes({
|
|
48
|
-
routes: []
|
|
49
|
-
});
|
|
50
|
-
debug(`server routes: %o`, routes2);
|
|
51
|
-
appContext = {
|
|
52
|
-
...api.useAppContext(),
|
|
53
|
-
apiOnly,
|
|
54
|
-
serverRoutes: routes2
|
|
55
|
-
};
|
|
56
|
-
api.setAppContext(appContext);
|
|
57
|
-
return;
|
|
25
|
+
const _default = ({ bundler }) => ({
|
|
26
|
+
name: "@modern-js/plugin-analyze",
|
|
27
|
+
setup: (api) => {
|
|
28
|
+
let pagesDir = [];
|
|
29
|
+
let nestedRouteEntries = [];
|
|
30
|
+
let originEntrypoints = [];
|
|
31
|
+
return {
|
|
32
|
+
async prepare() {
|
|
33
|
+
var _resolvedConfig_source;
|
|
34
|
+
let appContext = api.useAppContext();
|
|
35
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
36
|
+
const hookRunners = api.useHookRunners();
|
|
37
|
+
try {
|
|
38
|
+
if ((0, _utils1.checkIsBuildCommands)()) {
|
|
39
|
+
_utils.fs.emptydirSync(appContext.internalDirectory);
|
|
58
40
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
debug(`entrypoints: %o`, entrypoints);
|
|
67
|
-
const initialRoutes = getServerRoutes(entrypoints, {
|
|
68
|
-
appContext,
|
|
69
|
-
config: resolvedConfig
|
|
70
|
-
});
|
|
71
|
-
const { routes } = await hookRunners.modifyServerRoutes({
|
|
72
|
-
routes: initialRoutes
|
|
41
|
+
} catch {
|
|
42
|
+
}
|
|
43
|
+
const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.entriesDir, appContext.apiDirectory);
|
|
44
|
+
await hookRunners.addRuntimeExports();
|
|
45
|
+
if (apiOnly) {
|
|
46
|
+
const { routes: routes2 } = await hookRunners.modifyServerRoutes({
|
|
47
|
+
routes: []
|
|
73
48
|
});
|
|
74
|
-
debug(`server routes: %o`,
|
|
49
|
+
debug(`server routes: %o`, routes2);
|
|
75
50
|
appContext = {
|
|
76
51
|
...api.useAppContext(),
|
|
77
|
-
entrypoints,
|
|
78
|
-
serverRoutes: routes
|
|
79
|
-
};
|
|
80
|
-
api.setAppContext(appContext);
|
|
81
|
-
nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
|
|
82
|
-
pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !_path.extname(entry)).concat(nestedRouteEntries);
|
|
83
|
-
originEntrypoints = (0, _lodash.cloneDeep)(entrypoints);
|
|
84
|
-
const { importsStatemets } = await generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
85
|
-
const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
|
|
86
|
-
appContext,
|
|
87
|
-
config: resolvedConfig
|
|
88
|
-
});
|
|
89
|
-
debug(`html templates: %o`, htmlTemplates);
|
|
90
|
-
await hookRunners.addDefineTypes();
|
|
91
|
-
debug(`add Define Types`);
|
|
92
|
-
let checkedEntries = entrypoints.map((point) => point.entryName);
|
|
93
|
-
if ((0, _utils.isDevCommand)()) {
|
|
94
|
-
const { entry } = (0, _utils.minimist)((0, _utils.getArgv)());
|
|
95
|
-
checkedEntries = await (0, _getSelectedEntries.getSelectedEntries)(typeof entry === "string" ? entry.split(",") : entry, entrypoints);
|
|
96
|
-
}
|
|
97
|
-
appContext = {
|
|
98
|
-
...api.useAppContext(),
|
|
99
|
-
entrypoints,
|
|
100
|
-
checkedEntries,
|
|
101
52
|
apiOnly,
|
|
102
|
-
serverRoutes:
|
|
103
|
-
htmlTemplates
|
|
53
|
+
serverRoutes: routes2
|
|
104
54
|
};
|
|
105
55
|
api.setAppContext(appContext);
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const [{ getBundleEntry }, { getServerRoutes }, { generateCode }, { getHtmlTemplate }] = await Promise.all([
|
|
59
|
+
Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./getBundleEntry"))),
|
|
60
|
+
Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./getServerRoutes"))),
|
|
61
|
+
Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./generateCode"))),
|
|
62
|
+
Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./getHtmlTemplate")))
|
|
63
|
+
]);
|
|
64
|
+
const entrypoints = getBundleEntry(appContext, resolvedConfig);
|
|
65
|
+
debug(`entrypoints: %o`, entrypoints);
|
|
66
|
+
const initialRoutes = getServerRoutes(entrypoints, {
|
|
67
|
+
appContext,
|
|
68
|
+
config: resolvedConfig
|
|
69
|
+
});
|
|
70
|
+
const { routes } = await hookRunners.modifyServerRoutes({
|
|
71
|
+
routes: initialRoutes
|
|
72
|
+
});
|
|
73
|
+
debug(`server routes: %o`, routes);
|
|
74
|
+
appContext = {
|
|
75
|
+
...api.useAppContext(),
|
|
76
|
+
entrypoints,
|
|
77
|
+
serverRoutes: routes
|
|
78
|
+
};
|
|
79
|
+
api.setAppContext(appContext);
|
|
80
|
+
nestedRouteEntries = entrypoints.map((point) => point.nestedRoutesEntry).filter(Boolean);
|
|
81
|
+
pagesDir = entrypoints.map((point) => point.entry).filter((entry) => entry && !_path.extname(entry)).concat(nestedRouteEntries);
|
|
82
|
+
originEntrypoints = (0, _lodash.cloneDeep)(entrypoints);
|
|
83
|
+
const { importsStatemets } = await generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
84
|
+
const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
|
|
85
|
+
appContext,
|
|
86
|
+
config: resolvedConfig
|
|
87
|
+
});
|
|
88
|
+
debug(`html templates: %o`, htmlTemplates);
|
|
89
|
+
await hookRunners.addDefineTypes();
|
|
90
|
+
debug(`add Define Types`);
|
|
91
|
+
let checkedEntries = entrypoints.map((point) => point.entryName);
|
|
92
|
+
if ((0, _utils.isDevCommand)()) {
|
|
93
|
+
const { entry } = (0, _utils.minimist)((0, _utils.getArgv)());
|
|
94
|
+
checkedEntries = await (0, _getSelectedEntries.getSelectedEntries)(typeof entry === "string" ? entry.split(",") : entry, entrypoints);
|
|
95
|
+
}
|
|
96
|
+
appContext = {
|
|
97
|
+
...api.useAppContext(),
|
|
98
|
+
entrypoints,
|
|
99
|
+
checkedEntries,
|
|
100
|
+
apiOnly,
|
|
101
|
+
serverRoutes: routes,
|
|
102
|
+
htmlTemplates
|
|
103
|
+
};
|
|
104
|
+
api.setAppContext(appContext);
|
|
105
|
+
if ((0, _utils1.checkIsBuildCommands)()) {
|
|
106
|
+
const normalizedConfig = api.useResolvedConfigContext();
|
|
107
|
+
const createBuilderForModern = await (0, _builder.createBuilderGenerator)(bundler);
|
|
108
|
+
const builder = await createBuilderForModern({
|
|
109
|
+
normalizedConfig,
|
|
110
|
+
appContext
|
|
111
|
+
});
|
|
112
|
+
builder.onBeforeBuild(async ({ bundlerConfigs }) => {
|
|
113
|
+
const hookRunners2 = api.useHookRunners();
|
|
114
|
+
await (0, _routes.generateRoutes)(appContext);
|
|
115
|
+
await hookRunners2.beforeBuild({
|
|
116
|
+
bundlerConfigs
|
|
112
117
|
});
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
});
|
|
118
|
+
});
|
|
119
|
+
builder.onAfterBuild(async ({ stats }) => {
|
|
120
|
+
const hookRunners2 = api.useHookRunners();
|
|
121
|
+
await hookRunners2.afterBuild({
|
|
122
|
+
stats
|
|
119
123
|
});
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
+
await (0, _config.emitResolvedConfig)(appContext.appDirectory, normalizedConfig);
|
|
125
|
+
});
|
|
126
|
+
builder.onDevCompileDone(async ({ isFirstCompile }) => {
|
|
127
|
+
const hookRunners2 = api.useHookRunners();
|
|
128
|
+
if (process.stdout.isTTY || isFirstCompile) {
|
|
129
|
+
hookRunners2.afterDev({
|
|
130
|
+
isFirstCompile
|
|
124
131
|
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
builder.onDevCompileDone(async ({ isFirstCompile }) => {
|
|
128
|
-
const hookRunners2 = api.useHookRunners();
|
|
129
|
-
if (process.stdout.isTTY || isFirstCompile) {
|
|
130
|
-
hookRunners2.afterDev({
|
|
131
|
-
isFirstCompile
|
|
132
|
-
});
|
|
133
|
-
if (isFirstCompile) {
|
|
134
|
-
(0, _printInstructions.printInstructions)(hookRunners2, appContext, normalizedConfig);
|
|
135
|
-
}
|
|
132
|
+
if (isFirstCompile) {
|
|
133
|
+
(0, _printInstructions.printInstructions)(hookRunners2, appContext, normalizedConfig);
|
|
136
134
|
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
builder.onBeforeCreateCompiler(async ({ bundlerConfigs }) => {
|
|
138
|
+
const hookRunners2 = api.useHookRunners();
|
|
139
|
+
await (0, _generateCode.generateIndexCode)({
|
|
140
|
+
appContext,
|
|
141
|
+
config: resolvedConfig,
|
|
142
|
+
entrypoints,
|
|
143
|
+
api,
|
|
144
|
+
importsStatemets,
|
|
145
|
+
bundlerConfigs
|
|
137
146
|
});
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
await (0, _generateCode.generateIndexCode)({
|
|
141
|
-
appContext,
|
|
142
|
-
config: resolvedConfig,
|
|
143
|
-
entrypoints,
|
|
144
|
-
api,
|
|
145
|
-
importsStatemets,
|
|
146
|
-
bundlerConfigs
|
|
147
|
-
});
|
|
148
|
-
await hookRunners2.beforeCreateCompiler({
|
|
149
|
-
bundlerConfigs
|
|
150
|
-
});
|
|
147
|
+
await hookRunners2.beforeCreateCompiler({
|
|
148
|
+
bundlerConfigs
|
|
151
149
|
});
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
150
|
+
});
|
|
151
|
+
builder.onAfterCreateCompiler(async ({ compiler }) => {
|
|
152
|
+
const hookRunners2 = api.useHookRunners();
|
|
153
|
+
await hookRunners2.afterCreateCompiler({
|
|
154
|
+
compiler
|
|
157
155
|
});
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
api.setAppContext(appContext);
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
watchFiles() {
|
|
167
|
-
return {
|
|
168
|
-
files: pagesDir,
|
|
169
|
-
isPrivate: true
|
|
170
|
-
};
|
|
171
|
-
},
|
|
172
|
-
resolvedConfig({ resolved }) {
|
|
173
|
-
const appContext = api.useAppContext();
|
|
174
|
-
const config = (0, _config1.initialNormalizedConfig)(resolved, appContext, bundler);
|
|
175
|
-
return {
|
|
176
|
-
resolved: config
|
|
156
|
+
});
|
|
157
|
+
builder.addPlugins(resolvedConfig.builderPlugins);
|
|
158
|
+
appContext = {
|
|
159
|
+
...api.useAppContext(),
|
|
160
|
+
builder
|
|
177
161
|
};
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
162
|
+
api.setAppContext(appContext);
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
watchFiles() {
|
|
166
|
+
return {
|
|
167
|
+
files: pagesDir,
|
|
168
|
+
isPrivate: true
|
|
169
|
+
};
|
|
170
|
+
},
|
|
171
|
+
resolvedConfig({ resolved }) {
|
|
172
|
+
const appContext = api.useAppContext();
|
|
173
|
+
const config = (0, _config1.initialNormalizedConfig)(resolved, appContext, bundler);
|
|
174
|
+
return {
|
|
175
|
+
resolved: config
|
|
176
|
+
};
|
|
177
|
+
},
|
|
178
|
+
// This logic is not in the router plugin to avoid having to include some dependencies in the utils package
|
|
179
|
+
async modifyEntryImports({ entrypoint, imports }) {
|
|
180
|
+
const appContext = api.useAppContext();
|
|
181
|
+
const { srcDirectory, internalSrcAlias } = appContext;
|
|
182
|
+
const { fileSystemRoutes, nestedRoutesEntry } = entrypoint;
|
|
183
|
+
if (fileSystemRoutes && nestedRoutesEntry) {
|
|
184
|
+
const rootLayoutPath = _path.join(nestedRoutesEntry, "layout");
|
|
185
|
+
const rootLayoutFile = (0, _utils.findExists)([
|
|
186
|
+
".js",
|
|
187
|
+
".ts",
|
|
188
|
+
".jsx",
|
|
189
|
+
".tsx"
|
|
190
|
+
].map((ext) => `${rootLayoutPath}${ext}`));
|
|
191
|
+
if (rootLayoutFile) {
|
|
192
|
+
const rootLayoutBuffer = await _utils.fs.readFile(rootLayoutFile);
|
|
193
|
+
const rootLayout = rootLayoutBuffer.toString();
|
|
194
|
+
const [, moduleExports] = await (0, _utils1.parseModule)({
|
|
195
|
+
source: rootLayout.toString(),
|
|
196
|
+
filename: rootLayoutFile
|
|
197
|
+
});
|
|
198
|
+
const hasAppConfig = moduleExports.some((e) => e.n === _constants.APP_CONFIG_NAME);
|
|
199
|
+
const generateLayoutPath = (0, _utils1.replaceWithAlias)(srcDirectory, rootLayoutFile, internalSrcAlias);
|
|
200
|
+
if (hasAppConfig) {
|
|
201
|
+
imports.push({
|
|
202
|
+
value: generateLayoutPath,
|
|
203
|
+
specifiers: [
|
|
204
|
+
{
|
|
205
|
+
imported: _constants.APP_CONFIG_NAME
|
|
206
|
+
}
|
|
207
|
+
]
|
|
198
208
|
});
|
|
199
|
-
const hasAppConfig = moduleExports.some((e) => e.n === _constants.APP_CONFIG_NAME);
|
|
200
|
-
const generateLayoutPath = (0, _utils1.replaceWithAlias)(srcDirectory, rootLayoutFile, internalSrcAlias);
|
|
201
|
-
if (hasAppConfig) {
|
|
202
|
-
imports.push({
|
|
203
|
-
value: generateLayoutPath,
|
|
204
|
-
specifiers: [
|
|
205
|
-
{
|
|
206
|
-
imported: _constants.APP_CONFIG_NAME
|
|
207
|
-
}
|
|
208
|
-
]
|
|
209
|
-
});
|
|
210
|
-
}
|
|
211
|
-
const hasAppInit = moduleExports.some((e) => e.n === _constants.APP_INIT_EXPORTED);
|
|
212
|
-
if (hasAppInit) {
|
|
213
|
-
imports.push({
|
|
214
|
-
value: generateLayoutPath,
|
|
215
|
-
specifiers: [
|
|
216
|
-
{
|
|
217
|
-
imported: _constants.APP_INIT_EXPORTED,
|
|
218
|
-
local: _constants.APP_INIT_IMPORTED
|
|
219
|
-
}
|
|
220
|
-
]
|
|
221
|
-
});
|
|
222
|
-
}
|
|
223
209
|
}
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
210
|
+
const hasAppInit = moduleExports.some((e) => e.n === _constants.APP_INIT_EXPORTED);
|
|
211
|
+
if (hasAppInit) {
|
|
212
|
+
imports.push({
|
|
213
|
+
value: generateLayoutPath,
|
|
214
|
+
specifiers: [
|
|
215
|
+
{
|
|
216
|
+
imported: _constants.APP_INIT_EXPORTED,
|
|
217
|
+
local: _constants.APP_INIT_IMPORTED
|
|
218
|
+
}
|
|
219
|
+
]
|
|
220
|
+
});
|
|
235
221
|
}
|
|
236
|
-
};
|
|
237
|
-
},
|
|
238
|
-
async fileChange(e) {
|
|
239
|
-
const appContext = api.useAppContext();
|
|
240
|
-
const { appDirectory } = appContext;
|
|
241
|
-
const { filename, eventType } = e;
|
|
242
|
-
const isPageFile = (name) => pagesDir.some((pageDir) => name.includes(pageDir));
|
|
243
|
-
const absoluteFilePath = _path.resolve(appDirectory, filename);
|
|
244
|
-
const isRouteComponent = isPageFile(absoluteFilePath) && (0, _utils1.isPageComponentFile)(absoluteFilePath);
|
|
245
|
-
if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
|
|
246
|
-
const resolvedConfig = api.useResolvedConfigContext();
|
|
247
|
-
const { generateCode } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./generateCode")));
|
|
248
|
-
const entrypoints = (0, _lodash.cloneDeep)(originEntrypoints);
|
|
249
|
-
generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
250
222
|
}
|
|
251
223
|
}
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
};
|
|
224
|
+
return {
|
|
225
|
+
entrypoint,
|
|
226
|
+
imports
|
|
227
|
+
};
|
|
228
|
+
},
|
|
229
|
+
validateSchema() {
|
|
230
|
+
return {
|
|
231
|
+
target: "output.splitRouteChunks",
|
|
232
|
+
schema: {
|
|
233
|
+
type: "boolean"
|
|
234
|
+
}
|
|
235
|
+
};
|
|
236
|
+
},
|
|
237
|
+
async fileChange(e) {
|
|
238
|
+
const appContext = api.useAppContext();
|
|
239
|
+
const { appDirectory } = appContext;
|
|
240
|
+
const { filename, eventType } = e;
|
|
241
|
+
const isPageFile = (name) => pagesDir.some((pageDir) => name.includes(pageDir));
|
|
242
|
+
const absoluteFilePath = _path.resolve(appDirectory, filename);
|
|
243
|
+
const isRouteComponent = isPageFile(absoluteFilePath) && (0, _utils1.isPageComponentFile)(absoluteFilePath);
|
|
244
|
+
if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
|
|
245
|
+
const resolvedConfig = api.useResolvedConfigContext();
|
|
246
|
+
const { generateCode } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./generateCode")));
|
|
247
|
+
const entrypoints = (0, _lodash.cloneDeep)(originEntrypoints);
|
|
248
|
+
generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
});
|