@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
|
@@ -1,30 +1,24 @@
|
|
|
1
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
2
|
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
3
|
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
4
|
import path from 'path';
|
|
8
5
|
import { fs } from '@modern-js/utils';
|
|
9
6
|
import { makeLegalIdentifier } from "../makeLegalIdentifier";
|
|
10
7
|
import { FILE_SYSTEM_ROUTES_COMPONENTS_DIR, FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP, FILE_SYSTEM_ROUTES_INDEX, FILE_SYSTEM_ROUTES_LAYOUT } from "../constants";
|
|
11
8
|
import { replaceWithAlias } from "../utils";
|
|
12
9
|
import { debug, findLayout, shouldSkip, getRouteWeight } from "./utils";
|
|
13
|
-
|
|
14
10
|
const compName = (srcDirectory, filePath) => {
|
|
15
11
|
const legalCompName = makeLegalIdentifier(path.relative(srcDirectory, filePath));
|
|
16
12
|
return `Comp_${legalCompName}`;
|
|
17
13
|
};
|
|
18
|
-
|
|
19
14
|
const layoutNameAbbr = filePath => {
|
|
20
15
|
const prefix = 'L_';
|
|
21
16
|
const dirName = path.dirname(filePath).split('/').pop() || '';
|
|
22
17
|
return `${prefix}${makeLegalIdentifier(dirName)}`;
|
|
23
18
|
};
|
|
24
|
-
|
|
25
19
|
const parents = [];
|
|
26
|
-
/* eslint-disable no-param-reassign */
|
|
27
20
|
|
|
21
|
+
/* eslint-disable no-param-reassign */
|
|
28
22
|
const recursiveReadDirLegacy = ({
|
|
29
23
|
dir,
|
|
30
24
|
routes,
|
|
@@ -36,7 +30,6 @@ const recursiveReadDirLegacy = ({
|
|
|
36
30
|
let resetParent = false;
|
|
37
31
|
let parent = parents[parents.length - 1];
|
|
38
32
|
const layout = findLayout(dir);
|
|
39
|
-
|
|
40
33
|
if (layout) {
|
|
41
34
|
if (_basePath === '/') {
|
|
42
35
|
throw new Error(`should use _app instead of _layout in ${dir}`);
|
|
@@ -58,16 +51,13 @@ const recursiveReadDirLegacy = ({
|
|
|
58
51
|
routes = route.routes;
|
|
59
52
|
}
|
|
60
53
|
}
|
|
61
|
-
|
|
62
54
|
for (const relative of fs.readdirSync(dir)) {
|
|
63
55
|
const filePath = path.join(dir, relative);
|
|
64
|
-
|
|
65
56
|
if (!shouldSkip(filePath)) {
|
|
66
57
|
const filename = path.basename(filePath, path.extname(filePath));
|
|
67
58
|
const alias = replaceWithAlias(srcDirectory, filePath, srcAlias);
|
|
68
59
|
const componentName = compName(srcDirectory, filePath);
|
|
69
60
|
const dynamicRouteMatched = FILE_SYSTEM_ROUTES_DYNAMIC_REGEXP.exec(filename);
|
|
70
|
-
|
|
71
61
|
if (dynamicRouteMatched) {
|
|
72
62
|
if (hasDynamicRoute) {
|
|
73
63
|
throw new Error(`Can't set two dynamic route in one directory: ${dir}`);
|
|
@@ -75,7 +65,6 @@ const recursiveReadDirLegacy = ({
|
|
|
75
65
|
hasDynamicRoute = true;
|
|
76
66
|
}
|
|
77
67
|
}
|
|
78
|
-
|
|
79
68
|
const route = {
|
|
80
69
|
path: `${_basePath}${dynamicRouteMatched ? `:${dynamicRouteMatched[1]}${dynamicRouteMatched[2]}` : filename}`,
|
|
81
70
|
_component: alias,
|
|
@@ -83,7 +72,6 @@ const recursiveReadDirLegacy = ({
|
|
|
83
72
|
exact: true,
|
|
84
73
|
parent
|
|
85
74
|
};
|
|
86
|
-
|
|
87
75
|
if (fs.statSync(filePath).isDirectory()) {
|
|
88
76
|
recursiveReadDirLegacy({
|
|
89
77
|
dir: filePath,
|
|
@@ -94,39 +82,33 @@ const recursiveReadDirLegacy = ({
|
|
|
94
82
|
});
|
|
95
83
|
continue;
|
|
96
84
|
}
|
|
97
|
-
|
|
98
85
|
if (filename === FILE_SYSTEM_ROUTES_LAYOUT) {
|
|
99
86
|
continue;
|
|
100
87
|
}
|
|
101
|
-
|
|
102
88
|
if (filename === FILE_SYSTEM_ROUTES_INDEX) {
|
|
103
89
|
route.path = _basePath === '/' ? _basePath : `${_basePath.substring(0, _basePath.length - 1)}`;
|
|
104
90
|
}
|
|
105
|
-
|
|
106
91
|
if (filename === '404' && _basePath === '/') {
|
|
107
92
|
route.path = '*';
|
|
108
93
|
route.exact = false;
|
|
109
94
|
}
|
|
110
|
-
|
|
111
95
|
routes.push(route);
|
|
112
96
|
}
|
|
113
97
|
}
|
|
114
|
-
|
|
115
98
|
if (resetParent) {
|
|
116
99
|
parents.pop();
|
|
117
100
|
}
|
|
118
101
|
};
|
|
119
102
|
/* eslint-enable no-param-reassign */
|
|
120
103
|
|
|
121
|
-
|
|
122
104
|
const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory, internalDirAlias) => {
|
|
123
105
|
const flat = routes => routes.reduce((memo, route) => memo.concat(Array.isArray(route.routes) ? flat(route.routes) : [route]), []);
|
|
124
|
-
|
|
125
106
|
const generate = route => {
|
|
126
107
|
const codes = [];
|
|
127
108
|
let lastComponent = route.component;
|
|
128
|
-
const imports = [`import React from 'react';`, `import ${lastComponent} from '${route._component}'`];
|
|
109
|
+
const imports = [`import React from 'react';`, `import ${lastComponent} from '${route._component}'`];
|
|
129
110
|
|
|
111
|
+
// eslint-disable-next-line no-param-reassign, no-cond-assign
|
|
130
112
|
while (route = route.parent) {
|
|
131
113
|
const layoutComponent = route.component;
|
|
132
114
|
const layoutComponentAbbr = layoutNameAbbr(route._component);
|
|
@@ -135,7 +117,6 @@ const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory,
|
|
|
135
117
|
codes.push(`const ${currentComponent} = props => <${layoutComponent} Component={${lastComponent}} {...props} />;`);
|
|
136
118
|
lastComponent = currentComponent;
|
|
137
119
|
}
|
|
138
|
-
|
|
139
120
|
const file = path.resolve(internalComponentsDir, `${lastComponent}.jsx`);
|
|
140
121
|
fs.outputFileSync(file, `${imports.join('\n')}\n${codes.join('\n')}\nexport default ${lastComponent}`);
|
|
141
122
|
return {
|
|
@@ -143,7 +124,6 @@ const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory,
|
|
|
143
124
|
_component: replaceWithAlias(internalDirectory, file, internalDirAlias)
|
|
144
125
|
};
|
|
145
126
|
};
|
|
146
|
-
|
|
147
127
|
const normalized = flat(nested).map(route => route.parent ? _objectSpread(_objectSpread(_objectSpread({}, route), generate(route)), {}, {
|
|
148
128
|
parent: undefined
|
|
149
129
|
}) : _objectSpread(_objectSpread({}, route), {}, {
|
|
@@ -151,7 +131,6 @@ const normalizeNestedRoutes = (nested, internalComponentsDir, internalDirectory,
|
|
|
151
131
|
}));
|
|
152
132
|
return normalized;
|
|
153
133
|
};
|
|
154
|
-
|
|
155
134
|
export const getClientRoutes = ({
|
|
156
135
|
entrypoint,
|
|
157
136
|
srcDirectory,
|
|
@@ -163,15 +142,12 @@ export const getClientRoutes = ({
|
|
|
163
142
|
entry,
|
|
164
143
|
entryName
|
|
165
144
|
} = entrypoint;
|
|
166
|
-
|
|
167
145
|
if (!fs.existsSync(entry)) {
|
|
168
146
|
throw new Error(`generate file system routes error, ${entry} directory not found.`);
|
|
169
147
|
}
|
|
170
|
-
|
|
171
148
|
if (!(fs.existsSync(entry) && fs.statSync(entry).isDirectory())) {
|
|
172
149
|
throw new Error(`generate file system routes error, ${entry} should be directory.`);
|
|
173
150
|
}
|
|
174
|
-
|
|
175
151
|
let routes = [];
|
|
176
152
|
recursiveReadDirLegacy({
|
|
177
153
|
dir: entry,
|
|
@@ -183,15 +159,14 @@ export const getClientRoutes = ({
|
|
|
183
159
|
const internalComponentsDir = path.resolve(internalDirectory, `${entryName}/${FILE_SYSTEM_ROUTES_COMPONENTS_DIR}`);
|
|
184
160
|
fs.emptyDirSync(internalComponentsDir);
|
|
185
161
|
routes = normalizeNestedRoutes(routes, internalComponentsDir, internalDirectory, internalDirAlias);
|
|
186
|
-
parents.length = 0;
|
|
162
|
+
parents.length = 0;
|
|
187
163
|
|
|
164
|
+
// FIXME: support more situations
|
|
188
165
|
routes.sort((a, b) => {
|
|
189
166
|
const delta = getRouteWeight(a.path) - getRouteWeight(b.path);
|
|
190
|
-
|
|
191
167
|
if (delta === 0) {
|
|
192
168
|
return a.path.length - b.path.length;
|
|
193
169
|
}
|
|
194
|
-
|
|
195
170
|
return delta;
|
|
196
171
|
});
|
|
197
172
|
debug(`fileSystem routes: %o`, routes);
|
|
@@ -10,12 +10,9 @@ export const shouldSkip = file => {
|
|
|
10
10
|
if (fs.statSync(file).isDirectory()) {
|
|
11
11
|
return false;
|
|
12
12
|
}
|
|
13
|
-
|
|
14
13
|
const ext = path.extname(file);
|
|
15
|
-
|
|
16
14
|
if (FILE_SYSTEM_ROUTES_IGNORED_REGEX.test(file) || !JS_EXTENSIONS.includes(ext) || FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT === path.basename(file, ext)) {
|
|
17
15
|
return true;
|
|
18
16
|
}
|
|
19
|
-
|
|
20
17
|
return false;
|
|
21
18
|
};
|
|
@@ -3,44 +3,35 @@ import path from 'path';
|
|
|
3
3
|
import { findExists, ensureAbsolutePath } from '@modern-js/utils';
|
|
4
4
|
import { isDefaultExportFunction } from "./isDefaultExportFunction";
|
|
5
5
|
import { JS_EXTENSIONS, INDEX_FILE_NAME, APP_FILE_NAME, PAGES_DIR_NAME, FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT, NESTED_ROUTES_DIR } from "./constants";
|
|
6
|
-
|
|
7
6
|
const hasIndex = dir => findExists(JS_EXTENSIONS.map(ext => path.resolve(dir, `${INDEX_FILE_NAME}${ext}`)));
|
|
8
|
-
|
|
9
7
|
const hasApp = dir => findExists(JS_EXTENSIONS.map(ext => path.resolve(dir, `${APP_FILE_NAME}${ext}`)));
|
|
10
|
-
|
|
11
8
|
const hasPages = dir => fs.existsSync(path.join(dir, PAGES_DIR_NAME));
|
|
12
|
-
|
|
13
9
|
const hasNestedRoutes = dir => fs.existsSync(path.join(dir, NESTED_ROUTES_DIR));
|
|
14
|
-
|
|
15
10
|
const isBundleEntry = dir => hasApp(dir) || hasPages(dir) || hasIndex(dir) || hasNestedRoutes(dir);
|
|
16
|
-
|
|
17
11
|
const scanDir = dirs => dirs.map(dir => {
|
|
18
12
|
const indexFile = hasIndex(dir);
|
|
19
13
|
const customBootstrap = isDefaultExportFunction(indexFile) ? indexFile : false;
|
|
20
14
|
const entryName = path.basename(dir);
|
|
21
|
-
|
|
22
15
|
if (indexFile && !customBootstrap) {
|
|
23
16
|
return {
|
|
24
17
|
entryName,
|
|
25
18
|
entry: indexFile,
|
|
19
|
+
absoluteEntryDir: path.resolve(dir),
|
|
26
20
|
isAutoMount: false
|
|
27
21
|
};
|
|
28
22
|
}
|
|
29
|
-
|
|
30
23
|
const isHasApp = hasApp(dir);
|
|
31
|
-
|
|
32
24
|
if (isHasApp) {
|
|
33
25
|
return {
|
|
34
26
|
entryName,
|
|
35
27
|
entry: path.join(dir, APP_FILE_NAME),
|
|
36
28
|
isAutoMount: true,
|
|
29
|
+
absoluteEntryDir: path.resolve(dir),
|
|
37
30
|
customBootstrap
|
|
38
31
|
};
|
|
39
32
|
}
|
|
40
|
-
|
|
41
33
|
const isHasNestedRoutes = hasNestedRoutes(dir);
|
|
42
34
|
const isHasPages = hasPages(dir);
|
|
43
|
-
|
|
44
35
|
if (isHasNestedRoutes || isHasPages) {
|
|
45
36
|
const entrypoint = {
|
|
46
37
|
entryName,
|
|
@@ -49,27 +40,24 @@ const scanDir = dirs => dirs.map(dir => {
|
|
|
49
40
|
globalApp: findExists(JS_EXTENSIONS.map(ext => path.resolve(dir, `./${PAGES_DIR_NAME}/${FILE_SYSTEM_ROUTES_GLOBAL_LAYOUT}${ext}`)))
|
|
50
41
|
},
|
|
51
42
|
isAutoMount: true,
|
|
43
|
+
absoluteEntryDir: path.resolve(dir),
|
|
52
44
|
customBootstrap
|
|
53
45
|
};
|
|
54
|
-
|
|
55
46
|
if (isHasPages) {
|
|
56
47
|
entrypoint.entry = path.join(dir, PAGES_DIR_NAME);
|
|
57
48
|
}
|
|
58
|
-
|
|
59
49
|
if (isHasNestedRoutes) {
|
|
60
50
|
entrypoint.nestedRoutesEntry = path.join(dir, NESTED_ROUTES_DIR);
|
|
61
51
|
}
|
|
62
|
-
|
|
63
52
|
return entrypoint;
|
|
64
53
|
}
|
|
65
|
-
|
|
66
54
|
return {
|
|
67
55
|
entryName,
|
|
68
56
|
entry: indexFile,
|
|
57
|
+
absoluteEntryDir: path.resolve(dir),
|
|
69
58
|
isAutoMount: false
|
|
70
59
|
};
|
|
71
60
|
});
|
|
72
|
-
|
|
73
61
|
export const getFileSystemEntry = (appContext, config) => {
|
|
74
62
|
const {
|
|
75
63
|
appDirectory
|
|
@@ -80,7 +68,6 @@ export const getFileSystemEntry = (appContext, config) => {
|
|
|
80
68
|
}
|
|
81
69
|
} = config;
|
|
82
70
|
const src = ensureAbsolutePath(appDirectory, entriesDir);
|
|
83
|
-
|
|
84
71
|
if (fs.existsSync(src)) {
|
|
85
72
|
if (fs.statSync(src).isDirectory()) {
|
|
86
73
|
return scanDir(isBundleEntry(src) ? [src] : fs.readdirSync(src).map(file => path.join(src, file)).filter(file => fs.statSync(file).isDirectory() && isBundleEntry(file)));
|
|
@@ -3,7 +3,6 @@ import { fs, findExists, MAIN_ENTRY_NAME } from '@modern-js/utils';
|
|
|
3
3
|
import { HTML_PARTIALS_EXTENSIONS, HTML_PARTIALS_FOLDER } from "./constants";
|
|
4
4
|
import * as templates from "./templates";
|
|
5
5
|
var PartialPosition;
|
|
6
|
-
|
|
7
6
|
(function (PartialPosition) {
|
|
8
7
|
PartialPosition["TOP"] = "top";
|
|
9
8
|
PartialPosition["HEAD"] = "head";
|
|
@@ -11,7 +10,6 @@ var PartialPosition;
|
|
|
11
10
|
PartialPosition["BOTTOM"] = "bottom";
|
|
12
11
|
PartialPosition["INDEX"] = "index";
|
|
13
12
|
})(PartialPosition || (PartialPosition = {}));
|
|
14
|
-
|
|
15
13
|
const findPartials = (dir, entryName, position) => {
|
|
16
14
|
if (fs.existsSync(dir)) {
|
|
17
15
|
const base = findExists(HTML_PARTIALS_EXTENSIONS.map(ext => path.resolve(dir, `${position}${ext}`)));
|
|
@@ -21,11 +19,10 @@ const findPartials = (dir, entryName, position) => {
|
|
|
21
19
|
content: fs.readFileSync(file, 'utf8')
|
|
22
20
|
} : null;
|
|
23
21
|
}
|
|
24
|
-
|
|
25
22
|
return null;
|
|
26
|
-
};
|
|
27
|
-
|
|
23
|
+
};
|
|
28
24
|
|
|
25
|
+
// generate html template for
|
|
29
26
|
export const getHtmlTemplate = async (entrypoints, api, {
|
|
30
27
|
appContext,
|
|
31
28
|
config
|
|
@@ -41,14 +38,12 @@ export const getHtmlTemplate = async (entrypoints, api, {
|
|
|
41
38
|
} = config;
|
|
42
39
|
const htmlDir = path.resolve(appDirectory, configDir, HTML_PARTIALS_FOLDER);
|
|
43
40
|
const htmlTemplates = {};
|
|
44
|
-
|
|
45
41
|
for (const entrypoint of entrypoints) {
|
|
46
42
|
const {
|
|
47
43
|
entryName
|
|
48
44
|
} = entrypoint;
|
|
49
45
|
const name = entrypoints.length === 1 && entryName === MAIN_ENTRY_NAME ? '' : entryName;
|
|
50
46
|
const customIndexTemplate = findPartials(htmlDir, name, PartialPosition.INDEX);
|
|
51
|
-
|
|
52
47
|
if (customIndexTemplate) {
|
|
53
48
|
htmlTemplates[entryName] = customIndexTemplate.file;
|
|
54
49
|
} else {
|
|
@@ -71,12 +66,10 @@ export const getHtmlTemplate = async (entrypoints, api, {
|
|
|
71
66
|
fs.outputFileSync(templatePath, templates.html(partials), 'utf8');
|
|
72
67
|
htmlTemplates[entryName] = templatePath;
|
|
73
68
|
const bottomTemplate = findPartials(htmlDir, name, PartialPosition.BOTTOM);
|
|
74
|
-
|
|
75
69
|
if (bottomTemplate) {
|
|
76
70
|
htmlTemplates[`__${entryName}-bottom__`] = bottomTemplate.content;
|
|
77
71
|
}
|
|
78
72
|
}
|
|
79
73
|
}
|
|
80
|
-
|
|
81
74
|
return htmlTemplates;
|
|
82
75
|
};
|
|
@@ -1,27 +1,21 @@
|
|
|
1
1
|
const _excluded = ["path"],
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
_excluded2 = ["path"];
|
|
4
3
|
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
4
|
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
5
|
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
6
|
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
7
|
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
8
|
import path from 'path';
|
|
15
9
|
import fs from 'fs';
|
|
16
10
|
import { urlJoin, isPlainObject, removeLeadingSlash, getEntryOptions, SERVER_BUNDLE_DIRECTORY, MAIN_ENTRY_NAME, removeTailSlash } from '@modern-js/utils';
|
|
17
11
|
import { walkDirectory } from "./utils";
|
|
12
|
+
|
|
18
13
|
/**
|
|
19
14
|
* Add base url for each server route.
|
|
20
15
|
* @param baseUrl - Base url from server.baseUrl
|
|
21
16
|
* @param routes - Server routes.
|
|
22
17
|
* @returns Server routes with baseUrl prefixed.
|
|
23
18
|
*/
|
|
24
|
-
|
|
25
19
|
const applyBaseUrl = (baseUrl, routes) => {
|
|
26
20
|
if (baseUrl) {
|
|
27
21
|
if (Array.isArray(baseUrl)) {
|
|
@@ -35,37 +29,34 @@ const applyBaseUrl = (baseUrl, routes) => {
|
|
|
35
29
|
});
|
|
36
30
|
}
|
|
37
31
|
}
|
|
38
|
-
|
|
39
32
|
return routes;
|
|
40
33
|
};
|
|
34
|
+
|
|
41
35
|
/**
|
|
42
36
|
*
|
|
43
37
|
* @param original - Original entrypoint route info.
|
|
44
38
|
* @param routeOptions - Custom entrypoint route config from server.routes.
|
|
45
39
|
* @returns
|
|
46
40
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
41
|
const applyRouteOptions = (original, routeOptions) => {
|
|
50
42
|
const {
|
|
51
43
|
route,
|
|
52
44
|
disableSpa
|
|
53
45
|
} = routeOptions;
|
|
54
|
-
original.isSPA = !disableSpa;
|
|
46
|
+
original.isSPA = !disableSpa;
|
|
55
47
|
|
|
48
|
+
// set entryPath as dir
|
|
56
49
|
!original.isSPA && (original.entryPath = path.dirname(original.entryPath));
|
|
57
50
|
let routes;
|
|
58
|
-
|
|
59
51
|
if (route) {
|
|
60
52
|
if (Array.isArray(route)) {
|
|
61
53
|
routes = route.map(url => {
|
|
62
54
|
if (isPlainObject(url)) {
|
|
63
55
|
const _ref = url,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
56
|
+
{
|
|
57
|
+
path: urlPath
|
|
58
|
+
} = _ref,
|
|
59
|
+
other = _objectWithoutProperties(_ref, _excluded);
|
|
69
60
|
return _objectSpread(_objectSpread(_objectSpread({}, original), other), {}, {
|
|
70
61
|
urlPath
|
|
71
62
|
});
|
|
@@ -77,11 +68,10 @@ const applyRouteOptions = (original, routeOptions) => {
|
|
|
77
68
|
});
|
|
78
69
|
} else if (isPlainObject(route)) {
|
|
79
70
|
const _ref2 = route,
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
71
|
+
{
|
|
72
|
+
path: urlPath
|
|
73
|
+
} = _ref2,
|
|
74
|
+
other = _objectWithoutProperties(_ref2, _excluded2);
|
|
85
75
|
routes = [_objectSpread(_objectSpread(_objectSpread({}, original), other), {}, {
|
|
86
76
|
urlPath
|
|
87
77
|
})];
|
|
@@ -93,17 +83,15 @@ const applyRouteOptions = (original, routeOptions) => {
|
|
|
93
83
|
} else {
|
|
94
84
|
routes = [original];
|
|
95
85
|
}
|
|
96
|
-
|
|
97
86
|
return routes;
|
|
98
87
|
};
|
|
88
|
+
|
|
99
89
|
/**
|
|
100
90
|
* Collect routes from entrypoints.
|
|
101
91
|
* @param entrypoints - Bundle entrypoints.
|
|
102
92
|
* @param config - Normalized user config.
|
|
103
93
|
* @returns entrypoint Routes
|
|
104
94
|
*/
|
|
105
|
-
|
|
106
|
-
|
|
107
95
|
const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
108
96
|
const {
|
|
109
97
|
output: {
|
|
@@ -139,27 +127,24 @@ const collectHtmlRoutes = (entrypoints, appContext, config) => {
|
|
|
139
127
|
enableModernMode: Boolean(enableModernMode),
|
|
140
128
|
bundle: isSSR ? `${SERVER_BUNDLE_DIRECTORY}/${entryName}.js` : undefined
|
|
141
129
|
};
|
|
142
|
-
|
|
143
130
|
if (routes !== null && routes !== void 0 && routes.hasOwnProperty(entryName)) {
|
|
144
131
|
const routeOptions = isPlainObject(routes[entryName]) ? routes[entryName] : {
|
|
145
132
|
route: routes[entryName]
|
|
146
133
|
};
|
|
147
134
|
route = applyRouteOptions(route, routeOptions);
|
|
148
135
|
}
|
|
149
|
-
|
|
150
136
|
return Array.isArray(route) ? [...previous, ...route] : [...previous, route];
|
|
151
137
|
}, []);
|
|
152
138
|
htmlRoutes = applyBaseUrl(baseUrl, htmlRoutes);
|
|
153
139
|
return htmlRoutes;
|
|
154
140
|
};
|
|
141
|
+
|
|
155
142
|
/**
|
|
156
143
|
* Collect static public file routes from config/public folder.
|
|
157
144
|
* @param appContext - App context info.
|
|
158
145
|
* @param config - normalized user config.
|
|
159
146
|
* @returns Static public file routes.
|
|
160
147
|
*/
|
|
161
|
-
|
|
162
|
-
|
|
163
148
|
const collectStaticRoutes = (appContext, config) => {
|
|
164
149
|
const {
|
|
165
150
|
appDirectory
|
|
@@ -183,10 +168,8 @@ const collectStaticRoutes = (appContext, config) => {
|
|
|
183
168
|
};
|
|
184
169
|
}) : [];
|
|
185
170
|
};
|
|
186
|
-
|
|
187
171
|
export const getServerRoutes = (entrypoints, {
|
|
188
172
|
appContext,
|
|
189
173
|
config
|
|
190
174
|
}) => [...collectHtmlRoutes(entrypoints, appContext, config), ...collectStaticRoutes(appContext, config)];
|
|
191
|
-
|
|
192
175
|
const toPosix = pathStr => pathStr.split(path.sep).join(path.posix.sep);
|
|
@@ -1,13 +1,15 @@
|
|
|
1
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
2
|
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
3
|
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
4
|
import * as path from 'path';
|
|
8
5
|
import { createAsyncWaterfall } from '@modern-js/plugin';
|
|
9
6
|
import { createDebugger, fs, isApiOnly } from '@modern-js/utils';
|
|
10
7
|
import { cloneDeep } from '@modern-js/utils/lodash';
|
|
8
|
+
import { createBuilderForEdenX } from "../builder";
|
|
9
|
+
import { printInstructions } from "../utils/printInstructions";
|
|
10
|
+
import { generateRoutes } from "../utils/routes";
|
|
11
|
+
import { emitResolvedConfig } from "../utils/config";
|
|
12
|
+
import { getCommand } from "../utils/commands";
|
|
11
13
|
import { isRouteComponentFile } from "./utils";
|
|
12
14
|
const debug = createDebugger('plugin-analyze');
|
|
13
15
|
export const modifyEntryImports = createAsyncWaterfall();
|
|
@@ -42,19 +44,16 @@ export default (() => ({
|
|
|
42
44
|
return {
|
|
43
45
|
async prepare() {
|
|
44
46
|
var _resolvedConfig$sourc;
|
|
45
|
-
|
|
46
|
-
const appContext = api.useAppContext();
|
|
47
|
+
let appContext = api.useAppContext();
|
|
47
48
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
48
49
|
const hookRunners = api.useHookRunners();
|
|
49
|
-
|
|
50
50
|
try {
|
|
51
51
|
fs.emptydirSync(appContext.internalDirectory);
|
|
52
|
-
} catch (_unused) {
|
|
52
|
+
} catch (_unused) {
|
|
53
|
+
// FIXME:
|
|
53
54
|
}
|
|
54
|
-
|
|
55
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
56
|
await hookRunners.addRuntimeExports();
|
|
57
|
-
|
|
58
57
|
if (apiOnly) {
|
|
59
58
|
const {
|
|
60
59
|
routes
|
|
@@ -62,13 +61,13 @@ export default (() => ({
|
|
|
62
61
|
routes: []
|
|
63
62
|
});
|
|
64
63
|
debug(`server routes: %o`, routes);
|
|
65
|
-
|
|
64
|
+
appContext = _objectSpread(_objectSpread({}, appContext), {}, {
|
|
66
65
|
apiOnly,
|
|
67
66
|
serverRoutes: routes
|
|
68
|
-
})
|
|
67
|
+
});
|
|
68
|
+
api.setAppContext(appContext);
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
|
-
|
|
72
71
|
const [{
|
|
73
72
|
getBundleEntry
|
|
74
73
|
}, {
|
|
@@ -91,10 +90,11 @@ export default (() => ({
|
|
|
91
90
|
routes: initialRoutes
|
|
92
91
|
});
|
|
93
92
|
debug(`server routes: %o`, routes);
|
|
94
|
-
|
|
93
|
+
appContext = _objectSpread(_objectSpread({}, appContext), {}, {
|
|
95
94
|
entrypoints,
|
|
96
95
|
serverRoutes: routes
|
|
97
|
-
})
|
|
96
|
+
});
|
|
97
|
+
api.setAppContext(appContext);
|
|
98
98
|
const nestedRouteEntries = entrypoints.map(point => point.nestedRoutesEntry).filter(Boolean);
|
|
99
99
|
pagesDir = entrypoints.map(point => point.entry).filter(Boolean).concat(nestedRouteEntries);
|
|
100
100
|
originEntrypoints = cloneDeep(entrypoints);
|
|
@@ -106,19 +106,80 @@ export default (() => ({
|
|
|
106
106
|
debug(`html templates: %o`, htmlTemplates);
|
|
107
107
|
await hookRunners.addDefineTypes();
|
|
108
108
|
debug(`add Define Types`);
|
|
109
|
-
|
|
109
|
+
appContext = _objectSpread(_objectSpread({}, appContext), {}, {
|
|
110
110
|
entrypoints,
|
|
111
111
|
checkedEntries: defaultChecked,
|
|
112
112
|
apiOnly,
|
|
113
113
|
serverRoutes: routes,
|
|
114
114
|
htmlTemplates
|
|
115
|
-
})
|
|
115
|
+
});
|
|
116
|
+
api.setAppContext(appContext);
|
|
117
|
+
const command = getCommand();
|
|
118
|
+
const buildCommands = ['dev', 'build', 'inspect', 'deploy'];
|
|
119
|
+
if (buildCommands.includes(command)) {
|
|
120
|
+
const normalizedConfig = api.useResolvedConfigContext();
|
|
121
|
+
const builder = await createBuilderForEdenX({
|
|
122
|
+
normalizedConfig,
|
|
123
|
+
appContext,
|
|
124
|
+
compatPluginConfig: {
|
|
125
|
+
async onBeforeBuild({
|
|
126
|
+
bundlerConfigs
|
|
127
|
+
}) {
|
|
128
|
+
const hookRunners = api.useHookRunners();
|
|
129
|
+
await generateRoutes(appContext);
|
|
130
|
+
await hookRunners.beforeBuild({
|
|
131
|
+
bundlerConfigs
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
async onAfterBuild({
|
|
135
|
+
stats
|
|
136
|
+
}) {
|
|
137
|
+
const hookRunners = api.useHookRunners();
|
|
138
|
+
await hookRunners.afterBuild({
|
|
139
|
+
stats
|
|
140
|
+
});
|
|
141
|
+
await emitResolvedConfig(appContext.appDirectory, normalizedConfig);
|
|
142
|
+
},
|
|
143
|
+
async onDevCompileDone({
|
|
144
|
+
isFirstCompile
|
|
145
|
+
}) {
|
|
146
|
+
const hookRunners = api.useHookRunners();
|
|
147
|
+
if (process.stdout.isTTY || isFirstCompile) {
|
|
148
|
+
hookRunners.afterDev();
|
|
149
|
+
if (isFirstCompile) {
|
|
150
|
+
printInstructions(hookRunners, appContext, normalizedConfig);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
},
|
|
154
|
+
async onBeforeCreateCompiler({
|
|
155
|
+
bundlerConfigs
|
|
156
|
+
}) {
|
|
157
|
+
const hookRunners = api.useHookRunners();
|
|
158
|
+
// run modernjs framework `beforeCreateCompiler` hook
|
|
159
|
+
await hookRunners.beforeCreateCompiler({
|
|
160
|
+
bundlerConfigs
|
|
161
|
+
});
|
|
162
|
+
},
|
|
163
|
+
async onAfterCreateCompiler({
|
|
164
|
+
compiler
|
|
165
|
+
}) {
|
|
166
|
+
const hookRunners = api.useHookRunners();
|
|
167
|
+
// run modernjs framework afterCreateCompiler hooks
|
|
168
|
+
await hookRunners.afterCreateCompiler({
|
|
169
|
+
compiler
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
appContext = _objectSpread(_objectSpread({}, appContext), {}, {
|
|
175
|
+
builder
|
|
176
|
+
});
|
|
177
|
+
api.setAppContext(appContext);
|
|
178
|
+
}
|
|
116
179
|
},
|
|
117
|
-
|
|
118
180
|
watchFiles() {
|
|
119
181
|
return pagesDir;
|
|
120
182
|
},
|
|
121
|
-
|
|
122
183
|
async fileChange(e) {
|
|
123
184
|
const appContext = api.useAppContext();
|
|
124
185
|
const {
|
|
@@ -128,12 +189,9 @@ export default (() => ({
|
|
|
128
189
|
filename,
|
|
129
190
|
eventType
|
|
130
191
|
} = e;
|
|
131
|
-
|
|
132
192
|
const isPageFile = name => pagesDir.some(pageDir => name.includes(pageDir));
|
|
133
|
-
|
|
134
193
|
const absoluteFilePath = path.resolve(appDirectory, filename);
|
|
135
194
|
const isRouteComponent = isPageFile(absoluteFilePath) && isRouteComponentFile(absoluteFilePath);
|
|
136
|
-
|
|
137
195
|
if (isRouteComponent && (eventType === 'add' || eventType === 'unlink')) {
|
|
138
196
|
const resolvedConfig = api.useResolvedConfigContext();
|
|
139
197
|
const {
|
|
@@ -143,7 +201,6 @@ export default (() => ({
|
|
|
143
201
|
generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
144
202
|
}
|
|
145
203
|
}
|
|
146
|
-
|
|
147
204
|
};
|
|
148
205
|
}
|
|
149
206
|
}));
|
|
@@ -2,14 +2,11 @@ import fs from 'fs';
|
|
|
2
2
|
import { parse } from '@babel/parser';
|
|
3
3
|
import traverse from '@babel/traverse';
|
|
4
4
|
import * as t from '@babel/types';
|
|
5
|
-
|
|
6
5
|
const isFunction = node => t.isFunctionDeclaration(node) || t.isFunctionExpression(node) || t.isArrowFunctionExpression(node);
|
|
7
|
-
|
|
8
6
|
export const isDefaultExportFunction = file => {
|
|
9
7
|
if (!file || !fs.existsSync(file)) {
|
|
10
8
|
return false;
|
|
11
9
|
}
|
|
12
|
-
|
|
13
10
|
const ast = parse(fs.readFileSync(file, 'utf8'), {
|
|
14
11
|
sourceType: 'unambiguous',
|
|
15
12
|
plugins: ['jsx', 'typescript', 'classProperties', 'dynamicImport', 'exportDefaultFrom', 'exportNamespaceFrom', 'decorators-legacy', 'functionBind', 'classPrivateMethods', ['pipelineOperator', {
|
|
@@ -22,7 +19,6 @@ export const isDefaultExportFunction = file => {
|
|
|
22
19
|
const {
|
|
23
20
|
declaration
|
|
24
21
|
} = path.node;
|
|
25
|
-
|
|
26
22
|
if (isFunction(declaration)) {
|
|
27
23
|
isExportFunction = true;
|
|
28
24
|
}
|
|
@@ -7,10 +7,8 @@ const builtins = 'arguments Infinity NaN undefined null true false eval uneval i
|
|
|
7
7
|
const forbidList = new Set(`${reservedWords} ${builtins}`.split(' '));
|
|
8
8
|
export function makeLegalIdentifier(str) {
|
|
9
9
|
const identifier = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(/[^$_a-zA-Z0-9]/g, '_');
|
|
10
|
-
|
|
11
10
|
if (/\d/.test(identifier[0]) || forbidList.has(identifier)) {
|
|
12
11
|
return `_${identifier}`;
|
|
13
12
|
}
|
|
14
|
-
|
|
15
13
|
return identifier || '_';
|
|
16
14
|
}
|