@modern-js/utils 1.1.3 → 1.1.6-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/js/modern/alias.js +10 -10
  3. package/dist/js/modern/constants.js +8 -1
  4. package/dist/js/modern/getEntryOptions.js +2 -2
  5. package/dist/js/modern/getPackageManager.js +15 -2
  6. package/dist/js/modern/index.js +2 -1
  7. package/dist/js/modern/logger.js +2 -2
  8. package/dist/js/modern/monorepo.js +2 -2
  9. package/dist/js/modern/nodeEnv.js +31 -0
  10. package/dist/js/modern/watch.js +1 -1
  11. package/dist/js/node/alias.js +10 -10
  12. package/dist/js/node/constants.js +8 -1
  13. package/dist/js/node/getEntryOptions.js +2 -2
  14. package/dist/js/node/getPackageManager.js +17 -2
  15. package/dist/js/node/index.js +14 -0
  16. package/dist/js/node/logger.js +2 -2
  17. package/dist/js/node/monorepo.js +2 -2
  18. package/dist/js/node/nodeEnv.js +45 -0
  19. package/dist/js/node/watch.js +1 -1
  20. package/dist/js/treeshaking/alias.js +9 -9
  21. package/dist/js/treeshaking/constants.js +8 -1
  22. package/dist/js/treeshaking/formatWebpackMessages.js +1 -1
  23. package/dist/js/treeshaking/getEntryOptions.js +2 -2
  24. package/dist/js/treeshaking/getPackageManager.js +91 -15
  25. package/dist/js/treeshaking/index.js +2 -1
  26. package/dist/js/treeshaking/is/type.js +1 -1
  27. package/dist/js/treeshaking/logger.js +3 -3
  28. package/dist/js/treeshaking/monorepo.js +2 -2
  29. package/dist/js/treeshaking/nodeEnv.js +108 -0
  30. package/dist/js/treeshaking/watch.js +1 -1
  31. package/dist/types/constants.d.ts +1 -0
  32. package/dist/types/getPackageManager.d.ts +1 -1
  33. package/dist/types/index.d.ts +2 -1
  34. package/dist/types/nodeEnv.d.ts +3 -0
  35. package/dist/types/watch.d.ts +1 -1
  36. package/package.json +5 -4
  37. package/src/alias.ts +7 -7
  38. package/src/constants.ts +5 -0
  39. package/src/getPackageManager.ts +12 -2
  40. package/src/index.ts +1 -0
  41. package/src/nodeEnv.ts +28 -0
  42. package/src/watch.ts +2 -2
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # @modern-js/utils
2
2
 
3
+ ## 1.1.5
4
+
5
+ ### Patch Changes
6
+
7
+ - ca7dcb32: change watch logic
8
+
9
+ ## 1.1.4
10
+
11
+ ### Patch Changes
12
+
13
+ - d927bc83: update plugins list
14
+ - d73ff455: support multi process product
15
+ - 9c1ab865: fix: filter invalid ts paths
16
+ - d73ff455: support multi process product
17
+ - d73ff455: support multi process product
18
+ - d73ff455: support multi process product
19
+ - d73ff455: support multi process product
20
+
3
21
  ## 1.1.3
4
22
 
5
23
  ### Patch Changes
@@ -1,6 +1,6 @@
1
- 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; }
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
2
 
3
- 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; }
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
4
 
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
 
@@ -63,12 +63,12 @@ export const getAlias = (aliasOption, option) => {
63
63
  }
64
64
 
65
65
  return aliasConfig;
66
- };
67
- export const getUserAlias = (alias = {}) => {
68
- const keys = Object.keys(alias);
69
- const userKeys = keys.filter(key => !key.includes('@modern-js/runtime'));
70
- return userKeys.reduce((o, k) => {
66
+ }; // filter invalid ts paths that are not array
67
+
68
+ export const getUserAlias = (alias = {}) => Object.keys(alias).reduce((o, k) => {
69
+ if (Array.isArray(alias[k])) {
71
70
  o[k] = alias[k];
72
- return o;
73
- }, {});
74
- };
71
+ }
72
+
73
+ return o;
74
+ }, {});
@@ -159,6 +159,12 @@ export const INTERNAL_PLUGINS = {
159
159
  },
