From d7d4574644150049492066d03fd3c67aafcd3053 Mon Sep 17 00:00:00 2001 From: wighawag Date: Fri, 25 Oct 2024 18:15:20 +0100 Subject: [PATCH 1/6] compile to esm and cjs --- package.json | 21 ++++++++++++++++++--- tsconfig-cjs.json | 7 +++++++ tsconfig.json | 4 ++-- 3 files changed, 27 insertions(+), 5 deletions(-) create mode 100644 tsconfig-cjs.json diff --git a/package.json b/package.json index 3eeffe2..20c0b54 100644 --- a/package.json +++ b/package.json @@ -2,12 +2,27 @@ "name": "drand-client", "version": "1.2.6", "description": "A client to the drand randomness beacon network.", - "main": "index.js", - "types": "index.d.ts", + "type": "module", + "source": "src/index.ts", + "main": "./build/cjs/index.js", + "module": "./build/esm/index.js", + "types": "./build/index.d.ts", + "exports": { + ".": { + "require": { + "types": "./build/index.d.ts", + "default": "./build/cjs/index.cjs" + }, + "import": { + "types": "./build/index.d.ts", + "default": "./build/esm/index.js" + } + } + }, "scripts": { "clean": "rm -rf ./build/* && rm -rf lib/version.ts", "precompile": "node -p \"'export const LIB_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > lib/version.ts", - "compile": "npm run precompile && tsc --project tsconfig.json", + "compile": "npm run precompile && tsc --project tsconfig.json && tsc --project tsconfig-cjs.json", "publish:github": "npm publish --registry https://npm.pkg.github.com", "test": "jest --verbose ./test/**.test.ts", "lint": "eslint ./{lib,test}/*.ts", diff --git a/tsconfig-cjs.json b/tsconfig-cjs.json new file mode 100644 index 0000000..b0b32a6 --- /dev/null +++ b/tsconfig-cjs.json @@ -0,0 +1,7 @@ +{ + "extends": "./tsconfig.json", + "compilerOptions": { + "module": "CommonJS", + "outDir": "./build/cjs" + } +} diff --git a/tsconfig.json b/tsconfig.json index d598155..973873f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,9 +1,9 @@ { "compilerOptions": { - "module": "commonjs", + "module": "esnext", "target": "esnext", "sourceMap": true, - "outDir": "./build", + "outDir": "./build/esm", "moduleResolution": "node", "allowJs": true, "esModuleInterop": true, From 4dc0bbe17e9902159f0a7e5426efb6f6e6ef600a Mon Sep 17 00:00:00 2001 From: wighawag Date: Sat, 26 Oct 2024 07:39:06 +0100 Subject: [PATCH 2/6] fix --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 20c0b54..67904cf 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,7 @@ ".": { "require": { "types": "./build/index.d.ts", - "default": "./build/cjs/index.cjs" + "default": "./build/cjs/index.js" }, "import": { "types": "./build/index.d.ts", From bdff2e2026030da2e10215bcd12e17eb309706c3 Mon Sep 17 00:00:00 2001 From: wighawag Date: Sat, 26 Oct 2024 07:47:30 +0100 Subject: [PATCH 3/6] add dist/src to package --- package.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/package.json b/package.json index 67904cf..d94e414 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,10 @@ } } }, + "files": [ + "build", + "src" + ], "scripts": { "clean": "rm -rf ./build/* && rm -rf lib/version.ts", "precompile": "node -p \"'export const LIB_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > lib/version.ts", From 65ccf25a1f4162f791b679946af22250aa759e56 Mon Sep 17 00:00:00 2001 From: wighawag Date: Sat, 26 Oct 2024 16:16:14 +0100 Subject: [PATCH 4/6] do not make module as it uses "moduleResolution": "node" --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index d94e414..2b4bece 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,6 @@ "name": "drand-client", "version": "1.2.6", "description": "A client to the drand randomness beacon network.", - "type": "module", "source": "src/index.ts", "main": "./build/cjs/index.js", "module": "./build/esm/index.js", From 4887e39a35d5418427873af159ba726efc18cc65 Mon Sep 17 00:00:00 2001 From: wighawag Date: Wed, 30 Oct 2024 09:52:14 +0000 Subject: [PATCH 5/6] fix nodejs import of es module by specifying type in esm folder --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2b4bece..1ee54a7 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "scripts": { "clean": "rm -rf ./build/* && rm -rf lib/version.ts", "precompile": "node -p \"'export const LIB_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > lib/version.ts", - "compile": "npm run precompile && tsc --project tsconfig.json && tsc --project tsconfig-cjs.json", + "compile": "npm run precompile && tsc --project tsconfig.json && echo '{\"type\": \"module\"}' > build/esm/package.json && tsc --project tsconfig-cjs.json", "publish:github": "npm publish --registry https://npm.pkg.github.com", "test": "jest --verbose ./test/**.test.ts", "lint": "eslint ./{lib,test}/*.ts", From 86977069290c916d7bfdb0e521bb97b81c26ccc5 Mon Sep 17 00:00:00 2001 From: wighawag Date: Wed, 30 Oct 2024 10:29:34 +0000 Subject: [PATCH 6/6] revert type:module inclusion as it reqyire the use of .js extension import ( moduleResolution: NoneNext ) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1ee54a7..2b4bece 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "scripts": { "clean": "rm -rf ./build/* && rm -rf lib/version.ts", "precompile": "node -p \"'export const LIB_VERSION = ' + JSON.stringify(require('./package.json').version) + ';'\" > lib/version.ts", - "compile": "npm run precompile && tsc --project tsconfig.json && echo '{\"type\": \"module\"}' > build/esm/package.json && tsc --project tsconfig-cjs.json", + "compile": "npm run precompile && tsc --project tsconfig.json && tsc --project tsconfig-cjs.json", "publish:github": "npm publish --registry https://npm.pkg.github.com", "test": "jest --verbose ./test/**.test.ts", "lint": "eslint ./{lib,test}/*.ts",