@boperators/plugin-esbuild 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.
- package/dist/index.d.ts +9 -0
- package/dist/index.js +58 -0
- package/package.json +51 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Plugin } from "esbuild";
|
|
2
|
+
export interface BoperatorsPluginOptions {
|
|
3
|
+
/** Path to tsconfig.json, relative to absWorkingDir (or process.cwd()). 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,58 @@
|
|
|
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
|
+
return {
|
|
16
|
+
name: "boperators",
|
|
17
|
+
setup(build) {
|
|
18
|
+
var _a;
|
|
19
|
+
const workDir = (_a = build.initialOptions.absWorkingDir) !== null && _a !== void 0 ? _a : process.cwd();
|
|
20
|
+
const tsconfigPath = options.project
|
|
21
|
+
? node_path_1.default.resolve(workDir, options.project)
|
|
22
|
+
: node_path_1.default.join(workDir, "tsconfig.json");
|
|
23
|
+
const bopConfig = (0, boperators_1.loadConfig)({ searchDir: node_path_1.default.dirname(tsconfigPath) });
|
|
24
|
+
const tsMorphProject = new boperators_1.Project({
|
|
25
|
+
tsConfigFilePath: tsconfigPath,
|
|
26
|
+
});
|
|
27
|
+
const errorManager = new boperators_1.ErrorManager(bopConfig);
|
|
28
|
+
const overloadStore = new boperators_1.OverloadStore(tsMorphProject, errorManager, bopConfig.logger);
|
|
29
|
+
const overloadInjector = new boperators_1.OverloadInjector(tsMorphProject, overloadStore, bopConfig.logger);
|
|
30
|
+
// Scan all project files for overload definitions upfront
|
|
31
|
+
const allFiles = tsMorphProject.getSourceFiles();
|
|
32
|
+
for (const file of allFiles) {
|
|
33
|
+
overloadStore.addOverloadsFromFile(file);
|
|
34
|
+
}
|
|
35
|
+
errorManager.throwIfErrorsElseLogWarnings();
|
|
36
|
+
build.onLoad({ filter: include }, (args) => {
|
|
37
|
+
try {
|
|
38
|
+
const normalizedPath = normalizePath(args.path);
|
|
39
|
+
const sourceFile = tsMorphProject.getSourceFile(normalizedPath);
|
|
40
|
+
if (!sourceFile)
|
|
41
|
+
return null;
|
|
42
|
+
const originalText = sourceFile.getFullText();
|
|
43
|
+
const result = overloadInjector.overloadFile(sourceFile);
|
|
44
|
+
if (result.text === originalText)
|
|
45
|
+
return null;
|
|
46
|
+
// Preserve the original loader so esbuild handles JSX correctly
|
|
47
|
+
const loader = args.path.endsWith(".tsx") ? "tsx" : "ts";
|
|
48
|
+
return { contents: result.text, loader };
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
bopConfig.logger.error(`Error transforming ${args.path}: ${error}`);
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
exports.default = boperators;
|
package/package.json
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@boperators/plugin-esbuild",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"description": "esbuild plugin for boperators - transforms operator overloads at build time.",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/DiefBell/boperators",
|
|
9
|
+
"directory": "plugins/esbuild"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/DiefBell/boperators/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/DiefBell/boperators/tree/main/plugins/esbuild",
|
|
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
|
+
"esbuild",
|
|
25
|
+
"plugin",
|
|
26
|
+
"transform"
|
|
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
|
+
"esbuild": ">=0.17.0",
|
|
44
|
+
"typescript": ">=5.0.0 <5.10.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"@types/node": "^25.2.3",
|
|
48
|
+
"boperators": "file:../../package",
|
|
49
|
+
"esbuild": "^0.25.12"
|
|
50
|
+
}
|
|
51
|
+
}
|