From 3e6a66a8879fb40fda9be1a6b28026589ae03fe4 Mon Sep 17 00:00:00 2001 From: maxilie Date: Mon, 24 Apr 2023 13:46:50 -0400 Subject: [PATCH] gh-43: Fix ESModule incompatibility with node16 --- .eslintrc.js => .eslintrc.cjs | 0 build.js => build.cjs | 2 +- jest.config.js => jest.config.cjs | 0 package.json | 13 +++++++------ src/index.ts | 3 +-- tsconfig.json | 5 ++--- 6 files changed, 11 insertions(+), 12 deletions(-) rename .eslintrc.js => .eslintrc.cjs (100%) rename build.js => build.cjs (97%) rename jest.config.js => jest.config.cjs (100%) diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 100% rename from .eslintrc.js rename to .eslintrc.cjs diff --git a/build.js b/build.cjs similarity index 97% rename from build.js rename to build.cjs index 71174764..4f680130 100755 --- a/build.js +++ b/build.cjs @@ -7,7 +7,7 @@ esbuild bundle: true, entryPoints: ['./src/index.ts'], external: ['@babel/runtime', 'isomorphic-fetch', 'graphql-request'], - format: 'cjs', + format: 'esm', logLevel: 'info', metafile: true, minify: true, diff --git a/jest.config.js b/jest.config.cjs similarity index 100% rename from jest.config.js rename to jest.config.cjs diff --git a/package.json b/package.json index 6730f5e0..f1d24aab 100644 --- a/package.json +++ b/package.json @@ -3,23 +3,24 @@ "version": "1.1.0", "description": "TypeScript client for Weaviate", "main": "dist/index.js", - "types": "types/index.d.ts", + "types": "dist/index.d.ts", + "type": "module", "engines": { "node": ">=16.0.0" }, "files": [ "/dist/index.js", "/dist/index.js.map", - "/types/**/*.d.ts" + "/dist/**/*.d.ts" ], "scripts": { "test": "tsc -noEmit -p tsconfig-test.json && jest --useStderr --runInBand --detectOpenHandles", - "build": "npm run lint && tsc --emitDeclarationOnly && ./build.js", + "build": "npm run lint && tsc --emitDeclarationOnly && ./build.cjs", "prepack": "npm run build", - "lint": "eslint --ext .ts,.js .", + "lint": "eslint --ext .ts,.js,.cjs .", "lint:fix": "npm run lint -- --fix", - "format": "prettier --write --no-error-on-unmatched-pattern '**/*.{ts,js}' '!dist/**' '!types/**'", - "format:check": "prettier --check --no-error-on-unmatched-pattern '**/*.{ts,js}' '!dist/**' '!types/**'", + "format": "prettier --write --no-error-on-unmatched-pattern '**/*.{ts,js,cjs}' '!dist/**' '!types/**'", + "format:check": "prettier --check --no-error-on-unmatched-pattern '**/*.{ts,js,cjs}' '!dist/**' '!types/**'", "prepare": "husky install" }, "repository": { diff --git a/src/index.ts b/src/index.ts index ee862cce..8b3b6b6b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -92,8 +92,6 @@ function initDbVersionProvider(conn: Connection) { return dbVersionProvider; } -module.exports = app; -export default app; export * from './openapi/types'; export * from './graphql'; export * from './schema'; @@ -105,3 +103,4 @@ export * from './c11y'; export * from './backup'; export * from './cluster'; export * from './connection'; +export default app; diff --git a/tsconfig.json b/tsconfig.json index e1b78f5a..e20eaad9 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -11,16 +11,15 @@ "allowJs": true, "checkJs": false, "sourceMap": false, - "module": "commonjs", + "module": "ES2020", "moduleResolution": "node", "esModuleInterop": true, "skipLibCheck": true, "forceConsistentCasingInFileNames": true, "isolatedModules": true, - "outDir": "./types", + "outDir": "./dist", "declaration": true, "rootDir": "./src", - "types": ["node"] }, "include": ["./src/**/*"], "exclude": ["**/*.test.ts"]