@modern-js/app-tools 2.0.1 → 2.0.3-alpha.0

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.
Files changed (37) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/dist/js/modern/analyze/generateCode.js +4 -81
  3. package/dist/js/modern/analyze/index.js +26 -12
  4. package/dist/js/modern/analyze/nestedRoutes.js +2 -15
  5. package/dist/js/modern/analyze/templates.js +35 -60
  6. package/dist/js/modern/analyze/utils.js +9 -1
  7. package/dist/js/modern/config/initial/inits.js +1 -9
  8. package/dist/js/modern/index.js +6 -7
  9. package/dist/js/modern/locale/en.js +2 -1
  10. package/dist/js/modern/locale/zh.js +2 -1
  11. package/dist/js/node/analyze/generateCode.js +2 -77
  12. package/dist/js/node/analyze/index.js +24 -10
  13. package/dist/js/node/analyze/nestedRoutes.js +1 -14
  14. package/dist/js/node/analyze/templates.js +35 -60
  15. package/dist/js/node/analyze/utils.js +10 -1
  16. package/dist/js/node/config/initial/inits.js +1 -9
  17. package/dist/js/node/index.js +2 -3
  18. package/dist/js/node/locale/en.js +2 -1
  19. package/dist/js/node/locale/zh.js +2 -1
  20. package/dist/js/treeshaking/analyze/generateCode.js +21 -148
  21. package/dist/js/treeshaking/analyze/index.js +25 -18
  22. package/dist/js/treeshaking/analyze/nestedRoutes.js +26 -77
  23. package/dist/js/treeshaking/analyze/templates.js +97 -76
  24. package/dist/js/treeshaking/analyze/utils.js +5 -2
  25. package/dist/js/treeshaking/config/initial/inits.js +1 -12
  26. package/dist/js/treeshaking/index.js +8 -9
  27. package/dist/js/treeshaking/locale/en.js +2 -1
  28. package/dist/js/treeshaking/locale/zh.js +2 -1
  29. package/dist/types/analyze/utils.d.ts +2 -1
  30. package/dist/types/locale/en.d.ts +1 -0
  31. package/dist/types/locale/index.d.ts +2 -0
  32. package/dist/types/locale/zh.d.ts +1 -0
  33. package/package.json +24 -24
  34. package/dist/js/modern/analyze/Builder.js +0 -39
  35. package/dist/js/node/analyze/Builder.js +0 -64
  36. package/dist/js/treeshaking/analyze/Builder.js +0 -199
  37. package/dist/types/analyze/Builder.d.ts +0 -8
@@ -73,7 +73,6 @@ var import_config = require("../utils/config");
73
73
  var import_commands = require("../utils/commands");
74
74
  var import_config2 = require("../config");
75
75
  var import_utils2 = require("./utils");
76
- var import_Builder = require("./Builder");
77
76
  var import_constants = require("./constants");
78
77
  const debug = (0, import_utils.createDebugger)("plugin-analyze");
