-
Notifications
You must be signed in to change notification settings - Fork 2
Fix encodeComponent export by avoiding destructuring with rename #3
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
Conversation
…t = void 0;` Signed-off-by: indexzero <charlie.robbins@gmail.com>
|
Thank you @indexzero! I'll add some commits around this and clear caches as part of builds... interesting the tests didn't catch this... |
|
@indexzero Thank you for the kind greeting by the way! I am doing good! Hope you're doing well too. |
…t = void 0;` (#3) Signed-off-by: indexzero <charlie.robbins@gmail.com>
Document why we avoid destructuring from global objects due to a tsgo transpilation bug that causes runtime errors. References issue #3.
Replace destructuring from global objects with direct property access to work around tsgo transpilation bug that causes runtime errors. References: SocketDev/socket-packageurl-js#3
It looks like
Thanks 🫶 it is fun being back in the saddle with Node & JS again. Spent a few years in different worlds (energy & climate are mostly Python) which were educational though 🤓 |
|
I'm following up with commits to have tests run both |
|
That's a solid plan @jdalton. Thanks for creating / maintaining this functionality! It's been really useful separate from other libraries for purl ( |
Replace destructuring from global objects with direct property access to work around tsgo transpilation bug that causes runtime errors. References: SocketDev/socket-packageurl-js#3
Replace destructuring from global objects with direct property access to work around tsgo transpilation bug that causes runtime errors. References: SocketDev/socket-packageurl-js#3
Replace destructuring from global objects with direct property access to work around tsgo transpilation bug that causes runtime errors. References: SocketDev/socket-packageurl-js#3
…t = void 0;` (#3) Signed-off-by: indexzero <charlie.robbins@gmail.com>
Document why we avoid destructuring from global objects due to a tsgo transpilation bug that causes runtime errors. References issue #3.
What is the issue?
The simplest possible repro via
node -pe:pnpm install @socketregistry/packageurl-js@1.1.2 node -pe "(new (require('@socketregistry/packageurl-js').PackageURL)('npm', '@babel', 'runtime', '7.18.6', null, 'helpers/typeof.js').toString())"yields
./node_modules/.pnpm/@socketregistry+packageurl-js@1.1.2/node_modules/@socketregistry/packageurl-js/dist/purl-type.js:316 if ((0, encode_js_1.encodeComponent)(name) !== name) { ^ TypeError: (0 , encode_js_1.encodeComponent) is not a function at Object.npm [as validate] (./node_modules/.pnpm/@socketregistry+packageurl-js@1.1.2/node_modules/@socketregistry/packageurl-js/dist/purl-type.js:316:49) at new PackageURL (./node_modules/.pnpm/@socketregistry+packageurl-js@1.1.2/node_modules/@socketregistry/packageurl-js/dist/package-url.js:103:40) at [eval]:1:2 at runScriptInThisContext (node:internal/vm:209:10) at node:internal/process/execution:449:12 at [eval]-wrapper:6:24 at runScriptInContext (node:internal/process/execution:447:60) at evalFunction (node:internal/process/execution:87:30) at evalScript (node:internal/process/execution:99:3) at node:internal/main/eval_string:74:3The 1-liner above is just the
node -peequivalent to the example fromREADME.md:Why does this fix the issue?
There appears to be a subtle bug in
tsgothat is causing the destructured version of this assignment to transpile to:I'm far from an expert in that domain, but this does resolve the issue:
which yields