@modern-js/app-tools 2.0.0-beta.4 → 2.0.0-beta.6
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 +314 -0
- package/bin/modern.js +2 -0
- package/dist/js/modern/analyze/constants.js +10 -0
- package/dist/js/modern/analyze/generateCode.js +7 -9
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +9 -6
- package/dist/js/modern/analyze/getFileSystemEntry.js +11 -3
- package/dist/js/modern/analyze/index.js +7 -5
- package/dist/js/modern/analyze/nestedRoutes.js +29 -22
- package/dist/js/modern/analyze/templates.js +8 -1
- package/dist/js/modern/analyze/utils.js +19 -3
- package/dist/js/modern/builder/builderPlugins/compatModern.js +8 -2
- package/dist/js/modern/builder/index.js +1 -7
- package/dist/js/modern/commands/dev.js +6 -9
- package/dist/js/modern/commands/index.js +1 -1
- package/dist/js/modern/commands/{start.js → serve.js} +3 -1
- package/dist/js/modern/config/default.js +38 -61
- package/dist/js/modern/config/initial/createOutputConfig.js +1 -3
- package/dist/js/modern/config/initial/createSourceConfig.js +5 -1
- package/dist/js/modern/config/initial/transformNormalizedConfig.js +5 -1
- package/dist/js/modern/hooks.js +1 -0
- package/dist/js/modern/index.js +5 -5
- package/dist/js/modern/initialize/index.js +5 -4
- package/dist/js/modern/locale/en.js +1 -1
- package/dist/js/modern/locale/zh.js +1 -1
- package/dist/js/modern/schema/index.js +3 -1
- package/dist/js/modern/utils/commands.js +6 -1
- package/dist/js/modern/utils/getServerInternalPlugins.js +58 -0
- package/dist/js/node/analyze/Builder.js +14 -8
- package/dist/js/node/analyze/constants.js +35 -3
- package/dist/js/node/analyze/generateCode.js +27 -24
- package/dist/js/node/analyze/getBundleEntry.js +7 -3
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +33 -28
- package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +24 -22
- package/dist/js/node/analyze/getClientRoutes/index.js +8 -3
- package/dist/js/node/analyze/getClientRoutes/utils.js +10 -3
- package/dist/js/node/analyze/getFileSystemEntry.js +18 -6
- package/dist/js/node/analyze/getHtmlTemplate.js +18 -14
- package/dist/js/node/analyze/getServerRoutes.js +36 -34
- package/dist/js/node/analyze/index.js +45 -59
- package/dist/js/node/analyze/isDefaultExportFunction.js +7 -3
- package/dist/js/node/analyze/makeLegalIdentifier.js +7 -3
- package/dist/js/node/analyze/nestedRoutes.js +58 -49
- package/dist/js/node/analyze/templates.js +45 -32
- package/dist/js/node/analyze/utils.js +39 -17
- package/dist/js/node/builder/builderPlugins/compatModern.js +32 -24
- package/dist/js/node/builder/index.js +36 -48
- package/dist/js/node/builder/loaders/routerLoader.js +5 -3
- package/dist/js/node/builder/loaders/serverModuleLoader.js +5 -3
- package/dist/js/node/builder/share.js +7 -3
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +7 -3
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +7 -3
- package/dist/js/node/builder/webpackPlugins/routerPlugin.js +9 -7
- package/dist/js/node/commands/build.js +30 -28
- package/dist/js/node/commands/deploy.js +9 -5
- package/dist/js/node/commands/dev.js +39 -40
- package/dist/js/node/commands/index.js +5 -5
- package/dist/js/node/commands/inspect.js +10 -6
- package/dist/js/node/commands/{start.js → serve.js} +16 -10
- package/dist/js/node/config/default.js +44 -64
- package/dist/js/node/config/index.js +10 -3
- package/dist/js/node/config/initial/createHtmlConfig.js +7 -3
- package/dist/js/node/config/initial/createOutputConfig.js +8 -6
- package/dist/js/node/config/initial/createSourceConfig.js +12 -4
- package/dist/js/node/config/initial/createToolsConfig.js +7 -3
- package/dist/js/node/config/initial/index.js +9 -3
- package/dist/js/node/config/initial/inits.js +26 -22
- package/dist/js/node/config/initial/transformNormalizedConfig.js +12 -4
- package/dist/js/node/defineConfig.js +25 -22
- package/dist/js/node/exports/server.js +7 -3
- package/dist/js/node/hooks.js +8 -3
- package/dist/js/node/index.js +56 -69
- package/dist/js/node/initialize/index.js +33 -32
- package/dist/js/node/locale/en.js +8 -4
- package/dist/js/node/locale/index.js +8 -3
- package/dist/js/node/locale/zh.js +8 -4
- package/dist/js/node/schema/Schema.js +7 -3
- package/dist/js/node/schema/index.js +11 -4
- package/dist/js/node/schema/legacy.js +5 -3
- package/dist/js/node/types/config/deploy.js +15 -0
- package/dist/js/node/types/config/dev.js +15 -0
- package/dist/js/node/types/config/experiments.js +15 -0
- package/dist/js/node/types/config/html.js +15 -0
- package/dist/js/node/types/config/index.js +3 -3
- package/dist/js/node/types/config/output.js +15 -0
- package/dist/js/node/types/config/performance.js +15 -0
- package/dist/js/node/types/config/security.js +15 -0
- package/dist/js/node/types/config/source.js +15 -0
- package/dist/js/node/types/config/tools.js +15 -0
- package/dist/js/node/types/hooks.js +15 -0
- package/dist/js/node/types/index.js +5 -5
- package/dist/js/node/types/legacyConfig/deploy.js +15 -0
- package/dist/js/node/types/legacyConfig/dev.js +15 -0
- package/dist/js/node/types/legacyConfig/index.js +15 -0
- package/dist/js/node/types/legacyConfig/output.js +15 -0
- package/dist/js/node/types/legacyConfig/source.js +15 -0
- package/dist/js/node/types/legacyConfig/tools.js +15 -0
- package/dist/js/node/utils/commands.js +14 -4
- package/dist/js/node/utils/config.js +35 -30
- package/dist/js/node/utils/createFileWatcher.js +15 -10
- package/dist/js/node/utils/createServer.js +35 -29
- package/dist/js/node/utils/getServerInternalPlugins.js +79 -0
- package/dist/js/node/utils/getSpecifiedEntries.js +10 -6
- package/dist/js/node/utils/language.js +7 -3
- package/dist/js/node/utils/printInstructions.js +10 -6
- package/dist/js/node/utils/restart.js +11 -7
- package/dist/js/node/utils/routes.js +11 -7
- package/dist/js/node/utils/types.js +15 -0
- package/dist/js/treeshaking/analyze/constants.js +10 -1
- package/dist/js/treeshaking/analyze/generateCode.js +7 -11
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +9 -6
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +11 -3
- package/dist/js/treeshaking/analyze/index.js +7 -4
- package/dist/js/treeshaking/analyze/nestedRoutes.js +30 -23
- package/dist/js/treeshaking/analyze/templates.js +6 -1
- package/dist/js/treeshaking/analyze/utils.js +12 -3
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +6 -2
- package/dist/js/treeshaking/builder/index.js +1 -7
- package/dist/js/treeshaking/commands/dev.js +19 -24
- package/dist/js/treeshaking/commands/index.js +1 -1
- package/dist/js/treeshaking/commands/{start.js → serve.js} +10 -3
- package/dist/js/treeshaking/config/default.js +53 -56
- package/dist/js/treeshaking/config/initial/createOutputConfig.js +1 -3
- package/dist/js/treeshaking/config/initial/createSourceConfig.js +5 -1
- package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +5 -1
- package/dist/js/treeshaking/hooks.js +1 -0
- package/dist/js/treeshaking/index.js +5 -5
- package/dist/js/treeshaking/initialize/index.js +6 -5
- package/dist/js/treeshaking/locale/en.js +1 -1
- package/dist/js/treeshaking/locale/zh.js +1 -1
- package/dist/js/treeshaking/schema/index.js +7 -1
- package/dist/js/treeshaking/utils/commands.js +5 -1
- package/dist/js/treeshaking/utils/getServerInternalPlugins.js +210 -0
- package/dist/types/analyze/constants.d.ts +10 -1
- package/dist/types/analyze/utils.d.ts +2 -1
- package/dist/types/commands/index.d.ts +1 -1
- package/dist/types/commands/{start.d.ts → serve.d.ts} +0 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/locale/en.d.ts +1 -1
- package/dist/types/locale/index.d.ts +2 -2
- package/dist/types/locale/zh.d.ts +1 -1
- package/dist/types/types/config/index.d.ts +3 -0
- package/dist/types/types/config/source.d.ts +1 -0
- package/dist/types/types/hooks.d.ts +3 -0
- package/dist/types/utils/commands.d.ts +2 -1
- package/dist/types/utils/getServerInternalPlugins.d.ts +2 -0
- package/package.json +25 -22
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
14
|
+
var types_exports = {};
|
|
15
|
+
module.exports = __toCommonJS(types_exports);
|
|
@@ -25,4 +25,13 @@ var HTML_PARTIALS_EXTENSIONS = [
|
|
|
25
25
|
".ejs"
|
|
26
26
|
];
|
|
27
27
|
var FILE_SYSTEM_ROUTES_COMPONENTS_DIR = "internal_components";
|
|
28
|
-
|
|
28
|
+
var NESTED_ROUTE = {
|
|
29
|
+
LAYOUT_FILE: "layout",
|
|
30
|
+
LAYOUT_LOADER_FILE: "layout.loader",
|
|
31
|
+
PAGE_FILE: "page",
|
|
32
|
+
PAGE_LOADER_FILE: "page.loader",
|
|
33
|
+
LOADING_FILE: "loading",
|
|
34
|
+
ERROR_FILE: "error",
|
|
35
|
+
LOADER_FILE: "loader"
|
|
36
|
+
};
|
|
37
|
+
export { APP_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, ENTRY_POINT_FILE_NAME, FILE_SYSTEM_ROUTES_COMPONENTS_DIR, FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP, FILE_SYSTEM_ROUTES_FILE_NAME, FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT, FILE_SYSTEM_ROUTES_IGNORED_REGEX, FILE_SYSTEM_ROUTES_INDEX, FILE_SYSTEM_ROUTES_LAYOUT, HTML_PARTIALS_EXTENSIONS, HTML_PARTIALS_FOLDER, INDEX_FILE_NAME, JS_EXTENSIONS, LOADER_EXPORT_NAME, NESTED_ROUTE, NESTED_ROUTES_DIR, PAGES_DIR_NAME, TEMP_LOADERS_DIR };
|
|
@@ -150,7 +150,7 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
150
150
|
import path from "path";
|
|
151
151
|
import { fs, getEntryOptions, LOADER_ROUTES_DIR, logger } from "@modern-js/utils";
|
|
152
152
|
import { useResolvedConfigContext } from "@modern-js/core";
|
|
153
|
-
import {
|
|
153
|
+
import { isDevCommand } from "../utils/commands";
|
|
154
154
|
import * as templates from "./templates";
|
|
155
155
|
import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
|
|
156
156
|
import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, TEMP_LOADERS_DIR } from "./constants";
|
|
@@ -247,11 +247,9 @@ var createImportStatements = function(statements) {
|
|
|
247
247
|
};
|
|
248
248
|
var buildLoader = function() {
|
|
249
249
|
var _ref = _asyncToGenerator(function(entry, outfile) {
|
|
250
|
-
var command;
|
|
251
250
|
return __generator(this, function(_state) {
|
|
252
251
|
switch(_state.label){
|
|
253
252
|
case 0:
|
|
254
|
-
command = getCommand();
|
|
255
253
|
return [
|
|
256
254
|
4,
|
|
257
255
|
loaderBuilder.build({
|
|
@@ -259,7 +257,7 @@ var buildLoader = function() {
|
|
|
259
257
|
platform: "browser",
|
|
260
258
|
target: "esnext",
|
|
261
259
|
loader: loader,
|
|
262
|
-
watch:
|
|
260
|
+
watch: isDevCommand() && {},
|
|
263
261
|
bundle: true,
|
|
264
262
|
logLevel: "error",
|
|
265
263
|
entryPoints: [
|
|
@@ -301,11 +299,9 @@ var buildLoader = function() {
|
|
|
301
299
|
}();
|
|
302
300
|
var buildServerLoader = function() {
|
|
303
301
|
var _ref = _asyncToGenerator(function(entry, outfile) {
|
|
304
|
-
var command;
|
|
305
302
|
return __generator(this, function(_state) {
|
|
306
303
|
switch(_state.label){
|
|
307
304
|
case 0:
|
|
308
|
-
command = getCommand();
|
|
309
305
|
return [
|
|
310
306
|
4,
|
|
311
307
|
serverLoaderBuilder.build({
|
|
@@ -313,7 +309,7 @@ var buildServerLoader = function() {
|
|
|
313
309
|
platform: "node",
|
|
314
310
|
target: "esnext",
|
|
315
311
|
loader: loader,
|
|
316
|
-
watch:
|
|
312
|
+
watch: isDevCommand() && {},
|
|
317
313
|
bundle: true,
|
|
318
314
|
logLevel: "error",
|
|
319
315
|
entryPoints: [
|
|
@@ -336,7 +332,7 @@ var buildServerLoader = function() {
|
|
|
336
332
|
}();
|
|
337
333
|
var generateCode = function() {
|
|
338
334
|
var _ref = _asyncToGenerator(function(appContext, config, entrypoints, api) {
|
|
339
|
-
var ref, ref1, internalDirectory, distDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners,
|
|
335
|
+
var ref, ref1, ref2, internalDirectory, distDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, mountId, getRoutes;
|
|
340
336
|
function generateEntryCode(entrypoint) {
|
|
341
337
|
return _generateEntryCode.apply(this, arguments);
|
|
342
338
|
}
|
|
@@ -370,7 +366,7 @@ var generateCode = function() {
|
|
|
370
366
|
3,
|
|
371
367
|
3
|
|
372
368
|
];
|
|
373
|
-
if (!!
|
|
369
|
+
if (!!isV5) return [
|
|
374
370
|
3,
|
|
375
371
|
2
|
|
376
372
|
];
|
|
@@ -597,9 +593,9 @@ var generateCode = function() {
|
|
|
597
593
|
case 0:
|
|
598
594
|
internalDirectory = appContext.internalDirectory, distDirectory = appContext.distDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias, packageName = appContext.packageName;
|
|
599
595
|
hookRunners = api.useHookRunners();
|
|
600
|
-
|
|
596
|
+
isV5 = typeof ((ref = config.runtime) === null || ref === void 0 ? void 0 : ref.router) !== "boolean" && (config === null || config === void 0 ? void 0 : (ref1 = config.runtime) === null || ref1 === void 0 ? void 0 : (ref2 = ref1.router) === null || ref2 === void 0 ? void 0 : ref2.mode) === "react-router-5";
|
|
601
597
|
mountId = config.html.mountId;
|
|
602
|
-
getRoutes =
|
|
598
|
+
getRoutes = isV5 ? getClientRoutesLegacy : getClientRoutes;
|
|
603
599
|
return [
|
|
604
600
|
4,
|
|
605
601
|
Promise.all(entrypoints.map(generateEntryCode))
|
|
@@ -198,16 +198,19 @@ var normalizeNestedRoutes = function(nested, internalComponentsDir, internalDire
|
|
|
198
198
|
};
|
|
199
199
|
var getClientRoutes = function(param) {
|
|
200
200
|
var entrypoint = param.entrypoint, srcDirectory = param.srcDirectory, srcAlias = param.srcAlias, internalDirectory = param.internalDirectory, internalDirAlias = param.internalDirAlias;
|
|
201
|
-
var
|
|
202
|
-
if (!
|
|
203
|
-
|
|
201
|
+
var entryName = entrypoint.entryName, pageRoutesEntry = entrypoint.pageRoutesEntry;
|
|
202
|
+
if (!pageRoutesEntry) {
|
|
203
|
+
return [];
|
|
204
204
|
}
|
|
205
|
-
if (!
|
|
206
|
-
throw new Error("generate file system routes error, ".concat(
|
|
205
|
+
if (!fs.existsSync(pageRoutesEntry)) {
|
|
206
|
+
throw new Error("generate file system routes error, ".concat(pageRoutesEntry, " directory not found."));
|
|
207
|
+
}
|
|
208
|
+
if (!(fs.existsSync(pageRoutesEntry) && fs.statSync(pageRoutesEntry).isDirectory())) {
|
|
209
|
+
throw new Error("generate file system routes error, ".concat(pageRoutesEntry, " should be directory."));
|
|
207
210
|
}
|
|
208
211
|
var routes = [];
|
|
209
212
|
recursiveReadDir({
|
|
210
|
-
dir:
|
|
213
|
+
dir: pageRoutesEntry,
|
|
211
214
|
routes: routes,
|
|
212
215
|
basePath: "/",
|
|
213
216
|
srcDirectory: srcDirectory,
|
|
@@ -62,9 +62,11 @@ var scanDir = function(dirs) {
|
|
|
62
62
|
};
|
|
63
63
|
if (isHasPages) {
|
|
64
64
|
entrypoint.entry = path.join(dir, PAGES_DIR_NAME);
|
|
65
|
+
entrypoint.pageRoutesEntry = entrypoint.entry;
|
|
65
66
|
}
|
|
66
67
|
if (isHasNestedRoutes) {
|
|
67
|
-
entrypoint.
|
|
68
|
+
entrypoint.entry = path.join(dir, NESTED_ROUTES_DIR);
|
|
69
|
+
entrypoint.nestedRoutesEntry = entrypoint.entry;
|
|
68
70
|
}
|
|
69
71
|
return entrypoint;
|
|
70
72
|
}
|
|
@@ -78,7 +80,13 @@ var scanDir = function(dirs) {
|
|
|
78
80
|
};
|
|
79
81
|
var getFileSystemEntry = function(appContext, config) {
|
|
80
82
|
var appDirectory = appContext.appDirectory;
|
|
81
|
-
var
|
|
83
|
+
var _source = config.source, entriesDir = _source.entriesDir, disableEntryDirs = _source.disableEntryDirs;
|
|
84
|
+
var disabledDirs = [];
|
|
85
|
+
if (disableEntryDirs && Array.isArray(disableEntryDirs)) {
|
|
86
|
+
disabledDirs = disableEntryDirs === null || disableEntryDirs === void 0 ? void 0 : disableEntryDirs.map(function(dir) {
|
|
87
|
+
return ensureAbsolutePath(appDirectory, dir);
|
|
88
|
+
});
|
|
89
|
+
}
|
|
82
90
|
var src = ensureAbsolutePath(appDirectory, entriesDir || "");
|
|
83
91
|
if (fs.existsSync(src)) {
|
|
84
92
|
if (fs.statSync(src).isDirectory()) {
|
|
@@ -87,7 +95,7 @@ var getFileSystemEntry = function(appContext, config) {
|
|
|
87
95
|
] : fs.readdirSync(src).map(function(file) {
|
|
88
96
|
return path.join(src, file);
|
|
89
97
|
}).filter(function(file) {
|
|
90
|
-
return fs.statSync(file).isDirectory() && isBundleEntry(file);
|
|
98
|
+
return fs.statSync(file).isDirectory() && isBundleEntry(file) && !disabledDirs.includes(file);
|
|
91
99
|
}));
|
|
92
100
|
} else {
|
|
93
101
|
throw Error("source.entriesDir accept a directory.");
|
|
@@ -229,7 +229,7 @@ import { generateRoutes } from "../utils/routes";
|
|
|
229
229
|
import { emitResolvedConfig } from "../utils/config";
|
|
230
230
|
import { getCommand } from "../utils/commands";
|
|
231
231
|
import { initialNormalizedConfig } from "../config";
|
|
232
|
-
import {
|
|
232
|
+
import { isNestedRouteComponent, isPageComponentFile } from "./utils";
|
|
233
233
|
import { loaderBuilder, serverLoaderBuilder } from "./Builder";
|
|
234
234
|
var debug = createDebugger("plugin-analyze");
|
|
235
235
|
var analyze_default = function() {
|
|
@@ -237,11 +237,12 @@ var analyze_default = function() {
|
|
|
237
237
|
name: "@modern-js/plugin-analyze",
|
|
238
238
|
setup: function(api) {
|
|
239
239
|
var pagesDir = [];
|
|
240
|
+
var nestedRouteEntries = [];
|
|
240
241
|
var originEntrypoints = [];
|
|
241
242
|
return {
|
|
242
243
|
prepare: function prepare() {
|
|
243
244
|
return _asyncToGenerator(function() {
|
|
244
|
-
var ref, appContext, resolvedConfig, hookRunners, apiOnly, ref1, routes2, ref2, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, defaultChecked, initialRoutes, routes,
|
|
245
|
+
var ref, appContext, resolvedConfig, hookRunners, apiOnly, ref1, routes2, ref2, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, defaultChecked, initialRoutes, routes, htmlTemplates, command, buildCommands, normalizedConfig, builder;
|
|
245
246
|
return __generator(this, function(_state) {
|
|
246
247
|
switch(_state.label){
|
|
247
248
|
case 0:
|
|
@@ -363,6 +364,7 @@ var analyze_default = function() {
|
|
|
363
364
|
command = getCommand();
|
|
364
365
|
buildCommands = [
|
|
365
366
|
"dev",
|
|
367
|
+
"start",
|
|
366
368
|
"build",
|
|
367
369
|
"inspect",
|
|
368
370
|
"deploy"
|
|
@@ -505,6 +507,7 @@ var analyze_default = function() {
|
|
|
505
507
|
];
|
|
506
508
|
case 10:
|
|
507
509
|
builder = _state.sent();
|
|
510
|
+
builder.addPlugins(resolvedConfig.builderPlugins);
|
|
508
511
|
appContext = _objectSpreadProps(_objectSpread({}, appContext), {
|
|
509
512
|
builder: builder
|
|
510
513
|
});
|
|
@@ -555,8 +558,8 @@ var analyze_default = function() {
|
|
|
555
558
|
});
|
|
556
559
|
};
|
|
557
560
|
absoluteFilePath = path.resolve(appDirectory, filename);
|
|
558
|
-
isRouteComponent = isPageFile(absoluteFilePath) &&
|
|
559
|
-
if (!(isRouteComponent && (eventType === "add" || eventType === "unlink"))) return [
|
|
561
|
+
isRouteComponent = isPageFile(absoluteFilePath) && isPageComponentFile(absoluteFilePath);
|
|
562
|
+
if (!(isRouteComponent && (eventType === "add" || eventType === "unlink") || isNestedRouteComponent(nestedRouteEntries, absoluteFilePath) && eventType === "change")) return [
|
|
560
563
|
3,
|
|
561
564
|
2
|
|
562
565
|
];
|
|
@@ -176,20 +176,9 @@ var __generator = this && this.__generator || function(thisArg, body) {
|
|
|
176
176
|
};
|
|
177
177
|
import * as path from "path";
|
|
178
178
|
import { fs, getRouteId } from "@modern-js/utils";
|
|
179
|
-
import { JS_EXTENSIONS } from "./constants";
|
|
179
|
+
import { JS_EXTENSIONS, NESTED_ROUTE } from "./constants";
|
|
180
180
|
import { hasLoader, replaceWithAlias } from "./utils";
|
|
181
|
-
var
|
|
182
|
-
var PAGE_FILE = "page";
|
|
183
|
-
var LOADING_FILE = "loading";
|
|
184
|
-
var ERROR_FILE = "error";
|
|
185
|
-
var LOADER_FILE = "loader";
|
|
186
|
-
var conventionNames = [
|
|
187
|
-
LAYOUT_FILE,
|
|
188
|
-
PAGE_FILE,
|
|
189
|
-
LOADING_FILE,
|
|
190
|
-
ERROR_FILE,
|
|
191
|
-
LOADER_FILE
|
|
192
|
-
];
|
|
181
|
+
var conventionNames = Object.values(NESTED_ROUTE);
|
|
193
182
|
var getLoaderPath = function() {
|
|
194
183
|
var _ref = _asyncToGenerator(function(filename) {
|
|
195
184
|
return __generator(this, function(_state) {
|
|
@@ -235,7 +224,7 @@ var createRoute = function(routeInfo, rootDir, filename, entryName) {
|
|
|
235
224
|
};
|
|
236
225
|
var walk = function() {
|
|
237
226
|
var _ref = _asyncToGenerator(function(dirname, rootDir, alias, entryName) {
|
|
238
|
-
var isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute, ref, ref1,
|
|
227
|
+
var isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, pageLoaderFile, pageRoute, items, _iteratorNormalCompletion, _didIteratorError, _iteratorError, _iterator, _step, item, itemPath, extname, itemWithoutExt, isDirectory2, childRoute, ref, loaderPath, ref1, loaderPath1, err, finalRoute;
|
|
239
228
|
return __generator(this, function(_state) {
|
|
240
229
|
switch(_state.label){
|
|
241
230
|
case 0:
|
|
@@ -278,6 +267,8 @@ var walk = function() {
|
|
|
278
267
|
children: [],
|
|
279
268
|
isRoot: isRoot
|
|
280
269
|
};
|
|
270
|
+
pageLoaderFile = "";
|
|
271
|
+
pageRoute = null;
|
|
281
272
|
return [
|
|
282
273
|
4,
|
|
283
274
|
fs.readdir(dirname)
|
|
@@ -332,7 +323,12 @@ var walk = function() {
|
|
|
332
323
|
13
|
|
333
324
|
];
|
|
334
325
|
}
|
|
335
|
-
if (
|
|
326
|
+
if (itemWithoutExt === NESTED_ROUTE.LAYOUT_LOADER_FILE) {
|
|
327
|
+
if (!route.loader) {
|
|
328
|
+
route.loader = itemPath;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
if (!(itemWithoutExt === NESTED_ROUTE.LAYOUT_FILE)) return [
|
|
336
332
|
3,
|
|
337
333
|
10
|
|
338
334
|
];
|
|
@@ -342,14 +338,20 @@ var walk = function() {
|
|
|
342
338
|
getLoaderPath(itemPath)
|
|
343
339
|
];
|
|
344
340
|
case 9:
|
|
345
|
-
|
|
341
|
+
loaderPath = _state.sent();
|
|
342
|
+
if (loaderPath) {
|
|
343
|
+
route.loader = loaderPath;
|
|
344
|
+
}
|
|
346
345
|
_state.label = 10;
|
|
347
346
|
case 10:
|
|
348
|
-
if (
|
|
347
|
+
if (itemWithoutExt === NESTED_ROUTE.PAGE_LOADER_FILE) {
|
|
348
|
+
pageLoaderFile = itemPath;
|
|
349
|
+
}
|
|
350
|
+
if (!(itemWithoutExt === NESTED_ROUTE.PAGE_FILE)) return [
|
|
349
351
|
3,
|
|
350
352
|
12
|
|
351
353
|
];
|
|
352
|
-
|
|
354
|
+
pageRoute = createIndexRoute({
|
|
353
355
|
_component: replaceWithAlias(alias.basename, itemPath, alias.name)
|
|
354
356
|
}, rootDir, itemPath, entryName);
|
|
355
357
|
return [
|
|
@@ -357,14 +359,19 @@ var walk = function() {
|
|
|
357
359
|
getLoaderPath(itemPath)
|
|
358
360
|
];
|
|
359
361
|
case 11:
|
|
360
|
-
|
|
361
|
-
(
|
|
362
|
+
loaderPath1 = _state.sent();
|
|
363
|
+
if (loaderPath1) {
|
|
364
|
+
pageRoute.loader = loaderPath1;
|
|
365
|
+
} else if (pageLoaderFile) {
|
|
366
|
+
pageRoute.loader = pageLoaderFile;
|
|
367
|
+
}
|
|
368
|
+
(ref1 = route.children) === null || ref1 === void 0 ? void 0 : ref1.push(pageRoute);
|
|
362
369
|
_state.label = 12;
|
|
363
370
|
case 12:
|
|
364
|
-
if (itemWithoutExt === LOADING_FILE) {
|
|
371
|
+
if (itemWithoutExt === NESTED_ROUTE.LOADING_FILE) {
|
|
365
372
|
route.loading = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
366
373
|
}
|
|
367
|
-
if (itemWithoutExt === ERROR_FILE) {
|
|
374
|
+
if (itemWithoutExt === NESTED_ROUTE.ERROR_FILE) {
|
|
368
375
|
route.error = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
369
376
|
}
|
|
370
377
|
_state.label = 13;
|
|
@@ -401,7 +408,7 @@ var walk = function() {
|
|
|
401
408
|
7
|
|
402
409
|
];
|
|
403
410
|
case 17:
|
|
404
|
-
finalRoute = createRoute(route, rootDir, path.join(dirname, "".concat(LAYOUT_FILE, ".ts")), entryName);
|
|
411
|
+
finalRoute = createRoute(route, rootDir, path.join(dirname, "".concat(NESTED_ROUTE.LAYOUT_FILE, ".ts")), entryName);
|
|
405
412
|
if (isPathlessLayout) {
|
|
406
413
|
delete finalRoute.path;
|
|
407
414
|
}
|
|
@@ -399,7 +399,12 @@ var fileSystemRoutes = function() {
|
|
|
399
399
|
case 0:
|
|
400
400
|
name = "loader_".concat(index2);
|
|
401
401
|
filename = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "".concat(name, ".js"));
|
|
402
|
-
code = "
|
|
402
|
+
code = "";
|
|
403
|
+
if (loader.includes(".loader.")) {
|
|
404
|
+
code = "\n export { default as ".concat(name, " } from '").concat(slash(loader), "'\n ");
|
|
405
|
+
} else {
|
|
406
|
+
code = "\n export { loader as ".concat(name, " } from '").concat(slash(loader), "'\n ");
|
|
407
|
+
}
|
|
403
408
|
return [
|
|
404
409
|
4,
|
|
405
410
|
fs.ensureFile(filename)
|
|
@@ -185,7 +185,7 @@ import path from "path";
|
|
|
185
185
|
import { isReact18, normalizeToPosixPath, fs as fse } from "@modern-js/utils";
|
|
186
186
|
import { transform } from "esbuild";
|
|
187
187
|
import { parse } from "es-module-lexer";
|
|
188
|
-
import { FILE_SYSTEM_ROUTES_FILE_NAME, LOADER_EXPORT_NAME } from "./constants";
|
|
188
|
+
import { FILE_SYSTEM_ROUTES_FILE_NAME, LOADER_EXPORT_NAME, NESTED_ROUTE } from "./constants";
|
|
189
189
|
var walkDirectory = function(dir) {
|
|
190
190
|
return fs.readdirSync(dir).reduce(function(previous, filename) {
|
|
191
191
|
var filePath = path.join(dir, filename);
|
|
@@ -272,7 +272,7 @@ var getDefaultImports = function(param) {
|
|
|
272
272
|
}
|
|
273
273
|
return imports;
|
|
274
274
|
};
|
|
275
|
-
var
|
|
275
|
+
var isPageComponentFile = function(filePath) {
|
|
276
276
|
if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
|
|
277
277
|
return false;
|
|
278
278
|
}
|
|
@@ -286,6 +286,15 @@ var isRouteComponentFile = function(filePath) {
|
|
|
286
286
|
}
|
|
287
287
|
return false;
|
|
288
288
|
};
|
|
289
|
+
var isNestedRouteComponent = function(nestedRouteEntries, absoluteFilePath) {
|
|
290
|
+
var reg = new RegExp("(".concat(NESTED_ROUTE.LAYOUT_FILE, "|").concat(NESTED_ROUTE.PAGE_FILE, "})\\.tsx?$"));
|
|
291
|
+
return nestedRouteEntries.some(function(nestedRoutesEntry) {
|
|
292
|
+
if (absoluteFilePath.includes(nestedRoutesEntry) && reg.test(absoluteFilePath)) {
|
|
293
|
+
return true;
|
|
294
|
+
}
|
|
295
|
+
return false;
|
|
296
|
+
});
|
|
297
|
+
};
|
|
289
298
|
var replaceWithAlias = function(base, filePath, alias) {
|
|
290
299
|
return normalizeToPosixPath(path.join(alias, path.relative(base, filePath)));
|
|
291
300
|
};
|
|
@@ -366,4 +375,4 @@ var hasLoader = function() {
|
|
|
366
375
|
return _ref.apply(this, arguments);
|
|
367
376
|
};
|
|
368
377
|
}();
|
|
369
|
-
export { getDefaultImports, hasLoader,
|
|
378
|
+
export { getDefaultImports, hasLoader, isNestedRouteComponent, isPageComponentFile, parseModule, replaceWithAlias, walkDirectory };
|
|
@@ -104,7 +104,7 @@ var PluginCompatModern = function(appContext, modernConfig, options) {
|
|
|
104
104
|
var ref;
|
|
105
105
|
return ((ref = config.tools) === null || ref === void 0 ? void 0 : ref.htmlPlugin) !== false && target2 !== "node" && target2 !== "web-worker";
|
|
106
106
|
};
|
|
107
|
-
var ref
|
|
107
|
+
var ref;
|
|
108
108
|
var builderNormalizedConfig = api.getNormalizedConfig();
|
|
109
109
|
if (target === "node") {
|
|
110
110
|
chain.name("server");
|
|
@@ -148,7 +148,8 @@ var PluginCompatModern = function(appContext, modernConfig, options) {
|
|
|
148
148
|
var existNestedRoutes = entrypoints.some(function(entrypoint) {
|
|
149
149
|
return entrypoint.nestedRoutesEntry;
|
|
150
150
|
});
|
|
151
|
-
var
|
|
151
|
+
var routerConfig = modernConfig === null || modernConfig === void 0 ? void 0 : (ref = modernConfig.runtime) === null || ref === void 0 ? void 0 : ref.router;
|
|
152
|
+
var routerManifest = Boolean(routerConfig === null || routerConfig === void 0 ? void 0 : routerConfig.manifest);
|
|
152
153
|
if (existNestedRoutes || routerManifest) {
|
|
153
154
|
chain.plugin("route-plugin").use(RouterPlugin);
|
|
154
155
|
}
|
|
@@ -181,6 +182,9 @@ function applyNodeCompat(chain, modernConfig, isProd) {
|
|
|
181
182
|
if (isProd2 && ((outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg) === true || typeof (outputConfig === null || outputConfig === void 0 ? void 0 : (ref = outputConfig.ssg) === null || ref === void 0 ? void 0 : ref[0]) === "function")) {
|
|
182
183
|
return;
|
|
183
184
|
}
|
|
185
|
+
if (typeof entries === "undefined") {
|
|
186
|
+
throw new Error("No entry found, one of src/routes/layout.tsx, src/App.tsx, src/index.tsx is required");
|
|
187
|
+
}
|
|
184
188
|
var entryNames = Object.keys(entries);
|
|
185
189
|
if (isProd2 && entryNames.length === 1 && (outputConfig === null || outputConfig === void 0 ? void 0 : outputConfig.ssg)) {
|
|
186
190
|
return;
|
|
@@ -270,17 +270,11 @@ function createBuilderProviderConfig(normalizedConfig, appContext) {
|
|
|
270
270
|
htmlConfig.templateByEntries = _objectSpread({}, htmlConfig.templateByEntries, appContext.htmlTemplates);
|
|
271
271
|
}
|
|
272
272
|
return _objectSpreadProps(_objectSpread({}, normalizedConfig), {
|
|
273
|
-
source: _objectSpreadProps(_objectSpread({}, normalizedConfig.source), {
|
|
274
|
-
resolveExtensionPrefix: ".web"
|
|
275
|
-
}),
|
|
276
273
|
output: output,
|
|
277
274
|
dev: _objectSpreadProps(_objectSpread({}, normalizedConfig.dev), {
|
|
278
275
|
port: (ref = normalizedConfig.server) === null || ref === void 0 ? void 0 : ref.port
|
|
279
276
|
}),
|
|
280
|
-
html: htmlConfig
|
|
281
|
-
performance: _objectSpreadProps(_objectSpread({}, normalizedConfig.performance), {
|
|
282
|
-
removeMomentLocale: true
|
|
283
|
-
})
|
|
277
|
+
html: htmlConfig
|
|
284
278
|
});
|
|
285
279
|
}
|
|
286
280
|
function createBuilderOptions(target, appContext) {
|
|
@@ -181,9 +181,10 @@ import { setServer, createServer, injectDataLoaderPlugin } from "../utils/create
|
|
|
181
181
|
import { generateRoutes } from "../utils/routes";
|
|
182
182
|
import { getSpecifiedEntries } from "../utils/getSpecifiedEntries";
|
|
183
183
|
import { buildServerConfig } from "../utils/config";
|
|
184
|
+
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
|
184
185
|
var dev = function() {
|
|
185
186
|
var _ref = _asyncToGenerator(function(api, options) {
|
|
186
|
-
var ref, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, entrypoints, serverConfigFile,
|
|
187
|
+
var ref, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, entrypoints, serverConfigFile, checkedEntries, serverInternalPlugins, serverOptions, app, server;
|
|
187
188
|
return __generator(this, function(_state) {
|
|
188
189
|
switch(_state.label){
|
|
189
190
|
case 0:
|
|
@@ -197,7 +198,7 @@ var dev = function() {
|
|
|
197
198
|
cliOptions: options
|
|
198
199
|
});
|
|
199
200
|
ResolvedConfigContext.set(normalizedConfig);
|
|
200
|
-
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly, entrypoints = appContext.entrypoints, serverConfigFile = appContext.serverConfigFile
|
|
201
|
+
appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly, entrypoints = appContext.entrypoints, serverConfigFile = appContext.serverConfigFile;
|
|
201
202
|
return [
|
|
202
203
|
4,
|
|
203
204
|
getSpecifiedEntries(options.entry || false, entrypoints)
|
|
@@ -232,30 +233,23 @@ var dev = function() {
|
|
|
232
233
|
if (!appContext.builder && !apiOnly) {
|
|
233
234
|
throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
|
|
234
235
|
}
|
|
235
|
-
if (!!apiOnly) return [
|
|
236
|
-
3,
|
|
237
|
-
5
|
|
238
|
-
];
|
|
239
236
|
return [
|
|
240
237
|
4,
|
|
241
|
-
appContext
|
|
238
|
+
generateRoutes(appContext)
|
|
242
239
|
];
|
|
243
240
|
case 4:
|
|
244
|
-
|
|
245
|
-
_state.label = 5;
|
|
246
|
-
case 5:
|
|
241
|
+
_state.sent();
|
|
247
242
|
return [
|
|
248
243
|
4,
|
|
249
|
-
|
|
244
|
+
getServerInternalPlugins(api)
|
|
250
245
|
];
|
|
251
|
-
case
|
|
252
|
-
_state.sent();
|
|
246
|
+
case 5:
|
|
247
|
+
serverInternalPlugins = _state.sent();
|
|
253
248
|
serverOptions = {
|
|
254
249
|
dev: _objectSpread({
|
|
255
250
|
port: port,
|
|
256
251
|
https: normalizedConfig.dev.https
|
|
257
252
|
}, (ref = normalizedConfig.tools) === null || ref === void 0 ? void 0 : ref.devServer),
|
|
258
|
-
compiler: compiler || null,
|
|
259
253
|
pwd: appDirectory,
|
|
260
254
|
config: normalizedConfig,
|
|
261
255
|
serverConfigFile: serverConfigFile,
|
|
@@ -263,13 +257,15 @@ var dev = function() {
|
|
|
263
257
|
};
|
|
264
258
|
if (!apiOnly) return [
|
|
265
259
|
3,
|
|
266
|
-
|
|
260
|
+
7
|
|
267
261
|
];
|
|
268
262
|
return [
|
|
269
263
|
4,
|
|
270
|
-
createServer(serverOptions)
|
|
264
|
+
createServer(_objectSpreadProps(_objectSpread({}, serverOptions), {
|
|
265
|
+
compiler: null
|
|
266
|
+
}))
|
|
271
267
|
];
|
|
272
|
-
case
|
|
268
|
+
case 6:
|
|
273
269
|
app = _state.sent();
|
|
274
270
|
app.listen(port, function() {
|
|
275
271
|
var _ref = _asyncToGenerator(function(err) {
|
|
@@ -289,27 +285,26 @@ var dev = function() {
|
|
|
289
285
|
}());
|
|
290
286
|
return [
|
|
291
287
|
3,
|
|
292
|
-
|
|
288
|
+
9
|
|
293
289
|
];
|
|
294
|
-
case
|
|
290
|
+
case 7:
|
|
295
291
|
return [
|
|
296
292
|
4,
|
|
297
293
|
appContext.builder.startDevServer({
|
|
298
|
-
compiler: compiler,
|
|
299
294
|
printURLs: false,
|
|
300
295
|
serverOptions: serverOptions
|
|
301
296
|
})
|
|
302
297
|
];
|
|
303
|
-
case
|
|
298
|
+
case 8:
|
|
304
299
|
server = _state.sent().server;
|
|
305
300
|
setServer(server);
|
|
306
|
-
_state.label =
|
|
307
|
-
case
|
|
301
|
+
_state.label = 9;
|
|
302
|
+
case 9:
|
|
308
303
|
return [
|
|
309
304
|
4,
|
|
310
305
|
createFileWatcher(appContext, normalizedConfig.source.configDir, hookRunners)
|
|
311
306
|
];
|
|
312
|
-
case
|
|
307
|
+
case 10:
|
|
313
308
|
_state.sent();
|
|
314
309
|
return [
|
|
315
310
|
2
|
|
@@ -126,9 +126,10 @@ import { logger, chalk, isApiOnly } from "@modern-js/utils";
|
|
|
126
126
|
import server from "@modern-js/prod-server";
|
|
127
127
|
import { printInstructions } from "../utils/printInstructions";
|
|
128
128
|
import { injectDataLoaderPlugin } from "../utils/createServer";
|
|
129
|
+
import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
|
|
129
130
|
var start = function() {
|
|
130
131
|
var _ref = _asyncToGenerator(function(api) {
|
|
131
|
-
var ref, appContext, userConfig, hookRunners, appDirectory, port, serverConfigFile, apiOnly, app;
|
|
132
|
+
var ref, appContext, userConfig, hookRunners, appDirectory, port, serverConfigFile, apiOnly, serverInternalPlugins, app;
|
|
132
133
|
return __generator(this, function(_state) {
|
|
133
134
|
switch(_state.label){
|
|
134
135
|
case 0:
|
|
@@ -143,17 +144,23 @@ var start = function() {
|
|
|
143
144
|
];
|
|
144
145
|
case 1:
|
|
145
146
|
apiOnly = _state.sent();
|
|
147
|
+
return [
|
|
148
|
+
4,
|
|
149
|
+
getServerInternalPlugins(api)
|
|
150
|
+
];
|
|
151
|
+
case 2:
|
|
152
|
+
serverInternalPlugins = _state.sent();
|
|
146
153
|
return [
|
|
147
154
|
4,
|
|
148
155
|
server({
|
|
149
156
|
pwd: appDirectory,
|
|
150
157
|
config: userConfig,
|
|
151
158
|
serverConfigFile: serverConfigFile,
|
|
152
|
-
internalPlugins: injectDataLoaderPlugin(
|
|
159
|
+
internalPlugins: injectDataLoaderPlugin(serverInternalPlugins),
|
|
153
160
|
apiOnly: apiOnly
|
|
154
161
|
})
|
|
155
162
|
];
|
|
156
|
-
case
|
|
163
|
+
case 3:
|
|
157
164
|
app = _state.sent();
|
|
158
165
|
app.listen(port, function() {
|
|
159
166
|
var _ref = _asyncToGenerator(function(err) {
|