160
160
  '@modern-js/plugin-polyfill': {
161
161
  server: '@modern-js/plugin-polyfill'
162
+ },
163
+ '@modern-js/plugin-multiprocess': {
164
+ cli: '@modern-js/plugin-multiprocess/cli'
165
+ },
166
+ '@modern-js/plugin-nocode': {
167
+ cli: '@modern-js/plugin-nocode/cli'
162
168
  }
163
169
  };
164
170
  /**
@@ -304,5 +310,6 @@ export const PLUGIN_SCHEMAS = {
304
310
  schema: {
305
311
  type: ['object']
306
312
  }
307
- }]
313
+ }],
314
+ '@modern-js/plugin-nocode': []
308
315
  };
@@ -1,6 +1,6 @@
1
- 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; }
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
2
 
3
- 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; }
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
4
 
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
 
@@ -1,10 +1,15 @@
1
1
  import os from 'os';
2
2
  import path from 'path';
3
3
  import fs from 'fs-extra';
4
- export function getPackageManager(cwd = process.cwd()) {
4
+ import { canUsePnpm, canUseYarn } from "./nodeEnv";
5
+ const MAX_TIMES = 5;
6
+ export async function getPackageManager(cwd = process.cwd()) {
5
7
  let appDirectory = cwd;
8
+ let times = 0;
9
+
10
+ while (os.homedir() !== appDirectory && times < MAX_TIMES) {
11
+ times++;
6
12
 
7
- while (os.homedir() !== appDirectory) {
8
13
  if (fs.existsSync(path.resolve(appDirectory, 'pnpm-lock.yaml'))) {
9
14
  return 'pnpm';
10
15
  }
@@ -20,5 +25,13 @@ export function getPackageManager(cwd = process.cwd()) {
20
25
  appDirectory = path.join(appDirectory, '..');
21
26
  }
22
27
 
28
+ if (await canUsePnpm()) {
29
+ return 'pnpm';
30
+ }
31
+
32
+ if (await canUseYarn()) {
33
+ return 'yarn';
34
+ }
35
+
23
36
  return 'npm';
24
37
  }
@@ -28,4 +28,5 @@ export * from "./generateMetaTags";
28
28
  export * from "./prettyInstructions";
29
29
  export * from "./alias";
30
30
  export * from "./import";
31
- export * from "./watch";
31
+ export * from "./watch";
32
+ export * from "./nodeEnv";
@@ -1,6 +1,6 @@
1
- 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; }
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
2
 
3
- 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; }
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
4
 
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
 
@@ -1,6 +1,6 @@
1
- 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; }
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
2
 
3
- 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; }
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
4
 
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
 
@@ -0,0 +1,31 @@
1
+ import execa from 'execa';
2
+ export async function canUseNpm() {
3
+ try {
4
+ await execa('npm', ['--version'], {
5
+ env: process.env
6
+ });
7
+ return true;
8
+ } catch (e) {
9
+ return false;
10
+ }
11
+ }
12
+ export async function canUseYarn() {
13
+ try {
14
+ await execa('yarn', ['--version'], {
15
+ env: process.env
16
+ });
17
+ return true;
18
+ } catch (e) {
19
+ return false;
20
+ }
21
+ }
22
+ export async function canUsePnpm() {
23
+ try {
24
+ await execa('pnpm', ['--version'], {
25
+ env: process.env
26
+ });
27
+ return true;
28
+ } catch (e) {
29
+ return false;
30
+ }
31
+ }
@@ -8,7 +8,7 @@ export const WatchChangeType = {
8
8
  };
9
9
  export const watch = (watchDir, runTask, ignored = []) => {
10
10
  let ready = false;
11
- const watcher = chokidar.watch(`${watchDir}/**/*.{js,jsx,ts,tsx}`, {
11
+ const watcher = chokidar.watch(watchDir, {
12
12
  ignored
13
13
  });
14
14
  watcher.on('ready', () => ready = true);
@@ -17,9 +17,9 @@ var _applyOptionsChain = require("./applyOptionsChain");
17
17
 
18
18
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
19
 
20
- 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; }
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; }
21
21
 
22
- 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; }
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; }
23
23
 
24
24
  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; }
25
25
 
@@ -81,17 +81,17 @@ const getAlias = (aliasOption, option) => {
81
81
  }
82
82
 
83
83
  return aliasConfig;
84
- };
84
+ }; // filter invalid ts paths that are not array
85
+
85
86
 
86
87
  exports.getAlias = getAlias;
87
88
 
88
- const getUserAlias = (alias = {}) => {
89
- const keys = Object.keys(alias);
90
- const userKeys = keys.filter(key => !key.includes('@modern-js/runtime'));
91
- return userKeys.reduce((o, k) => {
89
+ const getUserAlias = (alias = {}) => Object.keys(alias).reduce((o, k) => {
90
+ if (Array.isArray(alias[k])) {
92
91
  o[k] = alias[k];
93
- return o;
94
- }, {});
95
- };
92
+ }
93
+
94
+ return o;
95
+ }, {});
96
96
 
97
97
  exports.getUserAlias = getUserAlias;
@@ -180,6 +180,12 @@ const INTERNAL_PLUGINS = {
180
180
  },
181
181
  '@modern-js/plugin-polyfill': {
182
182
  server: '@modern-js/plugin-polyfill'
183
+ },
184
+ '@modern-js/plugin-multiprocess': {
185
+ cli: '@modern-js/plugin-multiprocess/cli'
186
+ },
187
+ '@modern-js/plugin-nocode': {
188
+ cli: '@modern-js/plugin-nocode/cli'
183
189
  }
184
190
  };
185
191
  /**
@@ -326,6 +332,7 @@ const PLUGIN_SCHEMAS = {
326
332
  schema: {
327
333
  type: ['object']
328
334
  }
329
- }]
335
+ }],
336
+ '@modern-js/plugin-nocode': []
330
337
  };
331
338
  exports.PLUGIN_SCHEMAS = PLUGIN_SCHEMAS;
@@ -9,9 +9,9 @@ var _is = require("./is");
9
9
 
10
10
  var _constants = require("./constants");
11
11
 
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; }
12
+ 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; }
13
13
 
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; }
14
+ 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; }
15
15
 
16
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; }
17
17
 
@@ -11,12 +11,19 @@ var _path = _interopRequireDefault(require("path"));
11
11
 
12
12
  var _fsExtra = _interopRequireDefault(require("fs-extra"));
13
13
 
14
+ var _nodeEnv = require("./nodeEnv");
15
+
14
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
17
 
16
- function getPackageManager(cwd = process.cwd()) {
18
+ const MAX_TIMES = 5;
19
+
20
+ async function getPackageManager(cwd = process.cwd()) {
17
21
  let appDirectory = cwd;
22
+ let times = 0;
23
+
24
+ while (_os.default.homedir() !== appDirectory && times < MAX_TIMES) {
25
+ times++;
18
26
 
19
- while (_os.default.homedir() !== appDirectory) {
20
27
  if (_fsExtra.default.existsSync(_path.default.resolve(appDirectory, 'pnpm-lock.yaml'))) {
21
28
  return 'pnpm';
22
29
  }
@@ -32,5 +39,13 @@ function getPackageManager(cwd = process.cwd()) {
32
39
  appDirectory = _path.default.join(appDirectory, '..');
33
40
  }
34
41
 
42
+ if (await (0, _nodeEnv.canUsePnpm)()) {
43
+ return 'pnpm';
44
+ }
45
+
46
+ if (await (0, _nodeEnv.canUseYarn)()) {
47
+ return 'yarn';
48
+ }
49
+
35
50
  return 'npm';
36
51
  }
@@ -418,6 +418,20 @@ Object.keys(_watch).forEach(function (key) {
418
418
  });
419
419
  });
420
420
 
421
+ var _nodeEnv = require("./nodeEnv");
422
+
423
+ Object.keys(_nodeEnv).forEach(function (key) {
424
+ if (key === "default" || key === "__esModule") return;
425
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
426
+ if (key in exports && exports[key] === _nodeEnv[key]) return;
427
+ Object.defineProperty(exports, key, {
428
+ enumerable: true,
429
+ get: function () {
430
+ return _nodeEnv[key];
431
+ }
432
+ });
433
+ });
434
+
421
435
  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); }
422
436
 
423
437
  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; }
@@ -9,9 +9,9 @@ var _chalk = _interopRequireDefault(require("chalk"));
9
9
 
10
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
11
 
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; }
12
+ 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; }
13
13
 
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; }
14
+ 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; }
15
15
 
16
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; }
17
17
 
@@ -15,9 +15,9 @@ var _yaml = _interopRequireDefault(require("yaml"));
15
15
 
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
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; }
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
19
 
20
- 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; }
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
21
 
22
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
23
 
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.canUseNpm = canUseNpm;
7
+ exports.canUsePnpm = canUsePnpm;
8
+ exports.canUseYarn = canUseYarn;
9
+
10
+ var _execa = _interopRequireDefault(require("execa"));
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ async function canUseNpm() {
15
+ try {
16
+ await (0, _execa.default)('npm', ['--version'], {
17
+ env: process.env
18
+ });
19
+ return true;
20
+ } catch (e) {
21
+ return false;
22
+ }
23
+ }
24
+
25
+ async function canUseYarn() {
26
+ try {
27
+ await (0, _execa.default)('yarn', ['--version'], {
28
+ env: process.env
29
+ });
30
+ return true;
31
+ } catch (e) {
32
+ return false;
33
+ }
34
+ }
35
+
36
+ async function canUsePnpm() {
37
+ try {
38
+ await (0, _execa.default)('pnpm', ['--version'], {
39
+ env: process.env
40
+ });
41
+ return true;
42
+ } catch (e) {
43
+ return false;
44
+ }
45
+ }
@@ -24,7 +24,7 @@ exports.WatchChangeType = WatchChangeType;
24
24
 
25
25
  const watch = (watchDir, runTask, ignored = []) => {
26
26
  let ready = false;
27
- const watcher = chokidar.watch(`${watchDir}/**/*.{js,jsx,ts,tsx}`, {
27
+ const watcher = chokidar.watch(watchDir, {
28
28
  ignored
29
29
  });
30
30
  watcher.on('ready', () => ready = true);
@@ -1,6 +1,6 @@
1
- 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; }
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
2
 
3
- 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; }
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
4
 
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
 
@@ -58,15 +58,15 @@ export var getAlias = function getAlias(aliasOption, option) {
58
58
  }
59
59
 
60
60
  return aliasConfig;
61
- };
61
+ }; // filter invalid ts paths that are not array
62
+
62
63
  export var getUserAlias = function getUserAlias() {
63
64
  var alias = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
64
- var keys = Object.keys(alias);
65
- var userKeys = keys.filter(function (key) {
66
- return !key.includes('@modern-js/runtime');
67
- });
68
- return userKeys.reduce(function (o, k) {
69
- o[k] = alias[k];
65
+ return Object.keys(alias).reduce(function (o, k) {
66
+ if (Array.isArray(alias[k])) {
67
+ o[k] = alias[k];
68
+ }
69
+
70
70
  return o;
71
71
  }, {});
72
72
  };
@@ -161,6 +161,12 @@ export var INTERNAL_PLUGINS = {
161
161
  },
162
162
  '@modern-js/plugin-polyfill': {
163
163
  server: '@modern-js/plugin-polyfill'
164
+ },
165
+ '@modern-js/plugin-multiprocess': {
166
+ cli: '@modern-js/plugin-multiprocess/cli'
167
+ },
168
+ '@modern-js/plugin-nocode': {
169
+ cli: '@modern-js/plugin-nocode/cli'
164
170
  }
165
171
  };
166
172
  /**
@@ -304,5 +310,6 @@ export var PLUGIN_SCHEMAS = {
304
310
  schema: {
305
311
  type: ['object']
306
312
  }
307
- }]
313
+ }],
314
+ '@modern-js/plugin-nocode': []
308
315
  };
@@ -10,7 +10,7 @@ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Sy
10
10
 
11
11
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
12
 
13
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
13
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
14
14
 
15
15
  /* eslint-disable no-param-reassign */
16
16
 
@@ -1,6 +1,6 @@
1
- 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; }
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
2
 
3
- 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; }
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
4
 
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
 
@@ -1,25 +1,101 @@
1
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
2
+
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+
5
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
+
1
7
  import os from 'os';
2
8
  import path from 'path';
3
9
  import fs from 'fs-extra';
10
+ import { canUsePnpm, canUseYarn } from "./nodeEnv";
11
+ var MAX_TIMES = 5;
4
12
  export function getPackageManager() {
5
- var cwd = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : process.cwd();
6
- var appDirectory = cwd;
13
+ return _getPackageManager.apply(this, arguments);
14
+ }
15
+
16
+ function _getPackageManager() {
17
+ _getPackageManager = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
18
+ var cwd,
19
+ appDirectory,
20
+ times,
21
+ _args = arguments;
22
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
23
+ while (1) {
24
+ switch (_context.prev = _context.next) {
25
+ case 0:
26
+ cwd = _args.length > 0 && _args[0] !== undefined ? _args[0] : process.cwd();
27
+ appDirectory = cwd;
28
+ times = 0;
29
+
30
+ case 3:
31
+ if (!(os.homedir() !== appDirectory && times < MAX_TIMES)) {
32
+ _context.next = 14;
33
+ break;
34
+ }
35
+
36
+ times++;
37
+
38
+ if (!fs.existsSync(path.resolve(appDirectory, 'pnpm-lock.yaml'))) {
39
+ _context.next = 7;
40
+ break;
41
+ }
42
+
43
+ return _context.abrupt("return", 'pnpm');
44
+
45
+ case 7:
46
+ if (!fs.existsSync(path.resolve(appDirectory, 'yarn.lock'))) {
47
+ _context.next = 9;
48
+ break;
49
+ }
50
+
51
+ return _context.abrupt("return", 'yarn');
52
+
53
+ case 9:
54
+ if (!fs.existsSync(path.resolve(appDirectory, 'package-lock.json'))) {
55
+ _context.next = 11;
56
+ break;
57
+ }
58
+
59
+ return _context.abrupt("return", 'npm');
60
+
61
+ case 11:
62
+ appDirectory = path.join(appDirectory, '..');
63
+ _context.next = 3;
64
+ break;
65
+
66
+ case 14:
67
+ _context.next = 16;
68
+ return canUsePnpm();
69
+
70
+ case 16:
71
+ if (!_context.sent) {
72
+ _context.next = 18;
73
+ break;
74
+ }
75
+
76
+ return _context.abrupt("return", 'pnpm');
7
77
 
8
- while (os.homedir() !== appDirectory) {
9
- if (fs.existsSync(path.resolve(appDirectory, 'pnpm-lock.yaml'))) {
10
- return 'pnpm';
11
- }
78
+ case 18:
79
+ _context.next = 20;
80
+ return canUseYarn();
12
81
 
13
- if (fs.existsSync(path.resolve(appDirectory, 'yarn.lock'))) {
14
- return 'yarn';
15
- }
82
+ case 20:
83
+ if (!_context.sent) {
84
+ _context.next = 22;
85
+ break;
86
+ }
16
87
 
17
- if (fs.existsSync(path.resolve(appDirectory, 'package-lock.json'))) {
18
- return 'npm';
19
- }
88
+ return _context.abrupt("return", 'yarn');
20
89
 
21
- appDirectory = path.join(appDirectory, '..');
22
- }
90
+ case 22:
91
+ return _context.abrupt("return", 'npm');
23
92
 
24
- return 'npm';
93
+ case 23:
94
+ case "end":
95
+ return _context.stop();
96
+ }
97
+ }
98
+ }, _callee);
99
+ }));
100
+ return _getPackageManager.apply(this, arguments);
25
101
  }
@@ -28,4 +28,5 @@ export * from "./generateMetaTags";
28
28
  export * from "./prettyInstructions";
29
29
  export * from "./alias";
30
30
  export * from "./import";
31
- export * from "./watch";
31
+ export * from "./watch";
32
+ export * from "./nodeEnv";
@@ -1,4 +1,4 @@
1
- function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
2
 
3
3
  export function isString(str) {
4
4
  return typeof str === 'string';
@@ -10,9 +10,9 @@ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symb
10
10
 
11
11
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
12
 
13
- 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; }
13
+ 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; }
14
14
 
15
- 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; }
15
+ 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; }
16
16
 
17
17
  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; }
18
18
 
@@ -20,7 +20,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
20
20
 
21
21
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
22
22
 
23
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
23
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
24
24
 
25
25
  import chalk from 'chalk';
26
26
  var grey = chalk.grey,
@@ -1,6 +1,6 @@
1
- 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; }
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
2
 
3
- 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; }
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
4
 
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
 
@@ -0,0 +1,108 @@
1
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
2
+
3
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
4
+
5
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
6
+
7
+ import execa from 'execa';
8
+ export function canUseNpm() {
9
+ return _canUseNpm.apply(this, arguments);
10
+ }
11
+
12
+ function _canUseNpm() {
13
+ _canUseNpm = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
14
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
15
+ while (1) {
16
+ switch (_context.prev = _context.next) {
17
+ case 0:
18
+ _context.prev = 0;
19
+ _context.next = 3;
20
+ return execa('npm', ['--version'], {
21
+ env: process.env
22
+ });
23
+
24
+ case 3:
25
+ return _context.abrupt("return", true);
26
+
27
+ case 6:
28
+ _context.prev = 6;
29
+ _context.t0 = _context["catch"](0);
30
+ return _context.abrupt("return", false);
31
+
32
+ case 9:
33
+ case "end":
34
+ return _context.stop();
35
+ }
36
+ }
37
+ }, _callee, null, [[0, 6]]);
38
+ }));
39
+ return _canUseNpm.apply(this, arguments);
40
+ }
41
+
42
+ export function canUseYarn() {
43
+ return _canUseYarn.apply(this, arguments);
44
+ }
45
+
46
+ function _canUseYarn() {
47
+ _canUseYarn = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
48
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
49
+ while (1) {
50
+ switch (_context2.prev = _context2.next) {
51
+ case 0:
52
+ _context2.prev = 0;
53
+ _context2.next = 3;
54
+ return execa('yarn', ['--version'], {
55
+ env: process.env
56
+ });
57
+
58
+ case 3:
59
+ return _context2.abrupt("return", true);
60
+
61
+ case 6:
62
+ _context2.prev = 6;
63
+ _context2.t0 = _context2["catch"](0);
64
+ return _context2.abrupt("return", false);
65
+
66
+ case 9:
67
+ case "end":
68
+ return _context2.stop();
69
+ }
70
+ }
71
+ }, _callee2, null, [[0, 6]]);
72
+ }));
73
+ return _canUseYarn.apply(this, arguments);
74
+ }
75
+
76
+ export function canUsePnpm() {
77
+ return _canUsePnpm.apply(this, arguments);
78
+ }
79
+
80
+ function _canUsePnpm() {
81
+ _canUsePnpm = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3() {
82
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
83
+ while (1) {
84
+ switch (_context3.prev = _context3.next) {
85
+ case 0:
86
+ _context3.prev = 0;
87
+ _context3.next = 3;
88
+ return execa('pnpm', ['--version'], {
89
+ env: process.env
90
+ });
91
+
92
+ case 3:
93
+ return _context3.abrupt("return", true);
94
+
95
+ case 6:
96
+ _context3.prev = 6;
97
+ _context3.t0 = _context3["catch"](0);
98
+ return _context3.abrupt("return", false);
99
+
100
+ case 9:
101
+ case "end":
102
+ return _context3.stop();
103
+ }
104
+ }
105
+ }, _callee3, null, [[0, 6]]);
106
+ }));
107
+ return _canUsePnpm.apply(this, arguments);
108
+ }
@@ -15,7 +15,7 @@ export var WatchChangeType = {
15
15
  export var watch = function watch(watchDir, runTask) {
16
16
  var ignored = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
17
17
  var ready = false;
18
- var watcher = chokidar.watch("".concat(watchDir, "/**/*.{js,jsx,ts,tsx}"), {
18
+ var watcher = chokidar.watch(watchDir, {
19
19
  ignored: ignored
20
20
  });
21
21
  watcher.on('ready', function () {
@@ -194,4 +194,5 @@ export declare const PLUGIN_SCHEMAS: {
194
194
  type: string[];
195
195
  };
196
196
  }[];
197
+ '@modern-js/plugin-nocode': never[];
197
198
  };
@@ -1 +1 @@
1
- export declare function getPackageManager(cwd?: string): "pnpm" | "yarn" | "npm";
1
+ export declare function getPackageManager(cwd?: string): Promise<"npm" | "yarn" | "pnpm">;
@@ -27,4 +27,5 @@ export * from './generateMetaTags';
27
27
  export * from './prettyInstructions';
28
28
  export * from './alias';
29
29
  export * from './import';
30
- export * from './watch';
30
+ export * from './watch';
31
+ export * from './nodeEnv';
@@ -0,0 +1,3 @@
1
+ export declare function canUseNpm(): Promise<boolean>;
2
+ export declare function canUseYarn(): Promise<boolean>;
3
+ export declare function canUsePnpm(): Promise<boolean>;
@@ -4,5 +4,5 @@ declare type RunTaskType = (option: {
4
4
  changedFilePath: string;
5
5
  changeType: WatchChangeTypeValueT;
6
6
  }) => void | Promise<void>;
7
- export declare const watch: (watchDir: string, runTask: RunTaskType, ignored?: string[]) => import("chokidar").FSWatcher;
7
+ export declare const watch: (watchDir: string | string[], runTask: RunTaskType, ignored?: string[]) => import("chokidar").FSWatcher;
8
8
  export {};
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.1.3",
14
+ "version": "1.1.6-alpha.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/types/index.d.ts",
17
17
  "main": "./dist/js/node/index.js",
@@ -54,7 +54,8 @@
54
54
  "recursive-readdir": "^2.2.2",
55
55
  "strip-ansi": "6.0.0",
56
56
  "upath": "^2.0.1",
57
- "yaml": "^1.10.2"
57
+ "yaml": "^1.10.2",
58
+ "execa": "5"
58
59
  },
59
60
  "devDependencies": {
60
61
  "@types/debug": "^4.1.7",
@@ -65,8 +66,8 @@
65
66
  "@types/recursive-readdir": "^2.2.0",
66
67
  "typescript": "^4",
67
68
  "webpack": "^5.54.0",
68
- "@modern-js/plugin-testing": "^1.1.1",
69
- "@modern-js/module-tools": "^1.1.1"
69
+ "@modern-js/plugin-testing": "^1.2.0",
70
+ "@modern-js/module-tools": "^1.1.3"
70
71
  },
71
72
  "peerDependencies": {
72
73
  "typescript": "^4.4.3"
package/src/alias.ts CHANGED
@@ -80,11 +80,11 @@ export const getAlias = (
80
80
  return aliasConfig;
81
81
  };
82
82
 
83
- export const getUserAlias = (alias: Record<string, string | string[]> = {}) => {
84
- const keys = Object.keys(alias);
85
- const userKeys = keys.filter(key => !key.includes('@modern-js/runtime'));
86
- return userKeys.reduce<Record<string, string | string[]>>((o, k) => {
87
- o[k] = alias[k];
83
+ // filter invalid ts paths that are not array
84
+ export const getUserAlias = (alias: Record<string, string | string[]> = {}) =>
85
+ Object.keys(alias).reduce((o, k) => {
86
+ if (Array.isArray(alias[k])) {
87
+ o[k] = alias[k];
88
+ }
88
89
  return o;
89
- }, {});
90
- };
90
+ }, {} as Record<string, string | string[]>);
package/src/constants.ts CHANGED
@@ -120,6 +120,10 @@ export const INTERNAL_PLUGINS: {
120
120
  cli: '@modern-js/plugin-static-hosting/cli',
121
121
  },
122
122
  '@modern-js/plugin-polyfill': { server: '@modern-js/plugin-polyfill' },
123
+ '@modern-js/plugin-multiprocess': {
124
+ cli: '@modern-js/plugin-multiprocess/cli',
125
+ },
126
+ '@modern-js/plugin-nocode': { cli: '@modern-js/plugin-nocode/cli' },
123
127
  };
124
128
 
125
129
  /**
@@ -254,4 +258,5 @@ export const PLUGIN_SCHEMAS = {
254
258
  schema: { type: ['object'] },
255
259
  },
256
260
  ],
261
+ '@modern-js/plugin-nocode': [],
257
262
  };
@@ -1,10 +1,14 @@
1
1
  import os from 'os';
2
2
  import path from 'path';
3
3
  import fs from 'fs-extra';
4
+ import { canUsePnpm, canUseYarn } from './nodeEnv';
4
5
 
5
- export function getPackageManager(cwd: string = process.cwd()) {
6
+ const MAX_TIMES = 5;
7
+ export async function getPackageManager(cwd: string = process.cwd()) {
6
8
  let appDirectory = cwd;
7
- while (os.homedir() !== appDirectory) {
9
+ let times = 0;
10
+ while (os.homedir() !== appDirectory && times < MAX_TIMES) {
11
+ times++;
8
12
  if (fs.existsSync(path.resolve(appDirectory, 'pnpm-lock.yaml'))) {
9
13
  return 'pnpm';
10
14
  }
@@ -16,5 +20,11 @@ export function getPackageManager(cwd: string = process.cwd()) {
16
20
  }
17
21
  appDirectory = path.join(appDirectory, '..');
18
22
  }
23
+ if (await canUsePnpm()) {
24
+ return 'pnpm';
25
+ }
26
+ if (await canUseYarn()) {
27
+ return 'yarn';
28
+ }
19
29
  return 'npm';
20
30
  }
package/src/index.ts CHANGED
@@ -28,3 +28,4 @@ export * from './prettyInstructions';
28
28
  export * from './alias';
29
29
  export * from './import';
30
30
  export * from './watch';
31
+ export * from './nodeEnv';
package/src/nodeEnv.ts ADDED
@@ -0,0 +1,28 @@
1
+ import execa from 'execa';
2
+
3
+ export async function canUseNpm() {
4
+ try {
5
+ await execa('npm', ['--version'], { env: process.env });
6
+ return true;
7
+ } catch (e) {
8
+ return false;
9
+ }
10
+ }
11
+
12
+ export async function canUseYarn() {
13
+ try {
14
+ await execa('yarn', ['--version'], { env: process.env });
15
+ return true;
16
+ } catch (e) {
17
+ return false;
18
+ }
19
+ }
20
+
21
+ export async function canUsePnpm() {
22
+ try {
23
+ await execa('pnpm', ['--version'], { env: process.env });
24
+ return true;
25
+ } catch (e) {
26
+ return false;
27
+ }
28
+ }
package/src/watch.ts CHANGED
@@ -20,12 +20,12 @@ type RunTaskType = (option: {
20
20
  }) => void | Promise<void>;
21
21
 
22
22
  export const watch = (
23
- watchDir: string,
23
+ watchDir: string | string[],
24
24
  runTask: RunTaskType,
25
25
  ignored: string[] = [],
26
26
  ) => {
27
27
  let ready = false;
28
- const watcher = chokidar.watch(`${watchDir}/**/*.{js,jsx,ts,tsx}`, {
28
+ const watcher = chokidar.watch(watchDir, {
29
29
  ignored,
30
30
  });
31
31