-
-
Notifications
You must be signed in to change notification settings - Fork 8
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
chore: set tsconfig moduleResolution to Node16 #27
Conversation
the current crypto import behavior was copied from noble-hashes. I don’t remember why it’s this way. There’s probably some issue in some bundler (webpack, rollup, browserify, esbuild). If it works, then we shouldn’t touch it. Having 4 versions is not acceptable: it becomes much harder to audit and inflates bundle size a lot. When node v18 is deprecated, we would just fully switch to webcrypto. Also tests are failing. |
I agree with this strategy.
Fixed. |
we don’t need src/package.json. we already have lib/esm/package.json |
$ cat src/utils.ts | grep _assert
import { bytes as abytes, isBytes } from './_assert';
$ npm run build
> @noble/[email protected] build
> npm run build:clean; tsc && tsc -p tsconfig.esm.json
> @noble/[email protected] build:clean
> rm *.{js,d.ts,js.map,d.ts.map} esm/*.{js,d.ts,js.map,d.ts.map} 2> /dev/null
src/utils.ts:2:42 - error TS2835: Relative import paths need explicit file extensions in ECMAScript imports when '--moduleResolution' is 'node16' or 'nodenext'. Did you mean './_assert.js'?
2 import { bytes as abytes, isBytes } from './_assert';
~~~~~~~~~~~
Found 1 error in src/utils.ts:2
$ rm src/package.json
$ npm run build
> @noble/[email protected] build
> npm run build:clean; tsc && tsc -p tsconfig.esm.json
> @noble/[email protected] build:clean
> rm *.{js,d.ts,js.map,d.ts.map} esm/*.{js,d.ts,js.map,d.ts.map} 2> /dev/null
$ |
Yes, it should not detect it, that's fine. I use extensions for all files inside of the project except for |
ah, that was the whole reason for the pull request; for us to be able to detect these bugs |
Changing module resolution from bundler to node16 could ruin the build process for webpack / rollup / esbuild. It needs to be tested as well. There was this gist: https://gist.github.com/paulmillr/cf5f8441c93dfef87c814af18a06d166 which should be re-evaluated, but probably a couple of other issues. |
Exactly!
This commit shows the diff of built JS files before and after this PR. Except for comment changes, only |
That's false, i've just copied ciphers into ciphers-16 and changed moduleResolution and module to
The changes are quite big. For example, it changes all -export const cbc = generate("AES-CBC" /* BlockMode.CBC */);
-export const ctr = generate("AES-CTR" /* BlockMode.CTR */);
-export const gcm = generate("AES-GCM" /* BlockMode.GCM */);
+exports.cbc = generate("AES-CBC" /* BlockMode.CBC */);
+exports.ctr = generate("AES-CTR" /* BlockMode.CTR */);
+exports.gcm = generate("AES-GCM" /* BlockMode.GCM */); |
Nevermind: i've forgot to copy the |
Oh your method is great! |
I wish we could remove this |
One method would be moving However, this does break the "zero dependency" rule, which is a downside. |
I don’t think this is a long term solution. For example, dependencies won’t really work in deno. They would only work if npm specifier is utilized. If we just drop this conditional altogether once node v18 is deprecated, that would work much better. |
Good point |
moduleResolution
asNode16
, so thattsc -p tsconfig.esm.json
would warn us with the following error for missing file extension like the one in Downstream builds failing due to ambiguous import #24.Replacedimport ... from '@noble/ciphers/crypto';
toimport ... from './crypto.js';
. Not sure why it was with the full package name.Added
./crypto.js": "./esm/cryptoNode.js"
inesm/package.json
so that it will target the correct file in Node.js environment. I'm not sure if this is necessary but it seems to be harmless to add it.In my opinion, the clearer way is having four different builds: (1) CommonJS (using
globalThis.crypto
); (2) ES2020 (usingglobalThis.crypto
); (3) CommonJS_Node (usingnode:crypto
); (4) ES2020_Node (usingnode:crypto
). In this way, we can remove the"browser"
and"node"
fileds inpackage.json
, and have something like this in thepackage.json
:Since we only use
exports
(and don't use top-levelnode
norbrowser
) for different builds, this should have the best compatibility.I can implement this structure if you agree.