@modern-js/app-tools 2.0.0-beta.0 → 2.0.0-beta.1
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 +181 -0
- package/dist/js/modern/analyze/generateCode.js +29 -37
- package/dist/js/modern/analyze/getBundleEntry.js +4 -12
- package/dist/js/modern/analyze/getClientRoutes/getRoutes.js +5 -30
- package/dist/js/modern/analyze/getClientRoutes/getRoutesLegacy.js +5 -30
- package/dist/js/modern/analyze/getClientRoutes/utils.js +0 -3
- package/dist/js/modern/analyze/getFileSystemEntry.js +4 -17
- package/dist/js/modern/analyze/getHtmlTemplate.js +2 -9
- package/dist/js/modern/analyze/getServerRoutes.js +15 -32
- package/dist/js/modern/analyze/index.js +79 -22
- package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -4
- package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -2
- package/dist/js/modern/analyze/nestedRoutes.js +8 -33
- package/dist/js/modern/analyze/templates.js +22 -37
- package/dist/js/modern/analyze/utils.js +0 -7
- package/dist/js/modern/builder/builderPlugins/compatModern.js +30 -48
- package/dist/js/modern/builder/createHtmlConfig.js +2 -2
- package/dist/js/modern/builder/createOutputConfig.js +7 -4
- package/dist/js/modern/builder/createSourceConfig.js +0 -11
- package/dist/js/modern/builder/createToolsConfig.js +3 -10
- package/dist/js/modern/builder/index.js +24 -22
- package/dist/js/modern/builder/share.js +0 -4
- package/dist/js/modern/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -8
- package/dist/js/modern/builder/webpackPlugins/htmlBottomTemplate.js +2 -13
- package/dist/js/modern/builder/webpackPlugins/routerPlugin.js +97 -0
- package/dist/js/modern/commands/build.js +6 -46
- package/dist/js/modern/commands/dev.js +4 -16
- package/dist/js/modern/commands/inspect.js +3 -20
- package/dist/js/modern/commands/start.js +0 -2
- package/dist/js/modern/index.js +6 -15
- package/dist/js/modern/utils/config.js +1 -12
- package/dist/js/modern/utils/createServer.js +0 -5
- package/dist/js/modern/utils/getSpecifiedEntries.js +0 -6
- package/dist/js/modern/utils/printInstructions.js +2 -1
- package/dist/js/modern/utils/routes.js +0 -2
- package/dist/js/node/analyze/generateCode.js +29 -60
- package/dist/js/node/analyze/getBundleEntry.js +4 -18
- package/dist/js/node/analyze/getClientRoutes/getRoutes.js +5 -45
- package/dist/js/node/analyze/getClientRoutes/getRoutesLegacy.js +5 -45
- package/dist/js/node/analyze/getClientRoutes/index.js +0 -2
- package/dist/js/node/analyze/getClientRoutes/utils.js +0 -14
- package/dist/js/node/analyze/getFileSystemEntry.js +4 -25
- package/dist/js/node/analyze/getHtmlTemplate.js +2 -23
- package/dist/js/node/analyze/getServerRoutes.js +14 -40
- package/dist/js/node/analyze/index.js +79 -32
- package/dist/js/node/analyze/isDefaultExportFunction.js +0 -12
- package/dist/js/node/analyze/makeLegalIdentifier.js +0 -4
- package/dist/js/node/analyze/nestedRoutes.js +8 -41
- package/dist/js/node/analyze/templates.js +22 -47
- package/dist/js/node/analyze/utils.js +0 -20
- package/dist/js/node/builder/builderPlugins/compatModern.js +30 -59
- package/dist/js/node/builder/createHtmlConfig.js +2 -10
- package/dist/js/node/builder/createOutputConfig.js +7 -6
- package/dist/js/node/builder/createSourceConfig.js +0 -17
- package/dist/js/node/builder/createToolsConfig.js +3 -12
- package/dist/js/node/builder/index.js +24 -36
- package/dist/js/node/builder/share.js +0 -12
- package/dist/js/node/builder/webpackPlugins/htmlAsyncChunkPlugin.js +0 -10
- package/dist/js/node/builder/webpackPlugins/htmlBottomTemplate.js +2 -15
- package/dist/js/node/builder/webpackPlugins/routerPlugin.js +105 -0
- package/dist/js/node/commands/build.js +4 -57
- package/dist/js/node/commands/deploy.js +0 -2
- package/dist/js/node/commands/dev.js +3 -27
- package/dist/js/node/commands/index.js +0 -6
- package/dist/js/node/commands/inspect.js +3 -27
- package/dist/js/node/commands/start.js +0 -11
- package/dist/js/node/exports/server.js +0 -1
- package/dist/js/node/hooks.js +0 -2
- package/dist/js/node/index.js +7 -34
- package/dist/js/node/locale/index.js +0 -4
- package/dist/js/node/utils/commands.js +0 -2
- package/dist/js/node/utils/config.js +1 -25
- package/dist/js/node/utils/createServer.js +0 -15
- package/dist/js/node/utils/getSpecifiedEntries.js +0 -9
- package/dist/js/node/utils/language.js +0 -2
- package/dist/js/node/utils/printInstructions.js +2 -5
- package/dist/js/node/utils/routes.js +0 -5
- package/dist/js/treeshaking/analyze/generateCode.js +57 -100
- package/dist/js/treeshaking/analyze/getBundleEntry.js +11 -19
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutes.js +16 -42
- package/dist/js/treeshaking/analyze/getClientRoutes/getRoutesLegacy.js +16 -42
- package/dist/js/treeshaking/analyze/getClientRoutes/utils.js +0 -3
- package/dist/js/treeshaking/analyze/getFileSystemEntry.js +4 -17
- package/dist/js/treeshaking/analyze/getHtmlTemplate.js +2 -26
- package/dist/js/treeshaking/analyze/getServerRoutes.js +24 -37
- package/dist/js/treeshaking/analyze/index.js +185 -65
- package/dist/js/treeshaking/analyze/isDefaultExportFunction.js +0 -4
- package/dist/js/treeshaking/analyze/makeLegalIdentifier.js +0 -2
- package/dist/js/treeshaking/analyze/nestedRoutes.js +9 -51
- package/dist/js/treeshaking/analyze/templates.js +31 -50
- package/dist/js/treeshaking/analyze/utils.js +7 -14
- package/dist/js/treeshaking/builder/builderPlugins/compatModern.js +40 -59
- package/dist/js/treeshaking/builder/createHtmlConfig.js +15 -15
- package/dist/js/treeshaking/builder/createOutputConfig.js +26 -23
- package/dist/js/treeshaking/builder/createSourceConfig.js +7 -19
- package/dist/js/treeshaking/builder/createToolsConfig.js +16 -21
- package/dist/js/treeshaking/builder/index.js +38 -49
- package/dist/js/treeshaking/builder/share.js +0 -4
- package/dist/js/treeshaking/builder/webpackPlugins/htmlAsyncChunkPlugin.js +1 -13
- package/dist/js/treeshaking/builder/webpackPlugins/htmlBottomTemplate.js +2 -14
- package/dist/js/treeshaking/builder/webpackPlugins/routerPlugin.js +121 -0
- package/dist/js/treeshaking/commands/build.js +26 -111
- package/dist/js/treeshaking/commands/deploy.js +0 -3
- package/dist/js/treeshaking/commands/dev.js +13 -35
- package/dist/js/treeshaking/commands/inspect.js +5 -28
- package/dist/js/treeshaking/commands/start.js +0 -9
- package/dist/js/treeshaking/index.js +2 -39
- package/dist/js/treeshaking/utils/config.js +1 -17
- package/dist/js/treeshaking/utils/createServer.js +0 -10
- package/dist/js/treeshaking/utils/getSpecifiedEntries.js +0 -10
- package/dist/js/treeshaking/utils/printInstructions.js +0 -5
- package/dist/js/treeshaking/utils/routes.js +0 -4
- package/dist/types/analyze/index.d.ts +2 -3
- package/dist/types/analyze/nestedRoutes.d.ts +1 -1
- package/dist/types/analyze/templates.d.ts +3 -1
- package/dist/types/builder/builderPlugins/compatModern.d.ts +0 -1
- package/dist/types/builder/index.d.ts +2 -6
- package/dist/types/builder/webpackPlugins/routerPlugin.d.ts +10 -0
- package/dist/types/commands/inspect.d.ts +1 -4
- package/dist/types/index.d.ts +0 -2
- package/dist/types/utils/config.d.ts +0 -1
- package/package.json +23 -22
- package/dist/js/modern/utils/createCompiler.js +0 -58
- package/dist/js/node/utils/createCompiler.js +0 -75
- package/dist/js/treeshaking/utils/createCompiler.js +0 -117
- package/dist/types/utils/createCompiler.d.ts +0 -12
|
@@ -4,30 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getServerRoutes = void 0;
|
|
7
|
-
|
|
8
7
|
var _path = _interopRequireDefault(require("path"));
|
|
9
|
-
|
|
10
8
|
var _fs = _interopRequireDefault(require("fs"));
|
|
11
|
-
|
|
12
9
|
var _utils = require("@modern-js/utils");
|
|
13
|
-
|
|
14
10
|
var _utils2 = require("./utils");
|
|
15
|
-
|
|
16
11
|
const _excluded = ["path"],
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
_excluded2 = ["path"];
|
|
19
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
20
|
-
|
|
21
14
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
22
|
-
|
|
23
15
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
24
|
-
|
|
25
16
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
26
|
-
|
|
27
17
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
28
|
-
|
|
29
18
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
30
|
-
|
|
31
19
|
/**
|
|
32
20
|
* Add base url for each server route.
|
|
33
21
|
* @param baseUrl - Base url from server.baseUrl
|
|
@@ -47,37 +35,34 @@ const applyBaseUrl = (baseUrl, routes) => {
|
|
|
47
35
|
});
|
|
48
36
|
}
|
|
49
37
|
}
|
|
50
|
-
|
|
51
38
|
return routes;
|
|
52
39
|
};
|
|
40
|
+
|
|
53
41
|
/**
|
|
54
42
|
*
|
|
55
43
|
* @param original - Original entrypoint route info.
|
|
56
44
|
* @param routeOptions - Custom entrypoint route config from server.routes.
|
|
57
45
|
* @returns
|
|
58
46
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
47
|
const applyRouteOptions = (original, routeOptions) => {
|
|
62
48
|
const {
|
|
63
49
|
route,
|
|
64
50
|
disableSpa
|
|
65
51
|
} = routeOptions;
|
|
66
|
-
original.isSPA = !disableSpa;
|
|
52
|
+
original.isSPA = !disableSpa;
|
|
67
53
|
|
|
54
|
+
// set entryPath as dir
|
|
68
55
|
!original.isSPA && (original.entryPath = _path.default.dirname(original.entryPath));
|
|
69
56
|
let routes;
|
|
70
|
-
|
|
71
57
|
if (route) {
|
|
72
58
|
if (Array.isArray(route)) {
|
|
73
59
|
routes = route.map(url => {
|
|
74
60
|
if ((0, _utils.isPlainObject)(url)) {
|
|
75
61
|
const _ref = url,
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
62
|
+
{
|
|
63
|
+
path: urlPath
|
|
64
|
+
} = _ref,
|
|
65
|
+
other = _objectWithoutProperties(_ref, _excluded);
|
|
81
66
|
return _objectSpread(_objectSpread(_objectSpread({}, original), other), {}, {
|
|
82
67
|
urlPath
|
|
83
68
|
});
|
|
@@ -89,11 +74,10 @@ const applyRouteOptions = (original, routeOptions) => {
|
|
|
89
74
|
});
|
|
90
75
|
} else if ((0, _utils.isPlainObject)(route)) {
|
|
91
76
|
const _ref2 = route,
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
77
|
+
{
|
|
78
|
+
path: urlPath
|
|
79
|
+
} = _ref2,
|
|
80
|
+
other = _objectWithoutProperties(_ref2, _excluded2);
|
|
97
81
|
routes = [_objectSpread(_objectSpread(_objectSpread({}, original), other), {}, {
|
|
98
82
|
urlPath
|
|
99
83
|
})];
|
|
@@ -105,17 +89,15 @@ const applyRouteOptions = (original, routeOptions) => {
|
|
|
105
89
|
} else {
|
|
106
90
|
routes = [original];
|
|
107
91
|
}
|
|
108
|
-
|
|
109
92
|
return routes;
|
|
110
93
|
};
|
|
94
|
+
|
|
111
95
|
/**
|
|
112
96
|
* Collect routes from entrypoints.
|
|
113
97
|
* @param entrypoints - Bundle entrypoints.
|
|
114
98
|
* @param config - Normalized user config.
|
|
115
99
|
* @returns entrypoint Routes
|
|
116
100
|
*/
|
|
117
|
-
|
|
118
|
-
|
|
119
101
|
const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
120
102
|
const {
|
|
121
103
|
output: {
|
|
@@ -151,27 +133,24 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
|
151
133
|
enableModernMode: Boolean(enableModernMode),
|
|
152
134
|
bundle: isSSR ? `${_utils.SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : undefined
|
|
153
135
|
};
|
|
154
|
-
|
|
155
136
|
if (routes !== null && routes !== void 0 && routes.hasOwnProperty(entryName)) {
|
|
156
137
|
const routeOptions = (0, _utils.isPlainObject)(routes[entryName]) ? routes[entryName] : {
|
|
157
138
|
route: routes[entryName]
|
|
158
139
|
};
|
|
159
140
|
route = applyRouteOptions(route, routeOptions);
|
|
160
141
|
}
|
|
161
|
-
|
|
162
142
|
return Array.isArray(route) ? [...previous, ...route] : [...previous, route];
|
|
163
143
|
}, []);
|
|
164
144
|
htmlRoutes = applyBaseUrl(baseUrl, htmlRoutes);
|
|
165
145
|
return htmlRoutes;
|
|
166
146
|
};
|
|
147
|
+
|
|
167
148
|
/**
|
|
168
149
|
* Collect static public file routes from config/public folder.
|
|
169
150
|
* @param appContext - App context info.
|
|
170
151
|
* @param config - normalized user config.
|
|
171
152
|
* @returns Static public file routes.
|
|
172
153
|
*/
|
|
173
|
-
|
|
174
|
-
|
|
175
154
|
const collectStaticRoutes = (appContext, config) => {
|
|
176
155
|
const {
|
|
177
156
|
appDirectory
|
|
@@ -184,9 +163,7 @@ const collectStaticRoutes = (appContext, config) => {
|
|
|
184
163
|
publicRoutes = {}
|
|
185
164
|
}
|
|
186
165
|
} = config;
|
|
187
|
-
|
|
188
166
|
const publicFolder = _path.default.resolve(appDirectory, configDir, 'public');
|
|
189
|
-
|
|
190
167
|
return _fs.default.existsSync(publicFolder) ? (0, _utils2.walkDirectory)(publicFolder).map(filePath => {
|
|
191
168
|
const urlPath = `${(0, _utils.urlJoin)(toPosix(filePath).slice(toPosix(publicFolder).length))}`;
|
|
192
169
|
return {
|
|
@@ -197,12 +174,9 @@ const collectStaticRoutes = (appContext, config) => {
|
|
|
197
174
|
};
|
|
198
175
|
}) : [];
|
|
199
176
|
};
|
|
200
|
-
|
|
201
177
|
const getServerRoutes = (entrypoints, {
|
|
202
178
|
appContext,
|
|
203
179
|
config
|
|
204
180
|
}) => [...collectHtmlRoutes(entrypoints, appContext, config), ...collectStaticRoutes(appContext, config)];
|
|
205
|
-
|
|
206
181
|
exports.getServerRoutes = getServerRoutes;
|
|
207
|
-
|
|
208
182
|
const toPosix = pathStr => pathStr.split(_path.default.sep).join(_path.default.posix.sep);
|
|
@@ -4,27 +4,21 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.modifyServerRoutes = exports.modifyFileSystemRoutes = exports.modifyEntryRuntimePlugins = exports.modifyEntryRenderFunction = exports.modifyEntryImports = exports.modifyEntryExport = exports.modifyAsyncEntry = exports.htmlPartials = exports.default = exports.beforeGenerateRoutes = exports.addRuntimeExports = exports.addDefineTypes = void 0;
|
|
7
|
-
|
|
8
7
|
var path = _interopRequireWildcard(require("path"));
|
|
9
|
-
|
|
10
8
|
var _plugin = require("@modern-js/plugin");
|
|
11
|
-
|
|
12
9
|
var _utils = require("@modern-js/utils");
|
|
13
|
-
|
|
14
10
|
var _lodash = require("@modern-js/utils/lodash");
|
|
15
|
-
|
|
11
|
+
var _builder = require("../builder");
|
|
12
|
+
var _printInstructions = require("../utils/printInstructions");
|
|
13
|
+
var _routes = require("../utils/routes");
|
|
14
|
+
var _config = require("../utils/config");
|
|
15
|
+
var _commands = require("../utils/commands");
|
|
16
16
|
var _utils2 = require("./utils");
|
|
17
|
-
|
|
18
17
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
|
|
20
18
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
21
|
-
|
|
22
19
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
23
|
-
|
|
24
20
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
25
|
-
|
|
26
21
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
27
|
-
|
|
28
22
|
const debug = (0, _utils.createDebugger)('plugin-analyze');
|
|
29
23
|
const modifyEntryImports = (0, _plugin.createAsyncWaterfall)();
|
|
30
24
|
exports.modifyEntryImports = modifyEntryImports;
|
|
@@ -48,7 +42,6 @@ const beforeGenerateRoutes = (0, _plugin.createAsyncWaterfall)();
|
|
|
48
42
|
exports.beforeGenerateRoutes = beforeGenerateRoutes;
|
|
49
43
|
const addDefineTypes = (0, _plugin.createAsyncWaterfall)();
|
|
50
44
|
exports.addDefineTypes = addDefineTypes;
|
|
51
|
-
|
|
52
45
|
var _default = () => ({
|
|
53
46
|
name: '@modern-js/plugin-analyze',
|
|
54
47
|
registerHook: {
|
|
@@ -70,19 +63,16 @@ var _default = () => ({
|
|
|
70
63
|
return {
|
|
71
64
|
async prepare() {
|
|
72
65
|
var _resolvedConfig$sourc;
|
|
73
|
-
|
|
74
|
-
const appContext = api.useAppContext();
|
|
66
|
+
let appContext = api.useAppContext();
|
|
75
67
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
76
68
|
const hookRunners = api.useHookRunners();
|
|
77
|
-
|
|
78
69
|
try {
|
|
79
70
|
_utils.fs.emptydirSync(appContext.internalDirectory);
|
|
80
|
-
} catch (_unused) {
|
|
71
|
+
} catch (_unused) {
|
|
72
|
+
// FIXME:
|
|
81
73
|
}
|
|
82
|
-
|
|
83
74
|
const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$sourc = resolvedConfig.source) === null || _resolvedConfig$sourc === void 0 ? void 0 : _resolvedConfig$sourc.entriesDir);
|
|
84
75
|
await hookRunners.addRuntimeExports();
|
|
85
|
-
|
|
86
76
|
if (apiOnly) {
|
|
87
77
|
const {
|
|
88
78
|
routes
|
|
@@ -90,13 +80,13 @@ var _default = () => ({
|
|
|
90
80
|
routes: []
|
|
91
81
|
});
|
|
92
82
|
debug(`server routes: %o`, routes);
|
|
93
|
-
|
|
83
|
+
appContext = _objectSpread(_objectSpread({}, appContext), {}, {
|
|
94
84
|
apiOnly,
|
|
95
85
|
serverRoutes: routes
|
|
96
|
-
})
|
|
86
|
+
});
|
|
87
|
+
api.setAppContext(appContext);
|
|
97
88
|
return;
|
|
98
89
|
}
|
|
99
|
-
|
|
100
90
|
const [{
|
|
101
91
|
getBundleEntry
|
|
102
92
|
}, {
|
|
@@ -119,10 +109,11 @@ var _default = () => ({
|
|
|
119
109
|
routes: initialRoutes
|
|
120
110
|
});
|
|
121
111
|
debug(`server routes: %o`, routes);
|
|
122
|
-
|
|
112
|
+
appContext = _objectSpread(_objectSpread({}, appContext), {}, {
|
|
123
113
|
entrypoints,
|
|
124
114
|
serverRoutes: routes
|
|
125
|
-
})
|
|
115
|
+
});
|
|
116
|
+
api.setAppContext(appContext);
|
|
126
117
|
const nestedRouteEntries = entrypoints.map(point => point.nestedRoutesEntry).filter(Boolean);
|
|
127
118
|
pagesDir = entrypoints.map(point => point.entry).filter(Boolean).concat(nestedRouteEntries);
|
|
128
119
|
originEntrypoints = (0, _lodash.cloneDeep)(entrypoints);
|
|
@@ -134,19 +125,80 @@ var _default = () => ({
|
|
|
134
125
|
debug(`html templates: %o`, htmlTemplates);
|
|
135
126
|
await hookRunners.addDefineTypes();
|
|
136
127
|
debug(`add Define Types`);
|
|
137
|
-
|
|
128
|
+
appContext = _objectSpread(_objectSpread({}, appContext), {}, {
|
|
138
129
|
entrypoints,
|
|
139
130
|
checkedEntries: defaultChecked,
|
|
140
131
|
apiOnly,
|
|
141
132
|
serverRoutes: routes,
|
|
142
133
|
htmlTemplates
|
|
143
|
-
})
|
|
134
|
+
});
|
|
135
|
+
api.setAppContext(appContext);
|
|
136
|
+
const command = (0, _commands.getCommand)();
|
|
137
|
+
const buildCommands = ['dev', 'build', 'inspect', 'deploy'];
|
|
138
|
+
if (buildCommands.includes(command)) {
|
|
139
|
+
const normalizedConfig = api.useResolvedConfigContext();
|
|
140
|
+
const builder = await (0, _builder.createBuilderForEdenX)({
|
|
141
|
+
normalizedConfig,
|
|
142
|
+
appContext,
|
|
143
|
+
compatPluginConfig: {
|
|
144
|
+
async onBeforeBuild({
|
|
145
|
+
bundlerConfigs
|
|
146
|
+
}) {
|
|
147
|
+
const hookRunners = api.useHookRunners();
|
|
148
|
+
await (0, _routes.generateRoutes)(appContext);
|
|
149
|
+
await hookRunners.beforeBuild({
|
|
150
|
+
bundlerConfigs
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
async onAfterBuild({
|
|
154
|
+
stats
|
|
155
|
+
}) {
|
|
156
|
+
const hookRunners = api.useHookRunners();
|
|
157
|
+
await hookRunners.afterBuild({
|
|
158
|
+
stats
|
|
159
|
+
});
|
|
160
|
+
await (0, _config.emitResolvedConfig)(appContext.appDirectory, normalizedConfig);
|
|
161
|
+
},
|
|
162
|
+
async onDevCompileDone({
|
|
163
|
+
isFirstCompile
|
|
164
|
+
}) {
|
|
165
|
+
const hookRunners = api.useHookRunners();
|
|
166
|
+
if (process.stdout.isTTY || isFirstCompile) {
|
|
167
|
+
hookRunners.afterDev();
|
|
168
|
+
if (isFirstCompile) {
|
|
169
|
+
(0, _printInstructions.printInstructions)(hookRunners, appContext, normalizedConfig);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
async onBeforeCreateCompiler({
|
|
174
|
+
bundlerConfigs
|
|
175
|
+
}) {
|
|
176
|
+
const hookRunners = api.useHookRunners();
|
|
177
|
+
// run modernjs framework `beforeCreateCompiler` hook
|
|
178
|
+
await hookRunners.beforeCreateCompiler({
|
|
179
|
+
bundlerConfigs
|
|
180
|
+
});
|
|
181
|
+
},
|
|
182
|
+
async onAfterCreateCompiler({
|
|
183
|
+
compiler
|
|
184
|
+
}) {
|
|
185
|
+
const hookRunners = api.useHookRunners();
|
|
186
|
+
// run modernjs framework afterCreateCompiler hooks
|
|
187
|
+
await hookRunners.afterCreateCompiler({
|
|
188
|
+
compiler
|
|
189
|
+
});
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
appContext = _objectSpread(_objectSpread({}, appContext), {}, {
|
|
194
|
+
builder
|
|
195
|
+
});
|
|
196
|
+
api.setAppContext(appContext);
|
|
197
|
+
}
|
|
144
198
|
},
|
|
145
|
-
|
|
146
199
|
watchFiles() {
|
|
147
200
|
return pagesDir;
|
|
148
201
|
},
|
|
149
|
-
|
|
150
202
|
async fileChange(e) {
|
|
151
203
|
const appContext = api.useAppContext();
|
|
152
204
|
const {
|
|
@@ -156,12 +208,9 @@ var _default = () => ({
|
|
|
156
208
|
filename,
|
|
157
209
|
eventType
|
|
158
210
|
} = e;
|
|
159
|
-
|
|
160
211
|
const isPageFile = name => pagesDir.some(pageDir => name.includes(pageDir));
|
|
161
|
-
|
|
162
212
|
const absoluteFilePath = path.resolve(appDirectory, filename);
|
|
163
213
|
const isRouteComponent = isPageFile(absoluteFilePath) && (0, _utils2.isRouteComponentFile)(absoluteFilePath);
|
|
164
|
-
|
|
165
214
|
if (isRouteComponent && (eventType === 'add' || eventType === 'unlink')) {
|
|
166
215
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
167
216
|
const {
|
|
@@ -171,9 +220,7 @@ var _default = () => ({
|
|
|
171
220
|
generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
172
221
|
}
|
|
173
222
|
}
|
|
174
|
-
|
|
175
223
|
};
|
|
176
224
|
}
|
|
177
225
|
});
|
|
178
|
-
|
|
179
226
|
exports.default = _default;
|
|
@@ -4,28 +4,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.isDefaultExportFunction = void 0;
|
|
7
|
-
|
|
8
7
|
var _fs = _interopRequireDefault(require("fs"));
|
|
9
|
-
|
|
10
8
|
var _parser = require("@babel/parser");
|
|
11
|
-
|
|
12
9
|
var _traverse = _interopRequireDefault(require("@babel/traverse"));
|
|
13
|
-
|
|
14
10
|
var t = _interopRequireWildcard(require("@babel/types"));
|
|
15
|
-
|
|
16
11
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
-
|
|
18
12
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
-
|
|
20
13
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
14
|
const isFunction = node => t.isFunctionDeclaration(node) || t.isFunctionExpression(node) || t.isArrowFunctionExpression(node);
|
|
23
|
-
|
|
24
15
|
const isDefaultExportFunction = file => {
|
|
25
16
|
if (!file || !_fs.default.existsSync(file)) {
|
|
26
17
|
return false;
|
|
27
18
|
}
|
|
28
|
-
|
|
29
19
|
const ast = (0, _parser.parse)(_fs.default.readFileSync(file, 'utf8'), {
|
|
30
20
|
sourceType: 'unambiguous',
|
|
31
21
|
plugins: ['jsx', 'typescript', 'classProperties', 'dynamicImport', 'exportDefaultFrom', 'exportNamespaceFrom', 'decorators-legacy', 'functionBind', 'classPrivateMethods', ['pipelineOperator', {
|
|
@@ -38,7 +28,6 @@ const isDefaultExportFunction = file => {
|
|
|
38
28
|
const {
|
|
39
29
|
declaration
|
|
40
30
|
} = path.node;
|
|
41
|
-
|
|
42
31
|
if (isFunction(declaration)) {
|
|
43
32
|
isExportFunction = true;
|
|
44
33
|
}
|
|
@@ -46,5 +35,4 @@ const isDefaultExportFunction = file => {
|
|
|
46
35
|
});
|
|
47
36
|
return isExportFunction;
|
|
48
37
|
};
|
|
49
|
-
|
|
50
38
|
exports.isDefaultExportFunction = isDefaultExportFunction;
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.makeLegalIdentifier = makeLegalIdentifier;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* modified from https://github.com/rollup/plugins/blob/master/packages/pluginutils
|
|
10
9
|
* license at https://github.com/rollup/plugins/blob/master/LICENSE
|
|
@@ -12,13 +11,10 @@ exports.makeLegalIdentifier = makeLegalIdentifier;
|
|
|
12
11
|
const reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public';
|
|
13
12
|
const builtins = 'arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl';
|
|
14
13
|
const forbidList = new Set(`${reservedWords} ${builtins}`.split(' '));
|
|
15
|
-
|
|
16
14
|
function makeLegalIdentifier(str) {
|
|
17
15
|
const identifier = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(/[^$_a-zA-Z0-9]/g, '_');
|
|
18
|
-
|
|
19
16
|
if (/\d/.test(identifier[0]) || forbidList.has(identifier)) {
|
|
20
17
|
return `_${identifier}`;
|
|
21
18
|
}
|
|
22
|
-
|
|
23
19
|
return identifier || '_';
|
|
24
20
|
}
|
|
@@ -4,62 +4,45 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.walk = void 0;
|
|
7
|
-
|
|
8
7
|
var path = _interopRequireWildcard(require("path"));
|
|
9
|
-
|
|
10
8
|
var _utils = require("@modern-js/utils");
|
|
11
|
-
|
|
12
9
|
var _constants = require("./constants");
|
|
13
|
-
|
|
14
10
|
var _utils2 = require("./utils");
|
|
15
|
-
|
|
16
11
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
-
|
|
18
12
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
-
|
|
20
13
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
21
|
-
|
|
22
14
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
23
|
-
|
|
24
15
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
25
|
-
|
|
26
16
|
const LAYOUT_FILE = 'layout';
|
|
27
17
|
const PAGE_FILE = 'page';
|
|
28
18
|
const LOADING_FILE = 'loading';
|
|
29
19
|
const ERROR_FILE = 'error';
|
|
30
20
|
const LOADER_FILE = 'loader';
|
|
31
21
|
const conventionNames = [LAYOUT_FILE, PAGE_FILE, LOADING_FILE, ERROR_FILE, LOADER_FILE];
|
|
32
|
-
|
|
33
22
|
const replaceDynamicPath = routePath => {
|
|
34
23
|
return routePath.replace(/\[(.*?)\]/g, ':$1');
|
|
35
24
|
};
|
|
36
|
-
|
|
37
|
-
const createIndexRoute = (routeInfo, rootDir, filename) => {
|
|
25
|
+
const createIndexRoute = (routeInfo, rootDir, filename, entryName) => {
|
|
38
26
|
return createRoute(_objectSpread(_objectSpread({}, routeInfo), {}, {
|
|
39
27
|
index: true,
|
|
40
28
|
children: undefined
|
|
41
|
-
}), rootDir, filename);
|
|
29
|
+
}), rootDir, filename, entryName);
|
|
42
30
|
};
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
const id = (0, _utils.getRouteId)(filename, rootDir);
|
|
31
|
+
const createRoute = (routeInfo, rootDir, filename, entryName) => {
|
|
32
|
+
const id = (0, _utils.getRouteId)(filename, rootDir, entryName);
|
|
46
33
|
return _objectSpread(_objectSpread({}, routeInfo), {}, {
|
|
47
34
|
id,
|
|
48
35
|
type: 'nested'
|
|
49
36
|
});
|
|
50
37
|
};
|
|
51
|
-
|
|
52
|
-
const walk = async (dirname, rootDir, alias) => {
|
|
38
|
+
const walk = async (dirname, rootDir, alias, entryName) => {
|
|
53
39
|
if (!(await _utils.fs.pathExists(dirname))) {
|
|
54
40
|
return null;
|
|
55
41
|
}
|
|
56
|
-
|
|
57
42
|
const isDirectory = (await _utils.fs.stat(dirname)).isDirectory();
|
|
58
|
-
|
|
59
43
|
if (!isDirectory) {
|
|
60
44
|
return null;
|
|
61
45
|
}
|
|
62
|
-
|
|
63
46
|
const relativeDir = path.relative(rootDir, dirname);
|
|
64
47
|
const pathSegments = relativeDir.split(path.sep);
|
|
65
48
|
const lastSegment = pathSegments[pathSegments.length - 1];
|
|
@@ -67,65 +50,52 @@ const walk = async (dirname, rootDir, alias) => {
|
|
|
67
50
|
const isPathlessLayout = lastSegment.startsWith('__');
|
|
68
51
|
const isWithoutLayoutPath = lastSegment.includes('.');
|
|
69
52
|
let routePath = isRoot || isPathlessLayout ? '/' : `${lastSegment}`;
|
|
70
|
-
|
|
71
53
|
if (isWithoutLayoutPath) {
|
|
72
54
|
routePath = lastSegment.split('.').join('/');
|
|
73
55
|
}
|
|
74
|
-
|
|
75
56
|
routePath = replaceDynamicPath(routePath);
|
|
76
57
|
const route = {
|
|
77
58
|
path: routePath,
|
|
78
59
|
children: []
|
|
79
60
|
};
|
|
80
61
|
const items = await _utils.fs.readdir(dirname);
|
|
81
|
-
|
|
82
62
|
for (const item of items) {
|
|
83
63
|
const itemPath = path.join(dirname, item);
|
|
84
64
|
const extname = path.extname(item);
|
|
85
65
|
const itemWithoutExt = item.slice(0, -extname.length);
|
|
86
66
|
const isDirectory = (await _utils.fs.stat(itemPath)).isDirectory();
|
|
87
|
-
|
|
88
67
|
if (isDirectory) {
|
|
89
|
-
const childRoute = await walk(itemPath, rootDir, alias);
|
|
90
|
-
|
|
68
|
+
const childRoute = await walk(itemPath, rootDir, alias, entryName);
|
|
91
69
|
if (childRoute) {
|
|
92
70
|
var _route$children;
|
|
93
|
-
|
|
94
71
|
(_route$children = route.children) === null || _route$children === void 0 ? void 0 : _route$children.push(childRoute);
|
|
95
72
|
}
|
|
96
73
|
}
|
|
97
|
-
|
|
98
74
|
if (extname && (!_constants.JS_EXTENSIONS.includes(extname) || !conventionNames.includes(itemWithoutExt))) {
|
|
99
75
|
continue;
|
|
100
76
|
}
|
|
101
|
-
|
|
102
77
|
if (itemWithoutExt === LAYOUT_FILE) {
|
|
103
78
|
route._component = (0, _utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
|
|
104
79
|
}
|
|
105
|
-
|
|
106
80
|
if (itemWithoutExt === PAGE_FILE) {
|
|
107
81
|
var _route$children2;
|
|
108
|
-
|
|
109
82
|
const childRoute = createIndexRoute({
|
|
110
83
|
_component: (0, _utils2.replaceWithAlias)(alias.basename, itemPath, alias.name)
|
|
111
|
-
}, rootDir, itemPath);
|
|
84
|
+
}, rootDir, itemPath, entryName);
|
|
112
85
|
(_route$children2 = route.children) === null || _route$children2 === void 0 ? void 0 : _route$children2.push(childRoute);
|
|
113
86
|
}
|
|
114
|
-
|
|
115
87
|
if (itemWithoutExt === LOADER_FILE) {
|
|
116
88
|
route.loader = (0, _utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
|
|
117
89
|
}
|
|
118
|
-
|
|
119
90
|
if (itemWithoutExt === LOADING_FILE) {
|
|
120
91
|
route.loading = (0, _utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
|
|
121
92
|
}
|
|
122
|
-
|
|
123
93
|
if (itemWithoutExt === ERROR_FILE) {
|
|
124
94
|
route.error = (0, _utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
|
|
125
95
|
}
|
|
126
96
|
}
|
|
97
|
+
const finalRoute = createRoute(route, rootDir, path.join(dirname, `${LAYOUT_FILE}.ts`), entryName);
|
|
127
98
|
|
|
128
|
-
const finalRoute = createRoute(route, rootDir, path.join(dirname, `${LAYOUT_FILE}.ts`));
|
|
129
99
|
/**
|
|
130
100
|
* when the url is /, the __auth/layout.tsx component should not be rendered
|
|
131
101
|
* - routes
|
|
@@ -133,12 +103,9 @@ const walk = async (dirname, rootDir, alias) => {
|
|
|
133
103
|
* - layout.tsx
|
|
134
104
|
* - layout.tsx
|
|
135
105
|
*/
|
|
136
|
-
|
|
137
106
|
if (isPathlessLayout) {
|
|
138
107
|
delete finalRoute.path;
|
|
139
108
|
}
|
|
140
|
-
|
|
141
109
|
return finalRoute;
|
|
142
110
|
};
|
|
143
|
-
|
|
144
111
|
exports.walk = walk;
|