@modern-js/utils 1.0.1 → 1.1.3

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 (42) hide show
  1. package/CHANGELOG.md +26 -2
  2. package/dist/js/modern/FileSizeReporter.js +1 -1
  3. package/dist/js/modern/applyOptionsChain.js +2 -1
  4. package/dist/js/modern/compatRequire.js +11 -0
  5. package/dist/js/modern/constants.js +45 -2
  6. package/dist/js/modern/getEntryOptions.js +13 -4
  7. package/dist/js/modern/is/type.js +3 -0
  8. package/dist/js/modern/prettyInstructions.js +2 -2
  9. package/dist/js/modern/runtimeExports.js +5 -2
  10. package/dist/js/node/FileSizeReporter.js +5 -5
  11. package/dist/js/node/applyOptionsChain.js +6 -5
  12. package/dist/js/node/compatRequire.js +16 -2
  13. package/dist/js/node/constants.js +52 -5
  14. package/dist/js/node/getEntryOptions.js +14 -4
  15. package/dist/js/node/is/type.js +5 -0
  16. package/dist/js/node/prettyInstructions.js +5 -3
  17. package/dist/js/node/runtimeExports.js +8 -2
  18. package/dist/js/treeshaking/FileSizeReporter.js +1 -1
  19. package/dist/js/treeshaking/applyOptionsChain.js +2 -1
  20. package/dist/js/treeshaking/compatRequire.js +14 -0
  21. package/dist/js/treeshaking/constants.js +45 -2
  22. package/dist/js/treeshaking/getEntryOptions.js +14 -3
  23. package/dist/js/treeshaking/is/type.js +3 -0
  24. package/dist/js/treeshaking/prettyInstructions.js +2 -2
  25. package/dist/js/treeshaking/runtimeExports.js +8 -2
  26. package/dist/types/compatRequire.d.ts +2 -1
  27. package/dist/types/constants.d.ts +21 -2
  28. package/dist/types/getEntryOptions.d.ts +1 -1
  29. package/dist/types/is/type.d.ts +2 -1
  30. package/dist/types/prettyInstructions.d.ts +6 -1
  31. package/dist/types/runtimeExports.d.ts +1 -1
  32. package/package.json +3 -3
  33. package/src/FileSizeReporter.ts +1 -1
  34. package/src/applyOptionsChain.ts +2 -1
  35. package/src/compatRequire.ts +15 -0
  36. package/src/constants.ts +41 -3
  37. package/src/getEntryOptions.ts +23 -4
  38. package/src/is/type.ts +4 -0
  39. package/src/prettyInstructions.ts +2 -2
  40. package/src/runtimeExports.ts +12 -1
  41. package/tests/ensureAbsolutePath.test.ts +7 -4
  42. package/tests/getEntryOptions.test.ts +11 -0
package/CHANGELOG.md CHANGED
@@ -1,10 +1,34 @@
1
1
  # @modern-js/utils
2
2
 
3
- ## 1.0.1
3
+ ## 1.1.3
4
4
 
5
5
  ### Patch Changes
6
6
 
7
- - release 1.0.1
7
+ - 085a6a58: refactor server plugin
8
+ - 085a6a58: refactor server plugin
9
+ - 085a6a58: refactor server conifg
10
+ - d280ea33: chore: runtime exports can choose to generate d.ts file
11
+ - 085a6a58: support server runtime
12
+ - 085a6a58: feat: refactor server plugin
13
+
14
+ ## 1.1.2
15
+
16
+ ### Patch Changes
17
+
18
+ - 0fa83663: support more .env files
19
+ - f594fbc8: fix apple icon and favicon support
20
+
21
+ ## 1.1.1
22
+
23
+ ### Patch Changes
24
+
25
+ - c0fc0700: feat: support deploy plugin
26
+
27
+ ## 1.1.0
28
+
29
+ ### Minor Changes
30
+
31
+ - 96119db2: Relese v1.1.0
8
32
 
9
33
  ## 1.0.0
10
34
 
@@ -19,7 +19,7 @@ import filesize from 'filesize';
19
19
  import recursive from 'recursive-readdir';
20
20
  import stripAnsi from 'strip-ansi';
21
21
  import gzipSize from 'gzip-size';
22
- import { logger } from '.';
22
+ import { logger } from "./logger";
23
23
 
