Skip to content

Commit 5aafa4f

Browse files
committed
build config
1 parent 923b7e8 commit 5aafa4f

File tree

7 files changed

+559
-71
lines changed

7 files changed

+559
-71
lines changed

config/versions.json

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"versions": {
3+
"13": {
4+
"libpg-query": "13.5.7",
5+
"pgsql-parser": "13.18.0",
6+
"pgsql-deparser": "13.17.0",
7+
"@pgsql/types": "13.11.1",
8+
"npmTag": "pg13"
9+
},
10+
"14": {
11+
"libpg-query": "14.2.5",
12+
"pgsql-parser": "14.0.1",
13+
"pgsql-deparser": "14.0.1",
14+
"@pgsql/types": "14.1.1",
15+
"npmTag": "pg14"
16+
},
17+
"15": {
18+
"libpg-query": "15.4.8",
19+
"pgsql-parser": "15.0.0",
20+
"pgsql-deparser": "15.0.0",
21+
"@pgsql/types": "15.1.1",
22+
"npmTag": "pg15"
23+
},
24+
"16": {
25+
"libpg-query": "16.5.5",
26+
"pgsql-parser": "16.0.0",
27+
"pgsql-deparser": "16.0.0",
28+
"@pgsql/types": "16.1.1",
29+
"npmTag": "pg16"
30+
},
31+
"17": {
32+
"libpg-query": "17.5.5",
33+
"pgsql-parser": "17.7.5",
34+
"pgsql-deparser": "17.8.3",
35+
"@pgsql/types": "17.6.1",
36+
"npmTag": "pg17"
37+
}
38+
}
39+
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
"build:dev": "lerna run build:dev --stream; yarn symlink",
2121
"lint": "lerna run lint --parallel",
2222
"symlink": "symlink-workspace --logLevel error",
23-
"postinstall": "yarn symlink"
23+
"postinstall": "yarn symlink",
24+
"bump-versions": "ts-node scripts/bump-versions.ts"
2425
},
2526
"devDependencies": {
2627
"@types/jest": "^29.5.11",
@@ -39,6 +40,7 @@
3940
"prettier": "^3.0.2",
4041
"rimraf": "4.4.1",
4142
"strip-ansi": "^6",
43+
"semver": "^7.7.2",
4244
"symlink-workspace": "^1.10.0",
4345
"ts-jest": "^29.1.1",
4446
"ts-node": "^10.9.2",

packages/deparser/config/deparser-versions.json

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,5 @@
11
{
22
"packageName": "pgsql-deparser",
3-
"versions": {
4-
"13": {
5-
"deparserVersion": "13.17.0",
6-
"typesVersion": "13.11.1",
7-
"pgVersion": "13",
8-
"npmTag": "pg13"
9-
},
10-
"14": {
11-
"deparserVersion": "14.0.0",
12-
"typesVersion": "14.1.1",
13-
"pgVersion": "14",
14-
"npmTag": "pg14"
15-
},
16-
"15": {
17-
"deparserVersion": "15.0.0",
18-
"typesVersion": "15.1.1",
19-
"pgVersion": "15",
20-
"npmTag": "pg15"
21-
},
22-
"16": {
23-
"deparserVersion": "16.0.0",
24-
"typesVersion": "16.1.1",
25-
"pgVersion": "16",
26-
"npmTag": "pg16"
27-
}
28-
},
293
"packageTemplate": {
304
"author": "Dan Lynch <[email protected]>",
315
"homepage": "https://github.com/launchql/pgsql-parser",
@@ -37,7 +11,6 @@
3711
"scripts": {
3812
"copy": "copyfiles -f ../../../../LICENSE README.md package.json dist",
3913
"clean": "rimraf dist",
40-
"prepare": "npm run build",
4114
"build": "npm run clean && tsc && tsc -p tsconfig.esm.json && npm run copy",
4215
"publish:pkg": "npm publish --tag {{VERSION_TAG}}"
4316
},

packages/deparser/scripts/generate-version-packages.ts

Lines changed: 39 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,52 @@ import * as path from 'path';
77
*/
88

99
const VERSIONS_DIR = 'versions';
10-
const CONFIG_FILE = 'config/deparser-versions.json';
10+
const ROOT_CONFIG_FILE = '../../config/versions.json';
11+
const LOCAL_CONFIG_FILE = 'config/deparser-versions.json';
1112

12-
interface VersionConfig {
13-
deparserVersion: string;
14-
typesVersion: string;
15-
pgVersion: string;
13+
interface VersionInfo {
14+
'libpg-query': string;
15+
'pgsql-parser': string;
16+
'pgsql-deparser': string | null;
17+
'@pgsql/types': string;
1618
npmTag: string;
1719
}
1820

19-
interface Config {
21+
interface RootConfig {
22+
versions: Record<string, VersionInfo>;
23+
}
24+
25+
interface LocalConfig {
2026
packageName: string;
21-
versions: Record<string, VersionConfig>;
2227
packageTemplate: Record<string, any>;
2328
}
2429

25-
function loadConfig(): Config {
26-
const configPath = path.join(process.cwd(), CONFIG_FILE);
27-
const configContent = fs.readFileSync(configPath, 'utf-8');
28-
return JSON.parse(configContent);
30+
function loadConfigs(): { rootConfig: RootConfig; localConfig: LocalConfig } {
31+
// Load root versions config
32+
const rootConfigPath = path.join(__dirname, '..', ROOT_CONFIG_FILE);
33+
const rootConfigContent = fs.readFileSync(rootConfigPath, 'utf-8');
34+
const rootConfig: RootConfig = JSON.parse(rootConfigContent);
35+
36+
// Load local package template config
37+
const localConfigPath = path.join(process.cwd(), LOCAL_CONFIG_FILE);
38+
const localConfigContent = fs.readFileSync(localConfigPath, 'utf-8');
39+
const localConfig: LocalConfig = JSON.parse(localConfigContent);
40+
41+
return { rootConfig, localConfig };
2942
}
3043

31-
function generatePackageJson(packageName: string, version: string, versionConfig: VersionConfig, template: Record<string, any>): any {
44+
function generatePackageJson(packageName: string, pgVersion: string, versionInfo: VersionInfo, template: Record<string, any>): any {
3245
// Start with the template and override only the version-specific fields
3346
const packageJson: any = {
3447
...template,
3548
name: packageName,
36-
version: versionConfig.deparserVersion,
49+
version: versionInfo['pgsql-deparser'],
3750
dependencies: {
38-
[`@pgsql/types`]: `^${versionConfig.typesVersion}`
51+
[`@pgsql/types`]: `^${versionInfo['@pgsql/types']}`
3952
}
4053
};
4154

42-
packageJson.scripts['publish:pkg'] = `npm publish --tag ${versionConfig.npmTag}`;
55+
packageJson.scripts['publish:pkg'] = `npm publish --tag ${versionInfo.npmTag}`;
4356

4457
return packageJson;
4558
}
@@ -80,20 +93,26 @@ function generateTsConfigEsm(): any {
8093
function generateVersionPackages(): void {
8194
console.log('Generating package.json files for each version...\n');
8295

83-
const config = loadConfig();
96+
const { rootConfig, localConfig } = loadConfigs();
8497

85-
for (const [version, versionConfig] of Object.entries(config.versions)) {
86-
console.log(`Processing version ${version}...`);
98+
for (const [pgVersion, versionInfo] of Object.entries(rootConfig.versions)) {
99+
// Skip versions that don't have pgsql-deparser
100+
if (!versionInfo['pgsql-deparser']) {
101+
console.log(`Skipping PG${pgVersion} - no pgsql-deparser version available`);
102+
continue;
103+
}
104+
105+
console.log(`Processing version ${pgVersion}...`);
87106

88-
const versionDir = path.join(VERSIONS_DIR, version);
107+
const versionDir = path.join(VERSIONS_DIR, pgVersion);
89108

90109
if (!fs.existsSync(versionDir)) {
91110
console.error(` ✗ Version directory ${versionDir} does not exist!`);
92111
continue;
93112
}
94113

95114
// Generate package.json
96-
const packageJson = generatePackageJson(config.packageName, version, versionConfig, config.packageTemplate);
115+
const packageJson = generatePackageJson(localConfig.packageName, pgVersion, versionInfo, localConfig.packageTemplate);
97116
const packageJsonPath = path.join(versionDir, 'package.json');
98117
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2));
99118
console.log(` ✓ Created package.json`);

packages/parser/config/package.template.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "pgsql-parser",
3-
"version": "{{VERSION}}",
3+
"version": "{{PGSQL_PARSER_VERSION}}",
44
"author": "Dan Lynch <[email protected]>",
55
"description": "The real PostgreSQL query parser",
66
"main": "index.js",
@@ -22,12 +22,7 @@
2222
"scripts": {
2323
"copy": "copyfiles -f ../../../../LICENSE README.md package.json dist",
2424
"clean": "rimraf dist",
25-
"prepare": "npm run build",
2625
"build": "npm run clean && tsc && tsc -p tsconfig.esm.json && npm run copy",
27-
"build:dev": "npm run clean && tsc --declarationMap && tsc -p tsconfig.esm.json && npm run copy",
28-
"lint": "eslint . --fix",
29-
"test": "jest",
30-
"test:watch": "jest --watch",
3126
"publish:pkg": "npm publish --tag {{VERSION_TAG}}"
3227
},
3328
"keywords": [
@@ -42,6 +37,6 @@
4237
"dependencies": {
4338
"@pgsql/types": "{{TYPES_VERSION}}",
4439
"libpg-query": "{{LIBPG_QUERY_VERSION}}",
45-
"pgsql-deparser": "{{PGSQL_PARSER_VERSION}}"
40+
"pgsql-deparser": "{{PGSQL_DEPARSER_VERSION}}"
4641
}
4742
}

packages/parser/scripts/prepare-versions.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import * as fs from 'fs';
22
import * as path from 'path';
33

4-
// Read the versions configuration
5-
const configPath = path.join(__dirname, '../config/parser-versions.json');
6-
const config = JSON.parse(fs.readFileSync(configPath, 'utf-8'));
4+
// Read the versions configuration from root
5+
const rootConfigPath = path.join(__dirname, '../../../config/versions.json');
6+
const rootConfig = JSON.parse(fs.readFileSync(rootConfigPath, 'utf-8'));
77

88
// Read the package.json template
99
const templatePath = path.join(__dirname, '../config/package.template.json');
@@ -16,20 +16,22 @@ if (!fs.existsSync(versionsDir)) {
1616
}
1717

1818
// Generate version-specific packages
19-
const pgVersions = Object.keys(config['libpg-query']);
19+
const pgVersions = Object.keys(rootConfig.versions);
2020

2121
pgVersions.forEach(pgVersion => {
22-
const libpgQueryVersion = config['libpg-query'][pgVersion];
23-
const typesVersion = config['@pgsql/types'][pgVersion];
24-
const npmTag = config['npmTag'][pgVersion];
25-
26-
// For pgsql-parser, we only have versions 13 and 17
27-
let pgsqlParserVersion = config['pgsql-parser'][pgVersion];
28-
if (!pgsqlParserVersion) {
29-
// If specific version doesn't exist, skip this PG version
30-
console.log(`Skipping PG${pgVersion} - no pgsql-parser version available`);
22+
const versionInfo = rootConfig.versions[pgVersion];
23+
24+
// Skip if no libpg-query or pgsql-parser version available
25+
if (!versionInfo['libpg-query'] || !versionInfo['pgsql-parser']) {
26+
console.log(`Skipping PG${pgVersion} - missing libpg-query or pgsql-parser version`);
3127
return;
3228
}
29+
30+
const libpgQueryVersion = versionInfo['libpg-query'];
31+
const pgsqlParserVersion = versionInfo['pgsql-parser'];
32+
const pgsqlDeparserVersion = versionInfo['pgsql-deparser'];
33+
const typesVersion = versionInfo['@pgsql/types'];
34+
const npmTag = versionInfo['npmTag'];
3335

3436
// Create version directory
3537
const versionDir = path.join(versionsDir, `${pgVersion}`);
@@ -45,11 +47,11 @@ pgVersions.forEach(pgVersion => {
4547

4648
// Generate package.json
4749
const packageJson = packageTemplate
48-
.replace(/{{VERSION}}/g, `${pgVersion}.0.0`)
4950
.replace(/{{LIBPG_QUERY_VERSION}}/g, libpgQueryVersion)
50-
.replace(/{{PGSQL_PARSER_VERSION}}/g, pgsqlParserVersion)
5151
.replace(/{{VERSION_TAG}}/g, `${npmTag}`)
52-
.replace(/{{TYPES_VERSION}}/g, typesVersion);
52+
.replace(/{{TYPES_VERSION}}/g, typesVersion)
53+
.replace(/{{PGSQL_DEPARSER_VERSION}}/g, pgsqlDeparserVersion)
54+
.replace(/{{PGSQL_PARSER_VERSION}}/g, pgsqlParserVersion);
5355

5456
fs.writeFileSync(
5557
path.join(versionDir, 'package.json'),

0 commit comments

Comments
 (0)