@modern-js/module-tools 1.6.0-alpha.0 → 1.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/CHANGELOG.md +67 -27
  2. package/dist/js/modern/commands/build.js +19 -5
  3. package/dist/js/modern/features/build/bundle/index.js +5 -2
  4. package/dist/js/modern/features/build/bundle/runSpeedy.js +3 -3
  5. package/dist/js/modern/features/build/bundleless/generator-dts/utils.js +5 -5
  6. package/dist/js/modern/features/build/bundleless/index.js +12 -2
  7. package/dist/js/modern/features/build/bundleless/runBabel.js +2 -2
  8. package/dist/js/modern/features/build/bundleless/style.js +2 -2
  9. package/dist/js/modern/features/build/index.js +20 -16
  10. package/dist/js/modern/features/build/normalize.js +21 -13
  11. package/dist/js/modern/features/build/utils.js +12 -1
  12. package/dist/js/modern/index.js +1 -0
  13. package/dist/js/modern/schema/build-config.js +10 -3
  14. package/dist/js/modern/utils/babel.js +2 -0
  15. package/dist/js/modern/utils/copy.js +2 -2
  16. package/dist/js/node/commands/build.js +18 -6
  17. package/dist/js/node/features/build/bundle/index.js +8 -2
  18. package/dist/js/node/features/build/bundle/runSpeedy.js +3 -3
  19. package/dist/js/node/features/build/bundleless/generator-dts/utils.js +4 -5
  20. package/dist/js/node/features/build/bundleless/index.js +16 -2
  21. package/dist/js/node/features/build/bundleless/runBabel.js +1 -1
  22. package/dist/js/node/features/build/bundleless/style.js +1 -1
  23. package/dist/js/node/features/build/index.js +27 -14
  24. package/dist/js/node/features/build/normalize.js +20 -12
  25. package/dist/js/node/features/build/utils.js +19 -2
  26. package/dist/js/node/index.js +17 -0
  27. package/dist/js/node/schema/build-config.js +10 -3
  28. package/dist/js/node/utils/babel.js +5 -0
  29. package/dist/js/node/utils/copy.js +1 -1
  30. package/dist/types/features/build/bundle/runSpeedy.d.ts +1 -1
  31. package/dist/types/features/build/index.d.ts +9 -1
  32. package/dist/types/features/build/normalize.d.ts +2 -1
  33. package/dist/types/features/build/utils.d.ts +2 -1
  34. package/dist/types/index.d.ts +1 -0
  35. package/dist/types/schema/build-config.d.ts +22 -4
  36. package/dist/types/schema/index.d.ts +22 -4
  37. package/dist/types/schema/output.d.ts +22 -4
  38. package/dist/types/schema/types.d.ts +1 -0
  39. package/package.json +19 -17
package/CHANGELOG.md CHANGED
@@ -1,38 +1,78 @@
1
1
  # @modern-js/module-tools
2
2
 
3
- ## 1.6.0-alpha.0
3
+ ## 1.6.2
4
+
5
+ ### Patch Changes
6
+
7
+ - ff3ba0220: fix(babel-preset-module): babel transform import path of the style file or the static file
8
+
9
+ fix(babel-preset-module): 修复 Babel 在转换导入样式文件或者静态文件的路径出现的问题
10
+
11
+ - Updated dependencies [ff3ba0220]
12
+ - @modern-js/babel-preset-module@1.3.11
13
+
14
+ ## 1.6.1
15
+
16
+ ### Patch Changes
17
+
18
+ - nothing happen, only bump
19
+ - Updated dependencies
20
+ - @modern-js/babel-preset-module@1.3.10
21
+ - @modern-js/core@1.12.4
22
+ - @modern-js/style-compiler@1.2.12
23
+ - @modern-js/utils@1.7.11
24
+ - @modern-js/css-config@1.2.7
25
+ - @modern-js/plugin-analyze@1.4.7
26
+ - @modern-js/plugin-changeset@1.3.1
27
+ - @modern-js/plugin-jarvis@1.2.14
28
+
29
+ ## 1.6.0
4
30
 
5
31
  ### Minor Changes
6
32
 
