@boperators/plugin-bun 0.1.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,33 @@
1
+ # @boperators/plugin-bun
2
+
3
+ Bun plugin for [boperators](https://www.npmjs.com/package/boperators) that ensures operator overloads work when running TypeScript files directly with Bun, instead of requiring an intermediate transform step.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ bun add -D boperators @boperators/plugin-bun
9
+ ```
10
+
11
+ ## Setup
12
+
13
+ This plugin is enabled in your Bun config file, `bunfig.toml`:
14
+
15
+ ```toml
16
+ preload = ["./node_modules/@boperators/plugin-bun/index.ts"]
17
+ ```
18
+
19
+ Alternatively, instead of a long file path, create a `preload.ts` file in your project root:
20
+
21
+ ```typescript
22
+ import "@boperators/plugin-bun";
23
+ ```
24
+
25
+ and reference that in your `bunfig.toml`:
26
+
27
+ ```toml
28
+ preload = ["./preload.ts"]
29
+ ```
30
+
31
+ ## License
32
+
33
+ MIT
package/index.ts ADDED
@@ -0,0 +1,58 @@
1
+ import { readFileSync } from "node:fs";
2
+ import {
3
+ ErrorManager,
4
+ loadConfig,
5
+ OverloadInjector,
6
+ OverloadStore,
7
+ Project as TsMorphProject,
8
+ } from "boperators";
9
+ import { type BunPlugin, type PluginBuilder, plugin } from "bun";
10
+
11
+ const boperatorsPlugin: BunPlugin = {
12
+ name: "boperators",
13
+ target: "bun",
14
+ setup(build: PluginBuilder) {
15
+ // We'll manually get dependencies because then ts-morph returns a nice list of them!
16
+ const config = loadConfig();
17
+ const project = new TsMorphProject({ skipFileDependencyResolution: true });
18
+ const errorManager = new ErrorManager(config);
19
+ const overloadStore = new OverloadStore(
20
+ project,
21
+ errorManager,
22
+ config.logger,
23
+ );
24
+ const overloadInjector = new OverloadInjector(
25
+ project,
26
+ overloadStore,
27
+ config.logger,
28
+ );
29
+
30
+ build.onLoad({ filter: /\.ts$/ }, async (args) => {
31
+ try {
32
+ project.addSourceFileAtPath(args.path);
33
+ const dependencies = project.resolveSourceFileDependencies();
34
+
35
+ for (const depSourceFile of dependencies) {
36
+ overloadStore.addOverloadsFromFile(depSourceFile);
37
+ }
38
+ overloadStore.addOverloadsFromFile(args.path);
39
+
40
+ errorManager.throwIfErrorsElseLogWarnings();
41
+
42
+ const result = overloadInjector.overloadFile(args.path);
43
+
44
+ return { contents: result.text, loader: "ts" };
45
+ } catch (error) {
46
+ config.logger.error(`Error transforming ${args.path}: ${error}`);
47
+ // Return the original file as TypeScript so Bun doesn't
48
+ // fall back to parsing it as JavaScript.
49
+ const originalText = readFileSync(args.path, "utf-8");
50
+ return { contents: originalText, loader: "ts" };
51
+ } finally {
52
+ errorManager.clear();
53
+ }
54
+ });
55
+ },
56
+ };
57
+
58
+ plugin(boperatorsPlugin);
package/license.txt ADDED
@@ -0,0 +1,8 @@
1
+ Copyright 2025 Dief Bell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "@boperators/plugin-bun",
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "description": "Bun plugin for boperators - transforms operator overloads at runtime.",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/DiefBell/boperators",
9
+ "directory": "plugins/bun"
10
+ },
11
+ "homepage": "https://github.com/DiefBell/boperators/tree/main/plugins/bun",
12
+ "main": "./index.ts",
13
+ "keywords": [
14
+ "boperators",
15
+ "typescript",
16
+ "operator",
17
+ "overload",
18
+ "operator-overloading",
19
+ "bun",
20
+ "plugin",
21
+ "runtime"
22
+ ],
23
+ "scripts": {
24
+ "prepublish": "true"
25
+ },
26
+ "files": [
27
+ "package.json",
28
+ "README.md",
29
+ "license.txt",
30
+ "index.ts"
31
+ ],
32
+ "peerDependencies": {
33
+ "boperators": "0.1.0",
34
+ "typescript": ">=5.0.0 <5.10.0"
35
+ },
36
+ "devDependencies": {
37
+ "@types/bun": "^1.3.8"
38
+ }
39
+ }