@modern-js/app-tools 2.53.0 → 2.53.1-alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/cjs/plugins/deploy/dependencies/index.js +5 -13
- 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/esm/plugins/deploy/dependencies/index.js +20 -28
- package/dist/esm/plugins/deploy/platforms/netlify.js +1 -1
- package/dist/esm/plugins/deploy/platforms/node.js +1 -1
- package/dist/esm/plugins/deploy/platforms/vercel.js +1 -1
- package/dist/esm-node/plugins/deploy/dependencies/index.js +6 -14
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +1 -1
- package/dist/esm-node/plugins/deploy/platforms/node.js +1 -1
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +1 -1
- package/dist/js/modern/analyze/constants.js +15 -0
- package/dist/js/modern/analyze/generateCode.js +179 -0
- package/dist/js/modern/analyze/getBundleEntry.js +75 -0
- package/dist/js/modern/analyze/getClientRoutes.js +219 -0
- package/dist/js/modern/analyze/getFileSystemEntry.js +74 -0
- package/dist/js/modern/analyze/getHtmlTemplate.js +82 -0
- package/dist/js/modern/analyze/getServerRoutes.js +192 -0
- package/dist/js/modern/analyze/index.js +148 -0
- package/dist/js/modern/analyze/isDefaultExportFunction.js +32 -0
- package/dist/js/modern/analyze/makeLegalIdentifier.js +16 -0
- package/dist/js/modern/analyze/templates.js +88 -0
- package/dist/js/modern/analyze/utils.js +92 -0
- package/dist/js/modern/commands/build.js +154 -0
- package/dist/js/modern/commands/deploy.js +5 -0
- package/dist/js/modern/commands/dev.js +95 -0
- package/dist/js/modern/commands/index.js +3 -0
- package/dist/js/modern/commands/inspect.js +69 -0
- package/dist/js/modern/commands/start.js +31 -0
- package/dist/js/modern/exports/server.js +1 -0
- package/dist/js/modern/hooks.js +21 -0
- package/dist/js/modern/index.js +109 -0
- package/dist/js/modern/locale/en.js +35 -0
- package/dist/js/modern/locale/index.js +9 -0
- package/dist/js/modern/locale/zh.js +35 -0
- package/dist/js/modern/utils/config.js +78 -0
- package/dist/js/modern/utils/createCompiler.js +61 -0
- package/dist/js/modern/utils/createServer.js +18 -0
- package/dist/js/modern/utils/getSpecifiedEntries.js +36 -0
- package/dist/js/modern/utils/language.js +5 -0
- package/dist/js/modern/utils/printInstructions.js +11 -0
- package/dist/js/modern/utils/routes.js +15 -0
- package/dist/js/modern/utils/types.js +0 -0
- package/dist/js/node/analyze/constants.js +36 -0
- package/dist/js/node/analyze/generateCode.js +208 -0
- package/dist/js/node/analyze/getBundleEntry.js +89 -0
- package/dist/js/node/analyze/getClientRoutes.js +241 -0
- package/dist/js/node/analyze/getFileSystemEntry.js +90 -0
- package/dist/js/node/analyze/getHtmlTemplate.js +106 -0
- package/dist/js/node/analyze/getServerRoutes.js +208 -0
- package/dist/js/node/analyze/index.js +178 -0
- package/dist/js/node/analyze/isDefaultExportFunction.js +50 -0
- package/dist/js/node/analyze/makeLegalIdentifier.js +24 -0
- package/dist/js/node/analyze/templates.js +106 -0
- package/dist/js/node/analyze/utils.js +113 -0
- package/dist/js/node/commands/build.js +174 -0
- package/dist/js/node/commands/deploy.js +14 -0
- package/dist/js/node/commands/dev.js +120 -0
- package/dist/js/node/commands/index.js +44 -0
- package/dist/js/node/commands/inspect.js +98 -0
- package/dist/js/node/commands/start.js +47 -0
- package/dist/js/node/exports/server.js +13 -0
- package/dist/js/node/hooks.js +39 -0
- package/dist/js/node/index.js +141 -0
- package/dist/js/node/locale/en.js +42 -0
- package/dist/js/node/locale/index.js +20 -0
- package/dist/js/node/locale/zh.js +42 -0
- package/dist/js/node/utils/config.js +103 -0
- package/dist/js/node/utils/createCompiler.js +81 -0
- package/dist/js/node/utils/createServer.js +35 -0
- package/dist/js/node/utils/getSpecifiedEntries.js +46 -0
- package/dist/js/node/utils/language.js +13 -0
- package/dist/js/node/utils/printInstructions.js +22 -0
- package/dist/js/node/utils/routes.js +25 -0
- package/dist/js/node/utils/types.js +0 -0
- package/dist/types/config/initialize/inits.d.ts +1 -1
- package/dist/types/plugins/deploy/dependencies/index.d.ts +2 -1
- package/package.json +5 -5
@@ -36,19 +36,9 @@ var import_utils = require("@modern-js/utils");
|
|
36
36
|
var import_pkg_types = require("pkg-types");
|
37
37
|
var import_mlly = require("mlly");
|
38
38
|
var import_utils2 = require("./utils");
|
39
|
-
const handleDependencies = async (appDir, serverRootDir,
|
39
|
+
const handleDependencies = async (appDir, serverRootDir, includeEntries, entryFilter, modifyPackageJson) => {
|
40
40
|
const base = "/";
|
41
41
|
const entryFiles = await (0, import_utils2.findEntryFiles)(serverRootDir, entryFilter);
|
42
|
-
const includeEntries = include.map((item) => {
|
43
|
-
if ((0, import_node_path.isAbsolute)(item)) {
|
44
|
-
return item;
|
45
|
-
}
|
46
|
-
try {
|
47
|
-
return require.resolve(item);
|
48
|
-
} catch (error) {
|
49
|
-
}
|
50
|
-
return item;
|
51
|
-
});
|
52
42
|
const fileTrace = await (0, import_utils2.traceFiles)(entryFiles.concat(includeEntries), serverRootDir, base);
|
53
43
|
const currentProjectModules = import_node_path.default.join(appDir, "node_modules");
|
54
44
|
const tracedFiles = Object.fromEntries(await Promise.all([
|
@@ -199,7 +189,7 @@ const handleDependencies = async (appDir, serverRootDir, include, entryFilter) =
|
|
199
189
|
}
|
200
190
|
}
|
201
191
|
const outputPkgPath = import_node_path.default.join(serverRootDir, "package.json");
|
202
|
-
|
192
|
+
const newPkgJson = {
|
203
193
|
name: `${projectPkgJson.name || "modernjs-project"}-prod`,
|
204
194
|
version: projectPkgJson.version || "0.0.0",
|
205
195
|
private: true,
|
@@ -209,7 +199,9 @@ const handleDependencies = async (appDir, serverRootDir, include, entryFilter) =
|
|
209
199
|
Object.keys(pkg.versions)[0]
|
210
200
|
])
|
211
201
|
].sort(([a], [b]) => a.localeCompare(b)))
|
212
|
-
}
|
202
|
+
};
|
203
|
+
const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
|
204
|
+
await import_utils.fs.writeJSON(outputPkgPath, finalPkgJson);
|
213
205
|
};
|
214
206
|
// Annotate the CommonJS export names for ESM import in node:
|
215
207
|
0 && (module.exports = {
|
@@ -125,7 +125,7 @@ const createNetlifyPreset = (appContext, modernConfig, needModernServer) => {
|
|
125
125
|
return;
|
126
126
|
}
|
127
127
|
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
128
|
-
"@modern-js/prod-server"
|
128
|
+
require.resolve("@modern-js/prod-server")
|
129
129
|
]);
|
130
130
|
}
|
131
131
|
};
|
@@ -79,7 +79,7 @@ const createNodePreset = (appContext, config) => {
|
|
79
79
|
return !filePath.startsWith(staticDirectory);
|
80
80
|
};
|
81
81
|
await (0, import_dependencies.handleDependencies)(appDirectory, outputDirectory, [
|
82
|
-
"@modern-js/prod-server"
|
82
|
+
require.resolve("@modern-js/prod-server")
|
83
83
|
], filter);
|
84
84
|
}
|
85
85
|
};
|
@@ -137,7 +137,7 @@ const createVercelPreset = (appContext, modernConfig, needModernServer) => {
|
|
137
137
|
return;
|
138
138
|
}
|
139
139
|
await (0, import_dependencies.handleDependencies)(appDirectory, funcsDirectory, [
|
140
|
-
"@modern-js/prod-server"
|
140
|
+
require.resolve("@modern-js/prod-server")
|
141
141
|
]);
|
142
142
|
}
|
143
143
|
};
|
@@ -3,14 +3,14 @@ import { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
|
|
3
3
|
import { _ as _to_consumable_array } from "@swc/helpers/_/_to_consumable_array";
|
4
4
|
import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
|
5
5
|
import { _ as _ts_values } from "@swc/helpers/_/_ts_values";
|
6
|
-
import path
|
6
|
+
import path from "node:path";
|
7
7
|
import { fs as fse, pkgUp, semver } from "@modern-js/utils";
|
8
8
|
import { readPackageJSON } from "pkg-types";
|
9
9
|
import { parseNodeModulePath } from "mlly";
|
10
10
|
import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles, findPackageParents, resolveTracedPath } from "./utils";
|
11
11
|
var handleDependencies = function() {
|
12
|
-
var _ref = _async_to_generator(function(appDir, serverRootDir,
|
13
|
-
var base, entryFiles,
|
12
|
+
var _ref = _async_to_generator(function(appDir, serverRootDir, includeEntries, entryFilter, modifyPackageJson) {
|
13
|
+
var base, entryFiles, fileTrace, currentProjectModules, tracedFiles, _, tracedPackages, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, tracedFile, pkgName, tracedPackage, pkgJSON, tracedPackageVersion, err, multiVersionPkgs, singleVersionPackages, _iteratorNormalCompletion1, _didIteratorError1, _iteratorError1, _iterator1, _step1, tracedPackage1, versions, _iteratorNormalCompletion2, _didIteratorError2, _iteratorError2, _iterator2, _step2, version, projectPkgJson, _iteratorNormalCompletion3, _didIteratorError3, _iteratorError3, _loop, _iterator3, _step3, err, outputPkgPath, newPkgJson, finalPkgJson;
|
14
14
|
return _ts_generator(this, function(_state) {
|
15
15
|
switch (_state.label) {
|
16
16
|
case 0:
|
@@ -21,16 +21,6 @@ var handleDependencies = function() {
|
|
21
21
|
];
|
22
22
|
case 1:
|
23
23
|
entryFiles = _state.sent();
|
24
|
-
includeEntries = include.map(function(item) {
|
25
|
-
if (isAbsolute(item)) {
|
26
|
-
return item;
|
27
|
-
}
|
28
|
-
try {
|
29
|
-
return require.resolve(item);
|
30
|
-
} catch (error) {
|
31
|
-
}
|
32
|
-
return item;
|
33
|
-
});
|
34
24
|
return [
|
35
25
|
4,
|
36
26
|
traceFiles(entryFiles.concat(includeEntries), serverRootDir, base)
|
@@ -546,22 +536,24 @@ var handleDependencies = function() {
|
|
546
536
|
];
|
547
537
|
case 21:
|
548
538
|
outputPkgPath = path.join(serverRootDir, "package.json");
|
539
|
+
newPkgJson = {
|
540
|
+
name: "".concat(projectPkgJson.name || "modernjs-project", "-prod"),
|
541
|
+
version: projectPkgJson.version || "0.0.0",
|
542
|
+
private: true,
|
543
|
+
dependencies: Object.fromEntries(_to_consumable_array(Object.values(tracedPackages).map(function(pkg) {
|
544
|
+
return [
|
545
|
+
pkg.name,
|
546
|
+
Object.keys(pkg.versions)[0]
|
547
|
+
];
|
548
|
+
})).sort(function(param, param1) {
|
549
|
+
var _param = _sliced_to_array(param, 1), a = _param[0], _param1 = _sliced_to_array(param1, 1), b = _param1[0];
|
550
|
+
return a.localeCompare(b);
|
551
|
+
}))
|
552
|
+
};
|
553
|
+
finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
|
549
554
|
return [
|
550
555
|
4,
|
551
|
-
fse.writeJSON(outputPkgPath,
|
552
|
-
name: "".concat(projectPkgJson.name || "modernjs-project", "-prod"),
|
553
|
-
version: projectPkgJson.version || "0.0.0",
|
554
|
-
private: true,
|
555
|
-
dependencies: Object.fromEntries(_to_consumable_array(Object.values(tracedPackages).map(function(pkg) {
|
556
|
-
return [
|
557
|
-
pkg.name,
|
558
|
-
Object.keys(pkg.versions)[0]
|
559
|
-
];
|
560
|
-
})).sort(function(param, param1) {
|
561
|
-
var _param = _sliced_to_array(param, 1), a = _param[0], _param1 = _sliced_to_array(param1, 1), b = _param1[0];
|
562
|
-
return a.localeCompare(b);
|
563
|
-
}))
|
564
|
-
})
|
556
|
+
fse.writeJSON(outputPkgPath, finalPkgJson)
|
565
557
|
];
|
566
558
|
case 22:
|
567
559
|
_state.sent();
|
@@ -571,7 +563,7 @@ var handleDependencies = function() {
|
|
571
563
|
}
|
572
564
|
});
|
573
565
|
});
|
574
|
-
return function handleDependencies2(appDir, serverRootDir,
|
566
|
+
return function handleDependencies2(appDir, serverRootDir, includeEntries, entryFilter, modifyPackageJson) {
|
575
567
|
return _ref.apply(this, arguments);
|
576
568
|
};
|
577
569
|
}();
|
@@ -272,7 +272,7 @@ var createNetlifyPreset = function(appContext, modernConfig, needModernServer) {
|
|
272
272
|
return [
|
273
273
|
4,
|
274
274
|
handleDependencies(appDirectory, funcsDirectory, [
|
275
|
-
"@modern-js/prod-server"
|
275
|
+
require.resolve("@modern-js/prod-server")
|
276
276
|
])
|
277
277
|
];
|
278
278
|
case 3:
|
@@ -206,7 +206,7 @@ var createVercelPreset = function(appContext, modernConfig, needModernServer) {
|
|
206
206
|
return [
|
207
207
|
4,
|
208
208
|
handleDependencies(appDirectory, funcsDirectory, [
|
209
|
-
"@modern-js/prod-server"
|
209
|
+
require.resolve("@modern-js/prod-server")
|
210
210
|
])
|
211
211
|
];
|
212
212
|
case 1:
|
@@ -1,21 +1,11 @@
|
|
1
|
-
import path
|
1
|
+
import path from "node:path";
|
2
2
|
import { fs as fse, pkgUp, semver } from "@modern-js/utils";
|
3
3
|
import { readPackageJSON } from "pkg-types";
|
4
4
|
import { parseNodeModulePath } from "mlly";
|
5
5
|
import { linkPackage, writePackage, isFile, findEntryFiles, traceFiles, findPackageParents, resolveTracedPath } from "./utils";
|
6
|
-
const handleDependencies = async (appDir, serverRootDir,
|
6
|
+
const handleDependencies = async (appDir, serverRootDir, includeEntries, entryFilter, modifyPackageJson) => {
|
7
7
|
const base = "/";
|
8
8
|
const entryFiles = await findEntryFiles(serverRootDir, entryFilter);
|
9
|
-
const includeEntries = include.map((item) => {
|
10
|
-
if (isAbsolute(item)) {
|
11
|
-
return item;
|
12
|
-
}
|
13
|
-
try {
|
14
|
-
return require.resolve(item);
|
15
|
-
} catch (error) {
|
16
|
-
}
|
17
|
-
return item;
|
18
|
-
});
|
19
9
|
const fileTrace = await traceFiles(entryFiles.concat(includeEntries), serverRootDir, base);
|
20
10
|
const currentProjectModules = path.join(appDir, "node_modules");
|
21
11
|
const tracedFiles = Object.fromEntries(await Promise.all([
|
@@ -166,7 +156,7 @@ const handleDependencies = async (appDir, serverRootDir, include, entryFilter) =
|
|
166
156
|
}
|
167
157
|
}
|
168
158
|
const outputPkgPath = path.join(serverRootDir, "package.json");
|
169
|
-
|
159
|
+
const newPkgJson = {
|
170
160
|
name: `${projectPkgJson.name || "modernjs-project"}-prod`,
|
171
161
|
version: projectPkgJson.version || "0.0.0",
|
172
162
|
private: true,
|
@@ -176,7 +166,9 @@ const handleDependencies = async (appDir, serverRootDir, include, entryFilter) =
|
|
176
166
|
Object.keys(pkg.versions)[0]
|
177
167
|
])
|
178
168
|
].sort(([a], [b]) => a.localeCompare(b)))
|
179
|
-
}
|
169
|
+
};
|
170
|
+
const finalPkgJson = (modifyPackageJson === null || modifyPackageJson === void 0 ? void 0 : modifyPackageJson(newPkgJson)) || newPkgJson;
|
171
|
+
await fse.writeJSON(outputPkgPath, finalPkgJson);
|
180
172
|
};
|
181
173
|
export {
|
182
174
|
handleDependencies
|
@@ -46,7 +46,7 @@ const createNodePreset = (appContext, config) => {
|
|
46
46
|
return !filePath.startsWith(staticDirectory);
|
47
47
|
};
|
48
48
|
await handleDependencies(appDirectory, outputDirectory, [
|
49
|
-
"@modern-js/prod-server"
|
49
|
+
require.resolve("@modern-js/prod-server")
|
50
50
|
], filter);
|
51
51
|
}
|
52
52
|
};
|
@@ -0,0 +1,15 @@
|
|
1
|
+
export const JS_EXTENSIONS = ['.js', '.ts', '.jsx', '.tsx'];
|
2
|
+
export const INDEX_FILE_NAME = 'index';
|
3
|
+
export const APP_FILE_NAME = 'App';
|
4
|
+
export const PAGES_DIR_NAME = 'pages';
|
5
|
+
export const FILE_SYSTEM_ROUTES_FILE_NAME = 'routes.js';
|
6
|
+
export const ENTRY_POINT_FILE_NAME = 'index.js';
|
7
|
+
export const ENTRY_BOOTSTRAP_FILE_NAME = 'bootstrap.js';
|
8
|
+
export const FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP = /^\[(\S+)\]([*+?]?)$/;
|
9
|
+
export const FILE_SYSTEM_ROUTES_LAYOUT = '_layout';
|
10
|
+
export const FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT = '_app';
|
11
|
+
export const FILE_SYSTEM_ROUTES_INDEX = 'index';
|
12
|
+
export const FILE_SYSTEM_ROUTES_IGNORED_REGEX = /\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/;
|
13
|
+
export const HTML_PARTIALS_FOLDER = 'html';
|
14
|
+
export const HTML_PARTIALS_EXTENSIONS = ['.htm', '.html', '.ejs'];
|
15
|
+
export const FILE_SYSTEM_ROUTES_COMPONENTS_DIR = 'internal_components';
|
@@ -0,0 +1,179 @@
|
|
1
|
+
import path from 'path';
|
2
|
+
import { fs } from '@modern-js/utils';
|
3
|
+
import * as templates from "./templates";
|
4
|
+
import { getClientRoutes } from "./getClientRoutes";
|
5
|
+
import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
|
6
|
+
import { getDefaultImports } from "./utils";
|
7
|
+
|
8
|
+
const createImportSpecifier = specifiers => {
|
9
|
+
let defaults = '';
|
10
|
+
const named = [];
|
11
|
+
|
12
|
+
for (const {
|
13
|
+
local,
|
14
|
+
imported
|
15
|
+
} of specifiers) {
|
16
|
+
if (local && imported) {
|
17
|
+
named.push(`${imported} as ${local}`);
|
18
|
+
} else if (local) {
|
19
|
+
defaults = local;
|
20
|
+
} else {
|
21
|
+
named.push(imported);
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
if (defaults && named.length) {
|
26
|
+
return `${defaults}, { ${named.join(', ')} }`;
|
27
|
+
} else if (defaults) {
|
28
|
+
return defaults;
|
29
|
+
} else {
|
30
|
+
return `{ ${named.join(', ')} }`;
|
31
|
+
}
|
32
|
+
};
|
33
|
+
|
34
|
+
export const createImportStatements = statements => {
|
35
|
+
// merge import statements with the same value.
|
36
|
+
const deDuplicated = [];
|
37
|
+
const seen = new Map();
|
38
|
+
|
39
|
+
for (const {
|
40
|
+
value,
|
41
|
+
specifiers,
|
42
|
+
initialize
|
43
|
+
} of statements) {
|
44
|
+
if (!seen.has(value)) {
|
45
|
+
deDuplicated.push({
|
46
|
+
value,
|
47
|
+
specifiers,
|
48
|
+
initialize
|
49
|
+
});
|
50
|
+
seen.set(value, specifiers);
|
51
|
+
} else {
|
52
|
+
var _deDuplicated$modifyI, _deDuplicated$modifyI2;
|
53
|
+
|
54
|
+
seen.get(value).push(...specifiers); // make "initialize" param can be connected when multiple plugins were imported from same package
|
55
|
+
|
56
|
+
const modifyIndex = deDuplicated.findIndex(v => v.value === value);
|
57
|
+
const originInitialize = (_deDuplicated$modifyI = (_deDuplicated$modifyI2 = deDuplicated[modifyIndex]) === null || _deDuplicated$modifyI2 === void 0 ? void 0 : _deDuplicated$modifyI2.initialize) !== null && _deDuplicated$modifyI !== void 0 ? _deDuplicated$modifyI : '';
|
58
|
+
deDuplicated[modifyIndex].initialize = originInitialize.concat(`\n${initialize || ''}`);
|
59
|
+
}
|
60
|
+
}
|
61
|
+
|
62
|
+
return deDuplicated.map(({
|
63
|
+
value,
|
64
|
+
specifiers,
|
65
|
+
initialize
|
66
|
+
}) => `import ${createImportSpecifier(specifiers)} from '${value}';\n${initialize || ''}`).join('\n');
|
67
|
+
};
|
68
|
+
export const generateCode = async (appContext, config, entrypoints, api) => {
|
69
|
+
const {
|
70
|
+
internalDirectory,
|
71
|
+
srcDirectory,
|
72
|
+
internalDirAlias,
|
73
|
+
internalSrcAlias
|
74
|
+
} = appContext;
|
75
|
+
const hookRunners = api.useHookRunners();
|
76
|
+
const {
|
77
|
+
output: {
|
78
|
+
mountId
|
79
|
+
}
|
80
|
+
} = config;
|
81
|
+
|
82
|
+
for (const entrypoint of entrypoints) {
|
83
|
+
const {
|
84
|
+
entryName,
|
85
|
+
isAutoMount,
|
86
|
+
customBootstrap,
|
87
|
+
fileSystemRoutes
|
88
|
+
} = entrypoint;
|
89
|
+
|
90
|
+
if (isAutoMount) {
|
91
|
+
// generate routes file for file system routes entrypoint.
|
92
|
+
if (fileSystemRoutes) {
|
93
|
+
const initialRoutes = getClientRoutes({
|
94
|
+
entrypoint,
|
95
|
+
srcDirectory,
|
96
|
+
srcAlias: internalSrcAlias,
|
97
|
+
internalDirectory,
|
98
|
+
internalDirAlias
|
99
|
+
});
|
100
|
+
const {
|
101
|
+
routes
|
102
|
+
} = await hookRunners.modifyFileSystemRoutes({
|
103
|
+
entrypoint,
|
104
|
+
routes: initialRoutes
|
105
|
+
});
|
106
|
+
const {
|
107
|
+
code
|
108
|
+
} = await hookRunners.beforeGenerateRoutes({
|
109
|
+
entrypoint,
|
110
|
+
code: templates.fileSystemRoutes({
|
111
|
+
routes
|
112
|
+
})
|
113
|
+
});
|
114
|
+
fs.outputFileSync(path.resolve(internalDirectory, `./${entryName}/${FILE_SYSTEM_ROUTES_FILE_NAME}`), code, 'utf8');
|
115
|
+
} // call modifyEntryImports hook
|
116
|
+
|
117
|
+
|
118
|
+
const {
|
119
|
+
imports: importStatements
|
120
|
+
} = await hookRunners.modifyEntryImports({
|
121
|
+
entrypoint,
|
122
|
+
imports: getDefaultImports({
|
123
|
+
entrypoint,
|
124
|
+
srcDirectory,
|
125
|
+
internalSrcAlias,
|
126
|
+
internalDirAlias,
|
127
|
+
internalDirectory
|
128
|
+
})
|
129
|
+
}); // call modifyEntryRuntimePlugins hook
|
130
|
+
|
131
|
+
const {
|
132
|
+
plugins
|
133
|
+
} = await hookRunners.modifyEntryRuntimePlugins({
|
134
|
+
entrypoint,
|
135
|
+
plugins: []
|
136
|
+
}); // call modifyEntryRenderFunction hook
|
137
|
+
|
138
|
+
const {
|
139
|
+
code: renderFunction
|
140
|
+
} = await hookRunners.modifyEntryRenderFunction({
|
141
|
+
entrypoint,
|
142
|
+
code: templates.renderFunction({
|
143
|
+
plugins,
|
144
|
+
customBootstrap,
|
145
|
+
fileSystemRoutes
|
146
|
+
})
|
147
|
+
}); // call modifyEntryExport hook
|
148
|
+
|
149
|
+
const {
|
150
|
+
exportStatement
|
151
|
+
} = await hookRunners.modifyEntryExport({
|
152
|
+
entrypoint,
|
153
|
+
exportStatement: 'export default AppWrapper;'
|
154
|
+
});
|
155
|
+
const code = templates.index({
|
156
|
+
mountId: mountId,
|
157
|
+
imports: createImportStatements(importStatements),
|
158
|
+
renderFunction,
|
159
|
+
exportStatement
|
160
|
+
});
|
161
|
+
const entryFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_POINT_FILE_NAME}`);
|
162
|
+
entrypoint.entry = entryFile; // generate entry file.
|
163
|
+
|
164
|
+
if (config.source.enableAsyncEntry) {
|
165
|
+
const {
|
166
|
+
code: asyncEntryCode
|
167
|
+
} = await hookRunners.modifyAsyncEntry({
|
168
|
+
entrypoint,
|
169
|
+
code: `import('./${ENTRY_BOOTSTRAP_FILE_NAME}');`
|
170
|
+
});
|
171
|
+
fs.outputFileSync(entryFile, asyncEntryCode, 'utf8');
|
172
|
+
const bootstrapFile = path.resolve(internalDirectory, `./${entryName}/${ENTRY_BOOTSTRAP_FILE_NAME}`);
|
173
|
+
fs.outputFileSync(bootstrapFile, code, 'utf8');
|
174
|
+
} else {
|
175
|
+
fs.outputFileSync(entryFile, code, 'utf8');
|
176
|
+
}
|
177
|
+
}
|
178
|
+
}
|
179
|
+
};
|
@@ -0,0 +1,75 @@
|
|
1
|
+
import path from 'path';
|
2
|
+
import { ensureAbsolutePath, fs, findExists, MAIN_ENTRY_NAME } from '@modern-js/utils';
|
3
|
+
import { getFileSystemEntry } from "./getFileSystemEntry";
|
4
|
+
import { JS_EXTENSIONS } from "./constants";
|
5
|
+
|
6
|
+
const ensureExtensions = file => {
|
7
|
+
if (!path.extname(file)) {
|
8
|
+
return findExists(JS_EXTENSIONS.map(ext => `${file}${ext}`)) || file;
|
9
|
+
}
|
10
|
+
|
11
|
+
return file;
|
12
|
+
};
|
13
|
+
|
14
|
+
const ifAlreadyExists = (entrypoints, checked) => entrypoints.some(entrypoint => {
|
15
|
+
if (ensureExtensions(entrypoint.entry) === ensureExtensions(checked.entry)) {
|
16
|
+
// reset entryName
|
17
|
+
checked.entryName = entrypoint.entryName;
|
18
|
+
return true;
|
19
|
+
} // filesystem routes entrypoint conflict with normal entrypoint.
|
20
|
+
|
21
|
+
|
22
|
+
if (entrypoint.entry.startsWith(checked.entry) || checked.entry.startsWith(entrypoint.entry)) {
|
23
|
+
throw new Error(`Entry configuration conflicts\n Your configuration: ${checked.entry}.\n Default entrypoint: ${entrypoint.entry}\n Please reset source.entries or set source.disableDefaultEntries to disable the default entry rules.`);
|
24
|
+
}
|
25
|
+
|
26
|
+
return false;
|
27
|
+
});
|
28
|
+
|
29
|
+
export const getBundleEntry = (appContext, config) => {
|
30
|
+
const {
|
31
|
+
appDirectory,
|
32
|
+
packageName
|
33
|
+
} = appContext;
|
34
|
+
const {
|
35
|
+
source: {
|
36
|
+
disableDefaultEntries,
|
37
|
+
entries,
|
38
|
+
entriesDir
|
39
|
+
}
|
40
|
+
} = config;
|
41
|
+
const defaults = disableDefaultEntries ? [] : getFileSystemEntry(appContext, config); // merge entrypoints from user config with directory convention.
|
42
|
+
|
43
|
+
if (entries) {
|
44
|
+
Object.keys(entries).forEach(name => {
|
45
|
+
const value = entries[name];
|
46
|
+
const entrypoint = typeof value === 'string' ? {
|
47
|
+
entryName: name,
|
48
|
+
entry: ensureAbsolutePath(appDirectory, value),
|
49
|
+
isAutoMount: true,
|
50
|
+
fileSystemRoutes: fs.statSync(ensureAbsolutePath(appDirectory, value)).isDirectory() ? {} : undefined
|
51
|
+
} : {
|
52
|
+
entryName: name,
|
53
|
+
entry: ensureAbsolutePath(appDirectory, value.entry),
|
54
|
+
isAutoMount: !value.disableMount,
|
55
|
+
fileSystemRoutes: value.enableFileSystemRoutes ? {} : undefined
|
56
|
+
};
|
57
|
+
|
58
|
+
if (!ifAlreadyExists(defaults, entrypoint)) {
|
59
|
+
defaults.push(entrypoint);
|
60
|
+
}
|
61
|
+
});
|
62
|
+
}
|
63
|
+
|
64
|
+
if (!disableDefaultEntries) {
|
65
|
+
// find main entry point which server route is '/'.
|
66
|
+
const entriesDirAbs = ensureAbsolutePath(appDirectory, entriesDir);
|
67
|
+
const found = defaults.find(({
|
68
|
+
entryName,
|
69
|
+
entry
|
70
|
+
}) => entryName === packageName || path.dirname(entry) === entriesDirAbs);
|
71
|
+
found && (found.entryName = MAIN_ENTRY_NAME);
|
72
|
+
}
|
73
|
+
|
74
|
+
return defaults;
|
75
|
+
};
|