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

Make transform stateless#71

Merged
Rich-Harris merged 6 commits intomasterfrom
stateless
Jun 7, 2016
Merged

Make transform stateless#71
Rich-Harris merged 6 commits intomasterfrom
stateless

Conversation

@Rich-Harris
Copy link
Copy Markdown
Contributor

This follows up on @tivac's suggestion in rollup/rollup#658 – rather than tracking which CommonJS features are used and injecting them haphazardly using the intro hook, modules import commonjsHelpers. This is cleaner, and will allow the results of the transformation to be cached.

There is a wrinkle however: the synthetic ID used for the helpers goes through the same resolution process as any other ID. Since in this case that frequently means rollup-plugin-node-resolve, we end up passing trying to resolve whatever ID we use with the Node resolution algorithm, which will obviously fail.

So I'm proposing we adopt the following convention: plugins that generate synthetic helper modules, like this one, should use the null character (\0) in the ID. Plugins that implement resolveId should ignore IDs with the null character. (The reason I'm suggesting NUL is that it's invalid in filenames on both *nix and Windows.)

I've already taken the liberty of updating createFilter and node-resolve.

Any thoughts @rollup/collaborators?

Apologies for the bad git discipline, I managed to roll some extra stuff in here 😕

Comment thread src/index.js Outdated
}

const HELPERS_ID = '\0commonjsHelpers';
const HELPERS_NAME = '__commonjsHelpers';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I realize this is no worse than it was, but this should be generated so as not to conflict with anything in the file. Could do a simple indexOf with an incrementing suffix rather than trying to be clever with scopes.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

good point – fixed

@Rich-Harris Rich-Harris merged commit 6e8b598 into master Jun 7, 2016
@Rich-Harris Rich-Harris deleted the stateless branch June 7, 2016 18:43
@Victorystick
Copy link
Copy Markdown
Contributor

Neat! Prepending a module name with NUL is a decent hack. I'll update TypeScript accordingly.

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.

3 participants