Skip to content
This repository was archived by the owner on Nov 23, 2021. It is now read-only.

Remove gud package#36

Closed
TrySound wants to merge 2 commits into
StringEpsilon:masterfrom
TrySound:crm_remove_webpackism
Closed

Remove gud package#36
TrySound wants to merge 2 commits into
StringEpsilon:masterfrom
TrySound:crm_remove_webpackism

Conversation

@TrySound

Copy link
Copy Markdown

In this diff I removed gud package which is pure webpackism and requires
global to be defined. Rollup cannot handle this out of the box.
Moreover it's one more commonjs package which need to be transpiled.
I inlined commonjsGlobal and added gud like function.

Also tweaked rollup config. Migrated to more trusty terser and
simplified external function.

@StringEpsilon

Copy link
Copy Markdown
Owner

Thank you for contributing :)

Can you split the one commit to one commit for the rollup config change and one for the gud replacement?

I'll take a proper look at both changes later.

TrySound added 2 commits June 25, 2019 19:35
In this diff I removed gud package which is pure webpackism and requires
`global` to be defined. Rollup cannot handle this out of the box.
Moreover it's one more commonjs package which need to be transpiled.
I inlined commonjsGlobal and added gud like function.

Also tweaked rollup config. Migrated to more trusty terser and
simplified external function.
Comment thread src/implementation.ts
? global
: typeof self !== 'undefined'
? self
: {};

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Not familiar with this construct. But do we need all fallbacks? If you can point me to some documentation on the matter, that'd be appreciated

Also: Do we need the explicit check for undefined, or would !globalThis do the job as well?

@StringEpsilon StringEpsilon Jun 25, 2019

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thinking about it some more: I'm not a big fan of inlining that polyfill. Users are likely to have the proper polyfill anyway - and the package depends on @babel/runtime too.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Any not existing global access except typeof variable gives runtime error. I got it here.
https://github.com/rollup/rollup-plugin-commonjs/blob/master/src/helpers.js#L14

Babel runtime does not require from users any polyfilling. gud does require. Yes, webpack does this polyfilling out of the box. Rollup does not. This is really node.js specific thing and should not be in browser library.

@StringEpsilon StringEpsilon Jun 25, 2019

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Then we can either directly use globalThis (it's stage-3 now and supported by most browsers) with instructions on how to poly-fill (either through babel/core-js or with a designated polyfill package) or shorten the inlined version:

const commonjsGlobal: any =
  typeof globalThis !== 'undefined' // 'global proper'
  ? globalThis
  : typeof window !== 'undefined' 
  ? window // Browser
  : typeof global !== 'undefined'
  ? global // node.js

If the bare object is used, I expect breakage anyway in some scenarios (like if this library is duplicated across multiple loaded bundles). And if it doesn't break in those scenarios, then a global-ish construct isn't needed anyway.

I'd still prefer not to inline.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It's not supported by node v8. Polyfills are commonjs modules. Ok, I will remove empty object.

Comment thread rollup.config.js
}
return !id.includes(path.join(process.cwd(), "src"));
function isExternal(id) {
return id.startsWith(".") === false && path.isAbsolute(id) === false;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Nitpick: Wrong indentation.

(I should probably add an .editorconfig file.)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I can rebase if you will setup prettier. By default my editor enforce 2-space indentation.

@StringEpsilon

Copy link
Copy Markdown
Owner

Otherwise LGTM.

@TrySound TrySound closed this Feb 3, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants