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!: switch to type module #1252

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ module.exports = defineConfig({
'plugin:prettier/recommended',
],
parserOptions: {
project: ['./tsconfig.lint.json'],
project: ['./tsconfig.json'],
warnOnUnsupportedTypeScriptVersion: false,
},
rules: {
Expand Down Expand Up @@ -141,7 +141,7 @@ module.exports = defineConfig({
},
overrides: [
{
files: ['test/migrations/*.js'],
files: ['test/migrations/*.js', 'test/migrations/*.cjs'],
rules: {
'unicorn/prefer-module': 'off',

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/postgres-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ jobs:
run: pnpm run build

- name: Integration Test
run: pnpm ts-node test/ts/customRunnerDBUrl.ts
run: pnpm tsx test/ts/customRunnerDBUrl.ts
env:
DATABASE_URL: postgres://ubuntu:ubuntu@localhost:5432/integration_test

Expand Down Expand Up @@ -773,7 +773,7 @@ jobs:
run: pnpm run build

- name: Integration Test
run: pnpm ts-node test/ts/customRunnerDBClient.ts
run: pnpm tsx test/ts/customRunnerDBClient.ts
env:
DATABASE_URL: postgres://ubuntu:ubuntu@localhost:5432/integration_test

Expand Down Expand Up @@ -824,6 +824,6 @@ jobs:
run: pnpm run build

- name: Integration Test
run: pnpm ts-node test/ts/customRunnerUndefCount.ts
run: pnpm tsx test/ts/customRunnerUndefCount.ts
env:
DATABASE_URL: postgres://ubuntu:ubuntu@localhost:5432/integration_test
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,8 @@ versions.json
/lib

/migrations
/bin/*.cjs
/bin/*.js
/bin/*.mjs
/bin/esm

TAGS
REVISION
Expand Down
2 changes: 1 addition & 1 deletion .prettierrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @type {import('prettier').Config}
*/
module.exports = {
export default {
plugins: ['prettier-plugin-organize-imports'],
singleQuote: true,
trailingComma: 'es5',
Expand Down
7 changes: 0 additions & 7 deletions bin/node-pg-migrate

This file was deleted.

32 changes: 10 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,22 @@
},
"bin": {
"node-pg-migrate": "bin/node-pg-migrate.js",
"node-pg-migrate-cjs": "bin/node-pg-migrate.js",
"node-pg-migrate-esm": "bin/node-pg-migrate.mjs"
"node-pg-migrate-cjs": "bin/node-pg-migrate.cjs",
"node-pg-migrate-esm": "bin/node-pg-migrate.js"
},
"type": "commonjs",
"main": "dist/index.js",
"module": "dist/esm/index.mjs",
"type": "module",
"main": "dist/index.cjs",
"module": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
"./dist/*": {
"types": "./dist/*.d.ts",
"require": "./dist/*.js",
"import": "./dist/esm/*.mjs",
"default": "./dist/*.js"
},
"./bin/*": {
"require": "./bin/*.js",
"import": "./bin/*.mjs",
"default": "./bin/*.js"
},
".": {
"types": "./dist/index.d.ts",
"require": "./dist/index.js",
"import": "./dist/esm/index.mjs",
"default": "./dist/index.js"
"import": "./dist/index.js",
"require": "./dist/index.cjs"
},
"./*": {
"types": "./dist/*.d.ts",
"require": "./dist/*.js"
"./bin/*": {
"import": "./bin/*.js",
"require": "./bin/*.cjs"
},
"./package.json": "./package.json"
},
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion templates/migration-template.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ColumnDefinitions, MigrationBuilder } from 'node-pg-migrate';
import type { ColumnDefinitions, MigrationBuilder } from 'node-pg-migrate';

Check failure on line 1 in templates/migration-template.ts

View workflow job for this annotation

GitHub Actions / TS-Check: node-20, ubuntu-latest

Cannot find module 'node-pg-migrate' or its corresponding type declarations.

export const shorthands: ColumnDefinitions | undefined = undefined;

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const constraint = require('./014_add_constraint');
const constraint = require('./014_add_constraint.cjs');

exports.up = (pgm) => {
pgm.dropConstraint('t1', constraint.constraint);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions test/migration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type { DBConnection } from '../src/db';
import { getTimestamp, Migration } from '../src/migration';
import type { Logger, RunnerOption } from '../src/types';

const callbackMigration = '1414549381268_names.js';
const promiseMigration = '1414549381268_names_promise.js';
const callbackMigration = '1414549381268_names.cjs';
const promiseMigration = '1414549381268_names_promise.cjs';
const migrationsTable = 'pgmigrations';

const actionsCallback = require(`./${callbackMigration}`);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const table = require('./004_table');
const table = require('./004_table.cjs');

const schema = process.env.SCHEMA || 'public';

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const constraint = require('./014_add_constraint');
const constraint = require('./014_add_constraint.cjs');

exports.constraint = 'chck_nmbr_new';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const constraint = require('./016_rename_constraint');
const constraint = require('./016_rename_constraint.cjs');

exports.up = (pgm) => {
pgm.dropConstraint('t1', constraint.constraint);
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const create = require('./035_role_add');
const rename = require('./037_role_rename');
const create = require('./035_role_add.cjs');
const rename = require('./037_role_rename.cjs');

exports.up = (pgm) => {
pgm.dropRole('rx');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { params } = require('./039_function_create');
const { params } = require('./039_function_create.cjs');

exports.up = (pgm) => {
pgm.renameFunction('f', params, 'add');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const create = require('./039_function_create');
const rename = require('./040_function_rename');
const create = require('./039_function_create.cjs');
const rename = require('./040_function_rename.cjs');

exports.up = (pgm) => {
pgm.dropFunction('add', create.params);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const trigger = require('./043_trigger_create_rename');
const trigger = require('./043_trigger_create_rename.cjs');

exports.up = (pgm) => {
pgm.dropTrigger('tt', 'trig');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const domain = require('./046_domain_create_rename');
const domain = require('./046_domain_create_rename.cjs');

exports.up = (pgm) => {
pgm.dropTable('td');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const sequence = require('./049_sequence_create_rename');
const sequence = require('./049_sequence_create_rename.cjs');

exports.up = (pgm) => {
pgm.dropTable('ts');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const operator = require('./054_operator_create');
const operator = require('./054_operator_create.cjs');

exports.up = (pgm) => {
pgm.dropOperator('+', { left: 'complex', right: 'complex' });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const policy = require('./057_policy_create');
const policy = require('./057_policy_create.cjs');

exports.up = policy.down;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {
comment,
table: { schema, name },
} = require('./060_column_comment');
} = require('./060_column_comment.cjs');

exports.up = async (pgm) => {
const [{ description }] = await pgm.db.select(
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {
table: { schema, name },
comment,
} = require('./072_alter_column_comment');
} = require('./072_alter_column_comment.cjs');

exports.up = async (pgm) => {
const [{ description }] = await pgm.db.select(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {
constants: { schema, table, role1, role2, tablePrivileges, schemaPrivilege },
} = require('./085_grant_tables_schemas_roles');
} = require('./085_grant_tables_schemas_roles.cjs');

const hasTablePrivileges = async (pgm, role, tableName, privileges) => {
const rows = await pgm.db.select(`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {
constants: { schema, table, role1, role2, tablePrivileges, schemaPrivilege },
} = require('./085_grant_tables_schemas_roles');
} = require('./085_grant_tables_schemas_roles.cjs');

exports.up = (pgm) => {
pgm.revokeRoles(role1, role2);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const {
constants: { schema, table, role1, role2, tablePrivileges, schemaPrivilege },
} = require('./085_grant_tables_schemas_roles');
} = require('./085_grant_tables_schemas_roles.cjs');

const {
utils: { hasTablePrivileges, hasSchemaPrivilege, isMemberOf },
} = require('./086_grant_test');
} = require('./086_grant_test.cjs');

exports.up = async (pgm) => {
const hasGrantedTablePrivileges = await hasTablePrivileges(
Expand Down
5 changes: 4 additions & 1 deletion test/ts/customRunner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { resolve } from 'node:path';
import { dirname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import type { Client } from 'pg';
import type { RunnerOption } from '../../dist';
import { runner } from '../../dist';
Expand All @@ -13,6 +14,8 @@ type Options =
| ({ databaseUrl: string } & TestOptions)
| ({ dbClient: Client } & TestOptions);

const __dirname = dirname(fileURLToPath(import.meta.url));

export const run = async (options: Options): Promise<boolean> => {
const opts: Omit<RunnerOption, 'direction'> & Options = {
migrationsTable: 'migrations',
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "ES2022",
"noEmit": false,
"declaration": true,
"emitDeclarationOnly": true,
"rootDir": "src",
"outDir": "dist"
Expand Down
19 changes: 13 additions & 6 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
{
"compilerOptions": {
"target": "ES2022",
"module": "CommonJS",
"target": "ESNext",
"moduleResolution": "Node",
"module": "ESNext",
"lib": ["ES2022", "DOM"],
"strict": true,
"noEmit": true,
"resolveJsonModule": true,
"declaration": true,
"stripInternal": true,
"verbatimModuleSyntax": true,

"esModuleInterop": true,
"sourceMap": false,
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitAny": true,
"noUnusedLocals": true,
"noImplicitOverride": true,
"skipLibCheck": true

// These are configs specifically for !build and have to be reverted in the tsconfig.build.json
"skipLibCheck": true,
"allowSyntheticDefaultImports": true,
"resolveJsonModule": true
},
"exclude": ["node_modules", "templates", "dist", "migrations"]
"exclude": ["node_modules", "dist"]
}
16 changes: 0 additions & 16 deletions tsconfig.lint.json

This file was deleted.

2 changes: 1 addition & 1 deletion tsup-bin.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default defineConfig({
format: ['esm', 'cjs'],
target: ['es2022', 'node18'],
dts: false,
minify: false,
minify: true,
sourcemap: false,
bundle: false,
});
Loading
Loading