@modern-js/module-tools 1.21.5 → 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 (94) hide show
  1. package/CHANGELOG.md +83 -46
  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 +14 -19
  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 +13 -15
  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 +13 -35
  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 +1 -3
  90. package/dist/types/hooks/index.d.ts +2 -1
  91. package/dist/types/index.d.ts +2 -2
  92. package/dist/types/schema/types.d.ts +1 -3
  93. package/dist/types/types.d.ts +0 -1
  94. package/package.json +20 -44
@@ -4,36 +4,27 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.buildPlatform = void 0;
7
-
8
7
  var _utils = require("@modern-js/utils");
9
-
10
8
  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; }
11
-
12
9
  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; }
13
-
14
10
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
15
-
16
11
  const lg = _utils.Import.lazy('./logger', require);
17
-
18
12
  const pMap = _utils.Import.lazy('p-map', require);
19
-
20
13
  const buildPlatform = async (api, option) => {
21
14
  const {
22
15
  isTsProject = false,
23
16
  platform
24
17
  } = option;
25
- const lm = new lg.LoggerManager(); // 获取platforms的参数
26
-
18
+ const lm = new lg.LoggerManager();
19
+ // 获取platforms的参数
27
20
  const runners = api.useHookRunners();
28
21
  const buildTasks = await runners.platformBuild({
29
22
  isTsProject
30
23
  });
31
-
32
24
  if (buildTasks.length <= 0) {
33
25
  console.info(_utils.chalk.yellow('No build tasks detected.\nYou can use the `new` command to enable the more features'));
34
26
  return;
35
27
  }
36
-
37
28
  const loggerMap = {};
38
29
  const taskMapper = buildTasks.filter(task => platform === 'all' || task.name === platform).map(params => {
39
30
  const logger = lm.createLoggerText({
@@ -44,12 +35,10 @@ const buildPlatform = async (api, option) => {
44
35
  logger
45
36
  }, params);
46
37
  });
47
-
48
38
  if (taskMapper.length <= 0) {
49
39
  console.info(_utils.chalk.yellow(`'${platform}' is undefined task`));
50
40
  return;
51
41
  }
52
-
53
42
  lm.showCompiling();
54
43
  await pMap(taskMapper, async ({
55
44
  taskPath,
@@ -59,27 +48,29 @@ const buildPlatform = async (api, option) => {
59
48
  const childProcess = _utils.execa.node(taskPath, params, {
60
49
  stdio: 'inherit',
61
50
  all: true
62
- }); // lm.addStdout(logger, childProcess.stdout, {
51
+ });
52
+
53
+ // lm.addStdout(logger, childProcess.stdout, {
63
54
  // event: { data: true, error: true },
64
55
  // });
65
- // lm.addStderr(logger, childProcess.stderr);
66
-
67
56
 
57
+ // lm.addStderr(logger, childProcess.stderr);
68
58
  try {
69
59
  await childProcess;
70
60
  } catch (_unused) {
71
61
  // eslint-disable-next-line no-process-exit
72
62
  process.exit(1);
73
- } // lm.disappearCompiling();
63
+ }
64
+ // lm.disappearCompiling();
74
65
  // console.info(lg.colors.title(title));
75
66
  // console.info(a.all);
76
-
77
67
  }, {
78
68
  concurrency: 1
79
- }); // lm.disappearCompiling();
69
+ });
70
+
71
+ // lm.disappearCompiling();
80
72
  // for (const key of Object.keys(loggerMap)) {
81
73
  // console.info(loggerMap[key].value);
82
74
  // }
83
75
  };
84
-
85
76
  exports.buildPlatform = buildPlatform;
@@ -4,20 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.build = void 0;
7
-
8
7
  var _pMap = _interopRequireDefault(require("p-map"));
9
-
10
8
  var _runSpeedy = require("./runSpeedy");
11
-
12
9
  var _runRollup = require("./runRollup");
13
-
14
10
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
11
  const build = async (api, config) => {
17
12
  const tasks = config.dtsOnly ? [_runRollup.startRollup] : [_runSpeedy.runSpeedy, _runRollup.startRollup];
18
13
  await (0, _pMap.default)(tasks, async task => {
19
14
  await task(api, config);
20
15
  });
21
16
  };
22
-
23
17
  exports.build = build;
@@ -4,48 +4,31 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.startRollup = void 0;
7
-
8
7
  var _path = _interopRequireDefault(require("path"));
9
-
10
8
  var _typescript = _interopRequireDefault(require("typescript"));
11
-
12
9
  var _rollupPluginHashbang = _interopRequireDefault(require("rollup-plugin-hashbang"));
13
-
14
10
  var _pluginJson = _interopRequireDefault(require("@rollup/plugin-json"));
15
-
16
11
  var _error = require("../error");
17
-
18
12
  var _utils = require("../utils");
19
-
20
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
-
24
15
  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; }
25
-
26
16
  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; }
27
-
28
17
  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; }
29
-
30
18
  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; }
31
-
32
19
  // Copied from https://github.com/egoist/tsup/blob/dev/src/rollup.ts
20
+
33
21
  const loadCompilerOptions = tsconfig => {
34
22
  if (!tsconfig) {
35
23
  return {};
36
24
  }
37
-
38
25
  const configFile = _typescript.default.readConfigFile(tsconfig, _typescript.default.sys.readFile);
39
-
40
26
  const {
41
27
  options
42
28
  } = _typescript.default.parseJsonConfigFileContent(configFile.config, _typescript.default.sys, './');
43
-
44
29
  return options;
45
30
  };
46
-
47
31
  const dtsPlugin = require('rollup-plugin-dts');
48
-
49
32
  const getRollupConfig = async (api, options) => {
50
33
  const {
51
34
  appDirectory
@@ -60,38 +43,30 @@ const getRollupConfig = async (api, options) => {
60
43
  bundleOptions,
61
44
  tsconfig
62
45
  } = options;
63
-
64
46
  const distDir = _path.default.join(appDirectory, distPath, outputPath);
65
-
66
47
  const compilerOptions = loadCompilerOptions(tsconfig);
67
48
  const dtsOptions = {
68
49
  entry: bundleOptions.entry
69
50
  };
70
51
  const ignoreFiles = {
71
52
  name: 'ignore-files',
72
-
73
53
  load(id) {
74
54
  if (!/\.(js|jsx|ts|tsx|json)$/.test(id)) {
75
55
  return '';
76
56
  }
77
-
78
57
  return null;
79
58
  }
80
-
81
59
  };
82
60
  return {
83
61
  inputConfig: {
84
62
  input: dtsOptions.entry,
85
63
  external: bundleOptions.externals,
86
-
87
64
  onwarn(warning, handler) {
88
65
  if (warning.code === 'UNRESOLVED_IMPORT' || warning.code === 'CIRCULAR_DEPENDENCY' || warning.code === 'EMPTY_BUNDLE') {
89
66
  return;
90
67
  }
91
-
92
68
  handler(warning);
93
69
  },
94
-
95
70
  plugins: [(0, _rollupPluginHashbang.default)(), (0, _pluginJson.default)(), ignoreFiles, dtsPlugin.default({
96
71
  // use external to prevent them which come from node_modules from be bundled.
97
72
  respectExternal: true,
@@ -121,7 +96,6 @@ const getRollupConfig = async (api, options) => {
121
96
  }
122
97
  };
123
98
  };
124
-
125
99
  async function runRollup(options, context) {
126
100
  try {
127
101
  const {
@@ -137,7 +111,6 @@ async function runRollup(options, context) {
137
111
  }
138
112
  }
139
113
  }
140
-
141
114
  async function watchRollup(options) {
142
115
  const {
143
116
  watch
@@ -151,15 +124,14 @@ async function watchRollup(options) {
151
124
  console.info((0, _utils.watchSectionTitle)(titleText, _utils.SectionTitleStatus.Log));
152
125
  } else if (event.code === 'BUNDLE_END') {
153
126
  console.info((0, _utils.watchSectionTitle)(titleText, _utils.SectionTitleStatus.Success));
154
- } else if (event.code === 'ERROR') {// this is dts rollup plugin bug, error not complete message
127
+ } else if (event.code === 'ERROR') {
128
+ // this is dts rollup plugin bug, error not complete message
155
129
  }
156
130
  });
157
131
  }
158
-
159
132
  const startRollup = async (api, options) => {
160
133
  if (options.enableDts) {
161
134
  const config = await getRollupConfig(api, options);
162
-
163
135
  if (options.watch) {
164
136
  watchRollup(config);
165
137
  } else {
@@ -170,5 +142,4 @@ const startRollup = async (api, options) => {
170
142
  }
171
143
  }
172
144
  };
173
-
174
145
  exports.startRollup = startRollup;
@@ -4,27 +4,16 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.runSpeedy = exports.getDefine = exports.getAlias = void 0;
7
-
8
7
  var _path = _interopRequireDefault(require("path"));
9
-
10
8
  var _speedyCore = require("@speedy-js/speedy-core");
11
-
12
9
  var _speedyPluginEs = require("@speedy-js/speedy-plugin-es5");
13
-
14
10
  var _utils = require("@modern-js/utils");
15
-
16
11
  var _error = require("../error");
17
-
18
12
  var _utils2 = require("../utils");
19
-
20
13
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
14
  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; }
23
-
24
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; }
25
-
26
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; }
27
-
28
17
  const getAlias = api => {
29
18
  const {
30
19
  appDirectory,
@@ -32,8 +21,8 @@ const getAlias = api => {
32
21
  } = api.useAppContext();
33
22
  const {
34
23
  source
35
- } = api.useResolvedConfigContext(); // TODO: maybe check tsconfig `paths`
36
-
24
+ } = api.useResolvedConfigContext();
25
+ // TODO: maybe check tsconfig `paths`
37
26
  const defaultAlias = {
38
27
  '@': srcDirectory
39
28
  };
@@ -44,9 +33,7 @@ const getAlias = api => {
44
33
  });
45
34
  }, {});
46
35
  };
47
-
48
36
  exports.getAlias = getAlias;
49
-
50
37
  const getDefine = api => {
51
38
  const {
52
39
  source: {
@@ -64,9 +51,7 @@ const getDefine = api => {
64
51
  }, {});
65
52
  return _objectSpread(_objectSpread({}, envVarsDefine), globalVarsDefine);
66
53
  };
67
-
68
54
  exports.getDefine = getDefine;
69
-
70
55
  const getStyleOptionFromModern = async api => {
71
56
  const runner = api.useHookRunners();
72
57
  const {
@@ -89,13 +74,10 @@ const getStyleOptionFromModern = async api => {
89
74
  onLast: async _ => undefined
90
75
  });
91
76
  const postcssOption = (0, _utils2.getPostcssOption)(appDirectory, modernConfig);
92
-
93
77
  if (tailwindPlugin) {
94
78
  var _postcssOption$plugin;
95
-
96
79
  (_postcssOption$plugin = postcssOption.plugins) === null || _postcssOption$plugin === void 0 ? void 0 : _postcssOption$plugin.push(tailwindPlugin);
97
80
  }
98
-
99
81
  return {
100
82
  less: lessOption === null || lessOption === void 0 ? void 0 : lessOption.lessOption,
101
83
  sass: sassOption,
@@ -104,7 +86,6 @@ const getStyleOptionFromModern = async api => {
104
86
  })
105
87
  };
106
88
  };
