@boperators/plugin-vite 0.1.4

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.
@@ -0,0 +1,9 @@
1
+ import type { Plugin } from "vite";
2
+ export interface BoperatorsPluginOptions {
3
+ /** Path to tsconfig.json, relative to Vite's root. Defaults to "tsconfig.json". */
4
+ project?: string;
5
+ /** RegExp filter for files to transform. Defaults to /\.tsx?$/. */
6
+ include?: RegExp;
7
+ }
8
+ export declare function boperators(options?: BoperatorsPluginOptions): Plugin;
9
+ export default boperators;
package/dist/index.js ADDED
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.boperators = boperators;
7
+ const node_path_1 = __importDefault(require("node:path"));
8
+ const boperators_1 = require("boperators");
9
+ function normalizePath(p) {
10
+ return p.replace(/\\/g, "/");
11
+ }
12
+ function boperators(options = {}) {
13
+ var _a;
14
+ const include = (_a = options.include) !== null && _a !== void 0 ? _a : /\.tsx?$/;
15
+ let tsMorphProject;
16
+ let overloadStore;
17
+ let overloadInjector;
18
+ return {
19
+ name: "boperators",
20
+ enforce: "pre",
21
+ configResolved(config) {
22
+ const root = config.root;
23
+ const tsconfigPath = options.project
24
+ ? node_path_1.default.resolve(root, options.project)
25
+ : node_path_1.default.join(root, "tsconfig.json");
26
+ const bopConfig = (0, boperators_1.loadConfig)({ searchDir: node_path_1.default.dirname(tsconfigPath) });
27
+ tsMorphProject = new boperators_1.Project({ tsConfigFilePath: tsconfigPath });
28
+ const errorManager = new boperators_1.ErrorManager(bopConfig);
29
+ overloadStore = new boperators_1.OverloadStore(tsMorphProject, errorManager, bopConfig.logger);
30
+ overloadInjector = new boperators_1.OverloadInjector(tsMorphProject, overloadStore, bopConfig.logger);
31
+ const allFiles = tsMorphProject.getSourceFiles();
32
+ for (const file of allFiles) {
33
+ overloadStore.addOverloadsFromFile(file);
34
+ }
35
+ errorManager.throwIfErrorsElseLogWarnings();
36
+ },
37
+ transform(code, id) {
38
+ // Skip virtual modules (Vite's internal convention)
39
+ if (id.startsWith("\0"))
40
+ return null;
41
+ // Strip Vite query strings (e.g. ?t=123456, ?raw, ?url)
42
+ const cleanId = id.split("?")[0];
43
+ if (!include.test(cleanId))
44
+ return null;
45
+ const normalizedId = normalizePath(cleanId);
46
+ const sourceFile = tsMorphProject.getSourceFile(normalizedId);
47
+ if (!sourceFile)
48
+ return null;
49
+ // Sync ts-morph's in-memory state with Vite's current file content.
50
+ // This ensures HMR edits are picked up without restarting the plugin.
51
+ sourceFile.replaceWithText(code);
52
+ const result = overloadInjector.overloadFile(sourceFile);
53
+ if (result.text === code)
54
+ return null;
55
+ const map = (0, boperators_1.toV3SourceMap)(result.edits, code, result.text, normalizedId);
56
+ return { code: result.text, map };
57
+ },
58
+ };
59
+ }
60
+ exports.default = boperators;
package/package.json ADDED
@@ -0,0 +1,51 @@
1
+ {
2
+ "name": "@boperators/plugin-vite",
3
+ "version": "0.1.4",
4
+ "license": "MIT",
5
+ "description": "Vite plugin for boperators - transforms operator overloads at build time.",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/DiefBell/boperators",
9
+ "directory": "plugins/vite"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/DiefBell/boperators/issues"
13
+ },
14
+ "homepage": "https://github.com/DiefBell/boperators/tree/main/plugins/vite",
15
+ "type": "commonjs",
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "keywords": [
19
+ "boperators",
20
+ "typescript",
21
+ "operator",
22
+ "overload",
23
+ "operator-overloading",
24
+ "vite",
25
+ "plugin",
26
+ "rollup"
27
+ ],
28
+ "scripts": {
29
+ "build": "tsc",
30
+ "watch": "tsc -w",
31
+ "test": "bun test",
32
+ "test:watch": "bun test --watch",
33
+ "prepublish": "bun run build"
34
+ },
35
+ "files": [
36
+ "package.json",
37
+ "README.md",
38
+ "license.txt",
39
+ "dist"
40
+ ],
41
+ "peerDependencies": {
42
+ "boperators": "0.1.4",
43
+ "typescript": ">=5.0.0 <5.10.0",
44
+ "vite": ">=4.0.0"
45
+ },
46
+ "devDependencies": {
47
+ "@types/node": "^25.2.3",
48
+ "boperators": "file:../../package",
49
+ "vite": "^6.3.5"
50
+ }
51
+ }