@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
|
@@ -6,6 +6,11 @@ import * as path from 'path';
|
|
|
6
6
|
import { createAsyncWaterfall } from '@modern-js/plugin';
|
|
7
7
|
import { createDebugger, fs, isApiOnly } from '@modern-js/utils';
|
|
8
8
|
import { cloneDeep } from '@modern-js/utils/lodash';
|
|
9
|
+
import { createBuilderForEdenX } from "../builder";
|
|
10
|
+
import { printInstructions } from "../utils/printInstructions";
|
|
11
|
+
import { generateRoutes } from "../utils/routes";
|
|
12
|
+
import { emitResolvedConfig } from "../utils/config";
|
|
13
|
+
import { getCommand } from "../utils/commands";
|
|
9
14
|
import { isRouteComponentFile } from "./utils";
|
|
10
15
|
var debug = createDebugger('plugin-analyze');
|
|
11
16
|
export var modifyEntryImports = createAsyncWaterfall();
|
|
@@ -40,59 +45,51 @@ export default (function () {
|
|
|
40
45
|
var originEntrypoints = [];
|
|
41
46
|
return {
|
|
42
47
|
prepare: function prepare() {
|
|
43
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
48
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6() {
|
|
44
49
|
var _resolvedConfig$sourc;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
50
|
+
var appContext, resolvedConfig, hookRunners, apiOnly, _yield$hookRunners$mo, _routes, _yield$Promise$all, _yield$Promise$all2, getBundleEntry, getServerRoutes, generateCode, getHtmlTemplate, entrypoints, defaultChecked, initialRoutes, _yield$hookRunners$mo2, routes, nestedRouteEntries, htmlTemplates, command, buildCommands, normalizedConfig, builder;
|
|
51
|
+
return _regeneratorRuntime().wrap(function _callee6$(_context6) {
|
|
49
52
|
while (1) {
|
|
50
|
-
switch (
|
|
53
|
+
switch (_context6.prev = _context6.next) {
|
|
51
54
|
case 0:
|
|
52
55
|
appContext = api.useAppContext();
|
|
53
56
|
resolvedConfig = api.useResolvedConfigContext();
|
|
54
57
|
hookRunners = api.useHookRunners();
|
|
55
|
-
|
|
56
58
|
try {
|
|
57
59
|
fs.emptydirSync(appContext.internalDirectory);
|
|
58
|
-
} catch (_unused) {
|
|
60
|
+
} catch (_unused) {
|
|
61
|
+
// FIXME:
|
|
59
62
|
}
|
|
60
|
-
|
|
61
|
-
_context.next = 6;
|
|
63
|
+
_context6.next = 6;
|
|
62
64
|
return isApiOnly(appContext.appDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$sourc = resolvedConfig.source) === null || _resolvedConfig$sourc === void 0 ? void 0 : _resolvedConfig$sourc.entriesDir);
|
|
63
|
-
|
|
64
65
|
case 6:
|
|
65
|
-
apiOnly =
|
|
66
|
-
|
|
66
|
+
apiOnly = _context6.sent;
|
|
67
|
+
_context6.next = 9;
|
|
67
68
|
return hookRunners.addRuntimeExports();
|
|
68
|
-
|
|
69
69
|
case 9:
|
|
70
70
|
if (!apiOnly) {
|
|
71
|
-
|
|
71
|
+
_context6.next = 18;
|
|
72
72
|
break;
|
|
73
73
|
}
|
|
74
|
-
|
|
75
|
-
_context.next = 12;
|
|
74
|
+
_context6.next = 12;
|
|
76
75
|
return hookRunners.modifyServerRoutes({
|
|
77
76
|
routes: []
|
|
78
77
|
});
|
|
79
|
-
|
|
80
78
|
case 12:
|
|
81
|
-
_yield$hookRunners$mo =
|
|
79
|
+
_yield$hookRunners$mo = _context6.sent;
|
|
82
80
|
_routes = _yield$hookRunners$mo.routes;
|
|
83
81
|
debug("server routes: %o", _routes);
|
|
84
|
-
|
|
82
|
+
appContext = _objectSpread(_objectSpread({}, appContext), {}, {
|
|
85
83
|
apiOnly: apiOnly,
|
|
86
84
|
serverRoutes: _routes
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
case
|
|
91
|
-
|
|
85
|
+
});
|
|
86
|
+
api.setAppContext(appContext);
|
|
87
|
+
return _context6.abrupt("return");
|
|
88
|
+
case 18:
|
|
89
|
+
_context6.next = 20;
|
|
92
90
|
return Promise.all([import("./getBundleEntry"), import("./getServerRoutes"), import("./generateCode"), import("./getHtmlTemplate")]);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
_yield$Promise$all = _context.sent;
|
|
91
|
+
case 20:
|
|
92
|
+
_yield$Promise$all = _context6.sent;
|
|
96
93
|
_yield$Promise$all2 = _slicedToArray(_yield$Promise$all, 4);
|
|
97
94
|
getBundleEntry = _yield$Promise$all2[0].getBundleEntry;
|
|
98
95
|
getServerRoutes = _yield$Promise$all2[1].getServerRoutes;
|
|
@@ -107,19 +104,19 @@ export default (function () {
|
|
|
107
104
|
appContext: appContext,
|
|
108
105
|
config: resolvedConfig
|
|
109
106
|
});
|
|
110
|
-
|
|
107
|
+
_context6.next = 32;
|
|
111
108
|
return hookRunners.modifyServerRoutes({
|
|
112
109
|
routes: initialRoutes
|
|
113
110
|
});
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
_yield$hookRunners$mo2 = _context.sent;
|
|
111
|
+
case 32:
|
|
112
|
+
_yield$hookRunners$mo2 = _context6.sent;
|
|
117
113
|
routes = _yield$hookRunners$mo2.routes;
|
|
118
114
|
debug("server routes: %o", routes);
|
|
119
|
-
|
|
115
|
+
appContext = _objectSpread(_objectSpread({}, appContext), {}, {
|
|
120
116
|
entrypoints: entrypoints,
|
|
121
117
|
serverRoutes: routes
|
|
122
|
-
})
|
|
118
|
+
});
|
|
119
|
+
api.setAppContext(appContext);
|
|
123
120
|
nestedRouteEntries = entrypoints.map(function (point) {
|
|
124
121
|
return point.nestedRoutesEntry;
|
|
125
122
|
}).filter(Boolean);
|
|
@@ -127,85 +124,208 @@ export default (function () {
|
|
|
127
124
|
return point.entry;
|
|
128
125
|
}).filter(Boolean).concat(nestedRouteEntries);
|
|
129
126
|
originEntrypoints = cloneDeep(entrypoints);
|
|
130
|
-
|
|
127
|
+
_context6.next = 42;
|
|
131
128
|
return generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
_context.next = 42;
|
|
129
|
+
case 42:
|
|
130
|
+
_context6.next = 44;
|
|
135
131
|
return getHtmlTemplate(entrypoints, api, {
|
|
136
132
|
appContext: appContext,
|
|
137
133
|
config: resolvedConfig
|
|
138
134
|
});
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
htmlTemplates = _context.sent;
|
|
135
|
+
case 44:
|
|
136
|
+
htmlTemplates = _context6.sent;
|
|
142
137
|
debug("html templates: %o", htmlTemplates);
|
|
143
|
-
|
|
138
|
+
_context6.next = 48;
|
|
144
139
|
return hookRunners.addDefineTypes();
|
|
145
|
-
|
|
146
|
-
case 46:
|
|
140
|
+
case 48:
|
|
147
141
|
debug("add Define Types");
|
|
148
|
-
|
|
142
|
+
appContext = _objectSpread(_objectSpread({}, appContext), {}, {
|
|
149
143
|
entrypoints: entrypoints,
|
|
150
144
|
checkedEntries: defaultChecked,
|
|
151
145
|
apiOnly: apiOnly,
|
|
152
146
|
serverRoutes: routes,
|
|
153
147
|
htmlTemplates: htmlTemplates
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
|
|
148
|
+
});
|
|
149
|
+
api.setAppContext(appContext);
|
|
150
|
+
command = getCommand();
|
|
151
|
+
buildCommands = ['dev', 'build', 'inspect', 'deploy'];
|
|
152
|
+
if (!buildCommands.includes(command)) {
|
|
153
|
+
_context6.next = 60;
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
normalizedConfig = api.useResolvedConfigContext();
|
|
157
|
+
_context6.next = 57;
|
|
158
|
+
return createBuilderForEdenX({
|
|
159
|
+
normalizedConfig: normalizedConfig,
|
|
160
|
+
appContext: appContext,
|
|
161
|
+
compatPluginConfig: {
|
|
162
|
+
onBeforeBuild: function onBeforeBuild(_ref) {
|
|
163
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
164
|
+
var bundlerConfigs, hookRunners;
|
|
165
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
166
|
+
while (1) {
|
|
167
|
+
switch (_context.prev = _context.next) {
|
|
168
|
+
case 0:
|
|
169
|
+
bundlerConfigs = _ref.bundlerConfigs;
|
|
170
|
+
hookRunners = api.useHookRunners();
|
|
171
|
+
_context.next = 4;
|
|
172
|
+
return generateRoutes(appContext);
|
|
173
|
+
case 4:
|
|
174
|
+
_context.next = 6;
|
|
175
|
+
return hookRunners.beforeBuild({
|
|
176
|
+
bundlerConfigs: bundlerConfigs
|
|
177
|
+
});
|
|
178
|
+
case 6:
|
|
179
|
+
case "end":
|
|
180
|
+
return _context.stop();
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}, _callee);
|
|
184
|
+
}))();
|
|
185
|
+
},
|
|
186
|
+
onAfterBuild: function onAfterBuild(_ref2) {
|
|
187
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2() {
|
|
188
|
+
var stats, hookRunners;
|
|
189
|
+
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
190
|
+
while (1) {
|
|
191
|
+
switch (_context2.prev = _context2.next) {
|
|
192
|
+
case 0:
|
|
193
|
+
stats = _ref2.stats;
|
|
194
|
+
hookRunners = api.useHookRunners();
|
|
195
|
+
_context2.next = 4;
|
|
196
|
+
return hookRunners.afterBuild({
|
|
197
|
+
stats: stats
|
|
198
|
+
});
|
|
199
|
+
case 4:
|
|
200
|
+
_context2.next = 6;
|
|
201
|
+
return emitResolvedConfig(appContext.appDirectory, normalizedConfig);
|
|
202
|
+
case 6:
|
|
203
|
+
case "end":
|
|
204
|
+
return _context2.stop();
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
}, _callee2);
|
|
208
|
+
}))();
|
|
209
|
+
},
|
|
210
|
+
onDevCompileDone: function onDevCompileDone(_ref3) {
|
|
211
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3() {
|
|
212
|
+
var isFirstCompile, hookRunners;
|
|
213
|
+
return _regeneratorRuntime().wrap(function _callee3$(_context3) {
|
|
214
|
+
while (1) {
|
|
215
|
+
switch (_context3.prev = _context3.next) {
|
|
216
|
+
case 0:
|
|
217
|
+
isFirstCompile = _ref3.isFirstCompile;
|
|
218
|
+
hookRunners = api.useHookRunners();
|
|
219
|
+
if (process.stdout.isTTY || isFirstCompile) {
|
|
220
|
+
hookRunners.afterDev();
|
|
221
|
+
if (isFirstCompile) {
|
|
222
|
+
printInstructions(hookRunners, appContext, normalizedConfig);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
case 3:
|
|
226
|
+
case "end":
|
|
227
|
+
return _context3.stop();
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
}, _callee3);
|
|
231
|
+
}))();
|
|
232
|
+
},
|
|
233
|
+
onBeforeCreateCompiler: function onBeforeCreateCompiler(_ref4) {
|
|
234
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee4() {
|
|
235
|
+
var bundlerConfigs, hookRunners;
|
|
236
|
+
return _regeneratorRuntime().wrap(function _callee4$(_context4) {
|
|
237
|
+
while (1) {
|
|
238
|
+
switch (_context4.prev = _context4.next) {
|
|
239
|
+
case 0:
|
|
240
|
+
bundlerConfigs = _ref4.bundlerConfigs;
|
|
241
|
+
hookRunners = api.useHookRunners(); // run modernjs framework `beforeCreateCompiler` hook
|
|
242
|
+
_context4.next = 4;
|
|
243
|
+
return hookRunners.beforeCreateCompiler({
|
|
244
|
+
bundlerConfigs: bundlerConfigs
|
|
245
|
+
});
|
|
246
|
+
case 4:
|
|
247
|
+
case "end":
|
|
248
|
+
return _context4.stop();
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}, _callee4);
|
|
252
|
+
}))();
|
|
253
|
+
},
|
|
254
|
+
onAfterCreateCompiler: function onAfterCreateCompiler(_ref5) {
|
|
255
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5() {
|
|
256
|
+
var compiler, hookRunners;
|
|
257
|
+
return _regeneratorRuntime().wrap(function _callee5$(_context5) {
|
|
258
|
+
while (1) {
|
|
259
|
+
switch (_context5.prev = _context5.next) {
|
|
260
|
+
case 0:
|
|
261
|
+
compiler = _ref5.compiler;
|
|
262
|
+
hookRunners = api.useHookRunners(); // run modernjs framework afterCreateCompiler hooks
|
|
263
|
+
_context5.next = 4;
|
|
264
|
+
return hookRunners.afterCreateCompiler({
|
|
265
|
+
compiler: compiler
|
|
266
|
+
});
|
|
267
|
+
case 4:
|
|
268
|
+
case "end":
|
|
269
|
+
return _context5.stop();
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}, _callee5);
|
|
273
|
+
}))();
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
case 57:
|
|
278
|
+
builder = _context6.sent;
|
|
279
|
+
appContext = _objectSpread(_objectSpread({}, appContext), {}, {
|
|
280
|
+
builder: builder
|
|
281
|
+
});
|
|
282
|
+
api.setAppContext(appContext);
|
|
283
|
+
case 60:
|
|
157
284
|
case "end":
|
|
158
|
-
return
|
|
285
|
+
return _context6.stop();
|
|
159
286
|
}
|
|
160
287
|
}
|
|
161
|
-
},
|
|
288
|
+
}, _callee6);
|
|
162
289
|
}))();
|
|
163
290
|
},
|
|
164
291
|
watchFiles: function watchFiles() {
|
|
165
292
|
return pagesDir;
|
|
166
293
|
},
|
|
167
294
|
fileChange: function fileChange(e) {
|
|
168
|
-
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function
|
|
295
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee7() {
|
|
169
296
|
var appContext, appDirectory, filename, eventType, isPageFile, absoluteFilePath, isRouteComponent, resolvedConfig, _yield$import, generateCode, entrypoints;
|
|
170
|
-
|
|
171
|
-
return _regeneratorRuntime().wrap(function _callee2$(_context2) {
|
|
297
|
+
return _regeneratorRuntime().wrap(function _callee7$(_context7) {
|
|
172
298
|
while (1) {
|
|
173
|
-
switch (
|
|
299
|
+
switch (_context7.prev = _context7.next) {
|
|
174
300
|
case 0:
|
|
175
301
|
appContext = api.useAppContext();
|
|
176
302
|
appDirectory = appContext.appDirectory;
|
|
177
303
|
filename = e.filename, eventType = e.eventType;
|
|
178
|
-
|
|
179
304
|
isPageFile = function isPageFile(name) {
|
|
180
305
|
return pagesDir.some(function (pageDir) {
|
|
181
306
|
return name.includes(pageDir);
|
|
182
307
|
});
|
|
183
308
|
};
|
|
184
|
-
|
|
185
309
|
absoluteFilePath = path.resolve(appDirectory, filename);
|
|
186
310
|
isRouteComponent = isPageFile(absoluteFilePath) && isRouteComponentFile(absoluteFilePath);
|
|
187
|
-
|
|
188
311
|
if (!(isRouteComponent && (eventType === 'add' || eventType === 'unlink'))) {
|
|
189
|
-
|
|
312
|
+
_context7.next = 14;
|
|
190
313
|
break;
|
|
191
314
|
}
|
|
192
|
-
|
|
193
315
|
resolvedConfig = api.useResolvedConfigContext();
|
|
194
|
-
|
|
316
|
+
_context7.next = 10;
|
|
195
317
|
return import("./generateCode");
|
|
196
|
-
|
|
197
318
|
case 10:
|
|
198
|
-
_yield$import =
|
|
319
|
+
_yield$import = _context7.sent;
|
|
199
320
|
generateCode = _yield$import.generateCode;
|
|
200
321
|
entrypoints = cloneDeep(originEntrypoints);
|
|
201
322
|
generateCode(appContext, resolvedConfig, entrypoints, api);
|
|
202
|
-
|
|
203
323
|
case 14:
|
|
204
324
|
case "end":
|
|
205
|
-
return
|
|
325
|
+
return _context7.stop();
|
|
206
326
|
}
|
|
207
327
|
}
|
|
208
|
-
},
|
|
328
|
+
}, _callee7);
|
|
209
329
|
}))();
|
|
210
330
|
}
|
|
211
331
|
};
|
|
@@ -2,16 +2,13 @@ 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
|
var isFunction = function isFunction(node) {
|
|
7
6
|
return t.isFunctionDeclaration(node) || t.isFunctionExpression(node) || t.isArrowFunctionExpression(node);
|
|
8
7
|
};
|
|
9
|
-
|
|
10
8
|
export var isDefaultExportFunction = function isDefaultExportFunction(file) {
|
|
11
9
|
if (!file || !fs.existsSync(file)) {
|
|
12
10
|
return false;
|
|
13
11
|
}
|
|
14
|
-
|
|
15
12
|
var ast = parse(fs.readFileSync(file, 'utf8'), {
|
|
16
13
|
sourceType: 'unambiguous',
|
|
17
14
|
plugins: ['jsx', 'typescript', 'classProperties', 'dynamicImport', 'exportDefaultFrom', 'exportNamespaceFrom', 'decorators-legacy', 'functionBind', 'classPrivateMethods', ['pipelineOperator', {
|
|
@@ -22,7 +19,6 @@ export var isDefaultExportFunction = function isDefaultExportFunction(file) {
|
|
|
22
19
|
traverse(ast, {
|
|
23
20
|
ExportDefaultDeclaration: function ExportDefaultDeclaration(path) {
|
|
24
21
|
var declaration = path.node.declaration;
|
|
25
|
-
|
|
26
22
|
if (isFunction(declaration)) {
|
|
27
23
|
isExportFunction = true;
|
|
28
24
|
}
|
|
@@ -9,10 +9,8 @@ export function makeLegalIdentifier(str) {
|
|
|
9
9
|
var identifier = str.replace(/-(\w)/g, function (_, letter) {
|
|
10
10
|
return letter.toUpperCase();
|
|
11
11
|
}).replace(/[^$_a-zA-Z0-9]/g, '_');
|
|
12
|
-
|
|
13
12
|
if (/\d/.test(identifier[0]) || forbidList.has(identifier)) {
|
|
14
13
|
return "_".concat(identifier);
|
|
15
14
|
}
|
|
16
|
-
|
|
17
15
|
return identifier || '_';
|
|
18
16
|
}
|
|
@@ -12,59 +12,47 @@ var LOADING_FILE = 'loading';
|
|
|
12
12
|
var ERROR_FILE = 'error';
|
|
13
13
|
var LOADER_FILE = 'loader';
|
|
14
14
|
var conventionNames = [LAYOUT_FILE, PAGE_FILE, LOADING_FILE, ERROR_FILE, LOADER_FILE];
|
|
15
|
-
|
|
16
15
|
var replaceDynamicPath = function replaceDynamicPath(routePath) {
|
|
17
16
|
return routePath.replace(/\[(.*?)\]/g, ':$1');
|
|
18
17
|
};
|
|
19
|
-
|
|
20
|
-
var createIndexRoute = function createIndexRoute(routeInfo, rootDir, filename) {
|
|
18
|
+
var createIndexRoute = function createIndexRoute(routeInfo, rootDir, filename, entryName) {
|
|
21
19
|
return createRoute(_objectSpread(_objectSpread({}, routeInfo), {}, {
|
|
22
20
|
index: true,
|
|
23
21
|
children: undefined
|
|
24
|
-
}), rootDir, filename);
|
|
22
|
+
}), rootDir, filename, entryName);
|
|
25
23
|
};
|
|
26
|
-
|
|
27
|
-
var
|
|
28
|
-
var id = getRouteId(filename, rootDir);
|
|
24
|
+
var createRoute = function createRoute(routeInfo, rootDir, filename, entryName) {
|
|
25
|
+
var id = getRouteId(filename, rootDir, entryName);
|
|
29
26
|
return _objectSpread(_objectSpread({}, routeInfo), {}, {
|
|
30
27
|
id: id,
|
|
31
28
|
type: 'nested'
|
|
32
29
|
});
|
|
33
30
|
};
|
|
34
|
-
|
|
35
31
|
export var walk = /*#__PURE__*/function () {
|
|
36
|
-
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(dirname, rootDir, alias) {
|
|
32
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(dirname, rootDir, alias, entryName) {
|
|
37
33
|
var isDirectory, relativeDir, pathSegments, lastSegment, isRoot, isPathlessLayout, isWithoutLayoutPath, routePath, route, items, _iterator, _step, item, itemPath, extname, itemWithoutExt, _isDirectory, childRoute, _route$children, _route$children2, _childRoute, finalRoute;
|
|
38
|
-
|
|
39
34
|
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
40
35
|
while (1) {
|
|
41
36
|
switch (_context.prev = _context.next) {
|
|
42
37
|
case 0:
|
|
43
38
|
_context.next = 2;
|
|
44
39
|
return fs.pathExists(dirname);
|
|
45
|
-
|
|
46
40
|
case 2:
|
|
47
41
|
if (_context.sent) {
|
|
48
42
|
_context.next = 4;
|
|
49
43
|
break;
|
|
50
44
|
}
|
|
51
|
-
|
|
52
45
|
return _context.abrupt("return", null);
|
|
53
|
-
|
|
54
46
|
case 4:
|
|
55
47
|
_context.next = 6;
|
|
56
48
|
return fs.stat(dirname);
|
|
57
|
-
|
|
58
49
|
case 6:
|
|
59
50
|
isDirectory = _context.sent.isDirectory();
|
|
60
|
-
|
|
61
51
|
if (isDirectory) {
|
|
62
52
|
_context.next = 9;
|
|
63
53
|
break;
|
|
64
54
|
}
|
|
65
|
-
|
|
66
55
|
return _context.abrupt("return", null);
|
|
67
|
-
|
|
68
56
|
case 9:
|
|
69
57
|
relativeDir = path.relative(rootDir, dirname);
|
|
70
58
|
pathSegments = relativeDir.split(path.sep);
|
|
@@ -73,11 +61,9 @@ export var walk = /*#__PURE__*/function () {
|
|
|
73
61
|
isPathlessLayout = lastSegment.startsWith('__');
|
|
74
62
|
isWithoutLayoutPath = lastSegment.includes('.');
|
|
75
63
|
routePath = isRoot || isPathlessLayout ? '/' : "".concat(lastSegment);
|
|
76
|
-
|
|
77
64
|
if (isWithoutLayoutPath) {
|
|
78
65
|
routePath = lastSegment.split('.').join('/');
|
|
79
66
|
}
|
|
80
|
-
|
|
81
67
|
routePath = replaceDynamicPath(routePath);
|
|
82
68
|
route = {
|
|
83
69
|
path: routePath,
|
|
@@ -85,100 +71,76 @@ export var walk = /*#__PURE__*/function () {
|
|
|
85
71
|
};
|
|
86
72
|
_context.next = 21;
|
|
87
73
|
return fs.readdir(dirname);
|
|
88
|
-
|
|
89
74
|
case 21:
|
|
90
75
|
items = _context.sent;
|
|
91
76
|
_iterator = _createForOfIteratorHelper(items);
|
|
92
77
|
_context.prev = 23;
|
|
93
|
-
|
|
94
78
|
_iterator.s();
|
|
95
|
-
|
|
96
79
|
case 25:
|
|
97
80
|
if ((_step = _iterator.n()).done) {
|
|
98
81
|
_context.next = 47;
|
|
99
82
|
break;
|
|
100
83
|
}
|
|
101
|
-
|
|
102
84
|
item = _step.value;
|
|
103
85
|
itemPath = path.join(dirname, item);
|
|
104
86
|
extname = path.extname(item);
|
|
105
87
|
itemWithoutExt = item.slice(0, -extname.length);
|
|
106
88
|
_context.next = 32;
|
|
107
89
|
return fs.stat(itemPath);
|
|
108
|
-
|
|
109
90
|
case 32:
|
|
110
91
|
_isDirectory = _context.sent.isDirectory();
|
|
111
|
-
|
|
112
92
|
if (!_isDirectory) {
|
|
113
93
|
_context.next = 38;
|
|
114
94
|
break;
|
|
115
95
|
}
|
|
116
|
-
|
|
117
96
|
_context.next = 36;
|
|
118
|
-
return walk(itemPath, rootDir, alias);
|
|
119
|
-
|
|
97
|
+
return walk(itemPath, rootDir, alias, entryName);
|
|
120
98
|
case 36:
|
|
121
99
|
childRoute = _context.sent;
|
|
122
|
-
|
|
123
100
|
if (childRoute) {
|
|
124
101
|
(_route$children = route.children) === null || _route$children === void 0 ? void 0 : _route$children.push(childRoute);
|
|
125
102
|
}
|
|
126
|
-
|
|
127
103
|
case 38:
|
|
128
104
|
if (!(extname && (!JS_EXTENSIONS.includes(extname) || !conventionNames.includes(itemWithoutExt)))) {
|
|
129
105
|
_context.next = 40;
|
|
130
106
|
break;
|
|
131
107
|
}
|
|
132
|
-
|
|
133
108
|
return _context.abrupt("continue", 45);
|
|
134
|
-
|
|
135
109
|
case 40:
|
|
136
110
|
if (itemWithoutExt === LAYOUT_FILE) {
|
|
137
111
|
route._component = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
138
112
|
}
|
|
139
|
-
|
|
140
113
|
if (itemWithoutExt === PAGE_FILE) {
|
|
141
114
|
_childRoute = createIndexRoute({
|
|
142
115
|
_component: replaceWithAlias(alias.basename, itemPath, alias.name)
|
|
143
|
-
}, rootDir, itemPath);
|
|
116
|
+
}, rootDir, itemPath, entryName);
|
|
144
117
|
(_route$children2 = route.children) === null || _route$children2 === void 0 ? void 0 : _route$children2.push(_childRoute);
|
|
145
118
|
}
|
|
146
|
-
|
|
147
119
|
if (itemWithoutExt === LOADER_FILE) {
|
|
148
120
|
route.loader = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
149
121
|
}
|
|
150
|
-
|
|
151
122
|
if (itemWithoutExt === LOADING_FILE) {
|
|
152
123
|
route.loading = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
153
124
|
}
|
|
154
|
-
|
|
155
125
|
if (itemWithoutExt === ERROR_FILE) {
|
|
156
126
|
route.error = replaceWithAlias(alias.basename, itemPath, alias.name);
|
|
157
127
|
}
|
|
158
|
-
|
|
159
128
|
case 45:
|
|
160
129
|
_context.next = 25;
|
|
161
130
|
break;
|
|
162
|
-
|
|
163
131
|
case 47:
|
|
164
132
|
_context.next = 52;
|
|
165
133
|
break;
|
|
166
|
-
|
|
167
134
|
case 49:
|
|
168
135
|
_context.prev = 49;
|
|
169
136
|
_context.t0 = _context["catch"](23);
|
|
170
|
-
|
|
171
137
|
_iterator.e(_context.t0);
|
|
172
|
-
|
|
173
138
|
case 52:
|
|
174
139
|
_context.prev = 52;
|
|
175
|
-
|
|
176
140
|
_iterator.f();
|
|
177
|
-
|
|
178
141
|
return _context.finish(52);
|
|
179
|
-
|
|
180
142
|
case 55:
|
|
181
|
-
finalRoute = createRoute(route, rootDir, path.join(dirname, "".concat(LAYOUT_FILE, ".ts")));
|
|
143
|
+
finalRoute = createRoute(route, rootDir, path.join(dirname, "".concat(LAYOUT_FILE, ".ts")), entryName);
|
|
182
144
|
/**
|
|
183
145
|
* when the url is /, the __auth/layout.tsx component should not be rendered
|
|
184
146
|
* - routes
|
|
@@ -186,13 +148,10 @@ export var walk = /*#__PURE__*/function () {
|
|
|
186
148
|
* - layout.tsx
|
|
187
149
|
* - layout.tsx
|
|
188
150
|
*/
|
|
189
|
-
|
|
190
151
|
if (isPathlessLayout) {
|
|
191
152
|
delete finalRoute.path;
|
|
192
153
|
}
|
|
193
|
-
|
|
194
154
|
return _context.abrupt("return", finalRoute);
|
|
195
|
-
|
|
196
155
|
case 58:
|
|
197
156
|
case "end":
|
|
198
157
|
return _context.stop();
|
|
@@ -200,8 +159,7 @@ export var walk = /*#__PURE__*/function () {
|
|
|
200
159
|
}
|
|
201
160
|
}, _callee, null, [[23, 49, 52, 55]]);
|
|
202
161
|
}));
|
|
203
|
-
|
|
204
|
-
return function walk(_x, _x2, _x3) {
|
|
162
|
+
return function walk(_x, _x2, _x3, _x4) {
|
|
205
163
|
return _ref.apply(this, arguments);
|
|
206
164
|
};
|
|
207
165
|
}();
|