vbuch / node-signpdf

Simple signing of PDFs in node.
MIT License
688 stars 175 forks source link

Strange import usage #138

Closed danielbom closed 2 years ago

danielbom commented 3 years ago

I can't import the "node-signpdf" when using { "type": "module" }. Why the exports is so strange?

const { plainAddPlaceholder } = require("node-signpdf/dist/helpers");
const signer = require("node-signpdf").default;

This was my imports. Why I need get some thing from dist? This was so anti-pattern and strange.

import { plainAddPlaceholder } from "node-signpdf/dist/helpers";
import signer from "node-signpdf";

With { "type": "module" } into package.json this not work unless passing somes flags. I saw that the "node-signpdf" require "helpers" to create the base exports. Why not export it too?

import signer from "node-signpdf";
import { plainAddPlaceholder, extractSignature } from "node-signpdf";

// or this if you won't wanna destructuring the helpers in the base exporter
import signer from "node-signpdf";
import { helpers: { plainAddPlaceholder, extractSignature } } from "node-signpdf";

Do it like this is much better and straightforward.

vbuch commented 3 years ago

Short answer: Legacy.

Longer version: When this was started both src/ and dist/ were supposed to be distributed with the npm package allowing you to choose which one to use. I know it makes less sense now, but it would be version change if done this way now. This will most likely be fixed with version 2 (whenever that is).

stale[bot] commented 2 years ago

This issue has been automatically marked as stale because it has not had activity in the past 90 days. It will be closed if no further activity occurs. Thank you for your contributions.