@modern-js/builder 2.27.0 → 2.29.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,59 @@
1
1
  # @modern-js/builder
2
2
 
3
+ ## 2.29.0
4
+
5
+ ### Patch Changes
6
+
7
+ - 1171338: fix(app-tools): tools.tsChecker default value mismatch with doc
8
+
9
+ fix(app-tools): tools.tsChecker 默认值与文档不匹配
10
+
11
+ - 2ad31da: feat(builder): support performance preconnect/dnsPrefetch configurations
12
+
13
+ feat(builder): 支持 performance preconnect/dnsPrefetch 配置项
14
+
15
+ - Updated dependencies [e6b5355]
16
+ - Updated dependencies [93db783]
17
+ - Updated dependencies [bd4c354]
18
+ - Updated dependencies [ee59d06]
19
+ - Updated dependencies [cba7675]
20
+ - Updated dependencies [99052ea]
21
+ - Updated dependencies [d198779]
22
+ - Updated dependencies [1d71d2e]
23
+ - @modern-js/utils@2.29.0
24
+ - @modern-js/builder-shared@2.29.0
25
+ - @modern-js/monorepo-utils@2.29.0
26
+
27
+ ## 2.28.0
28
+
29
+ ### Minor Changes
30
+
31
+ - 7d966a1: feat(builder): source code build feature support project reference by adding tsCheck configuration
32
+ feat(builder): 源码构建增加 tsCheck 配置支持 project reference 的情况
33
+
34
+ ### Patch Changes
35
+
36
+ - fb93353: fix(builder): support source code build when ts-loader enable
37
+ fix(builder): 在 ts-loader 开启的时候支持源码构建
38
+ - 362416f: feat(builder): support import Node.js addons when target is node
39
+
40
+ feat(builder): 支持在 target 为 node 时引用 Node.js addons
41
+
42
+ - 820bfe9: feat(builder): add checkSyntax.ecmaVersion option
43
+
44
+ feat(builder): 新增 checkSyntax.ecmaVersion 选项
45
+
46
+ - Updated dependencies [6400d98]
47
+ - Updated dependencies [362416f]
48
+ - Updated dependencies [aa0c0c3]
49
+ - Updated dependencies [9301e46]
50
+ - Updated dependencies [00b58a7]
51
+ - Updated dependencies [820bfe9]
52
+ - Updated dependencies [d3e52e4]
53
+ - @modern-js/builder-shared@2.28.0
54
+ - @modern-js/utils@2.28.0
55
+ - @modern-js/monorepo-utils@2.28.0
56
+
3
57
  ## 2.27.0
4
58
 
5
59
  ### Patch Changes
@@ -18,36 +18,34 @@ _export(exports, {
18
18
  }
19
19
  });
20
20
  const _utils = require("@modern-js/utils");
