Skip to content

Conversation

@mixmix
Copy link
Contributor

@mixmix mixmix commented Sep 28, 2023

Trying to noderify secret-stack@7 we get errors from acorn trying to parse ??=, ??, cb?.(), opts?.timeout etc

I've looked through the stack for the best solution and tried:

  • ❌ set ecmaVersion: 2023. supposedly supported by the version of acorn we're using, but nope
  • ✔️ mutated the detect function to "tidy" the new features into version which don't break the parser

I also tidied logging to make it easier to see at a glance if things are passing

Copy link
Owner

@staltz staltz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mixmix in spirit this is great, and I've tried to do this myself once, but got lost in the complexity that is substack's forest of modules that handle this on top of acorn. acorn itself supports modern JS but the browserify ecosystem on top of it doesn't, yet.

Your PR however is going to cause at least two different kinds of showstopper bugs.

I recommend one these three:

  • Do this PR properly by updating acorn and detective and resolve etc
  • Don't update secret-stack to 7 (it didn't receive that very important updates compared to 6)
  • (My favorite) Use esbuild instead of noderify. I've used it for other projects and it's really really good. Not only is it flexible and does everything that noderify does, it's faster and well maintained.

'worker_threads',
'zlib'
'zlib',
'supports-color' // debug tests to see if this is present by requiring it
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a big problem. Whoever uses the actual real supports-color npm package will not be able to use noderify.

If this is only for tests then there should be tests-specific flag that activate this.

.replace(/\?\?=/g, '=') // nullish coalescing assignment
.replace(/\?\?/g, '||') // nullish coalescing
.replace(/\?\.\(/g, '(') // optional chaining (into a function)
.replace(/\?\./g, '.') // optional chaining (into a property)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is ~80% likely to cause breaking changes out there. ??= cannot be replaced by = without causing bugs that are hard to detect. Example:

BEFORE

function init(opts) {
  opts.timeout ??= 5*60*60;
}

AFTER

function init(opts) {
  opts.timeout = 5*60*60;
}

Now whoever calls init({timeout: 2}) will feel super confused that the timeout ends up being 5 hours instead of the expected 2 seconds.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this doesn't mutate the code that's exported. I confirmed that in the bundle.
This only mutates the code that detective is looking at for require commands

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants