@modern-js/app-tools 2.53.1-alpha.3 → 2.54.0
Sign up to get free protection for your applications and to get access to all the features.
- package/bin/modern.js +0 -2
- package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +2 -1
- package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +2 -2
- package/dist/cjs/commands/build.js +2 -0
- package/dist/cjs/commands/deploy.js +2 -2
- package/dist/cjs/commands/dev.js +19 -5
- package/dist/cjs/commands/index.js +113 -7
- package/dist/cjs/commands/serve.js +19 -5
- package/dist/cjs/hooks.js +5 -0
- package/dist/cjs/index.js +14 -83
- package/dist/cjs/plugins/analyze/constants.js +56 -0
- package/dist/cjs/{analyze → plugins/analyze}/generateCode.js +11 -84
- package/dist/cjs/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
- package/dist/cjs/{analyze → plugins/analyze}/getFileSystemEntry.js +33 -47
- package/dist/cjs/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
- package/dist/cjs/{analyze → plugins/analyze}/index.js +9 -24
- package/dist/cjs/plugins/analyze/templates.js +101 -0
- package/dist/cjs/{analyze → plugins/analyze}/utils.js +12 -55
- package/dist/cjs/plugins/deploy/dependencies/index.js +16 -25
- package/dist/cjs/plugins/deploy/dependencies/utils.js +1 -2
- package/dist/cjs/plugins/deploy/platforms/netlify.js +5 -9
- package/dist/cjs/plugins/deploy/platforms/node.js +5 -13
- package/dist/cjs/plugins/deploy/platforms/vercel.js +5 -9
- package/dist/cjs/{initialize → plugins/initialize}/index.js +1 -1
- package/dist/cjs/plugins/serverBuild.js +10 -4
- package/dist/cjs/utils/createServer.js +1 -1
- package/dist/cjs/utils/{getServerInternalPlugins.js → loadPlugins.js} +18 -11
- package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +4 -1
- package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -2
- package/dist/esm/commands/build.js +16 -9
- package/dist/esm/commands/deploy.js +2 -2
- package/dist/esm/commands/dev.js +13 -9
- package/dist/esm/commands/index.js +411 -3
- package/dist/esm/commands/serve.js +12 -8
- package/dist/esm/hooks.js +5 -0
- package/dist/esm/index.js +12 -394
- package/dist/esm/plugins/analyze/constants.js +24 -0
- package/dist/esm/{analyze → plugins/analyze}/generateCode.js +27 -169
- package/dist/esm/plugins/analyze/getBundleEntry.js +101 -0
- package/dist/esm/plugins/analyze/getFileSystemEntry.js +195 -0
- package/dist/esm/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
- package/dist/esm/{analyze → plugins/analyze}/index.js +42 -70
- package/dist/esm/plugins/analyze/templates.js +22 -0
- package/dist/esm/{analyze → plugins/analyze}/utils.js +13 -135
- package/dist/esm/plugins/deploy/dependencies/index.js +69 -94
- package/dist/esm/plugins/deploy/dependencies/utils.js +3 -4
- package/dist/esm/plugins/deploy/platforms/netlify.js +8 -10
- package/dist/esm/plugins/deploy/platforms/node.js +8 -14
- package/dist/esm/plugins/deploy/platforms/vercel.js +8 -10
- package/dist/esm/{initialize → plugins/initialize}/index.js +1 -1
- package/dist/esm/plugins/serverBuild.js +13 -6
- package/dist/esm/utils/createServer.js +2 -2
- package/dist/esm/utils/loadPlugins.js +64 -0
- package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +2 -1
- package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -2
- package/dist/esm-node/commands/build.js +2 -0
- package/dist/esm-node/commands/deploy.js +2 -2
- package/dist/esm-node/commands/dev.js +11 -7
- package/dist/esm-node/commands/index.js +92 -3
- package/dist/esm-node/commands/serve.js +10 -6
- package/dist/esm-node/hooks.js +5 -0
- package/dist/esm-node/index.js +12 -79
- package/dist/esm-node/plugins/analyze/constants.js +24 -0
- package/dist/esm-node/{analyze → plugins/analyze}/generateCode.js +14 -87
- package/dist/esm-node/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
- package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +75 -0
- package/dist/esm-node/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
- package/dist/esm-node/{analyze → plugins/analyze}/index.js +10 -25
- package/dist/esm-node/plugins/analyze/templates.js +75 -0
- package/dist/esm-node/{analyze → plugins/analyze}/utils.js +13 -52
- package/dist/esm-node/plugins/deploy/dependencies/index.js +18 -27
- package/dist/esm-node/plugins/deploy/dependencies/utils.js +1 -2
- package/dist/esm-node/plugins/deploy/platforms/netlify.js +6 -10
- package/dist/esm-node/plugins/deploy/platforms/node.js +6 -14
- package/dist/esm-node/plugins/deploy/platforms/vercel.js +6 -10
- package/dist/esm-node/{initialize → plugins/initialize}/index.js +1 -1
- package/dist/esm-node/plugins/serverBuild.js +11 -5
- package/dist/esm-node/utils/createServer.js +2 -2
- package/dist/esm-node/utils/loadPlugins.js +21 -0
- package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
- package/dist/types/commands/index.d.ts +10 -3
- package/dist/types/config/initialize/inits.d.ts +1 -1
- package/dist/types/exports/server.d.ts +4 -0
- package/dist/types/index.d.ts +2 -5
- package/dist/types/plugins/analyze/constants.d.ts +9 -0
- package/dist/types/{analyze → plugins/analyze}/generateCode.d.ts +1 -1
- package/dist/types/plugins/analyze/getBundleEntry.d.ts +4 -0
- package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +5 -0
- package/dist/types/{analyze → plugins/analyze}/getHtmlTemplate.d.ts +1 -1
- package/dist/types/{analyze → plugins/analyze}/getServerRoutes.d.ts +1 -1
- package/dist/types/{analyze → plugins/analyze}/index.d.ts +1 -1
- package/dist/types/plugins/analyze/templates.d.ts +19 -0
- package/dist/types/{analyze → plugins/analyze}/utils.d.ts +4 -6
- package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -9
- package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -7
- package/dist/types/{initialize → plugins/initialize}/index.d.ts +1 -1
- package/dist/types/types/hooks.d.ts +11 -1
- package/dist/types/utils/loadPlugins.d.ts +5 -0
- package/package.json +22 -30
- package/dist/cjs/analyze/constants.js +0 -122
- package/dist/cjs/analyze/getClientRoutes/getRoutes.js +0 -197
- package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +0 -195
- package/dist/cjs/analyze/getClientRoutes/index.js +0 -31
- package/dist/cjs/analyze/getClientRoutes/utils.js +0 -59
- package/dist/cjs/analyze/makeLegalIdentifier.js +0 -37
- package/dist/cjs/analyze/nestedRoutes.js +0 -295
- package/dist/cjs/analyze/templates.js +0 -444
- package/dist/cjs/plugins/deploy/exports.js +0 -28
- package/dist/esm/analyze/constants.js +0 -76
- package/dist/esm/analyze/getBundleEntry.js +0 -75
- package/dist/esm/analyze/getClientRoutes/getRoutes.js +0 -185
- package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +0 -183
- package/dist/esm/analyze/getClientRoutes/index.js +0 -6
- package/dist/esm/analyze/getClientRoutes/utils.js +0 -28
- package/dist/esm/analyze/getFileSystemEntry.js +0 -113
- package/dist/esm/analyze/makeLegalIdentifier.js +0 -15
- package/dist/esm/analyze/nestedRoutes.js +0 -398
- package/dist/esm/analyze/templates.js +0 -435
- package/dist/esm/plugins/deploy/exports.js +0 -4
- package/dist/esm/utils/getServerInternalPlugins.js +0 -40
- package/dist/esm-node/analyze/constants.js +0 -76
- package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +0 -163
- package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +0 -161
- package/dist/esm-node/analyze/getClientRoutes/index.js +0 -6
- package/dist/esm-node/analyze/getClientRoutes/utils.js +0 -22
- package/dist/esm-node/analyze/getFileSystemEntry.js +0 -89
- package/dist/esm-node/analyze/makeLegalIdentifier.js +0 -13
- package/dist/esm-node/analyze/nestedRoutes.js +0 -259
- package/dist/esm-node/analyze/templates.js +0 -405
- package/dist/esm-node/plugins/deploy/exports.js +0 -4
- package/dist/esm-node/utils/getServerInternalPlugins.js +0 -15
- package/dist/js/modern/analyze/constants.js +0 -15
- package/dist/js/modern/analyze/generateCode.js +0 -179
- package/dist/js/modern/analyze/getBundleEntry.js +0 -75
- package/dist/js/modern/analyze/getClientRoutes.js +0 -219
- package/dist/js/modern/analyze/getFileSystemEntry.js +0 -74
- package/dist/js/modern/analyze/getHtmlTemplate.js +0 -82
- package/dist/js/modern/analyze/getServerRoutes.js +0 -192
- package/dist/js/modern/analyze/index.js +0 -148
- package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -32
- package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -16
- package/dist/js/modern/analyze/templates.js +0 -88
- package/dist/js/modern/analyze/utils.js +0 -92
- package/dist/js/modern/commands/build.js +0 -154
- package/dist/js/modern/commands/deploy.js +0 -5
- package/dist/js/modern/commands/dev.js +0 -95
- package/dist/js/modern/commands/index.js +0 -3
- package/dist/js/modern/commands/inspect.js +0 -69
- package/dist/js/modern/commands/start.js +0 -31
- package/dist/js/modern/exports/server.js +0 -1
- package/dist/js/modern/hooks.js +0 -21
- package/dist/js/modern/index.js +0 -109
- package/dist/js/modern/locale/en.js +0 -35
- package/dist/js/modern/locale/index.js +0 -9
- package/dist/js/modern/locale/zh.js +0 -35
- package/dist/js/modern/utils/config.js +0 -78
- package/dist/js/modern/utils/createCompiler.js +0 -61
- package/dist/js/modern/utils/createServer.js +0 -18
- package/dist/js/modern/utils/getSpecifiedEntries.js +0 -36
- package/dist/js/modern/utils/language.js +0 -5
- package/dist/js/modern/utils/printInstructions.js +0 -11
- package/dist/js/modern/utils/routes.js +0 -15
- package/dist/js/modern/utils/types.js +0 -0
- package/dist/js/node/analyze/constants.js +0 -36
- package/dist/js/node/analyze/generateCode.js +0 -208
- package/dist/js/node/analyze/getBundleEntry.js +0 -89
- package/dist/js/node/analyze/getClientRoutes.js +0 -241
- package/dist/js/node/analyze/getFileSystemEntry.js +0 -90
- package/dist/js/node/analyze/getHtmlTemplate.js +0 -106
- package/dist/js/node/analyze/getServerRoutes.js +0 -208
- package/dist/js/node/analyze/index.js +0 -178
- package/dist/js/node/analyze/isDefaultExportFunction.js +0 -50
- package/dist/js/node/analyze/makeLegalIdentifier.js +0 -24
- package/dist/js/node/analyze/templates.js +0 -106
- package/dist/js/node/analyze/utils.js +0 -113
- package/dist/js/node/commands/build.js +0 -174
- package/dist/js/node/commands/deploy.js +0 -14
- package/dist/js/node/commands/dev.js +0 -120
- package/dist/js/node/commands/index.js +0 -44
- package/dist/js/node/commands/inspect.js +0 -98
- package/dist/js/node/commands/start.js +0 -47
- package/dist/js/node/exports/server.js +0 -13
- package/dist/js/node/hooks.js +0 -39
- package/dist/js/node/index.js +0 -141
- package/dist/js/node/locale/en.js +0 -42
- package/dist/js/node/locale/index.js +0 -20
- package/dist/js/node/locale/zh.js +0 -42
- package/dist/js/node/utils/config.js +0 -103
- package/dist/js/node/utils/createCompiler.js +0 -81
- package/dist/js/node/utils/createServer.js +0 -35
- package/dist/js/node/utils/getSpecifiedEntries.js +0 -46
- package/dist/js/node/utils/language.js +0 -13
- package/dist/js/node/utils/printInstructions.js +0 -22
- package/dist/js/node/utils/routes.js +0 -25
- package/dist/js/node/utils/types.js +0 -0
- package/dist/types/analyze/constants.d.ts +0 -42
- package/dist/types/analyze/getBundleEntry.d.ts +0 -3
- package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +0 -8
- package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +0 -9
- package/dist/types/analyze/getClientRoutes/index.d.ts +0 -2
- package/dist/types/analyze/getClientRoutes/utils.d.ts +0 -5
- package/dist/types/analyze/getFileSystemEntry.d.ts +0 -4
- package/dist/types/analyze/makeLegalIdentifier.d.ts +0 -1
- package/dist/types/analyze/nestedRoutes.d.ts +0 -7
- package/dist/types/analyze/templates.d.ts +0 -30
- package/dist/types/plugins/deploy/exports.d.ts +0 -1
- package/dist/types/utils/getServerInternalPlugins.d.ts +0 -2
- /package/dist/cjs/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
- /package/dist/cjs/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
- /package/dist/esm/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
- /package/dist/esm/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
- /package/dist/esm-node/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
- /package/dist/esm-node/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
- /package/dist/types/{analyze → plugins/analyze}/isDefaultExportFunction.d.ts +0 -0
@@ -1,192 +0,0 @@
|
|
1
|
-
const _excluded = ["path"],
|
2
|
-
_excluded2 = ["path"];
|
3
|
-
|
4
|
-
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; }
|
5
|
-
|
6
|
-
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; }
|
7
|
-
|
8
|
-
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; }
|
9
|
-
|
10
|
-
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; }
|
11
|
-
|
12
|
-
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; }
|
13
|
-
|
14
|
-
import path from 'path';
|
15
|
-
import fs from 'fs';
|
16
|
-
import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, MAIN_ENTRY_NAME, removeTailSlash } from '@modern-js/utils';
|
17
|
-
import { walkDirectory } from "./utils";
|
18
|
-
/**
|
19
|
-
* Add base url for each server route.
|
20
|
-
* @param baseUrl - Base url from server.baseUrl
|
21
|
-
* @param routes - Server routes.
|
22
|
-
* @returns Server routes with baseUrl prefixed.
|
23
|
-
*/
|
24
|
-
|
25
|
-
const applyBaseUrl = (baseUrl, routes) => {
|
26
|
-
if (baseUrl) {
|
27
|
-
if (Array.isArray(baseUrl)) {
|
28
|
-
return baseUrl.reduce((previous, current) => [...previous, ...applyBaseUrl(current, routes)], []);
|
29
|
-
} else {
|
30
|
-
return routes.map(route => {
|
31
|
-
const urlPath = urlJoin(baseUrl, route.urlPath);
|
32
|
-
return _objectSpread(_objectSpread({}, route), {}, {
|
33
|
-
urlPath: urlPath === '/' ? urlPath : removeTailSlash(urlPath)
|
34
|
-
});
|
35
|
-
});
|
36
|
-
}
|
37
|
-
}
|
38
|
-
|
39
|
-
return routes;
|
40
|
-
};
|
41
|
-
/**
|
42
|
-
*
|
43
|
-
* @param original - Original entrypoint route info.
|
44
|
-
* @param routeOptions - Custom entrypoint route config from server.routes.
|
45
|
-
* @returns
|
46
|
-
*/
|
47
|
-
|
48
|
-
|
49
|
-
const applyRouteOptions = (original, routeOptions) => {
|
50
|
-
const {
|
51
|
-
route,
|
52
|
-
disableSpa
|
53
|
-
} = routeOptions;
|
54
|
-
original.isSPA = !disableSpa; // set entryPath as dir
|
55
|
-
|
56
|
-
!original.isSPA && (original.entryPath = path.dirname(original.entryPath));
|
57
|
-
let routes;
|
58
|
-
|
59
|
-
if (route) {
|
60
|
-
if (Array.isArray(route)) {
|
61
|
-
routes = route.map(url => {
|
62
|
-
if (isPlainObject(url)) {
|
63
|
-
const _ref = url,
|
64
|
-
{
|
65
|
-
path: urlPath
|
66
|
-
} = _ref,
|
67
|
-
other = _objectWithoutProperties(_ref, _excluded);
|
68
|
-
|
69
|
-
return _objectSpread(_objectSpread(_objectSpread({}, original), other), {}, {
|
70
|
-
urlPath
|
71
|
-
});
|
72
|
-
} else {
|
73
|
-
return _objectSpread(_objectSpread({}, original), {}, {
|
74
|
-
urlPath: url
|
75
|
-
});
|
76
|
-
}
|
77
|
-
});
|
78
|
-
} else if (isPlainObject(route)) {
|
79
|
-
const _ref2 = route,
|
80
|
-
{
|
81
|
-
path: urlPath
|
82
|
-
} = _ref2,
|
83
|
-
other = _objectWithoutProperties(_ref2, _excluded2);
|
84
|
-
|
85
|
-
routes = [_objectSpread(_objectSpread(_objectSpread({}, original), other), {}, {
|
86
|
-
urlPath
|
87
|
-
})];
|
88
|
-
} else {
|
89
|
-
routes = [_objectSpread(_objectSpread({}, original), {}, {
|
90
|
-
urlPath: route
|
91
|
-
})];
|
92
|
-
}
|
93
|
-
} else {
|
94
|
-
routes = [original];
|
95
|
-
}
|
96
|
-
|
97
|
-
return routes;
|
98
|
-
};
|
99
|
-
/**
|
100
|
-
* Collect routes from entrypoints.
|
101
|
-
* @param entrypoints - Bundle entrypoints.
|
102
|
-
* @param config - Normalized user config.
|
103
|
-
* @returns entrypoint Routes
|
104
|
-
*/
|
105
|
-
|
106
|
-
|
107
|
-
const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
108
|
-
const {
|
109
|
-
output: {
|
110
|
-
htmlPath,
|
111
|
-
disableHtmlFolder,
|
112
|
-
enableModernMode
|
113
|
-
},
|
114
|
-
server: {
|
115
|
-
baseUrl,
|
116
|
-
routes,
|
117
|
-
ssr,
|
118
|
-
ssrByEntries
|
119
|
-
}
|
120
|
-
} = config;
|
121
|
-
const {
|
122
|
-
packageName
|
123
|
-
} = appContext;
|
124
|
-
let htmlRoutes = entrypoints.reduce((previous, {
|
125
|
-
entryName
|
126
|
-
}) => {
|
127
|
-
const entryOptions = getEntryOptions(entryName, ssr, ssrByEntries, packageName);
|
128
|
-
const isSSR = Boolean(entryOptions);
|
129
|
-
const {
|
130
|
-
resHeaders
|
131
|
-
} = (routes === null || routes === void 0 ? void 0 : routes[entryName]) || {};
|
132
|
-
let route = {
|
133
|
-
urlPath: `/${entryName === MAIN_ENTRY_NAME ? '' : entryName}`,
|
134
|
-
entryName,
|
135
|
-
entryPath: removeLeadingSlash(path.posix.normalize(`${htmlPath}/${entryName}${disableHtmlFolder ? '.html' : '/index.html'}`)),
|
136
|
-
isSPA: true,
|
137
|
-
isSSR,
|
138
|
-
responseHeaders: resHeaders,
|
139
|
-
enableModernMode: Boolean(enableModernMode),
|
140
|
-
bundle: isSSR ? `${SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : undefined
|
141
|
-
};
|
142
|
-
|
143
|
-
if (routes !== null && routes !== void 0 && routes.hasOwnProperty(entryName)) {
|
144
|
-
const routeOptions = isPlainObject(routes[entryName]) ? routes[entryName] : {
|
145
|
-
route: routes[entryName]
|
146
|
-
};
|
147
|
-
route = applyRouteOptions(route, routeOptions);
|
148
|
-
}
|
149
|
-
|
150
|
-
return Array.isArray(route) ? [...previous, ...route] : [...previous, route];
|
151
|
-
}, []);
|
152
|
-
htmlRoutes = applyBaseUrl(baseUrl, htmlRoutes);
|
153
|
-
return htmlRoutes;
|
154
|
-
};
|
155
|
-
/**
|
156
|
-
* Collect static public file routes from config/public folder.
|
157
|
-
* @param appContext - App context info.
|
158
|
-
* @param config - normalized user config.
|
159
|
-
* @returns Static public file routes.
|
160
|
-
*/
|
161
|
-
|
162
|
-
|
163
|
-
const collectStaticRoutes = (appContext, config) => {
|
164
|
-
const {
|
165
|
-
appDirectory
|
166
|
-
} = appContext;
|
167
|
-
const {
|
168
|
-
source: {
|
169
|
-
configDir
|
170
|
-
},
|
171
|
-
server: {
|
172
|
-
publicRoutes = {}
|
173
|
-
}
|
174
|
-
} = config;
|
175
|
-
const publicFolder = path.resolve(appDirectory, configDir, 'public');
|
176
|
-
return fs.existsSync(publicFolder) ? walkDirectory(publicFolder).map(filePath => {
|
177
|
-
const urlPath = `${urlJoin(toPosix(filePath).slice(toPosix(publicFolder).length))}`;
|
178
|
-
return {
|
179
|
-
urlPath: publicRoutes[removeLeadingSlash(urlPath)] || urlPath,
|
180
|
-
isSPA: true,
|
181
|
-
isSSR: false,
|
182
|
-
entryPath: toPosix(path.relative(path.resolve(appDirectory, configDir), filePath))
|
183
|
-
};
|
184
|
-
}) : [];
|
185
|
-
};
|
186
|
-
|
187
|
-
export const getServerRoutes = (entrypoints, {
|
188
|
-
appContext,
|
189
|
-
config
|
190
|
-
}) => [...collectHtmlRoutes(entrypoints, appContext, config), ...collectStaticRoutes(appContext, config)];
|
191
|
-
|
192
|
-
const toPosix = pathStr => pathStr.split(path.sep).join(path.posix.sep);
|
@@ -1,148 +0,0 @@
|
|
1
|
-
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; }
|
2
|
-
|
3
|
-
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; }
|
4
|
-
|
5
|
-
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; }
|
6
|
-
|
7
|
-
import * as path from 'path';
|
8
|
-
import { createAsyncWaterfall } from '@modern-js/plugin';
|
9
|
-
import { createDebugger, fs, isApiOnly } from '@modern-js/utils';
|
10
|
-
import { cloneDeep } from '@modern-js/utils/lodash';
|
11
|
-
import { isRouteComponentFile } from "./utils";
|
12
|
-
const debug = createDebugger('plugin-analyze');
|
13
|
-
export const modifyEntryImports = createAsyncWaterfall();
|
14
|
-
export const modifyEntryExport = createAsyncWaterfall();
|
15
|
-
export const addRuntimeExports = createAsyncWaterfall();
|
16
|
-
export const modifyEntryRuntimePlugins = createAsyncWaterfall();
|
17
|
-
export const modifyEntryRenderFunction = createAsyncWaterfall();
|
18
|
-
export const modifyAsyncEntry = createAsyncWaterfall();
|
19
|
-
export const modifyFileSystemRoutes = createAsyncWaterfall();
|
20
|
-
export const modifyServerRoutes = createAsyncWaterfall();
|
21
|
-
export const htmlPartials = createAsyncWaterfall();
|
22
|
-
export const beforeGenerateRoutes = createAsyncWaterfall();
|
23
|
-
export const addDefineTypes = createAsyncWaterfall();
|
24
|
-
export default (() => ({
|
25
|
-
name: '@modern-js/plugin-analyze',
|
26
|
-
registerHook: {
|
27
|
-
modifyAsyncEntry,
|
28
|
-
modifyEntryImports,
|
29
|
-
modifyEntryExport,
|
30
|
-
modifyEntryRuntimePlugins,
|
31
|
-
modifyEntryRenderFunction,
|
32
|
-
modifyFileSystemRoutes,
|
33
|
-
modifyServerRoutes,
|
34
|
-
htmlPartials,
|
35
|
-
addRuntimeExports,
|
36
|
-
beforeGenerateRoutes,
|
37
|
-
addDefineTypes
|
38
|
-
},
|
39
|
-
setup: api => {
|
40
|
-
let pagesDir = [];
|
41
|
-
let originEntrypoints = [];
|
42
|
-
return {
|
43
|
-
async prepare() {
|
44
|
-
var _resolvedConfig$sourc;
|
45
|
-
|
46
|
-
const appContext = api.useAppContext();
|
47
|
-
const resolvedConfig = api.useResolvedConfigContext();
|
48
|
-
const hookRunners = api.useHookRunners();
|
49
|
-
|
50
|
-
try {
|
51
|
-
fs.emptydirSync(appContext.internalDirectory);
|
52
|
-
} catch (_unused) {// FIXME:
|
53
|
-
}
|
54
|
-
|
55
|
-
const apiOnly = await isApiOnly(appContext.appDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$sourc = resolvedConfig.source) === null || _resolvedConfig$sourc === void 0 ? void 0 : _resolvedConfig$sourc.entriesDir);
|
56
|
-
await hookRunners.addRuntimeExports();
|
57
|
-
|
58
|
-
if (apiOnly) {
|
59
|
-
const {
|
60
|
-
routes
|
61
|
-
} = await hookRunners.modifyServerRoutes({
|
62
|
-
routes: []
|
63
|
-
});
|
64
|
-
debug(`server routes: %o`, routes);
|
65
|
-
api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
|
66
|
-
apiOnly,
|
67
|
-
serverRoutes: routes
|
68
|
-
}));
|
69
|
-
return;
|
70
|
-
}
|
71
|
-
|
72
|
-
const [{
|
73
|
-
getBundleEntry
|
74
|
-
}, {
|
75
|
-
getServerRoutes
|
76
|
-
}, {
|
77
|
-
generateCode
|
78
|
-
}, {
|
79
|
-
getHtmlTemplate
|
80
|
-
}] = await Promise.all([import("./getBundleEntry"), import("./getServerRoutes"), import("./generateCode"), import("./getHtmlTemplate")]);
|
81
|
-
const entrypoints = getBundleEntry(appContext, resolvedConfig);
|
82
|
-
const defaultChecked = entrypoints.map(point => point.entryName);
|
83
|
-
debug(`entrypoints: %o`, entrypoints);
|
84
|
-
const initialRoutes = getServerRoutes(entrypoints, {
|
85
|
-
appContext,
|
86
|
-
config: resolvedConfig
|
87
|
-
});
|
88
|
-
const {
|
89
|
-
routes
|
90
|
-
} = await hookRunners.modifyServerRoutes({
|
91
|
-
routes: initialRoutes
|
92
|
-
});
|
93
|
-
debug(`server routes: %o`, routes);
|
94
|
-
api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
|
95
|
-
entrypoints,
|
96
|
-
serverRoutes: routes
|
97
|
-
}));
|
98
|
-
pagesDir = entrypoints.map(point => point.entry);
|
99
|
-
originEntrypoints = cloneDeep(entrypoints);
|
100
|
-
await generateCode(appContext, resolvedConfig, entrypoints, api);
|
101
|
-
const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
|
102
|
-
appContext,
|
103
|
-
config: resolvedConfig
|
104
|
-
});
|
105
|
-
debug(`html templates: %o`, htmlTemplates);
|
106
|
-
await hookRunners.addDefineTypes();
|
107
|
-
debug(`add Define Types`);
|
108
|
-
api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
|
109
|
-
entrypoints,
|
110
|
-
checkedEntries: defaultChecked,
|
111
|
-
apiOnly,
|
112
|
-
serverRoutes: routes,
|
113
|
-
htmlTemplates
|
114
|
-
}));
|
115
|
-
},
|
116
|
-
|
117
|
-
watchFiles() {
|
118
|
-
return pagesDir;
|
119
|
-
},
|
120
|
-
|
121
|
-
async fileChange(e) {
|
122
|
-
const appContext = api.useAppContext();
|
123
|
-
const {
|
124
|
-
appDirectory
|
125
|
-
} = appContext;
|
126
|
-
const {
|
127
|
-
filename,
|
128
|
-
eventType
|
129
|
-
} = e;
|
130
|
-
|
131
|
-
const isPageFile = name => pagesDir.some(pageDir => name.includes(pageDir));
|
132
|
-
|
133
|
-
const absoluteFilePath = path.resolve(appDirectory, filename);
|
134
|
-
const isRouteComponent = isPageFile(absoluteFilePath) && isRouteComponentFile(absoluteFilePath);
|
135
|
-
|
136
|
-
if (isRouteComponent && (eventType === 'add' || eventType === 'unlink')) {
|
137
|
-
const resolvedConfig = api.useResolvedConfigContext();
|
138
|
-
const {
|
139
|
-
generateCode
|
140
|
-
} = await import("./generateCode");
|
141
|
-
const entrypoints = cloneDeep(originEntrypoints);
|
142
|
-
generateCode(appContext, resolvedConfig, entrypoints, api);
|
143
|
-
}
|
144
|
-
}
|
145
|
-
|
146
|
-
};
|
147
|
-
}
|
148
|
-
}));
|
@@ -1,32 +0,0 @@
|
|
1
|
-
import fs from 'fs';
|
2
|
-
import { parse } from '@babel/parser';
|
3
|
-
import traverse from '@babel/traverse';
|
4
|
-
import * as t from '@babel/types';
|
5
|
-
|
6
|
-
const isFunction = node => t.isFunctionDeclaration(node) || t.isFunctionExpression(node) || t.isArrowFunctionExpression(node);
|
7
|
-
|
8
|
-
export const isDefaultExportFunction = file => {
|
9
|
-
if (!file || !fs.existsSync(file)) {
|
10
|
-
return false;
|
11
|
-
}
|
12
|
-
|
13
|
-
const ast = parse(fs.readFileSync(file, 'utf8'), {
|
14
|
-
sourceType: 'unambiguous',
|
15
|
-
plugins: ['jsx', 'typescript', 'classProperties', 'dynamicImport', 'exportDefaultFrom', 'exportNamespaceFrom', 'decorators-legacy', 'functionBind', 'classPrivateMethods', ['pipelineOperator', {
|
16
|
-
proposal: 'minimal'
|
17
|
-
}], 'optionalChaining', 'optionalCatchBinding', 'objectRestSpread', 'numericSeparator']
|
18
|
-
});
|
19
|
-
let isExportFunction = false;
|
20
|
-
traverse(ast, {
|
21
|
-
ExportDefaultDeclaration: path => {
|
22
|
-
const {
|
23
|
-
declaration
|
24
|
-
} = path.node;
|
25
|
-
|
26
|
-
if (isFunction(declaration)) {
|
27
|
-
isExportFunction = true;
|
28
|
-
}
|
29
|
-
}
|
30
|
-
});
|
31
|
-
return isExportFunction;
|
32
|
-
};
|
@@ -1,16 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* modified from https://github.com/rollup/plugins/blob/master/packages/pluginutils
|
3
|
-
* license at https://github.com/rollup/plugins/blob/master/LICENSE
|
4
|
-
*/
|
5
|
-
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';
|
6
|
-
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';
|
7
|
-
const forbidList = new Set(`${reservedWords} ${builtins}`.split(' '));
|
8
|
-
export function makeLegalIdentifier(str) {
|
9
|
-
const identifier = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(/[^$_a-zA-Z0-9]/g, '_');
|
10
|
-
|
11
|
-
if (/\d/.test(identifier[0]) || forbidList.has(identifier)) {
|
12
|
-
return `_${identifier}`;
|
13
|
-
}
|
14
|
-
|
15
|
-
return identifier || '_';
|
16
|
-
}
|
@@ -1,88 +0,0 @@
|
|
1
|
-
export const index = ({
|
2
|
-
mountId,
|
3
|
-
imports,
|
4
|
-
renderFunction,
|
5
|
-
exportStatement
|
6
|
-
}) => `
|
7
|
-
const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
|
8
|
-
const IS_REACT18 = process.env.IS_REACT18 === 'true';
|
9
|
-
const MOUNT_ID = '${mountId}';
|
10
|
-
|
11
|
-
${imports}
|
12
|
-
|
13
|
-
let AppWrapper = null;
|
14
|
-
|
15
|
-
let root = null;
|
16
|
-
|
17
|
-
function render() {
|
18
|
-
${renderFunction}
|
19
|
-
}
|
20
|
-
|
21
|
-
AppWrapper = render();
|
22
|
-
|
23
|
-
${exportStatement};
|
24
|
-
`;
|
25
|
-
export const renderFunction = ({
|
26
|
-
plugins,
|
27
|
-
customBootstrap,
|
28
|
-
fileSystemRoutes
|
29
|
-
}) => `
|
30
|
-
AppWrapper = createApp({
|
31
|
-
plugins: [
|
32
|
-
${plugins.map(({
|
33
|
-
name,
|
34
|
-
options,
|
35
|
-
args
|
36
|
-
}) => `${name}({...${options}, ...App?.config?.${args || name}}),`).join('\n')}
|
37
|
-
]
|
38
|
-
})(${fileSystemRoutes ? '' : `App`})
|
39
|
-
|
40
|
-
if (IS_BROWSER) {
|
41
|
-
${customBootstrap ? `customBootstrap(AppWrapper);` : `bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM);`}
|
42
|
-
}
|
43
|
-
|
44
|
-
return AppWrapper
|
45
|
-
`;
|
46
|
-
export const html = partials => `
|
47
|
-
<!DOCTYPE html>
|
48
|
-
<html>
|
49
|
-
<head>
|
50
|
-
<%= meta %>
|
51
|
-
<title><%= title %></title>
|
52
|
-
|
53
|
-
${partials.top.join('\n')}
|
54
|
-
|
55
|
-
<script>
|
56
|
-
window.__assetPrefix__ = '<%= assetPrefix %>';
|
57
|
-
</script>
|
58
|
-
${partials.head.join('\n')}
|
59
|
-
|
60
|
-
<!--<?- chunksMap.css ?>-->
|
61
|
-
</head>
|
62
|
-
|
63
|
-
<body>
|
64
|
-
<noscript>
|
65
|
-
We're sorry but react app doesn't work properly without JavaScript enabled. Please enable it to continue.
|
66
|
-
</noscript>
|
67
|
-
<div id="<%= mountId %>"><!--<?- html ?>--></div>
|
68
|
-
${partials.body.join('\n')}
|
69
|
-
<!--<?- chunksMap.js ?>-->
|
70
|
-
<!--<?- SSRDataScript ?>-->
|
71
|
-
<!--<?- bottomTemplate ?>-->
|
72
|
-
</body>
|
73
|
-
|
74
|
-
</html>
|
75
|
-
`;
|
76
|
-
export const fileSystemRoutes = ({
|
77
|
-
routes
|
78
|
-
}) => `
|
79
|
-
import loadable from '@modern-js/runtime/loadable';
|
80
|
-
|
81
|
-
${routes.map(({
|
82
|
-
component,
|
83
|
-
_component
|
84
|
-
}) => `const ${component} = loadable(() => import('${_component}'));`).join('\n\n')}
|
85
|
-
|
86
|
-
|
87
|
-
export const routes = ${JSON.stringify(routes, null, 2).replace(/"component"\s*:\s*"(\S+)"/g, '"component": $1')}
|
88
|
-
`;
|
@@ -1,92 +0,0 @@
|
|
1
|
-
import fs from 'fs';
|
2
|
-
import path from 'path';
|
3
|
-
import { isReact18, normalizeToPosixPath } from '@modern-js/utils';
|
4
|
-
import { FILE_SYSTEM_ROUTES_FILE_NAME } from "./constants";
|
5
|
-
export const walkDirectory = dir => fs.readdirSync(dir).reduce((previous, filename) => {
|
6
|
-
const filePath = path.join(dir, filename);
|
7
|
-
|
8
|
-
if (fs.statSync(filePath).isDirectory()) {
|
9
|
-
return [...previous, ...walkDirectory(filePath)];
|
10
|
-
} else {
|
11
|
-
return [...previous, filePath];
|
12
|
-
}
|
13
|
-
}, []);
|
14
|
-
export const getDefaultImports = ({
|
15
|
-
entrypoint,
|
16
|
-
srcDirectory,
|
17
|
-
internalSrcAlias,
|
18
|
-
internalDirAlias,
|
19
|
-
internalDirectory
|
20
|
-
}) => {
|
21
|
-
const {
|
22
|
-
entryName,
|
23
|
-
fileSystemRoutes,
|
24
|
-
customBootstrap,
|
25
|
-
entry
|
26
|
-
} = entrypoint;
|
27
|
-
const imports = [{
|
28
|
-
specifiers: [{
|
29
|
-
local: 'React'
|
30
|
-
}],
|
31
|
-
value: 'react'
|
32
|
-
}, {
|
33
|
-
specifiers: [{
|
34
|
-
local: 'ReactDOM'
|
35
|
-
}],
|
36
|
-
value: isReact18(path.join(internalDirectory, '../../')) ? 'react-dom/client' : 'react-dom'
|
37
|
-
}, {
|
38
|
-
specifiers: [{
|
39
|
-
imported: 'createApp'
|
40
|
-
}, {
|
41
|
-
imported: 'bootstrap'
|
42
|
-
}],
|
43
|
-
value: '@modern-js/runtime'
|
44
|
-
}, customBootstrap && {
|
45
|
-
specifiers: [{
|
46
|
-
local: 'customBootstrap'
|
47
|
-
}],
|
48
|
-
value: normalizeToPosixPath(customBootstrap.replace(srcDirectory, internalSrcAlias))
|
49
|
-
}].filter(Boolean);
|
50
|
-
|
51
|
-
if (fileSystemRoutes) {
|
52
|
-
const route = {
|
53
|
-
specifiers: [{
|
54
|
-
imported: 'routes'
|
55
|
-
}],
|
56
|
-
value: normalizeToPosixPath(`${internalDirAlias}/${entryName}/${FILE_SYSTEM_ROUTES_FILE_NAME}`)
|
57
|
-
};
|
58
|
-
|
59
|
-
if (fileSystemRoutes.globalApp) {
|
60
|
-
imports.push({
|
61
|
-
specifiers: [{
|
62
|
-
local: 'App'
|
63
|
-
}],
|
64
|
-
value: normalizeToPosixPath(fileSystemRoutes.globalApp.replace(srcDirectory, internalSrcAlias))
|
65
|
-
});
|
66
|
-
} else {
|
67
|
-
route.initialize = 'const App = false;';
|
68
|
-
}
|
69
|
-
|
70
|
-
imports.push(route);
|
71
|
-
} else {
|
72
|
-
imports.push({
|
73
|
-
specifiers: [{
|
74
|
-
local: 'App'
|
75
|
-
}],
|
76
|
-
value: normalizeToPosixPath(entry.replace(srcDirectory, internalSrcAlias))
|
77
|
-
});
|
78
|
-
}
|
79
|
-
|
80
|
-
return imports;
|
81
|
-
};
|
82
|
-
export const isRouteComponentFile = filePath => {
|
83
|
-
if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
|
84
|
-
return false;
|
85
|
-
}
|
86
|
-
|
87
|
-
if (['.js', '.jsx', '.ts', '.tsx'].includes(path.extname(filePath))) {
|
88
|
-
return true;
|
89
|
-
}
|
90
|
-
|
91
|
-
return false;
|
92
|
-
};
|