@modern-js/app-tools 1.4.6 → 1.4.7-canary.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.
@@ -9,6 +9,7 @@ import { WebpackConfigTarget, getWebpackConfig } from '@modern-js/webpack';
9
9
  import { manager, ResolvedConfigContext } from '@modern-js/core';
10
10
  import { formatWebpackMessages, measureFileSizesBeforeBuild, printFileSizesAfterBuild, printBuildError, logger, isUseSSRBundle, emptyDir } from '@modern-js/utils';
11
11
  import { generateRoutes } from "../utils/routes";
12
+ import { buildServerConfig, emitResolvedConfig } from "../utils/config";
12
13
  // These sizes are pretty large. We'll warn for bundles exceeding them.
13
14
  const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
14
15
  const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024; // eslint-disable-next-line max-statements
@@ -91,10 +92,13 @@ export const build = async (api, options) => {
91
92
  }));
92
93
  });
93
94
  const {
94
- distDirectory
95
+ distDirectory,
96
+ appDirectory,
97
+ serverConfigFile
95
98
  } = appContext;
96
99
  const previousFileSizes = await measureFileSizesBeforeBuild(distDirectory);
97
100
  await emptyDir(distDirectory);
101
+ await buildServerConfig(appDirectory, serverConfigFile);
98
102
  const buildConfigs = [];
