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

fix: Do not reference __dirname if it does not exist #1168

Closed
wants to merge 1 commit into from
Closed
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
8 changes: 6 additions & 2 deletions src/migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@

import { createReadStream, createWriteStream } from 'node:fs';
import { mkdir, readdir } from 'node:fs/promises';
import { basename, extname, resolve } from 'node:path';
import { basename, dirname, extname, resolve } from 'node:path';
import { fileURLToPath } from 'node:url';
import type { QueryResult } from 'pg';
import type { DBConnection } from './db';
import MigrationBuilder from './migrationBuilder';
Expand Down Expand Up @@ -47,6 +48,9 @@
} & (CreateOptionsTemplate | CreateOptionsDefault);

const SEPARATOR = '_';
const _dirname = typeof __dirname !== 'undefined'
? __dirname
: dirname(fileURLToPath(import.meta.url));

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

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

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

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

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Build & Unit Test: node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Build & Unit Test: node-18, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / coverage-pr

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Create Migration Test: node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Config 2 Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-12.18, node-18, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Config 1 Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-14.11, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-13.14, node-18, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-13.14, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / TypeScript Migration Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-12.18, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Schema Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Env Vars Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-14.11, node-18, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-16.2, node-18, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Cockroach Test: cockroach-23.2.4, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / TypeScript Customrunner Client Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Schemas Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-15.6, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / TypeScript Customrunner Url Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-15.6, node-18, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Dotenv Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Dotenv Expand Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Cockroach Test: cockroach-22.2.19, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / TypeScript Customrunner undef count Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Password 2 Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 53 in src/migration.ts

View workflow job for this annotation

GitHub Actions / Password 1 Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

export async function loadMigrationFiles(
dir: string,
Expand Down Expand Up @@ -138,7 +142,7 @@
'templateFileName' in options
? resolve(process.cwd(), options.templateFileName)
: resolve(
__dirname,
_dirname,
`../templates/migration-template.${await resolveSuffix(directory, options)}`
);
const suffix = getSuffixFromFileName(templateFileName);
Expand Down
8 changes: 6 additions & 2 deletions src/runner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { extname, relative } from 'node:path';
import { dirname, extname, relative } from 'node:path';
import { fileURLToPath } from 'node:url';
import type { DBConnection } from './db';
import Db from './db';
import type { RunMigration } from './migration';
Expand All @@ -23,6 +24,9 @@
const idColumn = 'id';
const nameColumn = 'name';
const runOnColumn = 'run_on';
const _dirname = typeof __dirname !== 'undefined'
? __dirname
: dirname(fileURLToPath(import.meta.url));

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

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

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

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

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Build & Unit Test: node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Build & Unit Test: node-18, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / coverage-pr

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Create Migration Test: node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Config 2 Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-12.18, node-18, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Config 1 Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-14.11, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-13.14, node-18, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-13.14, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / TypeScript Migration Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-12.18, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Schema Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Env Vars Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-14.11, node-18, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-16.2, node-18, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Cockroach Test: cockroach-23.2.4, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / TypeScript Customrunner Client Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Schemas Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-15.6, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / TypeScript Customrunner Url Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-15.6, node-18, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Dotenv Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Dotenv Expand Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Cockroach Test: cockroach-22.2.19, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Postgres Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / TypeScript Customrunner undef count Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Password 2 Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

Check failure on line 29 in src/runner.ts

View workflow job for this annotation

GitHub Actions / Password 1 Test: pg-16.2, node-20, ubuntu-latest

The 'import.meta' meta-property is only allowed when the '--module' option is 'es2020', 'es2022', 'esnext', 'system', 'node16', or 'nodenext'.

async function loadMigrations(
db: DBConnection,
Expand All @@ -39,7 +43,7 @@
const actions: MigrationBuilderActions =
extname(filePath) === '.sql'
? await migrateSqlFile(filePath)
: require(relative(__dirname, filePath));
: require(relative(_dirname, filePath));
shorthands = { ...shorthands, ...actions.shorthands };

return new Migration(
Expand Down
Loading