@rsbuild/core 0.5.6 → 0.5.7

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.
@@ -39,7 +39,7 @@ const applyServerOptions = (command) => {
39
39
  command.option("-o --open [url]", "open the page in browser on startup").option("--port <port>", "specify a port number for server to listen").option("--host <host>", "specify the host that the server listens to");
40
40
  };
41
41
  function runCli() {
42
- import_commander.program.name("rsbuild").usage("<command> [options]").version("0.5.6");
42
+ import_commander.program.name("rsbuild").usage("<command> [options]").version("0.5.7");
43
43
  const devCommand = import_commander.program.command("dev");
44
44
  const buildCommand = import_commander.program.command("build");
45
45
  const previewCommand = import_commander.program.command("preview");
@@ -34,7 +34,7 @@ function prepareCli() {
34
34
  if (!npm_execpath || npm_execpath.includes("npx-cli.js") || npm_execpath.includes(".bun")) {
35
35
  console.log();
36
36
  }
37
- import_rslog.logger.greet(` ${`Rsbuild v${"0.5.6"}`}
37
+ import_rslog.logger.greet(` ${`Rsbuild v${"0.5.7"}`}
38
38
  `);
39
39
  }
40
40
  // Annotate the CommonJS export names for ESM import in node:
package/dist/index.js CHANGED
@@ -38,7 +38,7 @@ var import_config = require("./config");
38
38
  var import_shared = require("@rsbuild/shared");
39
39
  var import_mergeConfig = require("./mergeConfig");
40
40
  var import_constants = require("./constants");
41
- const version = "0.5.6";
41
+ const version = "0.5.7";
42
42
  // Annotate the CommonJS export names for ESM import in node:
43
43
  0 && (module.exports = {
44
44
  PLUGIN_CSS_NAME,
@@ -44,7 +44,7 @@ async function createContextByConfig(options, bundlerType, config = {}) {
44
44
  const context = {
45
45
  entry: (0, import_entry.getEntryObject)(config, "web"),
46
46
  targets: config.output?.targets || [],
47
- version: "0.5.6",
47
+ version: "0.5.7",
48
48
  rootPath,
49
49
  distPath,
50
50
  cachePath,
@@ -22,6 +22,7 @@ __export(initPlugins_exports, {
22
22
  getPluginAPI: () => getPluginAPI
23
23
  });
24
24
  module.exports = __toCommonJS(initPlugins_exports);
25
+ var import_node_path = require("node:path");
25
26
  var import_shared = require("@rsbuild/shared");
26
27
  var import_createContext = require("./createContext");
27
28
  function getHTMLPathByEntry(entryName, config) {
@@ -29,6 +30,23 @@ function getHTMLPathByEntry(entryName, config) {
29
30
  const filename = config.html.outputStructure === "flat" ? `${entryName}.html` : `${entryName}/index.html`;
30
31
  return (0, import_shared.removeLeadingSlash)(`${htmlPath}/${filename}`);
31
32
  }
33
+ function applyTransformPlugin(chain, transformer) {
34
+ const name = "RsbuildTransformPlugin";
35
+ if (chain.plugins.get(name)) {
36
+ return;
37
+ }
38
+ class RsbuildTransformPlugin {
39
+ apply(compiler) {
40
+ compiler.__rsbuildTransformer = transformer;
41
+ compiler.hooks.thisCompilation.tap(name, (compilation) => {
42
+ compilation.hooks.childCompiler.tap(name, (childCompiler) => {
43
+ childCompiler.__rsbuildTransformer = transformer;
44
+ });
45
+ });
46
+ }
47
+ }
48
+ chain.plugin(name).use(RsbuildTransformPlugin);
49
+ }
32
50
  function getPluginAPI({
33
51
  context,
34
52
  pluginManager
@@ -73,12 +91,27 @@ function getPluginAPI({
73
91
  return matched.api;
74
92
  }
75
93
  };
94
+ let transformId = 0;
95
+ const transformer = {};
96
+ const transform = (descriptor, handler) => {
97
+ const id = `rsbuild-transform-${transformId++}`;
98
+ transformer[id] = handler;
99
+ hooks.modifyBundlerChain.tap((chain) => {
100
+ const rule = chain.module.rule(id);
101
+ if (descriptor.test) {
102
+ rule.test(descriptor.test);
103
+ }
104
+ rule.use(id).loader((0, import_node_path.join)(__dirname, "../rspack/transformLoader")).options({ id });
105
+ applyTransformPlugin(chain, transformer);
106
+ });
107
+ };
76
108
  (0, import_shared.onExitProcess)(() => {
77
109
  hooks.onExit.call();
78
110
  });
79
111
  return {
80
112
  context: publicContext,
81
113
  expose,
114
+ transform,
82
115
  useExposed,
83
116
  getHTMLPaths,
84
117
  getRsbuildConfig,
@@ -0,0 +1,5 @@
1
+ import type { LoaderContext } from '@rspack/core';
2
+ import type { RspackSourceMap } from '@rsbuild/shared';
3
+ export default function transform(this: LoaderContext<{
4
+ id: string;
5
+ }>, source: string, map?: string | RspackSourceMap): Promise<void>;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var transformLoader_exports = {};
20
+ __export(transformLoader_exports, {
21
+ default: () => transform
22
+ });
23
+ module.exports = __toCommonJS(transformLoader_exports);
24
+ async function transform(source, map) {
25
+ const callback = this.async();
26
+ const bypass = () => callback(null, source, map);
27
+ const transformId = this.getOptions().id;
28
+ if (!transformId) {
29
+ return bypass();
30
+ }
31
+ const transform2 = this._compiler?.__rsbuildTransformer?.[transformId];
32
+ if (!transform2) {
33
+ return bypass();
34
+ }
35
+ const result = await transform2({
36
+ code: source,
37
+ resource: this.resource,
38
+ resourcePath: this.resourcePath,
39
+ resourceQuery: this.resourceQuery,
40
+ addDependency: this.addDependency
41
+ });
42
+ if (result === null || result === void 0) {
43
+ return bypass();
44
+ }
45
+ if (typeof result === "string") {
46
+ return callback(null, result, map);
47
+ }
48
+ const useMap = map !== void 0 && map !== null;
49
+ const finalMap = result.map ?? map;
50
+ callback(null, result.code, useMap ? finalMap : void 0);
51
+ }
package/dist/types.d.ts CHANGED
@@ -1,5 +1,10 @@
1
- import type { RsbuildConfig, RsbuildPlugin, RsbuildPlugins, RsbuildContext, NormalizedConfig, RsbuildPluginAPI } from '@rsbuild/shared';
1
+ import type { RsbuildConfig, RsbuildPlugin, RsbuildPlugins, RsbuildContext, NormalizedConfig, RsbuildPluginAPI, TransformHandler } from '@rsbuild/shared';
2
2
  import type { Hooks } from './initHooks';
3
+ declare module '@rspack/core' {
4
+ interface Compiler {
5
+ __rsbuildTransformer?: Record<string, TransformHandler>;
6
+ }
7
+ }
3
8
  export type { RsbuildPlugin, RsbuildPlugins, RsbuildPluginAPI };
4
9
  /** The inner context. */
5
10
  export type InternalContext = RsbuildContext & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rsbuild/core",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "description": "The Rspack-based build tool.",
5
5
  "homepage": "https://rsbuild.dev",
6
6
  "bugs": {
@@ -52,12 +52,12 @@
52
52
  "types.d.ts"
53
53
  ],
54
54
  "dependencies": {
55
- "@rspack/core": "0.5.9-canary-8778e17-20240328104834",
55
+ "@rspack/core": "0.5.9-canary-8778e17-20240403045016",
56
56
  "@swc/helpers": "0.5.3",
57
57
  "core-js": "~3.36.0",
58
58
  "html-webpack-plugin": "npm:html-rspack-plugin@5.6.2",
59
59
  "postcss": "^8.4.38",
60
- "@rsbuild/shared": "0.5.6"
60
+ "@rsbuild/shared": "0.5.7"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@types/node": "16.x",