@modern-js/utils 1.0.0 → 1.1.2

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 (77) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +1 -4
  3. package/dist/js/modern/FileSizeReporter.js +2 -2
  4. package/dist/js/modern/alias.js +1 -1
  5. package/dist/js/modern/applyOptionsChain.js +2 -1
  6. package/dist/js/modern/constants.js +25 -0
  7. package/dist/js/modern/ensureAbsolutePath.js +1 -1
  8. package/dist/js/modern/getEntryOptions.js +13 -4
  9. package/dist/js/modern/getPackageManager.js +1 -1
  10. package/dist/js/modern/index.js +1 -5
  11. package/dist/js/modern/is/index.js +1 -1
  12. package/dist/js/modern/is/type.js +3 -0
  13. package/dist/js/modern/monorepo.js +1 -1
  14. package/dist/js/modern/path.js +2 -13
  15. package/dist/js/modern/prettyInstructions.js +2 -2
  16. package/dist/js/modern/readTsConfig.js +1 -1
  17. package/dist/js/modern/runtimeExports.js +6 -2
  18. package/dist/js/node/FileSizeReporter.js +13 -17
  19. package/dist/js/node/alias.js +3 -7
  20. package/dist/js/node/applyOptionsChain.js +6 -5
  21. package/dist/js/node/constants.js +28 -2
  22. package/dist/js/node/ensureAbsolutePath.js +3 -5
  23. package/dist/js/node/getEntryOptions.js +14 -4
  24. package/dist/js/node/getPackageManager.js +6 -10
  25. package/dist/js/node/index.js +13 -17
  26. package/dist/js/node/is/index.js +3 -7
  27. package/dist/js/node/is/type.js +5 -0
  28. package/dist/js/node/monorepo.js +13 -17
  29. package/dist/js/node/path.js +5 -37
  30. package/dist/js/node/prettyInstructions.js +5 -3
  31. package/dist/js/node/readTsConfig.js +4 -6
  32. package/dist/js/node/runtimeExports.js +9 -7
  33. package/dist/js/treeshaking/FileSizeReporter.js +2 -2
  34. package/dist/js/treeshaking/alias.js +1 -1
  35. package/dist/js/treeshaking/applyOptionsChain.js +2 -1
  36. package/dist/js/treeshaking/constants.js +25 -0
  37. package/dist/js/treeshaking/ensureAbsolutePath.js +1 -1
  38. package/dist/js/treeshaking/getEntryOptions.js +14 -3
  39. package/dist/js/treeshaking/getPackageManager.js +1 -1
  40. package/dist/js/treeshaking/index.js +1 -5
  41. package/dist/js/treeshaking/is/index.js +1 -1
  42. package/dist/js/treeshaking/is/type.js +3 -0
  43. package/dist/js/treeshaking/monorepo.js +1 -1
  44. package/dist/js/treeshaking/path.js +4 -26
  45. package/dist/js/treeshaking/prettyInstructions.js +2 -2
  46. package/dist/js/treeshaking/readTsConfig.js +1 -1
  47. package/dist/js/treeshaking/runtimeExports.js +8 -2
  48. package/dist/types/constants.d.ts +5 -0
  49. package/dist/types/getEntryOptions.d.ts +1 -1
  50. package/dist/types/index.d.ts +1 -3
  51. package/dist/types/is/type.d.ts +2 -1
  52. package/dist/types/monorepo.d.ts +1 -1
  53. package/dist/types/path.d.ts +2 -11
  54. package/dist/types/prettyInstructions.d.ts +6 -1
  55. package/dist/types/runtimeExports.d.ts +1 -1
  56. package/package.json +3 -3
  57. package/src/FileSizeReporter.ts +2 -2
  58. package/src/alias.ts +1 -1
  59. package/src/applyOptionsChain.ts +2 -1
  60. package/src/constants.ts +20 -1
  61. package/src/ensureAbsolutePath.ts +1 -1
  62. package/src/getEntryOptions.ts +23 -4
  63. package/src/getPackageManager.ts +1 -1
  64. package/src/index.ts +1 -3
  65. package/src/is/index.ts +1 -1
  66. package/src/is/type.ts +4 -0
  67. package/src/monorepo.ts +1 -1
  68. package/src/path.ts +3 -21
  69. package/src/prettyInstructions.ts +2 -2
  70. package/src/readTsConfig.ts +1 -1
  71. package/src/runtimeExports.ts +32 -31
  72. package/tests/.eslintrc.js +6 -0
  73. package/tests/compatRequire.test.ts +1 -1
  74. package/tests/ensureAbsolutePath.test.ts +7 -4
  75. package/tests/findExists.test.ts +1 -1
  76. package/tests/getBrowserslist.test.ts +1 -1
  77. package/tests/getEntryOptions.test.ts +11 -0
