diff --git a/AGENTS.md b/AGENTS.md index 87b95763..33ef6a1f 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -16,7 +16,7 @@ A pnpm monorepo for PostgreSQL AST parsing, deparsing, and code generation. All | `@pgsql/types` | (published from proto-parser codegen) | Core TypeScript type definitions for PostgreSQL AST nodes | | `@pgsql/utils` | `packages/utils` | Type-safe AST node creation utilities | | `@pgsql/traverse` | `packages/traverse` | Visitor-pattern traversal of SQL and PL/pgSQL ASTs: `walk`, `walkSqlAst`, `walkPlpgsqlAst`, `traverse` | -| `@pgsql/transform-ast` | `packages/transform-ast` | Multi-version AST transformer (PG 13-17) | +| `@pgsql/transform-ast` | `packages/transform-ast` | Multi-version AST transformer (PG 13-18) | | `@pgsql/transform` | `packages/transform` | SQL schema transformation, statement classification (AST facts), qualification, round-trip validation | | `@pgsql/quotes` | `packages/quotes` | SQL identifier/string quoting and keyword classification | | `@pgsql/cli` | `packages/pgsql-cli` | CLI tool for parse/deparse operations | @@ -105,7 +105,7 @@ Every package supports these scripts: | `parser` | `npm run prepare-versions` | Generate version-specific sub-packages from `config/versions.json` | | (root) | `npm run bump-versions` | Interactive CLI to bump `pgsql-parser` / `pgsql-deparser` versions per PG version | -Version configuration lives in `config/versions.json` — maps PG versions (13-17) to their `libpg-query`, `pgsql-parser`, `pgsql-deparser`, and `@pgsql/types` versions plus npm dist-tags. +Version configuration lives in `config/versions.json` — maps PG versions (13-18) to their `libpg-query`, `pgsql-parser`, `pgsql-deparser`, and `@pgsql/types` versions plus npm dist-tags. `prepare-versions` writes into `packages/{parser,deparser}/versions/`, which is gitignored and **not** part of the root pnpm workspace — each generated tree gets its own `pnpm-workspace.yaml`, diff --git a/PUBLISH.md b/PUBLISH.md index bae40e04..c54b982d 100644 --- a/PUBLISH.md +++ b/PUBLISH.md @@ -1,187 +1,133 @@ # Publishing Guide -This guide covers the multi-version publishing workflow for the pgsql-parser monorepo, which supports PostgreSQL versions 13-17 with version-specific npm tags. +`main` tracks PostgreSQL 18. The PostgreSQL 18 packages are the workspace packages themselves and are +published from the root with `pnpm lerna publish` (dist-tag `latest`). -## Prerequisites +`pgsql-parser` and `pgsql-deparser` are also published for PostgreSQL 13–17, each under its own npm +dist-tag (`pg13` … `pg17`). Those packages are generated from `main` on demand; nothing about them is +committed apart from the version numbers in `config/versions.json`. -Before publishing any packages, you must build the entire monorepo: +Publishing a generated package must always pass `--tag pgNN`. Without it npm moves `latest`, which +has to stay on 18. -```bash -pnpm install && pnpm build -``` - -This installs all dependencies and builds all packages in the correct order using Lerna. - -## Multi-Version Publishing Overview - -The pgsql-parser project uses a sophisticated multi-version publishing system to support different PostgreSQL versions. Each PostgreSQL version has its own: - -- **Version numbers** for each package (parser, deparser, types) -- **npm tag** for publishing (pg13, pg14, pg15, pg16, pg17) -- **libpg-query dependency** version - -All version mappings are centrally managed in `config/versions.json`: - -```json -{ - "versions": { - "13": { - "libpg-query": "13.5.7", - "pgsql-parser": "13.18.0", - "pgsql-deparser": "13.17.0", - "@pgsql/types": "13.11.1", - "npmTag": "pg13" - }, - "17": { - "libpg-query": "17.5.5", - "pgsql-parser": "17.7.5", - "pgsql-deparser": "17.8.3", - "@pgsql/types": "17.6.1", - "npmTag": "pg17" - } - } -} -``` +## How a generated package is built -### 0. Bump the config versions +### `pgsql-deparser` for major N (13–17) -In the root: +There is one deparser: the PostgreSQL 18 one in `packages/deparser/src`. The package for major N is +that deparser plus the AST transformers from `packages/transform-ast` that upgrade an N tree to an +18 tree: ``` -pnpm bump-versions +PG N AST ── PGNToPG18Transformer ──▶ PG 18 AST ── Deparser (18) ──▶ SQL ``` -## Package Publishing Workflows +`npm run prepare-versions` in `packages/deparser` runs these scripts in order: -### 1. Deparser Package (`pgsql-deparser`) +| Script | What it does | +|--------|--------------| +| `strip-transformer-types` | Copies `transform-ast/src/transformers/vN-to-vN+1.ts` (13→14 … 17→18) into `versions/`, replacing the `@pgsql/types` version imports with `any` | +| `strip-direct-transformer-types` | Same for `transform-ast/src/transformers-direct/vN-to-v18/index.ts`, written to `versions/direct/vN-to-v18.ts` | +| `strip-deparser-types` | Copies `packages/deparser/src` into `versions/N/src/deparser/` with the `@pgsql/types` imports replaced by `any` | +| `organize-transformers` | Moves each major's chain (`vN-to-vN+1.ts` … `v17-to-v18.ts`) and its `vN-to-v18-direct.ts` into `versions/N/src/` | +| `generate-version-deparsers` | Writes `versions/N/src/index.ts`: a `Deparser` that runs `PGNToPG18Transformer` and hands the result to the 18 deparser | +| `generate-packages` | Writes `versions/N/package.json` (version and `@pgsql/types` range from `config/versions.json`, `@pgsql/quotes` at the workspace version), tsconfigs, README, and `versions/pnpm-workspace.yaml` | -The deparser package uses a template-based approach for multi-version publishing. +Every step exits non-zero if a source file is missing. -#### Prepare Versions -```bash -cd packages/deparser -npm run prepare-versions -``` +### `pgsql-parser` for major N (13–17) -This runs a complete preparation pipeline: -1. `strip-transformer-types` - Clean up transformer types -2. `strip-direct-transformer-types` - Clean up direct transformer types -3. `strip-deparser-types` - Clean up deparser types -4. `organize-transformers` - Organize transformers by version -5. `generate-version-deparsers` - Generate version-specific deparsers -6. `generate-packages` - Generate package.json files for each version - -The `generate-packages` script (`scripts/generate-version-packages.ts`): -- Uses the template from `config/deparser-versions.json` -- Creates version-specific packages in `packages/deparser/versions/` -- Sets up proper dependencies and npm tags for each PostgreSQL version -- Writes a `pnpm-workspace.yaml` into `versions/`, making the generated tree its - own workspace (it is gitignored, so it is deliberately not part of the root one) - -#### Install Dependencies -```bash -# Once per generation — covers every version directory -cd packages/deparser/versions -pnpm install -``` +`npm run prepare-versions` in `packages/parser` (`scripts/prepare-versions.ts`) writes +`versions/N/` for every major in `config/versions.json` except the workspace's own (18). Each +package is a thin re-export of three pinned dependencies taken from `config/versions.json`: -#### Build and Publish Individual Versions -```bash -# Navigate to a specific version directory -cd packages/deparser/versions/13 +- `libpg-query` — the parser for that major +- `pgsql-deparser` — the generated deparser for that major (exact version) +- `@pgsql/types` — the types for that major -# Build the package -npm run build +Because of the exact `pgsql-deparser` pin, **the deparser for a major must be on npm before the +parser for that major can be installed, built or published.** -# dist -cd dist/ - -# Publish with the correct tag -npm publish --tag pg13 -``` +### `versions/` directories -**I do 13,14,15,16... since 17 was already publish from the root `pnpm lerna publish` - -Now go to run, fetch fresh versions for config again: - -``` -pnpm bump-versions -``` +`packages/deparser/versions` and `packages/parser/versions` are gitignored and are their own pnpm +workspaces (each gets a `pnpm-workspace.yaml`). They are not part of the root workspace, so run +`pnpm install` inside `versions/` after every `prepare-versions`. +## `config/versions.json` -#### Publish All Deparser Versions -```bash -cd packages/deparser +One entry per major: -# Prepare all versions -npm run prepare-versions -(cd versions && pnpm install) - -# Build and publish each version -for version in versions/*/; do - cd "$version" - npm run build - cd dist/ - npm run publish:pkg # Uses the npmTag from config - cd .. -done -``` - -### 2. Parser Package (`pgsql-parser`) - -The parser package uses a version preparation script to generate multiple version-specific packages. - -#### Prepare Versions -```bash -cd packages/parser -npm run prepare-versions -``` - -This script (`scripts/prepare-versions.ts`): -- Reads version configuration from `config/versions.json` -- Creates version-specific directories in `packages/parser/versions/` -- Generates `package.json`, `tsconfig.json`, and source files for each PostgreSQL version -- Each version gets its own libpg-query dependency and npm tag -- Writes a `pnpm-workspace.yaml` into `versions/`, making the generated tree its - own workspace (it is gitignored, so it is deliberately not part of the root one) - -#### Install Dependencies -```bash -# Once per generation — covers every version directory -cd packages/parser/versions -pnpm install -``` - -#### Build and Publish Individual Versions -```bash -# Navigate to a specific version directory -cd packages/parser/versions/13 - -# Build the package -npm run build - -# cd to dist/ - -cd dist/ - -# Publish with the correct tag -npm publish --tag pg13 -``` - -#### Publish All Parser Versions -```bash -cd packages/parser - -# Prepare all versions -npm run prepare-versions -(cd versions && pnpm install) - -# Build and publish each version -for version in versions/*/; do - cd "$version" - npm run build - npm run publish:pkg # Uses the npmTag from config - cd .. -done +```json +"17": { + "libpg-query": "17.8.3", + "pgsql-parser": "17.10.0", + "pgsql-deparser": "17.19.0", + "@pgsql/types": "17.6.2", + "npmTag": "pg17" +} ``` +- `pgsql-parser` / `pgsql-deparser`: the version the next publish of that major will produce. +- `libpg-query` / `@pgsql/types`: what the generated packages pin. Both are published from other + repositories. +- The `18` entry is not used for generation; 18 is versioned by lerna. + +`pnpm bump-versions` (`scripts/bump-versions.ts`) edits this file interactively. For each major it +reads the major's dist-tag on npm for all four packages, then: + +- sets `libpg-query` and `@pgsql/types` to whatever the `pgNN` dist-tag points at (no prompt); +- prompts for `pgsql-parser` and `pgsql-deparser`: `latest` (when npm is ahead of the file), + `patch`, `minor`, `custom`, or `skip`; +- prints a summary and asks whether to save. + +Choose `skip` for every major you are not publishing, and commit the result. + +## Publishing one major + +Example for 17; replace `17` / `pg17` for another major. + +1. Build the workspace and set the versions: + + ```bash + pnpm install + pnpm build + pnpm bump-versions + ``` + +2. Generate, build and publish the deparser: + + ```bash + cd packages/deparser + npm run prepare-versions + cd versions + pnpm install + cd 17 + npm run build + cd dist + npm publish --tag pg17 + ``` + +3. Generate, build and publish the parser (needs step 2 to be on npm): + + ```bash + cd packages/parser + npm run prepare-versions + cd versions + pnpm install + cd 17 + npm run build + cd dist + npm publish --tag pg17 + ``` + +4. Check that only the `pgNN` tag moved: + + ```bash + npm view pgsql-deparser dist-tags + npm view pgsql-parser dist-tags + ``` + +`pnpm install` in `packages/parser/versions` resolves every generated major, so each +`pgsql-deparser` version listed in `config/versions.json` for 13–17 has to exist on npm at that +point. diff --git a/config/versions.json b/config/versions.json index 2498ead8..071f4547 100644 --- a/config/versions.json +++ b/config/versions.json @@ -22,21 +22,21 @@ "npmTag": "pg15" }, "16": { - "libpg-query": "16.6.0", - "pgsql-parser": "16.1.1", - "pgsql-deparser": "16.1.1", - "@pgsql/types": "16.1.1", + "libpg-query": "16.8.3", + "pgsql-parser": "16.2.0", + "pgsql-deparser": "16.2.0", + "@pgsql/types": "16.1.2", "npmTag": "pg16" }, "17": { - "libpg-query": "17.6.0", - "pgsql-parser": "17.8.3", - "pgsql-deparser": "17.11.2", - "@pgsql/types": "17.6.1", + "libpg-query": "17.8.3", + "pgsql-parser": "17.10.0", + "pgsql-deparser": "17.19.0", + "@pgsql/types": "17.6.2", "npmTag": "pg17" }, "18": { - "libpg-query": "18.1.5", + "libpg-query": "18.2.4", "pgsql-parser": "18.0.0", "pgsql-deparser": "18.0.0", "@pgsql/types": "18.0.0", diff --git a/packages/deparser/scripts/generate-version-deparsers.ts b/packages/deparser/scripts/generate-version-deparsers.ts index 60c5ceca..ec9b6101 100644 --- a/packages/deparser/scripts/generate-version-deparsers.ts +++ b/packages/deparser/scripts/generate-version-deparsers.ts @@ -14,28 +14,12 @@ interface VersionConfig { const VERSIONS_DIR = 'versions'; -const versionConfigs: VersionConfig[] = [ - { - version: 13, - directTransformerClass: 'PG13ToPG17Transformer', - directTransformerFile: './v13-to-v17-direct' - }, - { - version: 14, - directTransformerClass: 'PG14ToPG17Transformer', - directTransformerFile: './v14-to-v17-direct' - }, - { - version: 15, - directTransformerClass: 'PG15ToPG17Transformer', - directTransformerFile: './v15-to-v17-direct' - }, - { - version: 16, - directTransformerClass: 'PG16ToPG17Transformer', - directTransformerFile: './v16-to-v17-direct' - } -]; +// The main deparser speaks the PG18 AST, so every older major is upgraded to 18 first. +const versionConfigs: VersionConfig[] = [13, 14, 15, 16, 17].map(version => ({ + version, + directTransformerClass: `PG${version}ToPG18Transformer`, + directTransformerFile: `./v${version}-to-v18-direct` +})); function generateDeparserIndex(config: VersionConfig): string { return `/** @@ -44,27 +28,37 @@ function generateDeparserIndex(config: VersionConfig): string { */ import { Node, ParseResult } from '@pgsql/types'; -import { - deparse as deparse17, - deparseSync as deparseSync17, - DeparserOptions -} from './deparser'; +import { Deparser as Deparser18, DeparserOptions } from './deparser'; import { ${config.directTransformerClass} } from '${config.directTransformerFile}'; const tx = new ${config.directTransformerClass}(); -export async function deparse(query: Node | Node[] | ParseResult, opts?: DeparserOptions): Promise { - const ast17 = tx.transform(query); - return await deparse17(ast17, opts); +type Query = Node | Node[] | ParseResult; + +const toAst18 = (query: Query): any => + Array.isArray(query) ? query.map(node => tx.transform(node)) : tx.transform(query); + +export class Deparser extends Deparser18 { + constructor(tree: Query, opts: DeparserOptions = {}) { + super(toAst18(tree), opts); + } + + static deparse(query: Query, opts: DeparserOptions = {}): string { + return new Deparser(query, opts).deparseQuery(); + } +} + +export async function deparse(query: Query, opts?: DeparserOptions): Promise { + return Deparser.deparse(query, opts); } -export function deparseSync(query: Node | Node[] | ParseResult, opts?: DeparserOptions): string { - const ast17 = tx.transform(query); - return deparseSync17(ast17, opts); +export function deparseSync(query: Query, opts?: DeparserOptions): string { + return Deparser.deparse(query, opts); } -// Re-export DeparserOptions for convenience -export { DeparserOptions } from './deparser'; +export { DeparserOptions }; +export { splitSqlLines } from './deparser/utils/sql-formatter'; +export { QuoteUtils } from '@pgsql/quotes'; `; } @@ -73,6 +67,7 @@ function updateVersionDirectory(config: VersionConfig): void { if (!fs.existsSync(versionDir)) { console.error(`Version directory ${versionDir} does not exist!`); + process.exitCode = 1; return; } @@ -82,13 +77,6 @@ function updateVersionDirectory(config: VersionConfig): void { fs.mkdirSync(srcDir, { recursive: true }); } - // Remove old index.js if it exists - const oldIndexPath = path.join(srcDir, 'index.js'); - if (fs.existsSync(oldIndexPath)) { - fs.unlinkSync(oldIndexPath); - console.log(` ✓ Removed old index.js`); - } - // Generate new index.ts in src directory const indexContent = generateDeparserIndex(config); const indexPath = path.join(srcDir, 'index.ts'); diff --git a/packages/deparser/scripts/generate-version-packages.ts b/packages/deparser/scripts/generate-version-packages.ts index f77699a0..06bd70a4 100644 --- a/packages/deparser/scripts/generate-version-packages.ts +++ b/packages/deparser/scripts/generate-version-packages.ts @@ -41,6 +41,11 @@ function loadConfigs(): { rootConfig: RootConfig; localConfig: LocalConfig } { return { rootConfig, localConfig }; } +// The stripped deparser sources import @pgsql/quotes; pin the workspace's version. +const quotesVersion: string = JSON.parse( + fs.readFileSync(path.join(__dirname, '../../quotes/package.json'), 'utf-8') +).version; + function generatePackageJson(packageName: string, pgVersion: string, versionInfo: VersionInfo, template: Record): any { // Start with the template and override only the version-specific fields const packageJson: any = { @@ -48,7 +53,8 @@ function generatePackageJson(packageName: string, pgVersion: string, versionInfo name: packageName, version: versionInfo['pgsql-deparser'], dependencies: { - [`@pgsql/types`]: `^${versionInfo['@pgsql/types']}` + '@pgsql/quotes': quotesVersion, + '@pgsql/types': `^${versionInfo['@pgsql/types']}` } }; @@ -68,6 +74,8 @@ function generateTsConfig(): any { forceConsistentCasingInFileNames: true, strict: true, strictNullChecks: false, + // the copied sources have their AST types stripped to `any` + noImplicitAny: false, skipLibCheck: true, sourceMap: false, declaration: true, @@ -115,8 +123,10 @@ function generateVersionPackages(): void { const versionDir = path.join(VERSIONS_DIR, pgVersion); + // Only majors with a generated lane get a package; the newest major is the + // root workspace package and is published from there. if (!fs.existsSync(versionDir)) { - console.error(` ✗ Version directory ${versionDir} does not exist!`); + console.log(` Skipping PG${pgVersion} - no generated lane in ${versionDir}\n`); continue; } diff --git a/packages/deparser/scripts/organize-transformers-by-version.ts b/packages/deparser/scripts/organize-transformers-by-version.ts index e667a655..a294241f 100644 --- a/packages/deparser/scripts/organize-transformers-by-version.ts +++ b/packages/deparser/scripts/organize-transformers-by-version.ts @@ -2,221 +2,48 @@ import * as fs from 'fs'; import * as path from 'path'; /** - * Script to organize transformers by source version - * Creates a directory structure where each version has all transformers starting from that version + * Copies the stripped transformers each older major needs into versions//src: + * the sequential steps from N up to the main deparser's major, plus the direct + * vN-to-v transformer that chains them. */ -interface TransformerMapping { - sourceVersion: number; - transformers: { - fileName: string; - className: string; - targetVersion: number; - }[]; -} - const VERSIONS_DIR = 'versions'; +const SOURCE_VERSIONS = [13, 14, 15, 16, 17]; +const TARGET_VERSION = 18; -// Define what transformers each version needs -const versionMappings: TransformerMapping[] = [ - { - sourceVersion: 13, - transformers: [ - { fileName: 'v13-to-v14.ts', className: 'V13ToV14Transformer', targetVersion: 14 }, - { fileName: 'direct/v13-to-v17.ts', className: 'PG13ToPG17Transformer', targetVersion: 17 } - ] - }, - { - sourceVersion: 14, - transformers: [ - { fileName: 'v14-to-v15.ts', className: 'V14ToV15Transformer', targetVersion: 15 }, - { fileName: 'direct/v14-to-v17.ts', className: 'PG14ToPG17Transformer', targetVersion: 17 } - ] - }, - { - sourceVersion: 15, - transformers: [ - { fileName: 'v15-to-v16.ts', className: 'V15ToV16Transformer', targetVersion: 16 }, - { fileName: 'direct/v15-to-v17.ts', className: 'PG15ToPG17Transformer', targetVersion: 17 } - ] - }, - { - sourceVersion: 16, - transformers: [ - { fileName: 'v16-to-v17.ts', className: 'V16ToV17Transformer', targetVersion: 17 }, - { fileName: 'direct/v16-to-v17.ts', className: 'PG16ToPG17Transformer', targetVersion: 17 } - ] - } -]; - -function copyTransformer(sourcePath: string, destPath: string): void { - const content = fs.readFileSync(sourcePath, 'utf-8'); - fs.writeFileSync(destPath, content); -} - -function createIndexFile(version: number, transformers: TransformerMapping['transformers']): string { - const imports = transformers.map(t => { - const importPath = `./${path.basename(t.fileName, '.ts')}`; - return `export { ${t.className} } from '${importPath}';`; - }).join('\n'); - - return `/** - * Transformers for PostgreSQL version ${version} - * Auto-generated by organize-transformers-by-version.ts - */ - -${imports} - -// Export a convenience function to get all transformers for this version -export function getTransformersForV${version}() { - return { -${transformers.map(t => ` to${t.targetVersion}: ${t.className}`).join(',\n')} - }; -} -`; -} - -function copyReadme(versionDir: string): void { - const sourcePath = path.join(__dirname, '..', 'README.md'); - const destPath = path.join(versionDir, 'README.md'); - - if (fs.existsSync(sourcePath)) { - fs.copyFileSync(sourcePath, destPath); +function copyRequired(sourcePath: string, destPath: string): void { + if (!fs.existsSync(sourcePath)) { + console.error(` ✗ Source file not found: ${sourcePath}`); + process.exitCode = 1; + return; } + fs.copyFileSync(sourcePath, destPath); + console.log(` ✓ Copied ${path.basename(destPath)}`); } function organizeByVersion(): void { console.log('Organizing transformers by version...\n'); - for (const mapping of versionMappings) { - const versionDir = path.join(VERSIONS_DIR, mapping.sourceVersion.toString()); - const srcDir = path.join(versionDir, 'src'); - - // Create version directory and src subdirectory - if (!fs.existsSync(srcDir)) { - fs.mkdirSync(srcDir, { recursive: true }); - } + for (const version of SOURCE_VERSIONS) { + console.log(`Processing version ${version}...`); - console.log(`Processing version ${mapping.sourceVersion}...`); + const srcDir = path.join(VERSIONS_DIR, version.toString(), 'src'); + fs.mkdirSync(srcDir, { recursive: true }); - // Copy transformers to src directory - for (const transformer of mapping.transformers) { - const sourcePath = path.join(VERSIONS_DIR, transformer.fileName); - let destFileName = path.basename(transformer.fileName); - - // Rename direct transformers to avoid conflicts - if (transformer.fileName.startsWith('direct/')) { - const match = destFileName.match(/v(\d+)-to-v(\d+)\.ts/); - if (match) { - destFileName = `v${match[1]}-to-v${match[2]}-direct.ts`; - } - } - - const destPath = path.join(srcDir, destFileName); - - if (fs.existsSync(sourcePath)) { - copyTransformer(sourcePath, destPath); - console.log(` ✓ Copied ${destFileName}`); - } else { - console.warn(` ⚠ Source file not found: ${sourcePath}`); - } + for (let from = version; from < TARGET_VERSION; from++) { + const step = `v${from}-to-v${from + 1}.ts`; + copyRequired(path.join(VERSIONS_DIR, step), path.join(srcDir, step)); } - // Create index file in src directory - const indexContent = createIndexFile(mapping.sourceVersion, mapping.transformers); - fs.writeFileSync(path.join(srcDir, 'index.js'), indexContent); - console.log(` ✓ Created index.js`); - - // Create README in version directory (not in src) - copyReadme(versionDir); - console.log(` ✓ Created README.md`); - - console.log(''); - } - - // Also copy the base transformers that other versions might need - console.log('Copying dependency transformers...'); - - // v14 needs v14-to-v15 for its direct transformer - const v14SrcDir = path.join(VERSIONS_DIR, '14', 'src'); - if (fs.existsSync(path.join(VERSIONS_DIR, 'v14-to-v15.ts'))) { - copyTransformer( - path.join(VERSIONS_DIR, 'v14-to-v15.ts'), - path.join(v14SrcDir, 'v14-to-v15.ts') - ); - console.log(' ✓ Copied v14-to-v15.ts to v14 directory (dependency)'); - } - - // v14 also needs v15-to-v16 and v16-to-v17 - if (fs.existsSync(path.join(VERSIONS_DIR, 'v15-to-v16.ts'))) { - copyTransformer( - path.join(VERSIONS_DIR, 'v15-to-v16.ts'), - path.join(v14SrcDir, 'v15-to-v16.ts') + copyRequired( + path.join(VERSIONS_DIR, 'direct', `v${version}-to-v${TARGET_VERSION}.ts`), + path.join(srcDir, `v${version}-to-v${TARGET_VERSION}-direct.ts`) ); - console.log(' ✓ Copied v15-to-v16.ts to v14 directory (dependency)'); - } - - if (fs.existsSync(path.join(VERSIONS_DIR, 'v16-to-v17.ts'))) { - copyTransformer( - path.join(VERSIONS_DIR, 'v16-to-v17.ts'), - path.join(v14SrcDir, 'v16-to-v17.ts') - ); - console.log(' ✓ Copied v16-to-v17.ts to v14 directory (dependency)'); - } - // v13 needs all transformers for its direct transformer - const v13SrcDir = path.join(VERSIONS_DIR, '13', 'src'); - const v13Dependencies = ['v13-to-v14.ts', 'v14-to-v15.ts', 'v15-to-v16.ts', 'v16-to-v17.ts']; - for (const dep of v13Dependencies) { - if (fs.existsSync(path.join(VERSIONS_DIR, dep))) { - copyTransformer( - path.join(VERSIONS_DIR, dep), - path.join(v13SrcDir, dep) - ); - console.log(` ✓ Copied ${dep} to v13 directory (dependency)`); - } - } - - // v15 needs v15-to-v16 and v16-to-v17 for its direct transformer - const v15SrcDir = path.join(VERSIONS_DIR, '15', 'src'); - const v15Dependencies = ['v15-to-v16.ts', 'v16-to-v17.ts']; - for (const dep of v15Dependencies) { - if (fs.existsSync(path.join(VERSIONS_DIR, dep))) { - copyTransformer( - path.join(VERSIONS_DIR, dep), - path.join(v15SrcDir, dep) - ); - console.log(` ✓ Copied ${dep} to v15 directory (dependency)`); - } + console.log(''); } - console.log('\nDone! Transformers are organized in version-specific directories.'); - - // Copy deparser files - console.log('\nCopying deparser files...'); - const { execSync } = require('child_process'); - try { - execSync('npx ts-node scripts/strip-deparser-types.ts', { stdio: 'inherit' }); - } catch (error) { - console.error('Failed to copy deparser files:', error); - } - - // Now generate the deparser index files - console.log('\nGenerating deparser index files...'); - try { - execSync('npx ts-node scripts/generate-version-deparsers.ts', { stdio: 'inherit' }); - } catch (error) { - console.error('Failed to generate deparser files:', error); - } - - // Generate package.json files - console.log('\nGenerating package.json files...'); - try { - execSync('npx ts-node scripts/generate-version-packages.ts', { stdio: 'inherit' }); - } catch (error) { - console.error('Failed to generate package files:', error); - } + console.log('Done! Transformers are organized in version-specific directories.'); } -// Run the script -organizeByVersion(); \ No newline at end of file +organizeByVersion(); diff --git a/packages/deparser/scripts/strip-deparser-types.ts b/packages/deparser/scripts/strip-deparser-types.ts index 37dd408f..0857bf63 100644 --- a/packages/deparser/scripts/strip-deparser-types.ts +++ b/packages/deparser/scripts/strip-deparser-types.ts @@ -9,7 +9,7 @@ import * as ts from 'typescript'; const DEPARSER_SRC_DIR = 'src'; const VERSIONS_DIR = 'versions'; -const VERSIONS = [13, 14, 15, 16]; +const VERSIONS = [13, 14, 15, 16, 17]; // Types to strip const TYPES_TO_STRIP = ['Node', '@pgsql/types']; @@ -229,6 +229,7 @@ function copyDeparserToVersions(): void { if (!fs.existsSync(deparserSrcPath)) { console.error(`Deparser source directory not found: ${deparserSrcPath}`); + process.exitCode = 1; return; } diff --git a/packages/deparser/scripts/strip-direct-transformer-types.ts b/packages/deparser/scripts/strip-direct-transformer-types.ts index e0268cf1..b6a81b9d 100644 --- a/packages/deparser/scripts/strip-direct-transformer-types.ts +++ b/packages/deparser/scripts/strip-direct-transformer-types.ts @@ -8,17 +8,18 @@ import * as ts from 'typescript'; */ const DIRECT_TRANSFORMER_FILES = [ - '../transform/src/transformers-direct/v13-to-v17/index.ts', - '../transform/src/transformers-direct/v14-to-v17/index.ts', - '../transform/src/transformers-direct/v15-to-v17/index.ts', - '../transform/src/transformers-direct/v16-to-v17/index.ts' + '../transform-ast/src/transformers-direct/v13-to-v18/index.ts', + '../transform-ast/src/transformers-direct/v14-to-v18/index.ts', + '../transform-ast/src/transformers-direct/v15-to-v18/index.ts', + '../transform-ast/src/transformers-direct/v16-to-v18/index.ts', + '../transform-ast/src/transformers-direct/v17-to-v18/index.ts' ]; const OUTPUT_DIR = 'versions/direct'; // Types to strip and replace with 'any' const TYPES_TO_STRIP = [ - 'PG13', 'PG14', 'PG15', 'PG16', 'PG17', + 'PG13', 'PG14', 'PG15', 'PG16', 'PG17', 'PG18', 'TransformerContext' ]; @@ -272,6 +273,7 @@ function main() { processFile(file); } catch (error) { console.error(`Error processing ${file}:`, error); + process.exitCode = 1; } } diff --git a/packages/deparser/scripts/strip-transformer-types.ts b/packages/deparser/scripts/strip-transformer-types.ts index 736d59fb..2cdf986e 100644 --- a/packages/deparser/scripts/strip-transformer-types.ts +++ b/packages/deparser/scripts/strip-transformer-types.ts @@ -8,17 +8,18 @@ import * as ts from 'typescript'; */ const TRANSFORMER_FILES = [ - '../transform/src/transformers/v13-to-v14.ts', - '../transform/src/transformers/v14-to-v15.ts', - '../transform/src/transformers/v15-to-v16.ts', - '../transform/src/transformers/v16-to-v17.ts' + '../transform-ast/src/transformers/v13-to-v14.ts', + '../transform-ast/src/transformers/v14-to-v15.ts', + '../transform-ast/src/transformers/v15-to-v16.ts', + '../transform-ast/src/transformers/v16-to-v17.ts', + '../transform-ast/src/transformers/v17-to-v18.ts' ]; const OUTPUT_DIR = 'versions'; // Types to strip and replace with 'any' const TYPES_TO_STRIP = [ - 'PG13', 'PG14', 'PG15', 'PG16', 'PG17', + 'PG13', 'PG14', 'PG15', 'PG16', 'PG17', 'PG18', 'TransformerContext' ]; @@ -251,6 +252,7 @@ function main() { processFile(file); } catch (error) { console.error(`Error processing ${file}:`, error); + process.exitCode = 1; } } diff --git a/packages/parser/scripts/prepare-versions.ts b/packages/parser/scripts/prepare-versions.ts index 9fc54970..af6f2f13 100644 --- a/packages/parser/scripts/prepare-versions.ts +++ b/packages/parser/scripts/prepare-versions.ts @@ -23,8 +23,12 @@ fs.writeFileSync( "packages:\n - '*'\n" ); +// The newest major is this workspace package itself, published from the root +// with lerna; only the older majors get a generated package. +const workspaceMajor = require('../package.json').version.split('.')[0]; + // Generate version-specific packages -const pgVersions = Object.keys(rootConfig.versions); +const pgVersions = Object.keys(rootConfig.versions).filter(v => v !== workspaceMajor); pgVersions.forEach(pgVersion => { const versionInfo = rootConfig.versions[pgVersion]; diff --git a/scripts/bump-versions.ts b/scripts/bump-versions.ts index 15f31752..13823a83 100644 --- a/scripts/bump-versions.ts +++ b/scripts/bump-versions.ts @@ -94,7 +94,7 @@ async function fetchTaggedVersions(tags: string[]): Promise { taggedVersions[tag] = {}; console.log(` Tag: ${tag}`); - for (const pkg of BUMPABLE_PACKAGES) { + for (const pkg of PACKAGES) { process.stdout.write(` ${pkg}... `); const version = await fetchLatestVersion(pkg, tag); if (version) { @@ -300,9 +300,9 @@ async function processVersionBumps( // Display current vs latest for (const pkg of PACKAGES) { const current = pkg === 'pgsql-deparser' ? currentVersions[pkg] : currentVersions[pkg as keyof typeof currentVersions]; - // For bumpable packages, prefer tag-specific version if available + // Prefer the version on this major's dist-tag let latest: string | null = null; - if (BUMPABLE_PACKAGES.includes(pkg as any) && taggedVersions[currentVersions.npmTag]) { + if (taggedVersions[currentVersions.npmTag]) { latest = taggedVersions[currentVersions.npmTag][pkg as keyof PackageVersions] || null; } // Fall back to global latest if no tag-specific version @@ -318,9 +318,9 @@ async function processVersionBumps( for (const pkg of PACKAGES) { const current = pkg === 'pgsql-deparser' ? currentVersions[pkg] : currentVersions[pkg as keyof typeof currentVersions]; - // For bumpable packages, prefer tag-specific version if available + // Prefer the version on this major's dist-tag let latest: string | null = null; - if (BUMPABLE_PACKAGES.includes(pkg as any) && taggedVersions[currentVersions.npmTag]) { + if (taggedVersions[currentVersions.npmTag]) { latest = taggedVersions[currentVersions.npmTag][pkg as keyof PackageVersions] || null; } // Fall back to global latest if no tag-specific version @@ -328,9 +328,15 @@ async function processVersionBumps( latest = latestVersions[pkg as keyof PackageVersions] || null; } - // Skip read-only packages + // Read-only packages are published elsewhere: pin whatever this major's dist-tag points at if (READ_ONLY_PACKAGES.includes(pkg as any)) { - console.log(`\n📦 ${pkg}: ${current || 'null'} [read-only - no changes allowed]`); + const tagged = taggedVersions[currentVersions.npmTag]?.[pkg as keyof PackageVersions]; + if (tagged && tagged !== current) { + (updatedVersions as any)[pkg] = tagged; + console.log(`\n📦 ${pkg}: ${current || 'null'} → ${tagged} [follows the ${currentVersions.npmTag} dist-tag]`); + } else { + console.log(`\n📦 ${pkg}: ${current || 'null'} [follows the ${currentVersions.npmTag} dist-tag - unchanged]`); + } continue; }