7
- - 9cd364e06: refactor build feature and support bundle build
33
+ - b82869d: - use speedy as a bundler to support bundle, and support dts and css bundle.
34
+ - design `buildConfig` to support build for different scene, and design `buildPreset` to cover most of scenes.
35
+ - add `tools.speedy` to receive custom speedy config.
36
+ - remove child process to solving problems with serialisation parameters.
37
+ - add more test cases, improve quality construction.
38
+ - design a new log about build process
39
+
40
+ ### Patch Changes
41
+
42
+ - Updated dependencies [b82869d]
43
+ - Updated dependencies [b82869d]
44
+ - Updated dependencies [b82869d]
45
+ - Updated dependencies [b82869d]
46
+ - @modern-js/utils@1.7.10
47
+ - @modern-js/babel-preset-module@1.3.9
48
+ - @modern-js/core@1.12.3
49
+ - @modern-js/style-compiler@1.2.11
50
+ - @modern-js/css-config@1.2.7
51
+ - @modern-js/plugin-analyze@1.4.7
52
+ - @modern-js/plugin-changeset@1.3.1
53
+ - @modern-js/plugin-jarvis@1.2.14
54
+
55
+ ## 1.5.8
8
56
 
9
57
  ### Patch Changes
10
58
 
11
- - 9cd364e06: fix type error, add some test case
12
- - 9cd364e06: The buildPreset will be split out of a buildConfig, preset only supports built-in strings, config this piece to remove speedyOptions, watch, add platform, splitting, minify, external, and add tools.speedy
13
- - eeedc8005: feat: add plugin-jarvis to dependencies of solutions
14
- - f29e9bacf: feat: simplify context usage, no longer depend on containers
15
- - 9cd364e06: add buildPreset config, support bundle
16
- - Updated dependencies [9cd364e06]
17
- - Updated dependencies [9cd364e06]
18
- - Updated dependencies [9cd364e06]
19
- - Updated dependencies [f29e9bacf]
20
- - Updated dependencies [1a5759578]
21
- - Updated dependencies [9cd364e06]
22
- - Updated dependencies [f29e9bacf]
23
- - Updated dependencies [a90bc96bd]
24
- - @modern-js/utils@1.7.9-alpha.0
25
- - @modern-js/babel-preset-module@1.4.0-alpha.0
26
- - @modern-js/core@1.12.2-alpha.0
27
- - @modern-js/plugin-analyze@1.4.7-alpha.0
28
- - @modern-js/plugin-jarvis@1.2.14-alpha.0
29
- - @modern-js/style-compiler@1.2.11-alpha.0
30
- - @modern-js/plugin@1.4.0-alpha.0
31
- - @modern-js/css-config@1.2.8-alpha.0
32
- - @modern-js/plugin-changeset@1.3.1-alpha.0
33
- - @modern-js/plugin-i18n@1.2.8-alpha.0
34
- - @modern-js/new-action@1.3.11-alpha.0
35
- - @modern-js/babel-compiler@1.2.7-alpha.0
59
+ - eeedc80: feat: add plugin-jarvis to dependencies of solutions
60
+ - f29e9ba: feat: simplify context usage, no longer depend on containers
61
+ - Updated dependencies [f29e9ba]
62
+ - Updated dependencies [d9564f2]
63
+ - Updated dependencies [1a57595]
64
+ - Updated dependencies [42741db]
65
+ - Updated dependencies [341bb42]
66
+ - Updated dependencies [f29e9ba]
67
+ - Updated dependencies [a90bc96]
68
+ - @modern-js/core@1.12.2
69
+ - @modern-js/plugin-analyze@1.4.7
70
+ - @modern-js/plugin-jarvis@1.2.14
71
+ - @modern-js/plugin-changeset@1.3.1
72
+ - @modern-js/new-action@1.3.11
73
+ - @modern-js/plugin@1.4.0
74
+ - @modern-js/utils@1.7.9
75
+ - @modern-js/css-config@1.2.7
36
76
 
37
77
  ## 1.5.7
38
78
 
@@ -1,7 +1,6 @@
1
1
  import * as path from 'path';
2
- import { fs, Import, dotenv } from '@modern-js/utils';
2
+ import { fs, Import, dotenv, globby, slash } from '@modern-js/utils';
3
3
  import onExit from 'signal-exit';
4
- import { tempTsconfigName } from "../utils/constants";
5
4
  const tsConfigutils = Import.lazy('../utils/tsconfig', require);
6
5
  const valid = Import.lazy('../utils/valide', require);
7
6
  const buildFeature = Import.lazy('../features/build', require);
@@ -15,9 +14,24 @@ export const init = api => {
15
14
  appDirectory
16
15
  } = api.useAppContext();
17
16
  dotenv.config();
18
- onExit(() => {
19
- const tempTsconfigFileAbsPath = path.join(appDirectory, './node_modules', `./${tempTsconfigName}`);
20
- fs.removeSync(tempTsconfigFileAbsPath);
17
+ onExit(async code => {
18
+ if (code === 0) {
19
+ return;
20
+ }
21
+
22
+ const tempTsconfigPathPattern = path.join(appDirectory, './node_modules', `./tsconfig.**.**.json`);
23
+ const files = globby(slash(tempTsconfigPathPattern), {
24
+ stats: true,
25
+ absolute: true
26
+ });
27
+ const currentTime = Date.now();
28
+
29
+ for (const file of files) {
30
+ // over 30s, will delete it
31
+ if (currentTime - file.stats.birthtimeMs >= 30 * 1000) {
32
+ fs.unlinkSync(file.path);
33
+ }
34
+ }
21
35
  });
22
36
  };
23
37
  export const build = async (api, buildCommandOption) => {
@@ -1,6 +1,9 @@
1
+ import pMap from 'p-map';
1
2
  import { runSpeedy } from "./runSpeedy";
2
3
  import { startRollup } from "./runRollup";
3
4
  export const build = async (api, config) => {
4
- const tasks = config.dtsOnly ? [startRollup(api, config)] : [runSpeedy(api, config), startRollup(api, config)];
5
- await Promise.all(tasks);
5
+ const tasks = config.dtsOnly ? [startRollup] : [runSpeedy, startRollup];
6
+ await pMap(tasks, async task => {
7
+ await task(api, config);
8
+ });
6
9
  };
@@ -36,7 +36,7 @@ export const getDefine = api => {
36
36
  globalVars
37
37
  }
38
38
  } = api.useResolvedConfigContext();
39
- const envVarsDefine = ['NODE_ENV', ...(envVars || [])].reduce((memo, name) => {
39
+ const envVarsDefine = [...(envVars || [])].reduce((memo, name) => {
40
40
  memo[`process.env.${name}`] = JSON.stringify(process.env[name]);
41
41
  return memo;
42
42
  }, {});
@@ -114,7 +114,7 @@ export const runSpeedy = async (api, config) => {
114
114
  } = bundleOptions;
115
115
  const distDir = path.join(appDirectory, distPath, outputPath);
116
116
  const titleText = `[Bundle:Speedy:${format}_${target}]`;
117
- await getStyleOptionFromModern(api);
117
+ const style = await getStyleOptionFromModern(api);
118
118
  const alias = getAlias(api);
119
119
  const define = getDefine(api);
120
120
 
@@ -150,7 +150,7 @@ export const runSpeedy = async (api, config) => {
150
150
  splitting,
151
151
  filename: '[name]'
152
152
  },
153
- // style,
153
+ style,
154
154
  resolve: {
155
155
  alias
156
156
  },
@@ -5,17 +5,16 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
7
  import * as path from 'path';
8
- import { Import, glob, fs } from '@modern-js/utils';
8
+ import { Import, glob, fs, nanoid } from '@modern-js/utils';
9
9
  import { merge as deepMerge } from '@modern-js/utils/lodash';
10
10
  const babel = Import.lazy('../../../../utils/babel', require);
11
11
  const tsPathsTransform = Import.lazy('../../../../utils/tspaths-transform', require);
12
- const constants = Import.lazy('../../../../utils/constants', require);
13
12
  export const generatorTsConfig = (projectTsconfig, {
14
13
  appDirectory,
15
14
  distDir,
16
15
  sourceDir: _sourceDir = 'src'
17
16
  }) => {
18
- var _projectTsconfig$comp, _projectTsconfig$comp2, _projectTsconfig$incl, _projectTsconfig$excl;
17
+ var _projectTsconfig$comp, _projectTsconfig$comp2, _ref, _projectTsconfig$excl;
19
18
 
20
19
  const tempPath = path.resolve(appDirectory, './node_modules');
21
20
  const resolvePath = path.relative(tempPath, appDirectory); // const rootDir = projectTsconfig.compilerOptions?.rootDir
@@ -25,8 +24,9 @@ export const generatorTsConfig = (projectTsconfig, {
25
24
 
26
25
  const rootDir = path.join(resolvePath, _sourceDir);
27
26
  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']
27
+ // const include = projectTsconfig.include?.map(includePath =>
28
28
 
29
- const include = (_projectTsconfig$incl = projectTsconfig.include) === null || _projectTsconfig$incl === void 0 ? void 0 : _projectTsconfig$incl.map(includePath => path.join(resolvePath, includePath));
29
+ const include = (_ref = [_sourceDir]) === null || _ref === void 0 ? void 0 : _ref.map(includePath => path.join(resolvePath, includePath));
30
30
  const exclude = (_projectTsconfig$excl = projectTsconfig.exclude) === null || _projectTsconfig$excl === void 0 ? void 0 : _projectTsconfig$excl.map(excludePath => path.join(resolvePath, excludePath));
31
31
  const resetConfig = {
32
32
  compilerOptions: {
@@ -46,7 +46,7 @@ export const generatorTsConfig = (projectTsconfig, {
46
46
  isolatedModules: true
47
47
  }
48
48
  };
49
- const tempTsconfigPath = path.join(tempPath, constants.tempTsconfigName);
49
+ const tempTsconfigPath = path.join(tempPath, `tsconfig.${Date.now()}.${nanoid()}.json`);
50
50
  fs.ensureFileSync(tempTsconfigPath);
51
51
  fs.writeJSONSync(tempTsconfigPath, deepMerge(recommendOption, projectTsconfig, // 此处是必须要覆盖用户默认配置
52
52
  resetConfig));
@@ -1,13 +1,23 @@
1
+ import { chalk } from '@modern-js/utils';
2
+ import pMap from 'p-map';
1
3
  import { runBabelBuild } from "./runBabel";
2
4
  import { buildStyle } from "./style";
3
5
  import { genDts } from "./generator-dts";
4
6
  import { copyStaticAssets } from "./copy-assets";
5
7
  export const build = async (api, config, legacyOptions) => {
8
+ // valid format is umd
9
+ if (config.format === 'umd') {
10
+ console.info(chalk.yellowBright('bundleless 构建暂时不支持 umd 格式'));
11
+ return;
12
+ }
13
+
6
14
  if (legacyOptions !== null && legacyOptions !== void 0 && legacyOptions.styleOnly) {
7
15
  await buildStyle(api, config);
8
16
  return;
9
17
  }
10
18
 
11
- const tasks = config.dtsOnly ? [genDts(api, config)] : [runBabelBuild(api, config), genDts(api, config), buildStyle(api, config), copyStaticAssets(api, config)];
12
- await Promise.all(tasks);
19
+ const tasks = config.dtsOnly ? [genDts] : [runBabelBuild, genDts, buildStyle, copyStaticAssets];
20
+ await pMap(tasks, async task => {
21
+ await task(api, config);
22
+ });
13
23
  };
@@ -5,7 +5,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
7
  import path from 'path';
8
- import { Import, glob, fs, chalk, globby } from '@modern-js/utils';
8
+ import { Import, glob, fs, chalk, globby, slash } from '@modern-js/utils';
9
9
  import { InternalBuildError } from "../error";
10
10
  import { SectionTitleStatus, watchSectionTitle } from "../utils";
11
11
  export class BabelBuildError extends Error {
@@ -167,7 +167,7 @@ const outputDist = (outputResults, context) => {
167
167
 
168
168
  export const jsFileSuffix = ['js', 'jsx', 'ts', 'tsx'];
169
169
  export const haveNotAnyJsFile = async sourceDir => {
170
- const files = await globby(`${sourceDir}/**/*.{${jsFileSuffix.join(',')}}`);
170
+ const files = await globby(slash(`${sourceDir}/**/*.{${jsFileSuffix.join(',')}}`));
171
171
  return files.length === 0;
172
172
  };
173
173
  export const runBabelBuild = async (api, config) => {
@@ -5,7 +5,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
5
5
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
6
 
7
7
  import * as path from 'path';
8
- import { fs, glob, Import, watch as watcher, WatchChangeType, chalk, globby } from '@modern-js/utils';
8
+ import { fs, glob, Import, watch as watcher, WatchChangeType, chalk, globby, slash } from '@modern-js/utils';
9
9
  import { InternalBuildError } from "../error";
10
10
  import { watchSectionTitle, SectionTitleStatus, getPostcssOption } from "../utils";
11
11
  const compiler = Import.lazy('@modern-js/style-compiler', require);
@@ -147,7 +147,7 @@ export const runBuild = async option => {
147
147
  };
148
148
  export const styleFileSuffix = ['css', 'less', 'sass', 'scss'];
149
149
  export const haveNotAnyStyles = async sourceDir => {
150
- const files = await globby(`${sourceDir}/**/*.{${styleFileSuffix.join(',')}}`);
150
+ const files = await globby(slash(`${sourceDir}/**/*.{${styleFileSuffix.join(',')}}`));
151
151
  return files.length === 0;
152
152
  };
153
153
  export const buildStyle = async (api, config) => {
@@ -1,14 +1,15 @@
1
1
  import path from 'path';
2
2
  import { Import, fs, chalk } from '@modern-js/utils';
3
+ import pMap from 'p-map';
3
4
  import { ReadlineUtils } from "../../utils/readline";
4
5
  import { normalizeModuleConfig } from "./normalize";
5
6
  import { buildingText, buildSuccessText } from "./constants";
6
7
  import { ModuleBuildError, isInternalError } from "./error";
8
+ import { getAllDeps } from "./utils";
7
9
  const bundle = Import.lazy('./bundle', require);
8
10
  const bundleless = Import.lazy('./bundleless', require);
9
11
  const bp = Import.lazy('./build-platform', require);
10
-
11
- const checkPlatformAndRunBuild = async (platform, options) => {
12
+ export const checkPlatformAndRunBuild = async (platform, options) => {
12
13
  const {
13
14
  api,
14
15
  isTsProject
@@ -44,14 +45,22 @@ const checkPlatformAndRunBuild = async (platform, options) => {
44
45
  exit: false
45
46
  };
46
47
  };
47
-
48
- export const buildInNormalMode = async buildTasks => {
48
+ export const runBuild = async (api, normalizedModuleConfig, config) => {
49
+ await pMap(normalizedModuleConfig, async moduleConfig => {
50
+ if (moduleConfig.buildType === 'bundle') {
51
+ await bundle.build(api, moduleConfig);
52
+ } else {
53
+ await bundleless.build(api, moduleConfig, config);
54
+ }
55
+ });
56
+ };
57
+ export const buildInNormalMode = async (api, normalizedModuleConfig, config) => {
49
58
  console.info(chalk.blue.bold(buildingText));
50
59
 
51
60
  try {
52
61
  // eslint-disable-next-line no-console
53
62
  console.time(buildSuccessText);
54
- await Promise.all(buildTasks);
63
+ await runBuild(api, normalizedModuleConfig, config);
55
64
  ReadlineUtils.clearPrevLine(process.stdout); // eslint-disable-next-line no-console
56
65
 
57
66
  console.timeEnd(buildSuccessText);
@@ -92,25 +101,20 @@ export const build = async (api, config) => {
92
101
 
93
102
  if (clear) {
94
103
  fs.removeSync(path.join(appDirectory, outputPath));
95
- } // should normalize module tool config here, ensure the same config for build
104
+ }
96
105
 
106
+ const deps = getAllDeps(appDirectory); // should normalize module tool config here, ensure the same config for build
97
107
 
98
108
  const normalizedModuleConfig = normalizeModuleConfig({
99
109
  buildFeatOption: config,
100
- api
101
- });
102
- const buildTasks = normalizedModuleConfig.map(moduleConfig => {
103
- if (moduleConfig.buildType === 'bundle') {
104
- return bundle.build(api, moduleConfig);
105
- } else {
106
- return bundleless.build(api, moduleConfig, config);
107
- }
110
+ api,
111
+ deps
108
112
  });
109
113
 
110
114
  if (config.enableWatchMode) {
111
115
  console.info(chalk.blue.underline('start build in watch mode...\n'));
112
- await Promise.all(buildTasks);
116
+ await runBuild(api, normalizedModuleConfig, config);
113
117
  } else {
114
- await buildInNormalMode(buildTasks);
118
+ await buildInNormalMode(api, normalizedModuleConfig, config);
115
119
  }
116
120
  };
@@ -4,6 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
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
 
7
+ /* eslint-disable max-lines */
7
8
  import { Import, lodash } from '@modern-js/utils';
8
9
  import { mergeWith } from '@modern-js/utils/lodash';
9
10
  import { cliTsConfigDefaultValue } from "../../utils/constants";
@@ -93,15 +94,15 @@ export const getNormalizeModuleConfigByPackageModeAndFileds = (api, buildFeatOpt
93
94
 
94
95
 
95
96
  if (packageFields['jsnext:modern']) {
96
- configs.push(getConfigsByJsSyntaxType(packageFields['jsnext:modern'], 'modern'));
97
+ configs.push(getConfigsByJsSyntaxType(packageFields['jsnext:modern'], 'js/modern'));
97
98
  }
98
99
 
99
100
  if (packageFields.main) {
100
- configs.push(getConfigsByJsSyntaxType(packageFields.main, 'node'));
101
+ configs.push(getConfigsByJsSyntaxType(packageFields.main, 'js/node'));
101
102
  }
102
103
 
103
104
  if (packageFields.module) {
104
- configs.push(getConfigsByJsSyntaxType(packageFields.module, 'treeshaking'));
105
+ configs.push(getConfigsByJsSyntaxType(packageFields.module, 'js/treeshaking'));
105
106
  }
106
107
  }
107
108
 
@@ -181,27 +182,32 @@ export const getSourceMap = (config, buildType, api) => {
181
182
 
182
183
  return buildType === 'bundle';
183
184
  };
184
- export const normalizeBuildConfig = (context, buildConfig) => {
185
+ export const normalizeBuildConfig = (context, buildConfig, deps = []) => {
185
186
  const {
186
187
  buildFeatOption,
187
188
  api
188
189
  } = context;
189
190
  const configArray = Array.isArray(buildConfig) ? buildConfig : [buildConfig];
190
191
  const normalizedModule = configArray.map(config => {
191
- var _config$format, _config$target, _bundleOptions$minify, _config$outputPath, _config$dtsOnly;
192
+ var _config$format, _config$target, _bundleOptions$skipDe, _bundleOptions$minify, _bundleOptions$splitt, _config$outputPath, _config$dtsOnly;
192
193
 
193
194
  const format = (_config$format = config.format) !== null && _config$format !== void 0 ? _config$format : 'cjs';
194
195
  const target = (_config$target = config.target) !== null && _config$target !== void 0 ? _config$target : 'esnext';
195
196
  const {
196
197
  bundleOptions
197
198
  } = config;
199
+ const skipDeps = (_bundleOptions$skipDe = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.skipDeps) !== null && _bundleOptions$skipDe !== void 0 ? _bundleOptions$skipDe : true;
200
+ const externals = skipDeps === false ? (bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.externals) || [] : [...deps.map(dep => new RegExp(`^${dep}($|\\/|\\\\)`)), ...((bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.externals) || [])];
198
201
 
199
202
  const normalizedBundleOption = _objectSpread(_objectSpread({}, bundleOptions), {}, {
200
203
  entry: (bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.entry) || {
201
204
  index: `src/index.${buildFeatOption.isTsProject ? 'ts' : 'js'}`
202
205
  },
203
206
  platform: (bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.platform) || 'node',
204
- minify: (_bundleOptions$minify = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.minify) !== null && _bundleOptions$minify !== void 0 ? _bundleOptions$minify : false
207
+ minify: (_bundleOptions$minify = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.minify) !== null && _bundleOptions$minify !== void 0 ? _bundleOptions$minify : false,
208
+ externals,
209
+ splitting: (_bundleOptions$splitt = bundleOptions === null || bundleOptions === void 0 ? void 0 : bundleOptions.splitting) !== null && _bundleOptions$splitt !== void 0 ? _bundleOptions$splitt : false,
210
+ skipDeps
205
211
  });
206
212
 
207
213
  const normalizedBundlelessOptions = mergeWith({}, {
@@ -254,7 +260,8 @@ export const normalizeBuildConfig = (context, buildConfig) => {
254
260
  export const normalizeModuleConfig = context => {
255
261
  const {
256
262
  buildFeatOption,
257
- api
263
+ api,
264
+ deps
258
265
  } = context;
259
266
  const {
260
267
  output: {
@@ -264,7 +271,7 @@ export const normalizeModuleConfig = context => {
264
271
  } = api.useResolvedConfigContext(); // buildConfig is the most important.
265
272
 
266
273
  if (buildConfig) {
267
- return normalizeBuildConfig(context, buildConfig);
274
+ return normalizeBuildConfig(context, buildConfig, deps);
268
275
  } // buildPreset is the second important. It can be used when buildConfig is not defined.
269
276
  // buildPreset -> buildConfig
270
277
 
@@ -276,18 +283,19 @@ export const normalizeModuleConfig = context => {
276
283
  } = constants;
277
284
 
278
285
  if (unPresetConfigs[buildPreset]) {
279
- return normalizeBuildConfig(context, unPresetConfigs[buildPreset]);
286
+ return normalizeBuildConfig(context, unPresetConfigs[buildPreset], deps);
280
287
  } else if (unPresetWithTargetConfigs[buildPreset]) {
281
- return normalizeBuildConfig(context, unPresetWithTargetConfigs[buildPreset]);
288
+ return normalizeBuildConfig(context, unPresetWithTargetConfigs[buildPreset], deps);
282
289
  } // If the buildPreset is not found, then it is used 'npm-library'
283
290
  // TODO: Warning: The buildPreset 'npm-library' is not supported.
284
291
 
285
292
 
286
- return normalizeBuildConfig(context, unPresetConfigs['npm-library']);
293
+ return normalizeBuildConfig(context, unPresetConfigs['npm-library'], deps);
287
294
  } // If the user does not configure buildConfig and buildPreset,
288
295
  // the configuration is generated based on packageMode and packageField
289
296
 
290
297
 
291
298
  const legacyBuildConfig = getNormalizeModuleConfigByPackageModeAndFileds(api, buildFeatOption);
292
- return normalizeBuildConfig(context, legacyBuildConfig);
293
- };
299
+ return normalizeBuildConfig(context, legacyBuildConfig, deps);
300
+ };
301
+ /* eslint-enable max-lines */
@@ -1,7 +1,8 @@
1
1
  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; }
2
2
 
3
3
  import * as os from 'os';
4
- import { chalk, Import } from '@modern-js/utils';
4
+ import path from 'path';
5
+ import { chalk, Import, fs } from '@modern-js/utils';
5
6
  const constants = Import.lazy('./constants', require);
6
7
  const cssConfig = Import.lazy('@modern-js/css-config', require);
7
8
  /**
@@ -83,4 +84,14 @@ export const getPostcssOption = (appDirectory, modernConfig) => {
83
84
  enableSourceMap: (postcssOption === null || postcssOption === void 0 ? void 0 : postcssOption.sourceMap) || false,
84
85
  options: {}
85
86
  };
87
+ };
88
+ export const getAllDeps = appDirectory => {
89
+ try {
90
+ const json = JSON.parse(fs.readFileSync(path.resolve(appDirectory, './package.json'), 'utf8')); // return json[packageJsonConfig ?? PACKAGE_JSON_CONFIG_NAME] as T | undefined;
91
+
92
+ return [...Object.keys(json.dependencies || {}), ...Object.keys(json.devDependencies || {}), ...Object.keys(json.peerDependencies || {})];
93
+ } catch (e) {
94
+ console.warn('[WARN] package.json is broken');
95
+ return [];
96
+ }
86
97
  };
@@ -3,6 +3,7 @@ import ChangesetPlugin from '@modern-js/plugin-changeset';
3
3
  import AnalyzePlugin from '@modern-js/plugin-analyze';
4
4
  import LintPlugin from '@modern-js/plugin-jarvis';
5
5
  import { hooks } from "./hooks";
6
+ export * from "./types";
6
7
  const cli = Import.lazy('./cli', require);
7
8
  const local = Import.lazy('./locale', require);
8
9
  const schema = Import.lazy('./schema', require);
@@ -27,15 +27,22 @@ const properties = {
27
27
  },
28
28
  externals: {
29
29
  type: 'array',
30
- items: [{
31
- type: 'string'
32
- }]
30
+ items: {
31
+ anyOf: [{
32
+ instanceof: 'RegExp'
33
+ }, {
34
+ typeof: 'string'
35
+ }]
36
+ }
33
37
  },
34
38
  platform: {
35
39
  enum: ['node', 'browser']
36
40
  },
37
41
  minify: {
38
42
  enum: ['esbuild', 'terser', false]
43
+ },
44
+ skipDeps: {
45
+ type: 'boolean'
39
46
  }
40
47
  }
41
48
  },
@@ -4,6 +4,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
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
 
7
+ import path from 'path';
7
8
  import { getBabelConfig, applyUserBabelConfig } from '@modern-js/babel-preset-module';
8
9
  import { applyOptionsChain, getAlias, isUseSSRBundle } from '@modern-js/utils';
9
10
  export const getFinalAlias = (modernConfig, option) => {
@@ -60,6 +61,7 @@ export const resolveBabelConfig = (appDirectory, modernConfig, sourceMap, bundle
60
61
  lodashOptions,
61
62
  jsxTransformRuntime,
62
63
  importStyle,
64
+ sourceDir: path.join(appDirectory, bundlelessOptions.sourceDir),
63
65
  styleDir: bundlelessOptions.style.path,
64
66
  staticDir: bundlelessOptions.static.path,
65
67
  styledComponentsOptions: applyOptionsChain({
@@ -5,7 +5,7 @@ function _objectWithoutProperties(source, excluded) { if (source == null) return
5
5
  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; }
6
6
 
7
7
  import * as path from 'path';
8
- import { fs, Import, globby, fastGlob } from '@modern-js/utils';
8
+ import { fs, Import, globby, fastGlob, slash } from '@modern-js/utils';
9
9
  const normalizePath = Import.lazy('normalize-path', require);
10
10
  export const copyTask = async option => {
11
11
  const {
@@ -57,7 +57,7 @@ export const copyTask = async option => {
57
57
 
58
58
  glob = path.isAbsolute(fromOrigin) ? fromOrigin : path.posix.join(fastGlob.escapePath(normalizePath(path.resolve(context))), fromOrigin); // 计算 glob,获取目标文件
59
59
 
60
- const paths = await globby(glob, options);
60
+ const paths = await globby(slash(glob), options);
61
61
 
62
62
  if (!paths.length) {
63
63
  return;
@@ -11,8 +11,6 @@ var _utils = require("@modern-js/utils");
11
11
 
12
12
  var _signalExit = _interopRequireDefault(require("signal-exit"));
13
13
 
14
- var _constants = require("../utils/constants");
15
-
16
14
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
15
 
18
16
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -37,10 +35,24 @@ const init = api => {
37
35
 
38
36
  _utils.dotenv.config();
39
37
 
40
- (0, _signalExit.default)(() => {
41
- const tempTsconfigFileAbsPath = path.join(appDirectory, './node_modules', `./${_constants.tempTsconfigName}`);
42
-
43
- _utils.fs.removeSync(tempTsconfigFileAbsPath);
38
+ (0, _signalExit.default)(async code => {
39
+ if (code === 0) {
40
+ return;
41
+ }
42
+
43
+ const tempTsconfigPathPattern = path.join(appDirectory, './node_modules', `./tsconfig.**.**.json`);
44
+ const files = (0, _utils.globby)((0, _utils.slash)(tempTsconfigPathPattern), {
45
+ stats: true,
46
+ absolute: true
47
+ });
48
+ const currentTime = Date.now();
49
+
50
+ for (const file of files) {
51
+ // over 30s, will delete it
52
+ if (currentTime - file.stats.birthtimeMs >= 30 * 1000) {
53
+ _utils.fs.unlinkSync(file.path);
54
+ }
55
+ }
44
56
  });
45
57
  };
46
58
 
@@ -5,13 +5,19 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.build = void 0;
7
7
 
8
+ var _pMap = _interopRequireDefault(require("p-map"));
9
+
8
10
  var _runSpeedy = require("./runSpeedy");
9
11
 
10
12
  var _runRollup = require("./runRollup");
11
13
 
14
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
+
12
16
  const build = async (api, config) => {
13
- const tasks = config.dtsOnly ? [(0, _runRollup.startRollup)(api, config)] : [(0, _runSpeedy.runSpeedy)(api, config), (0, _runRollup.startRollup)(api, config)];
14
- await Promise.all(tasks);
17
+ const tasks = config.dtsOnly ? [_runRollup.startRollup] : [_runSpeedy.runSpeedy, _runRollup.startRollup];
18
+ await (0, _pMap.default)(tasks, async task => {
19
+ await task(api, config);
20
+ });
15
21
  };
16
22
 
17
23
  exports.build = build;
@@ -54,7 +54,7 @@ const getDefine = api => {
54
54
  globalVars
55
55
  }
56
56
  } = api.useResolvedConfigContext();
57
- const envVarsDefine = ['NODE_ENV', ...(envVars || [])].reduce((memo, name) => {
57
+ const envVarsDefine = [...(envVars || [])].reduce((memo, name) => {
58
58
  memo[`process.env.${name}`] = JSON.stringify(process.env[name]);
59
59
  return memo;
60
60
  }, {});
@@ -136,7 +136,7 @@ const runSpeedy = async (api, config) => {
136
136
  const distDir = _path.default.join(appDirectory, distPath, outputPath);
137
137
 
138
138
  const titleText = `[Bundle:Speedy:${format}_${target}]`;
139
- await getStyleOptionFromModern(api);
139
+ const style = await getStyleOptionFromModern(api);
140
140
  const alias = getAlias(api);
141
141
  const define = getDefine(api);
142
142
 
@@ -172,7 +172,7 @@ const runSpeedy = async (api, config) => {
172
172
  splitting,
173
173
  filename: '[name]'
174
174
  },
175
- // style,
175
+ style,
176
176
  resolve: {
177
177
  alias
178
178
  },