@modern-js/module-tools 2.0.0-beta.0 → 2.0.0-beta.1

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 (93) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/dist/js/modern/cli/build.js +2 -1
  3. package/dist/js/modern/cli/dev.js +2 -2
  4. package/dist/js/modern/cli/new.js +0 -3
  5. package/dist/js/modern/commands/build.js +0 -4
  6. package/dist/js/modern/commands/dev.js +2 -5
  7. package/dist/js/modern/features/build/build-platform.js +11 -14
  8. package/dist/js/modern/features/build/bundle/runRollup.js +5 -18
  9. package/dist/js/modern/features/build/bundle/runSpeedy.js +4 -18
  10. package/dist/js/modern/features/build/bundleless/copy-assets.js +0 -8
  11. package/dist/js/modern/features/build/bundleless/generator-dts/index.js +7 -17
  12. package/dist/js/modern/features/build/bundleless/generator-dts/utils.js +6 -16
  13. package/dist/js/modern/features/build/bundleless/index.js +0 -2
  14. package/dist/js/modern/features/build/bundleless/runBabel.js +7 -34
  15. package/dist/js/modern/features/build/bundleless/style.js +1 -30
  16. package/dist/js/modern/features/build/constants.js +0 -3
  17. package/dist/js/modern/features/build/error.js +4 -27
  18. package/dist/js/modern/features/build/index.js +6 -15
  19. package/dist/js/modern/features/build/legacy-constants.js +8 -4
  20. package/dist/js/modern/features/build/logger/logText.js +0 -12
  21. package/dist/js/modern/features/build/logger/loggerManager.js +6 -19
  22. package/dist/js/modern/features/build/normalize.js +18 -43
  23. package/dist/js/modern/features/build/utils.js +5 -14
  24. package/dist/js/modern/features/dev/index.js +4 -9
  25. package/dist/js/modern/hooks/index.js +0 -3
  26. package/dist/js/modern/index.js +5 -9
  27. package/dist/js/modern/schema/build-config.js +2 -1
  28. package/dist/js/modern/schema/output.js +5 -10
  29. package/dist/js/modern/utils/babel.js +12 -14
  30. package/dist/js/modern/utils/copy.js +6 -15
  31. package/dist/js/modern/utils/init-env.js +0 -1
  32. package/dist/js/modern/utils/logger.js +1 -16
  33. package/dist/js/modern/utils/readline.js +2 -4
  34. package/dist/js/modern/utils/tsconfig.js +0 -1
  35. package/dist/js/modern/utils/tspaths-transform/constants.js +4 -2
  36. package/dist/js/modern/utils/tspaths-transform/index.js +2 -19
  37. package/dist/js/modern/utils/tspaths-transform/utils.js +0 -3
  38. package/dist/js/modern/utils/valide.js +2 -6
  39. package/dist/js/node/cli/build.js +2 -6
  40. package/dist/js/node/cli/dev.js +2 -7
  41. package/dist/js/node/cli/index.js +0 -6
  42. package/dist/js/node/cli/new.js +0 -8
  43. package/dist/js/node/commands/build.js +0 -19
  44. package/dist/js/node/commands/dev.js +2 -15
  45. package/dist/js/node/commands/index.js +0 -2
  46. package/dist/js/node/features/build/build-platform.js +11 -20
  47. package/dist/js/node/features/build/bundle/index.js +0 -6
  48. package/dist/js/node/features/build/bundle/runRollup.js +3 -32
  49. package/dist/js/node/features/build/bundle/runSpeedy.js +4 -32
  50. package/dist/js/node/features/build/bundleless/copy-assets.js +0 -20
  51. package/dist/js/node/features/build/bundleless/generator-dts/index.js +7 -27
  52. package/dist/js/node/features/build/bundleless/generator-dts/utils.js +6 -32
  53. package/dist/js/node/features/build/bundleless/index.js +0 -11
  54. package/dist/js/node/features/build/bundleless/runBabel.js +6 -60
  55. package/dist/js/node/features/build/bundleless/style.js +1 -50
  56. package/dist/js/node/features/build/constants.js +0 -11
  57. package/dist/js/node/features/build/error.js +4 -40
  58. package/dist/js/node/features/build/index.js +6 -38
  59. package/dist/js/node/features/build/legacy-constants.js +8 -4
  60. package/dist/js/node/features/build/logger/index.js +0 -4
  61. package/dist/js/node/features/build/logger/logText.js +0 -18
  62. package/dist/js/node/features/build/logger/loggerManager.js +5 -26
  63. package/dist/js/node/features/build/normalize.js +18 -61
  64. package/dist/js/node/features/build/utils.js +5 -30
  65. package/dist/js/node/features/dev/index.js +4 -17
  66. package/dist/js/node/hooks/build.js +0 -5
  67. package/dist/js/node/hooks/dev.js +0 -5
  68. package/dist/js/node/hooks/index.js +0 -10
  69. package/dist/js/node/index.js +6 -26
  70. package/dist/js/node/locale/index.js +0 -5
  71. package/dist/js/node/schema/build-config.js +2 -1
  72. package/dist/js/node/schema/index.js +0 -5
  73. package/dist/js/node/schema/output.js +5 -12
  74. package/dist/js/node/utils/babel.js +12 -22
  75. package/dist/js/node/utils/color.js +0 -3
  76. package/dist/js/node/utils/copy.js +6 -23
  77. package/dist/js/node/utils/init-env.js +0 -3
  78. package/dist/js/node/utils/json.js +0 -2
  79. package/dist/js/node/utils/language.js +0 -3
  80. package/dist/js/node/utils/logger.js +1 -26
  81. package/dist/js/node/utils/readline.js +0 -8
  82. package/dist/js/node/utils/tsconfig.js +0 -7
  83. package/dist/js/node/utils/tspaths-transform/constants.js +4 -2
  84. package/dist/js/node/utils/tspaths-transform/index.js +2 -34
  85. package/dist/js/node/utils/tspaths-transform/utils.js +0 -7
  86. package/dist/js/node/utils/valide.js +2 -11
  87. package/dist/types/commands/build.d.ts +0 -1
  88. package/dist/types/features/build/logger/loggerManager.d.ts +0 -1
  89. package/dist/types/features/build/utils.d.ts +0 -1
  90. package/dist/types/index.d.ts +0 -2
  91. package/dist/types/schema/types.d.ts +1 -3
  92. package/dist/types/types.d.ts +0 -1
  93. package/package.json +19 -19