79
78
  var analyze_default = () => ({
@@ -224,6 +223,27 @@ var analyze_default = () => ({
224
223
  watchFiles() {
225
224
  return pagesDir;
226
225
  },
226
+ config() {
227
+ return {
228
+ tools: {
229
+ webpackChain: (chain, { name, CHAIN_ID }) => {
230
+ const appContext = api.useAppContext();
231
+ const resolvedConfig = api.useResolvedConfigContext();
232
+ const { entrypoints, internalDirectory } = appContext;
233
+ entrypoints.forEach((entrypoint) => {
234
+ const { entryName } = entrypoint;
235
+ if (entrypoint.nestedRoutesEntry && (0, import_utils.isUseSSRBundle)(resolvedConfig)) {
236
+ const serverLoadersFile = (0, import_utils2.getServerLoadersFile)(
237
+ internalDirectory,
238
+ entryName
239
+ );
240
+ chain.entry(`${entryName}-server-loaders`).add(serverLoadersFile);
241
+ }
242
+ });
243
+ }
244
+ }
245
+ };
246
+ },
227
247
  resolvedConfig({ resolved }) {
228
248
  const appContext = api.useAppContext();
229
249
  const config = (0, import_config2.initialNormalizedConfig)(resolved, appContext);
@@ -234,7 +254,7 @@ var analyze_default = () => ({
234
254
  modifyEntryImports(_0) {
235
255
  return __async(this, arguments, function* ({ entrypoint, imports }) {
236
256
  const appContext = api.useAppContext();
237
- const { srcDirectory } = appContext;
257
+ const { srcDirectory, internalSrcAlias } = appContext;
238
258
  const { fileSystemRoutes, nestedRoutesEntry } = entrypoint;
239
259
  if (fileSystemRoutes && nestedRoutesEntry) {
240
260
  const rootLayoutPath = path.join(nestedRoutesEntry, "layout");
@@ -256,7 +276,7 @@ var analyze_default = () => ({
256
276
  const generateLayoutPath = (0, import_utils2.replaceWithAlias)(
257
277
  srcDirectory,
258
278
  rootLayoutFile,
259
- "@_modern_js_src"
279
+ internalSrcAlias
260
280
  );
261
281
  if (hasAppConfig) {
262
282
  imports.push({
@@ -283,12 +303,6 @@ var analyze_default = () => ({
283
303
  };
284
304
  });
285
305
  },
286
- beforeRestart() {
287
- return __async(this, null, function* () {
288
- import_Builder.serverLoaderBuilder.stop();
289
- import_Builder.loaderBuilder.stop();
290
- });
291
- },
292
306
  fileChange(e) {
293
307
  return __async(this, null, function* () {
294
308
  const appContext = api.useAppContext();
@@ -297,7 +311,7 @@ var analyze_default = () => ({
297
311
  const isPageFile = (name) => pagesDir.some((pageDir) => name.includes(pageDir));
298
312
  const absoluteFilePath = path.resolve(appDirectory, filename);
299
313
  const isRouteComponent = isPageFile(absoluteFilePath) && (0, import_utils2.isPageComponentFile)(absoluteFilePath);
300
- if (isRouteComponent && (eventType === "add" || eventType === "unlink") || (0, import_utils2.isNestedRouteComponent)(nestedRouteEntries, absoluteFilePath) && eventType === "change") {
314
+ if (isRouteComponent && (eventType === "add" || eventType === "unlink")) {
301
315
  const resolvedConfig = api.useResolvedConfigContext();
302
316
  const { generateCode } = yield Promise.resolve().then(() => __toESM(require("./generateCode")));
303
317
  const entrypoints = (0, import_lodash.cloneDeep)(originEntrypoints);
@@ -68,12 +68,6 @@ var import_utils = require("@modern-js/utils");
68
68
  var import_constants = require("./constants");
69
69
  var import_utils2 = require("./utils");
70
70
  const conventionNames = Object.values(import_constants.NESTED_ROUTE);
71
- const getLoaderPath = (filename) => __async(void 0, null, function* () {
72
- if (yield (0, import_utils2.hasLoader)(filename)) {
73
- return filename;
74
- }
75
- return void 0;
76
- });
77
71
  const replaceDynamicPath = (routePath) => {
78
72
  return routePath.replace(/\[(.*?)\]/g, ":$1");
79
73
  };
@@ -144,10 +138,6 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
144
138
  }
145
139
  if (itemWithoutExt === import_constants.NESTED_ROUTE.LAYOUT_FILE) {
146
140
  route._component = (0, import_utils2.replaceWithAlias)(alias.basename, itemPath, alias.name);
147
- const loaderPath = yield getLoaderPath(itemPath);
148
- if (loaderPath) {
149
- route.loader = loaderPath;
150
- }
151
141
  }
152
142
  if (itemWithoutExt === import_constants.NESTED_ROUTE.PAGE_LOADER_FILE) {
153
143
  pageLoaderFile = itemPath;
@@ -161,10 +151,7 @@ const walk = (dirname, rootDir, alias, entryName) => __async(void 0, null, funct
161
151
  itemPath,
162
152
  entryName
163
153
  );
164
- const loaderPath = yield getLoaderPath(itemPath);
165
- if (loaderPath) {
166
- pageRoute.loader = loaderPath;
167
- } else if (pageLoaderFile) {
154
+ if (pageLoaderFile) {
168
155
  pageRoute.loader = pageLoaderFile;
169
156
  }
170
157
  (_b = route.children) == null ? void 0 : _b.push(pageRoute);
@@ -205,10 +205,9 @@ const routesForServer = ({
205
205
  ];`;
206
206
  let importLoadersCode = "";
207
207
  if (loaders.length > 0) {
208
- importLoadersCode = `
209
- import { ${loaders.map(
210
- (loader, index2) => `loader_${index2}`
211
- )} } from "${(0, import_utils.slash)(loaderIndexFile)}"`;
208
+ importLoadersCode = loaders.map((loader, index2) => {
209
+ return `import loader_${index2} from "${loader}"`;
210
+ }).join("\n");
212
211
  }
213
212
  return `
214
213
  ${importLoadersCode}
@@ -227,12 +226,6 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
227
226
  const errors = [];
228
227
  const loaders = [];
229
228
  const loadersMap = {};
230
- const loadersIndexFile = import_path.default.join(
231
- internalDirAlias,
232
- entryName,
233
- import_constants.TEMP_LOADERS_DIR,
234
- "index.js"
235
- );
236
229
  const loadersMapFile = import_path.default.join(
237
230
  internalDirectory,
238
231
  entryName,
@@ -244,13 +237,17 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
244
237
  import loadable, { lazy as loadableLazy } from "@modern-js/runtime/loadable"
245
238
  `;
246
239
  let rootLayoutCode = ``;
247
- let dataLoaderPath = "";
248
240
  let componentLoaderPath = "";
249
- if (ssrMode) {
250
- dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
241
+ const getDataLoaderPath = (loaderId) => {
242
+ if (!ssrMode)
243
+ return "";
244
+ let dataLoaderPath = require.resolve("@modern-js/plugin-data-loader/loader");
251
245
  if (nestedRoutesEntry) {
252
- dataLoaderPath = `${dataLoaderPath}?routesDir=${nestedRoutesEntry}&mapFile=${loadersMapFile}!`;
246
+ dataLoaderPath = `${(0, import_utils.slash)(dataLoaderPath)}?mapFile=${(0, import_utils.slash)(loadersMapFile)}&loaderId=${loaderId}!`;
253
247
  }
248
+ return dataLoaderPath;
249
+ };
250
+ if (ssrMode) {
254
251
  componentLoaderPath = `${import_path.default.join(
255
252
  __dirname,
256
253
  "../builder/loaders/routerLoader"
@@ -266,6 +263,7 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
266
263
  let error;
267
264
  let loader;
268
265
  let component = "";
266
+ let lazyImport = null;
269
267
  if (route.type === "nested") {
270
268
  if (route.loading) {
271
269
  loadings.push(route.loading);
@@ -279,22 +277,30 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
279
277
  loaders.push(route.loader);
280
278
  const loaderId = loaders.length - 1;
281
279
  loader = `loader_${loaderId}`;
282
- loadersMap[loader] = route.id;
280
+ loadersMap[loader] = {
281
+ routeId: route.id,
282
+ filePath: route.loader,
283
+ inline: false
284
+ };
283
285
  }
284
286
  if (route._component) {
285
287
  if (route.isRoot) {
286
288
  rootLayoutCode = `import RootLayout from '${route._component}'`;
287
289
  component = `RootLayout`;
288
290
  } else if (ssrMode === "string") {
289
- component = `loadable(() => import(/* webpackChunkName: "${route.id}" */ '${componentLoaderPath}${route._component}'))`;
291
+ lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${componentLoaderPath}${route._component}')`;
292
+ component = `loadable(${lazyImport})`;
290
293
  } else {
291
- component = `lazy(() => import(/* webpackChunkName: "${route.id}" */ '${componentLoaderPath}${route._component}'))`;
294
+ lazyImport = `() => import(/* webpackChunkName: "${route.id}" */ '${componentLoaderPath}${route._component}')`;
295
+ component = `lazy(${lazyImport})`;
292
296
  }
293
297
  }
294
298
  } else if (route._component) {
295
- component = `loadable(() => import('${route._component}'))`;
299
+ lazyImport = `() => import('${route._component}')`;
300
+ component = `loadable(${lazyImport})`;
296
301
  }
297
302
  const finalRoute = __spreadProps(__spreadValues({}, route), {
303
+ lazyImport,
298
304
  loading,
299
305
  loader,
300
306
  error,
@@ -311,7 +317,7 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
311
317
  for (const route of routes) {
312
318
  if ("type" in route) {
313
319
  const newRoute = traverseRouteTree(route);
314
- routeComponentsCode += `${JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g, "$1").replace(/"(loadableLazy.*\))"/g, "$1").replace(/"(lazy.*\))"/g, "$1").replace(/"(loading_[^"])"/g, "$1").replace(/"(loader_[^"])"/g, "$1").replace(/"(RootLayout)"/g, "$1").replace(/"(error_[^"])"/g, "$1").replace(/\\"/g, '"')},`;
320
+ routeComponentsCode += `${JSON.stringify(newRoute, null, 2).replace(/"(loadable.*\))"/g, "$1").replace(/"(loadableLazy.*\))"/g, "$1").replace(/"(\(\)[^,]+)",/g, "$1,").replace(/"(lazy\(.*\))"/g, "$1").replace(/"(loading_[^"])"/g, "$1").replace(/"(loader_[^"])"/g, "$1").replace(/"(RootLayout)"/g, "$1").replace(/"(error_[^"])"/g, "$1").replace(/\\"/g, '"')},`;
315
321
  } else {
316
322
  const component = `loadable(() => import('${route._component}'))`;
317
323
  const finalRoute = __spreadProps(__spreadValues({}, route), {
@@ -331,48 +337,17 @@ const fileSystemRoutes = (_0) => __async(void 0, [_0], function* ({
331
337
  `;
332
338
  }).join("");
333
339
  let importLoadersCode = "";
334
- if (loaders.length > 0) {
335
- importLoadersCode = `
336
- import { ${loaders.map(
337
- (loader, index2) => `loader_${index2}`
338
- )} } from "${(0, import_utils.slash)(dataLoaderPath)}${(0, import_utils.slash)(loadersIndexFile)}"
339
- `;
340
- const loaderEntryCode = loaders.map((loader, index2) => {
341
- return `export * from './loader_${index2}.js';`;
342
- }).join("\n");
343
- const loaderEntryFile = import_path.default.join(
344
- internalDirectory,
345
- entryName,
346
- import_constants.TEMP_LOADERS_DIR,
347
- "entry.js"
348
- );
349
- yield import_utils.fs.ensureFile(loaderEntryFile);
350
- yield import_utils.fs.writeFile(loaderEntryFile, loaderEntryCode);
351
- yield import_utils.fs.writeJSON(loadersMapFile, loadersMap);
352
- yield Promise.all(
353
- loaders.map((loader, index2) => __async(void 0, null, function* () {
354
- const name = `loader_${index2}`;
355
- const filename = import_path.default.join(
356
- internalDirectory,
357
- entryName,
358
- import_constants.TEMP_LOADERS_DIR,
359
- `${name}.js`
360
- );
361
- let code = "";
362
- if (loader.includes(".loader.")) {
363
- code = `
364
- export { default as ${name} } from '${(0, import_utils.slash)(loader)}'
365
- `;
366
- } else {
367
- code = `
368
- export { loader as ${name} } from '${(0, import_utils.slash)(loader)}'
369
- `;
370
- }
371
- yield import_utils.fs.ensureFile(filename);
372
- yield import_utils.fs.writeFile(filename, code);
373
- }))
374
- );
340
+ for (const [key, loaderInfo] of Object.entries(loadersMap)) {
341
+ if (loaderInfo.inline) {
342
+ importLoadersCode += `import { loader as ${key} } from "${getDataLoaderPath(key)}${loaderInfo.filePath}";
343
+ `;
344
+ } else {
345
+ importLoadersCode += `import ${key} from "${getDataLoaderPath(key)}${loaderInfo.filePath}";
346
+ `;
347
+ }
375
348
  }
349
+ yield import_utils.fs.ensureFile(loadersMapFile);
350
+ yield import_utils.fs.writeJSON(loadersMapFile, loadersMap);
376
351
  return `
377
352
  ${importLazyCode}
378
353
  ${rootLayoutCode}
@@ -44,6 +44,7 @@ var __async = (__this, __arguments, generator) => {
44
44
  var utils_exports = {};
45
45
  __export(utils_exports, {
46
46
  getDefaultImports: () => getDefaultImports,
47
+ getServerLoadersFile: () => getServerLoadersFile,
47
48
  hasLoader: () => hasLoader,
48
49
  isNestedRouteComponent: () => isNestedRouteComponent,
49
50
  isPageComponentFile: () => isPageComponentFile,
@@ -136,7 +137,7 @@ const isPageComponentFile = (filePath) => {
136
137
  };
137
138
  const isNestedRouteComponent = (nestedRouteEntries, absoluteFilePath) => {
138
139
  const reg = new RegExp(
139
- `(${import_constants.NESTED_ROUTE.LAYOUT_FILE}|${import_constants.NESTED_ROUTE.PAGE_FILE}})\\.tsx?$`
140
+ `(${import_constants.NESTED_ROUTE.LAYOUT_FILE}|${import_constants.NESTED_ROUTE.PAGE_FILE})\\.tsx?$`
140
141
  );
141
142
  return nestedRouteEntries.some((nestedRoutesEntry) => {
142
143
  if (absoluteFilePath.includes(nestedRoutesEntry) && reg.test(absoluteFilePath)) {
@@ -168,9 +169,17 @@ const hasLoader = (filename) => __async(void 0, null, function* () {
168
169
  });
169
170
  return moduleExports.some((e) => e.n === import_constants.LOADER_EXPORT_NAME);
170
171
  });
172
+ const getServerLoadersFile = (internalDirectory, entryName) => {
173
+ return import_path.default.join(
174
+ internalDirectory,
175
+ entryName,
176
+ "route-server-loaders.js"
177
+ );
178
+ };
171
179
  // Annotate the CommonJS export names for ESM import in node:
172
180
  0 && (module.exports = {
173
181
  getDefaultImports,
182
+ getServerLoadersFile,
174
183
  hasLoader,
175
184
  isNestedRouteComponent,
176
185
  isPageComponentFile,
@@ -154,7 +154,7 @@ function initToolsConfig(config) {
154
154
  ]
155
155
  }
156
156
  };
157
- const { tsChecker, tsLoader, htmlPlugin } = config.tools;
157
+ const { tsChecker, tsLoader } = config.tools;
158
158
  config.tools.tsChecker = (0, import_utils.applyOptionsChain)(defaultTsChecker, tsChecker);
159
159
  tsLoader && (config.tools.tsLoader = (tsLoaderConfig, utils) => {
160
160
  (0, import_utils.applyOptionsChain)(
@@ -166,14 +166,6 @@ function initToolsConfig(config) {
166
166
  utils
167
167
  );
168
168
  });
169
- config.tools.htmlPlugin = [
170
- (config2) => __spreadProps(__spreadValues({}, config2), {
171
- minify: typeof config2.minify === "object" ? __spreadProps(__spreadValues({}, config2.minify), {
172
- removeComments: false
173
- }) : config2.minify
174
- }),
175
- ...Array.isArray(htmlPlugin) ? htmlPlugin : htmlPlugin ? [htmlPlugin] : []
176
- ];
177
169
  }
178
170
  // Annotate the CommonJS export names for ESM import in node:
179
171
  0 && (module.exports = {
@@ -112,7 +112,6 @@ const buildCommand = (program, api) => __async(void 0, null, function* () {
112
112
  const buildProgram = program.command("build").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.build.describe)).option("-c --config <config>", import_locale.i18n.t(import_locale.localeKeys.command.shared.config)).option("--analyze", import_locale.i18n.t(import_locale.localeKeys.command.shared.analyze)).action((options) => __async(void 0, null, function* () {
113
113
  const { build } = yield Promise.resolve().then(() => __toESM(require("./commands/build")));
114
114
  yield build(api, options);
115
- process.exit(0);
116
115
  }));
117
116
  for (const platformBuilder of platformBuilders) {
118
117
  const platforms = (0, import_lodash.castArray)(platformBuilder.platform);
@@ -167,12 +166,12 @@ var src_default = () => ({
167
166
  yield deploy(api, options);
168
167
  process.exit(0);
169
168
  }));
170
- program.command("new").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.new.describe)).option("-d, --debug", import_locale.i18n.t(import_locale.localeKeys.command.new.debug), false).option(
169
+ program.command("new").usage("[options]").description(import_locale.i18n.t(import_locale.localeKeys.command.new.describe)).option("--lang <lang>", import_locale.i18n.t(import_locale.localeKeys.command.new.lang)).option("-d, --debug", import_locale.i18n.t(import_locale.localeKeys.command.new.debug), false).option(
171
170
  "-c, --config <config>",
172
171
  import_locale.i18n.t(import_locale.localeKeys.command.new.config)
173
172
  ).option("--dist-tag <tag>", import_locale.i18n.t(import_locale.localeKeys.command.new.distTag)).option("--registry", import_locale.i18n.t(import_locale.localeKeys.command.new.registry)).action((options) => __async(this, null, function* () {
174
173
  const { MWANewAction } = yield Promise.resolve().then(() => __toESM(require("@modern-js/new-action")));
175
- yield MWANewAction(__spreadProps(__spreadValues({}, options), { locale }));
174
+ yield MWANewAction(__spreadProps(__spreadValues({}, options), { locale: options.lang || locale }));
176
175
  }));
177
176
  program.command("inspect").description("inspect internal webpack config").option(
178
177
  `--env <env>`,
@@ -41,7 +41,8 @@ const EN_LOCALE = {
41
41
  debug: "using debug mode to log something",
42
42
  config: "set default generator config(json string)",
43
43
  distTag: `use specified tag version for it's generator`,
44
- registry: "set npm registry url to run npm command"
44
+ registry: "set npm registry url to run npm command",
45
+ lang: "set new command language(en or zh)"
45
46
  },
46
47
  inspect: {
47
48
  env: "specify env mode",
@@ -41,7 +41,8 @@ const ZH_LOCALE = {
41
41
  debug: "开启 Debug 模式,打印调试日志信息",
42
42
  config: "生成器运行默认配置(JSON 字符串)",
43
43
  distTag: "生成器使用特殊的 npm Tag 版本",
44
- registry: "生成器运行过程中定制 npm Registry"
44
+ registry: "生成器运行过程中定制 npm Registry",
45
+ lang: "设置 new 命令执行语言(zh 或者 en)"
45
46
  },
46
47
  inspect: {
47
48
  env: "查看指定环境下的配置",
@@ -148,20 +148,13 @@ var __generator = this && this.__generator || function(thisArg, body) {
148
148
  }
149
149
  };
150
150
  import path from "path";
151
- import { fs, getEntryOptions, LOADER_ROUTES_DIR, logger } from "@modern-js/utils";
151
+ import { fs, getEntryOptions, logger } from "@modern-js/utils";
152
152
  import { useResolvedConfigContext } from "@modern-js/core";
153
- import { isDevCommand } from "../utils/commands";
154
153
  import * as templates from "./templates";
155
154
  import { getClientRoutes, getClientRoutesLegacy } from "./getClientRoutes";
156
- import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME, TEMP_LOADERS_DIR } from "./constants";
157
- import { getDefaultImports } from "./utils";
155
+ import { FILE_SYSTEM_ROUTES_FILE_NAME, ENTRY_POINT_FILE_NAME, ENTRY_BOOTSTRAP_FILE_NAME } from "./constants";
156
+ import { getDefaultImports, getServerLoadersFile } from "./utils";
158
157
  import { walk } from "./nestedRoutes";
159
- import { loaderBuilder, serverLoaderBuilder } from "./Builder";
160
- var loader = {
161
- ".js": "jsx",
162
- ".ts": "tsx"
163
- };
164
- var EXTERNAL_REGEXP = /^[^./]|^\.[^./]|^\.\.[^/]/;
165
158
  var createImportSpecifier = function(specifiers) {
166
159
  var defaults = "";
167
160
  var named = [];
@@ -245,91 +238,6 @@ var createImportStatements = function(statements) {
245
238
  return "import ".concat(createImportSpecifier(specifiers), " from '").concat(value, "';\n").concat(initialize || "");
246
239
  }).join("\n");
247
240
  };
248
- var buildLoader = function() {
249
- var _ref = _asyncToGenerator(function(entry, outfile) {
250
- return __generator(this, function(_state) {
251
- switch(_state.label){
252
- case 0:
253
- return [
254
- 4,
255
- loaderBuilder.build({
256
- format: "esm",
257
- platform: "browser",
258
- target: "esnext",
259
- loader: loader,
260
- watch: isDevCommand() && {},
261
- bundle: true,
262
- logLevel: "error",
263
- entryPoints: [
264
- entry
265
- ],
266
- outfile: outfile,
267
- plugins: [
268
- {
269
- name: "make-all-packages-external",
270
- setup: function setup(build) {
271
- build.onResolve({
272
- filter: EXTERNAL_REGEXP
273
- }, function(args) {
274
- var external = true;
275
- if (args.kind === "entry-point") {
276
- external = false;
277
- }
278
- return {
279
- path: args.path,
280
- external: external
281
- };
282
- });
283
- }
284
- }
285
- ]
286
- })
287
- ];
288
- case 1:
289
- _state.sent();
290
- return [
291
- 2
292
- ];
293
- }
294
- });
295
- });
296
- return function buildLoader(entry, outfile) {
297
- return _ref.apply(this, arguments);
298
- };
299
- }();
300
- var buildServerLoader = function() {
301
- var _ref = _asyncToGenerator(function(entry, outfile) {
302
- return __generator(this, function(_state) {
303
- switch(_state.label){
304
- case 0:
305
- return [
306
- 4,
307
- serverLoaderBuilder.build({
308
- format: "cjs",
309
- platform: "node",
310
- target: "esnext",
311
- loader: loader,
312
- watch: isDevCommand() && {},
313
- bundle: true,
314
- logLevel: "error",
315
- entryPoints: [
316
- entry
317
- ],
318
- outfile: outfile
319
- })
320
- ];
321
- case 1:
322
- _state.sent();
323
- return [
324
- 2
325
- ];
326
- }
327
- });
328
- });
329
- return function buildServerLoader(entry, outfile) {
330
- return _ref.apply(this, arguments);
331
- };
332
- }();
333
241
  var generateCode = function() {
334
242
  var _ref = _asyncToGenerator(function(appContext, config, entrypoints, api) {
335
243
  var ref, ref1, ref2, internalDirectory, distDirectory, srcDirectory, internalDirAlias, internalSrcAlias, packageName, hookRunners, isV5, mountId, getRoutes;
@@ -338,18 +246,18 @@ var generateCode = function() {
338
246
  }
339
247
  function _generateEntryCode() {
340
248
  _generateEntryCode = _asyncToGenerator(function(entrypoint) {
341
- var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, routes, config2, ssr, mode, hasPageRoute, ref, code2, _, _tmp, routesServerFile, outputRoutesServerFile, code3, loaderEntryFile, loaderIndexFile, ref1, importStatements, plugins, ref2, renderFunction, exportStatement, code, entryFile, ref3, asyncEntryCode, bootstrapFile;
249
+ var entryName, isAutoMount, customBootstrap, fileSystemRoutes, initialRoutes, nestedRoute, routes, config2, ssr, mode, hasPageRoute, ref, code2, _, _tmp, routesServerFile, code3, ref1, importStatements, plugins, ref2, renderFunction, exportStatement, code, entryFile, ref3, asyncEntryCode, bootstrapFile;
342
250
  return __generator(this, function(_state) {
343
251
  switch(_state.label){
344
252
  case 0:
345
253
  entryName = entrypoint.entryName, isAutoMount = entrypoint.isAutoMount, customBootstrap = entrypoint.customBootstrap, fileSystemRoutes = entrypoint.fileSystemRoutes;
346
254
  if (!isAutoMount) return [
347
255
  3,
348
- 22
256
+ 17
349
257
  ];
350
258
  if (!fileSystemRoutes) return [
351
259
  3,
352
- 15
260
+ 10
353
261
  ];
354
262
  initialRoutes = [];
355
263
  nestedRoute = null;
@@ -442,10 +350,9 @@ var generateCode = function() {
442
350
  ref = _state.sent(), code2 = ref.code;
443
351
  if (!entrypoint.nestedRoutesEntry) return [
444
352
  3,
445
- 14
353
+ 9
446
354
  ];
447
- routesServerFile = path.join(internalDirectory, entryName, "route-server-loaders.js");
448
- outputRoutesServerFile = path.join(distDirectory, LOADER_ROUTES_DIR, entryName, "index.js");
355
+ routesServerFile = getServerLoadersFile(internalDirectory, entryName);
449
356
  code3 = templates.routesForServer({
450
357
  routes: routes,
451
358
  internalDirectory: internalDirectory,
@@ -463,45 +370,11 @@ var generateCode = function() {
463
370
  ];
464
371
  case 8:
465
372
  _state.sent();
466
- loaderEntryFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "entry.js");
467
- loaderIndexFile = path.join(internalDirectory, entryName, TEMP_LOADERS_DIR, "index.js");
468
- return [
469
- 4,
470
- fs.pathExists(loaderEntryFile)
471
- ];
373
+ _state.label = 9;
472
374
  case 9:
473
- if (!_state.sent()) return [
474
- 3,
475
- 11
476
- ];
477
- return [
478
- 4,
479
- buildLoader(loaderEntryFile, loaderIndexFile)
480
- ];
481
- case 10:
482
- _state.sent();
483
- _state.label = 11;
484
- case 11:
485
- return [
486
- 4,
487
- fs.pathExists(routesServerFile)
488
- ];
489
- case 12:
490
- if (!_state.sent()) return [
491
- 3,
492
- 14
493
- ];
494
- return [
495
- 4,
496
- buildServerLoader(routesServerFile, outputRoutesServerFile)
497
- ];
498
- case 13:
499
- _state.sent();
500
- _state.label = 14;
501
- case 14:
502
375
  fs.outputFileSync(path.resolve(internalDirectory, "./".concat(entryName, "/").concat(FILE_SYSTEM_ROUTES_FILE_NAME)), code2, "utf8");
503
- _state.label = 15;
504
- case 15:
376
+ _state.label = 10;
377
+ case 10:
505
378
  return [
506
379
  4,
507
380
  hookRunners.modifyEntryImports({
@@ -515,7 +388,7 @@ var generateCode = function() {
515
388
  })
516
389
  })
517
390
  ];
518
- case 16:
391
+ case 11:
519
392
  ref1 = _state.sent(), importStatements = ref1.imports;
520
393
  return [
521
394
  4,
@@ -524,7 +397,7 @@ var generateCode = function() {
524
397
  plugins: []
525
398
  })
526
399
  ];
527
- case 17:
400
+ case 12:
528
401
  plugins = _state.sent().plugins;
529
402
  return [
530
403
  4,
@@ -537,7 +410,7 @@ var generateCode = function() {
537
410
  })
538
411
  })
539
412
  ];
540
- case 18:
413
+ case 13:
541
414
  ref2 = _state.sent(), renderFunction = ref2.code;
542
415
  return [
543
416
  4,
@@ -546,7 +419,7 @@ var generateCode = function() {
546
419
  exportStatement: "export default AppWrapper;"
547
420
  })
548
421
  ];
549
- case 19:
422
+ case 14:
550
423
  exportStatement = _state.sent().exportStatement;
551
424
  code = templates.index({
552
425
  mountId: mountId,
@@ -558,7 +431,7 @@ var generateCode = function() {
558
431
  entrypoint.entry = entryFile;
559
432
  if (!config.source.enableAsyncEntry) return [
560
433
  3,
561
- 21
434
+ 16
562
435
  ];
563
436
  return [
564
437
  4,
@@ -567,19 +440,19 @@ var generateCode = function() {
567
440
  code: "import('./".concat(ENTRY_BOOTSTRAP_FILE_NAME, "');")
568
441
  })
569
442
  ];
570
- case 20:
443
+ case 15:
571
444
  ref3 = _state.sent(), asyncEntryCode = ref3.code;
572
445
  fs.outputFileSync(entryFile, asyncEntryCode, "utf8");
573
446
  bootstrapFile = path.resolve(internalDirectory, "./".concat(entryName, "/").concat(ENTRY_BOOTSTRAP_FILE_NAME));
574
447
  fs.outputFileSync(bootstrapFile, code, "utf8");
575
448
  return [
576
449
  3,
577
- 22
450
+ 17
578
451
  ];
579
- case 21:
452
+ case 16:
580
453
  fs.outputFileSync(entryFile, code, "utf8");
581
- _state.label = 22;
582
- case 22:
454
+ _state.label = 17;
455
+ case 17:
583
456
  return [
584
457
  2
585
458
  ];