diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile
index c19393d..4c9f4ab 100644
--- a/.devcontainer/Dockerfile
+++ b/.devcontainer/Dockerfile
@@ -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
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
index f5a9b97..81d1f95 100644
--- a/.github/workflows/test.yml
+++ b/.github/workflows/test.yml
@@ -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
diff --git a/.vscode/settings.json b/.vscode/settings.json
index 02b5dc1..b1791ed 100644
--- a/.vscode/settings.json
+++ b/.vscode/settings.json
@@ -1,4 +1,5 @@
{
+ "typescript.tsdk": "node_modules/typescript/lib",
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
diff --git a/README.md b/README.md
index 1fffbd8..afb4f0d 100644
--- a/README.md
+++ b/README.md
@@ -19,18 +19,19 @@ yarn add pg-error-enum
### Usage
-TypeScript or ES6 Modules
-
```ts
import { PostgresError } from "pg-error-enum";
```
-JavaScript
+
+Legacy CommonJS
```js
-const PostgresError = require("pg-error-enum").PostgresError;
+const { PostgresError } = require("pg-error-enum");
```
+
+
Usage
```ts
diff --git a/bin/sync.mts b/bin/sync.ts
similarity index 95%
rename from bin/sync.mts
rename to bin/sync.ts
index c875660..b59a624 100644
--- a/bin/sync.mts
+++ b/bin/sync.ts
@@ -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,
);
};
diff --git a/eslint.config.js b/eslint.config.js
new file mode 100644
index 0000000..3931d09
--- /dev/null
+++ b/eslint.config.js
@@ -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 },
+ ],
+ },
+ },
+);
diff --git a/eslint.config.mjs b/eslint.config.mjs
deleted file mode 100644
index 69fcd30..0000000
--- a/eslint.config.mjs
+++ /dev/null
@@ -1,14 +0,0 @@
-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: ["dist"] }, ...sharedConfig, {
- rules: {
- "@typescript-eslint/no-duplicate-enum-values": "off",
- "@typescript-eslint/restrict-template-expressions": [
- "error",
- { allowNumber: true },
- ],
- },
-});
diff --git a/knip.jsonc b/knip.jsonc
index 8bc9f99..dd3c73b 100644
--- a/knip.jsonc
+++ b/knip.jsonc
@@ -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}"],
}
diff --git a/package-test/.gitignore b/package-test/.gitignore
new file mode 100644
index 0000000..61c3bc7
--- /dev/null
+++ b/package-test/.gitignore
@@ -0,0 +1 @@
+.yarn
diff --git a/package-test/package.json b/package-test/package.json
new file mode 100644
index 0000000..9c1d344
--- /dev/null
+++ b/package-test/package.json
@@ -0,0 +1,5 @@
+{
+ "devDependencies": {
+ "pg-error-enum": "../"
+ }
+}
diff --git a/bin/test.js b/package-test/test.cjs
similarity index 55%
rename from bin/test.js
rename to package-test/test.cjs
index 76bef0c..c375a56 100644
--- a/bin/test.js
+++ b/package-test/test.cjs
@@ -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");
}
diff --git a/package-test/test.mjs b/package-test/test.mjs
new file mode 100644
index 0000000..59049fc
--- /dev/null
+++ b/package-test/test.mjs
@@ -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);
+}
diff --git a/package-test/yarn.lock b/package-test/yarn.lock
new file mode 100644
index 0000000..e69de29
diff --git a/package.json b/package.json
index 43c2d29..43fef7c 100644
--- a/package.json
+++ b/package.json
@@ -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 ",
@@ -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": "yarn@4.7.0+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",
@@ -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",
diff --git a/release-please-config.json b/release-please-config.json
index 3032bc0..e26be53 100644
--- a/release-please-config.json
+++ b/release-please-config.json
@@ -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": {
".": {
diff --git a/src/index.ts b/src/index.ts
index 3ea4e93..88cc1ab 100644
--- a/src/index.ts
+++ b/src/index.ts
@@ -1 +1 @@
-export { PostgresError } from "./PostgresError";
+export { PostgresError } from "./PostgresError.js";
diff --git a/tsconfig.build.json b/tsconfig.build.json
index 50210b4..974eb0d 100644
--- a/tsconfig.build.json
+++ b/tsconfig.build.json
@@ -1,7 +1,6 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
- "target": "ES5",
"declaration": true,
"rootDir": "./src"
},
diff --git a/tsconfig.json b/tsconfig.json
index f155121..970bbb5 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -1,11 +1,11 @@
{
"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"]
@@ -13,8 +13,7 @@
"files": [
"src/index.ts",
"src/PostgresError.ts",
- "bin/sync.mts",
- "bin/test.js",
- "eslint.config.mjs"
+ "bin/sync.ts",
+ "eslint.config.js"
]
}