@@ -4,34 +4,23 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.watchSectionTitle = exports.logTemplate = exports.getPostcssOption = exports.getAllDeps = exports.SectionTitleStatus = exports.LogStack = void 0;
7
-
8
7
  var os = _interopRequireWildcard(require("os"));
9
-
10
8
  var _path = _interopRequireDefault(require("path"));
11
-
12
9
  var _utils = require("@modern-js/utils");
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
11
  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
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; }
19
-
20
13
  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; }
21
-
22
14
  const constants = _utils.Import.lazy('./constants', require);
15
+
23
16
  /**
24
17
  * 处理日志信息
25
18
  */
26
-
27
-
28
19
  class LogStack {
29
20
  constructor() {
30
21
  _defineProperty(this, "_codeLogStack", void 0);
31
-
32
22
  this._codeLogStack = [];
33
23
  }
34
-
35
24
  update(latestLog, {
36
25
  splitEOL = false
37
26
  } = {}) {
@@ -41,22 +30,16 @@ class LogStack {
41
30
  });
42
31
  return;
43
32
  }
44
-
45
33
  this._codeLogStack.unshift(latestLog.trim());
46
34
  }
47
-
48
35
  clear() {
49
36
  this._codeLogStack = [];
50
37
  }
51
-
52
38
  get value() {
53
39
  return [...new Set(this._codeLogStack)];
54
40
  }
55
-
56
41
  }
57
-
58
42
  exports.LogStack = LogStack;
59
-
60
43
  const logTemplate = (title, messageStack, maxLength, {
61
44
  noBottomBorder: _noBottomBorder = false,
62
45
  bottomBorderText: _bottomBorderText = '',
@@ -72,35 +55,29 @@ const logTemplate = (title, messageStack, maxLength, {
72
55
  .slice(0, maxLength) // 控制长度
73
56
  .filter(s => s !== leftBorderFlag) // 过滤空字符串
74
57
  .reverse(); // 调换顺序,最新的消息在最后面
75
-
76
58
  const template = `${title}:
77
59
  ${_contentColor(messageFragments.join(os.EOL))}${_noBottomBorder ? '' : `\n${_bottomBorderText}`}`;
78
60
  return template;
79
61
  };
80
-
81
62
  exports.logTemplate = logTemplate;
82
63
  let SectionTitleStatus;
83
64
  exports.SectionTitleStatus = SectionTitleStatus;
84
-
85
65
  (function (SectionTitleStatus) {
86
66
  SectionTitleStatus[SectionTitleStatus["Success"] = 0] = "Success";
87
67
  SectionTitleStatus[SectionTitleStatus["Fail"] = 1] = "Fail";
88
68
  SectionTitleStatus[SectionTitleStatus["Log"] = 2] = "Log";
89
69
  })(SectionTitleStatus || (exports.SectionTitleStatus = SectionTitleStatus = {}));
90
-
91
70
  const watchSectionTitle = (str, status) => {
92
71
  if (status === SectionTitleStatus.Success) {
93
72
  return `${_utils.chalk.bgWhite.gray.underline(str)} ${_utils.chalk.green.underline('Successful')}`;
94
73
  } else if (status === SectionTitleStatus.Fail) {
95
74
  return `${_utils.chalk.bgWhite.gray.underline(str)} ${_utils.chalk.red.underline('Build Failed')}`;
96
75
  }
97
-
98
76
  return `${_utils.chalk.bgWhite.gray.underline(str)} ${_utils.chalk.blue.underline('Log')}`;
99
- }; // eslint-disable-next-line @typescript-eslint/no-unused-vars
100
-
77
+ };
101
78
 
79
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
102
80
  exports.watchSectionTitle = watchSectionTitle;
103
-
104
81
  const getPostcssOption = (...args) => {
105
82
  // const postcssOption: any = cssConfig.getPostcssConfig(
106
83
  // appDirectory,
@@ -115,18 +92,16 @@ const getPostcssOption = (...args) => {
115
92
  options: {}
116
93
  };
117
94
  };
118
-
119
95
  exports.getPostcssOption = getPostcssOption;
120
-
121
96
  const getAllDeps = appDirectory => {
122
97
  try {
123
- const json = JSON.parse(_utils.fs.readFileSync(_path.default.resolve(appDirectory, './package.json'), 'utf8')); // return json[packageJsonConfig ?? PACKAGE_JSON_CONFIG_NAME] as T | undefined;
98
+ const json = JSON.parse(_utils.fs.readFileSync(_path.default.resolve(appDirectory, './package.json'), 'utf8'));
124
99
 
100
+ // return json[packageJsonConfig ?? PACKAGE_JSON_CONFIG_NAME] as T | undefined;
125
101
  return [...Object.keys(json.dependencies || {}), ...Object.keys(json.devDependencies || {}), ...Object.keys(json.peerDependencies || {})];
126
102
  } catch (e) {
127
103
  console.warn('[WARN] package.json is broken');
128
104
  return [];
129
105
  }
130
106
  };
131
-
132
107
  exports.getAllDeps = getAllDeps;
@@ -4,21 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.showMenu = exports.runSubCmd = exports.devStorybook = void 0;
7
-
8
7
  var _utils = require("@modern-js/utils");
9
-
10
8
  const color = _utils.Import.lazy('../../utils/color', require);
11
-
12
9
  const showMenu = async (api, config) => {
13
10
  const runners = api.useHookRunners();
14
11
  const metas = await runners.moduleToolsMenu(undefined);
15
-
16
12
  if (metas.length <= 0) {
17
- console.info(_utils.chalk.yellow('No runnable development features found.\nYou can use the `new` command to enable the development features')); // eslint-disable-next-line no-process-exit
18
-
13
+ console.info(_utils.chalk.yellow('No runnable development features found.\nYou can use the `new` command to enable the development features'));
14
+ // eslint-disable-next-line no-process-exit
19
15
  process.exit(0);
20
16
  }
21
-
22
17
  const menuMessage = color.devMenuTitle('Select the debug mode:');
23
18
  const {
24
19
  type
@@ -29,35 +24,28 @@ const showMenu = async (api, config) => {
29
24
  choices: metas
30
25
  }]);
31
26
  const devMeta = metas.find(meta => meta.value === type);
32
-
33
27
  if (devMeta) {
34
28
  await devMeta.runTask(config);
35
29
  }
36
30
  };
37
-
38
31
  exports.showMenu = showMenu;
39
-
40
32
  const devStorybook = async (api, config) => {
41
33
  const runners = api.useHookRunners();
42
34
  const metas = await runners.moduleToolsMenu(undefined);
43
35
  const findStorybook = metas.find(meta => meta.value === 'storybook');
44
-
45
36
  if (findStorybook) {
46
37
  await findStorybook.runTask(config);
47
38
  } else {
48
- console.info(_utils.chalk.yellow('No development features found.\nYou can use the `new` command to enable the development features')); // eslint-disable-next-line no-process-exit
49
-
39
+ console.info(_utils.chalk.yellow('No development features found.\nYou can use the `new` command to enable the development features'));
40
+ // eslint-disable-next-line no-process-exit
50
41
  process.exit(0);
51
42
  }
52
43
  };
53
-
54
44
  exports.devStorybook = devStorybook;
55
-
56
45
  const runSubCmd = async (api, subCmd, config) => {
57
46
  const runners = api.useHookRunners();
58
47
  const metas = await runners.moduleToolsMenu(undefined);
59
48
  const devMeta = metas.find(meta => meta.value === subCmd || Array.isArray(meta.aliasValues) && meta.aliasValues.includes(subCmd));
60
-
61
49
  if (devMeta) {
62
50
  await devMeta.runTask(config);
63
51
  } else {
@@ -65,5 +53,4 @@ const runSubCmd = async (api, subCmd, config) => {
65
53
  process.exit(0);
66
54
  }
67
55
  };
68
-
69
56
  exports.runSubCmd = runSubCmd;
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.platformBuild = exports.moduleTailwindConfig = exports.moduleSassConfig = exports.moduleLessConfig = exports.lifecycle = exports.buildHooks = void 0;
7
-
8
7
  var _plugin = require("@modern-js/plugin");
9
-
10
8
  var _core = require("@modern-js/core");
11
-
12
9
  const platformBuild = (0, _plugin.createParallelWorkflow)();
13
10
  exports.platformBuild = platformBuild;
14
11
  const moduleLessConfig = (0, _plugin.createAsyncPipeline)();
@@ -24,7 +21,6 @@ const buildHooks = {
24
21
  moduleTailwindConfig
25
22
  };
26
23
  exports.buildHooks = buildHooks;
27
-
28
24
  const lifecycle = () => {
29
25
  (0, _core.registerHook)({
30
26
  moduleLessConfig,
@@ -33,5 +29,4 @@ const lifecycle = () => {
33
29
  platformBuild
34
30
  });
35
31
  };
36
-
37
32
  exports.lifecycle = lifecycle;
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.moduleToolsMenu = exports.lifecycle = exports.devHooks = exports.afterDev = void 0;
7
-
8
7
  var _plugin = require("@modern-js/plugin");
9
-
10
8
  var _core = require("@modern-js/core");
11
-
12
9
  const moduleToolsMenu = (0, _plugin.createParallelWorkflow)();
13
10
  exports.moduleToolsMenu = moduleToolsMenu;
14
11
  const afterDev = (0, _plugin.createAsyncWorkflow)();
@@ -18,12 +15,10 @@ const devHooks = {
18
15
  afterDev
19
16
  };
20
17
  exports.devHooks = devHooks;
21
-
22
18
  const lifecycle = () => {
23
19
  (0, _core.registerHook)({
24
20
  moduleToolsMenu,
25
21
  afterDev
26
22
  });
27
23
  };
28
-
29
24
  exports.lifecycle = lifecycle;
@@ -17,30 +17,20 @@ Object.defineProperty(exports, "devLifeCycle", {
17
17
  }
18
18
  });
19
19
  exports.lifecycle = exports.hooks = void 0;
20
-
21
20
  var _plugin = require("@modern-js/plugin");
22
-
23
21
  var _build = require("./build");
24
-
25
22
  var _dev = require("./dev");
26
-
27
23
  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; }
28
-
29
24
  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; }