99
103
  buildConfigs.push({
100
104
  type: 'legacy',
@@ -138,4 +142,5 @@ export const build = async (api, options) => {
138
142
 
139
143
  await generateRoutes(appContext);
140
144
  await hookRunners.afterBuild();
145
+ await emitResolvedConfig(appDirectory, resolvedConfig);
141
146
  };
@@ -10,6 +10,7 @@ import { createServer } from "../utils/createServer";
10
10
  import { generateRoutes } from "../utils/routes";
11
11
  import { printInstructions } from "../utils/printInstructions";
12
12
  import { getSpecifiedEntries } from "../utils/getSpecifiedEntries";
13
+ import { buildServerConfig } from "../utils/config";
13
14
  export const dev = async (api, options) => {
14
15
  const appContext = api.useAppContext();
15
16
  const userConfig = api.useResolvedConfigContext();
@@ -19,7 +20,8 @@ export const dev = async (api, options) => {
19
20
  distDirectory,
20
21
  port,
21
22
  existSrc,
22
- entrypoints
23
+ entrypoints,
24
+ serverConfigFile
23
25
  } = appContext;
24
26
  const checkedEntries = await getSpecifiedEntries(options.entry || false, entrypoints);
25
27
  api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
@@ -27,6 +29,11 @@ export const dev = async (api, options) => {
27
29
  }));
28
30
  appContext.checkedEntries = checkedEntries;
29
31
  fs.emptyDirSync(distDirectory);
32
+ await buildServerConfig(appDirectory, serverConfigFile, {
33
+ esbuildOptions: {
34
+ watch: true
35
+ }
36
+ });
30
37
  await hookRunners.beforeDev();
31
38
  let compiler = null;
32
39
 
@@ -48,6 +55,7 @@ export const dev = async (api, options) => {
48
55
  const app = await createServer({
49
56
  dev: _objectSpread(_objectSpread({}, {
50
57
  client: {
58
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
51
59
  port: port.toString(),
52
60
  overlay: false,
53
61
  logging: 'none',
@@ -65,6 +73,7 @@ export const dev = async (api, options) => {
65
73
  compiler,
66
74
  pwd: appDirectory,
67
75
  config: userConfig,
76
+ serverConfigFile,
68
77
  plugins: appContext.plugins.filter(p => p.server).map(p => p.server)
69
78
  });
70
79
  app.listen(port, async err => {
@@ -76,7 +85,7 @@ export const dev = async (api, options) => {
76
85
  clearConsole();
77
86
  logger.log(chalk.cyan(`Starting the development server...`));
78
87
  } else {
79
- await printInstructions(api, appContext, userConfig);
88
+ await printInstructions(hookRunners, appContext, userConfig);
80
89
  }
81
90
  });
82
91
  };
@@ -4,21 +4,24 @@ import { printInstructions } from "../utils/printInstructions";
4
4
  export const start = async api => {
5
5
  const appContext = api.useAppContext();
6
6
  const userConfig = api.useResolvedConfigContext();
7
+ const hookRunners = api.useHookRunners();
7
8
  const {
8
9
  appDirectory,
9
- port
10
+ port,
11
+ serverConfigFile
10
12
  } = appContext;
11
13
  logger.log(chalk.cyan(`Starting the modern server...`));
12
14
  const app = await server({
13
15
  pwd: appDirectory,
14
16
  config: userConfig,
15
- plugins: appContext.plugins.filter(p => p.server).map(p => p.server)
17
+ plugins: appContext.plugins.filter(p => p.server).map(p => p.server),
18
+ serverConfigFile
16
19
  });
17
20
  app.listen(port, async err => {
18
21
  if (err) {
19
22
  throw err;
20
23
  }
21
24
 
22
- await printInstructions(api, appContext, userConfig);
25
+ await printInstructions(hookRunners, appContext, userConfig);
23
26
  });
24
27
  };
@@ -0,0 +1 @@
1
+ export { defineServerConfig as defineConfig } from "../utils/config";
@@ -0,0 +1,53 @@
1
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
2
+
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+
5
+ function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
+
7
+ import * as path from 'path';
8
+ import { bundle } from '@modern-js/node-bundle-require';
9
+ import { CONFIG_CACHE_DIR, CONFIG_FILE_EXTENSIONS, fs, getServerConfig, OUTPUT_CONFIG_FILE } from '@modern-js/utils';
10
+ export const defineServerConfig = config => config;
11
+ export const buildServerConfig = async (appDirectory, configFile, options) => {
12
+ const configFilePath = await getServerConfig(appDirectory, configFile);
13
+
14
+ const getOutputFile = filepath => path.resolve(CONFIG_CACHE_DIR, `${filepath.replace(new RegExp(CONFIG_FILE_EXTENSIONS.join('|')), '')}.js`);
15
+
16
+ if (configFilePath) {
17
+ await bundle(configFilePath, _objectSpread(_objectSpread({}, options), {}, {
18
+ getOutputFile
19
+ }));
20
+ }
21
+ };
22
+ /**
23
+ *
24
+ * 处理循环引用的 replacer
25
+ */
26
+
27
+ export const safeReplacer = () => {
28
+ const cache = [];
29
+ const keyCache = [];
30
+ return function (key, value) {
31
+ if (typeof value === 'object' && value !== null) {
32
+ const index = cache.indexOf(value);
33
+
34
+ if (index !== -1) {
35
+ return `[Circular ${keyCache[index]}]`;
36
+ }
37
+
38
+ cache.push(value);
39
+ keyCache.push(key || 'root');
40
+ }
41
+
42
+ return value;
43
+ };
44
+ };
45
+ export const emitResolvedConfig = async (appDirectory, resolvedConfig) => {
46
+ var _resolvedConfig$outpu;
47
+
48
+ const outputPath = path.join(appDirectory, (resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$outpu = resolvedConfig.output) === null || _resolvedConfig$outpu === void 0 ? void 0 : _resolvedConfig$outpu.path) || './dist', OUTPUT_CONFIG_FILE);
49
+ await fs.writeJSON(outputPath, resolvedConfig, {
50
+ spaces: 2,
51
+ replacer: safeReplacer()
52
+ });
53
+ };
@@ -57,7 +57,7 @@ export const createCompiler = async ({
57
57
  logger.log(chalk.green(`Compiled successfully in ${prettyTime(statsData)} ms.\n`));
58
58
  }
59
59
 
60
- await printInstructions(api, appContext, userConfig);
60
+ await printInstructions(hookRunners, appContext, userConfig);
61
61
  }
62
62
 
63
63
  isFirstCompile = false;
@@ -1,5 +1,5 @@
1
1
  import { prettyInstructions, logger, isDev, chalk } from '@modern-js/utils';
2
- export const printInstructions = async (api, appContext, config) => {
2
+ export const printInstructions = async (hookRunners, appContext, config) => {
3
3
  let message = prettyInstructions(appContext, config);
4
4
  const {
5
5
  existSrc
@@ -10,7 +10,6 @@ export const printInstructions = async (api, appContext, config) => {
10
10
  } // call beforePrintInstructions hook.
11
11
 
12
12
 
13
- const hookRunners = api.useHookRunners();
14
13
  const {
15
14
  instructions
16
15
  } = await hookRunners.beforePrintInstructions({
@@ -15,6 +15,8 @@ var _utils = require("@modern-js/utils");
15
15
 
16
16
  var _routes = require("../utils/routes");
17
17
 
18
+ var _config = require("../utils/config");
19
+
18
20
  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
21
 
20
22
  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; }
@@ -107,10 +109,13 @@ const build = async (api, options) => {
107
109
  });
108
110
 
109
111
  const {
110
- distDirectory
112
+ distDirectory,
113
+ appDirectory,
114
+ serverConfigFile
111
115
  } = appContext;
112
116
  const previousFileSizes = await (0, _utils.measureFileSizesBeforeBuild)(distDirectory);
113
117
  await (0, _utils.emptyDir)(distDirectory);
118
+ await (0, _config.buildServerConfig)(appDirectory, serverConfigFile);
114
119
  const buildConfigs = [];
115
120
  buildConfigs.push({
116
121
  type: 'legacy',
@@ -154,6 +159,7 @@ const build = async (api, options) => {
154
159
 
155
160
  await (0, _routes.generateRoutes)(appContext);
156
161
  await hookRunners.afterBuild();
162
+ await (0, _config.emitResolvedConfig)(appDirectory, resolvedConfig);
157
163
  };
158
164
 
159
165
  exports.build = build;
@@ -17,6 +17,8 @@ var _printInstructions = require("../utils/printInstructions");
17
17
 
18
18
  var _getSpecifiedEntries = require("../utils/getSpecifiedEntries");
19
19
 
20
+ var _config = require("../utils/config");
21
+
20
22
  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); }
21
23
 
22
24
  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; }
@@ -36,7 +38,8 @@ const dev = async (api, options) => {
36
38
  distDirectory,
37
39
  port,
38
40
  existSrc,
39
- entrypoints
41
+ entrypoints,
42
+ serverConfigFile
40
43
  } = appContext;
41
44
  const checkedEntries = await (0, _getSpecifiedEntries.getSpecifiedEntries)(options.entry || false, entrypoints);
42
45
  api.setAppContext(_objectSpread(_objectSpread({}, appContext), {}, {
@@ -46,6 +49,11 @@ const dev = async (api, options) => {
46
49
 
47
50
  _utils.fs.emptyDirSync(distDirectory);
48
51
 
52
+ await (0, _config.buildServerConfig)(appDirectory, serverConfigFile, {
53
+ esbuildOptions: {
54
+ watch: true
55
+ }
56
+ });
49
57
  await hookRunners.beforeDev();
50
58
  let compiler = null;
51
59
 
@@ -67,6 +75,7 @@ const dev = async (api, options) => {
67
75
  const app = await (0, _createServer.createServer)({
68
76
  dev: _objectSpread(_objectSpread({}, {
69
77
  client: {
78
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
70
79
  port: port.toString(),
71
80
  overlay: false,
72
81
  logging: 'none',
@@ -84,6 +93,7 @@ const dev = async (api, options) => {
84
93
  compiler,
85
94
  pwd: appDirectory,
86
95
  config: userConfig,
96
+ serverConfigFile,
87
97
  plugins: appContext.plugins.filter(p => p.server).map(p => p.server)
88
98
  });
89
99
  app.listen(port, async err => {
@@ -96,7 +106,7 @@ const dev = async (api, options) => {
96
106
 
97
107
  _utils.logger.log(_utils.chalk.cyan(`Starting the development server...`));
98
108
  } else {
99
- await (0, _printInstructions.printInstructions)(api, appContext, userConfig);
109
+ await (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
100
110
  }
101
111
  });
102
112
  };
@@ -16,9 +16,11 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
16
16
  const start = async api => {
17
17
  const appContext = api.useAppContext();
18
18
  const userConfig = api.useResolvedConfigContext();
19
+ const hookRunners = api.useHookRunners();
19
20
  const {
20
21
  appDirectory,
21
- port
22
+ port,
23
+ serverConfigFile
22
24
  } = appContext;
23
25
 
24
26
  _utils.logger.log(_utils.chalk.cyan(`Starting the modern server...`));
@@ -26,14 +28,15 @@ const start = async api => {
26
28
  const app = await (0, _prodServer.default)({
27
29
  pwd: appDirectory,
28
30
  config: userConfig,
29
- plugins: appContext.plugins.filter(p => p.server).map(p => p.server)
31
+ plugins: appContext.plugins.filter(p => p.server).map(p => p.server),
32
+ serverConfigFile
30
33
  });
31
34
  app.listen(port, async err => {
32
35
  if (err) {
33
36
  throw err;
34
37
  }
35
38
 
36
- await (0, _printInstructions.printInstructions)(api, appContext, userConfig);
39
+ await (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
37
40
  });
38
41
  };
39
42
 
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "defineConfig", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _config.defineServerConfig;
10
+ }
11
+ });
12
+
13
+ var _config = require("../utils/config");
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.safeReplacer = exports.emitResolvedConfig = exports.defineServerConfig = exports.buildServerConfig = void 0;
7
+
8
+ var path = _interopRequireWildcard(require("path"));
9
+
10
+ var _nodeBundleRequire = require("@modern-js/node-bundle-require");
11
+
12
+ var _utils = require("@modern-js/utils");
13
+
14
+ 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); }
15
+
16
+ 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; }
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
+ const defineServerConfig = config => config;
25
+
26
+ exports.defineServerConfig = defineServerConfig;
27
+
28
+ const buildServerConfig = async (appDirectory, configFile, options) => {
29
+ const configFilePath = await (0, _utils.getServerConfig)(appDirectory, configFile);
30
+
31
+ const getOutputFile = filepath => path.resolve(_utils.CONFIG_CACHE_DIR, `${filepath.replace(new RegExp(_utils.CONFIG_FILE_EXTENSIONS.join('|')), '')}.js`);
32
+
33
+ if (configFilePath) {
34
+ await (0, _nodeBundleRequire.bundle)(configFilePath, _objectSpread(_objectSpread({}, options), {}, {
35
+ getOutputFile
36
+ }));
37
+ }
38
+ };
39
+ /**
40
+ *
41
+ * 处理循环引用的 replacer
42
+ */
43
+
44
+
45
+ exports.buildServerConfig = buildServerConfig;
46
+
47
+ const safeReplacer = () => {
48
+ const cache = [];
49
+ const keyCache = [];
50
+ return function (key, value) {
51
+ if (typeof value === 'object' && value !== null) {
52
+ const index = cache.indexOf(value);
53
+
54
+ if (index !== -1) {
55
+ return `[Circular ${keyCache[index]}]`;
56
+ }
57
+
58
+ cache.push(value);
59
+ keyCache.push(key || 'root');
60
+ }
61
+
62
+ return value;
63
+ };
64
+ };
65
+
66
+ exports.safeReplacer = safeReplacer;
67
+
68
+ const emitResolvedConfig = async (appDirectory, resolvedConfig) => {
69
+ var _resolvedConfig$outpu;
70
+
71
+ const outputPath = path.join(appDirectory, (resolvedConfig === null || resolvedConfig === void 0 ? void 0 : (_resolvedConfig$outpu = resolvedConfig.output) === null || _resolvedConfig$outpu === void 0 ? void 0 : _resolvedConfig$outpu.path) || './dist', _utils.OUTPUT_CONFIG_FILE);
72
+ await _utils.fs.writeJSON(outputPath, resolvedConfig, {
73
+ spaces: 2,
74
+ replacer: safeReplacer()
75
+ });
76
+ };
77
+
78
+ exports.emitResolvedConfig = emitResolvedConfig;
@@ -73,7 +73,7 @@ const createCompiler = async ({
73
73
  _utils.logger.log(_utils.chalk.green(`Compiled successfully in ${prettyTime(statsData)} ms.\n`));
74
74
  }
75
75
 
76
- await (0, _printInstructions.printInstructions)(api, appContext, userConfig);
76
+ await (0, _printInstructions.printInstructions)(hookRunners, appContext, userConfig);
77
77
  }
78
78
 
79
79
  isFirstCompile = false;
@@ -7,7 +7,7 @@ exports.printInstructions = void 0;
7
7
 
8
8
  var _utils = require("@modern-js/utils");
9
9
 
10
- const printInstructions = async (api, appContext, config) => {
10
+ const printInstructions = async (hookRunners, appContext, config) => {
11
11
  let message = (0, _utils.prettyInstructions)(appContext, config);
12
12
  const {
13
13
  existSrc
@@ -18,7 +18,6 @@ const printInstructions = async (api, appContext, config) => {
18
18
  } // call beforePrintInstructions hook.
19
19
 
20
20
 
21
- const hookRunners = api.useHookRunners();
22
21
  const {
23
22
  instructions
24
23
  } = await hookRunners.beforePrintInstructions({
@@ -0,0 +1 @@
1
+ export { defineServerConfig as defineConfig } from '../utils/config';
@@ -0,0 +1,12 @@
1
+ import { bundle } from '@modern-js/node-bundle-require';
2
+ import type { NormalizedConfig } from '@modern-js/core';
3
+ import type { ServerConfig } from '@modern-js/server-core';
4
+ export declare const defineServerConfig: (config: ServerConfig) => ServerConfig;
5
+ export declare const buildServerConfig: (appDirectory: string, configFile: string, options?: Parameters<typeof bundle>[1]) => Promise<void>;
6
+ /**
7
+ *
8
+ * 处理循环引用的 replacer
9
+ */
10
+
11
+ export declare const safeReplacer: () => (key: string, value: unknown) => unknown;
12
+ export declare const emitResolvedConfig: (appDirectory: string, resolvedConfig: NormalizedConfig) => Promise<void>;
@@ -1,2 +1,2 @@
1
- import type { PluginAPI, IAppContext, NormalizedConfig } from '@modern-js/core';
2
- export declare const printInstructions: (api: PluginAPI, appContext: IAppContext, config: NormalizedConfig) => Promise<void>;
1
+ import type { IAppContext, NormalizedConfig, ToRunners, CliHooks } from '@modern-js/core';
2
+ export declare const printInstructions: (hookRunners: ToRunners<CliHooks>, appContext: IAppContext, config: NormalizedConfig) => Promise<void>;
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.4.6",
14
+ "version": "1.4.7-canary.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -33,6 +33,10 @@
33
33
  "./types": {
34
34
  "jsnext:source": "./lib/types.d.ts",
35
35
  "default": "./lib/types.d.ts"
36
+ },
37
+ "./server": {
38
+ "jsnext:source": "./src/exports/server.ts",
39
+ "default": "./dist/js/node/exports/server.js"
36
40
  }
37
41
  },
38
42
  "typesVersions": {
@@ -42,6 +46,9 @@
42
46
  ],
43
47
  "types": [
44
48
  "./lib/types.d.ts"
49
+ ],
50
+ "server": [
51
+ "./dist/types/exports/server.d.ts"
45
52
  ]
46
53
  }
47
54
  },
@@ -53,6 +60,7 @@
53
60
  "@modern-js/core": "^1.6.1",
54
61
  "@modern-js/i18n-cli-language-detector": "^1.2.1",
55
62
  "@modern-js/new-action": "^1.3.3",
63
+ "@modern-js/node-bundle-require": "^1.2.3",
56
64
  "@modern-js/plugin": "^1.3.2",
57
65
  "@modern-js/plugin-analyze": "^1.3.5",
58
66
  "@modern-js/plugin-fast-refresh": "^1.2.3",
@@ -66,6 +74,7 @@
66
74
  "webpack": "^5.71.0"
67
75
  },
68
76
  "devDependencies": {
77
+ "@modern-js/server-core": "^1.2.4",
69
78
  "@scripts/build": "0.0.0",
70
79
  "@scripts/jest-config": "0.0.0",
71
80
  "@types/inquirer": "^8.2.0",
@@ -79,7 +88,8 @@
79
88
  "sideEffects": false,
80
89
  "publishConfig": {
81
90
  "registry": "https://registry.npmjs.org/",
82
- "access": "public"
91
+ "access": "public",
92
+ "types": "./dist/types/index.d.ts"
83
93
  },
84
94
  "scripts": {
85
95
  "new": "modern new",
@@ -0,0 +1,5 @@
1
+ // Jest Snapshot v1, https://goo.gl/fbAQLP
2
+
3
+ exports[`test app-tools utils safeReplacer should handle circular object 1`] = `"{\\"name\\":\\"a\\",\\"b\\":{\\"name\\":\\"b\\",\\"a\\":\\"[Circular root]\\"}}"`;
4
+
5
+ exports[`test app-tools utils safeReplacer should handle circular object 2`] = `"{\\"name\\":\\"c\\",\\"d\\":{\\"name\\":\\"d\\",\\"e\\":{\\"name\\":\\"e\\",\\"c\\":\\"[Circular root]\\"}}}"`;
@@ -6,6 +6,7 @@ import {
6
6
  getServer,
7
7
  } from '../src/utils/createServer';
8
8
  import { getSpecifiedEntries } from '../src/utils/getSpecifiedEntries';
9
+ import { safeReplacer } from '../src/utils/config';
9
10
 
10
11
  describe('test app-tools utils', () => {
11
12
  it('should return all entryNames correctly', async () => {
@@ -63,4 +64,49 @@ describe('test app-tools utils', () => {
63
64
  await closeServer();
64
65
  expect(getServer()).toBeNull();
65
66
  });
67
+
68
+ it('safeReplacer should handle circular object', () => {
69
+ const a: {
70
+ [key: string]: unknown;
71
+ } = {
72
+ name: 'a',
73
+ };
74
+
75
+ const b: {
76
+ [key: string]: unknown;
77
+ } = {
78
+ name: 'b',
79
+ };
80
+
81
+ a.b = b;
82
+ b.a = a;
83
+
84
+ const res1 = JSON.stringify(a, safeReplacer());
85
+ expect(res1).toMatchSnapshot();
86
+
87
+ const c: {
88
+ [key: string]: unknown;
89
+ } = {
90
+ name: 'c',
91
+ };
92
+
93
+ const d: {
94
+ [key: string]: unknown;
95
+ } = {
96
+ name: 'd',
97
+ };
98
+
99
+ const e: {
100
+ [key: string]: unknown;
101
+ } = {
102
+ name: 'e',
103
+ };
104
+
105
+ c.d = d;
106
+ d.e = e;
107
+ e.c = c;
108
+
109
+ const res2 = JSON.stringify(c, safeReplacer());
110
+ expect(res2).toMatchSnapshot();
111
+ });
66
112
  });