fluentui icon indicating copy to clipboard operation
fluentui copied to clipboard

AMD bundling: strip out process.env.NODE_ENV which isn't automatically defined by bundling

Open aksingh opened this issue 7 years ago • 9 comments

https://github.com/OfficeDev/office-ui-fabric-react/commit/a9245feee547762f0c8c9935cbf39d737b86c519 clearly introduces a breaking change without bumping the major version.

If fabric folks intend to use the minor versions as breaking, then please add guidelines that consumers should be fixing their fabric versions precisely up to the patch version.

aksingh avatar Sep 16 '19 19:09 aksingh

@kenotron and @TheLarkInn for clarity.

This change did not change a single API surface. It did not modify a pixel, or change anything other than to remove the typedef check inside of code. I don't think this would be considered a breaking change.

I believe the change was due to the typedef code causing webpack customers to pull in extra code without tree shaking out process.env production flagged code.

Could you clarify how it broken you? Are you using a particular configuration that this broke?

dzearing avatar Sep 16 '19 20:09 dzearing

@kenotron and @TheLarkInn Are there things we could be doing better here? For example if the customer is using an older version of webpack, or is using another bundler, process is not guaranteed to be defined, which could likely break them.

dzearing avatar Sep 16 '19 20:09 dzearing

@dzearing We don't use webpack for one of our builds and that one just silently broke with this change. Basically everyone using AMD modules or non-bundled builds is likely to break silently on this.

aksingh avatar Sep 17 '19 01:09 aksingh

@aksingh Sorry for the trouble. This is not totally obvious that this was an api break. I'm still not sure it was as we weren't changing an api surface, but certainly output bits changed in a way that made it more frictiony. You should be able to simply define process.env to unblock AMD bundling not automatically doing this.

Which project do you work on? I'd love to understand why you're still using AMD and not using any modern bundling system which supports building debug code, but more importantly would like a contact to talk about AMD needs. Checking process.env.NODE_ENV has been used as a standard pattern in many major modern libraries for optional debug code, but really we don't want to cause any unnecessary friction here.

@kenotron One idea would be to apply a babel transform on AMD output to strip out debug bits for AMD completely. Thoughts?

dzearing avatar Sep 17 '19 01:09 dzearing

There's an idea I had about post processing some of the code we transpile:

  1. lib-commonjs code still requires "lib" from other libraries from our codebase (requiring our consumers to still run babel in jest)
  2. lib-amd having their process.env stripped out

I am not against that post-transpile step. But have to think through what consequences are here.

kenotron avatar Sep 17 '19 16:09 kenotron

I work on the Planner team :) @dzearing we can chat offline reg other details

aksingh avatar Sep 19 '19 23:09 aksingh

We are looking at a fix to strip the process.env.NODE_ENV from amd build output to make this less janky. Sorry for the trouble.

I am going to rename this issue to reflect the true problem :)

dzearing avatar Sep 20 '19 00:09 dzearing

@kenotron assigned to you for now, a build step to find/replace probably would be good enough.

dzearing avatar Sep 20 '19 00:09 dzearing

@aksingh Please do reach out. It'd be great to have a contact who can give some background about why AMD, and what the future plans are for that, but also we'd love to know sooner that we broke something unexpectedly.

dzearing avatar Sep 20 '19 01:09 dzearing