30
-
31
25
  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; }
32
-
33
26
  const lifecycle = () => {
34
27
  (0, _dev.lifecycle)();
35
28
  (0, _build.lifecycle)();
36
29
  };
37
-
38
30
  exports.lifecycle = lifecycle;
39
31
  const addRuntimeExports = (0, _plugin.createAsyncWaterfall)();
40
32
  exports.addRuntimeExports = addRuntimeExports;
41
-
42
33
  const hooks = _objectSpread(_objectSpread(_objectSpread({}, _build.buildHooks), _dev.devHooks), {}, {
43
34
  addRuntimeExports
44
35
  });
45
-
46
36
  exports.hooks = hooks;
@@ -13,17 +13,11 @@ Object.defineProperty(exports, "defineConfig", {
13
13
  return _core.defineConfig;
14
14
  }
15
15
  });
16
-
17
16
  var _utils = require("@modern-js/utils");
18
-
19
17
  var _pluginChangeset = _interopRequireDefault(require("@modern-js/plugin-changeset"));
20
-
21
- var _pluginJarvis = _interopRequireDefault(require("@modern-js/plugin-jarvis"));
22
-
18
+ var _pluginLint = _interopRequireDefault(require("@modern-js/plugin-lint"));
23
19
  var _hooks = require("./hooks");