@@ -4,28 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  var _exportNames = {
7
- fs: true,
8
- upath: true,
9
- isRelativePath: true,
10
- path: true
7
+ fs: true
11
8
  };
12
9
  exports.fs = void 0;
13
- Object.defineProperty(exports, "isRelativePath", {
14
- enumerable: true,
15
- get: function () {
16
- return _path.isRelativePath;
17
- }
18
- });
19
- exports.upath = exports.path = void 0;
20
10
 
21
11
  var _fs = _interopRequireWildcard(require("fs-extra"));
22
12
 
23
13
  exports.fs = _fs;
24
14
 
25
- var _upath = _interopRequireWildcard(require("upath"));
26
-
27
- exports.upath = _upath;
28
-
29
15
  var _chalk = require("./chalk");
30
16
 
31
17
  Object.keys(_chalk).forEach(function (key) {
@@ -348,9 +334,19 @@ Object.keys(_readTsConfig).forEach(function (key) {
348
334
  });
349
335
  });
350
336
 
351
- var _path = _interopRequireWildcard(require("./path"));
337
+ var _path = require("./path");
352
338
 
353
- exports.path = _path;
339
+ Object.keys(_path).forEach(function (key) {
340
+ if (key === "default" || key === "__esModule") return;
341
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
342
+ if (key in exports && exports[key] === _path[key]) return;
343
+ Object.defineProperty(exports, key, {
344
+ enumerable: true,
345
+ get: function () {
346
+ return _path[key];
347
+ }
348
+ });
349
+ });
354
350
 
355
351
  var _generateMetaTags = require("./generateMetaTags");
356
352
 
@@ -15,7 +15,7 @@ exports.isUseSSRBundle = exports.isTypescript = exports.isSSR = exports.isFastRe
15
15
 
16
16
  var _fs = _interopRequireDefault(require("fs"));
17
17
 
18
- var path = _interopRequireWildcard(require("../path"));
18
+ var _path = _interopRequireDefault(require("path"));
19
19
 
20
20
  var _nodeEnv = require("./node-env");
21
21
 
@@ -59,10 +59,6 @@ Object.keys(_type).forEach(function (key) {
59
59
  });
60
60
  });
61
61
 
62
- 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); }
63
-
64
- 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; }
65
-
66
62
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
67
63
 
68
64
  /**
@@ -73,7 +69,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
73
69
  * @returns True if the name is in dependencies or devDependencies, false otherwise.
74
70
  */
