@gjsify/rolldown-plugin-deepkit 0.3.14

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/lib/index.d.ts ADDED
@@ -0,0 +1,6 @@
1
+ import type { Plugin } from 'rolldown';
2
+ export interface DeepkitPluginOptions {
3
+ reflection?: boolean;
4
+ }
5
+ export declare function deepkitPlugin(options?: DeepkitPluginOptions): Plugin;
6
+ export default deepkitPlugin;
package/lib/index.js ADDED
@@ -0,0 +1,53 @@
1
+ // Deepkit type-compiler reflection for Rolldown / Rollup / Vite.
2
+ //
3
+ // Direct port of `@gjsify/esbuild-plugin-deepkit`. Same lazy-loading
4
+ // contract: the Deepkit type compiler stays uninstalled until the user
5
+ // opts in via `reflection: true`, because its transitive dep
6
+ // `@marcj/ts-clone-node` does `require('typescript')` without declaring TS
7
+ // as a peer — eagerly importing breaks Yarn-PnP consumers that don't list
8
+ // TypeScript themselves.
9
+ //
10
+ // Hook: `transform(code, id)` with per-source filter via `createFilter`.
11
+ // `order: 'pre'` so reflection runs before any other JS transform.
12
+ import { inspect } from 'node:util';
13
+ let cachedLoader = null;
14
+ async function getLoader() {
15
+ if (cachedLoader)
16
+ return cachedLoader;
17
+ cachedLoader = (async () => {
18
+ const DkType = await import('@deepkit/type-compiler');
19
+ return new DkType.DeepkitLoader();
20
+ })();
21
+ return cachedLoader;
22
+ }
23
+ const FILTER = /\.(m|c)?tsx?$/;
24
+ function printDiagnostics(...args) {
25
+ console.log('[deepkit] printDiagnostics', inspect(args, false, 10, true));
26
+ }
27
+ export function deepkitPlugin(options = {}) {
28
+ const reflection = options.reflection ?? false;
29
+ return {
30
+ name: 'gjsify-deepkit',
31
+ transform: {
32
+ order: 'pre',
33
+ async handler(code, id) {
34
+ if (!reflection)
35
+ return null;
36
+ if (!FILTER.test(id))
37
+ return null;
38
+ try {
39
+ const loader = await getLoader();
40
+ const transformed = loader.transform(code, id);
41
+ if (transformed === code)
42
+ return null;
43
+ return { code: transformed, map: null };
44
+ }
45
+ catch (error) {
46
+ printDiagnostics({ file: id, error });
47
+ return null;
48
+ }
49
+ },
50
+ },
51
+ };
52
+ }
53
+ export default deepkitPlugin;
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@gjsify/rolldown-plugin-deepkit",
3
+ "version": "0.3.14",
4
+ "description": "Deepkit type compiler plugin for Rolldown / Rollup / Vite",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "module": "lib/index.js",
8
+ "types": "lib/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "types": "./lib/index.d.ts",
12
+ "default": "./lib/index.js"
13
+ }
14
+ },
15
+ "scripts": {
16
+ "clear": "rm -rf lib tsconfig.tsbuildinfo || exit 0",
17
+ "check": "tsc --noEmit",
18
+ "build": "tsc"
19
+ },
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/gjsify/gjsify.git"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/gjsify/gjsify/issues"
26
+ },
27
+ "homepage": "https://github.com/gjsify/gjsify/tree/main/packages/infra/rolldown-plugin-deepkit#readme",
28
+ "keywords": [
29
+ "rolldown",
30
+ "rollup",
31
+ "vite",
32
+ "deepkit",
33
+ "typescript",
34
+ "reflection"
35
+ ],
36
+ "license": "MIT",
37
+ "dependencies": {
38
+ "@deepkit/type-compiler": "^1.0.19",
39
+ "typescript": "^6.0.3"
40
+ },
41
+ "peerDependencies": {
42
+ "rolldown": "^1.0.0-rc.18"
43
+ },
44
+ "peerDependenciesMeta": {
45
+ "rolldown": {
46
+ "optional": true
47
+ }
48
+ },
49
+ "devDependencies": {
50
+ "@types/node": "^25.6.0",
51
+ "rolldown": "^1.0.0-rc.18"
52
+ }
53
+ }
package/src/index.ts ADDED
@@ -0,0 +1,65 @@
1
+ // Deepkit type-compiler reflection for Rolldown / Rollup / Vite.
2
+ //
3
+ // Direct port of `@gjsify/esbuild-plugin-deepkit`. Same lazy-loading
4
+ // contract: the Deepkit type compiler stays uninstalled until the user
5
+ // opts in via `reflection: true`, because its transitive dep
6
+ // `@marcj/ts-clone-node` does `require('typescript')` without declaring TS
7
+ // as a peer — eagerly importing breaks Yarn-PnP consumers that don't list
8
+ // TypeScript themselves.
9
+ //
10
+ // Hook: `transform(code, id)` with per-source filter via `createFilter`.
11
+ // `order: 'pre'` so reflection runs before any other JS transform.
12
+
13
+ import { inspect } from 'node:util';
14
+ import type { Plugin } from 'rolldown';
15
+
16
+ export interface DeepkitPluginOptions {
17
+ reflection?: boolean;
18
+ }
19
+
20
+ interface DeepkitLoader {
21
+ transform: (contents: string, path: string) => string;
22
+ }
23
+
24
+ let cachedLoader: Promise<DeepkitLoader> | null = null;
25
+ async function getLoader(): Promise<DeepkitLoader> {
26
+ if (cachedLoader) return cachedLoader;
27
+ cachedLoader = (async () => {
28
+ const DkType = await import('@deepkit/type-compiler');
29
+ return new DkType.DeepkitLoader() as DeepkitLoader;
30
+ })();
31
+ return cachedLoader;
32
+ }
33
+
34
+ const FILTER = /\.(m|c)?tsx?$/;
35
+
36
+ function printDiagnostics(...args: unknown[]): void {
37
+ console.log('[deepkit] printDiagnostics', inspect(args, false, 10, true));
38
+ }
39
+
40
+ export function deepkitPlugin(options: DeepkitPluginOptions = {}): Plugin {
41
+ const reflection = options.reflection ?? false;
42
+
43
+ return {
44
+ name: 'gjsify-deepkit',
45
+ transform: {
46
+ order: 'pre' as const,
47
+ async handler(code, id) {
48
+ if (!reflection) return null;
49
+ if (!FILTER.test(id)) return null;
50
+
51
+ try {
52
+ const loader = await getLoader();
53
+ const transformed = loader.transform(code, id);
54
+ if (transformed === code) return null;
55
+ return { code: transformed, map: null };
56
+ } catch (error) {
57
+ printDiagnostics({ file: id, error });
58
+ return null;
59
+ }
60
+ },
61
+ },
62
+ };
63
+ }
64
+
65
+ export default deepkitPlugin;
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "rootDir": "src",
4
+ "outDir": "lib",
5
+ "declaration": true,
6
+ "target": "ESNext",
7
+ "module": "ESNext",
8
+ "moduleResolution": "bundler",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "types": ["node"]
13
+ },
14
+ "include": ["src/**/*"]
15
+ }