@modern-js/app-tools 2.48.5 → 2.49.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.
@@ -25,13 +25,16 @@ var import_core = require("@modern-js/core");
25
25
  var import_utils = require("@modern-js/utils");
26
26
  var import_routes = require("../utils/routes");
27
27
  var import_config = require("../utils/config");
28
+ var import_register = require("../utils/register");
28
29
  const build = async (api, options) => {
30
+ var _resolvedConfig_source;
29
31
  if (options === null || options === void 0 ? void 0 : options.analyze) {
30
32
  process.env.BUNDLE_ANALYZE = "true";
31
33
  }
32
34
  let resolvedConfig = api.useResolvedConfigContext();
33
35
  const appContext = api.useAppContext();
34
36
  const hookRunners = api.useHookRunners();
37
+ await (0, import_register.registerCompiler)(appContext.appDirectory, appContext.distDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.alias);
35
38
  const { apiOnly } = appContext;
36
39
  if (apiOnly) {
37
40
  const { appDirectory: appDirectory2, distDirectory: distDirectory2, serverConfigFile: serverConfigFile2 } = appContext;
@@ -23,25 +23,29 @@ __export(dev_exports, {
23
23
  module.exports = __toCommonJS(dev_exports);
24
24
  var import_core = require("@modern-js/core");
25
25
  var import_utils = require("@modern-js/utils");
26
+ var import_server = require("@modern-js/server");
27
+ var import_prod_server = require("@modern-js/prod-server");
28
+ var import_register = require("../utils/register");
26
29
  var import_printInstructions = require("../utils/printInstructions");
27
30
  var import_createServer = require("../utils/createServer");
28
31
  var import_routes = require("../utils/routes");
29
32
  var import_config = require("../utils/config");
30
33
  var import_getServerInternalPlugins = require("../utils/getServerInternalPlugins");
31
34
  const dev = async (api, options, devServerOptions = {}) => {
32
- var _normalizedConfig_tools;
35
+ var _normalizedConfig_source, _normalizedConfig_tools;
33
36
  if (options.analyze) {
34
37
  process.env.BUNDLE_ANALYZE = "true";
35
38
  }
36
39
  let normalizedConfig = api.useResolvedConfigContext();
37
40
  const appContext = api.useAppContext();
38
41
  const hookRunners = api.useHookRunners();
42
+ await (0, import_register.registerCompiler)(appContext.appDirectory, appContext.distDirectory, normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias);
39
43
  normalizedConfig = {
40
44
  ...normalizedConfig,
41
45
  cliOptions: options
42
46
  };
43
47
  import_core.ResolvedConfigContext.set(normalizedConfig);
44
- const { appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName } = appContext;
48
+ const { appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes } = appContext;
45
49
  await (0, import_config.buildServerConfig)({
46
50
  appDirectory,
47
51
  distDirectory,
@@ -55,6 +59,7 @@ const dev = async (api, options, devServerOptions = {}) => {
55
59
  await (0, import_routes.generateRoutes)(appContext);
56
60
  const serverInternalPlugins = await (0, import_getServerInternalPlugins.getServerInternalPlugins)(api);
57
61
  const serverOptions = {
62
+ metaName,
58
63
  dev: {
59
64
  port,
60
65
  https: normalizedConfig.dev.https,
@@ -62,37 +67,32 @@ const dev = async (api, options, devServerOptions = {}) => {
62
67
  ...(_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer
63
68
  },
64
69
  appContext: {
65
- metaName,
66
- appDirectory: appContext.appDirectory,
67
- sharedDirectory: appContext.sharedDirectory,
70
+ appDirectory,
68
71
  apiDirectory: appContext.apiDirectory,
69
- lambdaDirectory: appContext.lambdaDirectory
72
+ lambdaDirectory: appContext.lambdaDirectory,
73
+ sharedDirectory: appContext.sharedDirectory
70
74
  },
75
+ routes: serverRoutes,
71
76
  pwd: appDirectory,
72
77
  config: normalizedConfig,
73
78
  serverConfigFile,
74
- internalPlugins: (0, import_createServer.injectDataLoaderPlugin)(serverInternalPlugins),
79
+ internalPlugins: serverInternalPlugins,
75
80
  ...devServerOptions
76
81
  };
77
82
  if (apiOnly) {
78
83
  var _normalizedConfig_dev;
79
- const app = await (0, import_createServer.createServer)({
80
- ...serverOptions,
81
- compiler: null
82
- });
84
+ const app = await (0, import_server.createDevServer)(serverOptions, import_prod_server.initProdMiddlewares);
83
85
  const host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || import_utils.DEFAULT_DEV_HOST;
84
86
  app.listen({
85
87
  port,
86
88
  host
87
- }, async (err) => {
88
- if (err) {
89
- throw err;
90
- }
89
+ }, () => {
91
90
  (0, import_printInstructions.printInstructions)(hookRunners, appContext, normalizedConfig);
92
91
  });
93
92
  } else {
94
93
  const { server } = await appContext.builder.startDevServer({
95
- serverOptions
94
+ serverOptions,
95
+ initProdMiddlewares: import_prod_server.initProdMiddlewares
96
96
  });
97
97
  (0, import_createServer.setServer)(server);
98
98
  }
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var serve_exports = {};
30
20
  __export(serve_exports, {
@@ -32,21 +22,25 @@ __export(serve_exports, {
32
22
  });
33
23
  module.exports = __toCommonJS(serve_exports);
34
24
  var import_utils = require("@modern-js/utils");
35
- var import_prod_server = __toESM(require("@modern-js/prod-server"));
25
+ var import_prod_server = require("@modern-js/prod-server");
36
26
  var import_printInstructions = require("../utils/printInstructions");
37
- var import_createServer = require("../utils/createServer");
38
27
  var import_getServerInternalPlugins = require("../utils/getServerInternalPlugins");
39
28
  const start = async (api) => {
40
29
  var _userConfig_source, _userConfig_output_distPath;
41
30
  const appContext = api.useAppContext();
42
31
  const userConfig = api.useResolvedConfigContext();
43
32
  const hookRunners = api.useHookRunners();
44
- const { appDirectory, port, serverConfigFile, metaName } = appContext;
33
+ const { distDirectory, appDirectory, port, serverConfigFile, metaName, serverRoutes } = appContext;
45
34
  import_utils.logger.info(`Starting production server...`);
46
35
  const apiOnly = await (0, import_utils.isApiOnly)(appContext.appDirectory, userConfig === null || userConfig === void 0 ? void 0 : (_userConfig_source = userConfig.source) === null || _userConfig_source === void 0 ? void 0 : _userConfig_source.entriesDir, appContext.apiDirectory);
36
+ let runMode;
37
+ if (apiOnly) {
38
+ runMode = "apiOnly";
39
+ }
47
40
  const serverInternalPlugins = await (0, import_getServerInternalPlugins.getServerInternalPlugins)(api);
48
- const app = await (0, import_prod_server.default)({
49
- pwd: appDirectory,
41
+ const app = await (0, import_prod_server.createProdServer)({
42
+ metaName,
43
+ pwd: distDirectory,
50
44
  config: {
51
45
  ...userConfig,
52
46
  dev: userConfig.dev,
@@ -55,20 +49,18 @@ const start = async (api) => {
55
49
  ...userConfig.output || {}
56
50
  }
57
51
  },
52
+ routes: serverRoutes,
58
53
  appContext: {
59
- metaName,
54
+ appDirectory,
60
55
  sharedDirectory: (0, import_utils.getTargetDir)(appContext.sharedDirectory, appContext.appDirectory, appContext.distDirectory),
61
56
  apiDirectory: (0, import_utils.getTargetDir)(appContext.apiDirectory, appContext.appDirectory, appContext.distDirectory),
62
57
  lambdaDirectory: (0, import_utils.getTargetDir)(appContext.lambdaDirectory, appContext.appDirectory, appContext.distDirectory)
63
58
  },
64
59
  serverConfigFile,
65
- internalPlugins: (0, import_createServer.injectDataLoaderPlugin)(serverInternalPlugins),
66
- apiOnly
60
+ internalPlugins: serverInternalPlugins,
61
+ runMode
67
62
  });
68
- app.listen(port, async (err) => {
69
- if (err) {
70
- throw err;
71
- }
63
+ app.listen(port, async () => {
72
64
  await (0, import_printInstructions.printInstructions)(hookRunners, appContext, userConfig);
73
65
  });
74
66
  };
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,25 +15,17 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
  var createServer_exports = {};
30
20
  __export(createServer_exports, {
31
21
  closeServer: () => closeServer,
32
22
  createServer: () => createServer,
33
23
  getServer: () => getServer,
34
- injectDataLoaderPlugin: () => injectDataLoaderPlugin,
35
24
  setServer: () => setServer
36
25
  });
37
26
  module.exports = __toCommonJS(createServer_exports);
38
27
  var import_server = require("@modern-js/server");
28
+ var import_prod_server = require("@modern-js/prod-server");
39
29
  let server = null;
40
30
  const getServer = () => server;
41
31
  const setServer = (newServer) => {
@@ -43,33 +33,21 @@ const setServer = (newServer) => {
43
33
  };
44
34
  const closeServer = async () => {
45
35
  if (server) {
46
- await server.close();
36
+ server.close();
47
37
  server = null;
48
38
  }
49
39
  };
50
40
  const createServer = async (options) => {
51
41
  if (server) {
52
- await server.close();
42
+ server.close();
53
43
  }
54
- server = new import_server.Server(options);
55
- const app = await server.init();
56
- return app;
57
- };
58
- const injectDataLoaderPlugin = (internalPlugins) => {
59
- const DataLoaderPlugin = require.resolve("@modern-js/plugin-data-loader/server");
60
- return {
61
- ...internalPlugins,
62
- "@modern-js/plugin-data-loader": {
63
- path: DataLoaderPlugin,
64
- forced: true
65
- }
66
- };
44
+ server = await (0, import_server.createDevServer)(options, import_prod_server.initProdMiddlewares);
45
+ return server;
67
46
  };
68
47
  // Annotate the CommonJS export names for ESM import in node:
69
48
  0 && (module.exports = {
70
49
  closeServer,
71
50
  createServer,
72
51
  getServer,
73
- injectDataLoaderPlugin,
74
52
  setServer
75
53
  });
@@ -21,10 +21,10 @@ __export(env_exports, {
21
21
  getAutoInjectEnv: () => getAutoInjectEnv
22
22
  });
23
23
  module.exports = __toCommonJS(env_exports);
24
- var import_utils = require("@modern-js/utils");
24
+ var import_universal = require("@modern-js/utils/universal");
25
25
  function getAutoInjectEnv(appContext) {
26
26
  const { metaName } = appContext;
27
- const prefix = `${(0, import_utils.cutNameByHyphen)(metaName)}_`.toUpperCase();
27
+ const prefix = `${(0, import_universal.cutNameByHyphen)(metaName)}_`.toUpperCase();
28
28
  const envReg = new RegExp(`^${prefix}`);
29
29
  return Object.keys(process.env).reduce((prev, key) => {
30
30
  const value = process.env[key];
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var register_exports = {};
30
+ __export(register_exports, {
31
+ registerCompiler: () => registerCompiler
32
+ });
33
+ module.exports = __toCommonJS(register_exports);
34
+ var import_node_path = __toESM(require("node:path"));
35
+ var import_utils = require("@modern-js/utils");
36
+ const registerCompiler = async (appDir = process.cwd(), distDir, alias) => {
37
+ const TS_CONFIG_FILENAME = `tsconfig.json`;
38
+ const tsconfigPath = import_node_path.default.resolve(appDir, TS_CONFIG_FILENAME);
39
+ const isTsProject = await import_utils.fs.pathExists(tsconfigPath);
40
+ const aliasConfig = (0, import_utils.getAliasConfig)(alias, {
41
+ appDirectory: appDir,
42
+ tsconfigPath
43
+ });
44
+ const { paths = {}, absoluteBaseUrl = "./" } = aliasConfig;
45
+ const tsPaths = Object.keys(paths).reduce((o, key) => {
46
+ let tsPath = paths[key];
47
+ if (typeof tsPath === "string" && import_node_path.default.isAbsolute(tsPath)) {
48
+ tsPath = import_node_path.default.relative(absoluteBaseUrl, tsPath);
49
+ }
50
+ if (typeof tsPath === "string") {
51
+ tsPath = [
52
+ tsPath
53
+ ];
54
+ }
55
+ return {
56
+ ...o,
57
+ [`${key}`]: tsPath
58
+ };
59
+ }, {});
60
+ let tsConfig = {};
61
+ if (isTsProject) {
62
+ tsConfig = (0, import_utils.readTsConfigByFile)(tsconfigPath);
63
+ }
64
+ try {
65
+ const tsNode = await Promise.resolve().then(() => __toESM(require("ts-node")));
66
+ const tsNodeOptions = tsConfig["ts-node"];
67
+ if (isTsProject) {
68
+ tsNode.register({
69
+ project: tsconfigPath,
70
+ scope: true,
71
+ // for env.d.ts, https://www.npmjs.com/package/ts-node#missing-types
72
+ files: true,
73
+ transpileOnly: true,
74
+ ignore: [
75
+ "(?:^|/)node_modules/",
76
+ `(?:^|/)${distDir}/`
77
+ ],
78
+ ...tsNodeOptions
79
+ });
80
+ }
81
+ } catch (error) {
82
+ const esbuildRegister = await Promise.resolve().then(() => __toESM(require("esbuild-register/dist/node")));
83
+ esbuildRegister.register({
84
+ tsconfigRaw: isTsProject ? tsConfig : void 0,
85
+ hookIgnoreNodeModules: true,
86
+ hookMatcher: (fileName) => !fileName.startsWith(distDir)
87
+ });
88
+ }
89
+ const tsConfigPaths = await Promise.resolve().then(() => __toESM(require("@modern-js/utils/tsconfig-paths")));
90
+ if (await import_utils.fs.pathExists(appDir)) {
91
+ const loaderRes = tsConfigPaths.loadConfig(appDir);
92
+ if (loaderRes.resultType === "success") {
93
+ tsConfigPaths.register({
94
+ baseUrl: absoluteBaseUrl || "./",
95
+ paths: tsPaths
96
+ });
97
+ }
98
+ }
99
+ };
100
+ // Annotate the CommonJS export names for ESM import in node:
101
+ 0 && (module.exports = {
102
+ registerCompiler
103
+ });
@@ -6,9 +6,10 @@ import { ResolvedConfigContext } from "@modern-js/core";
6
6
  import { logger } from "@modern-js/utils";
7
7
  import { generateRoutes } from "../utils/routes";
8
8
  import { buildServerConfig } from "../utils/config";
9
+ import { registerCompiler } from "../utils/register";
9
10
  var build = function() {
10
11
  var _ref = _async_to_generator(function(api, options) {
11
- var resolvedConfig, appContext, hookRunners, apiOnly, appDirectory, distDirectory, serverConfigFile, distDirectory1, appDirectory1, serverConfigFile1;
12
+ var _resolvedConfig_source, resolvedConfig, appContext, hookRunners, apiOnly, appDirectory, distDirectory, serverConfigFile, distDirectory1, appDirectory1, serverConfigFile1;
12
13
  return _ts_generator(this, function(_state) {
13
14
  switch (_state.label) {
14
15
  case 0:
@@ -18,11 +19,17 @@ var build = function() {
18
19
  resolvedConfig = api.useResolvedConfigContext();
19
20
  appContext = api.useAppContext();
20
21
  hookRunners = api.useHookRunners();
22
+ return [
23
+ 4,
24
+ registerCompiler(appContext.appDirectory, appContext.distDirectory, resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig_source = resolvedConfig.source) === null || _resolvedConfig_source === void 0 ? void 0 : _resolvedConfig_source.alias)
25
+ ];
26
+ case 1:
27
+ _state.sent();
21
28
  apiOnly = appContext.apiOnly;
22
29
  if (!apiOnly)
23
30
  return [
24
31
  3,
25
- 5
32
+ 6
26
33
  ];
27
34
  appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, serverConfigFile = appContext.serverConfigFile;
28
35
  return [
@@ -32,7 +39,7 @@ var build = function() {
32
39
  bundlerConfigs: void 0
33
40
  })
34
41
  ];
35
- case 1:
42
+ case 2:
36
43
  _state.sent();
37
44
  return [
38
45
  4,
@@ -42,13 +49,13 @@ var build = function() {
42
49
  configFile: serverConfigFile
43
50
  })
44
51
  ];
45
- case 2:
52
+ case 3:
46
53
  _state.sent();
47
54
  return [
48
55
  4,
49
56
  generateRoutes(appContext)
50
57
  ];
51
- case 3:
58
+ case 4:
52
59
  _state.sent();
53
60
  return [
54
61
  4,
@@ -57,12 +64,12 @@ var build = function() {
57
64
  stats: void 0
58
65
  })
59
66
  ];
60
- case 4:
67
+ case 5:
61
68
  _state.sent();
62
69
  return [
63
70
  2
64
71
  ];
65
- case 5:
72
+ case 6:
66
73
  resolvedConfig = _object_spread_props(_object_spread({}, resolvedConfig), {
67
74
  cliOptions: options
68
75
  });
@@ -76,7 +83,7 @@ var build = function() {
76
83
  configFile: serverConfigFile1
77
84
  })
78
85
  ];
79
- case 6:
86
+ case 7:
80
87
  _state.sent();
81
88
  logger.info("Starting production build...");
82
89
  if (!appContext.builder) {
@@ -86,7 +93,7 @@ var build = function() {
86
93
  4,
87
94
  appContext.builder.build()
88
95
  ];
89
- case 7:
96
+ case 8:
90
97
  _state.sent();
91
98
  return [
92
99
  2
@@ -4,14 +4,17 @@ import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
5
  import { ResolvedConfigContext } from "@modern-js/core";
6
6
  import { DEFAULT_DEV_HOST } from "@modern-js/utils";
7
+ import { createDevServer } from "@modern-js/server";
8
+ import { initProdMiddlewares } from "@modern-js/prod-server";
9
+ import { registerCompiler } from "../utils/register";
7
10
  import { printInstructions } from "../utils/printInstructions";
8
- import { setServer, createServer, injectDataLoaderPlugin } from "../utils/createServer";
11
+ import { setServer } from "../utils/createServer";
9
12
  import { generateRoutes } from "../utils/routes";
10
13
  import { buildServerConfig } from "../utils/config";
11
14
  import { getServerInternalPlugins } from "../utils/getServerInternalPlugins";
12
15
  var dev = function() {
13
16
  var _ref = _async_to_generator(function(api, options) {
14
- var devServerOptions, _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverInternalPlugins, serverOptions, _normalizedConfig_dev, app, host, server;
17
+ var devServerOptions, _normalizedConfig_source, _normalizedConfig_tools, normalizedConfig, appContext, hookRunners, appDirectory, distDirectory, port, apiOnly, serverConfigFile, metaName, serverRoutes, serverInternalPlugins, serverOptions, _normalizedConfig_dev, app, host, server;
15
18
  var _arguments = arguments;
16
19
  return _ts_generator(this, function(_state) {
17
20
  switch (_state.label) {
@@ -23,11 +26,17 @@ var dev = function() {
23
26
  normalizedConfig = api.useResolvedConfigContext();
24
27
  appContext = api.useAppContext();
25
28
  hookRunners = api.useHookRunners();
29
+ return [
30
+ 4,
31
+ registerCompiler(appContext.appDirectory, appContext.distDirectory, normalizedConfig === null || normalizedConfig === void 0 ? void 0 : (_normalizedConfig_source = normalizedConfig.source) === null || _normalizedConfig_source === void 0 ? void 0 : _normalizedConfig_source.alias)
32
+ ];
33
+ case 1:
34
+ _state.sent();
26
35
  normalizedConfig = _object_spread_props(_object_spread({}, normalizedConfig), {
27
36
  cliOptions: options
28
37
  });
29
38
  ResolvedConfigContext.set(normalizedConfig);
30
- appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly, serverConfigFile = appContext.serverConfigFile, metaName = appContext.metaName;
39
+ appDirectory = appContext.appDirectory, distDirectory = appContext.distDirectory, port = appContext.port, apiOnly = appContext.apiOnly, serverConfigFile = appContext.serverConfigFile, metaName = appContext.metaName, serverRoutes = appContext.serverRoutes;
31
40
  return [
32
41
  4,
33
42
  buildServerConfig({
@@ -37,13 +46,13 @@ var dev = function() {
37
46
  watch: true
38
47
  })
39
48
  ];
40
- case 1:
49
+ case 2:
41
50
  _state.sent();
42
51
  return [
43
52
  4,
44
53
  hookRunners.beforeDev()
45
54
  ];
46
- case 2:
55
+ case 3:
47
56
  _state.sent();
48
57
  if (!appContext.builder && !apiOnly) {
49
58
  throw new Error("Expect the Builder to have been initialized, But the appContext.builder received `undefined`");
@@ -52,81 +61,68 @@ var dev = function() {
52
61
  4,
53
62
  generateRoutes(appContext)
54
63
  ];
55
- case 3:
64
+ case 4:
56
65
  _state.sent();
57
66
  return [
58
67
  4,
59
68
  getServerInternalPlugins(api)
60
69
  ];
61
- case 4:
70
+ case 5:
62
71
  serverInternalPlugins = _state.sent();
63
72
  serverOptions = _object_spread({
73
+ metaName,
64
74
  dev: _object_spread({
65
75
  port,
66
76
  https: normalizedConfig.dev.https,
67
77
  host: normalizedConfig.dev.host
68
78
  }, (_normalizedConfig_tools = normalizedConfig.tools) === null || _normalizedConfig_tools === void 0 ? void 0 : _normalizedConfig_tools.devServer),
69
79
  appContext: {
70
- metaName,
71
- appDirectory: appContext.appDirectory,
72
- sharedDirectory: appContext.sharedDirectory,
80
+ appDirectory,
73
81
  apiDirectory: appContext.apiDirectory,
74
- lambdaDirectory: appContext.lambdaDirectory
82
+ lambdaDirectory: appContext.lambdaDirectory,
83
+ sharedDirectory: appContext.sharedDirectory
75
84
  },
85
+ routes: serverRoutes,
76
86
  pwd: appDirectory,
77
87
  config: normalizedConfig,
78
88
  serverConfigFile,
79
- internalPlugins: injectDataLoaderPlugin(serverInternalPlugins)
89
+ internalPlugins: serverInternalPlugins
80
90
  }, devServerOptions);
81
91
  if (!apiOnly)
82
92
  return [
83
93
  3,
84
- 6
94
+ 7
85
95
  ];
86
96
  return [
87
97
  4,
88
- createServer(_object_spread_props(_object_spread({}, serverOptions), {
89
- compiler: null
90
- }))
98
+ createDevServer(serverOptions, initProdMiddlewares)
91
99
  ];
92
- case 5:
100
+ case 6:
93
101
  app = _state.sent();
94
102
  host = ((_normalizedConfig_dev = normalizedConfig.dev) === null || _normalizedConfig_dev === void 0 ? void 0 : _normalizedConfig_dev.host) || DEFAULT_DEV_HOST;
95
103
  app.listen({
96
104
  port,
97
105
  host
98
106
  }, function() {
99
- var _ref2 = _async_to_generator(function(err) {
100
- return _ts_generator(this, function(_state2) {
101
- if (err) {
102
- throw err;
103
- }
104
- printInstructions(hookRunners, appContext, normalizedConfig);
105
- return [
106
- 2
107
- ];
108
- });
109
- });
110
- return function(err) {
111
- return _ref2.apply(this, arguments);
112
- };
113
- }());
107
+ printInstructions(hookRunners, appContext, normalizedConfig);
108
+ });
114
109
  return [
115
110
  3,
116
- 8
111
+ 9
117
112
  ];
118
- case 6:
113
+ case 7:
119
114
  return [
120
115
  4,
121
116
  appContext.builder.startDevServer({
122
- serverOptions
117
+ serverOptions,
118
+ initProdMiddlewares
123
119
  })
124
120
  ];
125
- case 7:
121
+ case 8:
126
122
  server = _state.sent().server;
127
123
  setServer(server);
128
- _state.label = 8;
129
- case 8:
124
+ _state.label = 9;
125
+ case 9:
130
126
  return [
131
127
  2
132
128
  ];