script-utils/bundlers/esbuild-impl/preprocess-plugin
This module defines a custom esbuild plugin that preprocesses JavaScript and TypeScript files.
@remarks We cannot use . instead of (dot) in the above description because the file itself is preprocessed with the same rule.
initCjs, initEsm and the shims they call are stringified with String(fn) and injected into every built bundle as an esbuild banner, so they must be reachable from one another by BARE identifier. That is why they all live in this module: esbuild compiles a cross-module call to (0, import_module.fn)(…), which would name a binding the emitted bundle does not have. Same-module references stay bare, and makeBanner() serializes the shims alongside the init function so they are in scope there. A shim that is not serialized silently degrades to whatever the consumer’s global scope holds under that name — which is how __name used to end up holding window.name.
Functions
Section titled “Functions”| Function | Description |
|---|---|
| ensureBrowserProcess | Ensures the bundle runs against a process global that browser-targeting packages recognize. |
| keepName | Returns its argument unchanged. |
| preprocessPlugin | Creates an esbuild plugin that preprocesses JavaScript and TypeScript files. This plugin performs the following tasks: - Replaces instances of import(dot)meta(dot)url with a Node.js-compatible __filename alternative. - Modifies the sourceMappingURL comment to ensure compatibility with Obsidian’s plugin system. - Adds a basic process object to the global scope if process is referenced but not defined. |