@rsbuild/plugin-source-build 0.0.0-nightly-20231024161008

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Bytedance, Inc. and its affiliates.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ <p align="center">
2
+ <a href="https://rsbuild.dev" target="blank"><img src="https://github.com/web-infra-dev/rsbuild/assets/7237365/84abc13e-b620-468f-a90b-dbf28e7e9427" alt="Rsbuild Logo" /></a>
3
+ </p>
4
+
5
+ # Rsbuild
6
+
7
+ Unleash the power of Rspack with the out-of-the-box build tool.
8
+
9
+ ## Documentation
10
+
11
+ https://rsbuild.dev/
12
+
13
+ ## Contributing
14
+
15
+ Please read the [Contributing Guide](https://github.com/web-infra-dev/rsbuild/blob/main/CONTRIBUTING.md).
16
+
17
+ ## License
18
+
19
+ Rsbuild is [MIT licensed](https://github.com/web-infra-dev/rsbuild/blob/main/LICENSE).
@@ -0,0 +1,13 @@
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;
7
+ }) => Promise<string[]>;
8
+ export interface PluginSourceBuildOptions {
9
+ projectName?: string;
10
+ sourceField?: string;
11
+ extraMonorepoStrategies?: ExtraMonorepoStrategies;
12
+ }
13
+ export declare function pluginSourceBuild(options?: PluginSourceBuildOptions): RsbuildPlugin<RsbuildPluginAPI>;
package/dist/index.js ADDED
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var src_exports = {};
30
+ __export(src_exports, {
31
+ getSourceInclude: () => getSourceInclude,
32
+ pluginName: () => pluginName,
33
+ pluginSourceBuild: () => pluginSourceBuild
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+ var import_path = __toESM(require("path"));
37
+ var import_fs_extra = require("@rsbuild/shared/fs-extra");
38
+ var import_shared = require("@rsbuild/shared");
39
+ var import_monorepo_utils = require("@rsbuild/monorepo-utils");
40
+ const pluginName = "plugin-source-build";
41
+ const getSourceInclude = async (options) => {
42
+ const { projects, sourceField } = options;
43
+ const includes = [];
44
+ for (const project of projects) {
45
+ includes.push(...project.getSourceEntryPaths({ field: sourceField }));
46
+ }
47
+ return includes;
48
+ };
49
+ function pluginSourceBuild(options) {
50
+ const {
51
+ projectName,
52
+ sourceField = "source",
53
+ extraMonorepoStrategies
54
+ } = options != null ? options : {};
55
+ return {
56
+ name: pluginName,
57
+ async setup(api) {
58
+ const projectRootPath = api.context.rootPath;
59
+ let projects = [];
60
+ api.modifyRsbuildConfig(async (config) => {
61
+ var _a, _b;
62
+ projects = await (0, import_monorepo_utils.getDependentProjects)(projectName || projectRootPath, {
63
+ cwd: projectRootPath,
64
+ recursive: true,
65
+ filter: (0, import_monorepo_utils.filterByField)(sourceField),
66
+ extraMonorepoStrategies
67
+ });
68
+ const includes = await getSourceInclude({
69
+ projects,
70
+ sourceField
71
+ });
72
+ config.source = (_a = config.source) != null ? _a : {};
73
+ config.source.include = [...(_b = config.source.include) != null ? _b : [], ...includes];
74
+ });
75
+ if (api.context.bundlerType === "webpack") {
76
+ api.modifyWebpackChain(
77
+ (chain, { CHAIN_ID }) => {
78
+ const {
79
+ tools: { tsLoader }
80
+ } = api.getNormalizedConfig();
81
+ const useTsLoader = Boolean(tsLoader);
82
+ chain.module.rule(useTsLoader ? CHAIN_ID.RULE.TS : CHAIN_ID.RULE.JS).resolve.mainFields.merge(["...", sourceField]);
83
+ chain.module.rule(useTsLoader ? CHAIN_ID.RULE.TS : CHAIN_ID.RULE.JS).resolve.merge({
84
+ conditionNames: ["...", sourceField]
85
+ });
86
+ const { TS_CONFIG_PATHS } = CHAIN_ID.RESOLVE_PLUGIN;
87
+ if (chain.resolve.plugins.has(TS_CONFIG_PATHS)) {
88
+ chain.resolve.plugin(TS_CONFIG_PATHS).tap((options2) => {
89
+ const references = projects.map((project) => import_path.default.join(project.dir, import_shared.TS_CONFIG_FILE)).filter((filePath) => import_fs_extra.fs.existsSync(filePath));
90
+ return options2.map((option) => ({
91
+ ...option,
92
+ references
93
+ }));
94
+ });
95
+ }
96
+ }
97
+ );
98
+ }
99
+ }
100
+ };
101
+ }
102
+ // Annotate the CommonJS export names for ESM import in node:
103
+ 0 && (module.exports = {
104
+ getSourceInclude,
105
+ pluginName,
106
+ pluginSourceBuild
107
+ });
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@rsbuild/plugin-source-build",
3
+ "description": "Source build plugin of Rsbuild",
4
+ "homepage": "https://rsbuild.dev",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/web-infra-dev/rsbuild",
8
+ "directory": "packages/plugin-source-build"
9
+ },
10
+ "license": "MIT",
11
+ "version": "0.0.0-nightly-20231024161008",
12
+ "types": "./dist/index.d.ts",
13
+ "main": "./dist/index.js",
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/index.d.ts",
17
+ "default": "./dist/index.js"
18
+ }
19
+ },
20
+ "files": [
21
+ "dist"
22
+ ],
23
+ "dependencies": {
24
+ "@rsbuild/monorepo-utils": "0.0.0-nightly-20231024161008",
25
+ "@rsbuild/shared": "0.0.0-nightly-20231024161008"
26
+ },
27
+ "devDependencies": {
28
+ "@babel/core": "^7.23.2",
29
+ "typescript": "^5",
30
+ "@rsbuild/core": "0.0.0-nightly-20231024161008",
31
+ "@rsbuild/webpack": "0.0.0-nightly-20231024161008",
32
+ "@rsbuild/test-helper": "0.0.0-nightly-20231024161008"
33
+ },
34
+ "peerDependencies": {
35
+ "@rsbuild/core": "0.0.0-nightly-20231024161008"
36
+ },
37
+ "publishConfig": {
38
+ "registry": "https://registry.npmjs.org/",
39
+ "access": "public",
40
+ "provenance": true
41
+ },
42
+ "scripts": {
43
+ "dev": "modern build --watch",
44
+ "build": "modern build"
45
+ }
46
+ }