@modern-js/app-tools 2.0.0-beta.2 → 2.0.0-beta.4
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 +556 -0
- package/bin/modern.js +11 -1
- package/dist/js/modern/analyze/Builder.js +39 -0
- package/dist/js/modern/analyze/constants.js +38 -16
- package/dist/js/modern/analyze/generateCode.js +272 -211
- package/dist/js/modern/analyze/getBundleEntry.js +34 -32
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +93 -49
- package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +89 -47
- package/dist/js/modern/analyze/getClientRoutes/index.js +6 -2
- package/dist/js/modern/analyze/getClientRoutes/utils.js +23 -10
- package/dist/js/modern/analyze/getFileSystemEntry.js +43 -22
- package/dist/js/modern/analyze/getHtmlTemplate.js +89 -49
- package/dist/js/modern/analyze/getServerRoutes.js +122 -126
- package/dist/js/modern/analyze/index.js +201 -160
- package/dist/js/modern/analyze/isDefaultExportFunction.js +30 -16
- package/dist/js/modern/analyze/makeLegalIdentifier.js +10 -11
- package/dist/js/modern/analyze/nestedRoutes.js +110 -53
- package/dist/js/modern/analyze/templates.js +191 -77
- package/dist/js/modern/analyze/utils.js +98 -51
- package/dist/js/modern/builder/builderPlugins/compatModern.js +125 -107
- package/dist/js/modern/builder/index.js +124 -89
- package/dist/js/modern/builder/loaders/routerLoader.js +17 -0
- package/dist/js/modern/builder/loaders/serverModuleLoader.js +7 -0
- package/dist/js/modern/builder/share.js +23 -21
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +23 -22
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +31 -27
- package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +100 -84
- package/dist/js/modern/commands/build.js +67 -42
- package/dist/js/modern/commands/deploy.js +27 -4
- package/dist/js/modern/commands/dev.js +93 -47
- package/dist/js/modern/commands/index.js +1 -1
- package/dist/js/modern/commands/inspect.js +30 -5
- package/dist/js/modern/commands/start.js +37 -16
- package/dist/js/modern/config/default.js +103 -114
- package/dist/js/modern/config/index.js +8 -2
- package/dist/js/modern/config/initial/createHtmlConfig.js +5 -2
- package/dist/js/modern/config/initial/createOutputConfig.js +11 -9
- package/dist/js/modern/config/initial/createSourceConfig.js +5 -2
- package/dist/js/modern/config/initial/createToolsConfig.js +7 -6
- package/dist/js/modern/config/initial/index.js +9 -4
- package/dist/js/modern/config/initial/inits.js +109 -73
- package/dist/js/modern/config/initial/transformNormalizedConfig.js +6 -3
- package/dist/js/modern/defineConfig.js +26 -11
- package/dist/js/modern/exports/server.js +4 -1
- package/dist/js/modern/hooks.js +15 -4
- package/dist/js/modern/index.js +178 -90
- package/dist/js/modern/initialize/index.js +98 -51
- package/dist/js/modern/locale/en.js +20 -21
- package/dist/js/modern/locale/index.js +6 -6
- package/dist/js/modern/locale/zh.js +21 -22
- package/dist/js/modern/schema/Schema.js +6 -5
- package/dist/js/modern/schema/index.js +51 -100
- package/dist/js/modern/schema/legacy.js +96 -231
- package/dist/js/modern/types/config/index.js +0 -1
- package/dist/js/modern/types/index.js +0 -1
- package/dist/js/modern/types/legacyConfig/output.js +0 -1
- package/dist/js/modern/utils/commands.js +5 -2
- package/dist/js/modern/utils/config.js +102 -41
- package/dist/js/modern/utils/createFileWatcher.js +84 -51
- package/dist/js/modern/utils/createServer.js +63 -17
- package/dist/js/modern/utils/getSpecifiedEntries.js +46 -19
- package/dist/js/modern/utils/language.js +6 -3
- package/dist/js/modern/utils/printInstructions.js +27 -8
- package/dist/js/modern/utils/restart.js +43 -16
- package/dist/js/modern/utils/routes.js +29 -12
- package/dist/js/node/analyze/Builder.js +58 -0
- package/dist/js/node/analyze/constants.js +54 -35
- package/dist/js/node/analyze/generateCode.js +291 -228
- package/dist/js/node/analyze/getBundleEntry.js +58 -44
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +132 -76
- package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +128 -74
- package/dist/js/node/analyze/getClientRoutes/index.js +23 -17
- package/dist/js/node/analyze/getClientRoutes/utils.js +44 -21
- package/dist/js/node/analyze/getFileSystemEntry.js +70 -39
- package/dist/js/node/analyze/getHtmlTemplate.js +116 -61
- package/dist/js/node/analyze/getServerRoutes.js +143 -137
- package/dist/js/node/analyze/index.js +247 -174
- package/dist/js/node/analyze/isDefaultExportFunction.js +55 -26
- package/dist/js/node/analyze/makeLegalIdentifier.js +27 -15
- package/dist/js/node/analyze/nestedRoutes.js +140 -67
- package/dist/js/node/analyze/templates.js +212 -84
- package/dist/js/node/analyze/utils.js +123 -62
- package/dist/js/node/builder/builderPlugins/compatModern.js +153 -120
- package/dist/js/node/builder/index.js +152 -98
- package/dist/js/node/builder/loaders/routerLoader.js +36 -0
- package/dist/js/node/builder/loaders/serverModuleLoader.js +26 -0
- package/dist/js/node/builder/share.js +46 -26
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +39 -26
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +47 -31
- package/dist/js/node/builder/webpackPlugins/routerPlugin.js +118 -90
- package/dist/js/node/commands/build.js +89 -52
- package/dist/js/node/commands/deploy.js +45 -10
- package/dist/js/node/commands/dev.js +115 -61
- package/dist/js/node/commands/index.js +19 -38
- package/dist/js/node/commands/inspect.js +48 -11
- package/dist/js/node/commands/start.js +65 -27
- package/dist/js/node/config/default.js +119 -118
- package/dist/js/node/config/index.js +25 -29
- package/dist/js/node/config/initial/createHtmlConfig.js +22 -6
- package/dist/js/node/config/initial/createOutputConfig.js +28 -13
- package/dist/js/node/config/initial/createSourceConfig.js +22 -6
- package/dist/js/node/config/initial/createToolsConfig.js +24 -10
- package/dist/js/node/config/initial/index.js +28 -17
- package/dist/js/node/config/initial/inits.js +126 -81
- package/dist/js/node/config/initial/transformNormalizedConfig.js +31 -15
- package/dist/js/node/defineConfig.js +43 -17
- package/dist/js/node/exports/server.js +21 -10
- package/dist/js/node/hooks.js +48 -29
- package/dist/js/node/index.js +225 -128
- package/dist/js/node/initialize/index.js +116 -61
- package/dist/js/node/locale/en.js +36 -25
- package/dist/js/node/locale/index.js +27 -15
- package/dist/js/node/locale/zh.js +37 -26
- package/dist/js/node/schema/Schema.js +23 -10
- package/dist/js/node/schema/index.js +77 -114
- package/dist/js/node/schema/legacy.js +117 -240
- package/dist/js/node/types/config/index.js +17 -16
- package/dist/js/node/types/index.js +19 -38
- package/dist/js/node/types/legacyConfig/output.js +0 -5
- package/dist/js/node/utils/commands.js +21 -6
- package/dist/js/node/utils/config.js +120 -51
- package/dist/js/node/utils/createFileWatcher.js +104 -60
- package/dist/js/node/utils/createServer.js +86 -25
- package/dist/js/node/utils/getSpecifiedEntries.js +64 -25
- package/dist/js/node/utils/language.js +24 -8
- package/dist/js/node/utils/printInstructions.js +47 -16
- package/dist/js/node/utils/restart.js +61 -21
- package/dist/js/node/utils/routes.js +53 -18
- package/dist/js/treeshaking/analyze/Builder.js +199 -0
- package/dist/js/treeshaking/analyze/constants.js +28 -16
- package/dist/js/treeshaking/analyze/generateCode.js +605 -355
- package/dist/js/treeshaking/analyze/getBundleEntry.js +55 -63
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +214 -168
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +215 -169
- package/dist/js/treeshaking/analyze/getClientRoutes/index.js +3 -2
- package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +19 -20
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +89 -86
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +298 -125
- package/dist/js/treeshaking/analyze/getServerRoutes.js +210 -146
- package/dist/js/treeshaking/analyze/index.js +571 -304
- package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +45 -26
- package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +13 -16
- package/dist/js/treeshaking/analyze/nestedRoutes.js +414 -160
- package/dist/js/treeshaking/analyze/templates.js +432 -161
- package/dist/js/treeshaking/analyze/utils.js +361 -80
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +282 -195
- package/dist/js/treeshaking/builder/index.js +371 -167
- package/dist/js/treeshaking/builder/loaders/routerLoader.js +13 -0
- package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +5 -0
- package/dist/js/treeshaking/builder/share.js +38 -44
- package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +108 -44
- package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +70 -39
- package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +334 -112
- package/dist/js/treeshaking/commands/build.js +286 -88
- package/dist/js/treeshaking/commands/deploy.js +153 -25
- package/dist/js/treeshaking/commands/dev.js +318 -132
- package/dist/js/treeshaking/commands/index.js +1 -1
- package/dist/js/treeshaking/commands/inspect.js +147 -32
- package/dist/js/treeshaking/commands/start.js +190 -68
- package/dist/js/treeshaking/config/default.js +210 -199
- package/dist/js/treeshaking/config/index.js +3 -2
- package/dist/js/treeshaking/config/initial/createHtmlConfig.js +19 -31
- package/dist/js/treeshaking/config/initial/createOutputConfig.js +43 -67
- package/dist/js/treeshaking/config/initial/createSourceConfig.js +37 -40
- package/dist/js/treeshaking/config/initial/createToolsConfig.js +23 -38
- package/dist/js/treeshaking/config/initial/index.js +10 -9
- package/dist/js/treeshaking/config/initial/inits.js +205 -106
- package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +27 -34
- package/dist/js/treeshaking/defineConfig.js +60 -13
- package/dist/js/treeshaking/exports/server.js +2 -1
- package/dist/js/treeshaking/hooks.js +30 -25
- package/dist/js/treeshaking/index.js +681 -256
- package/dist/js/treeshaking/initialize/index.js +290 -112
- package/dist/js/treeshaking/locale/en.js +34 -33
- package/dist/js/treeshaking/locale/index.js +5 -5
- package/dist/js/treeshaking/locale/zh.js +34 -33
- package/dist/js/treeshaking/schema/Schema.js +267 -69
- package/dist/js/treeshaking/schema/index.js +165 -121
- package/dist/js/treeshaking/schema/legacy.js +323 -256
- package/dist/js/treeshaking/types/config/deploy.js +1 -0
- package/dist/js/treeshaking/types/config/dev.js +1 -0
- package/dist/js/treeshaking/types/config/experiments.js +1 -0
- package/dist/js/treeshaking/types/config/html.js +1 -0
- package/dist/js/treeshaking/types/config/index.js +0 -1
- package/dist/js/treeshaking/types/config/output.js +1 -0
- package/dist/js/treeshaking/types/config/performance.js +1 -0
- package/dist/js/treeshaking/types/config/security.js +1 -0
- package/dist/js/treeshaking/types/config/source.js +1 -0
- package/dist/js/treeshaking/types/config/tools.js +1 -0
- package/dist/js/treeshaking/types/hooks.js +1 -0
- package/dist/js/treeshaking/types/index.js +0 -1
- package/dist/js/treeshaking/types/legacyConfig/deploy.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/dev.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/index.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/output.js +1 -1
- package/dist/js/treeshaking/types/legacyConfig/source.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/tools.js +1 -0
- package/dist/js/treeshaking/utils/commands.js +6 -5
- package/dist/js/treeshaking/utils/config.js +295 -117
- package/dist/js/treeshaking/utils/createFileWatcher.js +278 -118
- package/dist/js/treeshaking/utils/createServer.js +252 -67
- package/dist/js/treeshaking/utils/getSpecifiedEntries.js +182 -55
- package/dist/js/treeshaking/utils/language.js +6 -5
- package/dist/js/treeshaking/utils/printInstructions.js +151 -29
- package/dist/js/treeshaking/utils/restart.js +184 -42
- package/dist/js/treeshaking/utils/routes.js +151 -27
- package/dist/js/treeshaking/utils/types.js +1 -0
- package/dist/types/analyze/Builder.d.ts +8 -0
- package/dist/types/analyze/constants.d.ts +2 -0
- package/dist/types/analyze/index.d.ts +2 -0
- package/dist/types/analyze/templates.d.ts +10 -7
- package/dist/types/analyze/utils.d.ts +9 -1
- package/dist/types/builder/builderPlugins/compatModern.d.ts +2 -1
- package/dist/types/builder/index.d.ts +3 -3
- package/dist/types/builder/loaders/routerLoader.d.ts +3 -0
- package/dist/types/builder/loaders/serverModuleLoader.d.ts +3 -0
- package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +1 -7
- package/dist/types/defineConfig.d.ts +1 -0
- package/dist/types/index.d.ts +6 -1
- package/dist/types/initialize/index.d.ts +2 -0
- package/dist/types/types/config/dev.d.ts +2 -2
- package/dist/types/types/config/index.d.ts +1 -0
- package/dist/types/types/config/output.d.ts +0 -1
- package/dist/types/types/config/source.d.ts +1 -0
- package/dist/types/types/config/tools.d.ts +10 -1
- package/dist/types/types/hooks.d.ts +7 -1
- package/dist/types/types/legacyConfig/dev.d.ts +1 -0
- package/dist/types/types/legacyConfig/output.d.ts +1 -1
- package/dist/types/types/legacyConfig/source.d.ts +1 -0
- package/dist/types/types/legacyConfig/tools.d.ts +1 -0
- package/dist/types/utils/config.d.ts +1 -0
- package/dist/types/utils/createFileWatcher.d.ts +2 -1
- package/dist/types/utils/createServer.d.ts +1 -0
- package/dist/types/utils/restart.d.ts +1 -1
- package/lib/types.d.ts +1 -1
- package/package.json +26 -22
|
@@ -1,16 +1,81 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
fileSystemRoutes: () => fileSystemRoutes,
|
|
27
|
+
html: () => html,
|
|
28
|
+
index: () => index,
|
|
29
|
+
renderFunction: () => renderFunction,
|
|
30
|
+
routesForServer: () => routesForServer
|
|
5
31
|
});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
32
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
33
|
+
var import_path = __toESM(require("path"));
|
|
34
|
+
var import_utils = require("@modern-js/utils");
|
|
35
|
+
var import_constants = require("./constants");
|
|
36
|
+
var __defProp2 = Object.defineProperty;
|
|
37
|
+
var __defProps = Object.defineProperties;
|
|
38
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
39
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
40
|
+
var __hasOwnProp2 = Object.prototype.hasOwnProperty;
|
|
41
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
42
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
43
|
+
var __spreadValues = (a, b) => {
|
|
44
|
+
for (var prop in b || (b = {}))
|
|
45
|
+
if (__hasOwnProp2.call(b, prop))
|
|
46
|
+
__defNormalProp(a, prop, b[prop]);
|
|
47
|
+
if (__getOwnPropSymbols)
|
|
48
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
49
|
+
if (__propIsEnum.call(b, prop))
|
|
50
|
+
__defNormalProp(a, prop, b[prop]);
|
|
51
|
+
}
|
|
52
|
+
return a;
|
|
53
|
+
};
|
|
54
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
55
|
+
var __async = (__this, __arguments, generator) => {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
var fulfilled = (value) => {
|
|
58
|
+
try {
|
|
59
|
+
step(generator.next(value));
|
|
60
|
+
} catch (e) {
|
|
61
|
+
reject(e);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
var rejected = (value) => {
|
|
65
|
+
try {
|
|
66
|
+
step(generator.throw(value));
|
|
67
|
+
} catch (e) {
|
|
68
|
+
reject(e);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
72
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
73
|
+
});
|
|
74
|
+
};
|
|
10
75
|
const index = ({
|
|
11
76
|
mountId,
|
|
12
77
|
imports,
|
|
13
|
-
renderFunction,
|
|
78
|
+
renderFunction: renderFunction2,
|
|
14
79
|
exportStatement
|
|
15
80
|
}) => `
|
|
16
81
|
const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
|
|
@@ -24,28 +89,25 @@ let AppWrapper = null;
|
|
|
24
89
|
let root = null;
|
|
25
90
|
|
|
26
91
|
function render() {
|
|
27
|
-
${
|
|
92
|
+
${renderFunction2}
|
|
28
93
|
}
|
|
29
94
|
|
|
30
95
|
AppWrapper = render();
|
|
31
96
|
|
|
32
97
|
${exportStatement};
|
|
33
98
|
`;
|
|
34
|
-
exports.index = index;
|
|
35
99
|
const renderFunction = ({
|
|
36
100
|
plugins,
|
|
37
101
|
customBootstrap,
|
|
38
|
-
fileSystemRoutes
|
|
102
|
+
fileSystemRoutes: fileSystemRoutes2
|
|
39
103
|
}) => `
|
|
40
104
|
AppWrapper = createApp({
|
|
41
105
|
plugins: [
|
|
42
|
-
${plugins.map(
|
|
43
|
-
name,
|
|
44
|
-
|
|
45
|
-
args
|
|
46
|
-
}) => `${name}({...${options}, ...App?.config?.${args || name}}),`).join('\n')}
|
|
106
|
+
${plugins.map(
|
|
107
|
+
({ name, options, args }) => `${name}({...${options}, ...App?.config?.${args || name}}),`
|
|
108
|
+
).join("\n")}
|
|
47
109
|
]
|
|
48
|
-
})(${
|
|
110
|
+
})(${fileSystemRoutes2 ? "" : `App`})
|
|
49
111
|
|
|
50
112
|
if (IS_BROWSER) {
|
|
51
113
|
${customBootstrap ? `customBootstrap(AppWrapper);` : `bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM);`}
|
|
@@ -53,20 +115,19 @@ const renderFunction = ({
|
|
|
53
115
|
|
|
54
116
|
return AppWrapper
|
|
55
117
|
`;
|
|
56
|
-
|
|
57
|
-
const html = partials => `
|
|
118
|
+
const html = (partials) => `
|
|
58
119
|
<!DOCTYPE html>
|
|
59
120
|
<html>
|
|
60
121
|
<head>
|
|
61
122
|
<%= meta %>
|
|
62
123
|
<title><%= title %></title>
|
|
63
124
|
|
|
64
|
-
${partials.top.join(
|
|
125
|
+
${partials.top.join("\n")}
|
|
65
126
|
|
|
66
127
|
<script>
|
|
67
128
|
window.__assetPrefix__ = '<%= assetPrefix %>';
|
|
68
|
-
|
|
69
|
-
${partials.head.join(
|
|
129
|
+
<\/script>
|
|
130
|
+
${partials.head.join("\n")}
|
|
70
131
|
|
|
71
132
|
<!--<?- chunksMap.css ?>-->
|
|
72
133
|
</head>
|
|
@@ -76,7 +137,7 @@ const html = partials => `
|
|
|
76
137
|
We're sorry but react app doesn't work properly without JavaScript enabled. Please enable it to continue.
|
|
77
138
|
</noscript>
|
|
78
139
|
<div id="<%= mountId %>"><!--<?- html ?>--></div>
|
|
79
|
-
${partials.body.join(
|
|
140
|
+
${partials.body.join("\n")}
|
|
80
141
|
<!--<?- chunksMap.js ?>-->
|
|
81
142
|
<!--<?- SSRDataScript ?>-->
|
|
82
143
|
<!--<?- bottomTemplate ?>-->
|
|
@@ -84,30 +145,32 @@ const html = partials => `
|
|
|
84
145
|
|
|
85
146
|
</html>
|
|
86
147
|
`;
|
|
87
|
-
exports.html = html;
|
|
88
148
|
const routesForServer = ({
|
|
89
149
|
routes,
|
|
90
|
-
|
|
150
|
+
internalDirectory,
|
|
151
|
+
entryName
|
|
91
152
|
}) => {
|
|
92
|
-
const {
|
|
93
|
-
name,
|
|
94
|
-
basename
|
|
95
|
-
} = alias;
|
|
96
153
|
const loaders = [];
|
|
97
|
-
const
|
|
154
|
+
const loaderIndexFile = import_path.default.join(
|
|
155
|
+
internalDirectory,
|
|
156
|
+
entryName,
|
|
157
|
+
import_constants.TEMP_LOADERS_DIR,
|
|
158
|
+
"index.js"
|
|
159
|
+
);
|
|
160
|
+
const traverseRouteTree = (route) => {
|
|
161
|
+
var _a;
|
|
98
162
|
let children;
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
children = route === null || route === void 0 ? void 0 : (_route$children = route.children) === null || _route$children === void 0 ? void 0 : _route$children.map(traverseRouteTree);
|
|
163
|
+
if ("children" in route && route.children) {
|
|
164
|
+
children = (_a = route == null ? void 0 : route.children) == null ? void 0 : _a.map(traverseRouteTree);
|
|
102
165
|
}
|
|
103
166
|
let loader;
|
|
104
|
-
if (route.type ===
|
|
167
|
+
if (route.type === "nested") {
|
|
105
168
|
if (route.loader) {
|
|
106
169
|
loaders.push(route.loader);
|
|
107
170
|
loader = `loader_${loaders.length - 1}`;
|
|
108
171
|
}
|
|
109
172
|
}
|
|
110
|
-
const finalRoute =
|
|
173
|
+
const finalRoute = __spreadProps(__spreadValues({}, route), {
|
|
111
174
|
loader,
|
|
112
175
|
children
|
|
113
176
|
});
|
|
@@ -117,58 +180,82 @@ const routesForServer = ({
|
|
|
117
180
|
export const routes = [
|
|
118
181
|
`;
|
|
119
182
|
for (const route of routes) {
|
|
120
|
-
if (
|
|
183
|
+
if ("type" in route) {
|
|
121
184
|
const newRoute = traverseRouteTree(route);
|
|
122
|
-
routesCode += `${JSON.stringify(newRoute, null, 2).replace(
|
|
185
|
+
routesCode += `${JSON.stringify(newRoute, null, 2).replace(
|
|
186
|
+
/"(loader_[^"])"/g,
|
|
187
|
+
"$1"
|
|
188
|
+
)},`;
|
|
123
189
|
} else {
|
|
124
190
|
routesCode += `${JSON.stringify(route, null, 2)}`;
|
|
125
191
|
}
|
|
126
192
|
}
|
|
127
|
-
routesCode +=
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
193
|
+
routesCode += `
|
|
194
|
+
];`;
|
|
195
|
+
let importLoadersCode = "";
|
|
196
|
+
if (loaders.length > 0) {
|
|
197
|
+
importLoadersCode = `
|
|
198
|
+
import { ${loaders.map(
|
|
199
|
+
(loader, index2) => `loader_${index2}`
|
|
200
|
+
)} } from "${(0, import_utils.slash)(loaderIndexFile)}"`;
|
|
201
|
+
}
|
|
132
202
|
return `
|
|
133
203
|
${importLoadersCode}
|
|
134
204
|
${routesCode}
|
|
135
205
|
`;
|
|
136
206
|
};
|
|
137
|
-
|
|
138
|
-
const fileSystemRoutes = ({
|
|
207
|
+
const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
|
|
139
208
|
routes,
|
|
140
209
|
ssrMode,
|
|
141
210
|
nestedRoutesEntry,
|
|
142
|
-
entryName
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
211
|
+
entryName,
|
|
212
|
+
internalDirectory,
|
|
213
|
+
internalDirAlias
|
|
214
|
+
}) {
|
|
215
|
+
const loadings = [];
|
|
216
|
+
const errors = [];
|
|
217
|
+
const loaders = [];
|
|
218
|
+
const loadersMap = {};
|
|
219
|
+
const loadersIndexFile = import_path.default.join(
|
|
220
|
+
internalDirAlias,
|
|
221
|
+
entryName,
|
|
222
|
+
import_constants.TEMP_LOADERS_DIR,
|
|
223
|
+
"index.js"
|
|
224
|
+
);
|
|
225
|
+
const loadersMapFile = import_path.default.join(
|
|
226
|
+
internalDirectory,
|
|
227
|
+
entryName,
|
|
228
|
+
import_constants.TEMP_LOADERS_DIR,
|
|
229
|
+
"map.json"
|
|
230
|
+
);
|
|
147
231
|
const importLazyCode = `
|
|
148
232
|
import { lazy } from "react";
|
|
149
233
|
import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
|
|
150
234
|
`;
|
|
151
|
-
let
|
|
235
|
+
let rootLayoutCode = ``;
|
|
236
|
+
let dataLoaderPath = "";
|
|
237
|
+
let componentLoaderPath = "";
|
|
152
238
|
if (ssrMode) {
|
|
153
|
-
dataLoaderPath = require.resolve(
|
|
239
|
+
dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
|
|
154
240
|
if (nestedRoutesEntry) {
|
|
155
|
-
dataLoaderPath = `${dataLoaderPath}?routesDir=${nestedRoutesEntry}&
|
|
241
|
+
dataLoaderPath = `${dataLoaderPath}?routesDir=${nestedRoutesEntry}&mapFile=${loadersMapFile}!`;
|
|
156
242
|
}
|
|
243
|
+
componentLoaderPath = `${import_path.default.join(
|
|
244
|
+
__dirname,
|
|
245
|
+
"../builder/loaders/routerLoader"
|
|
246
|
+
)}!`;
|
|
157
247
|
}
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
const loaders = [];
|
|
161
|
-
const traverseRouteTree = route => {
|
|
248
|
+
const traverseRouteTree = (route) => {
|
|
249
|
+
var _a;
|
|
162
250
|
let children;
|
|
163
|
-
if (
|
|
164
|
-
|
|
165
|
-
children = route === null || route === void 0 ? void 0 : (_route$children2 = route.children) === null || _route$children2 === void 0 ? void 0 : _route$children2.map(traverseRouteTree);
|
|
251
|
+
if ("children" in route && route.children) {
|
|
252
|
+
children = (_a = route == null ? void 0 : route.children) == null ? void 0 : _a.map(traverseRouteTree);
|
|
166
253
|
}
|
|
167
254
|
let loading;
|
|
168
255
|
let error;
|
|
169
256
|
let loader;
|
|
170
|
-
let component =
|
|
171
|
-
if (route.type ===
|
|
257
|
+
let component = "";
|
|
258
|
+
if (route.type === "nested") {
|
|
172
259
|
if (route.loading) {
|
|
173
260
|
loadings.push(route.loading);
|
|
174
261
|
loading = `loading_${loadings.length - 1}`;
|
|
@@ -179,19 +266,24 @@ const fileSystemRoutes = ({
|
|
|
179
266
|
}
|
|
180
267
|
if (route.loader) {
|
|
181
268
|
loaders.push(route.loader);
|
|
182
|
-
|
|
269
|
+
const loaderId = loaders.length - 1;
|
|
270
|
+
loader = `loader_${loaderId}`;
|
|
271
|
+
loadersMap[loader] = route.id;
|
|
183
272
|
}
|
|
184
273
|
if (route._component) {
|
|
185
|
-
if (
|
|
186
|
-
|
|
274
|
+
if (route.isRoot) {
|
|
275
|
+
rootLayoutCode = `import RootLayout from '${route._component}'`;
|
|
276
|
+
component = `RootLayout`;
|
|
277
|
+
} else if (ssrMode === "string") {
|
|
278
|
+
component = `loadable(() => import(/* webpackChunkName: "${route.id}" */ '${componentLoaderPath}${route._component}'))`;
|
|
187
279
|
} else {
|
|
188
|
-
component = `
|
|
280
|
+
component = `lazy(() => import(/* webpackChunkName: "${route.id}" */ '${componentLoaderPath}${route._component}'))`;
|
|
189
281
|
}
|
|
190
282
|
}
|
|
191
283
|
} else if (route._component) {
|
|
192
284
|
component = `loadable(() => import('${route._component}'))`;
|
|
193
285
|
}
|
|
194
|
-
const finalRoute =
|
|
286
|
+
const finalRoute = __spreadProps(__spreadValues({}, route), {
|
|
195
287
|
loading,
|
|
196
288
|
loader,
|
|
197
289
|
error,
|
|
@@ -206,33 +298,69 @@ const fileSystemRoutes = ({
|
|
|
206
298
|
export const routes = [
|
|
207
299
|
`;
|
|
208
300
|
for (const route of routes) {
|
|
209
|
-
if (
|
|
301
|
+
if ("type" in route) {
|
|
210
302
|
const newRoute = traverseRouteTree(route);
|
|
211
|
-
routeComponentsCode += `${JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g,
|
|
303
|
+
routeComponentsCode += `${JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g, "$1").replace(/"(loadableLazy.*\))"/g, "$1").replace(/"(lazy.*\))"/g, "$1").replace(/"(loading_[^"])"/g, "$1").replace(/"(loader_[^"])"/g, "$1").replace(/"(RootLayout)"/g, "$1").replace(/"(error_[^"])"/g, "$1").replace(/\\"/g, '"')},`;
|
|
212
304
|
} else {
|
|
213
305
|
const component = `loadable(() => import('${route._component}'))`;
|
|
214
|
-
const finalRoute =
|
|
306
|
+
const finalRoute = __spreadProps(__spreadValues({}, route), {
|
|
215
307
|
component
|
|
216
308
|
});
|
|
217
|
-
routeComponentsCode += `${JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g,
|
|
309
|
+
routeComponentsCode += `${JSON.stringify(finalRoute, null, 2).replace(/"(loadable[^"]*)"/g, "$1").replace(/"(lazy[^"]*)"/g, "$1")},`;
|
|
218
310
|
}
|
|
219
311
|
}
|
|
220
|
-
routeComponentsCode +=
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
}).join(
|
|
312
|
+
routeComponentsCode += `
|
|
313
|
+
];`;
|
|
314
|
+
const importLoadingCode = loadings.map((loading, index2) => {
|
|
315
|
+
return `import loading_${index2} from '${loading}';
|
|
316
|
+
`;
|
|
317
|
+
}).join("");
|
|
318
|
+
const importErrorComponentsCode = errors.map((error, index2) => {
|
|
319
|
+
return `import error_${index2} from '${error}';
|
|
320
|
+
`;
|
|
321
|
+
}).join("");
|
|
322
|
+
let importLoadersCode = "";
|
|
323
|
+
if (loaders.length > 0) {
|
|
324
|
+
importLoadersCode = `
|
|
325
|
+
import { ${loaders.map(
|
|
326
|
+
(loader, index2) => `loader_${index2}`
|
|
327
|
+
)} } from "${(0, import_utils.slash)(dataLoaderPath)}${(0, import_utils.slash)(loadersIndexFile)}"
|
|
328
|
+
`;
|
|
329
|
+
const loaderEntryCode = loaders.map((loader, index2) => {
|
|
330
|
+
return `export * from './loader_${index2}.js';`;
|
|
331
|
+
}).join("\n");
|
|
332
|
+
const loaderEntryFile = import_path.default.join(
|
|
333
|
+
internalDirectory,
|
|
334
|
+
entryName,
|
|
335
|
+
import_constants.TEMP_LOADERS_DIR,
|
|
336
|
+
"entry.js"
|
|
337
|
+
);
|
|
338
|
+
yield import_utils.fs.ensureFile(loaderEntryFile);
|
|
339
|
+
yield import_utils.fs.writeFile(loaderEntryFile, loaderEntryCode);
|
|
340
|
+
yield import_utils.fs.writeJSON(loadersMapFile, loadersMap);
|
|
341
|
+
yield Promise.all(
|
|
342
|
+
loaders.map((loader, index2) => __async(void 0, null, function* () {
|
|
343
|
+
const name = `loader_${index2}`;
|
|
344
|
+
const filename = import_path.default.join(
|
|
345
|
+
internalDirectory,
|
|
346
|
+
entryName,
|
|
347
|
+
import_constants.TEMP_LOADERS_DIR,
|
|
348
|
+
`${name}.js`
|
|
349
|
+
);
|
|
350
|
+
const code = `
|
|
351
|
+
export { loader as ${name} } from '${(0, import_utils.slash)(loader)}'
|
|
352
|
+
`;
|
|
353
|
+
yield import_utils.fs.ensureFile(filename);
|
|
354
|
+
yield import_utils.fs.writeFile(filename, code);
|
|
355
|
+
}))
|
|
356
|
+
);
|
|
357
|
+
}
|
|
230
358
|
return `
|
|
231
359
|
${importLazyCode}
|
|
360
|
+
${rootLayoutCode}
|
|
232
361
|
${importLoadingCode}
|
|
233
362
|
${importErrorComponentsCode}
|
|
234
|
-
${
|
|
363
|
+
${importLoadersCode}
|
|
235
364
|
${routeComponentsCode}
|
|
236
365
|
`;
|
|
237
|
-
};
|
|
238
|
-
exports.fileSystemRoutes = fileSystemRoutes;
|
|
366
|
+
});
|
|
@@ -1,23 +1,70 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
21
|
+
mod
|
|
22
|
+
));
|
|
23
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
24
|
+
var stdin_exports = {};
|
|
25
|
+
__export(stdin_exports, {
|
|
26
|
+
getDefaultImports: () => getDefaultImports,
|
|
27
|
+
hasLoader: () => hasLoader,
|
|
28
|
+
isRouteComponentFile: () => isRouteComponentFile,
|
|
29
|
+
parseModule: () => parseModule,
|
|
30
|
+
replaceWithAlias: () => replaceWithAlias,
|
|
31
|
+
walkDirectory: () => walkDirectory
|
|
5
32
|
});
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var
|
|
9
|
-
var
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
33
|
+
module.exports = __toCommonJS(stdin_exports);
|
|
34
|
+
var import_fs = __toESM(require("fs"));
|
|
35
|
+
var import_path = __toESM(require("path"));
|
|
36
|
+
var import_utils = require("@modern-js/utils");
|
|
37
|
+
var import_esbuild = require("esbuild");
|
|
38
|
+
var import_es_module_lexer = require("es-module-lexer");
|
|
39
|
+
var import_constants = require("./constants");
|
|
40
|
+
var __async = (__this, __arguments, generator) => {
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
var fulfilled = (value) => {
|
|
43
|
+
try {
|
|
44
|
+
step(generator.next(value));
|
|
45
|
+
} catch (e) {
|
|
46
|
+
reject(e);
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
var rejected = (value) => {
|
|
50
|
+
try {
|
|
51
|
+
step(generator.throw(value));
|
|
52
|
+
} catch (e) {
|
|
53
|
+
reject(e);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
57
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
const walkDirectory = (dir) => import_fs.default.readdirSync(dir).reduce((previous, filename) => {
|
|
61
|
+
const filePath = import_path.default.join(dir, filename);
|
|
62
|
+
if (import_fs.default.statSync(filePath).isDirectory()) {
|
|
15
63
|
return [...previous, ...walkDirectory(filePath)];
|
|
16
64
|
} else {
|
|
17
65
|
return [...previous, filePath];
|
|
18
66
|
}
|
|
19
67
|
}, []);
|
|
20
|
-
exports.walkDirectory = walkDirectory;
|
|
21
68
|
const getDefaultImports = ({
|
|
22
69
|
entrypoint,
|
|
23
70
|
srcDirectory,
|
|
@@ -25,73 +72,87 @@ const getDefaultImports = ({
|
|
|
25
72
|
internalDirAlias,
|
|
26
73
|
internalDirectory
|
|
27
74
|
}) => {
|
|
28
|
-
const {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
}],
|
|
50
|
-
value: '@modern-js/runtime'
|
|
51
|
-
}, customBootstrap && {
|
|
52
|
-
specifiers: [{
|
|
53
|
-
local: 'customBootstrap'
|
|
54
|
-
}],
|
|
55
|
-
value: (0, _utils.normalizeToPosixPath)(customBootstrap.replace(srcDirectory, internalSrcAlias))
|
|
56
|
-
}].filter(Boolean);
|
|
75
|
+
const { entryName, fileSystemRoutes, customBootstrap, entry } = entrypoint;
|
|
76
|
+
const imports = [
|
|
77
|
+
{
|
|
78
|
+
specifiers: [{ local: "React" }],
|
|
79
|
+
value: "react"
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
specifiers: [{ local: "ReactDOM" }],
|
|
83
|
+
value: (0, import_utils.isReact18)(import_path.default.join(internalDirectory, "../../")) ? "react-dom/client" : "react-dom"
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
specifiers: [{ imported: "createApp" }, { imported: "bootstrap" }],
|
|
87
|
+
value: "@modern-js/runtime"
|
|
88
|
+
},
|
|
89
|
+
customBootstrap && {
|
|
90
|
+
specifiers: [{ local: "customBootstrap" }],
|
|
91
|
+
value: (0, import_utils.normalizeToPosixPath)(
|
|
92
|
+
customBootstrap.replace(srcDirectory, internalSrcAlias)
|
|
93
|
+
)
|
|
94
|
+
}
|
|
95
|
+
].filter(Boolean);
|
|
57
96
|
if (fileSystemRoutes) {
|
|
58
97
|
const route = {
|
|
59
|
-
specifiers: [{
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
98
|
+
specifiers: [{ imported: "routes" }],
|
|
99
|
+
value: (0, import_utils.normalizeToPosixPath)(
|
|
100
|
+
`${internalDirAlias}/${entryName}/${import_constants.FILE_SYSTEM_ROUTES_FILE_NAME.replace(
|
|
101
|
+
".js",
|
|
102
|
+
""
|
|
103
|
+
)}`
|
|
104
|
+
)
|
|
63
105
|
};
|
|
64
106
|
if (fileSystemRoutes.globalApp) {
|
|
65
107
|
imports.push({
|
|
66
|
-
specifiers: [{
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
108
|
+
specifiers: [{ local: "App" }],
|
|
109
|
+
value: (0, import_utils.normalizeToPosixPath)(
|
|
110
|
+
fileSystemRoutes.globalApp.replace(srcDirectory, internalSrcAlias)
|
|
111
|
+
)
|
|
70
112
|
});
|
|
71
113
|
} else {
|
|
72
|
-
route.initialize =
|
|
114
|
+
route.initialize = "const App = false;";
|
|
73
115
|
}
|
|
74
116
|
imports.push(route);
|
|
75
117
|
} else {
|
|
76
118
|
imports.push({
|
|
77
|
-
specifiers: [{
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
119
|
+
specifiers: [{ local: "App" }],
|
|
120
|
+
value: (0, import_utils.normalizeToPosixPath)(
|
|
121
|
+
entry.replace(srcDirectory, internalSrcAlias)
|
|
122
|
+
)
|
|
81
123
|
});
|
|
82
124
|
}
|
|
83
125
|
return imports;
|
|
84
126
|
};
|
|
85
|
-
|
|
86
|
-
const isRouteComponentFile = filePath => {
|
|
127
|
+
const isRouteComponentFile = (filePath) => {
|
|
87
128
|
if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
|
|
88
129
|
return false;
|
|
89
130
|
}
|
|
90
|
-
if ([
|
|
131
|
+
if ([".js", ".jsx", ".ts", ".tsx"].includes(import_path.default.extname(filePath))) {
|
|
91
132
|
return true;
|
|
92
133
|
}
|
|
93
134
|
return false;
|
|
94
135
|
};
|
|
95
|
-
|
|
96
|
-
const
|
|
97
|
-
|
|
136
|
+
const replaceWithAlias = (base, filePath, alias) => (0, import_utils.normalizeToPosixPath)(import_path.default.join(alias, import_path.default.relative(base, filePath)));
|
|
137
|
+
const parseModule = (_0) => __async(void 0, [_0], function* ({
|
|
138
|
+
source,
|
|
139
|
+
filename
|
|
140
|
+
}) {
|
|
141
|
+
let content = source;
|
|
142
|
+
if (filename.endsWith(".tsx") || filename.endsWith(".jsx")) {
|
|
143
|
+
const result = yield (0, import_esbuild.transform)(content, {
|
|
144
|
+
loader: import_path.default.extname(filename).slice(1),
|
|
145
|
+
format: "esm"
|
|
146
|
+
});
|
|
147
|
+
content = result.code;
|
|
148
|
+
}
|
|
149
|
+
return yield (0, import_es_module_lexer.parse)(content);
|
|
150
|
+
});
|
|
151
|
+
const hasLoader = (filename) => __async(void 0, null, function* () {
|
|
152
|
+
const source = yield import_utils.fs.readFile(filename);
|
|
153
|
+
const [, moduleExports] = yield parseModule({
|
|
154
|
+
source: source.toString(),
|
|
155
|
+
filename
|
|
156
|
+
});
|
|
157
|
+
return moduleExports.some((e) => e.n === import_constants.LOADER_EXPORT_NAME);
|
|
158
|
+
});
|