24
-
25
20
  var _types = require("./types");
26
-
27
21
  Object.keys(_types).forEach(function (key) {
28
22
  if (key === "default" || key === "__esModule") return;
29
23
  if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
@@ -35,28 +29,19 @@ Object.keys(_types).forEach(function (key) {
35
29
  }
36
30
  });
37
31
  });
38
-
39
32
  var _core = require("@modern-js/core");
40
-
41
33
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
42
-
43
34
  const upgradeModel = _utils.Import.lazy('@modern-js/upgrade', require);
44
-
45
35
  const cli = _utils.Import.lazy('./cli', require);
46
-
47
36
  const local = _utils.Import.lazy('./locale', require);
48
-
49
37
  const schema = _utils.Import.lazy('./schema', require);
50
-
51
38
  const lang = _utils.Import.lazy('./utils/language', require);
52
-
53
39
  const isBuildMode = process.argv.slice(2)[0] === 'build';
54
-
55
40
  var _default = () => ({
56
41
  name: '@modern-js/module-tools',
57
42
  post: ['@modern-js/plugin-changeset'],
58
43
  registerHook: _hooks.hooks,
59
- usePlugins: isBuildMode ? [] : [(0, _pluginChangeset.default)(), (0, _pluginJarvis.default)()],
44
+ usePlugins: isBuildMode ? [] : [(0, _pluginChangeset.default)(), (0, _pluginLint.default)()],
60
45
  setup: api => {
61
46
  const locale = lang.getLocaleLanguage();
62
47
  local.i18n.changeLanguage({
@@ -67,19 +52,16 @@ var _default = () => ({
67
52
  async prepare() {
68
53
  const appContext = api.useAppContext();
69
54
  const hookRunners = api.useHookRunners();
70
-
71
55
  try {
72
56
  _utils.fs.emptydirSync(appContext.internalDirectory);
73
- } catch (_unused) {// FIXME:
57
+ } catch (_unused) {
58
+ // FIXME:
74
59
  }
75
-
76
60
  await hookRunners.addRuntimeExports();
77
61
  },
78
-
79
62
  validateSchema() {
80
63
  return schema.addSchema();
81
64
  },
82
-
83
65
  config() {
84
66
  return {
85
67
  output: {
@@ -88,20 +70,18 @@ var _default = () => ({
88
70
  }
89
71
  };
90
72
  },
91
-
92
73
  commands({
93
74
  program
94
75
  }) {
95
76
  cli.devCli(program, api);
96
77
  cli.buildCli(program, api);
97
78
  cli.newCli(program, locale);
98
- upgradeModel.defineCommand(program.command('upgrade')); // 便于其他插件辨别
79
+ upgradeModel.defineCommand(program.command('upgrade'));
99
80
 
81
+ // 便于其他插件辨别
100
82
  program.$$libraryName = 'module-tools';
101
83
  }
102
-
103
84
  };
104
85
  }
105
86
  });
106
-
107
87
  exports.default = _default;
@@ -4,15 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.localeKeys = exports.i18n = void 0;
7
-
8
7
  var _utils = require("@modern-js/utils");
9
-
10
8
  var _zh = require("./zh");
11
-
12
9
  var _en = require("./en");
13
-
14
10
  const i18nPlugin = _utils.Import.lazy('@modern-js/plugin-i18n', require);
15
-
16
11
  const i18n = new i18nPlugin.I18n();
17
12
  exports.i18n = i18n;
18
13
  const localeKeys = i18n.init('zh', {
@@ -4,7 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.targets = exports.presets = exports.buildSchema = void 0;
7
- const targets = ['es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020', // The default target is esnext which means that by default, assume all of the latest JavaScript and CSS features are supported.
7
+ const targets = ['es5', 'es6', 'es2015', 'es2016', 'es2017', 'es2018', 'es2019', 'es2020',
8
+ // The default target is esnext which means that by default, assume all of the latest JavaScript and CSS features are supported.
8
9
  'esnext'];
9
10
  exports.targets = targets;
10
11
  const presets = ['npm-library', 'npm-library-with-umd', 'npm-component', 'npm-component-with-umd', ...['npm-library', 'npm-library-with-umd', 'npm-component', 'npm-component-with-umd'].reduce((ret, crt) => {
@@ -4,13 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.addSchema = void 0;
7
-
8
7
  var _source = require("./source");
9
-
10
8
  var _output = require("./output");
11
-
12
9
  var _tools = require("./tools");
13
-
14
10
  const addSchema = () => [..._source.sourceSchema, ..._output.outputSchema, ..._tools.toolsSchema];
15
-
16
11
  exports.addSchema = addSchema;
@@ -4,40 +4,33 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.outputSchema = void 0;
7
-
8
7
  var _buildConfig = require("./build-config");
9
-
10
8
  const PACKAGE_MODE_LIST = ['universal-js', 'universal-js-lite', 'browser-js', 'browser-js-lite', 'node-js'];
11
- const outputSchema = [
12
- /** packageMode will deprecated */
9
+ const outputSchema = [/** packageMode will deprecated */
13
10
  {
14
11
  target: 'output.packageMode',
15
12
  schema: {
16
13
  enum: PACKAGE_MODE_LIST
17
14
  }
18
- },
19
- /** packageFields will deprecated */
15
+ }, /** packageFields will deprecated */
20
16
  {
21
17
  target: 'output.packageFields',
22
18
  schema: {
23
19
  typeof: 'object'
24
20
  }
25
- },
26
- /** enableSourceMap will deprecated */
21
+ }, /** enableSourceMap will deprecated */
27
22
  {
28
23
  target: 'output.enableSourceMap',
29
24
  schema: {
30
25
  typeof: 'boolean'
31
26
  }
32
- },
33
- /** importStyle will deprecated */
27
+ }, /** importStyle will deprecated */
34
28
  {
35
29
  target: 'output.importStyle',
36
30
  schema: {
37
31
  enum: ['compiled-code', 'source-code']
38
32
  }
39
- },
40
- /** assetsPath will deprecated */
33
+ }, /** assetsPath will deprecated */
41
34
  {
42
35
  target: 'output.assetsPath',
43
36
  schema: {
@@ -4,43 +4,30 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.resolveBabelConfig = exports.getFinalAlias = void 0;
7
-
8
7
  var _path = _interopRequireDefault(require("path"));
9
-
10
8
  var _babelPresetModule = require("@modern-js/babel-preset-module");
11
-
12
9
  var _utils = require("@modern-js/utils");
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
11
  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; }
17
-
18
12
  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; }
19
-
20
13
  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; }
21
-
22
14
  const getFinalAlias = (modernConfig, option) => {
23
- const aliasConfig = (0, _utils.getAliasConfig)(modernConfig.source.alias, option); // 排除内部别名,因为不需要处理
24
-
15
+ const aliasConfig = (0, _utils.getAliasConfig)(modernConfig.source.alias, option);
16
+ // 排除内部别名,因为不需要处理
25
17
  const finalPaths = {};
26
18
  const internalAliasPrefix = '@modern-js/runtime';
27
-
28
19
  if (aliasConfig.paths && typeof aliasConfig.paths === 'object') {
29
20
  const pathsKey = Object.keys(aliasConfig.paths);
30
-
31
21
  for (const key of pathsKey) {
32
22
  if (!key.includes(internalAliasPrefix)) {
33
23
  finalPaths[key] = aliasConfig.paths[key];
34
24
  }
35
25
  }
36
26
  }
37
-
38
27
  aliasConfig.paths = finalPaths;
39
28
  return aliasConfig;
40
29
  };
41
-
42
30
  exports.getFinalAlias = getFinalAlias;
43
-
44
31
  const resolveBabelConfig = (appDirectory, modernConfig, sourceMap, bundlelessOptions, option) => {
45
32
  const {
46
33
  source: {
@@ -55,17 +42,20 @@ const resolveBabelConfig = (appDirectory, modernConfig, sourceMap, bundlelessOpt
55
42
  lodash: userLodashOption,
56
43
  styledComponents
57
44
  }
58
- } = modernConfig; // alias config
45
+ } = modernConfig;
59
46
 
47
+ // alias config
60
48
  const aliasConfig = getFinalAlias(modernConfig, _objectSpread({
61
49
  appDirectory
62
- }, option)); // lodash config
50
+ }, option));
63
51
 
52
+ // lodash config
64
53
  const lodashOptions = (0, _utils.applyOptionsChain)({
65
54
  id: ['lodash', 'ramda']
66
- }, // TODO: 需要处理类型问题
67
- userLodashOption); // babel config
68
-
55
+ },
56
+ // TODO: 需要处理类型问题
57
+ userLodashOption);
58
+ // babel config
69
59
  const internalBabelConfig = (0, _babelPresetModule.getBabelConfig)({
70
60
  appDirectory,
71
61
  enableReactPreset: true,
@@ -88,12 +78,12 @@ const resolveBabelConfig = (appDirectory, modernConfig, sourceMap, bundlelessOpt
88
78
  }, {
89
79
  type: option.type,
90
80
  syntax: option.syntax
91
- }); // Preventing warning when files are too large
81
+ });
92
82
 
83
+ // Preventing warning when files are too large
93
84
  internalBabelConfig.compact = false;
94
85
  internalBabelConfig.sourceMaps = sourceMap === 'external' ? true : sourceMap;
95
86
  const userBabelConfig = modernConfig.tools.babel;
96
87
  return (0, _babelPresetModule.applyUserBabelConfig)(internalBabelConfig, userBabelConfig);
97
88
  };
98
-
99
89
  exports.resolveBabelConfig = resolveBabelConfig;
@@ -4,9 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.devMenuTitle = void 0;
7
-
8
7
  var _utils = require("@modern-js/utils");
9
-
10
8
  const devMenuTitle = _utils.chalk.rgb(255, 153, 0);
11
-
12
9
  exports.devMenuTitle = devMenuTitle;
@@ -4,23 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.copyTask = void 0;
7
-
8
7
  var path = _interopRequireWildcard(require("path"));
9
-
10
8
  var _utils = require("@modern-js/utils");
11
-
12
9
  const _excluded = ["glob"];
13
-
14
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); }
15
-
16
11
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
-
18
12
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
19
-
20
13
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
21
-
22
14
  const normalizePath = _utils.Import.lazy('normalize-path', require);
