@jay-framework/typescript-bridge 0.2.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.
@@ -0,0 +1,26 @@
1
+ import type * as typescript from 'typescript';
2
+ declare const tsModule: typeof typescript;
3
+ /**
4
+ * Re-export the TypeScript module to avoid ESM/CommonJS compatibility issues
5
+ * This allows importing TypeScript in a consistent way across the project
6
+ */
7
+ export declare const ts: typeof typescript;
8
+ /**
9
+ * Re-export the TypeScript types for use in type annotations
10
+ */
11
+ export type { typescript as TypeScript };
12
+ /**
13
+ * Create a proxy that forwards all property access to the TypeScript module
14
+ * This allows accessing any TypeScript utility without explicitly listing them
15
+ */
16
+ export declare const tsBridge: typeof typescript;
17
+ /**
18
+ * Alternative approach: Create a function that returns any TypeScript utility
19
+ * Usage: getTs('isIdentifier')(node)
20
+ */
21
+ export declare function getTs<T extends keyof typeof tsModule>(utilName: T): (typeof tsModule)[T];
22
+ /**
23
+ * Default export for easy importing and destructuring
24
+ * Usage: import tsBridge, { ts } from '@jay-framework/typescript-bridge'
25
+ */
26
+ export default tsBridge;
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ import { createRequire } from 'module';
2
+ const require = createRequire(import.meta.url);
3
+ const tsModule = require('typescript');
4
+ /**
5
+ * Re-export the TypeScript module to avoid ESM/CommonJS compatibility issues
6
+ * This allows importing TypeScript in a consistent way across the project
7
+ */
8
+ export const ts = tsModule;
9
+ /**
10
+ * Create a proxy that forwards all property access to the TypeScript module
11
+ * This allows accessing any TypeScript utility without explicitly listing them
12
+ */
13
+ export const tsBridge = new Proxy(tsModule, {
14
+ get(target, prop) {
15
+ return target[prop];
16
+ },
17
+ });
18
+ /**
19
+ * Alternative approach: Create a function that returns any TypeScript utility
20
+ * Usage: getTs('isIdentifier')(node)
21
+ */
22
+ export function getTs(utilName) {
23
+ return tsModule[utilName];
24
+ }
25
+ /**
26
+ * Default export for easy importing and destructuring
27
+ * Usage: import tsBridge, { ts } from '@jay-framework/typescript-bridge'
28
+ */
29
+ export default tsBridge;
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@jay-framework/typescript-bridge",
3
+ "version": "0.2.0",
4
+ "type": "module",
5
+ "description": "TypeScript CommonJS to ESM bridge for seamless TypeScript utility access",
6
+ "license": "Apache-2.0",
7
+ "main": "dist/index.js",
8
+ "directories": {
9
+ "lib": "lib"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "readme.md"
14
+ ],
15
+ "scripts": {
16
+ "build": "npm run build:js && npm run build:types",
17
+ "build:watch": "npm run build:js -- --watch & npm run build:types -- --watch",
18
+ "build:js": "vite build",
19
+ "build:types": "tsup lib/index.ts --dts-only --format esm",
20
+ "build:check-types": "tsc",
21
+ "clean": "rimraf dist",
22
+ "confirm": "npm run clean && npm run build && npm run build:check-types",
23
+ "test": "echo \"No tests specified\""
24
+ },
25
+ "author": "",
26
+ "dependencies": {
27
+ "typescript": "^5.3.3"
28
+ },
29
+ "devDependencies": {
30
+ "@jay-framework/dev-environment": "^0.7.0",
31
+ "@types/node": "^20.11.5",
32
+ "rimraf": "^5.0.5",
33
+ "tsup": "^8.0.1",
34
+ "vite": "^5.0.11"
35
+ }
36
+ }
package/readme.md ADDED
@@ -0,0 +1,77 @@
1
+ # @jay-framework/typescript-bridge
2
+
3
+ A TypeScript CommonJS to ESM bridge that provides seamless access to TypeScript utilities without ESM/CommonJS compatibility issues.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @jay-framework/typescript-bridge
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ### Default Import (Recommended)
14
+
15
+ ```typescript
16
+ import tsBridge from '@jay-framework/typescript-bridge';
17
+
18
+ // Decompose into individual functions
19
+ const { isIdentifier, isStatement, isBinaryExpression, visitEachChild, SyntaxKind } = tsBridge;
20
+
21
+ // Use as normal
22
+ if (isIdentifier(node)) {
23
+ console.log(node.text);
24
+ }
25
+ ```
26
+
27
+ ### Named Imports
28
+
29
+ ```typescript
30
+ import { tsBridge, ts, getTs } from '@jay-framework/typescript-bridge';
31
+
32
+ // Use the proxy directly
33
+ tsBridge.isIdentifier(node);
34
+
35
+ // Access the full TypeScript module
36
+ ts.visitEachChild(node, visitor, context);
37
+
38
+ // Get utilities dynamically
39
+ const isIdentifier = getTs('isIdentifier');
40
+ isIdentifier(node);
41
+ ```
42
+
43
+ ### Type Imports
44
+
45
+ ```typescript
46
+ import type { TypeScript as ts } from '@jay-framework/typescript-bridge';
47
+
48
+ function processNode(node: ts.Node): void {
49
+ // Type-safe TypeScript usage
50
+ }
51
+ ```
52
+
53
+ ## Benefits
54
+
55
+ - **No ESM/CommonJS issues**: Handles the compatibility problems automatically
56
+ - **Type-safe**: Full TypeScript intellisense and type checking
57
+ - **Flexible**: Multiple import patterns to suit your needs
58
+ - **Lightweight**: Minimal overhead, direct access to TypeScript utilities
59
+ - **Maintainable**: No need to list all utilities explicitly
60
+
61
+ ## API
62
+
63
+ ### `tsBridge` (default export)
64
+
65
+ A proxy object that provides access to all TypeScript utilities.
66
+
67
+ ### `ts`
68
+
69
+ The full TypeScript module for direct access.
70
+
71
+ ### `getTs(utilName)`
72
+
73
+ A function that returns any TypeScript utility by name.
74
+
75
+ ### `TypeScript` (type)
76
+
77
+ TypeScript types for type annotations.