Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid __webpack_require__ conflicts #633

Merged
merged 2 commits into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,12 @@ function ncc (
map.mappings = ";" + map.mappings;
}

// __webpack_require__ can conflict with webpack injections in module scopes
// to avoid this without recomputing the source map we replace it with an
// identical length identifier
if (code.indexOf('"__webpack_require__"') === -1)
code = code.replace(/__webpack_require__/g, '__nccwpck_require__');

// for each .js / .mjs / .cjs file in the asset list, build that file with ncc itself
if (!noAssetBuilds) {
const compilation = compilationStack[compilationStack.length - 1];
Expand Down
32 changes: 16 additions & 16 deletions test/unit/bundle-subasset/output-coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ module.exports =
/******/ var __webpack_modules__ = ({

/***/ 929:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => {

__webpack_require__.r(__webpack_exports__);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(622);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_0__);
__nccwpck_require__.r(__webpack_exports__);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(622);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(path__WEBPACK_IMPORTED_MODULE_0__);


const file = __webpack_require__.ab + "pi-bridge.js";
const file = __nccwpck_require__.ab + "pi-bridge.js";

const obscureRequire = eval(`function obscureRequire (file) {
require(file);
}`);

console.log(obscureRequire(__webpack_require__.ab + "pi-bridge.js"));
console.log(obscureRequire(__nccwpck_require__.ab + "pi-bridge.js"));


/***/ }),
Expand All @@ -35,7 +35,7 @@ module.exports = require("path");
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ function __nccwpck_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(__webpack_module_cache__[moduleId]) {
/******/ return __webpack_module_cache__[moduleId].exports;
Expand All @@ -50,7 +50,7 @@ module.exports = require("path");
/******/ // Execute the module function
/******/ var threw = true;
/******/ try {
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__);
/******/ threw = false;
/******/ } finally {
/******/ if(threw) delete __webpack_module_cache__[moduleId];
Expand All @@ -64,21 +64,21 @@ module.exports = require("path");
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = (module) => {
/******/ __nccwpck_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => module['default'] :
/******/ () => module;
/******/ __webpack_require__.d(getter, { a: getter });
/******/ __nccwpck_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ __nccwpck_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
Expand All @@ -87,13 +87,13 @@ module.exports = require("path");
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop)
/******/ __nccwpck_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop)
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ __nccwpck_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
Expand All @@ -103,10 +103,10 @@ module.exports = require("path");
/******/
/******/ /* webpack/runtime/compat */
/******/
/******/ __webpack_require__.ab = __dirname + "/";/************************************************************************/
/******/ __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
/******/ // module exports must be returned from runtime so entry inlining is disabled
/******/ // startup
/******/ // Load entry module and return exports
/******/ return __webpack_require__(929);
/******/ return __nccwpck_require__(929);
/******/ })()
;
32 changes: 16 additions & 16 deletions test/unit/bundle-subasset/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@ module.exports =
/******/ var __webpack_modules__ = ({

/***/ 743:
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
/***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => {

__webpack_require__.r(__webpack_exports__);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(622);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_0__);
__nccwpck_require__.r(__webpack_exports__);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(622);
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(path__WEBPACK_IMPORTED_MODULE_0__);


const file = __webpack_require__.ab + "pi-bridge.js";
const file = __nccwpck_require__.ab + "pi-bridge.js";

const obscureRequire = eval(`function obscureRequire (file) {
require(file);
}`);

console.log(obscureRequire(__webpack_require__.ab + "pi-bridge.js"));
console.log(obscureRequire(__nccwpck_require__.ab + "pi-bridge.js"));


/***/ }),
Expand All @@ -35,7 +35,7 @@ module.exports = require("path");
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ function __nccwpck_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(__webpack_module_cache__[moduleId]) {
/******/ return __webpack_module_cache__[moduleId].exports;
Expand All @@ -50,7 +50,7 @@ module.exports = require("path");
/******/ // Execute the module function
/******/ var threw = true;
/******/ try {
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__);
/******/ threw = false;
/******/ } finally {
/******/ if(threw) delete __webpack_module_cache__[moduleId];
Expand All @@ -64,21 +64,21 @@ module.exports = require("path");
/******/ /* webpack/runtime/compat get default export */
/******/ (() => {
/******/ // getDefaultExport function for compatibility with non-harmony modules
/******/ __webpack_require__.n = (module) => {
/******/ __nccwpck_require__.n = (module) => {
/******/ var getter = module && module.__esModule ?
/******/ () => module['default'] :
/******/ () => module;
/******/ __webpack_require__.d(getter, { a: getter });
/******/ __nccwpck_require__.d(getter, { a: getter });
/******/ return getter;
/******/ };
/******/ })();
/******/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = (exports, definition) => {
/******/ __nccwpck_require__.d = (exports, definition) => {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
Expand All @@ -87,13 +87,13 @@ module.exports = require("path");
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/ __webpack_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop)
/******/ __nccwpck_require__.o = (obj, prop) => Object.prototype.hasOwnProperty.call(obj, prop)
/******/ })();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ (() => {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = (exports) => {
/******/ __nccwpck_require__.r = (exports) => {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
Expand All @@ -103,10 +103,10 @@ module.exports = require("path");
/******/
/******/ /* webpack/runtime/compat */
/******/
/******/ __webpack_require__.ab = __dirname + "/";/************************************************************************/
/******/ __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
/******/ // module exports must be returned from runtime so entry inlining is disabled
/******/ // startup
/******/ // Load entry module and return exports
/******/ return __webpack_require__(743);
/******/ return __nccwpck_require__(743);
/******/ })()
;
16 changes: 8 additions & 8 deletions test/unit/bundle-subasset2/output-coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports =
/******/ var __webpack_modules__ = ({

/***/ 448:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {


var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
Expand Down Expand Up @@ -43,10 +43,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
}
};
exports.__esModule = true;
var piscina_1 = __webpack_require__(409);
var path = __webpack_require__(622);
var piscina_1 = __nccwpck_require__(409);
var path = __nccwpck_require__(622);
var piscina = new piscina_1["default"]({
filename: __webpack_require__.ab + "pi-bridge.js"
filename: __nccwpck_require__.ab + "pi-bridge.js"
});
(function () {
return __awaiter(this, void 0, void 0, function () {
Expand Down Expand Up @@ -86,7 +86,7 @@ module.exports = require("piscina");
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ function __nccwpck_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(__webpack_module_cache__[moduleId]) {
/******/ return __webpack_module_cache__[moduleId].exports;
Expand All @@ -101,7 +101,7 @@ module.exports = require("piscina");
/******/ // Execute the module function
/******/ var threw = true;
/******/ try {
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __nccwpck_require__);
/******/ threw = false;
/******/ } finally {
/******/ if(threw) delete __webpack_module_cache__[moduleId];
Expand All @@ -114,10 +114,10 @@ module.exports = require("piscina");
/************************************************************************/
/******/ /* webpack/runtime/compat */
/******/
/******/ __webpack_require__.ab = __dirname + "/";/************************************************************************/
/******/ __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
/******/ // module exports must be returned from runtime so entry inlining is disabled
/******/ // startup
/******/ // Load entry module and return exports
/******/ return __webpack_require__(448);
/******/ return __nccwpck_require__(448);
/******/ })()
;
16 changes: 8 additions & 8 deletions test/unit/bundle-subasset2/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports =
/******/ var __webpack_modules__ = ({

/***/ 886:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {


var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
Expand Down Expand Up @@ -43,10 +43,10 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
}
};
exports.__esModule = true;
var piscina_1 = __webpack_require__(409);
var path = __webpack_require__(622);
var piscina_1 = __nccwpck_require__(409);
var path = __nccwpck_require__(622);
var piscina = new piscina_1["default"]({
filename: __webpack_require__.ab + "pi-bridge.js"
filename: __nccwpck_require__.ab + "pi-bridge.js"
});
(function () {
return __awaiter(this, void 0, void 0, function () {
Expand Down Expand Up @@ -86,7 +86,7 @@ module.exports = require("piscina");
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ function __nccwpck_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(__webpack_module_cache__[moduleId]) {
/******/ return __webpack_module_cache__[moduleId].exports;
Expand All @@ -101,7 +101,7 @@ module.exports = require("piscina");
/******/ // Execute the module function
/******/ var threw = true;
/******/ try {
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __nccwpck_require__);
/******/ threw = false;
/******/ } finally {
/******/ if(threw) delete __webpack_module_cache__[moduleId];
Expand All @@ -114,10 +114,10 @@ module.exports = require("piscina");
/************************************************************************/
/******/ /* webpack/runtime/compat */
/******/
/******/ __webpack_require__.ab = __dirname + "/";/************************************************************************/
/******/ __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
/******/ // module exports must be returned from runtime so entry inlining is disabled
/******/ // startup
/******/ // Load entry module and return exports
/******/ return __webpack_require__(886);
/******/ return __nccwpck_require__(886);
/******/ })()
;
12 changes: 6 additions & 6 deletions test/unit/externals/output-coverage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module.exports =
/******/ var __webpack_modules__ = ({

/***/ 157:
/***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
/***/ ((__unused_webpack_module, __unused_webpack_exports, __nccwpck_require__) => {

const external = __webpack_require__(306);
const external = __nccwpck_require__(306);

console.log(external);

Expand All @@ -26,7 +26,7 @@ module.exports = require("externalmapped");
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ function __nccwpck_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(__webpack_module_cache__[moduleId]) {
/******/ return __webpack_module_cache__[moduleId].exports;
Expand All @@ -41,7 +41,7 @@ module.exports = require("externalmapped");
/******/ // Execute the module function
/******/ var threw = true;
/******/ try {
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__);
/******/ threw = false;
/******/ } finally {
/******/ if(threw) delete __webpack_module_cache__[moduleId];
Expand All @@ -54,10 +54,10 @@ module.exports = require("externalmapped");
/************************************************************************/
/******/ /* webpack/runtime/compat */
/******/
/******/ __webpack_require__.ab = __dirname + "/";/************************************************************************/
/******/ __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
/******/ // module exports must be returned from runtime so entry inlining is disabled
/******/ // startup
/******/ // Load entry module and return exports
/******/ return __webpack_require__(157);
/******/ return __nccwpck_require__(157);
/******/ })()
;
Loading