hughsk / envify

:wrench: Selectively replace Node-style environment variables with plain strings.
902 stars 57 forks source link

Single-pass transformation #52

Closed ariya closed 7 years ago

ariya commented 7 years ago

This is utilizing Esprima's syntax delegate feature to track directly each syntax node as it is being constructed, looking for process.env.SOMETHING or process.env["SOMETHING"], and record the individual source replacement into an array (the whole replacements are applied directly on the source input later on). Thus, there is no need for an additional pass to traverse the syntax tree.

There is no API change, all tests pass.

ariya commented 7 years ago

Note that this change removes the need to use jstransform (which has been deprecated and which, IMHO, is a bit overkill for this kind of source transformation) and it also likely supersedes PR #30.

jesstelford commented 7 years ago

This fork fixed the following error for me when using rollup + rollup-plugin-browserify-transform:

Error transforming /home/test/node_modules/styled-components/dist/styled-components.es.js: Parse Error: Line 1: Illegal import declaration
ariya commented 7 years ago

@hughsk @zertosh Any interest in this PR? If yes, please advise on how to move forward 😸 . Thanks!

hughsk commented 7 years ago

Hey @ariya! Thanks very much, sorry for the delayed response — looks good to me :D

jaredbeck commented 7 years ago

Given that this was the only change between 3.4.1 and 4.0.0, and Ariya describes it as "no API change", why was the major version number incremented? To indicate the change in dependencies? If there really were no breaking changes in the API, it seems to me that the major version number should not be incremented. Of course, semver allows an increment, and it's your project Hugh, I just found it confusing.