@zerowire/unplugin 0.0.0-stage → 0.1.1
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 +68 -2
- package/dist/esbuild.d.ts +3 -0
- package/dist/esbuild.d.ts.map +1 -0
- package/dist/esbuild.js +3 -0
- package/dist/esbuild.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +39 -0
- package/dist/index.js.map +1 -0
- package/dist/rollup.d.ts +3 -0
- package/dist/rollup.d.ts.map +1 -0
- package/dist/rollup.js +3 -0
- package/dist/rollup.js.map +1 -0
- package/dist/vite.d.ts +3 -0
- package/dist/vite.d.ts.map +1 -0
- package/dist/vite.js +3 -0
- package/dist/vite.js.map +1 -0
- package/package.json +40 -3
package/README.md
CHANGED
|
@@ -1,3 +1,69 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @zerowire/unplugin
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Universal Ahead-of-Time build plugin for zerowire TypeScript binary codec and validator.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`@zerowire/unplugin` intercepts `compileWireCodec<T>()` macro calls in TypeScript code at build time and transforms them into compiled, branchless `DataView` validators, lazy Flyweight classes, and binary encoders. AST extraction and layout packing run via native Rust (`oxc_parser`), operating at sub-millisecond speeds without calling `tsc`.
|
|
8
|
+
|
|
9
|
+
Supported bundlers include Vite, Rolldown, Rollup, and esbuild.
|
|
10
|
+
|
|
11
|
+
## Installation
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pnpm add -D @zerowire/unplugin @zerowire/runtime
|
|
15
|
+
# or
|
|
16
|
+
npm install -D @zerowire/unplugin @zerowire/runtime
|
|
17
|
+
# or
|
|
18
|
+
bun add -d @zerowire/unplugin @zerowire/runtime
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Bundler Configuration
|
|
22
|
+
|
|
23
|
+
### Vite
|
|
24
|
+
|
|
25
|
+
```typescript
|
|
26
|
+
// vite.config.ts
|
|
27
|
+
import { defineConfig } from "vite";
|
|
28
|
+
import { zerowireVite } from "@zerowire/unplugin";
|
|
29
|
+
|
|
30
|
+
export default defineConfig({
|
|
31
|
+
plugins: [zerowireVite()],
|
|
32
|
+
});
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
### Rollup and Rolldown
|
|
36
|
+
|
|
37
|
+
```javascript
|
|
38
|
+
// rollup.config.js
|
|
39
|
+
import { zerowireRollup } from "@zerowire/unplugin";
|
|
40
|
+
|
|
41
|
+
export default {
|
|
42
|
+
plugins: [zerowireRollup()],
|
|
43
|
+
};
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### esbuild
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
import esbuild from "esbuild";
|
|
50
|
+
import { zerowireEsbuild } from "@zerowire/unplugin";
|
|
51
|
+
|
|
52
|
+
await esbuild.build({
|
|
53
|
+
entryPoints: ["src/index.ts"],
|
|
54
|
+
bundle: true,
|
|
55
|
+
outfile: "dist/bundle.js",
|
|
56
|
+
plugins: [zerowireEsbuild()],
|
|
57
|
+
});
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
## How It Works
|
|
61
|
+
|
|
62
|
+
1. During bundling, `@zerowire/unplugin` scans imported source files for `compileWireCodec<T>()` markers.
|
|
63
|
+
2. The Rust compiler extracts the target interface `T` using `oxc_parser` and `oxc_allocator`.
|
|
64
|
+
3. The layout packer sorts fixed fields by alignment (8B -> 4B -> 2B -> 1B) and emits a self-contained JavaScript codec module.
|
|
65
|
+
4. The call site is replaced with the compiled codec class, providing zero-overhead execution with no runtime compiler dependency.
|
|
66
|
+
|
|
67
|
+
## License
|
|
68
|
+
|
|
69
|
+
MIT OR Apache-2.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild.d.ts","sourceRoot":"","sources":["../src/esbuild.ts"],"names":[],"mappings":";AACA,wBAAgC"}
|
package/dist/esbuild.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"esbuild.js","sourceRoot":"","sources":["../src/esbuild.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,eAAe,QAAQ,CAAC,OAAO,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export interface ZeroWirePluginOptions {
|
|
2
|
+
/** Target file extensions to transform (default: ['.ts', '.tsx']) */
|
|
3
|
+
include?: string[];
|
|
4
|
+
}
|
|
5
|
+
export declare const unplugin: import("unplugin").UnpluginInstance<ZeroWirePluginOptions | undefined, boolean>;
|
|
6
|
+
export declare const vite: (options?: ZeroWirePluginOptions | undefined) => import("unplugin").VitePlugin<any> | import("unplugin").VitePlugin<any>[];
|
|
7
|
+
export declare const rollup: (options?: ZeroWirePluginOptions | undefined) => import("rollup").Plugin<any> | import("rollup").Plugin<any>[];
|
|
8
|
+
export declare const esbuild: (options?: ZeroWirePluginOptions | undefined) => import("unplugin").EsbuildPlugin;
|
|
9
|
+
export default unplugin;
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,qBAAqB;IACpC,qEAAqE;IACrE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB;AAED,eAAO,MAAM,QAAQ,iFAkCnB,CAAC;AAEH,eAAO,MAAM,IAAI,4HAAgB,CAAC;AAClC,eAAO,MAAM,MAAM,gHAAkB,CAAC;AACtC,eAAO,MAAM,OAAO,mFAAmB,CAAC;AACxC,eAAe,QAAQ,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//! @zerowire/unplugin: Ahead-of-Time build plugin for Vite, Rolldown, esbuild, and Rollup.
|
|
2
|
+
import { createUnplugin } from "unplugin";
|
|
3
|
+
import { compileWireCodec } from "@zerowire/napi";
|
|
4
|
+
export const unplugin = createUnplugin((options = {}) => {
|
|
5
|
+
const includeExts = options?.include ?? [".ts", ".tsx"];
|
|
6
|
+
return {
|
|
7
|
+
name: "zerowire-plugin",
|
|
8
|
+
transformInclude(id) {
|
|
9
|
+
return includeExts.some((ext) => id.endsWith(ext));
|
|
10
|
+
},
|
|
11
|
+
transform(code, id) {
|
|
12
|
+
if (!code.includes("compileWireCodec") && !code.includes("compileCodec")) {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const result = compileWireCodec(code, undefined);
|
|
17
|
+
// Replace compileWireCodec<T>() macro calls with compiled codec instantiation
|
|
18
|
+
const macroRegex = /(?:export\s+const\s+(\w+)\s*=\s*)?compile(?:Wire)?Codec<(\w+)>\(\);?/g;
|
|
19
|
+
const transformed = code.replace(macroRegex, (_match, varName, _typeName) => {
|
|
20
|
+
const exportVar = varName ? `export const ${varName} = ${result.targetType}Codec;` : "";
|
|
21
|
+
return `${result.jsCode}\n${exportVar}`;
|
|
22
|
+
});
|
|
23
|
+
return {
|
|
24
|
+
code: transformed,
|
|
25
|
+
map: null,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
catch (err) {
|
|
29
|
+
console.error(`[@zerowire/unplugin] Failed to transform ${id}:`, err);
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
});
|
|
35
|
+
export const vite = unplugin.vite;
|
|
36
|
+
export const rollup = unplugin.rollup;
|
|
37
|
+
export const esbuild = unplugin.esbuild;
|
|
38
|
+
export default unplugin;
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,2FAA2F;AAE3F,OAAO,EAAE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AO,CAAC,KAAK,CAAC,4CAA4C,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;gBACtE,OAAO,IAAI,CAAC;YACd,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,IAAI,GAAG,QAAQ,CAAC,IAAI,CAAC;AAClC,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC,MAAM,CAAC;AACtC,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC,OAAO,CAAC;AACxC,eAAe,QAAQ,CAAC"}
|
package/dist/rollup.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollup.d.ts","sourceRoot":"","sources":["../src/rollup.ts"],"names":[],"mappings":";AACA,wBAA+B"}
|
package/dist/rollup.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rollup.js","sourceRoot":"","sources":["../src/rollup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,eAAe,QAAQ,CAAC,MAAM,CAAC"}
|
package/dist/vite.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.d.ts","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":";AACA,wBAA6B"}
|
package/dist/vite.js
ADDED
package/dist/vite.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vite.js","sourceRoot":"","sources":["../src/vite.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,eAAe,QAAQ,CAAC,IAAI,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zerowire/unplugin",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "AOT build plugin for zerowire TypeScript validator and binary codec",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"exports": {
|
|
12
|
+
".": {
|
|
13
|
+
"import": "./dist/index.js",
|
|
14
|
+
"types": "./dist/index.d.ts"
|
|
15
|
+
},
|
|
16
|
+
"./vite": {
|
|
17
|
+
"import": "./dist/vite.js",
|
|
18
|
+
"types": "./dist/vite.d.ts"
|
|
19
|
+
},
|
|
20
|
+
"./esbuild": {
|
|
21
|
+
"import": "./dist/esbuild.js",
|
|
22
|
+
"types": "./dist/esbuild.d.ts"
|
|
23
|
+
},
|
|
24
|
+
"./rollup": {
|
|
25
|
+
"import": "./dist/rollup.js",
|
|
26
|
+
"types": "./dist/rollup.d.ts"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@zerowire/runtime": "0.1.1",
|
|
31
|
+
"unplugin": "^2.2.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@zerowire/napi": "0.1.1",
|
|
35
|
+
"typescript": "^5.8.0",
|
|
36
|
+
"vitest": "^3.0.0"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"build": "tsc -b",
|
|
40
|
+
"typecheck": "tsc --noEmit",
|
|
41
|
+
"test": "vitest run"
|
|
42
|
+
}
|
|
6
43
|
}
|