@rspack/browser 1.5.0-beta.1 → 1.5.0

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;
@@ -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,8 @@
1
+ /**
2
+ * We manually create binding.d.ts and re-export everything of the dts generated by napi to fix the cjs-esm interop
3
+ */
4
+
5
+ import * as binding from "./napi-binding";
6
+
7
+ export * from "./napi-binding"
8
+ export default binding;
@@ -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;
@@ -1,3 +1,25 @@
1
1
  export declare enum RequestType {
2
+ AddDependency = "AddDependency",
3
+ AddContextDependency = "AddContextDependency",
4
+ AddMissingDependency = "AddMissingDependency",
5
+ AddBuildDependency = "AddBuildDependency",
6
+ GetDependencies = "GetDependencies",
7
+ GetContextDependencies = "GetContextDependencies",
8
+ GetMissingDependencies = "GetMissingDependencies",
9
+ ClearDependencies = "ClearDependencies",
10
+ Resolve = "Resolve",
11
+ GetResolve = "GetResolve",
12
+ GetLogger = "GetLogger",
13
+ EmitError = "EmitError",
14
+ EmitWarning = "EmitWarning",
15
+ EmitFile = "EmitFile",
16
+ EmitDiagnostic = "EmitDiagnostic",
17
+ SetCacheable = "SetCacheable",
18
+ ImportModule = "ImportModule",
19
+ UpdateLoaderObjects = "UpdateLoaderObjects",
20
+ CompilationGetPath = "CompilationGetPath",
21
+ CompilationGetPathWithInfo = "CompilationGetPathWithInfo",
22
+ CompilationGetAssetPath = "CompilationGetAssetPath",
23
+ CompilationGetAssetPathWithInfo = "CompilationGetAssetPathWithInfo"
2
24
  }
3
25
  export declare function run(): Promise<void>;
@@ -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
  }