@rsbuild/plugin-source-build 0.4.9 → 0.4.11

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/dist/index.js CHANGED
@@ -44,7 +44,9 @@ var getSourceInclude = async (options) => {
44
44
  const { projects, sourceField } = options;
45
45
  const includes = [];
46
46
  for (const project of projects) {
47
- includes.push(...project.getSourceEntryPaths({ field: sourceField }));
47
+ includes.push(
48
+ ...project.getSourceEntryPaths({ field: sourceField, exports: true })
49
+ );
48
50
  }
49
51
  return includes;
50
52
  };
@@ -64,7 +66,7 @@ function pluginSourceBuild(options) {
64
66
  projects = await (0, import_monorepo_utils.getDependentProjects)(projectName || projectRootPath, {
65
67
  cwd: projectRootPath,
66
68
  recursive: true,
67
- filter: (0, import_monorepo_utils.filterByField)(sourceField),
69
+ filter: (0, import_monorepo_utils.filterByField)(sourceField, true),
68
70
  extraMonorepoStrategies
69
71
  });
70
72
  const includes = await getSourceInclude({
@@ -89,9 +91,19 @@ function pluginSourceBuild(options) {
89
91
  }
90
92
  });
91
93
  });
92
- const getReferences = () => projects.map((project) => import_node_path.default.join(project.dir, import_shared.TS_CONFIG_FILE)).filter((filePath) => import_node_fs.default.existsSync(filePath));
94
+ const getReferences = async () => {
95
+ const refers = projects.map((project) => import_node_path.default.join(project.dir, import_shared.TS_CONFIG_FILE)).filter((filePath) => import_node_fs.default.existsSync(filePath));
96
+ if (api.context.tsconfigPath) {
97
+ const { default: json5 } = await import("@rsbuild/shared/json5");
98
+ const { references } = json5.parse(
99
+ import_shared.fse.readFileSync(api.context.tsconfigPath, "utf-8")
100
+ );
101
+ return Array.isArray(references) ? references.map((r) => r.path).filter(Boolean).concat(refers) : refers;
102
+ }
103
+ return refers;
104
+ };
93
105
  if (api.context.bundlerType === "rspack") {
94
- api.modifyRspackConfig((config) => {
106
+ api.modifyRspackConfig(async (config) => {
95
107
  if (!api.context.tsconfigPath) {
96
108
  return;
97
109
  }
@@ -99,19 +111,20 @@ function pluginSourceBuild(options) {
99
111
  config.resolve.tsConfig = {
100
112
  ...config.resolve.tsConfig,
101
113
  configFile: api.context.tsconfigPath,
102
- references: getReferences()
114
+ references: await getReferences()
103
115
  };
104
116
  });
105
117
  } else {
106
- api.modifyBundlerChain((chain, { CHAIN_ID }) => {
118
+ api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
107
119
  const { TS_CONFIG_PATHS } = CHAIN_ID.RESOLVE_PLUGIN;
108
120
  if (!chain.resolve.plugins.has(TS_CONFIG_PATHS)) {
109
121
  return;
110
122
  }
123
+ const references = await getReferences();
111
124
  chain.resolve.plugin(TS_CONFIG_PATHS).tap(
112
125
  (options2) => options2.map((option) => ({
113
126
  ...option,
114
- references: getReferences()
127
+ references
115
128
  }))
116
129
  );
117
130
  });
package/dist/index.mjs CHANGED
@@ -9,7 +9,7 @@ import path from "path";
9
9
  // src/index.ts
10
10
  import fs from "fs";
11
11
  import path2 from "path";
12
- import { TS_CONFIG_FILE } from "@rsbuild/shared";
12
+ import { TS_CONFIG_FILE, fse } from "@rsbuild/shared";
13
13
  import {
14
14
  filterByField,
15
15
  getDependentProjects
@@ -19,7 +19,9 @@ var getSourceInclude = async (options) => {
19
19
  const { projects, sourceField } = options;
20
20
  const includes = [];
21
21
  for (const project of projects) {
22
- includes.push(...project.getSourceEntryPaths({ field: sourceField }));
22
+ includes.push(
23
+ ...project.getSourceEntryPaths({ field: sourceField, exports: true })
24
+ );
23
25
  }
24
26
  return includes;
25
27
  };
@@ -39,7 +41,7 @@ function pluginSourceBuild(options) {
39
41
  projects = await getDependentProjects(projectName || projectRootPath, {
40
42
  cwd: projectRootPath,
41
43
  recursive: true,
42
- filter: filterByField(sourceField),
44
+ filter: filterByField(sourceField, true),
43
45
  extraMonorepoStrategies
44
46
  });
45
47
  const includes = await getSourceInclude({
@@ -64,9 +66,19 @@ function pluginSourceBuild(options) {
64
66
  }
65
67
  });
66
68
  });
67
- const getReferences = () => projects.map((project) => path2.join(project.dir, TS_CONFIG_FILE)).filter((filePath) => fs.existsSync(filePath));
69
+ const getReferences = async () => {
70
+ const refers = projects.map((project) => path2.join(project.dir, TS_CONFIG_FILE)).filter((filePath) => fs.existsSync(filePath));
71
+ if (api.context.tsconfigPath) {
72
+ const { default: json5 } = await import("@rsbuild/shared/json5");
73
+ const { references } = json5.parse(
74
+ fse.readFileSync(api.context.tsconfigPath, "utf-8")
75
+ );
76
+ return Array.isArray(references) ? references.map((r) => r.path).filter(Boolean).concat(refers) : refers;
77
+ }
78
+ return refers;
79
+ };
68
80
  if (api.context.bundlerType === "rspack") {
69
- api.modifyRspackConfig((config) => {
81
+ api.modifyRspackConfig(async (config) => {
70
82
  if (!api.context.tsconfigPath) {
71
83
  return;
72
84
  }
@@ -74,19 +86,20 @@ function pluginSourceBuild(options) {
74
86
  config.resolve.tsConfig = {
75
87
  ...config.resolve.tsConfig,
76
88
  configFile: api.context.tsconfigPath,
77
- references: getReferences()
89
+ references: await getReferences()
78
90
  };
79
91
  });
80
92
  } else {
81
- api.modifyBundlerChain((chain, { CHAIN_ID }) => {
93
+ api.modifyBundlerChain(async (chain, { CHAIN_ID }) => {
82
94
  const { TS_CONFIG_PATHS } = CHAIN_ID.RESOLVE_PLUGIN;
83
95
  if (!chain.resolve.plugins.has(TS_CONFIG_PATHS)) {
84
96
  return;
85
97
  }
98
+ const references = await getReferences();
86
99
  chain.resolve.plugin(TS_CONFIG_PATHS).tap(
87
100
  (options2) => options2.map((option) => ({
88
101
  ...option,
89
- references: getReferences()
102
+ references
90
103
  }))
91
104
  );
92
105
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-source-build",
3
- "version": "0.4.9",
3
+ "version": "0.4.11",
4
4
  "description": "Source build plugin of Rsbuild",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "repository": {
@@ -23,18 +23,18 @@
23
23
  "dist"
24
24
  ],
25
25
  "dependencies": {
26
- "@rsbuild/monorepo-utils": "0.4.9",
27
- "@rsbuild/shared": "0.4.9"
26
+ "@rsbuild/monorepo-utils": "0.4.11",
27
+ "@rsbuild/shared": "0.4.11"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@babel/core": "^7.23.2",
31
31
  "typescript": "^5.3.0",
32
- "@rsbuild/core": "0.4.9",
33
- "@rsbuild/plugin-babel": "0.4.9",
34
- "@scripts/test-helper": "0.4.9"
32
+ "@rsbuild/core": "0.4.11",
33
+ "@rsbuild/plugin-babel": "0.4.11",
34
+ "@scripts/test-helper": "0.4.11"
35
35
  },
36
36
  "peerDependencies": {
37
- "@rsbuild/core": "^0.4.9"
37
+ "@rsbuild/core": "^0.4.11"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public",