@modern-js/app-tools 2.0.0-beta.1 → 2.0.0-beta.3
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 +445 -0
- package/bin/modern.js +10 -1
- package/dist/js/modern/analyze/constants.js +2 -0
- package/dist/js/modern/analyze/generateCode.js +39 -19
- package/dist/js/modern/analyze/getBundleEntry.js +1 -1
- package/dist/js/modern/analyze/getFileSystemEntry.js +1 -1
- package/dist/js/modern/analyze/getHtmlTemplate.js +1 -1
- package/dist/js/modern/analyze/getServerRoutes.js +8 -4
- package/dist/js/modern/analyze/index.js +12 -27
- package/dist/js/modern/analyze/nestedRoutes.js +17 -6
- package/dist/js/modern/analyze/templates.js +59 -27
- package/dist/js/modern/analyze/utils.js +30 -4
- package/dist/js/modern/builder/builderPlugins/compatModern.js +18 -12
- package/dist/js/modern/builder/index.js +31 -16
- package/dist/js/modern/builder/loaders/routerLoader.js +20 -0
- package/dist/js/modern/builder/loaders/serverModuleLoader.js +4 -0
- package/dist/js/modern/builder/share.js +1 -1
- package/dist/js/modern/commands/build.js +8 -2
- package/dist/js/modern/commands/dev.js +37 -32
- package/dist/js/modern/commands/inspect.js +4 -2
- package/dist/js/modern/config/default.js +206 -0
- package/dist/js/modern/config/index.js +2 -0
- package/dist/js/modern/config/initial/createHtmlConfig.js +32 -0
- package/dist/js/modern/{builder → config/initial}/createOutputConfig.js +16 -15
- package/dist/js/modern/config/initial/createSourceConfig.js +32 -0
- package/dist/js/modern/config/initial/createToolsConfig.js +41 -0
- package/dist/js/modern/config/initial/index.js +11 -0
- package/dist/js/modern/config/initial/inits.js +117 -0
- package/dist/js/modern/config/initial/transformNormalizedConfig.js +40 -0
- package/dist/js/modern/defineConfig.js +12 -0
- package/dist/js/modern/hooks.js +23 -19
- package/dist/js/modern/index.js +7 -5
- package/dist/js/modern/initialize/index.js +72 -0
- package/dist/js/modern/schema/Schema.js +39 -0
- package/dist/js/modern/schema/index.js +139 -0
- package/dist/js/modern/schema/legacy.js +284 -0
- package/dist/js/modern/types/config/deploy.js +0 -0
- package/dist/js/modern/types/config/dev.js +0 -0
- package/dist/js/modern/types/config/experiments.js +0 -0
- package/dist/js/modern/types/config/html.js +0 -0
- package/dist/js/modern/types/config/index.js +2 -0
- package/dist/js/modern/types/config/output.js +0 -0
- package/dist/js/modern/types/config/performance.js +0 -0
- package/dist/js/modern/types/config/security.js +0 -0
- package/dist/js/modern/types/config/source.js +0 -0
- package/dist/js/modern/types/config/tools.js +0 -0
- package/dist/js/modern/types/hooks.js +0 -0
- package/dist/js/modern/types/index.js +4 -0
- package/dist/js/modern/types/legacyConfig/deploy.js +0 -0
- package/dist/js/modern/types/legacyConfig/dev.js +0 -0
- package/dist/js/modern/types/legacyConfig/index.js +0 -0
- package/dist/js/modern/types/legacyConfig/output.js +1 -0
- package/dist/js/modern/types/legacyConfig/source.js +0 -0
- package/dist/js/modern/types/legacyConfig/tools.js +0 -0
- package/dist/js/modern/utils/config.js +1 -1
- package/dist/js/modern/utils/createFileWatcher.js +82 -0
- package/dist/js/modern/utils/restart.js +17 -0
- package/dist/js/node/analyze/constants.js +5 -1
- package/dist/js/node/analyze/generateCode.js +37 -17
- package/dist/js/node/analyze/getBundleEntry.js +1 -1
- package/dist/js/node/analyze/getFileSystemEntry.js +1 -1
- package/dist/js/node/analyze/getHtmlTemplate.js +1 -1
- package/dist/js/node/analyze/getServerRoutes.js +8 -4
- package/dist/js/node/analyze/index.js +13 -39
- package/dist/js/node/analyze/nestedRoutes.js +15 -4
- package/dist/js/node/analyze/templates.js +60 -27
- package/dist/js/node/analyze/utils.js +31 -3
- package/dist/js/node/builder/builderPlugins/compatModern.js +18 -12
- package/dist/js/node/builder/index.js +32 -16
- package/dist/js/node/builder/loaders/routerLoader.js +27 -0
- package/dist/js/node/builder/loaders/serverModuleLoader.js +11 -0
- package/dist/js/node/builder/share.js +1 -1
- package/dist/js/node/commands/build.js +8 -2
- package/dist/js/node/commands/dev.js +37 -32
- package/dist/js/node/commands/inspect.js +4 -2
- package/dist/js/node/config/default.js +213 -0
- package/dist/js/node/config/index.js +31 -0
- package/dist/js/node/config/initial/createHtmlConfig.js +38 -0
- package/dist/js/node/{builder → config/initial}/createOutputConfig.js +16 -15
- package/dist/js/node/config/initial/createSourceConfig.js +38 -0
- package/dist/js/node/config/initial/createToolsConfig.js +47 -0
- package/dist/js/node/config/initial/index.js +24 -0
- package/dist/js/node/config/initial/inits.js +127 -0
- package/dist/js/node/config/initial/transformNormalizedConfig.js +46 -0
- package/dist/js/node/defineConfig.js +20 -0
- package/dist/js/node/hooks.js +23 -28
- package/dist/js/node/index.js +30 -16
- package/dist/js/node/initialize/index.js +79 -0
- package/dist/js/node/schema/Schema.js +46 -0
- package/dist/js/node/schema/index.js +152 -0
- package/dist/js/node/schema/legacy.js +291 -0
- package/dist/js/node/types/config/deploy.js +0 -0
- package/dist/js/node/types/config/dev.js +0 -0
- package/dist/js/node/types/config/experiments.js +0 -0
- package/dist/js/node/types/config/html.js +0 -0
- package/dist/js/node/types/config/index.js +16 -0
- package/dist/js/node/types/config/output.js +0 -0
- package/dist/js/node/types/config/performance.js +0 -0
- package/dist/js/node/types/config/security.js +0 -0
- package/dist/js/node/types/config/source.js +0 -0
- package/dist/js/node/types/config/tools.js +0 -0
- package/dist/js/node/types/hooks.js +0 -0
- package/dist/js/node/types/index.js +38 -0
- package/dist/js/node/types/legacyConfig/deploy.js +0 -0
- package/dist/js/node/types/legacyConfig/dev.js +0 -0
- package/dist/js/node/types/legacyConfig/index.js +0 -0
- package/dist/js/node/types/legacyConfig/output.js +5 -0
- package/dist/js/node/types/legacyConfig/source.js +0 -0
- package/dist/js/node/types/legacyConfig/tools.js +0 -0
- package/dist/js/node/utils/config.js +1 -1
- package/dist/js/node/utils/createFileWatcher.js +91 -0
- package/dist/js/node/utils/restart.js +23 -0
- package/dist/js/treeshaking/analyze/constants.js +2 -0
- package/dist/js/treeshaking/analyze/generateCode.js +138 -82
- package/dist/js/treeshaking/analyze/getBundleEntry.js +1 -1
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +1 -1
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +1 -1
- package/dist/js/treeshaking/analyze/getServerRoutes.js +7 -5
- package/dist/js/treeshaking/analyze/index.js +10 -26
- package/dist/js/treeshaking/analyze/nestedRoutes.js +98 -55
- package/dist/js/treeshaking/analyze/templates.js +175 -101
- package/dist/js/treeshaking/analyze/utils.js +80 -4
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +18 -12
- package/dist/js/treeshaking/builder/index.js +29 -16
- package/dist/js/treeshaking/builder/loaders/routerLoader.js +14 -0
- package/dist/js/treeshaking/builder/loaders/serverModuleLoader.js +4 -0
- package/dist/js/treeshaking/builder/share.js +1 -1
- package/dist/js/treeshaking/commands/build.js +33 -23
- package/dist/js/treeshaking/commands/dev.js +56 -43
- package/dist/js/treeshaking/commands/inspect.js +8 -3
- package/dist/js/treeshaking/config/default.js +199 -0
- package/dist/js/treeshaking/config/index.js +2 -0
- package/dist/js/treeshaking/config/initial/createHtmlConfig.js +31 -0
- package/dist/js/treeshaking/config/initial/createOutputConfig.js +70 -0
- package/dist/js/treeshaking/config/initial/createSourceConfig.js +41 -0
- package/dist/js/treeshaking/config/initial/createToolsConfig.js +38 -0
- package/dist/js/treeshaking/config/initial/index.js +11 -0
- package/dist/js/treeshaking/config/initial/inits.js +114 -0
- package/dist/js/treeshaking/config/initial/transformNormalizedConfig.js +38 -0
- package/dist/js/treeshaking/defineConfig.js +14 -0
- package/dist/js/treeshaking/hooks.js +23 -19
- package/dist/js/treeshaking/index.js +7 -5
- package/dist/js/treeshaking/initialize/index.js +121 -0
- package/dist/js/treeshaking/schema/Schema.js +75 -0
- package/dist/js/treeshaking/schema/index.js +138 -0
- package/dist/js/treeshaking/schema/legacy.js +273 -0
- package/dist/js/treeshaking/types/config/deploy.js +0 -0
- package/dist/js/treeshaking/types/config/dev.js +0 -0
- package/dist/js/treeshaking/types/config/experiments.js +0 -0
- package/dist/js/treeshaking/types/config/html.js +0 -0
- package/dist/js/treeshaking/types/config/index.js +2 -0
- package/dist/js/treeshaking/types/config/output.js +0 -0
- package/dist/js/treeshaking/types/config/performance.js +0 -0
- package/dist/js/treeshaking/types/config/security.js +0 -0
- package/dist/js/treeshaking/types/config/source.js +0 -0
- package/dist/js/treeshaking/types/config/tools.js +0 -0
- package/dist/js/treeshaking/types/hooks.js +0 -0
- package/dist/js/treeshaking/types/index.js +4 -0
- package/dist/js/treeshaking/types/legacyConfig/deploy.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/dev.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/index.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/output.js +1 -0
- package/dist/js/treeshaking/types/legacyConfig/source.js +0 -0
- package/dist/js/treeshaking/types/legacyConfig/tools.js +0 -0
- package/dist/js/treeshaking/utils/config.js +1 -1
- package/dist/js/treeshaking/utils/createFileWatcher.js +123 -0
- package/dist/js/treeshaking/utils/restart.js +45 -0
- package/dist/types/analyze/constants.d.ts +2 -0
- package/dist/types/analyze/generateCode.d.ts +3 -2
- package/dist/types/analyze/getBundleEntry.d.ts +2 -2
- package/dist/types/analyze/getFileSystemEntry.d.ts +2 -2
- package/dist/types/analyze/getHtmlTemplate.d.ts +3 -3
- package/dist/types/analyze/getServerRoutes.d.ts +3 -2
- package/dist/types/analyze/index.d.ts +3 -41
- package/dist/types/analyze/templates.d.ts +9 -8
- package/dist/types/analyze/utils.d.ts +10 -2
- package/dist/types/builder/builderPlugins/compatModern.d.ts +2 -2
- package/dist/types/builder/index.d.ts +5 -2
- package/dist/types/builder/loaders/routerLoader.d.ts +3 -0
- package/dist/types/builder/loaders/serverModuleLoader.d.ts +3 -0
- package/dist/types/builder/share.d.ts +2 -2
- package/dist/types/commands/build.d.ts +2 -2
- package/dist/types/commands/deploy.d.ts +2 -2
- package/dist/types/commands/dev.d.ts +2 -2
- package/dist/types/commands/inspect.d.ts +9 -1
- package/dist/types/commands/start.d.ts +2 -2
- package/dist/types/config/default.d.ts +3 -0
- package/dist/types/config/index.d.ts +2 -0
- package/dist/types/config/initial/createHtmlConfig.d.ts +2 -0
- package/dist/types/config/initial/createOutputConfig.d.ts +2 -0
- package/dist/types/config/initial/createSourceConfig.d.ts +2 -0
- package/dist/types/config/initial/createToolsConfig.d.ts +2 -0
- package/dist/types/config/initial/index.d.ts +4 -0
- package/dist/types/config/initial/inits.d.ts +4 -0
- package/dist/types/config/initial/transformNormalizedConfig.d.ts +2 -0
- package/dist/types/defineConfig.d.ts +7 -0
- package/dist/types/hooks.d.ts +2 -42
- package/dist/types/index.d.ts +5 -5
- package/dist/types/initialize/index.d.ts +3 -0
- package/dist/types/schema/Schema.d.ts +14 -0
- package/dist/types/schema/index.d.ts +4 -0
- package/dist/types/schema/legacy.d.ts +3 -0
- package/dist/types/types/config/deploy.d.ts +9 -0
- package/dist/types/types/config/dev.d.ts +13 -0
- package/dist/types/types/config/experiments.d.ts +4 -0
- package/dist/types/types/config/html.d.ts +4 -0
- package/dist/types/types/config/index.d.ts +62 -0
- package/dist/types/types/config/output.d.ts +23 -0
- package/dist/types/types/config/performance.d.ts +4 -0
- package/dist/types/types/config/security.d.ts +4 -0
- package/dist/types/types/config/source.d.ts +22 -0
- package/dist/types/types/config/tools.d.ts +22 -0
- package/dist/types/types/hooks.d.ts +81 -0
- package/dist/types/types/index.d.ts +23 -0
- package/dist/types/types/legacyConfig/deploy.d.ts +8 -0
- package/dist/types/types/legacyConfig/dev.d.ts +12 -0
- package/dist/types/types/legacyConfig/index.d.ts +33 -0
- package/dist/types/types/legacyConfig/output.d.ts +51 -0
- package/dist/types/types/legacyConfig/source.d.ts +25 -0
- package/dist/types/types/legacyConfig/tools.d.ts +16 -0
- package/dist/types/utils/config.d.ts +2 -2
- package/dist/types/utils/createFileWatcher.d.ts +4 -0
- package/dist/types/utils/printInstructions.d.ts +3 -3
- package/dist/types/utils/restart.d.ts +3 -0
- package/lib/types.d.ts +1 -1
- package/package.json +28 -25
- package/dist/js/modern/builder/createHtmlConfig.js +0 -58
- package/dist/js/modern/builder/createSourceConfig.js +0 -74
- package/dist/js/modern/builder/createToolsConfig.js +0 -87
- package/dist/js/node/builder/createHtmlConfig.js +0 -68
- package/dist/js/node/builder/createSourceConfig.js +0 -82
- package/dist/js/node/builder/createToolsConfig.js +0 -94
- package/dist/js/treeshaking/builder/createHtmlConfig.js +0 -59
- package/dist/js/treeshaking/builder/createOutputConfig.js +0 -70
- package/dist/js/treeshaking/builder/createSourceConfig.js +0 -88
- package/dist/js/treeshaking/builder/createToolsConfig.js +0 -85
- package/dist/types/builder/createHtmlConfig.d.ts +0 -6
- package/dist/types/builder/createOutputConfig.d.ts +0 -3
- package/dist/types/builder/createSourceConfig.d.ts +0 -5
- package/dist/types/builder/createToolsConfig.d.ts +0 -13
|
@@ -4,15 +4,20 @@ import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
|
4
4
|
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
5
5
|
import _createForOfIteratorHelper from "@babel/runtime/helpers/esm/createForOfIteratorHelper";
|
|
6
6
|
import path from 'path';
|
|
7
|
-
import { fs, logger } from '@modern-js/utils';
|
|
7
|
+
import { fs, LOADER_ROUTES_DIR, logger } from '@modern-js/utils';
|
|
8
8
|
import { useResolvedConfigContext } from '@modern-js/core';
|
|
9
9
|
import esbuild from 'esbuild';
|
|
10
10
|
import { getCommand } from "../utils/commands";
|
|
11
11
|
import * as templates from "./templates";
|
|
12
12
|
import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
|
|
13
|
-
import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
|
|
13
|
+
import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, TEMP_LOADERS_DIR } from "./constants";
|
|
14
14
|
import { getDefaultImports } from "./utils";
|
|
15
15
|
import { walk } from "./nestedRoutes";
|
|
16
|
+
var loader = {
|
|
17
|
+
'.js': 'jsx',
|
|
18
|
+
'.ts': 'tsx'
|
|
19
|
+
};
|
|
20
|
+
var EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
|
|
16
21
|
var createImportSpecifier = function createImportSpecifier(specifiers) {
|
|
17
22
|
var defaults = '';
|
|
18
23
|
var named = [];
|
|
@@ -91,21 +96,16 @@ export var createImportStatements = function createImportStatements(statements)
|
|
|
91
96
|
};
|
|
92
97
|
var buildLoader = /*#__PURE__*/function () {
|
|
93
98
|
var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(entry, outfile) {
|
|
94
|
-
var
|
|
99
|
+
var command;
|
|
95
100
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
96
101
|
while (1) {
|
|
97
102
|
switch (_context.prev = _context.next) {
|
|
98
103
|
case 0:
|
|
99
|
-
loader = {
|
|
100
|
-
'.js': 'jsx',
|
|
101
|
-
'.ts': 'tsx'
|
|
102
|
-
};
|
|
103
|
-
EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
|
|
104
104
|
command = getCommand();
|
|
105
|
-
_context.next =
|
|
105
|
+
_context.next = 3;
|
|
106
106
|
return esbuild.build({
|
|
107
|
-
format: '
|
|
108
|
-
platform: '
|
|
107
|
+
format: 'esm',
|
|
108
|
+
platform: 'browser',
|
|
109
109
|
target: 'esnext',
|
|
110
110
|
loader: loader,
|
|
111
111
|
watch: command === 'dev' && {},
|
|
@@ -133,7 +133,7 @@ var buildLoader = /*#__PURE__*/function () {
|
|
|
133
133
|
}
|
|
134
134
|
}]
|
|
135
135
|
});
|
|
136
|
-
case
|
|
136
|
+
case 3:
|
|
137
137
|
case "end":
|
|
138
138
|
return _context.stop();
|
|
139
139
|
}
|
|
@@ -144,28 +144,59 @@ var buildLoader = /*#__PURE__*/function () {
|
|
|
144
144
|
return _ref2.apply(this, arguments);
|
|
145
145
|
};
|
|
146
146
|
}();
|
|
147
|
+
var buildServerLoader = /*#__PURE__*/function () {
|
|
148
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(entry, outfile) {
|
|
149
|
+
var command;
|
|
150
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
151
|
+
while (1) {
|
|
152
|
+
switch (_context2.prev = _context2.next) {
|
|
153
|
+
case 0:
|
|
154
|
+
command = getCommand();
|
|
155
|
+
_context2.next = 3;
|
|
156
|
+
return esbuild.build({
|
|
157
|
+
format: 'cjs',
|
|
158
|
+
platform: 'node',
|
|
159
|
+
target: 'esnext',
|
|
160
|
+
loader: loader,
|
|
161
|
+
watch: command === 'dev' && {},
|
|
162
|
+
bundle: true,
|
|
163
|
+
logLevel: 'error',
|
|
164
|
+
entryPoints: [entry],
|
|
165
|
+
outfile: outfile
|
|
166
|
+
});
|
|
167
|
+
case 3:
|
|
168
|
+
case "end":
|
|
169
|
+
return _context2.stop();
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}, _callee2);
|
|
173
|
+
}));
|
|
174
|
+
return function buildServerLoader(_x3, _x4) {
|
|
175
|
+
return _ref3.apply(this, arguments);
|
|
176
|
+
};
|
|
177
|
+
}();
|
|
147
178
|
export var generateCode = /*#__PURE__*/function () {
|
|
148
|
-
var
|
|
179
|
+
var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4(appContext, config, entrypoints, api) {
|
|
149
180
|
var _config$runtime, _config$runtime$route;
|
|
150
181
|
var internalDirectory, distDirectory, srcDirectory, internalDirAlias, internalSrcAlias, hookRunners, islegacy, mountId, getRoutes, generateEntryCode, _generateEntryCode;
|
|
151
|
-
return _regeneratorRuntime().wrap(function
|
|
182
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
152
183
|
while (1) {
|
|
153
|
-
switch (
|
|
184
|
+
switch (_context4.prev = _context4.next) {
|
|
154
185
|
case 0:
|
|
155
186
|
_generateEntryCode = function _generateEntryCode3() {
|
|
156
|
-
_generateEntryCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
157
|
-
var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, _yield$hookRunners$mo, routes, _config, ssr, mode, hasPageRoute, _yield$hookRunners$be, _code, routesServerFile, outputRoutesServerFile, _code2, _yield$hookRunners$mo2, importStatements, _yield$hookRunners$mo3, plugins, _yield$hookRunners$mo4, renderFunction, _yield$hookRunners$mo5, exportStatement, code, entryFile, _yield$hookRunners$mo6, asyncEntryCode, bootstrapFile;
|
|
158
|
-
return _regeneratorRuntime().wrap(function
|
|
187
|
+
_generateEntryCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(entrypoint) {
|
|
188
|
+
var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, _yield$hookRunners$mo, routes, _config, ssr, mode, hasPageRoute, _yield$hookRunners$be, _code, routesServerFile, outputRoutesServerFile, _code2, loaderEntryFile, loaderIndexFile, _yield$hookRunners$mo2, importStatements, _yield$hookRunners$mo3, plugins, _yield$hookRunners$mo4, renderFunction, _yield$hookRunners$mo5, exportStatement, code, entryFile, _yield$hookRunners$mo6, asyncEntryCode, bootstrapFile;
|
|
189
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
159
190
|
while (1) {
|
|
160
|
-
switch (
|
|
191
|
+
switch (_context3.prev = _context3.next) {
|
|
161
192
|
case 0:
|
|
162
193
|
entryName = entrypoint.entryName, isAutoMount = entrypoint.isAutoMount, customBootstrap = entrypoint.customBootstrap, fileSystemRoutes = entrypoint.fileSystemRoutes;
|
|
163
194
|
if (!isAutoMount) {
|
|
164
|
-
|
|
195
|
+
_context3.next = 85;
|
|
165
196
|
break;
|
|
166
197
|
}
|
|
167
198
|
if (!fileSystemRoutes) {
|
|
168
|
-
|
|
199
|
+
_context3.next = 55;
|
|
169
200
|
break;
|
|
170
201
|
}
|
|
171
202
|
initialRoutes = [];
|
|
@@ -180,37 +211,37 @@ export var generateCode = /*#__PURE__*/function () {
|
|
|
180
211
|
});
|
|
181
212
|
}
|
|
182
213
|
if (!entrypoint.nestedRoutesEntry) {
|
|
183
|
-
|
|
214
|
+
_context3.next = 16;
|
|
184
215
|
break;
|
|
185
216
|
}
|
|
186
217
|
if (islegacy) {
|
|
187
|
-
|
|
218
|
+
_context3.next = 14;
|
|
188
219
|
break;
|
|
189
220
|
}
|
|
190
|
-
|
|
221
|
+
_context3.next = 10;
|
|
191
222
|
return walk(entrypoint.nestedRoutesEntry, entrypoint.nestedRoutesEntry, {
|
|
192
223
|
name: internalSrcAlias,
|
|
193
224
|
basename: srcDirectory
|
|
194
225
|
}, entrypoint.entryName);
|
|
195
226
|
case 10:
|
|
196
|
-
nestedRoute =
|
|
227
|
+
nestedRoute = _context3.sent;
|
|
197
228
|
if (nestedRoute) {
|
|
198
229
|
initialRoutes.unshift(nestedRoute);
|
|
199
230
|
}
|
|
200
|
-
|
|
231
|
+
_context3.next = 16;
|
|
201
232
|
break;
|
|
202
233
|
case 14:
|
|
203
234
|
logger.error('Nested routes is not supported in legacy mode.');
|
|
204
235
|
// eslint-disable-next-line no-process-exit
|
|
205
236
|
process.exit(1);
|
|
206
237
|
case 16:
|
|
207
|
-
|
|
238
|
+
_context3.next = 18;
|
|
208
239
|
return hookRunners.modifyFileSystemRoutes({
|
|
209
240
|
entrypoint: entrypoint,
|
|
210
241
|
routes: initialRoutes
|
|
211
242
|
});
|
|
212
243
|
case 18:
|
|
213
|
-
_yield$hookRunners$mo =
|
|
244
|
+
_yield$hookRunners$mo = _context3.sent;
|
|
214
245
|
routes = _yield$hookRunners$mo.routes;
|
|
215
246
|
_config = useResolvedConfigContext();
|
|
216
247
|
ssr = _config === null || _config === void 0 ? void 0 : _config.server.ssr;
|
|
@@ -229,44 +260,69 @@ export var generateCode = /*#__PURE__*/function () {
|
|
|
229
260
|
process.exit(1);
|
|
230
261
|
}
|
|
231
262
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
263
|
+
_context3.t0 = hookRunners;
|
|
264
|
+
_context3.t1 = entrypoint;
|
|
265
|
+
_context3.next = 28;
|
|
266
|
+
return templates.fileSystemRoutes({
|
|
267
|
+
routes: routes,
|
|
268
|
+
ssrMode: mode,
|
|
269
|
+
nestedRoutesEntry: entrypoint.nestedRoutesEntry,
|
|
270
|
+
entryName: entrypoint.entryName,
|
|
271
|
+
internalDirectory: internalDirectory
|
|
241
272
|
});
|
|
242
|
-
case
|
|
243
|
-
|
|
273
|
+
case 28:
|
|
274
|
+
_context3.t2 = _context3.sent;
|
|
275
|
+
_context3.t3 = {
|
|
276
|
+
entrypoint: _context3.t1,
|
|
277
|
+
code: _context3.t2
|
|
278
|
+
};
|
|
279
|
+
_context3.next = 32;
|
|
280
|
+
return _context3.t0.beforeGenerateRoutes.call(_context3.t0, _context3.t3);
|
|
281
|
+
case 32:
|
|
282
|
+
_yield$hookRunners$be = _context3.sent;
|
|
244
283
|
_code = _yield$hookRunners$be.code;
|
|
245
284
|
if (!entrypoint.nestedRoutesEntry) {
|
|
246
|
-
|
|
285
|
+
_context3.next = 54;
|
|
247
286
|
break;
|
|
248
287
|
}
|
|
249
|
-
routesServerFile = path.join(internalDirectory, entryName, '
|
|
250
|
-
outputRoutesServerFile = path.join(distDirectory,
|
|
288
|
+
routesServerFile = path.join(internalDirectory, entryName, 'route-server-loaders.js');
|
|
289
|
+
outputRoutesServerFile = path.join(distDirectory, LOADER_ROUTES_DIR, entryName, 'index.js');
|
|
251
290
|
_code2 = templates.routesForServer({
|
|
252
291
|
routes: routes,
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
basename: srcDirectory
|
|
256
|
-
}
|
|
292
|
+
internalDirectory: internalDirectory,
|
|
293
|
+
entryName: entryName
|
|
257
294
|
});
|
|
258
|
-
|
|
295
|
+
_context3.next = 40;
|
|
259
296
|
return fs.ensureFile(routesServerFile);
|
|
260
|
-
case
|
|
261
|
-
|
|
297
|
+
case 40:
|
|
298
|
+
_context3.next = 42;
|
|
262
299
|
return fs.writeFile(routesServerFile, _code2);
|
|
263
|
-
case
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
300
|
+
case 42:
|
|
301
|
+
loaderEntryFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, 'entry.js');
|
|
302
|
+
loaderIndexFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, 'index.js');
|
|
303
|
+
_context3.next = 46;
|
|
304
|
+
return fs.pathExists(loaderEntryFile);
|
|
305
|
+
case 46:
|
|
306
|
+
if (!_context3.sent) {
|
|
307
|
+
_context3.next = 49;
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
_context3.next = 49;
|
|
311
|
+
return buildLoader(loaderEntryFile, loaderIndexFile);
|
|
312
|
+
case 49:
|
|
313
|
+
_context3.next = 51;
|
|
314
|
+
return fs.pathExists(routesServerFile);
|
|
315
|
+
case 51:
|
|
316
|
+
if (!_context3.sent) {
|
|
317
|
+
_context3.next = 54;
|
|
318
|
+
break;
|
|
319
|
+
}
|
|
320
|
+
_context3.next = 54;
|
|
321
|
+
return buildServerLoader(routesServerFile, outputRoutesServerFile);
|
|
322
|
+
case 54:
|
|
267
323
|
fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME)), _code, 'utf8');
|
|
268
|
-
case
|
|
269
|
-
|
|
324
|
+
case 55:
|
|
325
|
+
_context3.next = 57;
|
|
270
326
|
return hookRunners.modifyEntryImports({
|
|
271
327
|
entrypoint: entrypoint,
|
|
272
328
|
imports: getDefaultImports({
|
|
@@ -277,18 +333,18 @@ export var generateCode = /*#__PURE__*/function () {
|
|
|
277
333
|
internalDirectory: internalDirectory
|
|
278
334
|
})
|
|
279
335
|
});
|
|
280
|
-
case
|
|
281
|
-
_yield$hookRunners$mo2 =
|
|
336
|
+
case 57:
|
|
337
|
+
_yield$hookRunners$mo2 = _context3.sent;
|
|
282
338
|
importStatements = _yield$hookRunners$mo2.imports;
|
|
283
|
-
|
|
339
|
+
_context3.next = 61;
|
|
284
340
|
return hookRunners.modifyEntryRuntimePlugins({
|
|
285
341
|
entrypoint: entrypoint,
|
|
286
342
|
plugins: []
|
|
287
343
|
});
|
|
288
|
-
case
|
|
289
|
-
_yield$hookRunners$mo3 =
|
|
344
|
+
case 61:
|
|
345
|
+
_yield$hookRunners$mo3 = _context3.sent;
|
|
290
346
|
plugins = _yield$hookRunners$mo3.plugins;
|
|
291
|
-
|
|
347
|
+
_context3.next = 65;
|
|
292
348
|
return hookRunners.modifyEntryRenderFunction({
|
|
293
349
|
entrypoint: entrypoint,
|
|
294
350
|
code: templates.renderFunction({
|
|
@@ -297,16 +353,16 @@ export var generateCode = /*#__PURE__*/function () {
|
|
|
297
353
|
fileSystemRoutes: fileSystemRoutes
|
|
298
354
|
})
|
|
299
355
|
});
|
|
300
|
-
case
|
|
301
|
-
_yield$hookRunners$mo4 =
|
|
356
|
+
case 65:
|
|
357
|
+
_yield$hookRunners$mo4 = _context3.sent;
|
|
302
358
|
renderFunction = _yield$hookRunners$mo4.code;
|
|
303
|
-
|
|
359
|
+
_context3.next = 69;
|
|
304
360
|
return hookRunners.modifyEntryExport({
|
|
305
361
|
entrypoint: entrypoint,
|
|
306
362
|
exportStatement: 'export default AppWrapper;'
|
|
307
363
|
});
|
|
308
|
-
case
|
|
309
|
-
_yield$hookRunners$mo5 =
|
|
364
|
+
case 69:
|
|
365
|
+
_yield$hookRunners$mo5 = _context3.sent;
|
|
310
366
|
exportStatement = _yield$hookRunners$mo5.exportStatement;
|
|
311
367
|
code = templates.index({
|
|
312
368
|
mountId: mountId,
|
|
@@ -319,51 +375,51 @@ export var generateCode = /*#__PURE__*/function () {
|
|
|
319
375
|
|
|
320
376
|
// generate entry file.
|
|
321
377
|
if (!config.source.enableAsyncEntry) {
|
|
322
|
-
|
|
378
|
+
_context3.next = 84;
|
|
323
379
|
break;
|
|
324
380
|
}
|
|
325
|
-
|
|
381
|
+
_context3.next = 77;
|
|
326
382
|
return hookRunners.modifyAsyncEntry({
|
|
327
383
|
entrypoint: entrypoint,
|
|
328
384
|
code: "import('./".concat(ENTRY_BOOTSTRAP_FILE_NAME, "');")
|
|
329
385
|
});
|
|
330
|
-
case
|
|
331
|
-
_yield$hookRunners$mo6 =
|
|
386
|
+
case 77:
|
|
387
|
+
_yield$hookRunners$mo6 = _context3.sent;
|
|
332
388
|
asyncEntryCode = _yield$hookRunners$mo6.code;
|
|
333
389
|
fs.outputFileSync(entryFile, asyncEntryCode, 'utf8');
|
|
334
390
|
bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
|
|
335
391
|
fs.outputFileSync(bootstrapFile, code, 'utf8');
|
|
336
|
-
|
|
392
|
+
_context3.next = 85;
|
|
337
393
|
break;
|
|
338
|
-
case
|
|
394
|
+
case 84:
|
|
339
395
|
fs.outputFileSync(entryFile, code, 'utf8');
|
|
340
|
-
case
|
|
396
|
+
case 85:
|
|
341
397
|
case "end":
|
|
342
|
-
return
|
|
398
|
+
return _context3.stop();
|
|
343
399
|
}
|
|
344
400
|
}
|
|
345
|
-
},
|
|
401
|
+
}, _callee3);
|
|
346
402
|
}));
|
|
347
403
|
return _generateEntryCode.apply(this, arguments);
|
|
348
404
|
};
|
|
349
|
-
generateEntryCode = function _generateEntryCode2(
|
|
405
|
+
generateEntryCode = function _generateEntryCode2(_x9) {
|
|
350
406
|
return _generateEntryCode.apply(this, arguments);
|
|
351
407
|
};
|
|
352
408
|
internalDirectory = appContext.internalDirectory, distDirectory = appContext.distDirectory, srcDirectory = appContext.srcDirectory, internalDirAlias = appContext.internalDirAlias, internalSrcAlias = appContext.internalSrcAlias;
|
|
353
409
|
hookRunners = api.useHookRunners();
|
|
354
410
|
islegacy = Boolean(config === null || config === void 0 ? void 0 : (_config$runtime = config.runtime) === null || _config$runtime === void 0 ? void 0 : (_config$runtime$route = _config$runtime.router) === null || _config$runtime$route === void 0 ? void 0 : _config$runtime$route.legacy);
|
|
355
|
-
mountId = config.
|
|
411
|
+
mountId = config.html.mountId;
|
|
356
412
|
getRoutes = islegacy ? getClientRoutesLegacy : getClientRoutes;
|
|
357
|
-
|
|
413
|
+
_context4.next = 9;
|
|
358
414
|
return Promise.all(entrypoints.map(generateEntryCode));
|
|
359
415
|
case 9:
|
|
360
416
|
case "end":
|
|
361
|
-
return
|
|
417
|
+
return _context4.stop();
|
|
362
418
|
}
|
|
363
419
|
}
|
|
364
|
-
},
|
|
420
|
+
}, _callee4);
|
|
365
421
|
}));
|
|
366
|
-
return function generateCode(
|
|
367
|
-
return
|
|
422
|
+
return function generateCode(_x5, _x6, _x7, _x8) {
|
|
423
|
+
return _ref4.apply(this, arguments);
|
|
368
424
|
};
|
|
369
425
|
}();
|
|
@@ -55,7 +55,7 @@ export var getBundleEntry = function getBundleEntry(appContext, config) {
|
|
|
55
55
|
}
|
|
56
56
|
if (!disableDefaultEntries) {
|
|
57
57
|
// find main entry point which server route is '/'.
|
|
58
|
-
var entriesDirAbs = ensureAbsolutePath(appDirectory, entriesDir);
|
|
58
|
+
var entriesDirAbs = ensureAbsolutePath(appDirectory, entriesDir || '');
|
|
59
59
|
var found = defaults.find(function (_ref) {
|
|
60
60
|
var entryName = _ref.entryName,
|
|
61
61
|
entry = _ref.entry,
|
|
@@ -79,7 +79,7 @@ var scanDir = function scanDir(dirs) {
|
|
|
79
79
|
export var getFileSystemEntry = function getFileSystemEntry(appContext, config) {
|
|
80
80
|
var appDirectory = appContext.appDirectory;
|
|
81
81
|
var entriesDir = config.source.entriesDir;
|
|
82
|
-
var src = ensureAbsolutePath(appDirectory, entriesDir);
|
|
82
|
+
var src = ensureAbsolutePath(appDirectory, entriesDir || '');
|
|
83
83
|
if (fs.existsSync(src)) {
|
|
84
84
|
if (fs.statSync(src).isDirectory()) {
|
|
85
85
|
return scanDir(isBundleEntry(src) ? [src] : fs.readdirSync(src).map(function (file) {
|
|
@@ -40,7 +40,7 @@ export var getHtmlTemplate = /*#__PURE__*/function () {
|
|
|
40
40
|
appContext = _ref.appContext, config = _ref.config;
|
|
41
41
|
appDirectory = appContext.appDirectory, internalDirectory = appContext.internalDirectory;
|
|
42
42
|
configDir = config.source.configDir;
|
|
43
|
-
htmlDir = path.resolve(appDirectory, configDir, HTML_PARTIALS_FOLDER);
|
|
43
|
+
htmlDir = path.resolve(appDirectory, configDir || '', HTML_PARTIALS_FOLDER);
|
|
44
44
|
htmlTemplates = {};
|
|
45
45
|
_iterator = _createForOfIteratorHelper(entrypoints);
|
|
46
46
|
_context2.prev = 6;
|
|
@@ -87,9 +87,11 @@ var applyRouteOptions = function applyRouteOptions(original, routeOptions) {
|
|
|
87
87
|
* @returns entrypoint Routes
|
|
88
88
|
*/
|
|
89
89
|
var collectHtmlRoutes = function collectHtmlRoutes(entrypoints, appContext, config) {
|
|
90
|
-
var
|
|
91
|
-
|
|
92
|
-
|
|
90
|
+
var disableHtmlFolder = config.html.disableHtmlFolder,
|
|
91
|
+
_config$output = config.output,
|
|
92
|
+
_config$output$distPa = _config$output.distPath;
|
|
93
|
+
_config$output$distPa = _config$output$distPa === void 0 ? {} : _config$output$distPa;
|
|
94
|
+
var htmlPath = _config$output$distPa.html,
|
|
93
95
|
enableModernMode = _config$output.enableModernMode,
|
|
94
96
|
_config$server = config.server,
|
|
95
97
|
baseUrl = _config$server.baseUrl,
|
|
@@ -136,14 +138,14 @@ var collectStaticRoutes = function collectStaticRoutes(appContext, config) {
|
|
|
136
138
|
var configDir = config.source.configDir,
|
|
137
139
|
_config$server$public = config.server.publicRoutes,
|
|
138
140
|
publicRoutes = _config$server$public === void 0 ? {} : _config$server$public;
|
|
139
|
-
var publicFolder = path.resolve(appDirectory, configDir, 'public');
|
|
141
|
+
var publicFolder = path.resolve(appDirectory, configDir || '', 'public');
|
|
140
142
|
return fs.existsSync(publicFolder) ? walkDirectory(publicFolder).map(function (filePath) {
|
|
141
143
|
var urlPath = "".concat(urlJoin(toPosix(filePath).slice(toPosix(publicFolder).length)));
|
|
142
144
|
return {
|
|
143
145
|
urlPath: publicRoutes[removeLeadingSlash(urlPath)] || urlPath,
|
|
144
146
|
isSPA: true,
|
|
145
147
|
isSSR: false,
|
|
146
|
-
entryPath: toPosix(path.relative(path.resolve(appDirectory, configDir), filePath))
|
|
148
|
+
entryPath: toPosix(path.relative(path.resolve(appDirectory, configDir || ''), filePath))
|
|
147
149
|
};
|
|
148
150
|
}) : [];
|
|
149
151
|
};
|
|
@@ -3,7 +3,6 @@ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
|
3
3
|
import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
|
|
4
4
|
import _asyncToGenerator from "@babel/runtime/helpers/esm/asyncToGenerator";
|
|
5
5
|
import * as path from 'path';
|
|
6
|
-
import { createAsyncWaterfall } from '@modern-js/plugin';
|
|
7
6
|
import { createDebugger, fs, isApiOnly } from '@modern-js/utils';
|
|
8
7
|
import { cloneDeep } from '@modern-js/utils/lodash';
|
|
9
8
|
import { createBuilderForEdenX } from "../builder";
|
|
@@ -11,35 +10,12 @@ import { printInstructions } from "../utils/printInstructions";
|
|
|
11
10
|
import { generateRoutes } from "../utils/routes";
|
|
12
11
|
import { emitResolvedConfig } from "../utils/config";
|
|
13
12
|
import { getCommand } from "../utils/commands";
|
|
13
|
+
import { initialNormalizedConfig } from "../config";
|
|
14
14
|
import { isRouteComponentFile } from "./utils";
|
|
15
15
|
var debug = createDebugger('plugin-analyze');
|
|
16
|
-
export var modifyEntryImports = createAsyncWaterfall();
|
|
17
|
-
export var modifyEntryExport = createAsyncWaterfall();
|
|
18
|
-
export var addRuntimeExports = createAsyncWaterfall();
|
|
19
|
-
export var modifyEntryRuntimePlugins = createAsyncWaterfall();
|
|
20
|
-
export var modifyEntryRenderFunction = createAsyncWaterfall();
|
|
21
|
-
export var modifyAsyncEntry = createAsyncWaterfall();
|
|
22
|
-
export var modifyFileSystemRoutes = createAsyncWaterfall();
|
|
23
|
-
export var modifyServerRoutes = createAsyncWaterfall();
|
|
24
|
-
export var htmlPartials = createAsyncWaterfall();
|
|
25
|
-
export var beforeGenerateRoutes = createAsyncWaterfall();
|
|
26
|
-
export var addDefineTypes = createAsyncWaterfall();
|
|
27
16
|
export default (function () {
|
|
28
17
|
return {
|
|
29
18
|
name: '@modern-js/plugin-analyze',
|
|
30
|
-
registerHook: {
|
|
31
|
-
modifyAsyncEntry: modifyAsyncEntry,
|
|
32
|
-
modifyEntryImports: modifyEntryImports,
|
|
33
|
-
modifyEntryExport: modifyEntryExport,
|
|
34
|
-
modifyEntryRuntimePlugins: modifyEntryRuntimePlugins,
|
|
35
|
-
modifyEntryRenderFunction: modifyEntryRenderFunction,
|
|
36
|
-
modifyFileSystemRoutes: modifyFileSystemRoutes,
|
|
37
|
-
modifyServerRoutes: modifyServerRoutes,
|
|
38
|
-
htmlPartials: htmlPartials,
|
|
39
|
-
addRuntimeExports: addRuntimeExports,
|
|
40
|
-
beforeGenerateRoutes: beforeGenerateRoutes,
|
|
41
|
-
addDefineTypes: addDefineTypes
|
|
42
|
-
},
|
|
43
19
|
setup: function setup(api) {
|
|
44
20
|
var pagesDir = [];
|
|
45
21
|
var originEntrypoints = [];
|
|
@@ -61,7 +37,7 @@ export default (function () {
|
|
|
61
37
|
// FIXME:
|
|
62
38
|
}
|
|
63
39
|
_context6.next = 6;
|
|
64
|
-
return isApiOnly(appContext.appDirectory,
|
|
40
|
+
return isApiOnly(appContext.appDirectory, (_resolvedConfig$sourc = resolvedConfig.source) === null || _resolvedConfig$sourc === void 0 ? void 0 : _resolvedConfig$sourc.entriesDir);
|
|
65
41
|
case 6:
|
|
66
42
|
apiOnly = _context6.sent;
|
|
67
43
|
_context6.next = 9;
|
|
@@ -291,6 +267,14 @@ export default (function () {
|
|
|
291
267
|
watchFiles: function watchFiles() {
|
|
292
268
|
return pagesDir;
|
|
293
269
|
},
|
|
270
|
+
resolvedConfig: function resolvedConfig(_ref6) {
|
|
271
|
+
var resolved = _ref6.resolved;
|
|
272
|
+
var appContext = api.useAppContext();
|
|
273
|
+
var config = initialNormalizedConfig(resolved, appContext);
|
|
274
|
+
return {
|
|
275
|
+
resolved: config
|
|
276
|
+
};
|
|
277
|
+
},
|
|
294
278
|
fileChange: function fileChange(e) {
|
|
295
279
|
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
296
280
|
var appContext, appDirectory, filename, eventType, isPageFile, absoluteFilePath, isRouteComponent, resolvedConfig, _yield$import, generateCode, entrypoints;
|