@modern-js/app-tools 2.58.2 → 2.59.0
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/builder/builder-rspack/adapterCopy.js +1 -1
- package/dist/cjs/builder/generator/getBuilderEnvironments.js +1 -1
- package/dist/cjs/builder/generator/index.js +2 -3
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +8 -13
- package/dist/cjs/builder/shared/builderPlugins/index.js +1 -3
- package/dist/cjs/builder/shared/bundlerPlugins/RouterPlugin.js +1 -1
- package/dist/cjs/commands/build.js +2 -2
- package/dist/cjs/commands/dev.js +6 -5
- package/dist/cjs/commands/index.js +1 -1
- package/dist/cjs/commands/serve.js +4 -3
- package/dist/cjs/config/legacy/index.js +3 -3
- package/dist/cjs/esm/register-esm.mjs +2 -3
- package/dist/cjs/esm/utils.mjs +2 -2
- package/dist/cjs/index.js +17 -10
- package/dist/cjs/locale/index.js +1 -1
- package/dist/cjs/plugins/analyze/getFileSystemEntry.js +50 -44
- package/dist/cjs/plugins/analyze/getServerRoutes.js +2 -2
- package/dist/cjs/plugins/analyze/index.js +6 -6
- package/dist/cjs/plugins/analyze/utils.js +1 -1
- package/dist/cjs/plugins/deploy/dependencies/index.js +1 -1
- package/dist/cjs/plugins/deploy/dependencies/utils.js +2 -2
- package/dist/cjs/plugins/deploy/index.js +2 -2
- package/dist/cjs/plugins/deploy/platforms/netlify.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/node.js +1 -1
- package/dist/cjs/plugins/deploy/platforms/vercel.js +1 -1
- package/dist/cjs/plugins/serverBuild.js +2 -2
- package/dist/cjs/utils/createServer.js +1 -1
- package/dist/esm/builder/builder-rspack/adapterCopy.js +166 -0
- package/dist/esm/builder/builder-rspack/index.js +34 -0
- package/dist/esm/builder/builder-webpack/adapterModern.js +29 -0
- package/dist/esm/builder/builder-webpack/createCopyPattern.js +43 -0
- package/dist/esm/builder/builder-webpack/index.js +52 -0
- package/dist/esm/builder/generator/createBuilderProviderConfig.js +37 -0
- package/dist/esm/builder/generator/getBuilderEnvironments.js +81 -0
- package/dist/esm/builder/generator/index.js +93 -0
- package/dist/esm/builder/index.js +45 -0
- package/dist/esm/builder/shared/builderPlugins/adapterBasic.js +85 -0
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +126 -0
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +261 -0
- package/dist/esm/builder/shared/builderPlugins/index.js +3 -0
- package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +51 -0
- package/dist/esm/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +37 -0
- package/dist/esm/builder/shared/bundlerPlugins/RouterPlugin.js +314 -0
- package/dist/esm/builder/shared/bundlerPlugins/index.js +3 -0
- package/dist/esm/builder/shared/createCopyInfo.js +14 -0
- package/dist/esm/builder/shared/index.js +3 -0
- package/dist/esm/builder/shared/loaders/serverModuleLoader.js +7 -0
- package/dist/esm/builder/shared/types.js +0 -0
- package/dist/esm/commands/build.js +140 -0
- package/dist/esm/commands/deploy.js +48 -0
- package/dist/esm/commands/dev.js +193 -0
- package/dist/esm/commands/index.js +411 -0
- package/dist/esm/commands/inspect.js +28 -0
- package/dist/esm/commands/serve.js +94 -0
- package/dist/esm/config/default.js +190 -0
- package/dist/esm/config/index.js +3 -0
- package/dist/esm/config/initialize/index.js +9 -0
- package/dist/esm/config/initialize/inits.js +89 -0
- package/dist/esm/config/legacy/createHtmlConfig.js +21 -0
- package/dist/esm/config/legacy/createOutputConfig.js +45 -0
- package/dist/esm/config/legacy/createSourceConfig.js +46 -0
- package/dist/esm/config/legacy/createToolsConfig.js +28 -0
- package/dist/esm/config/legacy/index.js +43 -0
- package/dist/esm/defineConfig.js +16 -0
- package/dist/esm/esm/esbuild-loader.mjs +20 -0
- package/dist/esm/esm/register-esm.mjs +66 -0
- package/dist/esm/esm/ts-node-loader.mjs +21 -0
- package/dist/esm/esm/utils.mjs +43 -0
- package/dist/esm/exports/server.js +4 -0
- package/dist/esm/hooks.js +34 -0
- package/dist/esm/index.js +246 -0
- package/dist/esm/locale/en.js +43 -0
- package/dist/esm/locale/index.js +12 -0
- package/dist/esm/locale/zh.js +43 -0
- package/dist/esm/plugins/analyze/constants.js +14 -0
- package/dist/esm/plugins/analyze/getBundleEntry.js +102 -0
- package/dist/esm/plugins/analyze/getFileSystemEntry.js +266 -0
- package/dist/esm/plugins/analyze/getHtmlTemplate.js +178 -0
- package/dist/esm/plugins/analyze/getServerRoutes.js +132 -0
- package/dist/esm/plugins/analyze/index.js +380 -0
- package/dist/esm/plugins/analyze/isDefaultExportFunction.js +49 -0
- package/dist/esm/plugins/analyze/templates.js +6 -0
- package/dist/esm/plugins/analyze/utils.js +101 -0
- package/dist/esm/plugins/deploy/dependencies/index.js +615 -0
- package/dist/esm/plugins/deploy/dependencies/utils.js +421 -0
- package/dist/esm/plugins/deploy/exports.js +4 -0
- package/dist/esm/plugins/deploy/index.js +135 -0
- package/dist/esm/plugins/deploy/platforms/netlify-entry.js +11 -0
- package/dist/esm/plugins/deploy/platforms/netlify-entry.mjs +1 -0
- package/dist/esm/plugins/deploy/platforms/netlify-handler.js +205 -0
- package/dist/esm/plugins/deploy/platforms/netlify.js +327 -0
- package/dist/esm/plugins/deploy/platforms/node-entry.js +108 -0
- package/dist/esm/plugins/deploy/platforms/node.js +161 -0
- package/dist/esm/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm/plugins/deploy/platforms/vercel-entry.js +11 -0
- package/dist/esm/plugins/deploy/platforms/vercel-entry.mjs +3 -0
- package/dist/esm/plugins/deploy/platforms/vercel-handler.js +206 -0
- package/dist/esm/plugins/deploy/platforms/vercel.js +261 -0
- package/dist/esm/plugins/deploy/utils.js +47 -0
- package/dist/esm/plugins/initialize/index.js +119 -0
- package/dist/esm/plugins/serverBuild.js +87 -0
- package/dist/esm/types/config/deploy.js +0 -0
- package/dist/esm/types/config/dev.js +0 -0
- package/dist/esm/types/config/experiments.js +0 -0
- package/dist/esm/types/config/html.js +0 -0
- package/dist/esm/types/config/index.js +1 -0
- package/dist/esm/types/config/output.js +0 -0
- package/dist/esm/types/config/performance.js +0 -0
- package/dist/esm/types/config/security.js +0 -0
- package/dist/esm/types/config/source.js +0 -0
- package/dist/esm/types/config/testing.js +0 -0
- package/dist/esm/types/config/tools.js +0 -0
- package/dist/esm/types/hooks.js +0 -0
- package/dist/esm/types/index.js +3 -0
- package/dist/esm/types/legacyConfig/deploy.js +0 -0
- package/dist/esm/types/legacyConfig/dev.js +0 -0
- package/dist/esm/types/legacyConfig/index.js +0 -0
- package/dist/esm/types/legacyConfig/output.js +0 -0
- package/dist/esm/types/legacyConfig/source.js +0 -0
- package/dist/esm/types/legacyConfig/testing.js +0 -0
- package/dist/esm/types/legacyConfig/tools.js +0 -0
- package/dist/esm/types/utils.js +0 -0
- package/dist/esm/utils/config.js +122 -0
- package/dist/esm/utils/createServer.js +58 -0
- package/dist/esm/utils/env.js +16 -0
- package/dist/esm/utils/generateWatchFiles.js +71 -0
- package/dist/esm/utils/getSelectedEntries.js +67 -0
- package/dist/esm/utils/loadPlugins.js +74 -0
- package/dist/esm/utils/printInstructions.js +32 -0
- package/dist/esm/utils/register.js +188 -0
- package/dist/esm/utils/restart.js +67 -0
- package/dist/esm/utils/routes.js +42 -0
- package/dist/esm/utils/types.js +0 -0
- package/dist/esm-node/builder/builder-rspack/adapterCopy.js +67 -0
- package/dist/esm-node/builder/builder-rspack/index.js +12 -0
- package/dist/esm-node/builder/builder-webpack/adapterModern.js +26 -0
- package/dist/esm-node/builder/builder-webpack/createCopyPattern.js +41 -0
- package/dist/esm-node/builder/builder-webpack/index.js +20 -0
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.js +44 -0
- package/dist/esm-node/builder/generator/getBuilderEnvironments.js +60 -0
- package/dist/esm-node/builder/generator/index.js +36 -0
- package/dist/esm-node/builder/index.js +11 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterBasic.js +48 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +60 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +151 -0
- package/dist/esm-node/builder/shared/builderPlugins/index.js +3 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +30 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlBottomTemplate.js +31 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/RouterPlugin.js +228 -0
- package/dist/esm-node/builder/shared/bundlerPlugins/index.js +3 -0
- package/dist/esm-node/builder/shared/createCopyInfo.js +14 -0
- package/dist/esm-node/builder/shared/index.js +3 -0
- package/dist/esm-node/builder/shared/loaders/serverModuleLoader.js +7 -0
- package/dist/esm-node/builder/shared/types.js +0 -0
- package/dist/esm-node/commands/build.js +64 -0
- package/dist/esm-node/commands/deploy.js +12 -0
- package/dist/esm-node/commands/dev.js +105 -0
- package/dist/esm-node/commands/index.js +92 -0
- package/dist/esm-node/commands/inspect.js +15 -0
- package/dist/esm-node/commands/serve.js +52 -0
- package/dist/esm-node/config/default.js +197 -0
- package/dist/esm-node/config/index.js +3 -0
- package/dist/esm-node/config/initialize/index.js +9 -0
- package/dist/esm-node/config/initialize/inits.js +79 -0
- package/dist/esm-node/config/legacy/createHtmlConfig.js +21 -0
- package/dist/esm-node/config/legacy/createOutputConfig.js +45 -0
- package/dist/esm-node/config/legacy/createSourceConfig.js +29 -0
- package/dist/esm-node/config/legacy/createToolsConfig.js +28 -0
- package/dist/esm-node/config/legacy/index.js +43 -0
- package/dist/esm-node/defineConfig.js +13 -0
- package/dist/esm-node/esm/esbuild-loader.mjs +20 -0
- package/dist/esm-node/esm/register-esm.mjs +66 -0
- package/dist/esm-node/esm/ts-node-loader.mjs +21 -0
- package/dist/esm-node/esm/utils.mjs +43 -0
- package/dist/esm-node/exports/server.js +4 -0
- package/dist/esm-node/hooks.js +34 -0
- package/dist/esm-node/index.js +131 -0
- package/dist/esm-node/locale/en.js +43 -0
- package/dist/esm-node/locale/index.js +12 -0
- package/dist/esm-node/locale/zh.js +43 -0
- package/dist/esm-node/plugins/analyze/constants.js +14 -0
- package/dist/esm-node/plugins/analyze/getBundleEntry.js +61 -0
- package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +106 -0
- package/dist/esm-node/plugins/analyze/getHtmlTemplate.js +74 -0
- package/dist/esm-node/plugins/analyze/getServerRoutes.js +132 -0
- package/dist/esm-node/plugins/analyze/index.js +166 -0
- package/dist/esm-node/plugins/analyze/isDefaultExportFunction.js +47 -0
- package/dist/esm-node/plugins/analyze/templates.js +24 -0
- package/dist/esm-node/plugins/analyze/utils.js +68 -0
- package/dist/esm-node/plugins/deploy/dependencies/index.js +202 -0
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +137 -0
- package/dist/esm-node/plugins/deploy/exports.js +4 -0
- package/dist/esm-node/plugins/deploy/index.js +44 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify-entry.js +11 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify-entry.mjs +1 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify-handler.js +71 -0
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +117 -0
- package/dist/esm-node/plugins/deploy/platforms/node-entry.js +44 -0
- package/dist/esm-node/plugins/deploy/platforms/node.js +72 -0
- package/dist/esm-node/plugins/deploy/platforms/platform.js +0 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel-entry.js +11 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel-entry.mjs +3 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel-handler.js +72 -0
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +129 -0
- package/dist/esm-node/plugins/deploy/utils.js +44 -0
- package/dist/esm-node/plugins/initialize/index.js +84 -0
- package/dist/esm-node/plugins/serverBuild.js +58 -0
- package/dist/esm-node/types/config/deploy.js +0 -0
- package/dist/esm-node/types/config/dev.js +0 -0
- package/dist/esm-node/types/config/experiments.js +0 -0
- package/dist/esm-node/types/config/html.js +0 -0
- package/dist/esm-node/types/config/index.js +1 -0
- package/dist/esm-node/types/config/output.js +0 -0
- package/dist/esm-node/types/config/performance.js +0 -0
- package/dist/esm-node/types/config/security.js +0 -0
- package/dist/esm-node/types/config/source.js +0 -0
- package/dist/esm-node/types/config/testing.js +0 -0
- package/dist/esm-node/types/config/tools.js +0 -0
- package/dist/esm-node/types/hooks.js +0 -0
- package/dist/esm-node/types/index.js +3 -0
- package/dist/esm-node/types/legacyConfig/deploy.js +0 -0
- package/dist/esm-node/types/legacyConfig/dev.js +0 -0
- package/dist/esm-node/types/legacyConfig/index.js +0 -0
- package/dist/esm-node/types/legacyConfig/output.js +0 -0
- package/dist/esm-node/types/legacyConfig/source.js +0 -0
- package/dist/esm-node/types/legacyConfig/testing.js +0 -0
- package/dist/esm-node/types/legacyConfig/tools.js +0 -0
- package/dist/esm-node/types/utils.js +0 -0
- package/dist/esm-node/utils/config.js +49 -0
- package/dist/esm-node/utils/createServer.js +26 -0
- package/dist/esm-node/utils/env.js +16 -0
- package/dist/esm-node/utils/generateWatchFiles.js +30 -0
- package/dist/esm-node/utils/getSelectedEntries.js +34 -0
- package/dist/esm-node/utils/loadPlugins.js +22 -0
- package/dist/esm-node/utils/printInstructions.js +11 -0
- package/dist/esm-node/utils/register.js +96 -0
- package/dist/esm-node/utils/restart.js +22 -0
- package/dist/esm-node/utils/routes.js +21 -0
- package/dist/esm-node/utils/types.js +0 -0
- package/dist/types/builder/generator/createBuilderProviderConfig.d.ts +1 -1
- package/dist/types/builder/generator/index.d.ts +2 -2
- package/dist/types/builder/shared/builderPlugins/index.d.ts +0 -1
- package/dist/types/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.d.ts +1 -1
- package/dist/types/builder/shared/bundlerPlugins/HtmlBottomTemplate.d.ts +1 -1
- package/dist/types/builder/shared/bundlerPlugins/RouterPlugin.d.ts +1 -1
- package/dist/types/builder/shared/loaders/serverModuleLoader.d.ts +1 -1
- package/dist/types/builder/shared/types.d.ts +1 -1
- package/dist/types/commands/build.d.ts +1 -1
- package/dist/types/commands/dev.d.ts +1 -1
- package/dist/types/commands/inspect.d.ts +1 -1
- package/dist/types/config/default.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/plugins/analyze/getBundleEntry.d.ts +1 -1
- package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +1 -1
- package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -1
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -1
- package/dist/types/plugins/initialize/index.d.ts +1 -1
- package/dist/types/plugins/serverBuild.d.ts +1 -1
- package/dist/types/types/config/index.d.ts +8 -8
- package/dist/types/types/config/output.d.ts +1 -1
- package/dist/types/types/config/tools.d.ts +3 -3
- package/dist/types/types/hooks.d.ts +2 -2
- package/dist/types/types/index.d.ts +2 -2
- package/dist/types/types/legacyConfig/index.d.ts +3 -3
- package/dist/types/types/legacyConfig/tools.d.ts +1 -1
- package/dist/types/utils/printInstructions.d.ts +1 -1
- package/package.json +20 -20
- package/dist/cjs/builder/shared/builderPlugins/adapterWorker.js +0 -51
- package/dist/types/builder/shared/builderPlugins/adapterWorker.d.ts +0 -2
@@ -0,0 +1,314 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _class_call_check } from "@swc/helpers/_/_class_call_check";
|
3
|
+
import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
4
|
+
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
5
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
6
|
+
import { createHash } from "crypto";
|
7
|
+
import { ROUTE_MANIFEST_FILE } from "@modern-js/utils";
|
8
|
+
import { merge, mergeWith } from "@modern-js/utils/lodash";
|
9
|
+
import { ROUTE_MANIFEST } from "@modern-js/utils/universal/constants";
|
10
|
+
var PLUGIN_NAME = "ModernjsRoutePlugin";
|
11
|
+
var generateContentHash = function(content) {
|
12
|
+
return createHash("md5").update(content).digest("hex").slice(0, 8);
|
13
|
+
};
|
14
|
+
var RouterPlugin = /* @__PURE__ */ function() {
|
15
|
+
"use strict";
|
16
|
+
function RouterPlugin2(param) {
|
17
|
+
var _param_staticJsDir = param.staticJsDir, staticJsDir = _param_staticJsDir === void 0 ? "static/js" : _param_staticJsDir, HtmlBundlerPlugin = param.HtmlBundlerPlugin, enableInlineRouteManifests = param.enableInlineRouteManifests, _param_disableFilenameHash = param.disableFilenameHash, disableFilenameHash = _param_disableFilenameHash === void 0 ? false : _param_disableFilenameHash, _param_scriptLoading = param.scriptLoading, scriptLoading = _param_scriptLoading === void 0 ? "defer" : _param_scriptLoading, nonce = param.nonce;
|
18
|
+
_class_call_check(this, RouterPlugin2);
|
19
|
+
this.name = "RouterPlugin";
|
20
|
+
this.HtmlBundlerPlugin = HtmlBundlerPlugin;
|
21
|
+
this.enableInlineRouteManifests = enableInlineRouteManifests;
|
22
|
+
this.staticJsDir = staticJsDir;
|
23
|
+
this.disableFilenameHash = disableFilenameHash;
|
24
|
+
this.scriptLoading = scriptLoading;
|
25
|
+
this.nonce = nonce;
|
26
|
+
}
|
27
|
+
var _proto = RouterPlugin2.prototype;
|
28
|
+
_proto.isTargetNodeOrWebWorker = function isTargetNodeOrWebWorker(target) {
|
29
|
+
if (target === "node" || Array.isArray(target) && target.includes("node")) {
|
30
|
+
return true;
|
31
|
+
}
|
32
|
+
if (target === "webworker" || Array.isArray(target) && target.includes("webworker")) {
|
33
|
+
return true;
|
34
|
+
}
|
35
|
+
return false;
|
36
|
+
};
|
37
|
+
_proto.getEntryChunks = function getEntryChunks(compilation, chunks) {
|
38
|
+
var entrypointsArray = Array.from(compilation.entrypoints.entries());
|
39
|
+
var entryChunkIds = entrypointsArray.map(function(entrypoint) {
|
40
|
+
return entrypoint[0];
|
41
|
+
});
|
42
|
+
var entryChunks = _to_consumable_array(chunks).filter(function(chunk) {
|
43
|
+
var _chunk_names;
|
44
|
+
return (_chunk_names = chunk.names) === null || _chunk_names === void 0 ? void 0 : _chunk_names.some(function(name) {
|
45
|
+
return entryChunkIds.includes(name);
|
46
|
+
});
|
47
|
+
});
|
48
|
+
return entryChunks;
|
49
|
+
};
|
50
|
+
_proto.getEntryChunkFiles = function getEntryChunkFiles(entryChunks) {
|
51
|
+
return entryChunks.map(function(chunk) {
|
52
|
+
return _to_consumable_array(chunk.files || []).find(function(fname) {
|
53
|
+
return fname.includes(".js");
|
54
|
+
});
|
55
|
+
});
|
56
|
+
};
|
57
|
+
_proto.apply = function apply(compiler) {
|
58
|
+
var _this = this;
|
59
|
+
var target = compiler.options.target;
|
60
|
+
if (this.isTargetNodeOrWebWorker(target)) {
|
61
|
+
return;
|
62
|
+
}
|
63
|
+
var webpack = compiler.webpack;
|
64
|
+
var isRspack = "rspackVersion" in webpack;
|
65
|
+
var Compilation = webpack.Compilation, sources = webpack.sources;
|
66
|
+
var RawSource = sources.RawSource;
|
67
|
+
var normalizePath = function(path) {
|
68
|
+
if (!path.endsWith("/")) {
|
69
|
+
return "".concat(path, "/");
|
70
|
+
}
|
71
|
+
return path;
|
72
|
+
};
|
73
|
+
var chunksToHtmlName = /* @__PURE__ */ new Map();
|
74
|
+
var ROUTE_MANIFEST_HOLDER = "route-manifest";
|
75
|
+
var placeholder = "<!--<?- ".concat(ROUTE_MANIFEST_HOLDER, " ?>-->");
|
76
|
+
compiler.hooks.thisCompilation.tap(PLUGIN_NAME, function(compilation) {
|
77
|
+
_this.HtmlBundlerPlugin.getHooks(compilation).beforeEmit.tapAsync("RouterManifestPlugin", function(data, callback) {
|
78
|
+
var outputName = data.outputName;
|
79
|
+
var chunks = data.plugin.options.chunks;
|
80
|
+
chunksToHtmlName.set(chunks, outputName);
|
81
|
+
data.html = data.html.replace("</script>", "</script>".concat(placeholder));
|
82
|
+
callback(null, data);
|
83
|
+
});
|
84
|
+
var _this1 = _this;
|
85
|
+
compilation.hooks.processAssets.tapPromise({
|
86
|
+
name: PLUGIN_NAME,
|
87
|
+
stage: Compilation.PROCESS_ASSETS_STAGE_REPORT
|
88
|
+
}, /* @__PURE__ */ _async_to_generator(function() {
|
89
|
+
var _loop, stats, publicPath, _stats_chunks, chunks, namedChunkGroups, routeAssets, prevManifestAsset, prevManifestStr, prevManifest, asyncEntryNames, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, _step_value, name, chunkGroup, assets, referenceCssAssets, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, asyncEntryName, syncEntryName, syncEntry, asyncEntry, manifest, entryNames, entryChunks, orignalEntryIds, entryChunkFiles, entryChunkFileIds, i;
|
90
|
+
return _ts_generator(this, function(_state) {
|
91
|
+
_loop = function(i2) {
|
92
|
+
var entryName = entryNames[i2];
|
93
|
+
var file = entryChunkFiles[i2];
|
94
|
+
var chunkNames = entryChunks[i2].names;
|
95
|
+
var chunkId = entryChunkFileIds[i2];
|
96
|
+
var asset = compilation.assets[file];
|
97
|
+
if (!asset || !chunkId) {
|
98
|
+
return "continue";
|
99
|
+
}
|
100
|
+
var relatedAssets = {};
|
101
|
+
if (entryChunkFiles.length > 1) {
|
102
|
+
Object.keys(routeAssets).forEach(function(routeId) {
|
103
|
+
var segments = routeId.split("_");
|
104
|
+
var chunkName = segments[0];
|
105
|
+
if (chunkNames === null || chunkNames === void 0 ? void 0 : chunkNames.includes(chunkName)) {
|
106
|
+
relatedAssets[routeId] = routeAssets[routeId];
|
107
|
+
}
|
108
|
+
});
|
109
|
+
} else {
|
110
|
+
relatedAssets = routeAssets;
|
111
|
+
}
|
112
|
+
var manifest2 = {
|
113
|
+
routeAssets: relatedAssets
|
114
|
+
};
|
115
|
+
var injectedContent = "\n ;(function(){\n window.".concat(ROUTE_MANIFEST, " = ").concat(JSON.stringify(manifest2, function(k, v) {
|
116
|
+
if ((k === "assets" || k === "referenceCssAssets") && Array.isArray(v)) {
|
117
|
+
return v.map(function(item) {
|
118
|
+
return item.replace(publicPath, "");
|
119
|
+
});
|
120
|
+
}
|
121
|
+
return v;
|
122
|
+
}), ";\n })();\n ");
|
123
|
+
var htmlName = void 0;
|
124
|
+
var _iteratorNormalCompletion2 = true, _didIteratorError2 = false, _iteratorError2 = void 0;
|
125
|
+
try {
|
126
|
+
var _loop2 = function() {
|
127
|
+
var _step_value2 = _sliced_to_array(_step2.value, 2), chunks2 = _step_value2[0], name2 = _step_value2[1];
|
128
|
+
if (Array.isArray(chunkNames) && Array.isArray(chunks2) && chunkNames.every(function(value, index) {
|
129
|
+
return value === chunks2[index];
|
130
|
+
})) {
|
131
|
+
htmlName = name2;
|
132
|
+
return "break";
|
133
|
+
}
|
134
|
+
};
|
135
|
+
for (var _iterator2 = chunksToHtmlName.entries()[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
136
|
+
var _ret = _loop2();
|
137
|
+
if (_ret === "break")
|
138
|
+
break;
|
139
|
+
}
|
140
|
+
} catch (err) {
|
141
|
+
_didIteratorError2 = true;
|
142
|
+
_iteratorError2 = err;
|
143
|
+
} finally {
|
144
|
+
try {
|
145
|
+
if (!_iteratorNormalCompletion2 && _iterator2.return != null) {
|
146
|
+
_iterator2.return();
|
147
|
+
}
|
148
|
+
} finally {
|
149
|
+
if (_didIteratorError2) {
|
150
|
+
throw _iteratorError2;
|
151
|
+
}
|
152
|
+
}
|
153
|
+
}
|
154
|
+
var oldHtml = compilation.assets[htmlName];
|
155
|
+
var enableInlineRouteManifests = _this1.enableInlineRouteManifests, disableFilenameHash = _this1.disableFilenameHash, staticJsDir = _this1.staticJsDir, scriptLoading = _this1.scriptLoading, nonce = _this1.nonce;
|
156
|
+
var nonceAttr = nonce ? 'nonce="'.concat(nonce, '"') : "";
|
157
|
+
if (oldHtml) {
|
158
|
+
if (enableInlineRouteManifests) {
|
159
|
+
compilation.updateAsset(
|
160
|
+
htmlName,
|
161
|
+
new RawSource(oldHtml.source().toString().replace(placeholder, "<script ".concat(nonceAttr, ">").concat(injectedContent, "</script>"))),
|
162
|
+
// FIXME: The arguments third of updatgeAsset is a optional function in webpack.
|
163
|
+
void 0
|
164
|
+
);
|
165
|
+
} else {
|
166
|
+
var scriptPath = "".concat(staticJsDir, "/").concat(ROUTE_MANIFEST_HOLDER, "-").concat(entryName).concat(disableFilenameHash ? ".js" : ".".concat(generateContentHash(injectedContent), ".js"));
|
167
|
+
var scriptUrl = "".concat(publicPath).concat(scriptPath);
|
168
|
+
var scriptLoadingAttr = scriptLoading === "defer" ? scriptLoading : scriptLoading === "module" ? 'type="module"' : "";
|
169
|
+
var script = "<script ".concat(scriptLoadingAttr, " ").concat(nonceAttr, ' src="').concat(scriptUrl, '"></script>');
|
170
|
+
compilation.updateAsset(
|
171
|
+
htmlName,
|
172
|
+
new RawSource(oldHtml.source().toString().replace(placeholder, script)),
|
173
|
+
// FIXME: The arguments third of updatgeAsset is a optional function in webpack.
|
174
|
+
void 0
|
175
|
+
);
|
176
|
+
compilation.emitAsset(scriptPath, new RawSource(injectedContent));
|
177
|
+
}
|
178
|
+
}
|
179
|
+
};
|
180
|
+
stats = compilation.getStats().toJson({
|
181
|
+
all: false,
|
182
|
+
publicPath: true,
|
183
|
+
assets: true,
|
184
|
+
chunkGroups: true,
|
185
|
+
chunks: true,
|
186
|
+
ids: true
|
187
|
+
});
|
188
|
+
publicPath = stats.publicPath, _stats_chunks = stats.chunks, chunks = _stats_chunks === void 0 ? [] : _stats_chunks, namedChunkGroups = stats.namedChunkGroups;
|
189
|
+
routeAssets = {};
|
190
|
+
if (!namedChunkGroups) {
|
191
|
+
return [
|
192
|
+
2
|
193
|
+
];
|
194
|
+
}
|
195
|
+
prevManifestAsset = compilation.getAsset(ROUTE_MANIFEST_FILE);
|
196
|
+
prevManifestStr = prevManifestAsset ? prevManifestAsset.source.source().toString() : JSON.stringify({
|
197
|
+
routeAssets: {}
|
198
|
+
});
|
199
|
+
prevManifest = JSON.parse(prevManifestStr);
|
200
|
+
asyncEntryNames = [];
|
201
|
+
_iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
202
|
+
try {
|
203
|
+
for (_iterator = Object.entries(namedChunkGroups)[Symbol.iterator](); !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
204
|
+
_step_value = _sliced_to_array(_step.value, 2), name = _step_value[0], chunkGroup = _step_value[1];
|
205
|
+
if (name.startsWith("async-")) {
|
206
|
+
asyncEntryNames.push(name);
|
207
|
+
}
|
208
|
+
assets = chunkGroup.assets.map(function(asset) {
|
209
|
+
var filename = asset.name;
|
210
|
+
return publicPath ? normalizePath(publicPath) + filename : filename;
|
211
|
+
});
|
212
|
+
referenceCssAssets = assets.filter(function(asset) {
|
213
|
+
return /\.css$/.test(asset);
|
214
|
+
});
|
215
|
+
routeAssets[name] = {
|
216
|
+
chunkIds: chunkGroup.chunks,
|
217
|
+
assets,
|
218
|
+
referenceCssAssets
|
219
|
+
};
|
220
|
+
if (prevManifest.routeAssets[name]) {
|
221
|
+
mergeWith(routeAssets[name], prevManifest.routeAssets[name], function(obj, source) {
|
222
|
+
if (Array.isArray(obj)) {
|
223
|
+
return obj.concat(source);
|
224
|
+
}
|
225
|
+
return Object.assign(source, obj);
|
226
|
+
});
|
227
|
+
}
|
228
|
+
}
|
229
|
+
} catch (err) {
|
230
|
+
_didIteratorError = true;
|
231
|
+
_iteratorError = err;
|
232
|
+
} finally {
|
233
|
+
try {
|
234
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
235
|
+
_iterator.return();
|
236
|
+
}
|
237
|
+
} finally {
|
238
|
+
if (_didIteratorError) {
|
239
|
+
throw _iteratorError;
|
240
|
+
}
|
241
|
+
}
|
242
|
+
}
|
243
|
+
if (asyncEntryNames.length > 0) {
|
244
|
+
_iteratorNormalCompletion1 = true, _didIteratorError1 = false, _iteratorError1 = void 0;
|
245
|
+
try {
|
246
|
+
for (_iterator1 = asyncEntryNames[Symbol.iterator](); !(_iteratorNormalCompletion1 = (_step1 = _iterator1.next()).done); _iteratorNormalCompletion1 = true) {
|
247
|
+
asyncEntryName = _step1.value;
|
248
|
+
syncEntryName = asyncEntryName.replace("async-", "");
|
249
|
+
syncEntry = routeAssets[syncEntryName];
|
250
|
+
asyncEntry = routeAssets[asyncEntryName];
|
251
|
+
merge(syncEntry, asyncEntry);
|
252
|
+
}
|
253
|
+
} catch (err) {
|
254
|
+
_didIteratorError1 = true;
|
255
|
+
_iteratorError1 = err;
|
256
|
+
} finally {
|
257
|
+
try {
|
258
|
+
if (!_iteratorNormalCompletion1 && _iterator1.return != null) {
|
259
|
+
_iterator1.return();
|
260
|
+
}
|
261
|
+
} finally {
|
262
|
+
if (_didIteratorError1) {
|
263
|
+
throw _iteratorError1;
|
264
|
+
}
|
265
|
+
}
|
266
|
+
}
|
267
|
+
}
|
268
|
+
manifest = {
|
269
|
+
routeAssets
|
270
|
+
};
|
271
|
+
entryNames = Array.from(compilation.entrypoints.keys());
|
272
|
+
entryChunks = [];
|
273
|
+
if (isRspack) {
|
274
|
+
entryChunks = _this1.getEntryChunks(compilation, chunks);
|
275
|
+
} else {
|
276
|
+
orignalEntryIds = Object.keys(compilation.options.entry).map(function(entryName) {
|
277
|
+
var chunk = compilation.namedChunks.get(entryName);
|
278
|
+
if (chunk) {
|
279
|
+
return chunk.id;
|
280
|
+
}
|
281
|
+
return entryName;
|
282
|
+
});
|
283
|
+
entryChunks = _this1.getEntryChunks(compilation, chunks).filter(function(chunk) {
|
284
|
+
return orignalEntryIds.includes(chunk.id);
|
285
|
+
});
|
286
|
+
}
|
287
|
+
entryChunkFiles = _this1.getEntryChunkFiles(entryChunks);
|
288
|
+
entryChunkFileIds = entryChunks.map(function(chunk) {
|
289
|
+
return chunk.id;
|
290
|
+
});
|
291
|
+
for (i = 0; i < entryChunkFiles.length; i++)
|
292
|
+
_loop(i);
|
293
|
+
if (prevManifestAsset) {
|
294
|
+
compilation.updateAsset(
|
295
|
+
ROUTE_MANIFEST_FILE,
|
296
|
+
new RawSource(JSON.stringify(manifest, null, 2)),
|
297
|
+
// FIXME: The arguments third of updatgeAsset is a optional function in webpack.
|
298
|
+
void 0
|
299
|
+
);
|
300
|
+
} else {
|
301
|
+
compilation.emitAsset(ROUTE_MANIFEST_FILE, new RawSource(JSON.stringify(manifest, null, 2)));
|
302
|
+
}
|
303
|
+
return [
|
304
|
+
2
|
305
|
+
];
|
306
|
+
});
|
307
|
+
}));
|
308
|
+
});
|
309
|
+
};
|
310
|
+
return RouterPlugin2;
|
311
|
+
}();
|
312
|
+
export {
|
313
|
+
RouterPlugin
|
314
|
+
};
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import path from "path";
|
2
|
+
function createCopyInfo(appContext, config) {
|
3
|
+
var configDir = path.resolve(appContext.appDirectory, config.source.configDir || "./config");
|
4
|
+
var uploadDir = path.posix.join(configDir.replace(/\\/g, "/"), "upload");
|
5
|
+
var publicDir = path.posix.join(configDir.replace(/\\/g, "/"), "public");
|
6
|
+
return {
|
7
|
+
configDir,
|
8
|
+
uploadDir,
|
9
|
+
publicDir
|
10
|
+
};
|
11
|
+
}
|
12
|
+
export {
|
13
|
+
createCopyInfo
|
14
|
+
};
|
File without changes
|
@@ -0,0 +1,140 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
3
|
+
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
4
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
|
+
import { ResolvedConfigContext } from "@modern-js/core";
|
6
|
+
import { logger } from "@modern-js/utils";
|
7
|
+
import { buildServerConfig } from "../utils/config";
|
8
|
+
import { loadServerPlugins } from "../utils/loadPlugins";
|
9
|
+
import { registerCompiler } from "../utils/register";
|
10
|
+
import { generateRoutes } from "../utils/routes";
|
11
|
+
var build = function() {
|
12
|
+
var _ref = _async_to_generator(function(api, options) {
|
13
|
+
var _resolvedConfig_source, resolvedConfig, appContext, hookRunners, _resolvedConfig_source1, registerEsm, apiOnly, appDirectory, distDirectory, serverConfigFile, distDirectory1, appDirectory1, serverConfigFile1;
|
14
|
+
return _ts_generator(this, function(_state) {
|
15
|
+
switch (_state.label) {
|
16
|
+
case 0:
|
17
|
+
if (options === null || options === void 0 ? void 0 : options.analyze) {
|
18
|
+
process.env.BUNDLE_ANALYZE = "true";
|
19
|
+
}
|
20
|
+
resolvedConfig = api.useResolvedConfigContext();
|
21
|
+
appContext = api.useAppContext();
|
22
|
+
hookRunners = api.useHookRunners();
|
23
|
+
return [
|
24
|
+
4,
|
25
|
+
loadServerPlugins(api, appContext.appDirectory, appContext.metaName)
|
26
|
+
];
|
27
|
+
case 1:
|
28
|
+
_state.sent();
|
29
|
+
if (!(appContext.moduleType && appContext.moduleType === "module"))
|
30
|
+
return [
|
31
|
+
3,
|
32
|
+
4
|
33
|
+
];
|
34
|
+
return [
|
35
|
+
4,
|
36
|
+
import("../esm/register-esm.mjs")
|
37
|
+
];
|
38
|
+
case 2:
|
39
|
+
registerEsm = _state.sent().registerEsm;
|
40
|
+
return [
|
41
|
+
4,
|
42
|
+
registerEsm({
|
43
|
+
appDir: appContext.appDirectory,
|
44
|
+
distDir: appContext.distDirectory,
|
45
|
+
alias: (_resolvedConfig_source1 = resolvedConfig.source) === null || _resolvedConfig_source1 === void 0 ? void 0 : _resolvedConfig_source1.alias
|
46
|
+
})
|
47
|
+
];
|
48
|
+
case 3:
|
49
|
+
_state.sent();
|
50
|
+
_state.label = 4;
|
51
|
+
case 4:
|
52
|
+
return [
|
53
|
+
4,
|
54
|
+
registerCompiler(appContext.appDirectory, appContext.distDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.alias)
|
55
|
+
];
|
56
|
+
case 5:
|
57
|
+
_state.sent();
|
58
|
+
apiOnly = appContext.apiOnly;
|
59
|
+
if (!apiOnly)
|
60
|
+
return [
|
61
|
+
3,
|
62
|
+
10
|
63
|
+
];
|
64
|
+
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverConfigFile = appContext.serverConfigFile;
|
65
|
+
return [
|
66
|
+
4,
|
67
|
+
hookRunners.beforeBuild({
|
68
|
+
// "null" bundlerConfigs
|
69
|
+
bundlerConfigs: void 0
|
70
|
+
})
|
71
|
+
];
|
72
|
+
case 6:
|
73
|
+
_state.sent();
|
74
|
+
return [
|
75
|
+
4,
|
76
|
+
buildServerConfig({
|
77
|
+
appDirectory,
|
78
|
+
distDirectory,
|
79
|
+
configFile: serverConfigFile
|
80
|
+
})
|
81
|
+
];
|
82
|
+
case 7:
|
83
|
+
_state.sent();
|
84
|
+
return [
|
85
|
+
4,
|
86
|
+
generateRoutes(appContext)
|
87
|
+
];
|
88
|
+
case 8:
|
89
|
+
_state.sent();
|
90
|
+
return [
|
91
|
+
4,
|
92
|
+
hookRunners.afterBuild({
|
93
|
+
// "null" stats
|
94
|
+
stats: void 0
|
95
|
+
})
|
96
|
+
];
|
97
|
+
case 9:
|
98
|
+
_state.sent();
|
99
|
+
return [
|
100
|
+
2
|
101
|
+
];
|
102
|
+
case 10:
|
103
|
+
resolvedConfig = _object_spread_props(_object_spread({}, resolvedConfig), {
|
104
|
+
cliOptions: options
|
105
|
+
});
|
106
|
+
ResolvedConfigContext.set(resolvedConfig);
|
107
|
+
distDirectory1 = appContext.distDirectory, appDirectory1 = appContext.appDirectory, serverConfigFile1 = appContext.serverConfigFile;
|
108
|
+
return [
|
109
|
+
4,
|
110
|
+
buildServerConfig({
|
111
|
+
appDirectory: appDirectory1,
|
112
|
+
distDirectory: distDirectory1,
|
113
|
+
configFile: serverConfigFile1
|
114
|
+
})
|
115
|
+
];
|
116
|
+
case 11:
|
117
|
+
_state.sent();
|
118
|
+
logger.info("Starting production build...");
|
119
|
+
if (!appContext.builder) {
|
120
|
+
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
121
|
+
}
|
122
|
+
return [
|
123
|
+
4,
|
124
|
+
appContext.builder.build()
|
125
|
+
];
|
126
|
+
case 12:
|
127
|
+
_state.sent();
|
128
|
+
return [
|
129
|
+
2
|
130
|
+
];
|
131
|
+
}
|
132
|
+
});
|
133
|
+
});
|
134
|
+
return function build2(api, options) {
|
135
|
+
return _ref.apply(this, arguments);
|
136
|
+
};
|
137
|
+
}();
|
138
|
+
export {
|
139
|
+
build
|
140
|
+
};
|
@@ -0,0 +1,48 @@
|
|
1
|
+
import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
|
2
|
+
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
3
|
+
import { getServerPlugins } from "../utils/loadPlugins";
|
4
|
+
var deploy = function() {
|
5
|
+
var _ref = _async_to_generator(function(api, options) {
|
6
|
+
var hookRunners, metaName;
|
7
|
+
return _ts_generator(this, function(_state) {
|
8
|
+
switch (_state.label) {
|
9
|
+
case 0:
|
10
|
+
hookRunners = api.useHookRunners();
|
11
|
+
metaName = api.useAppContext().metaName;
|
12
|
+
return [
|
13
|
+
4,
|
14
|
+
getServerPlugins(api, metaName)
|
15
|
+
];
|
16
|
+
case 1:
|
17
|
+
_state.sent();
|
18
|
+
return [
|
19
|
+
4,
|
20
|
+
hookRunners.beforeDeploy(options)
|
21
|
+
];
|
22
|
+
case 2:
|
23
|
+
_state.sent();
|
24
|
+
return [
|
25
|
+
4,
|
26
|
+
hookRunners.deploy(options)
|
27
|
+
];
|
28
|
+
case 3:
|
29
|
+
_state.sent();
|
30
|
+
return [
|
31
|
+
4,
|
32
|
+
hookRunners.afterDeploy(options)
|
33
|
+
];
|
34
|
+
case 4:
|
35
|
+
_state.sent();
|
36
|
+
return [
|
37
|
+
2
|
38
|
+
];
|
39
|
+
}
|
40
|
+
});
|
41
|
+
});
|
42
|
+
return function deploy2(api, options) {
|
43
|
+
return _ref.apply(this, arguments);
|
44
|
+
};
|
45
|
+
}();
|
46
|
+
export {
|
47
|
+
deploy
|
48
|
+
};
|