@rsbuild/plugin-source-build 0.0.17 → 0.0.18

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.d.ts CHANGED
@@ -1,13 +1,16 @@
1
- import type { RsbuildPlugin, RsbuildPluginAPI } from '@rsbuild/core';
2
- import { type Project, type ExtraMonorepoStrategies } from '@rsbuild/monorepo-utils';
3
- export declare const pluginName = "plugin-source-build";
4
- export declare const getSourceInclude: (options: {
5
- projects: Project[];
6
- sourceField: string;
1
+ import { RsbuildPlugin, RsbuildPluginAPI } from '@rsbuild/core';
2
+ import { Project, ExtraMonorepoStrategies } from '@rsbuild/monorepo-utils';
3
+
4
+ declare const pluginName = "plugin-source-build";
5
+ declare const getSourceInclude: (options: {
6
+ projects: Project[];
7
+ sourceField: string;
7
8
  }) => Promise<string[]>;
8
- export interface PluginSourceBuildOptions {
9
- projectName?: string;
10
- sourceField?: string;
11
- extraMonorepoStrategies?: ExtraMonorepoStrategies;
9
+ interface PluginSourceBuildOptions {
10
+ projectName?: string;
11
+ sourceField?: string;
12
+ extraMonorepoStrategies?: ExtraMonorepoStrategies;
12
13
  }
13
- export declare function pluginSourceBuild(options?: PluginSourceBuildOptions): RsbuildPlugin<RsbuildPluginAPI>;
14
+ declare function pluginSourceBuild(options?: PluginSourceBuildOptions): RsbuildPlugin<RsbuildPluginAPI>;
15
+
16
+ export { PluginSourceBuildOptions, getSourceInclude, pluginName, pluginSourceBuild };
package/dist/index.js CHANGED
@@ -26,6 +26,8 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
26
26
  mod
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
29
31
  var src_exports = {};
30
32
  __export(src_exports, {
31
33
  getSourceInclude: () => getSourceInclude,
@@ -37,8 +39,8 @@ var import_path = __toESM(require("path"));
37
39
  var import_fs_extra = require("@rsbuild/shared/fs-extra");
38
40
  var import_shared = require("@rsbuild/shared");
39
41
  var import_monorepo_utils = require("@rsbuild/monorepo-utils");
40
- const pluginName = "plugin-source-build";
41
- const getSourceInclude = async (options) => {
42
+ var pluginName = "plugin-source-build";
43
+ var getSourceInclude = async (options) => {
42
44
  const { projects, sourceField } = options;
43
45
  const includes = [];
44
46
  for (const project of projects) {
package/dist/index.mjs ADDED
@@ -0,0 +1,82 @@
1
+ // ../../node_modules/.pnpm/@modern-js+module-tools@2.39.2_typescript@5.2.2/node_modules/@modern-js/module-tools/shims/esm.js
2
+ import { fileURLToPath } from "url";
3
+ import path from "path";
4
+
5
+ // ../../scripts/require_shims.js
6
+ import { createRequire } from "module";
7
+ global.require = createRequire(import.meta.url);
8
+
9
+ // src/index.ts
10
+ import path2 from "path";
11
+ import { fs } from "@rsbuild/shared/fs-extra";
12
+ import { TS_CONFIG_FILE } from "@rsbuild/shared";
13
+ import {
14
+ filterByField,
15
+ getDependentProjects
16
+ } from "@rsbuild/monorepo-utils";
17
+ var pluginName = "plugin-source-build";
18
+ var getSourceInclude = async (options) => {
19
+ const { projects, sourceField } = options;
20
+ const includes = [];
21
+ for (const project of projects) {
22
+ includes.push(...project.getSourceEntryPaths({ field: sourceField }));
23
+ }
24
+ return includes;
25
+ };
26
+ function pluginSourceBuild(options) {
27
+ const {
28
+ projectName,
29
+ sourceField = "source",
30
+ extraMonorepoStrategies
31
+ } = options ?? {};
32
+ return {
33
+ name: pluginName,
34
+ setup(api) {
35
+ const projectRootPath = api.context.rootPath;
36
+ let projects = [];
37
+ api.modifyRsbuildConfig(async (config) => {
38
+ projects = await getDependentProjects(projectName || projectRootPath, {
39
+ cwd: projectRootPath,
40
+ recursive: true,
41
+ filter: filterByField(sourceField),
42
+ extraMonorepoStrategies
43
+ });
44
+ const includes = await getSourceInclude({
45
+ projects,
46
+ sourceField
47
+ });
48
+ config.source = config.source ?? {};
49
+ config.source.include = [...config.source.include ?? [], ...includes];
50
+ });
51
+ if (api.context.bundlerType === "webpack") {
52
+ api.modifyWebpackChain(
53
+ (chain, { CHAIN_ID }) => {
54
+ const {
55
+ tools: { tsLoader }
56
+ } = api.getNormalizedConfig();
57
+ const useTsLoader = Boolean(tsLoader);
58
+ chain.module.rule(useTsLoader ? CHAIN_ID.RULE.TS : CHAIN_ID.RULE.JS).resolve.mainFields.merge([sourceField, "..."]);
59
+ chain.module.rule(useTsLoader ? CHAIN_ID.RULE.TS : CHAIN_ID.RULE.JS).resolve.merge({
60
+ conditionNames: ["...", sourceField]
61
+ });
62
+ const { TS_CONFIG_PATHS } = CHAIN_ID.RESOLVE_PLUGIN;
63
+ if (chain.resolve.plugins.has(TS_CONFIG_PATHS)) {
64
+ chain.resolve.plugin(TS_CONFIG_PATHS).tap((options2) => {
65
+ const references = projects.map((project) => path2.join(project.dir, TS_CONFIG_FILE)).filter((filePath) => fs.existsSync(filePath));
66
+ return options2.map((option) => ({
67
+ ...option,
68
+ references
69
+ }));
70
+ });
71
+ }
72
+ }
73
+ );
74
+ }
75
+ }
76
+ };
77
+ }
78
+ export {
79
+ getSourceInclude,
80
+ pluginName,
81
+ pluginSourceBuild
82
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/plugin-source-build",
3
- "version": "0.0.17",
3
+ "version": "0.0.18",
4
4
  "description": "Source build plugin of Rsbuild",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "repository": {
@@ -12,6 +12,7 @@
12
12
  "exports": {
13
13
  ".": {
14
14
  "types": "./dist/index.d.ts",
15
+ "import": "./dist/index.mjs",
15
16
  "default": "./dist/index.js"
16
17
  }
17
18
  },
@@ -21,18 +22,18 @@
21
22
  "dist"
22
23
  ],
23
24
  "dependencies": {
24
- "@rsbuild/monorepo-utils": "0.0.17",
25
- "@rsbuild/shared": "0.0.17"
25
+ "@rsbuild/monorepo-utils": "0.0.18",
26
+ "@rsbuild/shared": "0.0.18"
26
27
  },
27
28
  "devDependencies": {
28
29
  "@babel/core": "^7.23.2",
29
30
  "typescript": "^5.2.2",
30
- "@rsbuild/core": "0.0.17",
31
- "@rsbuild/test-helper": "0.0.17",
32
- "@rsbuild/webpack": "0.0.17"
31
+ "@rsbuild/core": "0.0.18",
32
+ "@rsbuild/test-helper": "0.0.18",
33
+ "@rsbuild/webpack": "0.0.18"
33
34
  },
34
35
  "peerDependencies": {
35
- "@rsbuild/core": "^0.0.17"
36
+ "@rsbuild/core": "^0.0.18"
36
37
  },
37
38
  "publishConfig": {
38
39
  "access": "public",