75
71
  const isDepExists = (appDirectory, name) => {
76
- const json = require(path.resolve(appDirectory, './package.json'));
72
+ const json = require(_path.default.resolve(appDirectory, './package.json'));
77
73
 
78
74
  const {
79
75
  dependencies = {},
@@ -91,7 +87,7 @@ const isDepExists = (appDirectory, name) => {
91
87
 
92
88
  exports.isDepExists = isDepExists;
93
89
 
94
- const isTypescript = root => _fs.default.existsSync(path.resolve(root, './tsconfig.json'));
90
+ const isTypescript = root => _fs.default.existsSync(_path.default.resolve(root, './tsconfig.json'));
95
91
  /**
96
92
  * Is Empty object
97
93
  *
@@ -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
  }
@@ -7,16 +7,12 @@ exports.isYarnWorkspaces = exports.isPnpmWorkspaces = exports.isMonorepo = expor
7
7
 
8
8
  var _fs = _interopRequireDefault(require("fs"));
9
9
 
10
+ var _path = _interopRequireDefault(require("path"));
11
+
10
12
  var _glob = _interopRequireDefault(require("glob"));
11
13
 
12
14
  var _yaml = _interopRequireDefault(require("yaml"));
13
15
 
14
- var path = _interopRequireWildcard(require("./path"));
15
-
16
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
-
18
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
-
20
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
17
 
22
18
  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; }
@@ -32,14 +28,14 @@ const WOKRSPACES_FILES = {
32
28
  LERNA: 'lerna.json'
33
29
  };
34
30
 
35
- const isLerna = root => _fs.default.existsSync(path.join(root, WOKRSPACES_FILES.LERNA));
31
+ const isLerna = root => _fs.default.existsSync(_path.default.join(root, WOKRSPACES_FILES.LERNA));
36
32
 
37
33
  exports.isLerna = isLerna;
38
34
 
39
35
  const isYarnWorkspaces = root => {
40
36
  var _json$workspaces;
41
37
 
42
- const pkg = path.join(root, WOKRSPACES_FILES.YARN);
38
+ const pkg = _path.default.join(root, WOKRSPACES_FILES.YARN);
43
39
 
44
40
  if (!_fs.default.existsSync(pkg)) {
45
41
  return false;
@@ -51,7 +47,7 @@ const isYarnWorkspaces = root => {
51
47
 
52
48
  exports.isYarnWorkspaces = isYarnWorkspaces;
53
49
 
54
- const isPnpmWorkspaces = root => _fs.default.existsSync(path.join(root, WOKRSPACES_FILES.PNPM));
50
+ const isPnpmWorkspaces = root => _fs.default.existsSync(_path.default.join(root, WOKRSPACES_FILES.PNPM));
55
51
 
56
52
  exports.isPnpmWorkspaces = isPnpmWorkspaces;
57
53
 
@@ -60,7 +56,7 @@ const isMonorepo = root => isLerna(root) || isYarnWorkspaces(root) || isPnpmWork
60
56
  exports.isMonorepo = isMonorepo;
61
57
 
62
58
  const isModernjsMonorepo = root => {
63
- const json = JSON.parse(_fs.default.readFileSync(path.join(root, 'package.json'), 'utf8'));
59
+ const json = JSON.parse(_fs.default.readFileSync(_path.default.join(root, 'package.json'), 'utf8'));
64
60
 
65
61
  const deps = _objectSpread(_objectSpread({}, json.dependencies || {}), json.devDependencies || {});
66
62
 
@@ -79,7 +75,7 @@ const findMonorepoRoot = (appDirectory, maxDepth = PACKAGE_MAX_DEPTH) => {
79
75
  } // eslint-disable-next-line no-param-reassign
80
76
 
81
77
 
82
- appDirectory = path.dirname(appDirectory);
78
+ appDirectory = _path.default.dirname(appDirectory);
83
79
  }
84
80
 
85
81
  return inMonorepo ? appDirectory : undefined;
@@ -91,28 +87,28 @@ const getMonorepoPackages = root => {
91
87
  let packages = [];
92
88
 
93
89
  if (isYarnWorkspaces(root)) {
94
- const json = JSON.parse(_fs.default.readFileSync(path.join(root, 'package.json'), 'utf8'));
90
+ const json = JSON.parse(_fs.default.readFileSync(_path.default.join(root, 'package.json'), 'utf8'));
95
91
  ({
96
92
  packages
97
93
  } = json.workspaces);
98
94
  } else if (isLerna(root)) {
99
- const json = JSON.parse(_fs.default.readFileSync(path.resolve(root, 'lerna.json'), 'utf8'));
95
+ const json = JSON.parse(_fs.default.readFileSync(_path.default.resolve(root, 'lerna.json'), 'utf8'));
100
96
  ({
101
97
  packages
102
98
  } = json);
103
99
  } else {
104
100
  ({
105
101
  packages
106
- } = _yaml.default.parse(_fs.default.readFileSync(path.join(root, WOKRSPACES_FILES.PNPM), 'utf8')));
102
+ } = _yaml.default.parse(_fs.default.readFileSync(_path.default.join(root, WOKRSPACES_FILES.PNPM), 'utf8')));
107
103
  }
108
104
 
109
105
  if (packages) {
110
106
  return packages.map(name => // The trailing / ensures only dirs are picked up
111
- _glob.default.sync(path.join(root, `${name}/`), {
107
+ _glob.default.sync(_path.default.join(root, `${name}/`), {
112
108
  ignore: ['**/node_modules/**']
113
- })).flat().filter(filepath => _fs.default.existsSync(path.resolve(filepath, 'package.json'))).map(filepath => ({
109
+ })).flat().filter(filepath => _fs.default.existsSync(_path.default.resolve(filepath, 'package.json'))).map(filepath => ({
114
110
  path: filepath,
115
- name: JSON.parse(_fs.default.readFileSync(path.resolve(filepath, 'package.json'), 'utf8')).name
111
+ name: JSON.parse(_fs.default.readFileSync(_path.default.resolve(filepath, 'package.json'), 'utf8')).name
116
112
  }));
117
113
  }
118
114
 
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.win32 = exports.sep = exports.resolve = exports.relative = exports.posix = exports.normalize = exports.join = exports.isRelativePath = exports.isAbsolute = exports.extname = exports.dirname = exports.basename = void 0;
6
+ exports.normalizeToPosixPath = exports.normalizeOutputPath = exports.isRelativePath = void 0;
7
7
 
8
8
  var _path = _interopRequireDefault(require("path"));
9
9
 
@@ -15,42 +15,10 @@ const isRelativePath = test => /^\.\.?($|[\\/])/.test(test);
15
15
 
16
16
  exports.isRelativePath = isRelativePath;
17
17
 
18
- const join = (...paths) => _upath.default.normalizeSafe(_path.default.join(...paths));
18
+ const normalizeOutputPath = s => s.replace(/\\/g, '\\\\');
19
19
 
20
- exports.join = join;
20
+ exports.normalizeOutputPath = normalizeOutputPath;
21
21
 
22
- const resolve = (...paths) => _upath.default.normalizeSafe(_path.default.resolve(...paths));
22
+ const normalizeToPosixPath = p => _upath.default.normalizeSafe(_path.default.normalize(p));
23
23
 
24
- exports.resolve = resolve;
25
-
26
- const relative = (from, to) => _upath.default.normalizeSafe(_path.default.relative(from, to));
27
-
28
- exports.relative = relative;
29
-
30
- const basename = (p, ext) => _upath.default.normalizeSafe(_path.default.basename(p, ext));
31
-
32
- exports.basename = basename;
33
-
34
- const dirname = p => _upath.default.normalizeSafe(_path.default.dirname(p));
35
-
36
- exports.dirname = dirname;
37
-
38
- const extname = p => _path.default.extname(p);
39
-
40
- exports.extname = extname;
41
-
42
- const isAbsolute = p => _path.default.isAbsolute(p);
43
-
44
- exports.isAbsolute = isAbsolute;
45
-
46
- const normalize = p => _upath.default.normalizeSafe(_path.default.normalize(p));
47
-
48
- exports.normalize = normalize;
49
- const {
50
- sep,
51
- win32,
52
- posix
53
- } = _path.default;
54
- exports.posix = posix;
55
- exports.win32 = win32;
56
- exports.sep = sep;
24
+ exports.normalizeToPosixPath = normalizeToPosixPath;
@@ -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
@@ -5,17 +5,15 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.readTsConfigByFile = exports.readTsConfig = void 0;
7
7
 
8
- var path = _interopRequireWildcard(require("./path"));
8
+ var _path = _interopRequireDefault(require("path"));
9
9
 
10
- 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); }
11
-
12
- 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; }
10
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
11
 
14
12
  const readTsConfig = root => {
15
13
  // import typescript from 'typescript' cause eslint fromat error.
16
14
  const typescript = require('typescript');
17
15
 
18
- return typescript.readConfigFile(path.resolve(root, './tsconfig.json'), typescript.sys.readFile).config;
16
+ return typescript.readConfigFile(_path.default.resolve(root, './tsconfig.json'), typescript.sys.readFile).config;
19
17
  };
20
18
 
21
19
  exports.readTsConfig = readTsConfig;
@@ -24,7 +22,7 @@ const readTsConfigByFile = filename => {
24
22
  // import typescript from 'typescript' cause eslint fromat error.
25
23
  const typescript = require('typescript');
26
24
 
27
- return typescript.readConfigFile(path.resolve(filename), typescript.sys.readFile).config;
25
+ return typescript.readConfigFile(_path.default.resolve(filename), typescript.sys.readFile).config;
28
26
  };
29
27
 
30
28
  exports.readTsConfigByFile = readTsConfigByFile;
@@ -5,13 +5,11 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.createRuntimeExportsUtils = void 0;
7
7
 
8
- var _fsExtra = _interopRequireDefault(require("fs-extra"));
9
-
10
- var path = _interopRequireWildcard(require("./path"));
8
+ var _path = _interopRequireDefault(require("path"));
11
9
 
12
- 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); }
10
+ var _fsExtra = _interopRequireDefault(require("fs-extra"));
13
11
 
14
- 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; }
12
+ var _path2 = require("./path");
15
13
 
16
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
15
 
@@ -31,15 +29,19 @@ const memo = fn => {
31
29
  };
32
30
  };
33
31
 
34
- const createRuntimeExportsUtils = memo((pwd, namespace) => {
35
- const entryExportFile = path.join(pwd, `.runtime-exports/${namespace ? `${namespace}.js` : 'index.js'}`); // const ensure = () => {
32
+ const createRuntimeExportsUtils = memo((pwd = '', namespace) => {
33
+ const entryExportFile = _path.default.join(pwd, `.runtime-exports/${namespace ? `${namespace}.js` : 'index.js'}`); // const ensure = () => {
36
34
  // if (!fs.existsSync(entryExportFile)) {
37
35
  // fs.outputFileSync(entryExportFile, '');
38
36
  // }
39
37
  // fs.ensureFileSync(entryExportFile);
40
38
  // };
41
39
 
40
+
42
41
  const addExport = statement => {
42
+ // eslint-disable-next-line no-param-reassign
43
+ statement = (0, _path2.normalizeOutputPath)(statement);
44
+
43
45
  try {
44
46
  _fsExtra.default.ensureFileSync(entryExportFile);
45
47
 
@@ -25,13 +25,13 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
25
25
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
26
26
 
27
27
  import fs from 'fs';
28
- import * as path from "./path";
28
+ import path from 'path';
29
29
  import chalk from 'chalk';
30
30
  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);
@@ -5,8 +5,8 @@ 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 fs from 'fs';
8
+ import path from 'path';
8
9
  import chalk from 'chalk';
9
- import * as path from "./path";
10
10
  import { readTsConfigByFile } from "./readTsConfig";
11
11
  import { applyOptionsChain } from "./applyOptionsChain";
12
12
  export var validAlias = function validAlias(modernConfig, _ref) {
@@ -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
 
@@ -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
  */
@@ -123,6 +128,24 @@ export var INTERNAL_PLUGINS = {
123
128
  },
124
129
  '@modern-js/plugin-tailwindcss': {
125
130
  cli: '@modern-js/plugin-tailwindcss/cli'
131
+ },
132
+ '@modern-js/plugin-lambda-fc': {
133
+ cli: '@modern-js/plugin-lambda-fc/cli'
134
+ },
135
+ '@modern-js/plugin-lambda-scf': {
136
+ cli: '@modern-js/plugin-lambda-scf/cli'
137
+ },
138
+ '@modern-js/plugin-cdn-oss': {
139
+ cli: '@modern-js/plugin-cdn-oss/cli'
140
+ },
141
+ '@modern-js/plugin-cdn-cos': {
142
+ cli: '@modern-js/plugin-cdn-cos/cli'
143
+ },
144
+ '@modern-js/plugin-static-hosting': {
145
+ cli: '@modern-js/plugin-static-hosting/cli'
146
+ },
147
+ '@modern-js/plugin-polyfill': {
148
+ server: '@modern-js/plugin-polyfill'
126
149
  }
127
150
  };
128
151
  /**
@@ -217,6 +240,8 @@ export var PLUGIN_SCHEMAS = {
217
240
  schema: {
218
241
  oneOf: [{
219
242
  type: 'boolean'
243
+ }, {
244
+ type: 'object'
220
245
  }, {
221
246
  "instanceof": 'Function'
222
247
  }]
@@ -1,4 +1,4 @@
1
- import * as path from "./path";
1
+ import path from 'path';
2
2
  /**
3
3
  * ensure absolute file path.
4
4
  * @param base - Base path to resolve relative from.
@@ -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
  };
@@ -1,6 +1,6 @@
1
1
  import os from 'os';
2
+ import path from 'path';
2
3
  import fs from 'fs-extra';
3
- import * as path from "./path";
4
4
  export function getPackageManager() {
5
5
  var cwd = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : process.cwd();
6
6
  var appDirectory = cwd;
@@ -1,7 +1,5 @@
1
1
  import * as _fs from 'fs-extra';
2
2
  export { _fs as fs };
3
- import * as _upath from 'upath';
4
- export { _upath as upath };
5
3
  export * from "./chalk";
6
4
  export * from "./formatWebpackMessages";
7
5
  export * from "./FileSizeReporter";
@@ -25,9 +23,7 @@ export * from "./monorepo";
25
23
  export * from "./getPackageManager";
26
24
  export * from "./runtimeExports";
27
25
  export * from "./readTsConfig";
28
- export { isRelativePath } from "./path";
29
- import * as _path from "./path";
30
- export { _path as path };
26
+ export * from "./path";
31
27
  export * from "./generateMetaTags";
32
28
  export * from "./prettyInstructions";
33
29
  export * from "./alias";
@@ -1,5 +1,5 @@
1
1
  import fs from 'fs';
2
- import * as path from "../path";
2
+ import path from 'path';
3
3
  import { isDev } from "./node-env";
4
4
  /**
5
5
  * Check if the package name is in dependencies or devDependencies.
@@ -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
  }
@@ -5,9 +5,9 @@ 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 fs from 'fs';
8
+ import path from 'path';
8
9
  import glob from 'glob';
9
10
  import yaml from 'yaml';
10
- import * as path from "./path";
11
11
  var PACKAGE_MAX_DEPTH = 5;
12
12
  var WOKRSPACES_FILES = {
13
13
  YARN: 'package.json',
@@ -3,31 +3,9 @@ import upath from 'upath';
3
3
  export var isRelativePath = function isRelativePath(test) {
4
4
  return /^\.\.?($|[\\/])/.test(test);
5
5
  };
6
- export var join = function join() {
7
- return upath.normalizeSafe(path.join.apply(path, arguments));
6
+ export var normalizeOutputPath = function normalizeOutputPath(s) {
7
+ return s.replace(/\\/g, '\\\\');
8
8
  };
9
- export var resolve = function resolve() {
10
- return upath.normalizeSafe(path.resolve.apply(path, arguments));
11
- };
12
- export var relative = function relative(from, to) {
13
- return upath.normalizeSafe(path.relative(from, to));
14
- };
15
- export var basename = function basename(p, ext) {
16
- return upath.normalizeSafe(path.basename(p, ext));
17
- };
18
- export var dirname = function dirname(p) {
19
- return upath.normalizeSafe(path.dirname(p));
20
- };
21
- export var extname = function extname(p) {
22
- return path.extname(p);
23
- };
24
- export var isAbsolute = function isAbsolute(p) {
25
- return path.isAbsolute(p);
26
- };
27
- export var normalize = function normalize(p) {
9
+ export var normalizeToPosixPath = function normalizeToPosixPath(p) {
28
10
  return upath.normalizeSafe(path.normalize(p));
29
- };
30
- var sep = path.sep,
31
- win32 = path.win32,
32
- posix = path.posix;
33
- export { sep, win32, posix };
11
+ };
@@ -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;
@@ -1,4 +1,4 @@
1
- import * as path from "./path";
1
+ import path from 'path';
2
2
  export var readTsConfig = function readTsConfig(root) {
3
3
  // import typescript from 'typescript' cause eslint fromat error.
4
4
  var typescript = require('typescript');
@@ -1,5 +1,6 @@
1
+ import path from 'path';
1
2
  import fs from 'fs-extra';
2
- import * as path from "./path";
3
+ import { normalizeOutputPath } from "./path";
3
4
 
4
5
  var memo = function memo(fn) {
5
6
  var cache = new Map();
@@ -21,7 +22,9 @@ var memo = function memo(fn) {
21
22
  };
22
23
  };
23
24
 
24
- export var createRuntimeExportsUtils = memo(function (pwd, namespace) {
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;
25
28
  var entryExportFile = path.join(pwd, ".runtime-exports/".concat(namespace ? "".concat(namespace, ".js") : 'index.js')); // const ensure = () => {
26
29
  // if (!fs.existsSync(entryExportFile)) {
27
30
  // fs.outputFileSync(entryExportFile, '');
@@ -30,6 +33,9 @@ export var createRuntimeExportsUtils = memo(function (pwd, namespace) {
30
33
  // };
31
34
 
32
35
  var addExport = function addExport(statement) {
36
+ // eslint-disable-next-line no-param-reassign
37
+ statement = normalizeOutputPath(statement);
38
+
33
39
  try {
34
40
  fs.ensureFileSync(entryExportFile);
35
41
 
@@ -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
  */
@@ -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;