-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some ideas regarding maintenance #115
Comments
Hey @stopsopa! I am actually using the Node.js built-in test runner, which last time I looked does not produce a web-publishable test coverage report, like Jest does. Will keep an eye on this. However I have added a link the documentation. This package does dual export CommonJS/ESM already. The type docs are published to GH here and are auto-published on release. Thanks for taking a look! |
$ tree .
.
├── index.js
├── node_modules
│ └── hmac-auth-express
│ ├── CHANGELOG.md
│ ├── LICENSE
│ ├── MIGRATION_GUIDE.md
│ ├── README.md
│ ├── dist
│ │ ├── errors.d.ts
│ │ ├── errors.js
│ │ ├── generate.d.ts
│ │ ├── generate.js
│ │ ├── index.d.ts
│ │ ├── index.js
│ │ ├── order.d.ts
│ │ ├── order.js
│ │ ├── validateArguments.d.ts
│ │ └── validateArguments.js
│ └── package.json
├── package.json
└── yarn.lock
3 directories, 18 files
all files are in esm format like this one: $ cat node_modules/hmac-auth-express/dist/index.js | head
import validateArguments from "./validateArguments.js";
import AuthError from "./errors.js";
import generate from "./generate.js";
import order from "./order.js";
const crypto = await import("node:crypto");
export { AuthError, generate, order };
export const defaults = {
algorithm: "sha256",
identifier: "HMAC",
header: "authorization",
...
.. using import/export format additionally the final package.json is with "type": "module" $ cat node_modules/hmac-auth-express/package.json | head
{
"name": "hmac-auth-express",
"type": "module",
"version": "9.0.0",
"description": "Express middleware for HMAC authentication",
"keywords": [
"nodejs",
"javascript",
"middleware",
"express", and when I'm trying to import it in regular commonjs setup (with not defined "type" in my local package.json -> which by default mean commonjs) ... const { HMAC } = require("hmac-auth-express");
console.log("HMAC", HMAC);
HMAC("secret") ... using require I get the error: node index.js
Debugger listening on ws://127.0.0.1:65082/cebf1ad3-f69f-4be8-98f9-3438d29239cd
For help, see: https://nodejs.org/en/docs/inspector
Debugger attached.
Waiting for the debugger to disconnect...
/Users/user/project/hm/index.js:3
const { HMAC } = require("hmac-auth-express");
^
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/user/project/hm/node_modules/hmac-auth-express/dist/index.js from /Users/user/project/hm/index.js not supported.
Instead change the require of /Users/user/project/hm/node_modules/hmac-auth-express/dist/index.js in /Users/user/project/hm/index.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/Users/user/project/hm/index.js:3:18) {
code: 'ERR_REQUIRE_ESM'
}
Node.js v20.15.0 If esm and commonjs would be available I would expect structure similar to this
where package.json would be without "type", something what is suggested in this article: https://blog.mastykarz.nl/create-npm-package-commonjs-esm-typescript/ BTW: That's a shame that there is no full tutorial how to publish properly libraries to npm despite TS popularity. Even the article above is not covering it in 100%. Ideally I would expect to find it in TS documentation. Here is the library I was trying to use to explore this subject recently: https://github.com/stopsopa/tsdi-lite |
Great lib.
You could do though few more things:
[Image 1]
[Image 2]
The text was updated successfully, but these errors were encountered: