@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.
Files changed (214) hide show
  1. package/bin/modern.js +0 -2
  2. package/dist/cjs/builder/shared/builderPlugins/adapterHtml.js +2 -1
  3. package/dist/cjs/builder/shared/builderPlugins/adapterSSR.js +2 -2
  4. package/dist/cjs/commands/build.js +2 -0
  5. package/dist/cjs/commands/deploy.js +2 -2
  6. package/dist/cjs/commands/dev.js +19 -5
  7. package/dist/cjs/commands/index.js +113 -7
  8. package/dist/cjs/commands/serve.js +19 -5
  9. package/dist/cjs/hooks.js +5 -0
  10. package/dist/cjs/index.js +14 -83
  11. package/dist/cjs/plugins/analyze/constants.js +56 -0
  12. package/dist/cjs/{analyze → plugins/analyze}/generateCode.js +11 -84
  13. package/dist/cjs/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
  14. package/dist/cjs/{analyze → plugins/analyze}/getFileSystemEntry.js +33 -47
  15. package/dist/cjs/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  16. package/dist/cjs/{analyze → plugins/analyze}/index.js +9 -24
  17. package/dist/cjs/plugins/analyze/templates.js +101 -0
  18. package/dist/cjs/{analyze → plugins/analyze}/utils.js +12 -55
  19. package/dist/cjs/plugins/deploy/dependencies/index.js +16 -25
  20. package/dist/cjs/plugins/deploy/dependencies/utils.js +1 -2
  21. package/dist/cjs/plugins/deploy/platforms/netlify.js +5 -9
  22. package/dist/cjs/plugins/deploy/platforms/node.js +5 -13
  23. package/dist/cjs/plugins/deploy/platforms/vercel.js +5 -9
  24. package/dist/cjs/{initialize → plugins/initialize}/index.js +1 -1
  25. package/dist/cjs/plugins/serverBuild.js +10 -4
  26. package/dist/cjs/utils/createServer.js +1 -1
  27. package/dist/cjs/utils/{getServerInternalPlugins.js → loadPlugins.js} +18 -11
  28. package/dist/esm/builder/shared/builderPlugins/adapterHtml.js +4 -1
  29. package/dist/esm/builder/shared/builderPlugins/adapterSSR.js +2 -2
  30. package/dist/esm/commands/build.js +16 -9
  31. package/dist/esm/commands/deploy.js +2 -2
  32. package/dist/esm/commands/dev.js +13 -9
  33. package/dist/esm/commands/index.js +411 -3
  34. package/dist/esm/commands/serve.js +12 -8
  35. package/dist/esm/hooks.js +5 -0
  36. package/dist/esm/index.js +12 -394
  37. package/dist/esm/plugins/analyze/constants.js +24 -0
  38. package/dist/esm/{analyze → plugins/analyze}/generateCode.js +27 -169
  39. package/dist/esm/plugins/analyze/getBundleEntry.js +101 -0
  40. package/dist/esm/plugins/analyze/getFileSystemEntry.js +195 -0
  41. package/dist/esm/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  42. package/dist/esm/{analyze → plugins/analyze}/index.js +42 -70
  43. package/dist/esm/plugins/analyze/templates.js +22 -0
  44. package/dist/esm/{analyze → plugins/analyze}/utils.js +13 -135
  45. package/dist/esm/plugins/deploy/dependencies/index.js +69 -94
  46. package/dist/esm/plugins/deploy/dependencies/utils.js +3 -4
  47. package/dist/esm/plugins/deploy/platforms/netlify.js +8 -10
  48. package/dist/esm/plugins/deploy/platforms/node.js +8 -14
  49. package/dist/esm/plugins/deploy/platforms/vercel.js +8 -10
  50. package/dist/esm/{initialize → plugins/initialize}/index.js +1 -1
  51. package/dist/esm/plugins/serverBuild.js +13 -6
  52. package/dist/esm/utils/createServer.js +2 -2
  53. package/dist/esm/utils/loadPlugins.js +64 -0
  54. package/dist/esm-node/builder/shared/builderPlugins/adapterHtml.js +2 -1
  55. package/dist/esm-node/builder/shared/builderPlugins/adapterSSR.js +2 -2
  56. package/dist/esm-node/commands/build.js +2 -0
  57. package/dist/esm-node/commands/deploy.js +2 -2
  58. package/dist/esm-node/commands/dev.js +11 -7
  59. package/dist/esm-node/commands/index.js +92 -3
  60. package/dist/esm-node/commands/serve.js +10 -6
  61. package/dist/esm-node/hooks.js +5 -0
  62. package/dist/esm-node/index.js +12 -79
  63. package/dist/esm-node/plugins/analyze/constants.js +24 -0
  64. package/dist/esm-node/{analyze → plugins/analyze}/generateCode.js +14 -87
  65. package/dist/esm-node/{analyze → plugins/analyze}/getBundleEntry.js +11 -20
  66. package/dist/esm-node/plugins/analyze/getFileSystemEntry.js +75 -0
  67. package/dist/esm-node/{analyze → plugins/analyze}/getServerRoutes.js +1 -1
  68. package/dist/esm-node/{analyze → plugins/analyze}/index.js +10 -25
  69. package/dist/esm-node/plugins/analyze/templates.js +75 -0
  70. package/dist/esm-node/{analyze → plugins/analyze}/utils.js +13 -52
  71. package/dist/esm-node/plugins/deploy/dependencies/index.js +18 -27
  72. package/dist/esm-node/plugins/deploy/dependencies/utils.js +1 -2
  73. package/dist/esm-node/plugins/deploy/platforms/netlify.js +6 -10
  74. package/dist/esm-node/plugins/deploy/platforms/node.js +6 -14
  75. package/dist/esm-node/plugins/deploy/platforms/vercel.js +6 -10
  76. package/dist/esm-node/{initialize → plugins/initialize}/index.js +1 -1
  77. package/dist/esm-node/plugins/serverBuild.js +11 -5
  78. package/dist/esm-node/utils/createServer.js +2 -2
  79. package/dist/esm-node/utils/loadPlugins.js +21 -0
  80. package/dist/types/builder/builder-webpack/createCopyPattern.d.ts +2 -2
  81. package/dist/types/commands/index.d.ts +10 -3
  82. package/dist/types/config/initialize/inits.d.ts +1 -1
  83. package/dist/types/exports/server.d.ts +4 -0
  84. package/dist/types/index.d.ts +2 -5
  85. package/dist/types/plugins/analyze/constants.d.ts +9 -0
  86. package/dist/types/{analyze → plugins/analyze}/generateCode.d.ts +1 -1
  87. package/dist/types/plugins/analyze/getBundleEntry.d.ts +4 -0
  88. package/dist/types/plugins/analyze/getFileSystemEntry.d.ts +5 -0
  89. package/dist/types/{analyze → plugins/analyze}/getHtmlTemplate.d.ts +1 -1
  90. package/dist/types/{analyze → plugins/analyze}/getServerRoutes.d.ts +1 -1
  91. package/dist/types/{analyze → plugins/analyze}/index.d.ts +1 -1
  92. package/dist/types/plugins/analyze/templates.d.ts +19 -0
  93. package/dist/types/{analyze → plugins/analyze}/utils.d.ts +4 -6
  94. package/dist/types/plugins/deploy/dependencies/index.d.ts +1 -9
  95. package/dist/types/plugins/deploy/dependencies/utils.d.ts +1 -7
  96. package/dist/types/{initialize → plugins/initialize}/index.d.ts +1 -1
  97. package/dist/types/types/hooks.d.ts +11 -1
  98. package/dist/types/utils/loadPlugins.d.ts +5 -0
  99. package/package.json +22 -30
  100. package/dist/cjs/analyze/constants.js +0 -122
  101. package/dist/cjs/analyze/getClientRoutes/getRoutes.js +0 -197
  102. package/dist/cjs/analyze/getClientRoutes/getRoutesLegacy.js +0 -195
  103. package/dist/cjs/analyze/getClientRoutes/index.js +0 -31
  104. package/dist/cjs/analyze/getClientRoutes/utils.js +0 -59
  105. package/dist/cjs/analyze/makeLegalIdentifier.js +0 -37
  106. package/dist/cjs/analyze/nestedRoutes.js +0 -295
  107. package/dist/cjs/analyze/templates.js +0 -444
  108. package/dist/cjs/plugins/deploy/exports.js +0 -28
  109. package/dist/esm/analyze/constants.js +0 -76
  110. package/dist/esm/analyze/getBundleEntry.js +0 -75
  111. package/dist/esm/analyze/getClientRoutes/getRoutes.js +0 -185
  112. package/dist/esm/analyze/getClientRoutes/getRoutesLegacy.js +0 -183
  113. package/dist/esm/analyze/getClientRoutes/index.js +0 -6
  114. package/dist/esm/analyze/getClientRoutes/utils.js +0 -28
  115. package/dist/esm/analyze/getFileSystemEntry.js +0 -113
  116. package/dist/esm/analyze/makeLegalIdentifier.js +0 -15
  117. package/dist/esm/analyze/nestedRoutes.js +0 -398
  118. package/dist/esm/analyze/templates.js +0 -435
  119. package/dist/esm/plugins/deploy/exports.js +0 -4
  120. package/dist/esm/utils/getServerInternalPlugins.js +0 -40
  121. package/dist/esm-node/analyze/constants.js +0 -76
  122. package/dist/esm-node/analyze/getClientRoutes/getRoutes.js +0 -163
  123. package/dist/esm-node/analyze/getClientRoutes/getRoutesLegacy.js +0 -161
  124. package/dist/esm-node/analyze/getClientRoutes/index.js +0 -6
  125. package/dist/esm-node/analyze/getClientRoutes/utils.js +0 -22
  126. package/dist/esm-node/analyze/getFileSystemEntry.js +0 -89
  127. package/dist/esm-node/analyze/makeLegalIdentifier.js +0 -13
  128. package/dist/esm-node/analyze/nestedRoutes.js +0 -259
  129. package/dist/esm-node/analyze/templates.js +0 -405
  130. package/dist/esm-node/plugins/deploy/exports.js +0 -4
  131. package/dist/esm-node/utils/getServerInternalPlugins.js +0 -15
  132. package/dist/js/modern/analyze/constants.js +0 -15
  133. package/dist/js/modern/analyze/generateCode.js +0 -179
  134. package/dist/js/modern/analyze/getBundleEntry.js +0 -75
  135. package/dist/js/modern/analyze/getClientRoutes.js +0 -219
  136. package/dist/js/modern/analyze/getFileSystemEntry.js +0 -74
  137. package/dist/js/modern/analyze/getHtmlTemplate.js +0 -82
  138. package/dist/js/modern/analyze/getServerRoutes.js +0 -192
  139. package/dist/js/modern/analyze/index.js +0 -148
  140. package/dist/js/modern/analyze/isDefaultExportFunction.js +0 -32
  141. package/dist/js/modern/analyze/makeLegalIdentifier.js +0 -16
  142. package/dist/js/modern/analyze/templates.js +0 -88
  143. package/dist/js/modern/analyze/utils.js +0 -92
  144. package/dist/js/modern/commands/build.js +0 -154
  145. package/dist/js/modern/commands/deploy.js +0 -5
  146. package/dist/js/modern/commands/dev.js +0 -95
  147. package/dist/js/modern/commands/index.js +0 -3
  148. package/dist/js/modern/commands/inspect.js +0 -69
  149. package/dist/js/modern/commands/start.js +0 -31
  150. package/dist/js/modern/exports/server.js +0 -1
  151. package/dist/js/modern/hooks.js +0 -21
  152. package/dist/js/modern/index.js +0 -109
  153. package/dist/js/modern/locale/en.js +0 -35
  154. package/dist/js/modern/locale/index.js +0 -9
  155. package/dist/js/modern/locale/zh.js +0 -35
  156. package/dist/js/modern/utils/config.js +0 -78
  157. package/dist/js/modern/utils/createCompiler.js +0 -61
  158. package/dist/js/modern/utils/createServer.js +0 -18
  159. package/dist/js/modern/utils/getSpecifiedEntries.js +0 -36
  160. package/dist/js/modern/utils/language.js +0 -5
  161. package/dist/js/modern/utils/printInstructions.js +0 -11
  162. package/dist/js/modern/utils/routes.js +0 -15
  163. package/dist/js/modern/utils/types.js +0 -0
  164. package/dist/js/node/analyze/constants.js +0 -36
  165. package/dist/js/node/analyze/generateCode.js +0 -208
  166. package/dist/js/node/analyze/getBundleEntry.js +0 -89
  167. package/dist/js/node/analyze/getClientRoutes.js +0 -241
  168. package/dist/js/node/analyze/getFileSystemEntry.js +0 -90
  169. package/dist/js/node/analyze/getHtmlTemplate.js +0 -106
  170. package/dist/js/node/analyze/getServerRoutes.js +0 -208
  171. package/dist/js/node/analyze/index.js +0 -178
  172. package/dist/js/node/analyze/isDefaultExportFunction.js +0 -50
  173. package/dist/js/node/analyze/makeLegalIdentifier.js +0 -24
  174. package/dist/js/node/analyze/templates.js +0 -106
  175. package/dist/js/node/analyze/utils.js +0 -113
  176. package/dist/js/node/commands/build.js +0 -174
  177. package/dist/js/node/commands/deploy.js +0 -14
  178. package/dist/js/node/commands/dev.js +0 -120
  179. package/dist/js/node/commands/index.js +0 -44
  180. package/dist/js/node/commands/inspect.js +0 -98
  181. package/dist/js/node/commands/start.js +0 -47
  182. package/dist/js/node/exports/server.js +0 -13
  183. package/dist/js/node/hooks.js +0 -39
  184. package/dist/js/node/index.js +0 -141
  185. package/dist/js/node/locale/en.js +0 -42
  186. package/dist/js/node/locale/index.js +0 -20
  187. package/dist/js/node/locale/zh.js +0 -42
  188. package/dist/js/node/utils/config.js +0 -103
  189. package/dist/js/node/utils/createCompiler.js +0 -81
  190. package/dist/js/node/utils/createServer.js +0 -35
  191. package/dist/js/node/utils/getSpecifiedEntries.js +0 -46
  192. package/dist/js/node/utils/language.js +0 -13
  193. package/dist/js/node/utils/printInstructions.js +0 -22
  194. package/dist/js/node/utils/routes.js +0 -25
  195. package/dist/js/node/utils/types.js +0 -0
  196. package/dist/types/analyze/constants.d.ts +0 -42
  197. package/dist/types/analyze/getBundleEntry.d.ts +0 -3
  198. package/dist/types/analyze/getClientRoutes/getRoutes.d.ts +0 -8
  199. package/dist/types/analyze/getClientRoutes/getRoutesLegacy.d.ts +0 -9
  200. package/dist/types/analyze/getClientRoutes/index.d.ts +0 -2
  201. package/dist/types/analyze/getClientRoutes/utils.d.ts +0 -5
  202. package/dist/types/analyze/getFileSystemEntry.d.ts +0 -4
  203. package/dist/types/analyze/makeLegalIdentifier.d.ts +0 -1
  204. package/dist/types/analyze/nestedRoutes.d.ts +0 -7
  205. package/dist/types/analyze/templates.d.ts +0 -30
  206. package/dist/types/plugins/deploy/exports.d.ts +0 -1
  207. package/dist/types/utils/getServerInternalPlugins.d.ts +0 -2
  208. /package/dist/cjs/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  209. /package/dist/cjs/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  210. /package/dist/esm/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  211. /package/dist/esm/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  212. /package/dist/esm-node/{analyze → plugins/analyze}/getHtmlTemplate.js +0 -0
  213. /package/dist/esm-node/{analyze → plugins/analyze}/isDefaultExportFunction.js +0 -0
  214. /package/dist/types/{analyze → plugins/analyze}/isDefaultExportFunction.d.ts +0 -0
@@ -1,178 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.modifyServerRoutes = exports.modifyFileSystemRoutes = exports.modifyEntryRuntimePlugins = exports.modifyEntryRenderFunction = exports.modifyEntryImports = exports.modifyEntryExport = exports.modifyAsyncEntry = exports.htmlPartials = exports.default = exports.beforeGenerateRoutes = exports.addRuntimeExports = exports.addDefineTypes = void 0;
7
-
8
- var path = _interopRequireWildcard(require("path"));
9
-
10
- var _plugin = require("@modern-js/plugin");
11
-
12
- var _utils = require("@modern-js/utils");
13
-
14
- var _lodash = require("@modern-js/utils/lodash");
15
-
16
- var _utils2 = require("./utils");
17
-
18
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
19
-
20
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
21
-
22
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
23
-
24
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
25
-
26
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
27
-
28
- const debug = (0, _utils.createDebugger)('plugin-analyze');
29
- const modifyEntryImports = (0, _plugin.createAsyncWaterfall)();
30
- exports.modifyEntryImports = modifyEntryImports;
31
- const modifyEntryExport = (0, _plugin.createAsyncWaterfall)();
32
- exports.modifyEntryExport = modifyEntryExport;
33
- const addRuntimeExports = (0, _plugin.createAsyncWaterfall)();
34
- exports.addRuntimeExports = addRuntimeExports;
35
- const modifyEntryRuntimePlugins = (0, _plugin.createAsyncWaterfall)();
36
- exports.modifyEntryRuntimePlugins = modifyEntryRuntimePlugins;
37
- const modifyEntryRenderFunction = (0, _plugin.createAsyncWaterfall)();
38
- exports.modifyEntryRenderFunction = modifyEntryRenderFunction;
39
- const modifyAsyncEntry = (0, _plugin.createAsyncWaterfall)();
40
- exports.modifyAsyncEntry = modifyAsyncEntry;
41
- const modifyFileSystemRoutes = (0, _plugin.createAsyncWaterfall)();
42
- exports.modifyFileSystemRoutes = modifyFileSystemRoutes;
43
- const modifyServerRoutes = (0, _plugin.createAsyncWaterfall)();
44
- exports.modifyServerRoutes = modifyServerRoutes;
45
- const htmlPartials = (0, _plugin.createAsyncWaterfall)();
46
- exports.htmlPartials = htmlPartials;
47
- const beforeGenerateRoutes = (0, _plugin.createAsyncWaterfall)();
48
- exports.beforeGenerateRoutes = beforeGenerateRoutes;
49
- const addDefineTypes = (0, _plugin.createAsyncWaterfall)();
50
- exports.addDefineTypes = addDefineTypes;
51
-
52
- var _default = () => ({
53
- name: '@modern-js/plugin-analyze',
54
- registerHook: {
55
- modifyAsyncEntry,
56
- modifyEntryImports,
57
- modifyEntryExport,
58
- modifyEntryRuntimePlugins,
59
- modifyEntryRenderFunction,
60
- modifyFileSystemRoutes,
61
- modifyServerRoutes,
62
- htmlPartials,
63
- addRuntimeExports,
64
- beforeGenerateRoutes,
65
- addDefineTypes
66
- },
67
- setup: api => {
68
- let pagesDir = [];
69
- let originEntrypoints = [];
70
- return {
71
- async prepare() {
72
- var _resolvedConfig$sourc;
73
-
74
- const appContext = api.useAppContext();
75
- const resolvedConfig = api.useResolvedConfigContext();
76
- const hookRunners = api.useHookRunners();
77
-
78
- try {
79
- _utils.fs.emptydirSync(appContext.internalDirectory);
80
- } catch (_unused) {// FIXME:
81
- }
82
-
83
- const apiOnly = await (0, _utils.isApiOnly)(appContext.appDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$sourc = resolvedConfig.source) === null || _resolvedConfig$sourc === void 0 ? void 0 : _resolvedConfig$sourc.entriesDir);
84
- await hookRunners.addRuntimeExports();
85
-
86
- if (apiOnly) {
87
- const {
88
- routes
89
- } = await hookRunners.modifyServerRoutes({
90
- routes: []
91
- });
92
- debug(`server routes: %o`, routes);
93
- api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
94
- apiOnly,
95
- serverRoutes: routes
96
- }));
97
- return;
98
- }
99
-
100
- const [{
101
- getBundleEntry
102
- }, {
103
- getServerRoutes
104
- }, {
105
- generateCode
106
- }, {
107
- getHtmlTemplate
108
- }] = await Promise.all([Promise.resolve().then(() => _interopRequireWildcard(require("./getBundleEntry"))), Promise.resolve().then(() => _interopRequireWildcard(require("./getServerRoutes"))), Promise.resolve().then(() => _interopRequireWildcard(require("./generateCode"))), Promise.resolve().then(() => _interopRequireWildcard(require("./getHtmlTemplate")))]);
109
- const entrypoints = getBundleEntry(appContext, resolvedConfig);
110
- const defaultChecked = entrypoints.map(point => point.entryName);
111
- debug(`entrypoints: %o`, entrypoints);
112
- const initialRoutes = getServerRoutes(entrypoints, {
113
- appContext,
114
- config: resolvedConfig
115
- });
116
- const {
117
- routes
118
- } = await hookRunners.modifyServerRoutes({
119
- routes: initialRoutes
120
- });
121
- debug(`server routes: %o`, routes);
122
- api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
123
- entrypoints,
124
- serverRoutes: routes
125
- }));
126
- pagesDir = entrypoints.map(point => point.entry);
127
- originEntrypoints = (0, _lodash.cloneDeep)(entrypoints);
128
- await generateCode(appContext, resolvedConfig, entrypoints, api);
129
- const htmlTemplates = await getHtmlTemplate(entrypoints, api, {
130
- appContext,
131
- config: resolvedConfig
132
- });
133
- debug(`html templates: %o`, htmlTemplates);
134
- await hookRunners.addDefineTypes();
135
- debug(`add Define Types`);
136
- api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
137
- entrypoints,
138
- checkedEntries: defaultChecked,
139
- apiOnly,
140
- serverRoutes: routes,
141
- htmlTemplates
142
- }));
143
- },
144
-
145
- watchFiles() {
146
- return pagesDir;
147
- },
148
-
149
- async fileChange(e) {
150
- const appContext = api.useAppContext();
151
- const {
152
- appDirectory
153
- } = appContext;
154
- const {
155
- filename,
156
- eventType
157
- } = e;
158
-
159
- const isPageFile = name => pagesDir.some(pageDir => name.includes(pageDir));
160
-
161
- const absoluteFilePath = path.resolve(appDirectory, filename);
162
- const isRouteComponent = isPageFile(absoluteFilePath) && (0, _utils2.isRouteComponentFile)(absoluteFilePath);
163
-
164
- if (isRouteComponent && (eventType === 'add' || eventType === 'unlink')) {
165
- const resolvedConfig = api.useResolvedConfigContext();
166
- const {
167
- generateCode
168
- } = await Promise.resolve().then(() => _interopRequireWildcard(require("./generateCode")));
169
- const entrypoints = (0, _lodash.cloneDeep)(originEntrypoints);
170
- generateCode(appContext, resolvedConfig, entrypoints, api);
171
- }
172
- }
173
-
174
- };
175
- }
176
- });
177
-
178
- exports.default = _default;
@@ -1,50 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isDefaultExportFunction = void 0;
7
-
8
- var _fs = _interopRequireDefault(require("fs"));
9
-
10
- var _parser = require("@babel/parser");
11
-
12
- var _traverse = _interopRequireDefault(require("@babel/traverse"));
13
-
14
- var t = _interopRequireWildcard(require("@babel/types"));
15
-
16
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
-
18
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- const isFunction = node => t.isFunctionDeclaration(node) || t.isFunctionExpression(node) || t.isArrowFunctionExpression(node);
23
-
24
- const isDefaultExportFunction = file => {
25
- if (!file || !_fs.default.existsSync(file)) {
26
- return false;
27
- }
28
-
29
- const ast = (0, _parser.parse)(_fs.default.readFileSync(file, 'utf8'), {
30
- sourceType: 'unambiguous',
31
- plugins: ['jsx', 'typescript', 'classProperties', 'dynamicImport', 'exportDefaultFrom', 'exportNamespaceFrom', 'decorators-legacy', 'functionBind', 'classPrivateMethods', ['pipelineOperator', {
32
- proposal: 'minimal'
33
- }], 'optionalChaining', 'optionalCatchBinding', 'objectRestSpread', 'numericSeparator']
34
- });
35
- let isExportFunction = false;
36
- (0, _traverse.default)(ast, {
37
- ExportDefaultDeclaration: path => {
38
- const {
39
- declaration
40
- } = path.node;
41
-
42
- if (isFunction(declaration)) {
43
- isExportFunction = true;
44
- }
45
- }
46
- });
47
- return isExportFunction;
48
- };
49
-
50
- exports.isDefaultExportFunction = isDefaultExportFunction;
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.makeLegalIdentifier = makeLegalIdentifier;
7
-
8
- /**
9
- * modified from https://github.com/rollup/plugins/blob/master/packages/pluginutils
10
- * license at https://github.com/rollup/plugins/blob/master/LICENSE
11
- */
12
- const reservedWords = 'break case class catch const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield enum await implements package protected static interface private public';
13
- const builtins = 'arguments Infinity NaN undefined null true false eval uneval isFinite isNaN parseFloat parseInt decodeURI decodeURIComponent encodeURI encodeURIComponent escape unescape Object Function Boolean Symbol Error EvalError InternalError RangeError ReferenceError SyntaxError TypeError URIError Number Math Date String RegExp Array Int8Array Uint8Array Uint8ClampedArray Int16Array Uint16Array Int32Array Uint32Array Float32Array Float64Array Map Set WeakMap WeakSet SIMD ArrayBuffer DataView JSON Promise Generator GeneratorFunction Reflect Proxy Intl';
14
- const forbidList = new Set(`${reservedWords} ${builtins}`.split(' '));
15
-
16
- function makeLegalIdentifier(str) {
17
- const identifier = str.replace(/-(\w)/g, (_, letter) => letter.toUpperCase()).replace(/[^$_a-zA-Z0-9]/g, '_');
18
-
19
- if (/\d/.test(identifier[0]) || forbidList.has(identifier)) {
20
- return `_${identifier}`;
21
- }
22
-
23
- return identifier || '_';
24
- }
@@ -1,106 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.renderFunction = exports.index = exports.html = exports.fileSystemRoutes = void 0;
7
-
8
- const index = ({
9
- mountId,
10
- imports,
11
- renderFunction,
12
- exportStatement
13
- }) => `
14
- const IS_BROWSER = typeof window !== 'undefined' && window.name !== 'nodejs';
15
- const IS_REACT18 = process.env.IS_REACT18 === 'true';
16
- const MOUNT_ID = '${mountId}';
17
-
18
- ${imports}
19
-
20
- let AppWrapper = null;
21
-
22
- let root = null;
23
-
24
- function render() {
25
- ${renderFunction}
26
- }
27
-
28
- AppWrapper = render();
29
-
30
- ${exportStatement};
31
- `;
32
-
33
- exports.index = index;
34
-
35
- const renderFunction = ({
36
- plugins,
37
- customBootstrap,
38
- fileSystemRoutes
39
- }) => `
40
- AppWrapper = createApp({
41
- plugins: [
42
- ${plugins.map(({
43
- name,
44
- options,
45
- args
46
- }) => `${name}({...${options}, ...App?.config?.${args || name}}),`).join('\n')}
47
- ]
48
- })(${fileSystemRoutes ? '' : `App`})
49
-
50
- if (IS_BROWSER) {
51
- ${customBootstrap ? `customBootstrap(AppWrapper);` : `bootstrap(AppWrapper, MOUNT_ID, root, ReactDOM);`}
52
- }
53
-
54
- return AppWrapper
55
- `;
56
-
57
- exports.renderFunction = renderFunction;
58
-
59
- const html = partials => `
60
- <!DOCTYPE html>
61
- <html>
62
- <head>
63
- <%= meta %>
64
- <title><%= title %></title>
65
-
66
- ${partials.top.join('\n')}
67
-
68
- <script>
69
- window.__assetPrefix__ = '<%= assetPrefix %>';
70
- </script>
71
- ${partials.head.join('\n')}
72
-
73
- <!--<?- chunksMap.css ?>-->
74
- </head>
75
-
76
- <body>
77
- <noscript>
78
- We're sorry but react app doesn't work properly without JavaScript enabled. Please enable it to continue.
79
- </noscript>
80
- <div id="<%= mountId %>"><!--<?- html ?>--></div>
81
- ${partials.body.join('\n')}
82
- <!--<?- chunksMap.js ?>-->
83
- <!--<?- SSRDataScript ?>-->
84
- <!--<?- bottomTemplate ?>-->
85
- </body>
86
-
87
- </html>
88
- `;
89
-
90
- exports.html = html;
91
-
92
- const fileSystemRoutes = ({
93
- routes
94
- }) => `
95
- import loadable from '@modern-js/runtime/loadable';
96
-
97
- ${routes.map(({
98
- component,
99
- _component
100
- }) => `const ${component} = loadable(() => import('${_component}'));`).join('\n\n')}
101
-
102
-
103
- export const routes = ${JSON.stringify(routes, null, 2).replace(/"component"\s*:\s*"(\S+)"/g, '"component": $1')}
104
- `;
105
-
106
- exports.fileSystemRoutes = fileSystemRoutes;
@@ -1,113 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.walkDirectory = exports.isRouteComponentFile = exports.getDefaultImports = void 0;
7
-
8
- var _fs = _interopRequireDefault(require("fs"));
9
-
10
- var _path = _interopRequireDefault(require("path"));
11
-
12
- var _utils = require("@modern-js/utils");
13
-
14
- var _constants = require("./constants");
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- const walkDirectory = dir => _fs.default.readdirSync(dir).reduce((previous, filename) => {
19
- const filePath = _path.default.join(dir, filename);
20
-
21
- if (_fs.default.statSync(filePath).isDirectory()) {
22
- return [...previous, ...walkDirectory(filePath)];
23
- } else {
24
- return [...previous, filePath];
25
- }
26
- }, []);
27
-
28
- exports.walkDirectory = walkDirectory;
29
-
30
- const getDefaultImports = ({
31
- entrypoint,
32
- srcDirectory,
33
- internalSrcAlias,
34
- internalDirAlias,
35
- internalDirectory
36
- }) => {
37
- const {
38
- entryName,
39
- fileSystemRoutes,
40
- customBootstrap,
41
- entry
42
- } = entrypoint;
43
- const imports = [{
44
- specifiers: [{
45
- local: 'React'
46
- }],
47
- value: 'react'
48
- }, {
49
- specifiers: [{
50
- local: 'ReactDOM'
51
- }],
52
- value: (0, _utils.isReact18)(_path.default.join(internalDirectory, '../../')) ? 'react-dom/client' : 'react-dom'
53
- }, {
54
- specifiers: [{
55
- imported: 'createApp'
56
- }, {
57
- imported: 'bootstrap'
58
- }],
59
- value: '@modern-js/runtime'
60
- }, customBootstrap && {
61
- specifiers: [{
62
- local: 'customBootstrap'
63
- }],
64
- value: (0, _utils.normalizeToPosixPath)(customBootstrap.replace(srcDirectory, internalSrcAlias))
65
- }].filter(Boolean);
66
-
67
- if (fileSystemRoutes) {
68
- const route = {
69
- specifiers: [{
70
- imported: 'routes'
71
- }],
72
- value: (0, _utils.normalizeToPosixPath)(`${internalDirAlias}/${entryName}/${_constants.FILE_SYSTEM_ROUTES_FILE_NAME}`)
73
- };
74
-
75
- if (fileSystemRoutes.globalApp) {
76
- imports.push({
77
- specifiers: [{
78
- local: 'App'
79
- }],
80
- value: (0, _utils.normalizeToPosixPath)(fileSystemRoutes.globalApp.replace(srcDirectory, internalSrcAlias))
81
- });
82
- } else {
83
- route.initialize = 'const App = false;';
84
- }
85
-
86
- imports.push(route);
87
- } else {
88
- imports.push({
89
- specifiers: [{
90
- local: 'App'
91
- }],
92
- value: (0, _utils.normalizeToPosixPath)(entry.replace(srcDirectory, internalSrcAlias))
93
- });
94
- }
95
-
96
- return imports;
97
- };
98
-
99
- exports.getDefaultImports = getDefaultImports;
100
-
101
- const isRouteComponentFile = filePath => {
102
- if (/\.(d|test|spec|e2e)\.(js|jsx|ts|tsx)$/.test(filePath)) {
103
- return false;
104
- }
105
-
106
- if (['.js', '.jsx', '.ts', '.tsx'].includes(_path.default.extname(filePath))) {
107
- return true;
108
- }
109
-
110
- return false;
111
- };
112
-
113
- exports.isRouteComponentFile = isRouteComponentFile;
@@ -1,174 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.build = void 0;
7
-
8
- var _webpack = require("@modern-js/webpack");
9
-
10
- var _core = require("@modern-js/core");
11
-
12
- var _utils = require("@modern-js/utils");
13
-
14
- var _routes = require("../utils/routes");
15
-
16
- var _config = require("../utils/config");
17
-
18
- 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; }
19
-
20
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
21
-
22
- 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; }
23
-
24
- // These sizes are pretty large. We'll warn for bundles exceeding them.
25
- const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
26
- const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
27
-
28
- const build = async (api, options) => {
29
- let resolvedConfig = api.useResolvedConfigContext();
30
- const appContext = api.useAppContext();
31
- const hookRunners = api.useHookRunners();
32
- const {
33
- apiOnly
34
- } = appContext;
35
-
36
- if (apiOnly) {
37
- const {
38
- appDirectory,
39
- distDirectory,
40
- serverConfigFile
41
- } = appContext;
42
- await (0, _utils.emptyDir)(distDirectory);
43
- await hookRunners.beforeBuild({
44
- webpackConfigs: []
45
- });
46
- await (0, _config.buildServerConfig)({
47
- appDirectory,
48
- distDirectory,
49
- configFile: serverConfigFile
50
- });
51
- await (0, _routes.generateRoutes)(appContext);
52
- await hookRunners.afterBuild();
53
- return;
54
- }
55
-
56
- const webpackBuild = async (webpackConfig, type) => {
57
- const compiler = (0, _webpack.webpack)(webpackConfig);
58
- return new Promise((resolve, reject) => {
59
- let label = process.env.NODE_ENV || '';
60
-
61
- if (type && type !== 'legacy') {
62
- label += ` ${type}`;
63
- }
64
-
65
- _utils.logger.info(`Creating a ${label} build...`);
66
-
67
- compiler.run((err, stats) => {
68
- let messages;
69
-
70
- if (!err) {
71
- messages = (0, _utils.formatWebpackMessages)(stats.toJson({
72
- all: false,
73
- warnings: true,
74
- errors: true
75
- }));
76
-
77
- if (messages.errors.length === 0) {
78
- _utils.logger.info(`File sizes after ${label} build:\n`);
79
-
80
- (0, _utils.printFileSizesAfterBuild)(stats, previousFileSizes, distDirectory, WARN_AFTER_BUNDLE_GZIP_SIZE, WARN_AFTER_CHUNK_GZIP_SIZE);
81
-
82
- _utils.logger.log();
83
- }
84
- } // When using run or watch, call close and wait for it to finish before calling run or watch again.
85
- // Concurrent compilations will corrupt the output files.
86
-
87
-
88
- compiler.close(closeErr => {
89
- if (closeErr) {
90
- _utils.logger.error(closeErr);
91
- }
92
-
93
- if (err) {
94
- reject(err);
95
- } else {
96
- if (messages.errors.length) {
97
- reject(new Error(messages.errors.join('\n\n')));
98
- return;
99
- }
100
-
101
- resolve({
102
- warnings: messages.warnings
103
- });
104
- }
105
- });
106
- });
107
- });
108
- };
109
-
110
- resolvedConfig = _objectSpread(_objectSpread({}, resolvedConfig), {}, {
111
- cliOptions: options
112
- });
113
-
114
- _core.ResolvedConfigContext.set(resolvedConfig);
115
-
116
- const {
117
- distDirectory,
118
- appDirectory,
119
- serverConfigFile
120
- } = appContext;
121
- const previousFileSizes = await (0, _utils.measureFileSizesBeforeBuild)(distDirectory);
122
- await (0, _utils.emptyDir)(distDirectory);
123
- await (0, _config.buildServerConfig)({
124
- appDirectory,
125
- distDirectory,
126
- configFile: serverConfigFile
127
- });
128
- const buildConfigs = [];
129
- buildConfigs.push({
130
- type: 'legacy',
131
- config: (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.CLIENT, appContext, resolvedConfig)
132
- });
133
-
134
- if (resolvedConfig.output.enableModernMode) {
135
- buildConfigs.push({
136
- type: 'modern',
137
- config: (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.MODERN, appContext, resolvedConfig)
138
- });
139
- }
140
-
141
- if ((0, _utils.isUseSSRBundle)(resolvedConfig)) {
142
- buildConfigs.push({
143
- type: 'ssr',
144
- config: (0, _webpack.getWebpackConfig)(_webpack.WebpackConfigTarget.NODE, appContext, resolvedConfig)
145
- });
146
- }
147
-
148
- await hookRunners.beforeBuild({
149
- webpackConfigs: buildConfigs.map(({
150
- config
151
- }) => config)
152
- });
153
-
154
- for (const buildConfig of buildConfigs) {
155
- const {
156
- type: buildType,
157
- config
158
- } = buildConfig;
159
-
160
- try {
161
- await webpackBuild(config, buildType);
162
- } catch (error) {
163
- (0, _utils.printBuildError)(error); // eslint-disable-next-line no-process-exit
164
-
165
- process.exit(1);
166
- }
167
- }
168
-
169
- await (0, _routes.generateRoutes)(appContext);
170
- await hookRunners.afterBuild();
171
- await (0, _config.emitResolvedConfig)(appDirectory, resolvedConfig);
172
- };
173
-
174
- exports.build = build;
@@ -1,14 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.deploy = void 0;
7
-
8
- const deploy = async (api, options) => {
9
- const hookRunners = api.useHookRunners();
10
- await hookRunners.beforeDeploy(options);
11
- await hookRunners.afterDeploy(options);
12
- };
13
-
14
- exports.deploy = deploy;