21
- const builderPluginAntd = () => {
22
- return {
23
- name: `builder-plugin-antd`,
24
- setup(api) {
25
- api.modifyBuilderConfig((builderConfig) => {
26
- var _builderConfig_source_transformImport;
27
- var _builderConfig;
28
- var _source;
29
- (_source = (_builderConfig = builderConfig).source) !== null && _source !== void 0 ? _source : _builderConfig.source = {};
30
- if (builderConfig.source.transformImport === false || ((_builderConfig_source_transformImport = builderConfig.source.transformImport) === null || _builderConfig_source_transformImport === void 0 ? void 0 : _builderConfig_source_transformImport.some((item) => item.libraryName === "antd"))) {
31
- return;
32
- }
33
- const antdMajorVersion = (0, _utils.getAntdMajorVersion)(api.context.rootPath);
34
- if (antdMajorVersion && antdMajorVersion < 5) {
35
- var _builderConfig1;
36
- var _source1;
37
- (_source1 = (_builderConfig1 = builderConfig).source) !== null && _source1 !== void 0 ? _source1 : _builderConfig1.source = {};
38
- builderConfig.source.transformImport = [
39
- ...builderConfig.source.transformImport || [],
40
- {
41
- libraryName: "antd",
42
- libraryDirectory: useSSR(api.context.target) ? "lib" : "es",
43
- style: true
44
- }
45
- ];
46
- }
47
- });
48
- }
49
- };
50
- };
21
+ const builderPluginAntd = () => ({
22
+ name: `builder-plugin-antd`,
23
+ setup(api) {
24
+ api.modifyBuilderConfig((builderConfig) => {
25
+ var _builderConfig_source_transformImport;
26
+ var _builderConfig;
27
+ var _source;
28
+ (_source = (_builderConfig = builderConfig).source) !== null && _source !== void 0 ? _source : _builderConfig.source = {};
29
+ if (builderConfig.source.transformImport === false || ((_builderConfig_source_transformImport = builderConfig.source.transformImport) === null || _builderConfig_source_transformImport === void 0 ? void 0 : _builderConfig_source_transformImport.some((item) => item.libraryName === "antd"))) {
30
+ return;
31
+ }
32
+ const antdMajorVersion = (0, _utils.getAntdMajorVersion)(api.context.rootPath);
33
+ if (antdMajorVersion && antdMajorVersion < 5) {
34
+ var _builderConfig1;
35
+ var _source1;
36
+ (_source1 = (_builderConfig1 = builderConfig).source) !== null && _source1 !== void 0 ? _source1 : _builderConfig1.source = {};
37
+ builderConfig.source.transformImport = [
38
+ ...builderConfig.source.transformImport || [],
39
+ {
40
+ libraryName: "antd",
41
+ libraryDirectory: useSSR(api.context.target) ? "lib" : "es",
42
+ style: true
43
+ }
44
+ ];
45
+ }
46
+ });
47
+ }
48
+ });
51
49
  function useSSR(target) {
52
50
  return (Array.isArray(target) ? target : [
53
51
  target
@@ -10,37 +10,36 @@ Object.defineProperty(exports, "builderPluginArco", {
10
10
  });
11
11
  const _utils = require("@modern-js/utils");
12
12
  const _antd = require("./antd");
13
- const builderPluginArco = () => {
14
- return {
15
- name: `builder-plugin-arco`,
16
- setup(api) {
17
- const ARCO_NAME = "@arco-design/web-react";
18
- const ARCO_ICON = `${ARCO_NAME}/icon`;
19
- api.modifyBuilderConfig((builderConfig) => {
20
- var _builderConfig;
21
- const { transformImport = [] } = builderConfig.source || {};
22
- if (transformImport === false || !(0, _utils.isPackageInstalled)(ARCO_NAME, api.context.rootPath)) {
23
- return;
24
- }
25
- const isUseSSR = (0, _antd.useSSR)(api.context.target);
26
- if (!(transformImport === null || transformImport === void 0 ? void 0 : transformImport.some((item) => item.libraryName === ARCO_NAME))) {
27
- transformImport.push({
28
- libraryName: ARCO_NAME,
29
- libraryDirectory: isUseSSR ? "lib" : "es",
30
- camelToDashComponentName: false,
31
- style: true
32
- });
33
- }
34
- if (!(transformImport === null || transformImport === void 0 ? void 0 : transformImport.some((item) => item.libraryName === ARCO_ICON))) {
35
- transformImport.push({
36
- libraryName: ARCO_ICON,
37
- libraryDirectory: isUseSSR ? "react-icon-cjs" : "react-icon",
38
- camelToDashComponentName: false
39
- });
40
- }
41
- (_builderConfig = builderConfig).source || (_builderConfig.source = {});
42
- builderConfig.source.transformImport = transformImport;
43
- });
44
- }
45
- };
46
- };
13
+ const builderPluginArco = () => ({
14
+ name: `builder-plugin-arco`,
15
+ setup(api) {
16
+ const ARCO_NAME = "@arco-design/web-react";
17
+ const ARCO_ICON = `${ARCO_NAME}/icon`;
18
+ api.modifyBuilderConfig((builderConfig) => {
19
+ var _transformImport, _transformImport1;
20
+ var _builderConfig;
21
+ const { transformImport = [] } = builderConfig.source || {};
22
+ if (transformImport === false || !(0, _utils.isPackageInstalled)(ARCO_NAME, api.context.rootPath)) {
23
+ return;
24
+ }
25
+ const isUseSSR = (0, _antd.useSSR)(api.context.target);
26
+ if (!((_transformImport = transformImport) === null || _transformImport === void 0 ? void 0 : _transformImport.some((item) => item.libraryName === ARCO_NAME))) {
27
+ transformImport.push({
28
+ libraryName: ARCO_NAME,
29
+ libraryDirectory: isUseSSR ? "lib" : "es",
30
+ camelToDashComponentName: false,
31
+ style: true
32
+ });
33
+ }
34
+ if (!((_transformImport1 = transformImport) === null || _transformImport1 === void 0 ? void 0 : _transformImport1.some((item) => item.libraryName === ARCO_ICON))) {
35
+ transformImport.push({
36
+ libraryName: ARCO_ICON,
37
+ libraryDirectory: isUseSSR ? "react-icon-cjs" : "react-icon",
38
+ camelToDashComponentName: false
39
+ });
40
+ }
41
+ (_builderConfig = builderConfig).source || (_builderConfig.source = {});
42
+ builderConfig.source.transformImport = transformImport;
43
+ });
44
+ }
45
+ });
@@ -28,7 +28,7 @@ function builderPluginCheckSyntax() {
28
28
  chain.plugin(CheckSyntaxPlugin.name).use(CheckSyntaxPlugin, [
29
29
  {
30
30
  targets,
31
- exclude: typeof checkSyntax === "object" ? checkSyntax.exclude : void 0
31
+ ...typeof checkSyntax === "object" ? checkSyntax : {}
32
32
  }
33
33
  ]);
34
34
  });
@@ -23,11 +23,12 @@ const _path = /* @__PURE__ */ _interop_require_default._(require("path"));
23
23
  const _buildershared = require("@modern-js/builder-shared");
24
24
  const _lodash = /* @__PURE__ */ _interop_require_default._(require("@modern-js/utils/lodash"));
25
25
  async function getTemplateParameters(entryName, config, assetPrefix) {
26
+ var _templateParametersByEntries;
26
27
  const { applyOptionsChain } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
27
28
  const { mountId, templateParameters, templateParametersByEntries } = config.html;
28
29
  const meta = await (0, _buildershared.getMetaTags)(entryName, config);
29
30
  const title = (0, _buildershared.getTitle)(entryName, config);
30
- const templateParams = (templateParametersByEntries === null || templateParametersByEntries === void 0 ? void 0 : templateParametersByEntries[entryName]) || templateParameters;
31
+ const templateParams = ((_templateParametersByEntries = templateParametersByEntries) === null || _templateParametersByEntries === void 0 ? void 0 : _templateParametersByEntries[entryName]) || templateParameters;
31
32
  const baseParameters = {
32
33
  meta,
33
34
  title,
@@ -36,8 +36,10 @@ const plugins = {
36
36
  rem: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./rem"))).then((m) => m.builderPluginRem()),
37
37
  wasm: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./wasm"))).then((m) => m.builderPluginWasm()),
38
38
  moment: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./moment"))).then((m) => m.builderPluginMoment()),
39
+ nodeAddons: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./nodeAddons"))).then((m) => m.builderPluginNodeAddons()),
39
40
  externals: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./externals"))).then((m) => m.builderPluginExternals()),
40
41
  sourceBuild: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./sourceBuild"))).then((m) => m.builderPluginSourceBuild({
41
42
  sourceField: "source"
42
- }))
43
+ })),
44
+ networkPerformance: () => Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("./networkPerformance"))).then((m) => m.builderPluginNetworkPerformance())
43
45
  };