23
-
24
15
  const copyTask = async option => {
25
16
  const {
26
17
  modernConfig,
@@ -37,11 +28,9 @@ const copyTask = async option => {
37
28
  }
38
29
  } = modernConfig;
39
30
  const copyDistDir = path.join(outputPath, jsPath);
40
-
41
31
  if (!copy) {
42
32
  return;
43
33
  }
44
-
45
34
  try {
46
35
  // 类型暂时这样处理,待之后优化copy的逻辑
47
36
  for (const copyOption of copy) {
@@ -52,11 +41,10 @@ const copyTask = async option => {
52
41
  globOptions,
53
42
  to: toOrigin
54
43
  } = copyOption;
55
- let fromOrigin = from; // 获取 glob 规则
56
-
44
+ let fromOrigin = from;
45
+ // 获取 glob 规则
57
46
  let glob = '';
58
47
  let options = {};
59
-
60
48
  if (fromOrigin !== null && typeof fromOrigin === 'object') {
61
49
  var _fromOrigin = fromOrigin;
62
50
  ({
@@ -68,23 +56,19 @@ const copyTask = async option => {
68
56
  } else if (globOptions && typeof globOptions === 'object') {
69
57
  options = globOptions;
70
58
  }
71
-
72
- glob = path.isAbsolute(fromOrigin) ? fromOrigin : path.posix.join(_utils.fastGlob.escapePath(normalizePath(path.resolve(context))), fromOrigin); // 计算 glob,获取目标文件
73
-
59
+ glob = path.isAbsolute(fromOrigin) ? fromOrigin : path.posix.join(_utils.fastGlob.escapePath(normalizePath(path.resolve(context))), fromOrigin);
60
+ // 计算 glob,获取目标文件
74
61
  const paths = await (0, _utils.globby)((0, _utils.slash)(glob), options);
75
-
76
62
  if (!paths.length) {
77
63
  return;
78
64
  }
79
-
80
65
  const to = path.normalize(toOrigin ? toOrigin : '');
81
66
  const isToDirectory = path.extname(to) === '';
82
67
  paths.forEach(item => {
83
- const relativeFrom = path.relative(context, item); // 如果 to 是目录,通过相对路径计算完整的产物路径;如果 to 是文件,直接作为最终产物路径
84
-
68
+ const relativeFrom = path.relative(context, item);
69
+ // 如果 to 是目录,通过相对路径计算完整的产物路径;如果 to 是文件,直接作为最终产物路径
85
70
  const fileName = isToDirectory ? path.join(to, relativeFrom) : to;
86
71
  const finalToPath = path.resolve(copyDistDir, fileName);
87
-
88
72
  _utils.fs.copySync(item, finalToPath);
89
73
  });
90
74
  }
@@ -92,5 +76,4 @@ const copyTask = async option => {
92
76
  console.error(`copy error: ${e.message}`);
93
77
  }
94
78
  };
95
-
96
79
  exports.copyTask = copyTask;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.initEnv = void 0;
7
-
8
7
  const initEnv = ({
9
8
  syntax,
10
9
  type
@@ -16,8 +15,6 @@ const initEnv = ({
16
15
  } else if (syntax === 'es5' && type === 'module') {
17
16
  return 'ESM_ES5';
18
17
  }
19
-
20
18
  return '';
21
19
  };
22
-
23
20
  exports.initEnv = initEnv;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.safeParse = void 0;
7
-
8
7
  const safeParse = jsonString => {
9
8
  try {
10
9
  return {
@@ -18,5 +17,4 @@ const safeParse = jsonString => {
18
17
  };
19
18
  }
20
19
  };
21
-
22
20
  exports.safeParse = safeParse;