@modern-js/app-tools 2.27.0 → 2.28.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 +2 -2
- 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 +2 -2
- package/dist/cjs/analyze/templates.js +4 -4
- package/dist/cjs/analyze/utils.js +2 -1
- 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 +11 -9
- package/dist/cjs/commands/build.js +2 -1
- package/dist/cjs/commands/dev.js +3 -2
- package/dist/cjs/commands/inspect.js +2 -1
- package/dist/cjs/commands/serve.js +2 -2
- package/dist/cjs/index.js +7 -2
- package/dist/cjs/initialize/index.js +70 -72
- package/dist/esm/analyze/generateCode.js +2 -2
- package/dist/esm/analyze/getFileSystemEntry.js +2 -1
- package/dist/esm/analyze/getServerRoutes.js +5 -4
- package/dist/esm/analyze/nestedRoutes.js +2 -2
- package/dist/esm/analyze/templates.js +4 -4
- package/dist/esm/analyze/utils.js +2 -1
- 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 +12 -10
- package/dist/esm/commands/build.js +2 -2
- package/dist/esm/commands/dev.js +5 -3
- package/dist/esm/commands/inspect.js +2 -2
- package/dist/esm/commands/serve.js +2 -2
- package/dist/esm/index.js +7 -5
- package/dist/esm-node/analyze/generateCode.js +2 -2
- 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 +2 -2
- package/dist/esm-node/analyze/templates.js +4 -4
- package/dist/esm-node/analyze/utils.js +2 -1
- 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 +11 -9
- package/dist/esm-node/commands/build.js +2 -1
- package/dist/esm-node/commands/dev.js +3 -2
- package/dist/esm-node/commands/inspect.js +2 -1
- package/dist/esm-node/commands/serve.js +2 -2
- package/dist/esm-node/index.js +6 -4
- package/dist/esm-node/initialize/index.js +70 -72
- package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +2 -2
- package/dist/types/analyze/nestedRoutes.d.ts +2 -2
- package/dist/types/analyze/templates.d.ts +3 -3
- package/dist/types/commands/dev.d.ts +4 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/types/hooks.d.ts +2 -2
- package/package.json +24 -24
|
@@ -13,52 +13,50 @@ const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
|
|
|
13
13
|
const _fsextra = /* @__PURE__ */ _interop_require_default._(require("@modern-js/utils/fs-extra"));
|
|
14
14
|
const _utils = require("@modern-js/utils");
|
|
15
15
|
const _shared = require("../shared");
|
|
16
|
-
const builderPluginAdpaterCopy = (options) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
config.builtins
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
]
|
|
30
|
-
}
|
|
31
|
-
};
|
|
32
|
-
publicPath = (_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.publicPath;
|
|
33
|
-
});
|
|
34
|
-
api.onDevCompileDone(async () => {
|
|
35
|
-
await transformHtmlFiles();
|
|
36
|
-
});
|
|
37
|
-
api.onAfterBuild(async () => {
|
|
38
|
-
await transformHtmlFiles();
|
|
39
|
-
});
|
|
40
|
-
async function transformHtmlFiles() {
|
|
41
|
-
var _normalizedConfig_output_distPath;
|
|
42
|
-
const { normalizedConfig } = options;
|
|
43
|
-
const publicDir = _path.default.resolve(((_normalizedConfig_output_distPath = normalizedConfig.output.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.root) || "./dist", "./public");
|
|
44
|
-
if (!_fsextra.default.existsSync(publicDir) || !_fsextra.default.statSync(publicDir).isDirectory()) {
|
|
45
|
-
return;
|
|
16
|
+
const builderPluginAdpaterCopy = (options) => ({
|
|
17
|
+
name: "builder-plugin-adapter-rspack-copy",
|
|
18
|
+
setup(api) {
|
|
19
|
+
let publicPath;
|
|
20
|
+
api.modifyRspackConfig((config) => {
|
|
21
|
+
var _config_builtins_copy, _config_builtins, _config_output;
|
|
22
|
+
config.builtins = {
|
|
23
|
+
...config.builtins || {},
|
|
24
|
+
copy: {
|
|
25
|
+
patterns: [
|
|
26
|
+
...((_config_builtins = config.builtins) === null || _config_builtins === void 0 ? void 0 : (_config_builtins_copy = _config_builtins.copy) === null || _config_builtins_copy === void 0 ? void 0 : _config_builtins_copy.patterns) || [],
|
|
27
|
+
...createConfigBuiltinCopy(options)
|
|
28
|
+
]
|
|
46
29
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
30
|
+
};
|
|
31
|
+
publicPath = (_config_output = config.output) === null || _config_output === void 0 ? void 0 : _config_output.publicPath;
|
|
32
|
+
});
|
|
33
|
+
api.onDevCompileDone(async () => {
|
|
34
|
+
await transformHtmlFiles();
|
|
35
|
+
});
|
|
36
|
+
api.onAfterBuild(async () => {
|
|
37
|
+
await transformHtmlFiles();
|
|
38
|
+
});
|
|
39
|
+
async function transformHtmlFiles() {
|
|
40
|
+
var _normalizedConfig_output_distPath;
|
|
41
|
+
const { normalizedConfig } = options;
|
|
42
|
+
const publicDir = _path.default.resolve(((_normalizedConfig_output_distPath = normalizedConfig.output.distPath) === null || _normalizedConfig_output_distPath === void 0 ? void 0 : _normalizedConfig_output_distPath.root) || "./dist", "./public");
|
|
43
|
+
if (!_fsextra.default.existsSync(publicDir) || !_fsextra.default.statSync(publicDir).isDirectory()) {
|
|
44
|
+
return;
|
|
58
45
|
}
|
|
46
|
+
const HTML_REGEXP = /\.html?$/;
|
|
47
|
+
const filepaths = (await _fsextra.default.readdir(publicDir)).map((file) => _path.default.resolve(publicDir, file));
|
|
48
|
+
await Promise.all(filepaths.filter((file) => HTML_REGEXP.test(file)).map(async (file) => {
|
|
49
|
+
const content = await _fsextra.default.readFile(file, "utf-8");
|
|
50
|
+
if (publicPath) {
|
|
51
|
+
await _fsextra.default.writeFile(file, content.replace(/<%=\s*assetPrefix\s*%>/g, (0, _utils.removeTailSlash)(publicPath)));
|
|
52
|
+
} else {
|
|
53
|
+
_utils.logger.warn("Expect get a string from `publicPath`, but receive `undefined`.");
|
|
54
|
+
await _fsextra.default.writeFile(file, content.replace(/<%=\s*assetPrefix\s*%>/g, (0, _utils.removeTailSlash)("/")));
|
|
55
|
+
}
|
|
56
|
+
}));
|
|
59
57
|
}
|
|
60
|
-
}
|
|
61
|
-
};
|
|
58
|
+
}
|
|
59
|
+
});
|
|
62
60
|
function createConfigBuiltinCopy(options) {
|
|
63
61
|
const { normalizedConfig, appContext } = options;
|
|
64
62
|
const { publicDir } = (0, _shared.createCopyInfo)(appContext, normalizedConfig);
|
|
@@ -10,28 +10,26 @@ Object.defineProperty(exports, "builderPluginAdapterModern", {
|
|
|
10
10
|
});
|
|
11
11
|
const _path = require("path");
|
|
12
12
|
const _createCopyPattern = require("./createCopyPattern");
|
|
13
|
-
const builderPluginAdapterModern = (options) => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
};
|
|
37
|
-
};
|
|
13
|
+
const builderPluginAdapterModern = (options) => ({
|
|
14
|
+
name: "builder-plugin-adapter-modern",
|
|
15
|
+
setup(api) {
|
|
16
|
+
const { normalizedConfig: modernConfig, appContext } = options;
|
|
17
|
+
api.modifyWebpackChain((chain, { CHAIN_ID }) => {
|
|
18
|
+
chain.resolve.modules.add("node_modules").add((0, _path.join)(api.context.rootPath, "node_modules"));
|
|
19
|
+
if (chain.plugins.has(CHAIN_ID.PLUGIN.COPY)) {
|
|
20
|
+
const defaultCopyPattern = (0, _createCopyPattern.createPublicPattern)(appContext, modernConfig, chain);
|
|
21
|
+
chain.plugin(CHAIN_ID.PLUGIN.COPY).tap((args) => {
|
|
22
|
+
var _args_;
|
|
23
|
+
return [
|
|
24
|
+
{
|
|
25
|
+
patterns: [
|
|
26
|
+
...((_args_ = args[0]) === null || _args_ === void 0 ? void 0 : _args_.patterns) || [],
|
|
27
|
+
defaultCopyPattern
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
];
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
@@ -10,9 +10,10 @@ Object.defineProperty(exports, "createBuilderProviderConfig", {
|
|
|
10
10
|
});
|
|
11
11
|
const _createCopyPattern = require("../builder-webpack/createCopyPattern");
|
|
12
12
|
function modifyOutputConfig(config, appContext) {
|
|
13
|
+
var _copy;
|
|
13
14
|
const defaultCopyPattern = (0, _createCopyPattern.createUploadPattern)(appContext, config);
|
|
14
15
|
const { copy } = config.output;
|
|
15
|
-
const copyOptions = Array.isArray(copy) ? copy : copy === null ||
|
|
16
|
+
const copyOptions = Array.isArray(copy) ? copy : (_copy = copy) === null || _copy === void 0 ? void 0 : _copy.patterns;
|
|
16
17
|
const builderCopy = [
|
|
17
18
|
...copyOptions || [],
|
|
18
19
|
defaultCopyPattern
|
|
@@ -58,12 +58,13 @@ const builderPluginAdapterSSR = (options) => ({
|
|
|
58
58
|
}
|
|
59
59
|
});
|
|
60
60
|
const isStreamingSSR = (userConfig) => {
|
|
61
|
+
var _server;
|
|
61
62
|
const isStreaming = (ssr) => ssr && typeof ssr === "object" && ssr.mode === "stream";
|
|
62
63
|
const { server } = userConfig;
|
|
63
64
|
if (isStreaming(server.ssr)) {
|
|
64
65
|
return true;
|
|
65
66
|
}
|
|
66
|
-
if ((server === null ||
|
|
67
|
+
if (((_server = server) === null || _server === void 0 ? void 0 : _server.ssrByEntries) && typeof server.ssrByEntries === "object") {
|
|
67
68
|
for (const name of Object.keys(server.ssrByEntries)) {
|
|
68
69
|
if (isStreaming(server.ssrByEntries[name])) {
|
|
69
70
|
return true;
|
|
@@ -80,33 +81,33 @@ function applyAsyncChunkHtmlPlugin({ chain, modernConfig, CHAIN_ID, HtmlBundlerP
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
function applyRouterPlugin(chain, options) {
|
|
83
|
-
var _normalizedConfig_runtime, _normalizedConfig_deploy_worker;
|
|
84
|
+
var _normalizedConfig_runtime, _normalizedConfig, _routerConfig, _normalizedConfig_deploy_worker;
|
|
84
85
|
const { appContext, normalizedConfig } = options;
|
|
85
86
|
const { entrypoints } = appContext;
|
|
86
87
|
const existNestedRoutes = entrypoints.some((entrypoint) => entrypoint.nestedRoutesEntry);
|
|
87
|
-
const routerConfig = normalizedConfig === null ||
|
|
88
|
-
const routerManifest = Boolean(routerConfig === null ||
|
|
88
|
+
const routerConfig = (_normalizedConfig = normalizedConfig) === null || _normalizedConfig === void 0 ? void 0 : (_normalizedConfig_runtime = _normalizedConfig.runtime) === null || _normalizedConfig_runtime === void 0 ? void 0 : _normalizedConfig_runtime.router;
|
|
89
|
+
const routerManifest = Boolean((_routerConfig = routerConfig) === null || _routerConfig === void 0 ? void 0 : _routerConfig.manifest);
|
|
89
90
|
const workerSSR = Boolean((_normalizedConfig_deploy_worker = normalizedConfig.deploy.worker) === null || _normalizedConfig_deploy_worker === void 0 ? void 0 : _normalizedConfig_deploy_worker.ssr);
|
|
90
91
|
if (existNestedRoutes || routerManifest || workerSSR) {
|
|
91
92
|
chain.plugin("route-plugin").use(_bundlerPlugins.RouterPlugin);
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
|
|
95
|
-
var
|
|
96
|
+
var _outputConfig, _this, _outputConfig1, _outputConfig2, _outputConfig3;
|
|
96
97
|
const { server: serverConfig, output: outputConfig } = appNormalizedConfig;
|
|
97
98
|
const entries = chain.entryPoints.entries();
|
|
98
|
-
if (isProd && ((outputConfig === null ||
|
|
99
|
+
if (isProd && (((_outputConfig = outputConfig) === null || _outputConfig === void 0 ? void 0 : _outputConfig.ssg) === true || typeof ((_this = (_outputConfig1 = outputConfig) === null || _outputConfig1 === void 0 ? void 0 : _outputConfig1.ssg) === null || _this === void 0 ? void 0 : _this[0]) === "function")) {
|
|
99
100
|
return;
|
|
100
101
|
}
|
|
101
102
|
if (typeof entries === "undefined") {
|
|
102
103
|
throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
|
|
103
104
|
}
|
|
104
105
|
const entryNames = Object.keys(entries);
|
|
105
|
-
if (isProd && entryNames.length === 1 && (outputConfig === null ||
|
|
106
|
+
if (isProd && entryNames.length === 1 && ((_outputConfig2 = outputConfig) === null || _outputConfig2 === void 0 ? void 0 : _outputConfig2.ssg)) {
|
|
106
107
|
return;
|
|
107
108
|
}
|
|
108
109
|
const ssgEntries = [];
|
|
109
|
-
if (isProd && (outputConfig === null ||
|
|
110
|
+
if (isProd && ((_outputConfig3 = outputConfig) === null || _outputConfig3 === void 0 ? void 0 : _outputConfig3.ssg)) {
|
|
110
111
|
const { ssg } = outputConfig;
|
|
111
112
|
entryNames.forEach((name) => {
|
|
112
113
|
if (ssg[name]) {
|
|
@@ -116,7 +117,8 @@ function applyFilterEntriesBySSRConfig({ isProd, chain, appNormalizedConfig }) {
|
|
|
116
117
|
}
|
|
117
118
|
const { ssr, ssrByEntries } = serverConfig || {};
|
|
118
119
|
entryNames.forEach((name) => {
|
|
119
|
-
|
|
120
|
+
var _ssrByEntries, _ssrByEntries1;
|
|
121
|
+
if (!ssgEntries.includes(name) && (ssr && ((_ssrByEntries = ssrByEntries) === null || _ssrByEntries === void 0 ? void 0 : _ssrByEntries[name]) === false || !ssr && !((_ssrByEntries1 = ssrByEntries) === null || _ssrByEntries1 === void 0 ? void 0 : _ssrByEntries1[name]))) {
|
|
120
122
|
chain.entryPoints.delete(name);
|
|
121
123
|
}
|
|
122
124
|
});
|
|
@@ -13,7 +13,8 @@ const _utils = require("@modern-js/utils");
|
|
|
13
13
|
const _routes = require("../utils/routes");
|
|
14
14
|
const _config = require("../utils/config");
|
|
15
15
|
const build = async (api, options) => {
|
|
16
|
-
|
|
16
|
+
var _options;
|
|
17
|
+
if ((_options = options) === null || _options === void 0 ? void 0 : _options.analyze) {
|
|
17
18
|
process.env.BUNDLE_ANALYZE = "true";
|
|
18
19
|
}
|
|
19
20
|
let resolvedConfig = api.useResolvedConfigContext();
|
package/dist/cjs/commands/dev.js
CHANGED
|
@@ -15,7 +15,7 @@ const _createServer = require("../utils/createServer");
|
|
|
15
15
|
const _routes = require("../utils/routes");
|
|
16
16
|
const _config = require("../utils/config");
|
|
17
17
|
const _getServerInternalPlugins = require("../utils/getServerInternalPlugins");
|
|
18
|
-
const dev = async (api, options) => {
|
|
18
|
+
const dev = async (api, options, devServerOptions = {}) => {
|
|
19
19
|
var _normalizedConfig_tools;
|
|
20
20
|
if (options.analyze) {
|
|
21
21
|
process.env.BUNDLE_ANALYZE = "true";
|
|
@@ -58,7 +58,8 @@ const dev = async (api, options) => {
|
|
|
58
58
|
pwd: appDirectory,
|
|
59
59
|
config: normalizedConfig,
|
|
60
60
|
serverConfigFile,
|
|
61
|
-
internalPlugins: (0, _createServer.injectDataLoaderPlugin)(serverInternalPlugins)
|
|
61
|
+
internalPlugins: (0, _createServer.injectDataLoaderPlugin)(serverInternalPlugins),
|
|
62
|
+
...devServerOptions
|
|
62
63
|
};
|
|
63
64
|
if (apiOnly) {
|
|
64
65
|
var _normalizedConfig_dev;
|
|
@@ -10,6 +10,7 @@ Object.defineProperty(exports, "inspect", {
|
|
|
10
10
|
});
|
|
11
11
|
const _path = require("path");
|
|
12
12
|
const inspect = async (api, options) => {
|
|
13
|
+
var _appContext;
|
|
13
14
|
const appContext = api.useAppContext();
|
|
14
15
|
if (!appContext.builder) {
|
|
15
16
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
|
@@ -17,7 +18,7 @@ const inspect = async (api, options) => {
|
|
|
17
18
|
return appContext.builder.inspectConfig({
|
|
18
19
|
env: options.env,
|
|
19
20
|
verbose: options.verbose,
|
|
20
|
-
outputPath: (0, _path.join)(appContext === null ||
|
|
21
|
+
outputPath: (0, _path.join)((_appContext = appContext) === null || _appContext === void 0 ? void 0 : _appContext.builder.context.distPath, options.output),
|
|
21
22
|
writeToDisk: true
|
|
22
23
|
});
|
|
23
24
|
};
|
|
@@ -15,13 +15,13 @@ const _printInstructions = require("../utils/printInstructions");
|
|
|
15
15
|
const _createServer = require("../utils/createServer");
|
|
16
16
|
const _getServerInternalPlugins = require("../utils/getServerInternalPlugins");
|
|
17
17
|
const start = async (api) => {
|
|
18
|
-
var _userConfig_source, _userConfig_output_distPath;
|
|
18
|
+
var _userConfig_source, _userConfig, _userConfig_output_distPath;
|
|
19
19
|
const appContext = api.useAppContext();
|
|
20
20
|
const userConfig = api.useResolvedConfigContext();
|
|
21
21
|
const hookRunners = api.useHookRunners();
|
|
22
22
|
const { appDirectory, port, serverConfigFile, metaName } = appContext;
|
|
23
23
|
_utils.logger.log(_utils.chalk.cyan(`Starting the modern server...`));
|
|
24
|
-
const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, userConfig === null ||
|
|
24
|
+
const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, (_userConfig = userConfig) === null || _userConfig === void 0 ? void 0 : (_userConfig_source = _userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory);
|
|
25
25
|
const serverInternalPlugins = await (0, _getServerInternalPlugins.getServerInternalPlugins)(api);
|
|
26
26
|
const app = await (0, _prodserver.default)({
|
|
27
27
|
pwd: appDirectory,
|
package/dist/cjs/index.js
CHANGED
|
@@ -13,6 +13,9 @@ _export(exports, {
|
|
|
13
13
|
mergeConfig: function() {
|
|
14
14
|
return _core.mergeConfig;
|
|
15
15
|
},
|
|
16
|
+
dev: function() {
|
|
17
|
+
return _commands.dev;
|
|
18
|
+
},
|
|
16
19
|
devCommand: function() {
|
|
17
20
|
return devCommand;
|
|
18
21
|
},
|
|
@@ -41,6 +44,7 @@ const _locale = require("./locale");
|
|
|
41
44
|
const _restart = require("./utils/restart");
|
|
42
45
|
const _generateWatchFiles = require("./utils/generateWatchFiles");
|
|
43
46
|
const _core = require("@modern-js/core");
|
|
47
|
+
const _commands = require("./commands");
|
|
44
48
|
_export_star._(require("./defineConfig"), exports);
|
|
45
49
|
_export_star._(require("./types"), exports);
|
|
46
50
|
const devCommand = async (program, api) => {
|
|
@@ -90,6 +94,7 @@ const buildCommand = async (program, api) => {
|
|
|
90
94
|
const appTools = (options = {
|
|
91
95
|
bundler: "webpack"
|
|
92
96
|
}) => {
|
|
97
|
+
var _options, _options1;
|
|
93
98
|
return {
|
|
94
99
|
name: "@modern-js/app-tools",
|
|
95
100
|
post: [
|
|
@@ -105,10 +110,10 @@ const appTools = (options = {
|
|
|
105
110
|
registerHook: _hooks.hooks,
|
|
106
111
|
usePlugins: [
|
|
107
112
|
(0, _initialize.default)({
|
|
108
|
-
bundler: (options === null ||
|
|
113
|
+
bundler: ((_options = options) === null || _options === void 0 ? void 0 : _options.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
|
109
114
|
}),
|
|
110
115
|
(0, _analyze.default)({
|
|
111
|
-
bundler: (options === null ||
|
|
116
|
+
bundler: ((_options1 = options) === null || _options1 === void 0 ? void 0 : _options1.bundler) === "experimental-rspack" ? "rspack" : "webpack"
|
|
112
117
|
}),
|
|
113
118
|
(0, _pluginlint.lintPlugin)()
|
|
114
119
|
],
|
|
@@ -11,81 +11,79 @@ Object.defineProperty(exports, "default", {
|
|
|
11
11
|
const _utils = require("@modern-js/utils");
|
|
12
12
|
const _schema = require("../schema");
|
|
13
13
|
const _config = require("../config");
|
|
14
|
-
const _default = ({ bundler }) => {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
14
|
+
const _default = ({ bundler }) => ({
|
|
15
|
+
name: "@modern-js/plugin-initialize",
|
|
16
|
+
post: [
|
|
17
|
+
"@modern-js/plugin-ssr",
|
|
18
|
+
"@modern-js/plugin-document",
|
|
19
|
+
"@modern-js/plugin-state",
|
|
20
|
+
"@modern-js/plugin-router",
|
|
21
|
+
"@modern-js/plugin-router-v5",
|
|
22
|
+
"@modern-js/plugin-polyfill"
|
|
23
|
+
],
|
|
24
|
+
setup(api) {
|
|
25
|
+
const config = () => {
|
|
26
|
+
const appContext = api.useAppContext();
|
|
27
|
+
const userConfig = api.useConfigContext();
|
|
28
|
+
api.setAppContext({
|
|
29
|
+
...appContext,
|
|
30
|
+
bundlerType: bundler
|
|
31
|
+
});
|
|
32
|
+
return (0, _config.checkIsLegacyConfig)(userConfig) ? (0, _config.createLegacyDefaultConfig)(appContext) : (0, _config.createDefaultConfig)(appContext, bundler);
|
|
33
|
+
};
|
|
34
|
+
const validateSchema = () => {
|
|
35
|
+
const userConfig = api.useConfigContext();
|
|
36
|
+
const schemas = (0, _config.checkIsLegacyConfig)(userConfig) ? _schema.legacySchema : _schema.schema;
|
|
37
|
+
return schemas.generate();
|
|
38
|
+
};
|
|
39
|
+
return {
|
|
40
|
+
config,
|
|
41
|
+
validateSchema,
|
|
42
|
+
async resolvedConfig({ resolved }) {
|
|
43
|
+
var _resolved_output_distPath;
|
|
44
|
+
let appContext = api.useAppContext();
|
|
28
45
|
const userConfig = api.useConfigContext();
|
|
29
|
-
|
|
46
|
+
const port = await getServerPort(resolved);
|
|
47
|
+
appContext = {
|
|
30
48
|
...appContext,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
|
|
62
|
-
stabilizeConfig(resolved, normalizedConfig, [
|
|
63
|
-
"source",
|
|
64
|
-
"bff",
|
|
65
|
-
"dev",
|
|
66
|
-
"html",
|
|
67
|
-
"output",
|
|
68
|
-
"tools",
|
|
69
|
-
"testing",
|
|
70
|
-
"plugins",
|
|
71
|
-
"builderPlugins",
|
|
72
|
-
"runtime",
|
|
73
|
-
"runtimeByEntries",
|
|
74
|
-
"deploy",
|
|
75
|
-
"performance"
|
|
76
|
-
]);
|
|
77
|
-
if (bundler === "webpack") {
|
|
78
|
-
resolved.security = normalizedConfig.security || {};
|
|
79
|
-
resolved.experiments = normalizedConfig.experiments;
|
|
80
|
-
}
|
|
81
|
-
return {
|
|
82
|
-
resolved
|
|
83
|
-
};
|
|
49
|
+
port,
|
|
50
|
+
distDirectory: (0, _utils.ensureAbsolutePath)(appContext.distDirectory, ((_resolved_output_distPath = resolved.output.distPath) === null || _resolved_output_distPath === void 0 ? void 0 : _resolved_output_distPath.root) || "dist")
|
|
51
|
+
};
|
|
52
|
+
api.setAppContext(appContext);
|
|
53
|
+
const normalizedConfig = (0, _config.checkIsLegacyConfig)(resolved) ? (0, _config.transformNormalizedConfig)(resolved) : resolved;
|
|
54
|
+
resolved._raw = userConfig;
|
|
55
|
+
resolved.server = {
|
|
56
|
+
...normalizedConfig.server || {},
|
|
57
|
+
port
|
|
58
|
+
};
|
|
59
|
+
var _normalizedConfig_autoLoadPlugins;
|
|
60
|
+
resolved.autoLoadPlugins = (_normalizedConfig_autoLoadPlugins = normalizedConfig.autoLoadPlugins) !== null && _normalizedConfig_autoLoadPlugins !== void 0 ? _normalizedConfig_autoLoadPlugins : false;
|
|
61
|
+
stabilizeConfig(resolved, normalizedConfig, [
|
|
62
|
+
"source",
|
|
63
|
+
"bff",
|
|
64
|
+
"dev",
|
|
65
|
+
"html",
|
|
66
|
+
"output",
|
|
67
|
+
"tools",
|
|
68
|
+
"testing",
|
|
69
|
+
"plugins",
|
|
70
|
+
"builderPlugins",
|
|
71
|
+
"runtime",
|
|
72
|
+
"runtimeByEntries",
|
|
73
|
+
"deploy",
|
|
74
|
+
"performance"
|
|
75
|
+
]);
|
|
76
|
+
if (bundler === "webpack") {
|
|
77
|
+
resolved.security = normalizedConfig.security || {};
|
|
78
|
+
resolved.experiments = normalizedConfig.experiments;
|
|
84
79
|
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
}
|
|
80
|
+
return {
|
|
81
|
+
resolved
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
});
|
|
89
87
|
function stabilizeConfig(resolve, config, keys) {
|
|
90
88
|
keys.forEach((key) => {
|
|
91
89
|
resolve[key] = config[key] || {};
|
|
@@ -100,7 +100,7 @@ export var generateCode = function() {
|
|
|
100
100
|
}
|
|
101
101
|
function _generateEntryCode() {
|
|
102
102
|
_generateEntryCode = _async_to_generator(function(entrypoint) {
|
|
103
|
-
var entryName, isMainEntry, isAutoMount, fileSystemRoutes, _config_output, initialRoutes, nestedRoute, routes, _$config, ssr, useSSG, mode, hasPageRoute, code, _, _tmp, routesServerFile, code1, serverLoaderCombined, serverLoaderFile, imports, entryFile;
|
|
103
|
+
var entryName, isMainEntry, isAutoMount, fileSystemRoutes, _config_output, _config, initialRoutes, nestedRoute, routes, _$config, ssr, useSSG, mode, hasPageRoute, code, _, _tmp, routesServerFile, code1, serverLoaderCombined, serverLoaderFile, imports, entryFile;
|
|
104
104
|
return _ts_generator(this, function(_state) {
|
|
105
105
|
switch (_state.label) {
|
|
106
106
|
case 0:
|
|
@@ -181,7 +181,7 @@ export var generateCode = function() {
|
|
|
181
181
|
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
182
182
|
entryName: entrypoint.entryName,
|
|
183
183
|
internalDirectory: internalDirectory,
|
|
184
|
-
splitRouteChunks: _$config === null ||
|
|
184
|
+
splitRouteChunks: (_config = _$config) === null || _config === void 0 ? void 0 : (_config_output = _config.output) === null || _config_output === void 0 ? void 0 : _config_output.splitRouteChunks
|
|
185
185
|
})
|
|
186
186
|
];
|
|
187
187
|
case 4:
|
|
@@ -87,7 +87,8 @@ export var getFileSystemEntry = function(appContext, config) {
|
|
|
87
87
|
var _config_source = config.source, entriesDir = _config_source.entriesDir, disableEntryDirs = _config_source.disableEntryDirs;
|
|
88
88
|
var disabledDirs = [];
|
|
89
89
|
if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
|
|
90
|
-
|
|
90
|
+
var _disableEntryDirs;
|
|
91
|
+
disabledDirs = (_disableEntryDirs = disableEntryDirs) === null || _disableEntryDirs === void 0 ? void 0 : _disableEntryDirs.map(function(dir) {
|
|
91
92
|
return ensureAbsolutePath(appDirectory, dir);
|
|
92
93
|
});
|
|
93
94
|
}
|
|
@@ -69,18 +69,19 @@ var applyRouteOptions = function(original, routeOptions) {
|
|
|
69
69
|
return routes;
|
|
70
70
|
};
|
|
71
71
|
var collectHtmlRoutes = function(entrypoints, appContext, config) {
|
|
72
|
-
var _deploy_worker;
|
|
72
|
+
var _deploy_worker, _deploy;
|
|
73
73
|
var mainEntryName = config.source.mainEntryName, disableHtmlFolder = config.html.disableHtmlFolder, _config_output = config.output, tmp = _config_output.distPath, _ref = tmp === void 0 ? {} : tmp, htmlPath = _ref.html, _config_server = config.server, baseUrl = _config_server.baseUrl, routes = _config_server.routes, ssr = _config_server.ssr, ssrByEntries = _config_server.ssrByEntries, deploy = config.deploy;
|
|
74
74
|
var packageName = appContext.packageName;
|
|
75
|
-
var workerSSR = deploy === null ||
|
|
75
|
+
var workerSSR = (_deploy = deploy) === null || _deploy === void 0 ? void 0 : (_deploy_worker = _deploy.worker) === null || _deploy_worker === void 0 ? void 0 : _deploy_worker.ssr;
|
|
76
76
|
var htmlRoutes = entrypoints.reduce(function(previous, param) {
|
|
77
77
|
var entryName = param.entryName;
|
|
78
|
+
var _routes, _routes1;
|
|
78
79
|
var isMainEntry = entryName === (mainEntryName || MAIN_ENTRY_NAME);
|
|
79
80
|
var entryOptions = getEntryOptions(entryName, isMainEntry, ssr, ssrByEntries, packageName);
|
|
80
81
|
var isSSR = Boolean(entryOptions);
|
|
81
82
|
var isWorker = Boolean(workerSSR);
|
|
82
83
|
var isStream = typeof entryOptions === "object" && entryOptions.mode === "stream";
|
|
83
|
-
var resHeaders = ((routes === null ||
|
|
84
|
+
var resHeaders = (((_routes = routes) === null || _routes === void 0 ? void 0 : _routes[entryName]) || {}).resHeaders;
|
|
84
85
|
var route = {
|
|
85
86
|
urlPath: "/".concat(isMainEntry ? "" : entryName),
|
|
86
87
|
entryName: entryName,
|
|
@@ -92,7 +93,7 @@ var collectHtmlRoutes = function(entrypoints, appContext, config) {
|
|
|
92
93
|
worker: isWorker ? "".concat(SERVER_WORKER_BUNDLE_DIRECTORY, "/").concat(entryName, ".js") : void 0,
|
|
93
94
|
bundle: isSSR ? "".concat(SERVER_BUNDLE_DIRECTORY, "/").concat(entryName, ".js") : void 0
|
|
94
95
|
};
|
|
95
|
-
if (routes === null ||
|
|
96
|
+
if ((_routes1 = routes) === null || _routes1 === void 0 ? void 0 : _routes1.hasOwnProperty(entryName)) {
|
|
96
97
|
var routeOptions = isPlainObject(routes[entryName]) ? routes[entryName] : {
|
|
97
98
|
route: routes[entryName]
|
|
98
99
|
};
|
|
@@ -40,7 +40,7 @@ var createRoute = function(routeInfo, rootDir, filename, entryName, isMainEntry)
|
|
|
40
40
|
};
|
|
41
41
|
export var walk = function() {
|
|
42
42
|
var _ref = _async_to_generator(function(dirname, rootDir, alias, entryName, isMainEntry) {
|
|
43
|
-
var _route_children, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, splatLoaderFile, splatRoute, pageConfigFile, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory1, childRoute, _route_children1, _route_children2, _route_children3, err, finalRoute, childRoute1, _$path;
|
|
43
|
+
var _routePath, _route_children, isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, splatLoaderFile, splatRoute, pageConfigFile, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory1, childRoute, _route_children1, _route_children2, _route_children3, err, finalRoute, childRoute1, _$path;
|
|
44
44
|
return _ts_generator(this, function(_state) {
|
|
45
45
|
switch (_state.label) {
|
|
46
46
|
case 0:
|
|
@@ -79,7 +79,7 @@ export var walk = function() {
|
|
|
79
79
|
}
|
|
80
80
|
routePath = replaceDynamicPath(routePath);
|
|
81
81
|
route = {
|
|
82
|
-
path: routePath === null ||
|
|
82
|
+
path: (_routePath = routePath) === null || _routePath === void 0 ? void 0 : _routePath.replace(/\$$/, "?"),
|
|
83
83
|
children: [],
|
|
84
84
|
isRoot: isRoot
|
|
85
85
|
};
|
|
@@ -28,8 +28,8 @@ export var routesForServer = function(param) {
|
|
|
28
28
|
var traverseRouteTree = function(route2) {
|
|
29
29
|
var children;
|
|
30
30
|
if ("children" in route2 && route2.children) {
|
|
31
|
-
var _route_children;
|
|
32
|
-
children = route2 === null ||
|
|
31
|
+
var _route_children, _route;
|
|
32
|
+
children = (_route = route2) === null || _route === void 0 ? void 0 : (_route_children = _route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
|
|
33
33
|
}
|
|
34
34
|
var loader;
|
|
35
35
|
if (route2.type === "nested") {
|
|
@@ -111,8 +111,8 @@ export var fileSystemRoutes = function() {
|
|
|
111
111
|
traverseRouteTree = function(route2) {
|
|
112
112
|
var children;
|
|
113
113
|
if ("children" in route2 && route2.children) {
|
|
114
|
-
var _route_children;
|
|
115
|
-
children = route2 === null ||
|
|
114
|
+
var _route_children, _route;
|
|
115
|
+
children = (_route = route2) === null || _route === void 0 ? void 0 : (_route_children = _route.children) === null || _route_children === void 0 ? void 0 : _route_children.map(traverseRouteTree);
|
|
116
116
|
}
|
|
117
117
|
var loading;
|
|
118
118
|
var error;
|
|
@@ -13,7 +13,7 @@ export var builderPluginAdpaterCopy = function(options) {
|
|
|
13
13
|
setup: function setup(api) {
|
|
14
14
|
var publicPath;
|
|
15
15
|
api.modifyRspackConfig(function(config) {
|
|
16
|
-
var
|
|
16
|
+
var _config_builtins_copy, _config_builtins, _config_output;
|
|
17
17
|
config.builtins = _object_spread_props(_object_spread({}, config.builtins || {}), {
|
|
18
18
|
copy: {
|
|
19
19
|
patterns: _to_consumable_array(((_config_builtins = config.builtins) === null || _config_builtins === void 0 ? void 0 : (_config_builtins_copy = _config_builtins.copy) === null || _config_builtins_copy === void 0 ? void 0 : _config_builtins_copy.patterns) || []).concat(_to_consumable_array(createConfigBuiltinCopy(options)))
|
|
@@ -3,9 +3,10 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
|
|
3
3
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
|
4
4
|
import { createUploadPattern } from "../builder-webpack/createCopyPattern";
|
|
5
5
|
function modifyOutputConfig(config, appContext) {
|
|
6
|
+
var _copy;
|
|
6
7
|
var defaultCopyPattern = createUploadPattern(appContext, config);
|
|
7
8
|
var copy = config.output.copy;
|
|
8
|
-
var copyOptions = Array.isArray(copy) ? copy : copy === null ||
|
|
9
|
+
var copyOptions = Array.isArray(copy) ? copy : (_copy = copy) === null || _copy === void 0 ? void 0 : _copy.patterns;
|
|
9
10
|
var builderCopy = _to_consumable_array(copyOptions || []).concat([
|
|
10
11
|
defaultCopyPattern
|
|
11
12
|
]);
|