Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add tsx support #1021

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
35 changes: 4 additions & 31 deletions bin/node-pg-migrate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env node

import { readFileSync } from 'node:fs';

Check failure on line 3 in bin/node-pg-migrate.ts

View workflow job for this annotation

GitHub Actions / Lint: node-20, ubuntu-latest

'readFileSync' is defined but never used

Check failure on line 3 in bin/node-pg-migrate.ts

View workflow job for this annotation

GitHub Actions / Lint: node-20, ubuntu-latest

Delete `adFileSync·}·from·'node:fs';⏎import·{·re`
import { resolve } from 'node:path';
import { format } from 'node:util';
import ConnectionParameters from 'pg/lib/connection-parameters';
Expand Down Expand Up @@ -251,36 +251,6 @@
let DECAMELIZE = argv[decamelizeArg];
let tsconfigPath = argv[tsconfigArg];

function readTsconfig() {
if (tsconfigPath) {
let tsconfig;
const json5 = tryRequire('json5');

try {
const config = readFileSync(resolve(process.cwd(), tsconfigPath), {
encoding: 'utf-8',
});
tsconfig = json5 ? json5.parse(config) : JSON.parse(config);
} catch (err) {
console.error("Can't load tsconfig.json:", err);
}

const tsnode = tryRequire('ts-node');
if (!tsnode) {
console.error("For TypeScript support, please install 'ts-node' module");
}

if (tsconfig && tsnode) {
tsnode.register(tsconfig);
if (!MIGRATIONS_FILE_LANGUAGE) {
MIGRATIONS_FILE_LANGUAGE = 'ts';
}
} else {
process.exit(1);
}
}
}

function readJson(json) {
if (typeof json === 'object') {
SCHEMA = typeof SCHEMA !== 'undefined' ? SCHEMA : json[schemaArg];
Expand Down Expand Up @@ -369,7 +339,10 @@
readJson(jsonConfig);
}

readTsconfig();
if (tsconfigPath) {
process.env.TSX_TSCONFIG_PATH = tsconfigPath;
}
require('tsx/cjs');

Check failure on line 345 in bin/node-pg-migrate.ts

View workflow job for this annotation

GitHub Actions / Lint: node-20, ubuntu-latest

Expected blank line before this statement

const action = argv._.shift();

Expand Down