Skip to content

Commit 7fc8055

Browse files
committed
feat(parser): Bundle types locally to avoid @pgsql/types dependency
- Copy TypeScript type definitions from types/*/dist/ during build - Update import paths to use local ./types instead of @pgsql/types - Make parser package completely self-contained with all necessary types - Update PUBLISH.md to document the types bundling process
1 parent d83fb6e commit 7fc8055

File tree

4 files changed

+43
-14
lines changed

4 files changed

+43
-14
lines changed

PUBLISH.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,13 @@ PARSER_BUILD_TYPE=lts npm run build
229229
### Build Process
230230
The simplified parser package:
231231
1. Copies WASM files from the `versions/*/wasm/` directories
232-
2. Generates index files from templates based on the build configuration
233-
3. Creates version-specific export files
234-
4. Creates a `build-info.json` file documenting what was included
232+
2. Copies TypeScript type definitions from the `types/*/dist/` directories
233+
3. Updates import paths to use local types instead of `@pgsql/types`
234+
4. Generates index files from templates based on the build configuration
235+
5. Creates version-specific export files
236+
6. Creates a `build-info.json` file documenting what was included
235237

236-
The templates automatically adjust to include only the versions specified in the build configuration, ensuring proper TypeScript types and runtime validation.
238+
The templates automatically adjust to include only the versions specified in the build configuration, ensuring proper TypeScript types and runtime validation. The package is completely self-contained with all necessary types bundled.
237239

238240
**Note**: Build scripts use `cross-env` for Windows compatibility.
239241

parser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pgsql/parser",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"author": "Dan Lynch <[email protected]>",
55
"description": "Multi-version PostgreSQL parser with dynamic version selection",
66
"main": "./wasm/index.cjs",

parser/scripts/prepare.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,40 @@ config.versions.forEach(version => {
107107
if (fs.statSync(sourcePath).isFile()) {
108108
console.log(`Copying ${file} for v${version}...`);
109109
fs.copyFileSync(sourcePath, destPath);
110+
111+
// Update index.d.ts to use local types
112+
if (file === 'index.d.ts') {
113+
let content = fs.readFileSync(destPath, 'utf8');
114+
content = content.replace('export * from "@pgsql/types";', 'export * from "./types";');
115+
fs.writeFileSync(destPath, content);
116+
}
110117
}
111118
});
119+
120+
// Copy types files
121+
const typesSourceDir = path.join(__dirname, `../../types/${version}/dist`);
122+
const typesTargetDir = path.join(versionWasmDir, 'types');
123+
124+
if (fs.existsSync(typesSourceDir)) {
125+
// Create types directory
126+
if (!fs.existsSync(typesTargetDir)) {
127+
fs.mkdirSync(typesTargetDir, { recursive: true });
128+
}
129+
130+
// Copy essential type files
131+
const typeFiles = ['index.d.ts', 'index.js', 'types.d.ts', 'types.js', 'enums.d.ts', 'enums.js'];
132+
typeFiles.forEach(file => {
133+
const sourcePath = path.join(typesSourceDir, file);
134+
const destPath = path.join(typesTargetDir, file);
135+
136+
if (fs.existsSync(sourcePath)) {
137+
console.log(`Copying types/${file} for v${version}...`);
138+
fs.copyFileSync(sourcePath, destPath);
139+
}
140+
});
141+
} else {
142+
console.warn(`Warning: Types for version ${version} not found at ${typesSourceDir}`);
143+
}
112144
});
113145

114146
// Generate files from templates

parser/templates/index.d.ts.template

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,6 @@ export interface ParseResult {
1313
};
1414
}
1515

16-
export interface Parser {
17-
parse(query: string): ParseResult;
18-
parseSync?(query: string): ParseResult;
19-
fingerprint?(query: string): string;
20-
normalize?(query: string): string;
21-
loadModule?(): Promise<void>;
22-
}
23-
2416
export declare class Parser {
2517
constructor(version?: ${VERSION_UNION});
2618
parse(query: string): Promise<ParseResult>;
@@ -32,4 +24,7 @@ export declare class Parser {
3224
export default Parser;
3325

3426
// Version-specific exports
35-
${VERSION_TYPE_EXPORTS}
27+
${VERSION_TYPE_EXPORTS}
28+
29+
// Re-export types from the default version
30+
export * from './v${DEFAULT_VERSION}/types';

0 commit comments

Comments
 (0)