@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,94 @@
|
|
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 path from "path";
|
6
|
+
import { createProdServer } from "@modern-js/prod-server";
|
7
|
+
import { SERVER_DIR, getMeta, getTargetDir, isApiOnly, logger } from "@modern-js/utils";
|
8
|
+
import { loadServerPlugins } from "../utils/loadPlugins";
|
9
|
+
import { printInstructions } from "../utils/printInstructions";
|
10
|
+
var start = function() {
|
11
|
+
var _ref = _async_to_generator(function(api) {
|
12
|
+
var _userConfig_source, _userConfig_output_distPath, appContext, userConfig, hookRunners, distDirectory, appDirectory, internalDirectory, port, metaName, serverRoutes, serverConfigFile, apiOnly, runMode, meta, serverConfigPath, pluginInstances, app;
|
13
|
+
return _ts_generator(this, function(_state) {
|
14
|
+
switch (_state.label) {
|
15
|
+
case 0:
|
16
|
+
appContext = api.useAppContext();
|
17
|
+
userConfig = api.useResolvedConfigContext();
|
18
|
+
hookRunners = api.useHookRunners();
|
19
|
+
distDirectory = appContext.distDirectory, appDirectory = appContext.appDirectory, internalDirectory = appContext.internalDirectory, port = appContext.port, metaName = appContext.metaName, serverRoutes = appContext.serverRoutes, serverConfigFile = appContext.serverConfigFile;
|
20
|
+
logger.info("Starting production server...");
|
21
|
+
return [
|
22
|
+
4,
|
23
|
+
isApiOnly(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory)
|
24
|
+
];
|
25
|
+
case 1:
|
26
|
+
apiOnly = _state.sent();
|
27
|
+
if (apiOnly) {
|
28
|
+
runMode = "apiOnly";
|
29
|
+
}
|
30
|
+
meta = getMeta(metaName);
|
31
|
+
serverConfigPath = path.resolve(distDirectory, SERVER_DIR, "".concat(meta, ".server"));
|
32
|
+
return [
|
33
|
+
4,
|
34
|
+
loadServerPlugins(api, appDirectory, metaName)
|
35
|
+
];
|
36
|
+
case 2:
|
37
|
+
pluginInstances = _state.sent();
|
38
|
+
return [
|
39
|
+
4,
|
40
|
+
createProdServer({
|
41
|
+
metaName,
|
42
|
+
pwd: distDirectory,
|
43
|
+
config: _object_spread_props(_object_spread({}, userConfig), {
|
44
|
+
dev: userConfig.dev,
|
45
|
+
// server-core can't get RegExp & Function output.enableInlineScripts by JSON.stringy;
|
46
|
+
output: _object_spread({
|
47
|
+
path: (_userConfig_output_distPath = userConfig.output.distPath) === null || _userConfig_output_distPath === void 0 ? void 0 : _userConfig_output_distPath.root
|
48
|
+
}, userConfig.output || {})
|
49
|
+
}),
|
50
|
+
routes: serverRoutes,
|
51
|
+
plugins: pluginInstances,
|
52
|
+
serverConfigFile,
|
53
|
+
serverConfigPath,
|
54
|
+
appContext: {
|
55
|
+
appDirectory,
|
56
|
+
internalDirectory,
|
57
|
+
sharedDirectory: getTargetDir(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
|
58
|
+
apiDirectory: getTargetDir(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
|
59
|
+
lambdaDirectory: getTargetDir(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
|
60
|
+
},
|
61
|
+
runMode
|
62
|
+
})
|
63
|
+
];
|
64
|
+
case 3:
|
65
|
+
app = _state.sent();
|
66
|
+
app.listen(port, /* @__PURE__ */ _async_to_generator(function() {
|
67
|
+
return _ts_generator(this, function(_state2) {
|
68
|
+
switch (_state2.label) {
|
69
|
+
case 0:
|
70
|
+
return [
|
71
|
+
4,
|
72
|
+
printInstructions(hookRunners, appContext, userConfig)
|
73
|
+
];
|
74
|
+
case 1:
|
75
|
+
_state2.sent();
|
76
|
+
return [
|
77
|
+
2
|
78
|
+
];
|
79
|
+
}
|
80
|
+
});
|
81
|
+
}));
|
82
|
+
return [
|
83
|
+
2
|
84
|
+
];
|
85
|
+
}
|
86
|
+
});
|
87
|
+
});
|
88
|
+
return function start2(api) {
|
89
|
+
return _ref.apply(this, arguments);
|
90
|
+
};
|
91
|
+
}();
|
92
|
+
export {
|
93
|
+
start
|
94
|
+
};
|
@@ -0,0 +1,190 @@
|
|
1
|
+
import { _ as _define_property } from "@swc/helpers/_/_define_property";
|
2
|
+
import { MAIN_ENTRY_NAME } from "@modern-js/utils";
|
3
|
+
import { getAutoInjectEnv } from "../utils/env";
|
4
|
+
function createDefaultConfig(appContext) {
|
5
|
+
var dev = {
|
6
|
+
// `dev.port` should not have a default value
|
7
|
+
// because we will use `server.port` by default
|
8
|
+
port: void 0
|
9
|
+
};
|
10
|
+
var output = {
|
11
|
+
distPath: {
|
12
|
+
root: "dist",
|
13
|
+
html: "html",
|
14
|
+
js: "static/js",
|
15
|
+
css: "static/css",
|
16
|
+
server: "bundles",
|
17
|
+
worker: "worker"
|
18
|
+
},
|
19
|
+
cleanDistPath: true,
|
20
|
+
disableNodePolyfill: true,
|
21
|
+
enableInlineRouteManifests: true,
|
22
|
+
disableInlineRouteManifests: false
|
23
|
+
};
|
24
|
+
var _obj;
|
25
|
+
var source = {
|
26
|
+
entries: void 0,
|
27
|
+
mainEntryName: MAIN_ENTRY_NAME,
|
28
|
+
enableAsyncEntry: false,
|
29
|
+
enableCustomEntry: false,
|
30
|
+
disableDefaultEntries: false,
|
31
|
+
entriesDir: "./src",
|
32
|
+
configDir: "./config",
|
33
|
+
globalVars: getAutoInjectEnv(appContext),
|
34
|
+
alias: (_obj = {}, _define_property(_obj, appContext.internalDirAlias, appContext.internalDirectory), _define_property(_obj, appContext.internalSrcAlias, appContext.srcDirectory), _define_property(_obj, "@", appContext.srcDirectory), _define_property(_obj, "@shared", appContext.sharedDirectory), _obj)
|
35
|
+
};
|
36
|
+
var html = {
|
37
|
+
title: "",
|
38
|
+
mountId: "root",
|
39
|
+
meta: {
|
40
|
+
charset: {
|
41
|
+
charset: "utf-8"
|
42
|
+
},
|
43
|
+
viewport: "width=device-width, initial-scale=1.0, shrink-to-fit=no, viewport-fit=cover, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no",
|
44
|
+
"http-equiv": {
|
45
|
+
"http-equiv": "x-ua-compatible",
|
46
|
+
content: "ie=edge"
|
47
|
+
},
|
48
|
+
renderer: "webkit",
|
49
|
+
layoutmode: "standard",
|
50
|
+
imagemode: "force",
|
51
|
+
"wap-font-scale": "no",
|
52
|
+
"format-detection": "telephone=no"
|
53
|
+
}
|
54
|
+
};
|
55
|
+
var server = {
|
56
|
+
routes: void 0,
|
57
|
+
publicRoutes: void 0,
|
58
|
+
ssr: void 0,
|
59
|
+
ssrByEntries: void 0,
|
60
|
+
baseUrl: "/",
|
61
|
+
port: 8080
|
62
|
+
};
|
63
|
+
return {
|
64
|
+
source,
|
65
|
+
output,
|
66
|
+
server,
|
67
|
+
dev,
|
68
|
+
html,
|
69
|
+
tools: {
|
70
|
+
tsChecker: {
|
71
|
+
issue: {
|
72
|
+
exclude: [
|
73
|
+
{
|
74
|
+
file: "**/api/lambda/**/*"
|
75
|
+
}
|
76
|
+
]
|
77
|
+
}
|
78
|
+
}
|
79
|
+
},
|
80
|
+
plugins: [],
|
81
|
+
builderPlugins: [],
|
82
|
+
runtime: {},
|
83
|
+
runtimeByEntries: {}
|
84
|
+
};
|
85
|
+
}
|
86
|
+
function createLegacyDefaultConfig(appContext) {
|
87
|
+
var _obj;
|
88
|
+
var defaultAlias = appContext ? (_obj = {}, _define_property(_obj, appContext.internalDirAlias, appContext.internalDirectory), _define_property(_obj, appContext.internalSrcAlias, appContext.srcDirectory), _define_property(_obj, "@", appContext.srcDirectory), _define_property(_obj, "@shared", appContext.sharedDirectory), _obj) : {};
|
89
|
+
var sourceDefaults = {
|
90
|
+
entries: void 0,
|
91
|
+
mainEntryName: MAIN_ENTRY_NAME,
|
92
|
+
enableAsyncEntry: false,
|
93
|
+
enableCustomEntry: false,
|
94
|
+
disableDefaultEntries: false,
|
95
|
+
entriesDir: "./src",
|
96
|
+
configDir: "./config",
|
97
|
+
apiDir: "./api",
|
98
|
+
envVars: [],
|
99
|
+
globalVars: getAutoInjectEnv(appContext),
|
100
|
+
alias: defaultAlias,
|
101
|
+
moduleScopes: void 0,
|
102
|
+
include: []
|
103
|
+
};
|
104
|
+
var outputDefaults = {
|
105
|
+
assetPrefix: "/",
|
106
|
+
htmlPath: "html",
|
107
|
+
jsPath: "static/js",
|
108
|
+
cssPath: "static/css",
|
109
|
+
mediaPath: "static/media",
|
110
|
+
path: "dist",
|
111
|
+
title: "",
|
112
|
+
titleByEntries: void 0,
|
113
|
+
meta: {
|
114
|
+
charset: {
|
115
|
+
charset: "utf-8"
|
116
|
+
},
|
117
|
+
viewport: "width=device-width, initial-scale=1.0, shrink-to-fit=no, viewport-fit=cover, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no",
|
118
|
+
"http-equiv": {
|
119
|
+
"http-equiv": "x-ua-compatible",
|
120
|
+
content: "ie=edge"
|
121
|
+
},
|
122
|
+
renderer: "webkit",
|
123
|
+
layoutmode: "standard",
|
124
|
+
imagemode: "force",
|
125
|
+
"wap-font-scale": "no",
|
126
|
+
"format-detection": "telephone=no"
|
127
|
+
},
|
128
|
+
metaByEntries: void 0,
|
129
|
+
inject: "head",
|
130
|
+
injectByEntries: void 0,
|
131
|
+
mountId: "root",
|
132
|
+
favicon: "",
|
133
|
+
faviconByEntries: void 0,
|
134
|
+
copy: void 0,
|
135
|
+
disableHtmlFolder: false,
|
136
|
+
disableCssModuleExtension: false,
|
137
|
+
disableCssExtract: false,
|
138
|
+
enableCssModuleTSDeclaration: false,
|
139
|
+
disableMinimize: false,
|
140
|
+
enableInlineStyles: false,
|
141
|
+
enableInlineScripts: false,
|
142
|
+
disableSourceMap: false,
|
143
|
+
disableInlineRuntimeChunk: false,
|
144
|
+
disableAssetsCache: false,
|
145
|
+
enableLatestDecorators: false,
|
146
|
+
polyfill: "entry",
|
147
|
+
dataUriLimit: 1e4,
|
148
|
+
templateParameters: {},
|
149
|
+
templateParametersByEntries: void 0,
|
150
|
+
cssModuleLocalIdentName: void 0,
|
151
|
+
disableNodePolyfill: false,
|
152
|
+
enableTsLoader: false
|
153
|
+
};
|
154
|
+
var serverDefaults = {
|
155
|
+
routes: void 0,
|
156
|
+
publicRoutes: void 0,
|
157
|
+
ssr: void 0,
|
158
|
+
ssrByEntries: void 0,
|
159
|
+
baseUrl: "/",
|
160
|
+
port: 8080
|
161
|
+
};
|
162
|
+
var devDefaults = {
|
163
|
+
assetPrefix: false,
|
164
|
+
https: false
|
165
|
+
};
|
166
|
+
var toolsDefaults = {
|
167
|
+
webpack: void 0,
|
168
|
+
babel: void 0,
|
169
|
+
postcss: void 0,
|
170
|
+
autoprefixer: void 0,
|
171
|
+
lodash: void 0,
|
172
|
+
devServer: void 0,
|
173
|
+
tsLoader: void 0,
|
174
|
+
terser: void 0,
|
175
|
+
minifyCss: void 0
|
176
|
+
};
|
177
|
+
return {
|
178
|
+
source: sourceDefaults,
|
179
|
+
output: outputDefaults,
|
180
|
+
server: serverDefaults,
|
181
|
+
dev: devDefaults,
|
182
|
+
tools: toolsDefaults,
|
183
|
+
runtime: {},
|
184
|
+
runtimeByEntries: {}
|
185
|
+
};
|
186
|
+
}
|
187
|
+
export {
|
188
|
+
createDefaultConfig,
|
189
|
+
createLegacyDefaultConfig
|
190
|
+
};
|
@@ -0,0 +1,9 @@
|
|
1
|
+
import { initHtmlConfig, initSourceConfig } from "./inits";
|
2
|
+
function initialNormalizedConfig(config, appContext, bundler) {
|
3
|
+
initHtmlConfig(config, appContext);
|
4
|
+
initSourceConfig(config, appContext, bundler);
|
5
|
+
return config;
|
6
|
+
}
|
7
|
+
export {
|
8
|
+
initialNormalizedConfig
|
9
|
+
};
|
@@ -0,0 +1,89 @@
|
|
1
|
+
import path, { isAbsolute } from "path";
|
2
|
+
import { findExists } from "@modern-js/utils";
|
3
|
+
function initHtmlConfig(config, appContext) {
|
4
|
+
var ICON_EXTENSIONS = [
|
5
|
+
"png",
|
6
|
+
"jpg",
|
7
|
+
"jpeg",
|
8
|
+
"svg",
|
9
|
+
"ico"
|
10
|
+
];
|
11
|
+
config.html.appIcon = createBuilderAppIcon(config, appContext);
|
12
|
+
config.html.favicon = createBuilderFavicon(config, appContext);
|
13
|
+
return config.html;
|
14
|
+
function createBuilderAppIcon(config2, appContext2) {
|
15
|
+
var appIcon = config2.html.appIcon;
|
16
|
+
var configDir = config2.source.configDir;
|
17
|
+
var getDefaultAppIcon = function() {
|
18
|
+
return findExists(ICON_EXTENSIONS.map(function(ext) {
|
19
|
+
return path.resolve(appContext2.appDirectory, configDir || "./config", "icon.".concat(ext));
|
20
|
+
}));
|
21
|
+
};
|
22
|
+
return appIcon || getDefaultAppIcon() || void 0;
|
23
|
+
}
|
24
|
+
function createBuilderFavicon(config2, appContext2) {
|
25
|
+
var configDir = config2.source.configDir;
|
26
|
+
var favicon = config2.html.favicon;
|
27
|
+
var getDefaultFavicon = function() {
|
28
|
+
return findExists(ICON_EXTENSIONS.map(function(ext) {
|
29
|
+
return path.resolve(appContext2.appDirectory, configDir || "./config", "favicon.".concat(ext));
|
30
|
+
}));
|
31
|
+
};
|
32
|
+
return favicon || getDefaultFavicon() || void 0;
|
33
|
+
}
|
34
|
+
}
|
35
|
+
function initSourceConfig(config, appContext, bundler) {
|
36
|
+
config.source.include = createBuilderInclude(config, appContext);
|
37
|
+
if (bundler === "webpack") {
|
38
|
+
config.source.moduleScopes = createBuilderModuleScope(config);
|
39
|
+
}
|
40
|
+
}
|
41
|
+
function createBuilderInclude(config, appContext) {
|
42
|
+
var include = config.source.include;
|
43
|
+
var defaultInclude = [
|
44
|
+
appContext.internalDirectory
|
45
|
+
];
|
46
|
+
var transformInclude = (include || []).map(function(include2) {
|
47
|
+
if (typeof include2 === "string") {
|
48
|
+
if (isAbsolute(include2)) {
|
49
|
+
return include2;
|
50
|
+
}
|
51
|
+
return new RegExp(include2);
|
52
|
+
}
|
53
|
+
return include2;
|
54
|
+
}).concat(defaultInclude);
|
55
|
+
return transformInclude;
|
56
|
+
}
|
57
|
+
function createBuilderModuleScope(config) {
|
58
|
+
var moduleScopes = config.source.moduleScopes;
|
59
|
+
if (moduleScopes) {
|
60
|
+
var DEFAULT_SCOPES = [
|
61
|
+
"./src",
|
62
|
+
"./shared",
|
63
|
+
/node_modules/
|
64
|
+
];
|
65
|
+
var builderModuleScope = applyScopeOptions(DEFAULT_SCOPES, moduleScopes);
|
66
|
+
return builderModuleScope;
|
67
|
+
} else {
|
68
|
+
return void 0;
|
69
|
+
}
|
70
|
+
function isPrimitiveScope(items) {
|
71
|
+
return items.every(function(item) {
|
72
|
+
return typeof item === "string" || Object.prototype.toString.call(item) === "[object RegExp]";
|
73
|
+
});
|
74
|
+
}
|
75
|
+
function applyScopeOptions(defaults, options) {
|
76
|
+
if (Array.isArray(options)) {
|
77
|
+
if (isPrimitiveScope(options)) {
|
78
|
+
return defaults.concat(options);
|
79
|
+
}
|
80
|
+
return options.reduce(applyScopeOptions, defaults);
|
81
|
+
}
|
82
|
+
return options(defaults) || defaults;
|
83
|
+
}
|
84
|
+
}
|
85
|
+
export {
|
86
|
+
createBuilderModuleScope,
|
87
|
+
initHtmlConfig,
|
88
|
+
initSourceConfig
|
89
|
+
};
|
@@ -0,0 +1,21 @@
|
|
1
|
+
function createHtmlConfig(config) {
|
2
|
+
var _config_output = config.output, disableHtmlFolder = _config_output.disableHtmlFolder, favicon = _config_output.favicon, faviconByEntries = _config_output.faviconByEntries, inject = _config_output.inject, injectByEntries = _config_output.injectByEntries, meta = _config_output.meta, metaByEntries = _config_output.metaByEntries, mountId = _config_output.mountId, title = _config_output.title, titleByEntries = _config_output.titleByEntries, templateParameters = _config_output.templateParameters, templateParametersByEntries = _config_output.templateParametersByEntries, crossorigin = _config_output.crossorigin;
|
3
|
+
return {
|
4
|
+
disableHtmlFolder,
|
5
|
+
favicon,
|
6
|
+
faviconByEntries,
|
7
|
+
inject,
|
8
|
+
injectByEntries,
|
9
|
+
meta,
|
10
|
+
metaByEntries,
|
11
|
+
mountId,
|
12
|
+
title,
|
13
|
+
titleByEntries,
|
14
|
+
crossorigin,
|
15
|
+
templateParameters,
|
16
|
+
templateParametersByEntries
|
17
|
+
};
|
18
|
+
}
|
19
|
+
export {
|
20
|
+
createHtmlConfig
|
21
|
+
};
|
@@ -0,0 +1,45 @@
|
|
1
|
+
function createOutputConfig(config) {
|
2
|
+
var _config_output = config.output, assetPrefix = _config_output.assetPrefix, copy = _config_output.copy, cssModuleLocalIdentName = _config_output.cssModuleLocalIdentName, cssPath = _config_output.cssPath, jsPath = _config_output.jsPath, htmlPath = _config_output.htmlPath, mediaPath = _config_output.mediaPath, enableTsLoader = _config_output.enableTsLoader, path = _config_output.path, disableInlineRuntimeChunk = _config_output.disableInlineRuntimeChunk, disableCssExtract = _config_output.disableCssExtract, disableMinimize = _config_output.disableMinimize, disableSourceMap = _config_output.disableSourceMap, disableTsChecker = _config_output.disableTsChecker, enableCssModuleTSDeclaration = _config_output.enableCssModuleTSDeclaration, enableInlineScripts = _config_output.enableInlineScripts, enableInlineStyles = _config_output.enableInlineStyles, polyfill = _config_output.polyfill, dataUriLimit = _config_output.dataUriLimit, disableAssetsCache = _config_output.disableAssetsCache, enableLatestDecorators = _config_output.enableLatestDecorators, disableCssModuleExtension = _config_output.disableCssModuleExtension, ssg = _config_output.ssg, disableNodePolyfill = _config_output.disableNodePolyfill;
|
3
|
+
return {
|
4
|
+
assetPrefix,
|
5
|
+
copy,
|
6
|
+
distPath: {
|
7
|
+
root: path,
|
8
|
+
css: cssPath,
|
9
|
+
js: jsPath,
|
10
|
+
html: htmlPath,
|
11
|
+
// modern.js v1 output all media files to `dist/media` by default
|
12
|
+
svg: mediaPath || "media",
|
13
|
+
image: mediaPath || "media",
|
14
|
+
font: mediaPath || "media",
|
15
|
+
media: mediaPath || "media"
|
16
|
+
},
|
17
|
+
dataUriLimit: {
|
18
|
+
svg: dataUriLimit,
|
19
|
+
image: dataUriLimit,
|
20
|
+
font: dataUriLimit,
|
21
|
+
media: dataUriLimit
|
22
|
+
},
|
23
|
+
cssModuleLocalIdentName,
|
24
|
+
disableCssExtract,
|
25
|
+
disableCssModuleExtension,
|
26
|
+
disableInlineRuntimeChunk,
|
27
|
+
disableMinimize,
|
28
|
+
disableSourceMap,
|
29
|
+
disableTsChecker: disableTsChecker || enableTsLoader,
|
30
|
+
enableCssModuleTSDeclaration,
|
31
|
+
enableInlineScripts,
|
32
|
+
enableInlineStyles,
|
33
|
+
polyfill,
|
34
|
+
disableFilenameHash: disableAssetsCache,
|
35
|
+
enableLatestDecorators,
|
36
|
+
ssg,
|
37
|
+
// set `true`, only in legacy config
|
38
|
+
enableAssetFallback: true,
|
39
|
+
enableAssetManifest: true,
|
40
|
+
disableNodePolyfill
|
41
|
+
};
|
42
|
+
}
|
43
|
+
export {
|
44
|
+
createOutputConfig
|
45
|
+
};
|
@@ -0,0 +1,46 @@
|
|
1
|
+
function createSourceConfig(config) {
|
2
|
+
var _config_source = config.source, alias = _config_source.alias, envVars = _config_source.envVars, globalVars = _config_source.globalVars, include = _config_source.include, moduleScopes = _config_source.moduleScopes, preEntry = _config_source.preEntry, entries = _config_source.entries, mainEntryName = _config_source.mainEntryName, enableAsyncEntry = _config_source.enableAsyncEntry, enableCustomEntry = _config_source.enableCustomEntry, disableDefaultEntries = _config_source.disableDefaultEntries, entriesDir = _config_source.entriesDir, configDir = _config_source.configDir;
|
3
|
+
var builderGlobalVars = globalVars || {};
|
4
|
+
var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = void 0;
|
5
|
+
try {
|
6
|
+
for (var _iterator = (envVars || [])[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
7
|
+
var envVar = _step.value;
|
8
|
+
var envVarValue = process.env[envVar];
|
9
|
+
envVarValue && (builderGlobalVars["process.env.".concat(envVar)] = envVarValue);
|
10
|
+
}
|
11
|
+
} catch (err) {
|
12
|
+
_didIteratorError = true;
|
13
|
+
_iteratorError = err;
|
14
|
+
} finally {
|
15
|
+
try {
|
16
|
+
if (!_iteratorNormalCompletion && _iterator.return != null) {
|
17
|
+
_iterator.return();
|
18
|
+
}
|
19
|
+
} finally {
|
20
|
+
if (_didIteratorError) {
|
21
|
+
throw _iteratorError;
|
22
|
+
}
|
23
|
+
}
|
24
|
+
}
|
25
|
+
return {
|
26
|
+
alias,
|
27
|
+
moduleScopes,
|
28
|
+
globalVars: builderGlobalVars,
|
29
|
+
include,
|
30
|
+
preEntry,
|
31
|
+
entries,
|
32
|
+
mainEntryName,
|
33
|
+
enableAsyncEntry,
|
34
|
+
enableCustomEntry,
|
35
|
+
disableDefaultEntries,
|
36
|
+
entriesDir,
|
37
|
+
configDir,
|
38
|
+
resolveExtensionPrefix: {
|
39
|
+
web: ".web",
|
40
|
+
node: ".node"
|
41
|
+
}
|
42
|
+
};
|
43
|
+
}
|
44
|
+
export {
|
45
|
+
createSourceConfig
|
46
|
+
};
|
@@ -0,0 +1,28 @@
|
|
1
|
+
function createToolsConfig(config) {
|
2
|
+
var _config_tools = config.tools, autoprefixer = _config_tools.autoprefixer, babel = _config_tools.babel, minifyCss = _config_tools.minifyCss, terser = _config_tools.terser, webpack = _config_tools.webpack, webpackChain = _config_tools.webpackChain, tsLoader = _config_tools.tsLoader, styledComponents = _config_tools.styledComponents, sass = _config_tools.sass, postcss = _config_tools.postcss, less = _config_tools.less, htmlPlugin = _config_tools.htmlPlugin, devServer = _config_tools.devServer, tailwindcss = _config_tools.tailwindcss, jest = _config_tools.jest, esbuild = _config_tools.esbuild;
|
3
|
+
var enableTsLoader = config.output.enableTsLoader;
|
4
|
+
return {
|
5
|
+
tsLoader: enableTsLoader ? tsLoader : void 0,
|
6
|
+
autoprefixer,
|
7
|
+
babel,
|
8
|
+
minifyCss,
|
9
|
+
terser,
|
10
|
+
webpack,
|
11
|
+
webpackChain,
|
12
|
+
styledComponents,
|
13
|
+
sass,
|
14
|
+
postcss,
|
15
|
+
less,
|
16
|
+
htmlPlugin,
|
17
|
+
devServer,
|
18
|
+
tailwindcss,
|
19
|
+
jest,
|
20
|
+
esbuild: {
|
21
|
+
loader: false,
|
22
|
+
minimize: esbuild
|
23
|
+
}
|
24
|
+
};
|
25
|
+
}
|
26
|
+
export {
|
27
|
+
createToolsConfig
|
28
|
+
};
|
@@ -0,0 +1,43 @@
|
|
1
|
+
import { createHtmlConfig } from "./createHtmlConfig";
|
2
|
+
import { createOutputConfig } from "./createOutputConfig";
|
3
|
+
import { createSourceConfig } from "./createSourceConfig";
|
4
|
+
import { createToolsConfig } from "./createToolsConfig";
|
5
|
+
function transformNormalizedConfig(config) {
|
6
|
+
var html = createHtmlConfig(config);
|
7
|
+
var output = createOutputConfig(config);
|
8
|
+
var source = createSourceConfig(config);
|
9
|
+
var tools = createToolsConfig(config);
|
10
|
+
var bff = config.bff, dev = config.dev, deploy = config.deploy, runtime = config.runtime, runtimeByEntries = config.runtimeByEntries, server = config.server, cliOptions = config.cliOptions, plugins = config.plugins, testing = config.testing, autoLoadPlugins = config.autoLoadPlugins;
|
11
|
+
return {
|
12
|
+
source,
|
13
|
+
html,
|
14
|
+
output,
|
15
|
+
tools,
|
16
|
+
bff,
|
17
|
+
dev,
|
18
|
+
deploy,
|
19
|
+
runtime,
|
20
|
+
runtimeByEntries,
|
21
|
+
server,
|
22
|
+
cliOptions,
|
23
|
+
testing,
|
24
|
+
devtools: {},
|
25
|
+
builderPlugins: [],
|
26
|
+
plugins,
|
27
|
+
security: {},
|
28
|
+
_raw: {},
|
29
|
+
experiments: {},
|
30
|
+
environments: {},
|
31
|
+
autoLoadPlugins,
|
32
|
+
performance: {
|
33
|
+
removeMomentLocale: true
|
34
|
+
}
|
35
|
+
};
|
36
|
+
}
|
37
|
+
function checkIsLegacyConfig(config) {
|
38
|
+
return Boolean(config.legacy);
|
39
|
+
}
|
40
|
+
export {
|
41
|
+
checkIsLegacyConfig,
|
42
|
+
transformNormalizedConfig
|
43
|
+
};
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
|
2
|
+
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
|
3
|
+
var defineConfig = function(config) {
|
4
|
+
return config;
|
5
|
+
};
|
6
|
+
var defineLegacyConfig = function(config) {
|
7
|
+
var _config_autoLoadPlugins;
|
8
|
+
return _object_spread_props(_object_spread({}, config), {
|
9
|
+
legacy: true,
|
10
|
+
autoLoadPlugins: (_config_autoLoadPlugins = config.autoLoadPlugins) !== null && _config_autoLoadPlugins !== void 0 ? _config_autoLoadPlugins : true
|
11
|
+
});
|
12
|
+
};
|
13
|
+
export {
|
14
|
+
defineConfig,
|
15
|
+
defineLegacyConfig
|
16
|
+
};
|
@@ -0,0 +1,20 @@
|
|
1
|
+
import { pathToFileURL } from 'url';
|
2
|
+
import { createMatchPath } from './utils.mjs';
|
3
|
+
|
4
|
+
let matchPath;
|
5
|
+
export async function initialize({ appDir, alias, tsconfigPath }) {
|
6
|
+
matchPath = createMatchPath({
|
7
|
+
alias,
|
8
|
+
appDir,
|
9
|
+
tsconfigPath,
|
10
|
+
});
|
11
|
+
}
|
12
|
+
|
13
|
+
export function resolve(specifier, context, defaultResolve) {
|
14
|
+
const match = matchPath(specifier);
|
15
|
+
return match
|
16
|
+
? defaultResolve(pathToFileURL(match).href, context)
|
17
|
+
: defaultResolve(specifier, context);
|
18
|
+
}
|
19
|
+
|
20
|
+
export { load } from 'esbuild-register/loader';
|
@@ -0,0 +1,66 @@
|
|
1
|
+
import assert from 'node:assert';
|
2
|
+
import path from 'node:path';
|
3
|
+
import { fs, isVersionAtLeast1819, readTsConfigByFile } from '@modern-js/utils';
|
4
|
+
|
5
|
+
const checkDep = async dep => {
|
6
|
+
try {
|
7
|
+
await import(dep);
|
8
|
+
return true;
|
9
|
+
} catch (error) {
|
10
|
+
return false;
|
11
|
+
}
|
12
|
+
};
|
13
|
+
|
14
|
+
export const registerEsm = async ({ appDir, distDir, alias }) => {
|
15
|
+
const nodeVersion = process.versions.node;
|
16
|
+
const versionArr = nodeVersion.split('.').map(Number);
|
17
|
+
|
18
|
+
assert(
|
19
|
+
isVersionAtLeast1819(nodeVersion),
|
20
|
+
`The node version of the esm project must be greater than 18.19.0, current version is ${nodeVersion}`,
|
21
|
+
);
|
22
|
+
const hasTsNode = await checkDep('ts-node');
|
23
|
+
const TS_CONFIG_FILENAME = `tsconfig.json`;
|
24
|
+
const tsconfigPath = path.resolve(appDir, TS_CONFIG_FILENAME);
|
25
|
+
const hasTsconfig = await fs.pathExists(tsconfigPath);
|
26
|
+
const { register } = await import('node:module');
|
27
|
+
if (hasTsNode && hasTsconfig) {
|
28
|
+
// These can be overridden by ts-node options in tsconfig.json
|
29
|
+
process.env.TS_NODE_TRANSPILE_ONLY = true;
|
30
|
+
process.env.TS_NODE_PROJECT = tsconfigPath;
|
31
|
+
process.env.TS_NODE_SCOPE = true;
|
32
|
+
process.env.TS_NODE_FILES = true;
|
33
|
+
process.env.TS_NODE_IGNORE = `(?:^|/)node_modules/,(?:^|/)${path.relative(
|
34
|
+
appDir,
|
35
|
+
distDir,
|
36
|
+
)}/`;
|
37
|
+
register('./ts-node-loader.mjs', import.meta.url, {
|
38
|
+
data: {
|
39
|
+
appDir,
|
40
|
+
distDir,
|
41
|
+
alias,
|
42
|
+
tsconfigPath,
|
43
|
+
},
|
44
|
+
});
|
45
|
+
} else {
|
46
|
+
process.env.MODERN_NODE_LOADER = 'esbuild';
|
47
|
+
let tsConfig = {};
|
48
|
+
if (hasTsconfig) {
|
49
|
+
tsConfig = readTsConfigByFile(tsconfigPath);
|
50
|
+
}
|
51
|
+
const esbuildRegister = await import('esbuild-register/dist/node');
|
52
|
+
esbuildRegister.register({
|
53
|
+
tsconfigRaw: hasTsconfig ? tsConfig : undefined,
|
54
|
+
hookIgnoreNodeModules: true,
|
55
|
+
hookMatcher: fileName => !fileName.startsWith(distDir),
|
56
|
+
});
|
57
|
+
register('./esbuild-loader.mjs', import.meta.url, {
|
58
|
+
data: {
|
59
|
+
appDir,
|
60
|
+
distDir,
|
61
|
+
alias,
|
62
|
+
tsconfigPath,
|
63
|
+
},
|
64
|
+
});
|
65
|
+
}
|
66
|
+
};
|