From 3a1725141b55867cb4d9ebd3d745c1e5d6072ddc Mon Sep 17 00:00:00 2001 From: Erko Risthein Date: Thu, 11 Dec 2025 12:02:46 +0200 Subject: [PATCH 1/4] Fix source map resolution for bundlers Changed module entry point from root to dist/node/ where source maps have correct relative paths. Previously, the prepack script copied files to root, breaking source map paths that expected to be two directories deep (../../src/). Changes: - Set main/module/types to dist/node/web-eid.js - Add exports field for clean subpath imports - Include src/**/* and dist/node/**/* in package files - Update README import examples - Remove npm link "Cons" section (exports field fixes this) The prepack/postpack scripts are kept for backwards compatibility with direct file imports like '@web-eid/web-eid-library/web-eid'. --- README.md | 10 ++-------- package.json | 45 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 9eb0349..2b5f63d 100644 --- a/README.md +++ b/README.md @@ -250,7 +250,7 @@ When using a build tool like WebPack, Babel, Rollup or the TypeScript compiler: ```javascript // Import the Web-eID library -import * as webeid from '@web-eid/web-eid-library/web-eid'; +import * as webeid from '@web-eid/web-eid-library'; // ...or only what you need import { @@ -258,7 +258,7 @@ import { authenticate, Action, ErrorCode -} from '@web-eid/web-eid-library/web-eid'; +} from '@web-eid/web-eid-library'; // If you need TypeScript interfaces, they are also available! @@ -914,12 +914,6 @@ npm link ~/workspace/web-eid-library - This option might be more convenient for active development. - After making changes to the Web-eID library source and rebuilding the library project, you don't need to reinstall the dependency in your other project. -**Cons** -- ES modules are located at `web-eid/dist/node/` instead of directly under `web-eid/`. - ```ts - import AuthenticateOptions from 'web-eid/dist/node/models/AuthenticateOptions'; - ``` - #### Using `npm pack` You can use `npm pack` to generate a package and install the package archive. diff --git a/package.json b/package.json index c8d0189..a0aec74 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,45 @@ "type": "git", "url": "git@github.com:web-eid/web-eid.js.git" }, - "module": "web-eid.js", + "main": "dist/node/web-eid.js", + "module": "dist/node/web-eid.js", + "types": "dist/node/web-eid.d.ts", + "exports": { + ".": { + "types": "./dist/node/web-eid.d.ts", + "import": "./dist/node/web-eid.js" + }, + "./config": { + "types": "./dist/node/config.d.ts", + "import": "./dist/node/config.js" + }, + "./errors/*": { + "types": "./dist/node/errors/*.d.ts", + "import": "./dist/node/errors/*.js" + }, + "./models/*": { + "types": "./dist/node/models/*.d.ts", + "import": "./dist/node/models/*.js" + }, + "./models/message/*": { + "types": "./dist/node/models/message/*.d.ts", + "import": "./dist/node/models/message/*.js" + }, + "./services/*": { + "types": "./dist/node/services/*.d.ts", + "import": "./dist/node/services/*.js" + }, + "./utils/*": { + "types": "./dist/node/utils/*.d.ts", + "import": "./dist/node/utils/*.js" + } + }, "files": [ + "src/**/*", + "dist/node/**/*", + "dist/es/*", + "dist/iife/*", + "dist/umd/*", "config.d.ts", "config.d.ts.map", "config.js", @@ -30,12 +67,8 @@ "errors/**/*", "models/**/*", "services/**/*", - "utils/**/*", - "dist/es/*", - "dist/iife/*", - "dist/umd/*" + "utils/**/*" ], - "types": "web-eid.d.ts", "author": "Tanel Metsar", "license": "MIT", "devDependencies": { From 5cae4f867ce3903a4a4fbe9efbdc3dce93448e0f Mon Sep 17 00:00:00 2001 From: Erko Risthein Date: Thu, 11 Dec 2025 12:25:48 +0200 Subject: [PATCH 2/4] Address code review feedback: add CommonJS support and module type declaration - Add "type": "module" to clarify ES module intent - Change "main" to point to UMD build for CommonJS consumers - Add "require" condition to exports for CommonJS support --- package.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index a0aec74..b85090d 100644 --- a/package.json +++ b/package.json @@ -17,13 +17,15 @@ "type": "git", "url": "git@github.com:web-eid/web-eid.js.git" }, - "main": "dist/node/web-eid.js", + "type": "module", + "main": "dist/umd/web-eid.js", "module": "dist/node/web-eid.js", "types": "dist/node/web-eid.d.ts", "exports": { ".": { "types": "./dist/node/web-eid.d.ts", - "import": "./dist/node/web-eid.js" + "import": "./dist/node/web-eid.js", + "require": "./dist/umd/web-eid.js" }, "./config": { "types": "./dist/node/config.d.ts", From 1aedf92a79fb797633f0394826987ae9d0f117d4 Mon Sep 17 00:00:00 2001 From: Erko Risthein Date: Thu, 11 Dec 2025 14:48:07 +0200 Subject: [PATCH 3/4] Add type:module and rename UMD to .cjs for proper ESM/CJS support - Rename UMD bundle outputs from .js to .cjs extension - Update main and exports to reference .cjs files - Add exports for dist bundles (es, umd, iife) for direct imports This ensures Node.js correctly parses UMD as CommonJS while the package is declared as ESM. --- package.json | 9 ++++++--- rollup.config.mjs | 4 ++-- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index b85090d..2dd7200 100644 --- a/package.json +++ b/package.json @@ -18,14 +18,14 @@ "url": "git@github.com:web-eid/web-eid.js.git" }, "type": "module", - "main": "dist/umd/web-eid.js", + "main": "dist/umd/web-eid.cjs", "module": "dist/node/web-eid.js", "types": "dist/node/web-eid.d.ts", "exports": { ".": { "types": "./dist/node/web-eid.d.ts", "import": "./dist/node/web-eid.js", - "require": "./dist/umd/web-eid.js" + "require": "./dist/umd/web-eid.cjs" }, "./config": { "types": "./dist/node/config.d.ts", @@ -50,7 +50,10 @@ "./utils/*": { "types": "./dist/node/utils/*.d.ts", "import": "./dist/node/utils/*.js" - } + }, + "./dist/es/*": "./dist/es/*", + "./dist/iife/*": "./dist/iife/*", + "./dist/umd/*": "./dist/umd/*" }, "files": [ "src/**/*", diff --git a/rollup.config.mjs b/rollup.config.mjs index 9905f93..49c179e 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -34,13 +34,13 @@ export default { plugins: [terser()], }, { - file: "dist/umd/web-eid.js", + file: "dist/umd/web-eid.cjs", format: "umd", name: "webeid", sourcemap: true, }, { - file: "dist/umd/web-eid.min.js", + file: "dist/umd/web-eid.min.cjs", format: "umd", name: "webeid", sourcemap: false, From 33722b7c5432acbc51f52466c8499388da3c1d02 Mon Sep 17 00:00:00 2001 From: Erko Risthein Date: Thu, 11 Dec 2025 15:16:16 +0200 Subject: [PATCH 4/4] Add "default" condition as fallback for compatibility --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 2dd7200..863ee97 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ ".": { "types": "./dist/node/web-eid.d.ts", "import": "./dist/node/web-eid.js", - "require": "./dist/umd/web-eid.cjs" + "require": "./dist/umd/web-eid.cjs", + "default": "./dist/umd/web-eid.cjs" }, "./config": { "types": "./dist/node/config.d.ts",