107
-
108
89
  const runSpeedy = async (api, config) => {
109
90
  const {
110
91
  appDirectory
@@ -133,30 +114,24 @@ const runSpeedy = async (api, config) => {
133
114
  externals,
134
115
  getModuleId
135
116
  } = bundleOptions;
136
-
137
117
  const distDir = _path.default.join(appDirectory, distPath, outputPath);
138
-
139
118
  const titleText = `[Bundle:Speedy:${format}_${target}]`;
140
119
  const style = await getStyleOptionFromModern(api);
141
120
  const alias = getAlias(api);
142
121
  const define = getDefine(api);
143
-
144
122
  const watchPlugin = () => {
145
123
  return {
146
124
  name: 'watch-plugin',
147
-
148
125
  apply(compiler) {
149
126
  compiler.hooks.watchChange.tap('watch-plugin', async () => {
150
127
  console.info((0, _utils2.watchSectionTitle)(titleText, _utils2.SectionTitleStatus.Log));
151
128
  });
152
129
  }
153
-
154
130
  };
155
131
  };
156
-
157
132
  const plugins = target === 'es5' ? [(0, _speedyPluginEs.es5InputPlugin)()] : [];
158
- plugins.push(watchPlugin()); // TODO: add speedy plugin about react
159
-
133
+ plugins.push(watchPlugin());
134
+ // TODO: add speedy plugin about react
160
135
  const internalSpeedyConfig = {
161
136
  command: 'build',
162
137
  mode: 'production',
@@ -187,12 +162,10 @@ const runSpeedy = async (api, config) => {
187
162
  };
188
163
  const speedyConfig = (0, _utils.applyOptionsChain)(internalSpeedyConfig, userSpeedyConfig);
189
164
  const compiler = await _speedyCore.SpeedyBundler.create(speedyConfig);
190
-
191
165
  try {
192
166
  if (watch) {
193
167
  console.info((0, _utils2.watchSectionTitle)(titleText, _utils2.SectionTitleStatus.Log));
194
168
  }
195
-
196
169
  await compiler.build();
197
170
  } catch (e) {
198
171
  /**
@@ -208,5 +181,4 @@ const runSpeedy = async (api, config) => {
208
181
  }
209
182
  }
210
183
  };
211
-
212
184
  exports.runSpeedy = runSpeedy;
@@ -4,19 +4,12 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.copyStaticAssets = void 0;
7
-
8
7
  var path = _interopRequireWildcard(require("path"));
9
-
10
8
  var _utils = require("@modern-js/utils");
11
-
12
9
  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); }
13
-
14
10
  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; }
15
-
16
11
  const copyUtils = _utils.Import.lazy('../../../utils/copy', require);
17
-
18
12
  const SRC_DIRS = 'src';
19
-
20
13
  const copyAssets = ({
21
14
  targetDir,
22
15
  outputDir
@@ -24,20 +17,15 @@ const copyAssets = ({
24
17
  const assetsFiles = _utils.glob.sync(`${targetDir}/**/*.*`, {
25
18
  ignore: ['**/*.{js,jsx,ts,tsx,d.ts,scss,less,css,sass}']
26
19
  });
27
-
28
20
  if (assetsFiles.length > 0) {
29
21
  _utils.fs.ensureDirSync(outputDir);
30
22
  }
31
-
32
23
  for (const resource of assetsFiles) {
33
24
  const file = path.relative(targetDir, resource);
34
-
35
25
  _utils.fs.ensureDirSync(path.dirname(path.resolve(outputDir, file)));
36
-
37
26
  _utils.fs.copyFileSync(resource, path.resolve(outputDir, file));
38
27
  }
39
28
  };
40
-
41
29
  const watchAssets = (api, {
42
30
  targetDir,
43
31
  outputDir
@@ -48,21 +36,15 @@ const watchAssets = (api, {
48
36
  }) => {
49
37
  if (changeType === _utils.WatchChangeType.UNLINK) {
50
38
  const removeFile = path.normalize(`${outputDir}/${path.relative(targetDir, changedFilePath)}`);
51
-
52
39
  _utils.fs.removeSync(removeFile);
53
-
54
40
  return;
55
41
  }
56
-
57
42
  const file = path.relative(targetDir, changedFilePath);
58
-
59
43
  _utils.fs.copyFileSync(changedFilePath, path.resolve(outputDir, file));
60
44
  }, ['**/*.{js,jsx,ts,tsx,d.ts,scss,less,css,sass}']);
61
45
  };
62
-
63
46
  const copyStaticAssets = async (api, config) => {
64
47
  var _bundlelessOptions$so;
65
-
66
48
  const appContext = api.useAppContext();
67
49
  const modernConfig = api.useResolvedConfigContext();
68
50
  const {
@@ -92,7 +74,6 @@ const copyStaticAssets = async (api, config) => {
92
74
  modernConfig,
93
75
  appContext
94
76
  });
95
-
96
77
  if (config.watch) {
97
78
  watchAssets(api, {
98
79
  targetDir: srcDir,
@@ -100,5 +81,4 @@ const copyStaticAssets = async (api, config) => {
100
81
  });
101
82
  }
102
83
  };
103
-
104
84
  exports.copyStaticAssets = copyStaticAssets;
@@ -4,34 +4,23 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.genDts = void 0;
7
-
8
7
  var _path = _interopRequireDefault(require("path"));
9
-
10
8
  var _utils = require("@modern-js/utils");
11
-
12
9
  var _error = require("../../error");
13
-
14
10
  var _utils2 = require("../../utils");
15
-
16
11
  var _utils3 = require("./utils");
17
-
18
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
13
  const utils = _utils.Import.lazy('./utils', require);
21
-
22
14
  const getProjectTsconfig = tsconfigPath => {
23
15
  if (!tsconfigPath || !_utils.fs.existsSync(tsconfigPath)) {
24
16
  return {};
25
17
  }
26
-
27
18
  return _utils.json5.parse(_utils.fs.readFileSync(tsconfigPath, 'utf-8'));
28
19
  };
29
-
30
20
  const resolveLog = (childProgress, {
31
21
  watch: _watch = false
32
22
  } = {}) => {
33
23
  var _childProgress$stdout, _childProgress$stdout2, _childProgress$stderr;
34
-
35
24
  /**
36
25
  * tsc 所有的log信息都是从stdout data 事件中获取
37
26
  * 正常模式下,如果有报错信息,交给 resolveLog 后面的逻辑来处理
@@ -42,8 +31,8 @@ const resolveLog = (childProgress, {
42
31
  console.info((0, _utils2.watchSectionTitle)('[Bundleless:DTS]', _utils2.SectionTitleStatus.Log));
43
32
  console.info(data.toString());
44
33
  }
45
- }); // 正常以下内容都不会触发,因为tsc 不会产生以下类型的log信息,不过防止意外情况
46
-
34
+ });
35
+ // 正常以下内容都不会触发,因为tsc 不会产生以下类型的log信息,不过防止意外情况
47
36
  (_childProgress$stdout2 = childProgress.stdout) === null || _childProgress$stdout2 === void 0 ? void 0 : _childProgress$stdout2.on('error', error => {
48
37
  console.error(error.message);
49
38
  });
@@ -51,7 +40,6 @@ const resolveLog = (childProgress, {
51
40
  console.error(chunk.toString());
52
41
  });
53
42
  };
54
-
55
43
  const generatorDts = async (_, config) => {
56
44
  const {
57
45
  tsconfigPath,
@@ -68,9 +56,9 @@ const generatorDts = async (_, config) => {
68
56
  });
69
57
  const tscBinFile = (0, _utils3.getTscBinPath)(appDirectory);
70
58
  const watchParams = watch ? ['-w'] : [];
71
- const childProgress = (0, _utils.execa)(tscBinFile, ['-p', willDeleteTsconfigPath,
72
- /* Required parameter, use it stdout have color */
73
- '--pretty', // https://github.com/microsoft/TypeScript/issues/21824
59
+ const childProgress = (0, _utils.execa)(tscBinFile, ['-p', willDeleteTsconfigPath, /* Required parameter, use it stdout have color */
60
+ '--pretty',
61
+ // https://github.com/microsoft/TypeScript/issues/21824
74
62
  '--preserveWatchOutput', ...watchParams], {
75
63
  stdio: 'pipe',
76
64
  cwd: appDirectory
@@ -78,7 +66,6 @@ const generatorDts = async (_, config) => {
78
66
  resolveLog(childProgress, {
79
67
  watch
80
68
  });
81
-
82
69
  try {
83
70
  await childProgress;
84
71
  } catch (e) {
@@ -88,10 +75,8 @@ const generatorDts = async (_, config) => {
88
75
  });
89
76
  }
90
77
  }
91
-
92
78
  _utils.fs.removeSync(willDeleteTsconfigPath);
93
79
  };
94
-
95
80
  const genDts = async (api, config) => {
96
81
  const {
97
82
  outputPath,
@@ -102,11 +87,9 @@ const genDts = async (api, config) => {
102
87
  },
103
88
  enableDts
104
89
  } = config;
105
-
106
90
  if (!enableDts) {
107
91
  return;
108
92
  }
109
-
110
93
  const {
111
94
  appDirectory
112
95
  } = api.useAppContext();
@@ -116,9 +99,7 @@ const genDts = async (api, config) => {
116
99
  path: distPath = 'dist'
117
100
  }
118
101
  } = modernConfig;
119
-
120
102
  const distDir = _path.default.join(appDirectory, distPath, outputPath);
121
-
122
103
  const option = {
123
104
  appDirectory,
124
105
  distDir,
@@ -126,9 +107,8 @@ const genDts = async (api, config) => {
126
107
  watch,
127
108
  sourceDir
128
109
  };
129
- await generatorDts(modernConfig, option); // TODO: watch 模式下无法转换
130
-
110
+ await generatorDts(modernConfig, option);
111
+ // TODO: watch 模式下无法转换
131
112
  utils.resolveAlias(modernConfig, option);
132
113
  };
133
-
134
114
  exports.genDts = genDts;
@@ -4,44 +4,32 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.resolveAlias = exports.getTscBinPath = exports.generatorTsConfig = void 0;
7
-
8
7
  var path = _interopRequireWildcard(require("path"));
9
-
10
8
  var _utils = require("@modern-js/utils");
11
-
12
9
  var _lodash = require("@modern-js/utils/lodash");
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 ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
19
-
20
13
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
21
-
22
14
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
23
-
24
15
  const babel = _utils.Import.lazy('../../../../utils/babel', require);
25
-
26
16
  const tsPathsTransform = _utils.Import.lazy('../../../../utils/tspaths-transform', require);
27
-
28
17
  const generatorTsConfig = (projectTsconfig, {
29
18
  appDirectory,
30
19
  distDir,
31
20
  sourceDir: _sourceDir = 'src'
32
21
  }) => {
33
22
  var _projectTsconfig$comp, _projectTsconfig$comp2, _ref, _projectTsconfig$excl;
34
-
35
23
  const tempPath = path.resolve(appDirectory, './node_modules');
36
- const resolvePath = path.relative(tempPath, appDirectory); // const rootDir = projectTsconfig.compilerOptions?.rootDir
24
+ const resolvePath = path.relative(tempPath, appDirectory);
25
+ // const rootDir = projectTsconfig.compilerOptions?.rootDir
37
26
  // ? path.join(resolvePath, projectTsconfig.compilerOptions?.rootDir)
38
27
  // : resolvePath;
39
28
  // 目前限制 rootDir 的路径为 sourceDir
40
-
41
29
  const rootDir = path.join(resolvePath, _sourceDir);
42
- const baseUrl = (_projectTsconfig$comp = projectTsconfig.compilerOptions) !== null && _projectTsconfig$comp !== void 0 && _projectTsconfig$comp.baseUrl ? path.join(appDirectory, (_projectTsconfig$comp2 = projectTsconfig.compilerOptions) === null || _projectTsconfig$comp2 === void 0 ? void 0 : _projectTsconfig$comp2.baseUrl) : appDirectory; // if include = ['src'], final include should be ['../src']
30
+ const baseUrl = (_projectTsconfig$comp = projectTsconfig.compilerOptions) !== null && _projectTsconfig$comp !== void 0 && _projectTsconfig$comp.baseUrl ? path.join(appDirectory, (_projectTsconfig$comp2 = projectTsconfig.compilerOptions) === null || _projectTsconfig$comp2 === void 0 ? void 0 : _projectTsconfig$comp2.baseUrl) : appDirectory;
31
+ // if include = ['src'], final include should be ['../src']
43
32
  // const include = projectTsconfig.include?.map(includePath =>
44
-
45
33
  const include = (_ref = [_sourceDir]) === null || _ref === void 0 ? void 0 : _ref.map(includePath => path.join(resolvePath, includePath));
46
34
  const exclude = (_projectTsconfig$excl = projectTsconfig.exclude) === null || _projectTsconfig$excl === void 0 ? void 0 : _projectTsconfig$excl.map(excludePath => path.join(resolvePath, excludePath));
47
35
  const resetConfig = {
@@ -56,11 +44,9 @@ const generatorTsConfig = (projectTsconfig, {
56
44
  include,
57
45
  exclude
58
46
  };
59
-
60
47
  if (projectTsconfig.extends) {
61
48
  resetConfig.extends = projectTsconfig.extends.startsWith('.') ? path.join(resolvePath, projectTsconfig.extends) : projectTsconfig.extends;
62
49
  }
63
-
64
50
  const recommendOption = {
65
51
  // Ensure that Babel can safely transpile files in the TypeScript project
66
52
  compilerOptions: {
@@ -68,17 +54,13 @@ const generatorTsConfig = (projectTsconfig, {
68
54
  }
69
55
  };
70
56
  const tempTsconfigPath = path.join(tempPath, `tsconfig.${Date.now()}.${(0, _utils.nanoid)()}.json`);
71
-
72
57
  _utils.fs.ensureFileSync(tempTsconfigPath);
73
-
74
- _utils.fs.writeJSONSync(tempTsconfigPath, (0, _lodash.merge)(recommendOption, projectTsconfig, // 此处是必须要覆盖用户默认配置
58
+ _utils.fs.writeJSONSync(tempTsconfigPath, (0, _lodash.merge)(recommendOption, projectTsconfig,
59
+ // 此处是必须要覆盖用户默认配置
75
60
  resetConfig));
76
-
77
61
  return tempTsconfigPath;
78
62
  };
79
-
80
63
  exports.generatorTsConfig = generatorTsConfig;
81
-
82
64
  const resolveAlias = (modernConfig, config, watchFilenames = []) => {
83
65
  const {
84
66
  output
@@ -101,31 +83,23 @@ const resolveAlias = (modernConfig, config, watchFilenames = []) => {
101
83
  baseUrl: path.join(config.appDirectory, output.path || 'dist'),
102
84
  paths: mergedPaths
103
85
  });
104
-
105
86
  for (const r of result) {
106
87
  _utils.fs.writeFileSync(r.path, r.content);
107
88
  }
108
89
  };
109
-
110
90
  exports.resolveAlias = resolveAlias;
111
-
112
91
  const getTscBinPath = appDirectory => {
113
92
  const {
114
93
  root
115
94
  } = path.parse(appDirectory);
116
95
  let currentDirectory = appDirectory;
117
-
118
96
  while (currentDirectory !== root) {
119
97
  const tscBinFile = path.join(currentDirectory, './node_modules/.bin/tsc');
120
-
121
98
  if (_utils.fs.existsSync(tscBinFile)) {
122
99
  return tscBinFile;
123
100
  }
124
-
125
101
  currentDirectory = path.dirname(currentDirectory);
126
102
  }
127
-
128
103
  throw new Error('Failed to excute the `tsc` command, please check if `typescript` is installed correctly in the current directory.');
129
104
  };
130
-
131
105
  exports.getTscBinPath = getTscBinPath;