@@ -0,0 +1,2 @@
1
+ import { type DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
+ export declare const builderPluginNetworkPerformance: () => DefaultBuilderPlugin;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderPluginNetworkPerformance", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginNetworkPerformance;
9
+ }
10
+ });
11
+ const _buildershared = require("@modern-js/builder-shared");
12
+ const builderPluginNetworkPerformance = () => ({
13
+ name: `builder-plugin-network-performance`,
14
+ setup(api) {
15
+ api.modifyBundlerChain(async (chain, { CHAIN_ID, isServer, isWebWorker, isServiceWorker, HtmlPlugin }) => {
16
+ const config = api.getNormalizedConfig();
17
+ const { performance: { dnsPrefetch, preconnect } } = config;
18
+ if (isServer || isWebWorker || isServiceWorker) {
19
+ return;
20
+ }
21
+ if (dnsPrefetch) {
22
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_DNS_PREFETCH).use(_buildershared.HtmlNetworkPerformancePlugin, [
23
+ dnsPrefetch,
24
+ "dnsPrefetch",
25
+ HtmlPlugin
26
+ ]);
27
+ }
28
+ if (preconnect) {
29
+ chain.plugin(CHAIN_ID.PLUGIN.HTML_PRECONNECT).use(_buildershared.HtmlNetworkPerformancePlugin, [
30
+ preconnect,
31
+ "preconnect",
32
+ HtmlPlugin
33
+ ]);
34
+ }
35
+ });
36
+ }
37
+ });
@@ -0,0 +1,2 @@
1
+ import { type DefaultBuilderPlugin } from '@modern-js/builder-shared';
2
+ export declare const builderPluginNodeAddons: () => DefaultBuilderPlugin;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "builderPluginNodeAddons", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return builderPluginNodeAddons;
9
+ }
10
+ });
11
+ const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
+ const _buildershared = require("@modern-js/builder-shared");
13
+ const builderPluginNodeAddons = () => ({
14
+ name: "builder-plugin-node-addons",
15
+ setup(api) {
16
+ api.modifyBundlerChain(async (chain, { isServer, isServiceWorker, CHAIN_ID }) => {
17
+ if (!isServer && !isServiceWorker) {
18
+ return;
19
+ }
20
+ const { chalk, pkgUp } = await Promise.resolve().then(() => /* @__PURE__ */ _interop_require_wildcard._(require("@modern-js/utils")));
21
+ const getDistName = (resource) => {
22
+ const pkgJSON = pkgUp.sync({
23
+ cwd: resource
24
+ });
25
+ if (!pkgJSON) {
26
+ throw new Error(`Failed to compile Node.js addons, couldn't find the package.json of ${chalk.yellow(resource)}.`);
27
+ }
28
+ const getFilename = (resource2, pkgName2) => {
29
+ var _match;
30
+ const reg = new RegExp(`node_modules/${pkgName2}/(.+)`);
31
+ const match = resource2.match(reg);
32
+ const filename = (_match = match) === null || _match === void 0 ? void 0 : _match[1];
33
+ if (!filename) {
34
+ return "[name].[ext]";
35
+ }
36
+ return `${filename}`;
37
+ };
38
+ const { name: pkgName } = require(pkgJSON);
39
+ const config = api.getNormalizedConfig();
40
+ const serverPath = (0, _buildershared.getDistPath)(config.output, "server");
41
+ return `${serverPath}/${getFilename(resource, pkgName)}`;
42
+ };
43
+ chain.module.rule(CHAIN_ID.RULE.NODE).test(/\.node$/).use(CHAIN_ID.USE.NODE).loader((0, _buildershared.getSharedPkgCompiledPath)("node-loader")).options({
44
+ name: getDistName
45
+ });
46
+ });
47
+ }
48
+ });
@@ -16,68 +16,66 @@ const defaultOptions = {
16
16
  enableRuntime: true,
17
17
  rootFontSize: 50
18
18
  };
19
- const builderPluginRem = () => {
20
- return {
21
- name: "builder-plugin-rem",
22
- pre: [
23
- "builder-plugin-css",
24
- "builder-plugin-less",
25
- "builder-plugin-sass",
26
- "builder-plugin-stylus"
27
- ],
28
- setup(api) {
29
- api.modifyBundlerChain(async (chain, { CHAIN_ID, isServer, isWebWorker, HtmlPlugin }) => {
30
- const config = api.getNormalizedConfig();
31
- const { output: { convertToRem } } = config;
32
- if (!convertToRem || isServer || isWebWorker) {
33
- return;
34
- }
35
- const userOptions = {
36
- ...defaultOptions,
37
- ...typeof convertToRem === "boolean" ? {} : convertToRem
38
- };
39
- const { default: PxToRemPlugin } = await Promise.resolve((0, _buildershared.getSharedPkgCompiledPath)("postcss-pxtorem")).then((p) => /* @__PURE__ */ _interop_require_wildcard._(require(p)));
40
- const applyRules = [
41
- CHAIN_ID.RULE.CSS,
42
- CHAIN_ID.RULE.LESS,
43
- CHAIN_ID.RULE.SASS,
44
- CHAIN_ID.RULE.STYLUS
45
- ];
46
- const getPxToRemPlugin = () => PxToRemPlugin({
47
- rootValue: userOptions.rootFontSize,
48
- unitPrecision: 5,
49
- propList: [
50
- "*"
51
- ],
52
- ..._lodash.default.cloneDeep(userOptions.pxtorem || {})
53
- });
54
- applyRules.forEach((name) => {
55
- chain.module.rules.has(name) && chain.module.rule(name).use(CHAIN_ID.USE.POSTCSS).tap((options = {}) => {
56
- var _options_postcssOptions;
57
- return {
58
- ...options,
59
- postcssOptions: {
60
- ...options.postcssOptions || {},
61
- plugins: [
62
- ...((_options_postcssOptions = options.postcssOptions) === null || _options_postcssOptions === void 0 ? void 0 : _options_postcssOptions.plugins) || [],
63
- getPxToRemPlugin()
64
- ]
65
- }
66
- };
67
- });
19
+ const builderPluginRem = () => ({
20
+ name: "builder-plugin-rem",
21
+ pre: [
22
+ "builder-plugin-css",
23
+ "builder-plugin-less",
24
+ "builder-plugin-sass",
25
+ "builder-plugin-stylus"
26
+ ],
27
+ setup(api) {
28
+ api.modifyBundlerChain(async (chain, { CHAIN_ID, isServer, isWebWorker, HtmlPlugin }) => {
29
+ const config = api.getNormalizedConfig();
30
+ const { output: { convertToRem } } = config;
31
+ if (!convertToRem || isServer || isWebWorker) {
32
+ return;
33
+ }
34
+ const userOptions = {
35
+ ...defaultOptions,
36
+ ...typeof convertToRem === "boolean" ? {} : convertToRem
37
+ };
38
+ const { default: PxToRemPlugin } = await Promise.resolve((0, _buildershared.getSharedPkgCompiledPath)("postcss-pxtorem")).then((p) => /* @__PURE__ */ _interop_require_wildcard._(require(p)));
39
+ const applyRules = [
40
+ CHAIN_ID.RULE.CSS,
41
+ CHAIN_ID.RULE.LESS,
42
+ CHAIN_ID.RULE.SASS,
43
+ CHAIN_ID.RULE.STYLUS
44
+ ];
45
+ const getPxToRemPlugin = () => PxToRemPlugin({
46
+ rootValue: userOptions.rootFontSize,
47
+ unitPrecision: 5,
48
+ propList: [
49
+ "*"
50
+ ],
51
+ ..._lodash.default.cloneDeep(userOptions.pxtorem || {})
52
+ });
53
+ applyRules.forEach((name) => {
54
+ chain.module.rules.has(name) && chain.module.rule(name).use(CHAIN_ID.USE.POSTCSS).tap((options = {}) => {
55
+ var _options_postcssOptions;
56
+ return {
57
+ ...options,
58
+ postcssOptions: {
59
+ ...options.postcssOptions || {},
60
+ plugins: [
61
+ ...((_options_postcssOptions = options.postcssOptions) === null || _options_postcssOptions === void 0 ? void 0 : _options_postcssOptions.plugins) || [],
62
+ getPxToRemPlugin()
63
+ ]
64
+ }
65
+ };
68
66
  });
69
- if (!userOptions.enableRuntime) {
70
- return;
71
- }
72
- const entries = Object.keys(chain.entryPoints.entries() || {});
73
- const distDir = (0, _buildershared.getDistPath)(config.output, "js");
74
- chain.plugin(CHAIN_ID.PLUGIN.AUTO_SET_ROOT_SIZE).use(_buildershared.AutoSetRootFontSizePlugin, [
75
- userOptions,
76
- entries,
77
- HtmlPlugin,
78
- distDir
79
- ]);
80
67
  });
81
- }
82
- };
83
- };
68
+ if (!userOptions.enableRuntime) {
69
+ return;
70
+ }
71
+ const entries = Object.keys(chain.entryPoints.entries() || {});
72
+ const distDir = (0, _buildershared.getDistPath)(config.output, "js");
73
+ chain.plugin(CHAIN_ID.PLUGIN.AUTO_SET_ROOT_SIZE).use(_buildershared.AutoSetRootFontSizePlugin, [
74
+ userOptions,
75
+ entries,
76
+ HtmlPlugin,
77
+ distDir
78
+ ]);
79
+ });
80
+ }
81
+ });
@@ -9,12 +9,6 @@ export declare const getSourceInclude: (options: {
9
9
  sourceField: string;
10
10
  extraMonorepoStrategies?: ExtraMonorepoStrategies;
11
11
  }) => Promise<string[]>;
12
- export declare const sourceBuildInWebpack: (api: WebpackBuilderPluginAPI, options: {
13
- sourceField: string;
14
- projectRootPath: string;
15
- projectName?: string;
16
- extraMonorepoStrategies?: ExtraMonorepoStrategies;
17
- }) => void;
18
12
  export interface PluginSourceBuildOptions {
19
13
  projectName?: string;
20
14
  sourceField?: string;
@@ -16,14 +16,13 @@ _export(exports, {
16
16
  getSourceInclude: function() {
17
17
  return getSourceInclude;
18
18
  },
19
- sourceBuildInWebpack: function() {
20
- return sourceBuildInWebpack;
21
- },
22
19
  builderPluginSourceBuild: function() {
23
20
  return builderPluginSourceBuild;
24
21
  }
25
22
  });
26
23
  const _monorepoutils = require("@modern-js/monorepo-utils");
24
+ const _utils = require("@modern-js/utils");
25
+ const log = (0, _utils.debug)("BUILDER_PLUGIN_SOURCE_BUILD");
27
26
  const pluginName = "builder-plugin-source-build";
28
27
  const getSourceInclude = async (options) => {
29
28
  const { projectNameOrRootPath, sourceField, extraMonorepoStrategies, findMonorepoStartPath } = options;
@@ -39,55 +38,9 @@ const getSourceInclude = async (options) => {
39
38
  field: sourceField
40
39
  }));
41
40
  }
41
+ log(`get include projects: ${includes}`);
42
42
  return includes;
43
43
  };
44
- const sourceBuildInWebpack = (api, options) => {
45
- const { sourceField, projectRootPath, projectName, extraMonorepoStrategies } = options;
46
- api.modifyBuilderConfig(async (config) => {
47
- var _config_experiments;
48
- const { sourceBuild = true } = (_config_experiments = config.experiments) !== null && _config_experiments !== void 0 ? _config_experiments : {};
49
- if (!sourceBuild) {
50
- return;
51
- }
52
- const includes = await getSourceInclude({
53
- projectNameOrRootPath: projectName || projectRootPath,
54
- sourceField,
55
- findMonorepoStartPath: projectRootPath,
56
- extraMonorepoStrategies
57
- });
58
- var _config_source;
59
- config.source = (_config_source = config.source) !== null && _config_source !== void 0 ? _config_source : {};
60
- var _config_source_include;
61
- config.source.include = [
62
- ...(_config_source_include = config.source.include) !== null && _config_source_include !== void 0 ? _config_source_include : [],
63
- ...includes
64
- ];
65
- });
66
- api.modifyBundlerChain((chain) => {
67
- const { experiments: { sourceBuild } } = api.getNormalizedConfig();
68
- if (!sourceBuild) {
69
- return;
70
- }
71
- if (chain.resolve.mainFields.values().length === 0) {
72
- chain.resolve.mainFields.prepend("...");
73
- chain.resolve.mainFields.prepend(sourceField);
74
- }
75
- });
76
- api.modifyWebpackConfig(async (config) => {
77
- const { experiments: { sourceBuild } } = api.getNormalizedConfig();
78
- if (!sourceBuild) {
79
- return;
80
- }
81
- var _config_resolve;
82
- config.resolve = (_config_resolve = config.resolve) !== null && _config_resolve !== void 0 ? _config_resolve : {};
83
- var _config_resolve_conditionNames;
84
- config.resolve.conditionNames = [
85
- "...",
86
- sourceField,
87
- ...(_config_resolve_conditionNames = config.resolve.conditionNames) !== null && _config_resolve_conditionNames !== void 0 ? _config_resolve_conditionNames : []
88
- ];
89
- });
90
- };
91
44
  function builderPluginSourceBuild(options) {
92
45
  const { projectName, sourceField = "source", extraMonorepoStrategies } = options !== null && options !== void 0 ? options : {};
93
46
  return {
@@ -116,15 +69,16 @@ function builderPluginSourceBuild(options) {
116
69
  ];
117
70
  });
118
71
  api.modifyBundlerChain((chain, { CHAIN_ID }) => {
119
- const { experiments: { sourceBuild } } = api.getNormalizedConfig();
72
+ const { experiments: { sourceBuild }, tools: { tsLoader } } = api.getNormalizedConfig();
120
73
  if (!sourceBuild) {
121
74
  return;
122
75
  }
123
- chain.module.rule(CHAIN_ID.RULE.JS).resolve.mainFields.merge([
76
+ const useTsLoader = Boolean(tsLoader);
77
+ chain.module.rule(useTsLoader ? CHAIN_ID.RULE.TS : CHAIN_ID.RULE.JS).resolve.mainFields.merge([
124
78
  "...",
125
79
  sourceField
126
80
  ]);
127
- chain.module.rule(CHAIN_ID.RULE.JS).resolve.merge({
81
+ chain.module.rule(useTsLoader ? CHAIN_ID.RULE.TS : CHAIN_ID.RULE.JS).resolve.merge({
128
82
  conditionNames: [
129
83
  "...",
130
84
  sourceField
@@ -9,11 +9,13 @@ Object.defineProperty(exports, "builderPluginTsChecker", {
9
9
  }
10
10
  });
11
11
  const _interop_require_wildcard = require("@swc/helpers/_/_interop_require_wildcard");
12
+ const _lodash = require("@modern-js/utils/lodash");
12
13
  const builderPluginTsChecker = () => {
13
14
  return {
14
15
  name: "builder-plugin-ts-checker",
15
16
  setup(api) {
16
17
  api.modifyBundlerChain(async (chain, { target }) => {
18
+ var _experiments;
17
19
  const config = api.getNormalizedConfig();
18
20
  if (config.output.disableTsChecker || !api.context.tsconfigPath) {
19
21
  return;
@@ -34,13 +36,22 @@ const builderPluginTsChecker = () => {
34
36
  logger.warn('"typescript" is not found in current project, Type Checker will not work.');
35
37
  return;
36
38
  }
39
+ const { experiments } = api.getNormalizedConfig();
40
+ var _experiments_sourceBuild;
41
+ const enableSourceBuild = (_experiments_sourceBuild = (_experiments = experiments) === null || _experiments === void 0 ? void 0 : _experiments.sourceBuild) !== null && _experiments_sourceBuild !== void 0 ? _experiments_sourceBuild : false;
37
42
  const tsCheckerOptions = applyOptionsChain({
38
43
  typescript: {
39
44
  // avoid OOM issue
40
45
  memoryLimit: 8192,
41
46
  // use tsconfig of user project
42
47
  configFile: api.context.tsconfigPath,
43
- typescriptPath
48
+ typescriptPath,
49
+ // In source build mode, using the project reference generates a TS2307 error,
50
+ // so additional configuration of the tsChecker is required
51
+ ...enableSourceBuild ? {
52
+ build: true,
53
+ mode: "readonly"
54
+ } : {}
44
55
  },
45
56
  issue: {
46
57
  exclude: [
@@ -59,7 +70,7 @@ const builderPluginTsChecker = () => {
59
70
  console.error(message.replace(/ERROR/g, "Type Error"));
60
71
  }
61
72
  }
62
- }, typeof config.tools.tsChecker === "object" ? config.tools.tsChecker : {});
73
+ }, config.tools.tsChecker, void 0, _lodash.merge);
63
74
  if (api.context.bundlerType === "rspack" && chain.get("mode") === "production") {
64
75
  logger.info("ts-checker running...");
65
76
  logger.info("ts-checker is running slowly and will block builds until it is complete, please be patient and wait.");
package/package.json CHANGED
@@ -18,7 +18,7 @@
18
18
  "engines": {
19
19
  "node": ">=14.0.0"
20
20
  },
21
- "version": "2.27.0",
21
+ "version": "2.29.0",
22
22
  "jsnext:source": "./src/index.ts",
23
23
  "types": "./dist/index.d.ts",
24
24
  "main": "./dist/index.js",
@@ -32,18 +32,18 @@
32
32
  "dependencies": {
33
33
  "@svgr/webpack": "8.0.1",
34
34
  "@swc/helpers": "0.5.1",
35
- "@modern-js/builder-shared": "2.27.0",
36
- "@modern-js/monorepo-utils": "2.27.0",
37
- "@modern-js/utils": "2.27.0"
35
+ "@modern-js/monorepo-utils": "2.29.0",
36
+ "@modern-js/builder-shared": "2.29.0",
37
+ "@modern-js/utils": "2.29.0"
38
38
  },
39
39
  "devDependencies": {
40
40
  "@types/babel__core": "^7.20.0",
41
41
  "@types/node": "^14",
42
42
  "typescript": "^5",
43
- "@modern-js/builder-webpack-provider": "2.27.0",
44
- "@modern-js/builder-rspack-provider": "2.27.0",
45
- "@scripts/build": "2.27.0",
46
- "@scripts/vitest-config": "2.27.0"
43
+ "@modern-js/builder-webpack-provider": "2.29.0",
44
+ "@modern-js/builder-rspack-provider": "2.29.0",
45
+ "@scripts/build": "2.29.0",
46
+ "@scripts/vitest-config": "2.29.0"
47
47
  },
48
48
  "publishConfig": {
49
49
  "registry": "https://registry.npmjs.org/",