24
24
  function canReadAsset(asset) {
25
25
  return /\.(js|css)$/.test(asset) && !/service-worker\.js/.test(asset) && !/precache-manifest\.[0-9a-f]+\.js/.test(asset);
@@ -1,4 +1,5 @@
1
- import { isFunction, logger, isPlainObject } from '.';
1
+ // eslint-disable-next-line import/no-useless-path-segments
2
+ import { isFunction, logger, isPlainObject } from "./index";
2
3
  export const applyOptionsChain = (defaults, options, utils, mergeFn = Object.assign) => {
3
4
  if (!options) {
4
5
  return defaults;
@@ -1,10 +1,21 @@
1
+ import { findExists } from "./findExists";
1
2
  /**
2
3
  * Require function compatible with esm and cjs module.
3
4
  * @param filePath - File to required.
4
5
  * @returns module export object.
5
6
  */
7
+
6
8
  export const compatRequire = filePath => {
7
9
  const mod = require(filePath);
8
10
 
9
11
  return mod !== null && mod !== void 0 && mod.__esModule ? mod.default : mod;
12
+ };
13
+ export const requireExistModule = (filename, extensions = ['.ts', '.js']) => {
14
+ const exist = findExists(extensions.map(ext => `${filename}${ext}`));
15
+
16
+ if (!exist) {
17
+ return null;
18
+ }
19
+
20
+ return compatRequire(exist);
10
21
  };
@@ -17,6 +17,11 @@ export const HMR_SOCK_PATH = '/_modern_js_hmr_ws';
17
17
  */
18
18
 
19
19
  export const ROUTE_SPEC_FILE = 'route.json';
20
+ /**
21
+ * main entry name
22
+ */
23
+
24
+ export const MAIN_ENTRY_NAME = 'main';
20
25
  /**
21
26
  * open editor request path
22
27
  */
@@ -42,7 +47,18 @@ export const SERVER_RENDER_FUNCTION_NAME = 'serverRender';
42
47
  */
43
48
 
44
49
  export const LOADABLE_STATS_FILE = 'loadable-stats.json';
50
+ /**
51
+ * real entry generate by modern.js
52
+ */
53
+
45
54
  export const HIDE_MODERN_JS_DIR = './node_modules/.modern-js';
55
+ /**
56
+ * internal specified folder
57
+ */
58
+
59
+ export const API_DIR = 'api';
60
+ export const SERVER_DIR = 'server';
61
+ export const SHARED_DIR = 'shared';
46
62
  /**
47
63
  * Internal plugins that work as soon as they are installed.
48
64
  */
@@ -113,6 +129,10 @@ export const INTERNAL_PLUGINS = {
113
129
  '@modern-js/plugin-server-build': {
114
130
  cli: '@modern-js/plugin-server-build'
115
131
  },
132
+ '@modern-js/plugin-server': {
133
+ cli: '@modern-js/plugin-server/cli',
134
+ server: '@modern-js/plugin-server/server'
135
+ },
116
136
  '@modern-js/plugin-micro-frontend': {
117
137
  cli: '@modern-js/plugin-micro-frontend/cli'
118
138
  },
@@ -121,6 +141,24 @@ export const INTERNAL_PLUGINS = {
121
141
  },
122
142
  '@modern-js/plugin-tailwindcss': {
123
143
  cli: '@modern-js/plugin-tailwindcss/cli'
144
+ },
145
+ '@modern-js/plugin-lambda-fc': {
146
+ cli: '@modern-js/plugin-lambda-fc/cli'
147
+ },
148
+ '@modern-js/plugin-lambda-scf': {
149
+ cli: '@modern-js/plugin-lambda-scf/cli'
150
+ },
151
+ '@modern-js/plugin-cdn-oss': {
152
+ cli: '@modern-js/plugin-cdn-oss/cli'
153
+ },
154
+ '@modern-js/plugin-cdn-cos': {
155
+ cli: '@modern-js/plugin-cdn-cos/cli'
156
+ },
157
+ '@modern-js/plugin-static-hosting': {
158
+ cli: '@modern-js/plugin-static-hosting/cli'
159
+ },
160
+ '@modern-js/plugin-polyfill': {
161
+ server: '@modern-js/plugin-polyfill'
124
162
  }
125
163
  };
126
164
  /**
@@ -152,7 +190,10 @@ export const PLUGIN_SCHEMAS = {
152
190
  type: 'object',
153
191
  properties: {
154
192
  prefix: {
155
- type: 'string'
193
+ type: ['string', 'array'],
194
+ items: {
195
+ type: 'string'
196
+ }
156
197
  },
157
198
  fetcher: {
158
199
  type: 'string'
@@ -160,7 +201,7 @@ export const PLUGIN_SCHEMAS = {
160
201
  proxy: {
161
202
  type: 'object'
162
203
  },
163
- requestCreater: {
204
+ requestCreator: {
164
205
  type: 'string'
165
206
  }
166
207
  }
@@ -217,6 +258,8 @@ export const PLUGIN_SCHEMAS = {
217
258
  schema: {
218
259
  oneOf: [{
219
260
  type: 'boolean'
261
+ }, {
262
+ type: 'object'
220
263
  }, {
221
264
  instanceof: 'Function'
222
265
  }]
@@ -5,11 +5,20 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
5
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
6
 
7
7
  import { isPlainObject } from "./is";
8
- export const getEntryOptions = (name, baseOptions, optionsByEntries) => {
8
+ import { MAIN_ENTRY_NAME } from "./constants";
9
+ export const getEntryOptions = (name, baseOptions, optionsByEntries, packageName) => {
9
10
  if (optionsByEntries) {
10
- // eslint-disable-next-line no-nested-ternary
11
- return optionsByEntries.hasOwnProperty(name) ? isPlainObject(optionsByEntries[name]) && isPlainObject(baseOptions) ? _objectSpread(_objectSpread({}, baseOptions), optionsByEntries[name]) : optionsByEntries[name] : baseOptions;
11
+ let optionsByEntry = getOptionsByEntryName(name, optionsByEntries); // compatible with main entry using packageName as the key
12
+
13
+ if (optionsByEntry === undefined && name === MAIN_ENTRY_NAME && packageName) {
14
+ optionsByEntry = getOptionsByEntryName(packageName, optionsByEntries);
15
+ } // eslint-disable-next-line no-nested-ternary
16
+
17
+
18
+ return optionsByEntry !== undefined ? isPlainObject(optionsByEntry) && isPlainObject(baseOptions) ? _objectSpread(_objectSpread({}, baseOptions), optionsByEntry) : optionsByEntry : baseOptions;
12
19
  } else {
13
20
  return baseOptions;
14
21
  }
15
- };
22
+ };
23
+
24
+ const getOptionsByEntryName = (name, optionsByEntries) => optionsByEntries.hasOwnProperty(name) ? optionsByEntries[name] : undefined;
@@ -22,4 +22,7 @@ export function isPromise(obj) {
22
22
  /* eslint-disable promise/prefer-await-to-then */
23
23
  return Boolean(obj) && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
24
24
  /* eslint-enable promise/prefer-await-to-then */
25
+ }
26
+ export function isRegExp(obj) {
27
+ return Object.prototype.toString.call(obj) === '[object RegExp]';
25
28
  }
@@ -3,7 +3,7 @@ import chalk from 'chalk';
3
3
  import { isDev } from "./is"; // TODO: type
4
4
 
5
5
  // TODO: remove hard code 'main'
6
- const isSPA = entrypoints => entrypoints.length === 1 && entrypoints[0].entryName === 'main';
6
+ export const isSingleEntry = entrypoints => entrypoints.length === 1 && entrypoints[0].entryName === 'main';
7
7
 
8
8
  const normalizeUrl = url => url.replace(/([^:]\/)\/+/g, '$1');
9
9
 
@@ -44,7 +44,7 @@ export const prettyInstructions = (appContext, config) => {
44
44
  const routes = serverRoutes.filter(route => route.entryName);
45
45
  let message = 'App running at:\n\n';
46
46
 
47
- if (isSPA(entrypoints)) {
47
+ if (isSingleEntry(entrypoints)) {
48
48
  message += urls.map(({
49
49
  type,
50
50
  url
@@ -18,8 +18,9 @@ const memo = fn => {
18
18
  };
19
19
  };
20
20
 
21
- export const createRuntimeExportsUtils = memo((pwd, namespace) => {
22
- const entryExportFile = path.join(pwd, `.runtime-exports/${namespace ? `${namespace}.js` : 'index.js'}`); // const ensure = () => {
21
+ export const createRuntimeExportsUtils = memo((pwd = '', namespace, ts = false) => {
22
+ const entryExportFile = path.join(pwd, `.runtime-exports/${namespace ? `${namespace}.js` : 'index.js'}`);
23
+ const entryExportTsFile = path.join(pwd, `.runtime-exports/${namespace ? `${namespace}.d.ts` : 'index.d.ts'}`); // const ensure = () => {
23
24
  // if (!fs.existsSync(entryExportFile)) {
24
25
  // fs.outputFileSync(entryExportFile, '');
25
26
  // }
@@ -32,9 +33,11 @@ export const createRuntimeExportsUtils = memo((pwd, namespace) => {
32
33
 
33
34
  try {
34
35
  fs.ensureFileSync(entryExportFile);
36
+ fs.ensureFileSync(entryExportTsFile);
35
37
 
36
38
  if (!fs.readFileSync(entryExportFile, 'utf8').includes(statement)) {
37
39
  fs.appendFileSync(entryExportFile, `${statement}\n`);
40
+ ts && fs.appendFileSync(entryExportTsFile, `${statement.replace('.js', '.d')}\n`);
38
41
  }
39
42
  } catch (_unused) {// FIXME:
40
43
  }
@@ -32,7 +32,7 @@ var _stripAnsi = _interopRequireDefault(require("strip-ansi"));
32
32
 
33
33
  var _gzipSize = _interopRequireDefault(require("gzip-size"));
34
34
 
35
- var _ = require(".");
35
+ var _logger = require("./logger");
36
36
 
37
37
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
38
38
 
@@ -101,13 +101,13 @@ function printFileSizesAfterBuild(webpackStats, previousSizeMap, buildFolder, ma
101
101
  suggestBundleSplitting = true;
102
102
  }
103
103
 
104
- _.logger.log(' ' + fileNameLabel + ' ' + sizeLabel + ' ' + (isLarge ? _chalk.default.yellow(gzipSizeLabel) : gzipSizeLabel));
104
+ _logger.logger.log(' ' + fileNameLabel + ' ' + sizeLabel + ' ' + (isLarge ? _chalk.default.yellow(gzipSizeLabel) : gzipSizeLabel));
105
105
  });
106
106
 
107
107
  if (suggestBundleSplitting) {
108
- _.logger.log();
108
+ _logger.logger.log();
109
109
 
110
- _.logger.warn('The bundle size is significantly larger than recommended.');
110
+ _logger.logger.warn('The bundle size is significantly larger than recommended.');
111
111
  }
112
112
  }
113
113
 
@@ -124,7 +124,7 @@ function printFileSizesHeader(longestFileNameLength, longestSizeLabelLength) {
124
124
  return prev + curLabel + ' ';
125
125
  }, ' ');
126
126
 
127
- _.logger.log(_chalk.default.bold(_chalk.default.blue(headerRow)));
127
+ _logger.logger.log(_chalk.default.bold(_chalk.default.blue(headerRow)));
128
128
  }
129
129
 
130
130
  function removeFileNameHash(buildFolder, fileName) {
@@ -5,21 +5,22 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.applyOptionsChain = void 0;
7
7
 
8
- var _ = require(".");
8
+ var _index = require("./index");
9
9
 
10
+ // eslint-disable-next-line import/no-useless-path-segments
10
11
  const applyOptionsChain = (defaults, options, utils, mergeFn = Object.assign) => {
11
12
  if (!options) {
12
13
  return defaults;
13
14
  }
14
15
 
15
- if ((0, _.isPlainObject)(options)) {
16
+ if ((0, _index.isPlainObject)(options)) {
16
17
  return mergeFn(defaults, options);
17
- } else if ((0, _.isFunction)(options)) {
18
+ } else if ((0, _index.isFunction)(options)) {
18
19
  const ret = options(defaults, utils);
19
20
 
20
21
  if (ret) {
21
- if (!(0, _.isPlainObject)(ret)) {
22
- _.logger.warn(`${options.name}: Function should mutate the config and return nothing, Or return a cloned or merged version of config object.`);
22
+ if (!(0, _index.isPlainObject)(ret)) {
23
+ _index.logger.warn(`${options.name}: Function should mutate the config and return nothing, Or return a cloned or merged version of config object.`);
23
24
  }
24
25
 
25
26
  return ret;
@@ -3,7 +3,9 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.compatRequire = void 0;
6
+ exports.requireExistModule = exports.compatRequire = void 0;
7
+
8
+ var _findExists = require("./findExists");
7
9
 
8
10
  /**
9
11
  * Require function compatible with esm and cjs module.
@@ -16,4 +18,16 @@ const compatRequire = filePath => {
16
18
  return mod !== null && mod !== void 0 && mod.__esModule ? mod.default : mod;
17
19
  };
18
20
 
19
- exports.compatRequire = compatRequire;
21
+ exports.compatRequire = compatRequire;
22
+
23
+ const requireExistModule = (filename, extensions = ['.ts', '.js']) => {
24
+ const exist = (0, _findExists.findExists)(extensions.map(ext => `${filename}${ext}`));
25
+
26
+ if (!exist) {
27
+ return null;
28
+ }
29
+
30
+ return compatRequire(exist);
31
+ };
32
+
33
+ exports.requireExistModule = requireExistModule;
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.SERVER_RENDER_FUNCTION_NAME = exports.SERVER_BUNDLE_DIRECTORY = exports.ROUTE_SPEC_FILE = exports.PLUGIN_SCHEMAS = exports.LOADABLE_STATS_FILE = exports.LAUNCH_EDITOR_ENDPOINT = exports.INTERNAL_SRC_ALIAS = exports.INTERNAL_PLUGINS = exports.INTERNAL_DIR_ALAIS = exports.HMR_SOCK_PATH = exports.HIDE_MODERN_JS_DIR = exports.ENTRY_NAME_PATTERN = void 0;
6
+ exports.SHARED_DIR = exports.SERVER_RENDER_FUNCTION_NAME = exports.SERVER_DIR = exports.SERVER_BUNDLE_DIRECTORY = exports.ROUTE_SPEC_FILE = exports.PLUGIN_SCHEMAS = exports.MAIN_ENTRY_NAME = exports.LOADABLE_STATS_FILE = exports.LAUNCH_EDITOR_ENDPOINT = exports.INTERNAL_SRC_ALIAS = exports.INTERNAL_PLUGINS = exports.INTERNAL_DIR_ALAIS = exports.HMR_SOCK_PATH = exports.HIDE_MODERN_JS_DIR = exports.ENTRY_NAME_PATTERN = exports.API_DIR = void 0;
7
7
 
8
8
  /**
9
9
  * alias to src directory
@@ -28,10 +28,16 @@ const HMR_SOCK_PATH = '/_modern_js_hmr_ws';
28
28
  exports.HMR_SOCK_PATH = HMR_SOCK_PATH;
29
29
  const ROUTE_SPEC_FILE = 'route.json';
30
30
  /**
31
- * open editor request path
31
+ * main entry name
32
32
  */
33
33
 
34
34
  exports.ROUTE_SPEC_FILE = ROUTE_SPEC_FILE;
35
+ const MAIN_ENTRY_NAME = 'main';
36
+ /**
37
+ * open editor request path
38
+ */
39
+
40
+ exports.MAIN_ENTRY_NAME = MAIN_ENTRY_NAME;
35
41
  const LAUNCH_EDITOR_ENDPOINT = '/__open-stack-frame-in-editor';
36
42
  /**
37
43
  * server side bundles directory, which relative to dist.
@@ -57,13 +63,27 @@ const SERVER_RENDER_FUNCTION_NAME = 'serverRender';
57
63
 
58
64
  exports.SERVER_RENDER_FUNCTION_NAME = SERVER_RENDER_FUNCTION_NAME;
59
65
  const LOADABLE_STATS_FILE = 'loadable-stats.json';
66
+ /**
67
+ * real entry generate by modern.js
68
+ */
69
+
60
70
  exports.LOADABLE_STATS_FILE = LOADABLE_STATS_FILE;
61
71
  const HIDE_MODERN_JS_DIR = './node_modules/.modern-js';
62
72
  /**
63
- * Internal plugins that work as soon as they are installed.
73
+ * internal specified folder
64
74
  */
65
75
 
66
76
  exports.HIDE_MODERN_JS_DIR = HIDE_MODERN_JS_DIR;
77
+ const API_DIR = 'api';
78
+ exports.API_DIR = API_DIR;
79
+ const SERVER_DIR = 'server';
80
+ exports.SERVER_DIR = SERVER_DIR;
81
+ const SHARED_DIR = 'shared';
82
+ /**
83
+ * Internal plugins that work as soon as they are installed.
84
+ */
85
+
86
+ exports.SHARED_DIR = SHARED_DIR;
67
87
  const INTERNAL_PLUGINS = {
68
88
  '@modern-js/app-tools': {
69
89
  cli: '@modern-js/app-tools/cli'
@@ -130,6 +150,10 @@ const INTERNAL_PLUGINS = {
130
150
  '@modern-js/plugin-server-build': {
131
151
  cli: '@modern-js/plugin-server-build'
132
152
  },
153
+ '@modern-js/plugin-server': {
154
+ cli: '@modern-js/plugin-server/cli',
155
+ server: '@modern-js/plugin-server/server'
156
+ },
133
157
  '@modern-js/plugin-micro-frontend': {
134
158
  cli: '@modern-js/plugin-micro-frontend/cli'
135
159
  },
@@ -138,6 +162,24 @@ const INTERNAL_PLUGINS = {
138
162
  },
139
163
  '@modern-js/plugin-tailwindcss': {
140
164
  cli: '@modern-js/plugin-tailwindcss/cli'
165
+ },
166
+ '@modern-js/plugin-lambda-fc': {
167
+ cli: '@modern-js/plugin-lambda-fc/cli'
168
+ },
169
+ '@modern-js/plugin-lambda-scf': {
170
+ cli: '@modern-js/plugin-lambda-scf/cli'
171
+ },
172
+ '@modern-js/plugin-cdn-oss': {
173
+ cli: '@modern-js/plugin-cdn-oss/cli'
174
+ },
175
+ '@modern-js/plugin-cdn-cos': {
176
+ cli: '@modern-js/plugin-cdn-cos/cli'
177
+ },
178
+ '@modern-js/plugin-static-hosting': {
179
+ cli: '@modern-js/plugin-static-hosting/cli'
180
+ },
181
+ '@modern-js/plugin-polyfill': {
182
+ server: '@modern-js/plugin-polyfill'
141
183
  }
142
184
  };
143
185
  /**
@@ -170,7 +212,10 @@ const PLUGIN_SCHEMAS = {
170
212
  type: 'object',
171
213
  properties: {
172
214
  prefix: {
173
- type: 'string'
215
+ type: ['string', 'array'],
216
+ items: {
217
+ type: 'string'
218
+ }
174
219
  },
175
220
  fetcher: {
176
221
  type: 'string'
@@ -178,7 +223,7 @@ const PLUGIN_SCHEMAS = {
178
223
  proxy: {
179
224
  type: 'object'
180
225
  },
181
- requestCreater: {
226
+ requestCreator: {
182
227
  type: 'string'
183
228
  }
184
229
  }
@@ -235,6 +280,8 @@ const PLUGIN_SCHEMAS = {
235
280
  schema: {
236
281
  oneOf: [{
237
282
  type: 'boolean'
283
+ }, {
284
+ type: 'object'
238
285
  }, {
239
286
  instanceof: 'Function'
240
287
  }]
@@ -7,19 +7,29 @@ exports.getEntryOptions = void 0;
7
7
 
8
8
  var _is = require("./is");
9
9
 
10
+ var _constants = require("./constants");
11
+
10
12
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
11
13
 
12
14
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
13
15
 
14
16
  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; }
15
17
 
16
- const getEntryOptions = (name, baseOptions, optionsByEntries) => {
18
+ const getEntryOptions = (name, baseOptions, optionsByEntries, packageName) => {
17
19
  if (optionsByEntries) {
18
- // eslint-disable-next-line no-nested-ternary
19
- return optionsByEntries.hasOwnProperty(name) ? (0, _is.isPlainObject)(optionsByEntries[name]) && (0, _is.isPlainObject)(baseOptions) ? _objectSpread(_objectSpread({}, baseOptions), optionsByEntries[name]) : optionsByEntries[name] : baseOptions;
20
+ let optionsByEntry = getOptionsByEntryName(name, optionsByEntries); // compatible with main entry using packageName as the key
21
+
22
+ if (optionsByEntry === undefined && name === _constants.MAIN_ENTRY_NAME && packageName) {
23
+ optionsByEntry = getOptionsByEntryName(packageName, optionsByEntries);
24
+ } // eslint-disable-next-line no-nested-ternary
25
+
26
+
27
+ return optionsByEntry !== undefined ? (0, _is.isPlainObject)(optionsByEntry) && (0, _is.isPlainObject)(baseOptions) ? _objectSpread(_objectSpread({}, baseOptions), optionsByEntry) : optionsByEntry : baseOptions;
20
28
  } else {
21
29
  return baseOptions;
22
30
  }
23
31
  };
24
32
 
25
- exports.getEntryOptions = getEntryOptions;
33
+ exports.getEntryOptions = getEntryOptions;
34
+
35
+ const getOptionsByEntryName = (name, optionsByEntries) => optionsByEntries.hasOwnProperty(name) ? optionsByEntries[name] : undefined;
@@ -8,6 +8,7 @@ exports.isFunction = isFunction;
8
8
  exports.isObject = isObject;
9
9
  exports.isPlainObject = isPlainObject;
10
10
  exports.isPromise = isPromise;
11
+ exports.isRegExp = isRegExp;
11
12
  exports.isString = isString;
12
13
  exports.isUndefined = isUndefined;
13
14
 
@@ -41,4 +42,8 @@ function isPromise(obj) {
41
42
  /* eslint-disable promise/prefer-await-to-then */
42
43
  return Boolean(obj) && (typeof obj === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
43
44
  /* eslint-enable promise/prefer-await-to-then */
45
+ }
46
+
47
+ function isRegExp(obj) {
48
+ return Object.prototype.toString.call(obj) === '[object RegExp]';
44
49
  }
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.prettyInstructions = void 0;
6
+ exports.prettyInstructions = exports.isSingleEntry = void 0;
7
7
 
8
8
  var _os = _interopRequireDefault(require("os"));
9
9
 
@@ -14,7 +14,9 @@ var _is = require("./is");
14
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
15
 
16
16
  // TODO: remove hard code 'main'
17
- const isSPA = entrypoints => entrypoints.length === 1 && entrypoints[0].entryName === 'main';
17
+ const isSingleEntry = entrypoints => entrypoints.length === 1 && entrypoints[0].entryName === 'main';
18
+
19
+ exports.isSingleEntry = isSingleEntry;
18
20
 
19
21
  const normalizeUrl = url => url.replace(/([^:]\/)\/+/g, '$1');
20
22
 
@@ -56,7 +58,7 @@ const prettyInstructions = (appContext, config) => {
56
58
  const routes = serverRoutes.filter(route => route.entryName);
57
59
  let message = 'App running at:\n\n';
58
60
 
59
- if (isSPA(entrypoints)) {
61
+ if (isSingleEntry(entrypoints)) {
60
62
  message += urls.map(({
61
63
  type,
62
64
  url
@@ -29,8 +29,10 @@ const memo = fn => {
29
29
  };
30
30
  };
31
31
 
32
- const createRuntimeExportsUtils = memo((pwd, namespace) => {
33
- const entryExportFile = _path.default.join(pwd, `.runtime-exports/${namespace ? `${namespace}.js` : 'index.js'}`); // const ensure = () => {
32
+ const createRuntimeExportsUtils = memo((pwd = '', namespace, ts = false) => {
33
+ const entryExportFile = _path.default.join(pwd, `.runtime-exports/${namespace ? `${namespace}.js` : 'index.js'}`);
34
+
35
+ const entryExportTsFile = _path.default.join(pwd, `.runtime-exports/${namespace ? `${namespace}.d.ts` : 'index.d.ts'}`); // const ensure = () => {
34
36
  // if (!fs.existsSync(entryExportFile)) {
35
37
  // fs.outputFileSync(entryExportFile, '');
36
38
  // }
@@ -45,8 +47,12 @@ const createRuntimeExportsUtils = memo((pwd, namespace) => {
45
47
  try {
46
48
  _fsExtra.default.ensureFileSync(entryExportFile);
47
49
 
50
+ _fsExtra.default.ensureFileSync(entryExportTsFile);
51
+
48
52
  if (!_fsExtra.default.readFileSync(entryExportFile, 'utf8').includes(statement)) {
49
53
  _fsExtra.default.appendFileSync(entryExportFile, `${statement}\n`);
54
+
55
+ ts && _fsExtra.default.appendFileSync(entryExportTsFile, `${statement.replace('.js', '.d')}\n`);
50
56
  }
51
57
  } catch (_unused) {// FIXME:
52
58
  }
@@ -31,7 +31,7 @@ import filesize from 'filesize';
31
31
  import recursive from 'recursive-readdir';
32
32
  import stripAnsi from 'strip-ansi';
33
33
  import gzipSize from 'gzip-size';
34
- import { logger } from '.';
34
+ import { logger } from "./logger";
35
35
 
36
36
  function canReadAsset(asset) {
37
37
  return /\.(js|css)$/.test(asset) && !/service-worker\.js/.test(asset) && !/precache-manifest\.[0-9a-f]+\.js/.test(asset);
@@ -1,4 +1,5 @@
1
- import { isFunction, logger, isPlainObject } from '.';
1
+ // eslint-disable-next-line import/no-useless-path-segments
2
+ import { isFunction, logger, isPlainObject } from "./index";
2
3
  export var applyOptionsChain = function applyOptionsChain(defaults, options, utils) {
3
4
  var mergeFn = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : Object.assign;
4
5
 
@@ -1,10 +1,24 @@
1
+ import { findExists } from "./findExists";
1
2
  /**
2
3
  * Require function compatible with esm and cjs module.
3
4
  * @param filePath - File to required.
4
5
  * @returns module export object.
5
6
  */
7
+
6
8
  export var compatRequire = function compatRequire(filePath) {
7
9
  var mod = require(filePath);
8
10
 
9
11
  return mod !== null && mod !== void 0 && mod.__esModule ? mod["default"] : mod;
12
+ };
13
+ export var requireExistModule = function requireExistModule(filename) {
14
+ var extensions = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : ['.ts', '.js'];
15
+ var exist = findExists(extensions.map(function (ext) {
16
+ return "".concat(filename).concat(ext);
17
+ }));
18
+
19
+ if (!exist) {
20
+ return null;
21
+ }
22
+
23
+ return compatRequire(exist);
10
24
  };
@@ -19,6 +19,11 @@ export var HMR_SOCK_PATH = '/_modern_js_hmr_ws';
19
19
  */
20
20
 
21
21
  export var ROUTE_SPEC_FILE = 'route.json';
22
+ /**
23
+ * main entry name
24
+ */
25
+
26
+ export var MAIN_ENTRY_NAME = 'main';
22
27
  /**
23
28
  * open editor request path
24
29
  */
@@ -44,7 +49,18 @@ export var SERVER_RENDER_FUNCTION_NAME = 'serverRender';
44
49
  */
45
50
 
46
51
  export var LOADABLE_STATS_FILE = 'loadable-stats.json';
52
+ /**
53
+ * real entry generate by modern.js
54
+ */
55
+
47
56
  export var HIDE_MODERN_JS_DIR = './node_modules/.modern-js';
57
+ /**
58
+ * internal specified folder
59
+ */
60
+
61
+ export var API_DIR = 'api';
62
+ export var SERVER_DIR = 'server';
63
+ export var SHARED_DIR = 'shared';
48
64
  /**
49
65
  * Internal plugins that work as soon as they are installed.
50
66
  */
@@ -115,6 +131,10 @@ export var INTERNAL_PLUGINS = {
115
131
  '@modern-js/plugin-server-build': {
116
132
  cli: '@modern-js/plugin-server-build'
117
133
  },
134
+ '@modern-js/plugin-server': {
135
+ cli: '@modern-js/plugin-server/cli',
136
+ server: '@modern-js/plugin-server/server'
137
+ },
118
138
  '@modern-js/plugin-micro-frontend': {
119
139
  cli: '@modern-js/plugin-micro-frontend/cli'
120
140
  },
@@ -123,6 +143,24 @@ export var INTERNAL_PLUGINS = {
123
143
  },
124
144
  '@modern-js/plugin-tailwindcss': {
125
145
  cli: '@modern-js/plugin-tailwindcss/cli'
146
+ },
147
+ '@modern-js/plugin-lambda-fc': {
148
+ cli: '@modern-js/plugin-lambda-fc/cli'
149
+ },
150
+ '@modern-js/plugin-lambda-scf': {
151
+ cli: '@modern-js/plugin-lambda-scf/cli'
152
+ },
153
+ '@modern-js/plugin-cdn-oss': {
154
+ cli: '@modern-js/plugin-cdn-oss/cli'
155
+ },
156
+ '@modern-js/plugin-cdn-cos': {
157
+ cli: '@modern-js/plugin-cdn-cos/cli'
158
+ },
159
+ '@modern-js/plugin-static-hosting': {
160
+ cli: '@modern-js/plugin-static-hosting/cli'
161
+ },
162
+ '@modern-js/plugin-polyfill': {
163
+ server: '@modern-js/plugin-polyfill'
126
164
  }
127
165
  };
128
166
  /**
@@ -152,7 +190,10 @@ export var PLUGIN_SCHEMAS = {
152
190
  type: 'object',
153
191
  properties: {
154
192
  prefix: {
155
- type: 'string'
193
+ type: ['string', 'array'],
194
+ items: {
195
+ type: 'string'
196
+ }
156
197
  },
157
198
  fetcher: {
158
199
  type: 'string'
@@ -160,7 +201,7 @@ export var PLUGIN_SCHEMAS = {
160
201
  proxy: {
161
202
  type: 'object'
162
203
  },
163
- requestCreater: {
204
+ requestCreator: {
164
205
  type: 'string'
165
206
  }
166
207
  }
@@ -217,6 +258,8 @@ export var PLUGIN_SCHEMAS = {
217
258
  schema: {
218
259
  oneOf: [{
219
260
  type: 'boolean'
261
+ }, {
262
+ type: 'object'
220
263
  }, {
221
264
  "instanceof": 'Function'
222
265
  }]
@@ -5,11 +5,22 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
5
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
6
 
7
7
  import { isPlainObject } from "./is";
8
- export var getEntryOptions = function getEntryOptions(name, baseOptions, optionsByEntries) {
8
+ import { MAIN_ENTRY_NAME } from "./constants";
9
+ export var getEntryOptions = function getEntryOptions(name, baseOptions, optionsByEntries, packageName) {
9
10
  if (optionsByEntries) {
10
- // eslint-disable-next-line no-nested-ternary
11
- return optionsByEntries.hasOwnProperty(name) ? isPlainObject(optionsByEntries[name]) && isPlainObject(baseOptions) ? _objectSpread(_objectSpread({}, baseOptions), optionsByEntries[name]) : optionsByEntries[name] : baseOptions;
11
+ var optionsByEntry = getOptionsByEntryName(name, optionsByEntries); // compatible with main entry using packageName as the key
12
+
13
+ if (optionsByEntry === undefined && name === MAIN_ENTRY_NAME && packageName) {
14
+ optionsByEntry = getOptionsByEntryName(packageName, optionsByEntries);
15
+ } // eslint-disable-next-line no-nested-ternary
16
+
17
+
18
+ return optionsByEntry !== undefined ? isPlainObject(optionsByEntry) && isPlainObject(baseOptions) ? _objectSpread(_objectSpread({}, baseOptions), optionsByEntry) : optionsByEntry : baseOptions;
12
19
  } else {
13
20
  return baseOptions;
14
21
  }
22
+ };
23
+
24
+ var getOptionsByEntryName = function getOptionsByEntryName(name, optionsByEntries) {
25
+ return optionsByEntries.hasOwnProperty(name) ? optionsByEntries[name] : undefined;
15
26
  };
@@ -24,4 +24,7 @@ export function isPromise(obj) {
24
24
  /* eslint-disable promise/prefer-await-to-then */
25
25
  return Boolean(obj) && (_typeof(obj) === 'object' || typeof obj === 'function') && typeof obj.then === 'function';
26
26
  /* eslint-enable promise/prefer-await-to-then */
27
+ }
28
+ export function isRegExp(obj) {
29
+ return Object.prototype.toString.call(obj) === '[object RegExp]';
27
30
  }
@@ -15,7 +15,7 @@ import chalk from 'chalk';
15
15
  import { isDev } from "./is"; // TODO: type
16
16
 
17
17
  // TODO: remove hard code 'main'
18
- var isSPA = function isSPA(entrypoints) {
18
+ export var isSingleEntry = function isSingleEntry(entrypoints) {
19
19
  return entrypoints.length === 1 && entrypoints[0].entryName === 'main';
20
20
  };
21
21
 
@@ -63,7 +63,7 @@ export var prettyInstructions = function prettyInstructions(appContext, config)
63
63
  });
64
64
  var message = 'App running at:\n\n';
65
65
 
66
- if (isSPA(entrypoints)) {
66
+ if (isSingleEntry(entrypoints)) {
67
67
  message += urls.map(function (_ref2) {
68
68
  var type = _ref2.type,
69
69
  url = _ref2.url;
@@ -22,8 +22,12 @@ var memo = function memo(fn) {
22
22
  };
23
23
  };
24
24
 
25
- export var createRuntimeExportsUtils = memo(function (pwd, namespace) {
26
- var entryExportFile = path.join(pwd, ".runtime-exports/".concat(namespace ? "".concat(namespace, ".js") : 'index.js')); // const ensure = () => {
25
+ export var createRuntimeExportsUtils = memo(function () {
26
+ var pwd = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
27
+ var namespace = arguments.length > 1 ? arguments[1] : undefined;
28
+ var ts = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
29
+ var entryExportFile = path.join(pwd, ".runtime-exports/".concat(namespace ? "".concat(namespace, ".js") : 'index.js'));
30
+ var entryExportTsFile = path.join(pwd, ".runtime-exports/".concat(namespace ? "".concat(namespace, ".d.ts") : 'index.d.ts')); // const ensure = () => {
27
31
  // if (!fs.existsSync(entryExportFile)) {
28
32
  // fs.outputFileSync(entryExportFile, '');
29
33
  // }
@@ -36,9 +40,11 @@ export var createRuntimeExportsUtils = memo(function (pwd, namespace) {
36
40
 
37
41
  try {
38
42
  fs.ensureFileSync(entryExportFile);
43
+ fs.ensureFileSync(entryExportTsFile);
39
44
 
40
45
  if (!fs.readFileSync(entryExportFile, 'utf8').includes(statement)) {
41
46
  fs.appendFileSync(entryExportFile, "".concat(statement, "\n"));
47
+ ts && fs.appendFileSync(entryExportTsFile, "".concat(statement.replace('.js', '.d'), "\n"));
42
48
  }
43
49
  } catch (_unused) {// FIXME:
44
50
  }
@@ -3,4 +3,5 @@
3
3
  * @param filePath - File to required.
4
4
  * @returns module export object.
5
5
  */
6
- export declare const compatRequire: (filePath: string) => any;
6
+ export declare const compatRequire: (filePath: string) => any;
7
+ export declare const requireExistModule: (filename: string, extensions?: string[]) => any;
@@ -17,6 +17,11 @@ export declare const HMR_SOCK_PATH = "/_modern_js_hmr_ws";
17
17
  */
18
18
 
19
19
  export declare const ROUTE_SPEC_FILE = "route.json";
20
+ /**
21
+ * main entry name
22
+ */
23
+
24
+ export declare const MAIN_ENTRY_NAME = "main";
20
25
  /**
21
26
  * open editor request path
22
27
  */
@@ -42,7 +47,18 @@ export declare const SERVER_RENDER_FUNCTION_NAME = "serverRender";
42
47
  */
43
48
 
44
49
  export declare const LOADABLE_STATS_FILE = "loadable-stats.json";
50
+ /**
51
+ * real entry generate by modern.js
52
+ */
53
+
45
54
  export declare const HIDE_MODERN_JS_DIR = "./node_modules/.modern-js";
55
+ /**
56
+ * internal specified folder
57
+ */
58
+
59
+ export declare const API_DIR = "api";
60
+ export declare const SERVER_DIR = "server";
61
+ export declare const SHARED_DIR = "shared";
46
62
  /**
47
63
  * Internal plugins that work as soon as they are installed.
48
64
  */
@@ -83,7 +99,10 @@ export declare const PLUGIN_SCHEMAS: {
83
99
  type: string;
84
100
  properties: {
85
101
  prefix: {
86
- type: string;
102
+ type: string[];
103
+ items: {
104
+ type: string;
105
+ };
87
106
  };
88
107
  fetcher: {
89
108
  type: string;
@@ -91,7 +110,7 @@ export declare const PLUGIN_SCHEMAS: {
91
110
  proxy: {
92
111
  type: string;
93
112
  };
94
- requestCreater: {
113
+ requestCreator: {
95
114
  type: string;
96
115
  };
97
116
  };
@@ -1 +1 @@
1
- export declare const getEntryOptions: <T>(name: string, baseOptions?: T | undefined, optionsByEntries?: Record<string, T> | undefined) => T | undefined;
1
+ export declare const getEntryOptions: <T>(name: string, baseOptions?: T | undefined, optionsByEntries?: Record<string, T> | undefined, packageName?: string | undefined) => T | undefined;
@@ -4,4 +4,5 @@ export declare function isArray(obj: any): obj is any[];
4
4
  export declare function isFunction(func: any): func is Function;
5
5
  export declare function isObject(obj: any): obj is object;
6
6
  export declare function isPlainObject(obj: any): obj is Record<string, any>;
7
- export declare function isPromise(obj: any): obj is Promise<any>;
7
+ export declare function isPromise(obj: any): obj is Promise<any>;
8
+ export declare function isRegExp(obj: any): obj is RegExp;
@@ -1 +1,6 @@
1
- export declare const prettyInstructions: (appContext: any, config: any) => string;
1
+ interface EntryPoint {
2
+ entryName: string;
3
+ }
4
+ export declare const isSingleEntry: (entrypoints: EntryPoint[]) => boolean;
5
+ export declare const prettyInstructions: (appContext: any, config: any) => string;
6
+ export {};
@@ -1,4 +1,4 @@
1
- export declare const createRuntimeExportsUtils: (pwd: string, namespace: string) => {
1
+ export declare const createRuntimeExportsUtils: (pwd: any, namespace: string, ts?: any) => {
2
2
  addExport: (statement: string) => void;
3
3
  getPath: () => string;
4
4
  };
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.0.1",
14
+ "version": "1.1.3",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -65,8 +65,8 @@
65
65
  "@types/recursive-readdir": "^2.2.0",
66
66
  "typescript": "^4",
67
67
  "webpack": "^5.54.0",
68
- "@modern-js/plugin-testing": "^1.0.2",
69
- "@modern-js/module-tools": "^1.0.2"
68
+ "@modern-js/plugin-testing": "^1.1.1",
69
+ "@modern-js/module-tools": "^1.1.1"
70
70
  },
71
71
  "peerDependencies": {
72
72
  "typescript": "^4.4.3"
@@ -18,7 +18,7 @@ import filesize from 'filesize';
18
18
  import recursive from 'recursive-readdir';
19
19
  import stripAnsi from 'strip-ansi';
20
20
  import gzipSize from 'gzip-size';
21
- import { logger } from '.';
21
+ import { logger } from './logger';
22
22
 
23
23
 
24
24
  function canReadAsset(asset:string) {
@@ -1,4 +1,5 @@
1
- import { isFunction, logger, isPlainObject } from '.';
1
+ // eslint-disable-next-line import/no-useless-path-segments
2
+ import { isFunction, logger, isPlainObject } from './index';
2
3
 
3
4
  export const applyOptionsChain = <T, U>(
4
5
  defaults: T,
@@ -1,3 +1,5 @@
1
+ import { findExists } from './findExists';
2
+
1
3
  /**
2
4
  * Require function compatible with esm and cjs module.
3
5
  * @param filePath - File to required.
@@ -8,3 +10,16 @@ export const compatRequire = (filePath: string) => {
8
10
 
9
11
  return mod?.__esModule ? mod.default : mod;
10
12
  };
13
+
14
+ export const requireExistModule = (
15
+ filename: string,
16
+ extensions = ['.ts', '.js'],
17
+ ) => {
18
+ const exist = findExists(extensions.map(ext => `${filename}${ext}`));
19
+
20
+ if (!exist) {
21
+ return null;
22
+ }
23
+
24
+ return compatRequire(exist);
25
+ };
package/src/constants.ts CHANGED
@@ -18,6 +18,11 @@ export const HMR_SOCK_PATH = '/_modern_js_hmr_ws';
18
18
  */
19
19
  export const ROUTE_SPEC_FILE = 'route.json';
20
20
 
21
+ /**
22
+ * main entry name
23
+ */
24
+ export const MAIN_ENTRY_NAME = 'main';
25
+
21
26
  /**
22
27
  * open editor request path
23
28
  */
@@ -43,8 +48,20 @@ export const SERVER_RENDER_FUNCTION_NAME = 'serverRender';
43
48
  */
44
49
  export const LOADABLE_STATS_FILE = 'loadable-stats.json';
45
50
 
51
+ /**
52
+ * real entry generate by modern.js
53
+ */
46
54
  export const HIDE_MODERN_JS_DIR = './node_modules/.modern-js';
47
55
 
56
+ /**
57
+ * internal specified folder
58
+ */
59
+ export const API_DIR = 'api';
60
+
61
+ export const SERVER_DIR = 'server';
62
+
63
+ export const SHARED_DIR = 'shared';
64
+
48
65
  /**
49
66
  * Internal plugins that work as soon as they are installed.
50
67
  */
@@ -86,11 +103,23 @@ export const INTERNAL_PLUGINS: {
86
103
  },
87
104
  '@modern-js/plugin-unbundle': { cli: '@modern-js/plugin-unbundle' },
88
105
  '@modern-js/plugin-server-build': { cli: '@modern-js/plugin-server-build' },
106
+ '@modern-js/plugin-server': {
107
+ cli: '@modern-js/plugin-server/cli',
108
+ server: '@modern-js/plugin-server/server',
109
+ },
89
110
  '@modern-js/plugin-micro-frontend': {
90
111
  cli: '@modern-js/plugin-micro-frontend/cli',
91
112
  },
92
113
  '@modern-js/plugin-jarvis': { cli: '@modern-js/plugin-jarvis/cli' },
93
114
  '@modern-js/plugin-tailwindcss': { cli: '@modern-js/plugin-tailwindcss/cli' },
115
+ '@modern-js/plugin-lambda-fc': { cli: '@modern-js/plugin-lambda-fc/cli' },
116
+ '@modern-js/plugin-lambda-scf': { cli: '@modern-js/plugin-lambda-scf/cli' },
117
+ '@modern-js/plugin-cdn-oss': { cli: '@modern-js/plugin-cdn-oss/cli' },
118
+ '@modern-js/plugin-cdn-cos': { cli: '@modern-js/plugin-cdn-cos/cli' },
119
+ '@modern-js/plugin-static-hosting': {
120
+ cli: '@modern-js/plugin-static-hosting/cli',
121
+ },
122
+ '@modern-js/plugin-polyfill': { server: '@modern-js/plugin-polyfill' },
94
123
  };
95
124
 
96
125
  /**
@@ -120,10 +149,13 @@ export const PLUGIN_SCHEMAS = {
120
149
  schema: {
121
150
  type: 'object',
122
151
  properties: {
123
- prefix: { type: 'string' },
152
+ prefix: {
153
+ type: ['string', 'array'],
154
+ items: { type: 'string' },
155
+ },
124
156
  fetcher: { type: 'string' },
125
157
  proxy: { type: 'object' },
126
- requestCreater: { type: 'string' },
158
+ requestCreator: { type: 'string' },
127
159
  },
128
160
  },
129
161
  },
@@ -175,7 +207,13 @@ export const PLUGIN_SCHEMAS = {
175
207
  '@modern-js/plugin-ssg': [
176
208
  {
177
209
  target: 'output.ssg',
178
- schema: { oneOf: [{ type: 'boolean' }, { instanceof: 'Function' }] },
210
+ schema: {
211
+ oneOf: [
212
+ { type: 'boolean' },
213
+ { type: 'object' },
214
+ { instanceof: 'Function' },
215
+ ],
216
+ },
179
217
  },
180
218
  ],
181
219
  '@modern-js/plugin-ssr': [
@@ -1,18 +1,37 @@
1
1
  import { isPlainObject } from './is';
2
+ import { MAIN_ENTRY_NAME } from './constants';
2
3
 
3
4
  export const getEntryOptions = <T>(
4
5
  name: string,
5
6
  baseOptions?: T,
6
7
  optionsByEntries?: Record<string, T>,
8
+ packageName?: string,
7
9
  ) => {
8
10
  if (optionsByEntries) {
11
+ let optionsByEntry = getOptionsByEntryName(name, optionsByEntries);
12
+
13
+ // compatible with main entry using packageName as the key
14
+ if (
15
+ optionsByEntry === undefined &&
16
+ name === MAIN_ENTRY_NAME &&
17
+ packageName
18
+ ) {
19
+ optionsByEntry = getOptionsByEntryName(packageName, optionsByEntries);
20
+ }
21
+
9
22
  // eslint-disable-next-line no-nested-ternary
10
- return optionsByEntries.hasOwnProperty(name)
11
- ? isPlainObject(optionsByEntries[name]) && isPlainObject(baseOptions)
12
- ? { ...baseOptions, ...optionsByEntries[name] }
13
- : optionsByEntries[name]
23
+ return optionsByEntry !== undefined
24
+ ? isPlainObject(optionsByEntry) && isPlainObject(baseOptions)
25
+ ? { ...baseOptions, ...optionsByEntry }
26
+ : optionsByEntry
14
27
  : baseOptions;
15
28
  } else {
16
29
  return baseOptions;
17
30
  }
18
31
  };
32
+
33
+ const getOptionsByEntryName = <T>(
34
+ name: string,
35
+ optionsByEntries: Record<string, T>,
36
+ ) =>
37
+ optionsByEntries.hasOwnProperty(name) ? optionsByEntries[name] : undefined;
package/src/is/type.ts CHANGED
@@ -37,3 +37,7 @@ export function isPromise(obj: any): obj is Promise<any> {
37
37
  );
38
38
  /* eslint-enable promise/prefer-await-to-then */
39
39
  }
40
+
41
+ export function isRegExp(obj: any): obj is RegExp {
42
+ return Object.prototype.toString.call(obj) === '[object RegExp]';
43
+ }
@@ -14,7 +14,7 @@ interface ServerRoute {
14
14
  }
15
15
 
16
16
  // TODO: remove hard code 'main'
17
- const isSPA = (entrypoints: EntryPoint[]) =>
17
+ export const isSingleEntry = (entrypoints: EntryPoint[]) =>
18
18
  entrypoints.length === 1 && entrypoints[0].entryName === 'main';
19
19
 
20
20
  const normalizeUrl = (url: string) => url.replace(/([^:]\/)\/+/g, '$1');
@@ -62,7 +62,7 @@ export const prettyInstructions = (appContext: any, config: any) => {
62
62
 
63
63
  let message = 'App running at:\n\n';
64
64
 
65
- if (isSPA(entrypoints)) {
65
+ if (isSingleEntry(entrypoints)) {
66
66
  message += urls
67
67
  .map(
68
68
  ({ type, url }) =>
@@ -21,11 +21,15 @@ const memo = <T extends (...args: any[]) => any>(fn: T) => {
21
21
  };
22
22
 
23
23
  export const createRuntimeExportsUtils = memo(
24
- (pwd: string, namespace: string) => {
24
+ (pwd = '', namespace: string, ts = false) => {
25
25
  const entryExportFile = path.join(
26
26
  pwd,
27
27
  `.runtime-exports/${namespace ? `${namespace}.js` : 'index.js'}`,
28
28
  );
29
+ const entryExportTsFile = path.join(
30
+ pwd,
31
+ `.runtime-exports/${namespace ? `${namespace}.d.ts` : 'index.d.ts'}`,
32
+ );
29
33
 
30
34
  // const ensure = () => {
31
35
  // if (!fs.existsSync(entryExportFile)) {
@@ -39,8 +43,15 @@ export const createRuntimeExportsUtils = memo(
39
43
  statement = normalizeOutputPath(statement);
40
44
  try {
41
45
  fs.ensureFileSync(entryExportFile);
46
+ fs.ensureFileSync(entryExportTsFile);
47
+
42
48
  if (!fs.readFileSync(entryExportFile, 'utf8').includes(statement)) {
43
49
  fs.appendFileSync(entryExportFile, `${statement}\n`);
50
+ ts &&
51
+ fs.appendFileSync(
52
+ entryExportTsFile,
53
+ `${statement.replace('.js', '.d')}\n`,
54
+ );
44
55
  }
45
56
  } catch {
46
57
  // FIXME:
@@ -1,13 +1,16 @@
1
+ import path from 'path';
1
2
  import { ensureAbsolutePath } from '@/ensureAbsolutePath';
2
3
 
3
4
  describe('ensure absolute file path', () => {
4
5
  test('should return filePath directly', () => {
5
- expect(ensureAbsolutePath('/a/b', '/a/b/c/d/e.jsx')).toEqual(
6
- '/a/b/c/d/e.jsx',
7
- );
6
+ expect(
7
+ path.isAbsolute(ensureAbsolutePath('/a/b', '/a/b/c/d/e.jsx')),
8
+ ).toBeTruthy();
8
9
  });
9
10
 
10
11
  test(`should resolve absolute path`, () => {
11
- expect(ensureAbsolutePath('/a/b', 'c/d/e.jsx')).toEqual('/a/b/c/d/e.jsx');
12
+ expect(
13
+ path.isAbsolute(ensureAbsolutePath('/a/b', 'c/d/e.jsx')),
14
+ ).toBeTruthy();
12
15
  });
13
16
  });
@@ -15,6 +15,17 @@ describe('get entry options', () => {
15
15
  ).toEqual('a');
16
16
  });
17
17
 
18
+ test(`should compatible with main entry using packageName as key`, () => {
19
+ expect(
20
+ getEntryOptions(
21
+ 'main',
22
+ 'default value',
23
+ { 'package-name': 'a' },
24
+ 'package-name',
25
+ ),
26
+ ).toEqual('a');
27
+ });
28
+
18
29
  expect(
19
30
  getEntryOptions(
20
31
  'page-a',