Skip to content
Merged
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: 3 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
FROM mcr.microsoft.com/devcontainers/javascript-node:20
FROM mcr.microsoft.com/devcontainers/javascript-node:22

ENV COREPACK_ENABLE_DOWNLOAD_PROMPT=0

RUN corepack enable
31 changes: 17 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,31 @@ jobs:
with:
node-version: 22
cache: "yarn"
- name: Install deps, build, then clear deps
- name: Install deps and build
run: |
yarn install --immutable
yarn build
rm -rf node_modules
- name: Test on Node 22

- name: test built package on node@22
working-directory: ./package-test/
run: |
# CI implies --immutable
yarn install --no-immutable

node -v
node bin/test.js
# Not using a matrix here since it's simpler
# to just duplicate it and not spawn new instances
node test.cjs
node test.mjs

# Not using a matrix here since it's simpler
# to just duplicate it and not spawn new instances

- uses: actions/setup-node@v4
with:
node-version: 20
- name: Test on Node 20
- name: test build package on node@20
working-directory: ./package-test/
run: |
node -v
node bin/test.js
- uses: actions/setup-node@v4
with:
node-version: 18
- name: Test on Node 18
run: |
node -v
node bin/test.js
node test.cjs
node test.mjs
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"typescript.tsdk": "node_modules/typescript/lib",
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
Expand Down
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,19 @@ yarn add pg-error-enum

### Usage

TypeScript or ES6 Modules

```ts
import { PostgresError } from "pg-error-enum";
```

JavaScript
<details>
<summary>Legacy CommonJS</summary>

```js
const PostgresError = require("pg-error-enum").PostgresError;
const { PostgresError } = require("pg-error-enum");
```

</details>

Usage

```ts
Expand Down
6 changes: 1 addition & 5 deletions bin/sync.mts → bin/sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,7 @@ const getEnum = async () => {

const writeEnum = (enumString: string) => {
writeFileSync(
new URL(
"../src/PostgresError.ts",
// @ts-expect-error requires package.json type: module
import.meta.url,
),
new URL("../src/PostgresError.ts", import.meta.url),
enumString,
);
};
Expand Down
18 changes: 18 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import tseslint from "typescript-eslint";

// eslint-disable-next-line import/extensions
import sharedConfig from "@nihalgonsalves/esconfig/eslint.config.shared.js";

export default tseslint.config(
{ ignores: ["package-test", "dist"] },
...sharedConfig,
{
rules: {
"@typescript-eslint/no-duplicate-enum-values": "off",
"@typescript-eslint/restrict-template-expressions": [
"error",
{ allowNumber: true },
],
},
},
);
14 changes: 0 additions & 14 deletions eslint.config.mjs

This file was deleted.

2 changes: 1 addition & 1 deletion knip.jsonc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://unpkg.com/knip@5/schema.json",
"entry": ["src/index.ts!", "bin/sync.mts"],
"entry": ["src/index.ts!", "bin/sync.ts"],
"project": ["**/*.{js,cjs,mjs,jsx,ts,cts,mts,tsx}"],
}
1 change: 1 addition & 0 deletions package-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.yarn
5 changes: 5 additions & 0 deletions package-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"devDependencies": {
"pg-error-enum": "../"
}
}
4 changes: 1 addition & 3 deletions bin/test.js → package-test/test.cjs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
// eslint-disable-next-line @typescript-eslint/no-require-imports
const { PostgresError } = require("../dist");
const { PostgresError } = require("pg-error-enum");

const main = () => {
console.log("Got code for UNIQUE_VIOLATION", PostgresError.UNIQUE_VIOLATION);

// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition, @typescript-eslint/no-unsafe-enum-comparison
if (PostgresError.UNIQUE_VIOLATION !== "23505") {
throw new Error("Failed");
}
Expand Down
18 changes: 18 additions & 0 deletions package-test/test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { PostgresError } from "pg-error-enum";

const main = () => {
console.log("Got code for UNIQUE_VIOLATION", PostgresError.UNIQUE_VIOLATION);

if (PostgresError.UNIQUE_VIOLATION !== "23505") {
throw new Error("Failed");
}

console.log("OK");
};

try {
main();
} catch (e) {
console.error(e);
process.exit(1);
}
Empty file added package-test/yarn.lock
Empty file.
12 changes: 9 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "pg-error-enum",
"type": "module",
"version": "0.7.3",
"description": "TypeScript Enum for Postgres Errors with no runtime dependencies",
"author": "Nihal Gonsalves <[email protected]>",
Expand All @@ -12,11 +13,13 @@
"url": "https://github.com/nihalgonsalves/pg-error-enum/issues"
},
"homepage": "https://github.com/nihalgonsalves/pg-error-enum#readme",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"exports": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
},
"packageManager": "[email protected]+sha512.5a0afa1d4c1d844b3447ee3319633797bcd6385d9a44be07993ae52ff4facabccafb4af5dcd1c2f9a94ac113e5e9ff56f6130431905884414229e284e37bb7c9",
"scripts": {
"sync": "node --experimental-strip-types bin/sync.mts",
"sync": "node --experimental-strip-types bin/sync.ts",
"clean": "rm -rf ./dist/",
"typecheck": "tsc --noEmit --project tsconfig.json && tsc --noEmit --project tsconfig.build.json",
"build": "tsc --build tsconfig.build.json",
Expand All @@ -29,6 +32,9 @@
"files": [
"dist/**/*"
],
"engines": {
"node": "^20.19.0 || ^22.12.0 || >23.0.0"
},
"devDependencies": {
"@nihalgonsalves/esconfig": "^0.11.0",
"@types/node": "^18",
Expand Down
2 changes: 0 additions & 2 deletions release-please-config.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
"$schema": "https://raw.githubusercontent.com/googleapis/release-please/main/schemas/config.json",
"bump-minor-pre-major": true,
"bump-patch-for-minor-pre-major": true,
"bootstrap-sha": "0e75ce7c949dbb046b8e2bd3a4afeae6c4f09b60",
"packages": {
".": {
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { PostgresError } from "./PostgresError";
export { PostgresError } from "./PostgresError.js";
1 change: 0 additions & 1 deletion tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "ES5",
"declaration": true,
"rootDir": "./src"
},
Expand Down
15 changes: 7 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
{
"extends": "@nihalgonsalves/esconfig/tsconfig.shared.json",
"compilerOptions": {
"target": "es2020",
// TODO: Also publish as ES Module?
"module": "commonjs",
"moduleResolution": "node",
"verbatimModuleSyntax": false,
// https://github.com/microsoft/TypeScript/wiki/Node-Target-Mapping
"lib": ["ES2023"],
"module": "NodeNext",
"target": "ES2023",
"moduleResolution": "NodeNext",
"erasableSyntaxOnly": false,
"outDir": "./dist",
"types": ["node"]
},
"files": [
"src/index.ts",
"src/PostgresError.ts",
"bin/sync.mts",
"bin/test.js",
"eslint.config.mjs"
"bin/sync.ts",
"eslint.config.js"
]
}