Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Modify module wrapper so that "process", "global" are shadowable #21

Closed
wants to merge 1 commit into from

Conversation

ide
Copy link
Contributor

@ide ide commented Jan 11, 2017

In upstream Node the module wrapper doesn't define "process" and "global" so you can write code like const process = require('process') without an error due to redefining the variable. Short of updating this entire vendored copy of Node, a simple way I could think of that provides similar semantics is to modify the module wrapper by adding an extra IIFE that omits "process" and "global" from its parameter list.

Test Plan: Tested this end-to-end inside of Electron itself by building it from source and ensuring the test app loads.

In upstream Node the module wrapper doesn't define "process" and "global" so you can write code like `const process = require('process')` without an error due to redefining the variable. Short of updating this entire vendored copy of Node, a simple way I could think of that provides similar semantics is to modify the module wrapper by adding an extra IIFE that omits "process" and "global" from its parameter list.
@anaisbetts
Copy link

Short of updating this entire vendored copy of Node

Afaik that's exactly what we do, this repo tracks upstream node every time we make a major release of Electron

@ide
Copy link
Contributor Author

ide commented Jan 11, 2017

@paulcbetts I did some more digging -- it looks like this Electron-specific commit forked the module wrapper from Node: 8238770

So I guess rebasing on top of upstream wouldn't fix the issue at hand (see electron/electron#8358), there still needs to be a patch like this.

'(function (exports, require, module, __filename, __dirname, process, global) { ',
'\n});'
'(function (exports, require, module, __filename, __dirname, process, global) { ' +
'return function (exports, require, module, __filename, __dirname) { ',
Copy link
Contributor

Choose a reason for hiding this comment

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

@ide is the return statement needed here?

Looks like return value for this function is unused when it is called on line 506

@kevinsawicki kevinsawicki changed the base branch from atom to electron January 24, 2017 20:38
@kevinsawicki kevinsawicki changed the base branch from electron to atom January 24, 2017 20:38
@kevinsawicki
Copy link
Contributor

@ide apologies for the delay merging this, we were in the middle of upgrading to node 7.4 from node 6.5.

This upgrade is complete now, would you mind rebasing/retargeting this change against the electron branch in this repo?

@kevinsawicki
Copy link
Contributor

We try to maintain the fewer number of commit patches to node so I've merged this change into the original patch to minimize conflicts going forward.

So this was merged directly into commit f691373

Thanks 👍

@ide
Copy link
Contributor Author

ide commented Jan 30, 2017

Sweet, thanks, keeping the fork commits small and simple totally makes sense.

@ide ide closed this Jan 30, 2017
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