@rspack-canary/browser 1.5.0-canary-efb61069-20250820113456 → 1.5.1-canary-7c68c987-20250828115508

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/README.md ADDED
@@ -0,0 +1,15 @@
1
+ <picture>
2
+ <img alt="Rspack Banner" src="https://assets.rspack.rs/rspack/rspack-banner.png">
3
+ </picture>
4
+
5
+ # @rspack/browser
6
+
7
+ Rspack for running in the browser. This is still in early stage and may not follow the semver.
8
+
9
+ ## Documentation
10
+
11
+ See <https://rspack.rs/api/javascript-api/browser> for details.
12
+
13
+ ## License
14
+
15
+ Rspack is [MIT licensed](https://github.com/web-infra-dev/rspack/blob/main/LICENSE).
@@ -94,6 +94,11 @@ declare class Compiler {
94
94
  cache: Cache;
95
95
  compilerPath: string;
96
96
  options: RspackOptionsNormalized;
97
+ /**
98
+ * Note: This is not a webpack public API, maybe removed in future.
99
+ * @internal
100
+ */
101
+ __internal_browser_require: (id: string) => unknown;
97
102
  constructor(context: string, options: RspackOptionsNormalized);
98
103
  get recordsInputPath(): never;
99
104
  get recordsOutputPath(): never;
@@ -18,7 +18,7 @@ declare class MultiWatching {
18
18
  * @param compiler - the compiler
19
19
  */
20
20
  constructor(watchings: Watching[], compiler: MultiCompiler);
21
- invalidate(callback: Callback<Error, void>): void;
21
+ invalidate(callback?: Callback<Error, void>): void;
22
22
  invalidateWithChangesAndRemovals(changedFiles?: Set<string>, removedFiles?: Set<string>, callback?: Callback<Error, void>): void;
23
23
  close(callback: Callback<Error, void>): void;
24
24
  suspend(): void;
@@ -16,4 +16,8 @@ export default class NativeWatchFileSystem implements WatchFileSystem {
16
16
  }, _startTime: number, options: Watchpack.WatchOptions, callback: (error: Error | null, fileTimeInfoEntries: Map<string, FileSystemInfoEntry | "ignore">, contextTimeInfoEntries: Map<string, FileSystemInfoEntry | "ignore">, changedFiles: Set<string>, removedFiles: Set<string>) => void, callbackUndelayed: (fileName: string, changeTime: number) => void): Watcher;
17
17
  getNativeWatcher(options: Watchpack.WatchOptions): binding.NativeWatcher;
18
18
  triggerEvent(kind: "change" | "remove" | "create", path: string): void;
19
+ formatWatchDependencies(dependencies: Iterable<string> & {
20
+ added?: Iterable<string>;
21
+ removed?: Iterable<string>;
22
+ }): [string[], string[]];
19
23
  }
@@ -0,0 +1,28 @@
1
+ import type { Compiler } from ".";
2
+ interface BrowserHttpImportPluginOptions {
3
+ /**
4
+ * ESM CDN domain
5
+ */
6
+ domain: string | ((request: string, packageName: string) => string);
7
+ /**
8
+ * Specify ESM CDN URL for dependencies.
9
+ */
10
+ dependencyUrl?: Record<string, string | undefined> | ((packageName: string) => string | undefined);
11
+ /**
12
+ * Specify versions for dependencies.
13
+ * Default to "latest" if not specified.
14
+ */
15
+ dependencyVersions?: Record<string, string | undefined>;
16
+ }
17
+ /**
18
+ * Convert imports of dependencies in node modules to http imports from esm cdn.
19
+ */
20
+ export declare class BrowserHttpImportEsmPlugin {
21
+ private options;
22
+ constructor(options: BrowserHttpImportPluginOptions);
23
+ apply(compiler: Compiler): void;
24
+ resolveWithUrlIssuer(request: string, issuer: URL): string;
25
+ resolveNodeModule(request: string, packageName: string): string;
26
+ isNodeModule(request: string): boolean;
27
+ }
28
+ export {};
@@ -0,0 +1,32 @@
1
+ import type { Compiler } from "../Compiler";
2
+ type BrowserRequire = typeof Compiler.prototype.__internal_browser_require;
3
+ /**
4
+ * Represents the runtime context for CommonJS modules in a browser environment.
5
+ */
6
+ interface CommonJsRuntime {
7
+ module: any;
8
+ exports: any;
9
+ require: BrowserRequire;
10
+ }
11
+ interface BrowserRequirePluginOptions {
12
+ /**
13
+ * This function defines how to execute CommonJS code.
14
+ */
15
+ execute: (code: string, runtime: CommonJsRuntime) => void;
16
+ }
17
+ /**
18
+ * This plugin inject browser-compatible `require` function to the `Compiler`.
19
+ * 1. It resolves the JavaScript in the memfs with Node.js resolution algorithm rather than in the host filesystem.
20
+ * 2. It transform ESM to CommonJS which will be executed with a user-defined `execute` function.
21
+ */
22
+ export declare class BrowserRequirePlugin {
23
+ private options;
24
+ /**
25
+ * This is an unsafe way to execute code in the browser using `new Function`.
26
+ * It is your responsibility to ensure that your application is not vulnerable to attacks due to this function.
27
+ */
28
+ static unsafeExecute: (code: string, runtime: CommonJsRuntime) => void;
29
+ constructor(options: BrowserRequirePluginOptions);
30
+ apply(compiler: Compiler): void;
31
+ }
32
+ export {};
@@ -1,4 +1,6 @@
1
1
  export * from "../index";
2
+ export { BrowserHttpImportEsmPlugin } from "./BrowserHttpImportEsmPlugin";
3
+ export { BrowserRequirePlugin } from "./BrowserRequire";
2
4
  export declare const builtinMemFs: {
3
5
  fs: import("memfs").IFs;
4
6
  volume: import("memfs").Volume;
@@ -5,7 +5,8 @@ export declare class ExternalsPlugin extends RspackBuiltinPlugin {
5
5
  #private;
6
6
  private type;
7
7
  private externals;
8
+ private placeInInitial?;
8
9
  name: BuiltinPluginName;
9
- constructor(type: string, externals: Externals);
10
+ constructor(type: string, externals: Externals, placeInInitial?: boolean | undefined);
10
11
  raw(): BuiltinPlugin | undefined;
11
12
  }
@@ -1,22 +1,8 @@
1
1
  import type { Module } from "../../Module";
2
2
  export declare const BuiltinLazyCompilationPlugin: {
3
- new (module: (args: {
4
- module: string;
5
- path: string;
6
- }) => {
7
- active: boolean;
8
- data: string;
9
- client: string;
10
- }, cacheable: boolean, entries: boolean, imports: boolean, test?: RegExp | ((module: Module) => boolean) | undefined): {
3
+ new (currentActiveModules: () => Set<string>, entries: boolean, imports: boolean, client: string, test?: RegExp | ((module: Module) => boolean) | undefined): {
11
4
  name: string;
12
- _args: [module: (args: {
13
- module: string;
14
- path: string;
15
- }) => {
16
- active: boolean;
17
- data: string;
18
- client: string;
19
- }, cacheable: boolean, entries: boolean, imports: boolean, test?: RegExp | ((module: Module) => boolean) | undefined];
5
+ _args: [currentActiveModules: () => Set<string>, entries: boolean, imports: boolean, client: string, test?: RegExp | ((module: Module) => boolean) | undefined];
20
6
  affectedHooks: "done" | "compilation" | "run" | "afterDone" | "thisCompilation" | "invalid" | "compile" | "normalModuleFactory" | "contextModuleFactory" | "initialize" | "shouldEmit" | "infrastructureLog" | "beforeRun" | "emit" | "assetEmitted" | "afterEmit" | "failed" | "shutdown" | "watchRun" | "watchClose" | "environment" | "afterEnvironment" | "afterPlugins" | "afterResolvers" | "make" | "beforeCompile" | "afterCompile" | "finishMake" | "entryOption" | "additionalPass" | undefined;
21
7
  raw(compiler: import("../..").Compiler): import("../../binding").BuiltinPlugin;
22
8
  apply(compiler: import("../..").Compiler): void;
@@ -322,8 +322,32 @@ export interface LoaderContext<OptionsType = {}> {
322
322
  */
323
323
  __internal__setParseMeta: (key: string, value: string) => void;
324
324
  }
325
- export type LoaderDefinitionFunction<OptionsType = {}, ContextAdditions = {}> = (this: LoaderContext<OptionsType> & ContextAdditions, content: string, sourceMap?: string | SourceMap, additionalData?: AdditionalData) => string | void | Buffer | Promise<string | Buffer>;
326
- export type PitchLoaderDefinitionFunction<OptionsType = {}, ContextAdditions = {}> = (this: LoaderContext<OptionsType> & ContextAdditions, remainingRequest: string, previousRequest: string, data: object) => string | void | Buffer | Promise<string | Buffer>;
325
+ export type LoaderDefinitionFunction<OptionsType = {}, ContextAdditions = {}> = (this: LoaderContext<OptionsType> & ContextAdditions, content: string, sourceMap?: string | SourceMap, additionalData?: AdditionalData) => string | void | Buffer | Promise<string | Buffer | void>;
326
+ export type PitchLoaderDefinitionFunction<OptionsType = {}, ContextAdditions = {}> = (this: LoaderContext<OptionsType> & ContextAdditions, remainingRequest: string, previousRequest: string, data: object) => string | void | Buffer | Promise<string | Buffer | void>;
327
+ /**
328
+ * Defines a loader for Rspack.
329
+ * A loader is a transformer that converts various types of modules into Rspack
330
+ * supported types. By using different kinds of loaders, you can extend Rspack to
331
+ * process additional module types, including JSX, Markdown, Sass, Less, and more.
332
+ *
333
+ * @template OptionsType - The type of options that the loader accepts
334
+ * @template ContextAdditions - Additional properties to add to the loader context
335
+ *
336
+ * @example
337
+ * ```ts
338
+ * import type { LoaderDefinition } from '@rspack/core';
339
+ *
340
+ * type MyLoaderOptions = {
341
+ * foo: string;
342
+ * };
343
+ *
344
+ * const myLoader: LoaderDefinition<MyLoaderOptions> = function(source) {
345
+ * return someOperation(source);
346
+ * };
347
+ *
348
+ * export default myLoader;
349
+ * ```
350
+ */
327
351
  export type LoaderDefinition<OptionsType = {}, ContextAdditions = {}> = LoaderDefinitionFunction<OptionsType, ContextAdditions> & {
328
352
  raw?: false;
329
353
  pitch?: PitchLoaderDefinitionFunction;