Skip to content

Commit cc96c83

Browse files
authored
fix: ensure nested builds of __nccwpck_require__ (#751)
* fix: ensure nested builds of __nccwpck_require__ * fix double nesting
1 parent 37ccb67 commit cc96c83

File tree

7 files changed

+1129
-1
lines changed

7 files changed

+1129
-1
lines changed

src/index.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -546,8 +546,22 @@ function ncc (
546546
// __webpack_require__ can conflict with webpack injections in module scopes
547547
// to avoid this without recomputing the source map we replace it with an
548548
// identical length identifier
549-
if (code.indexOf('"__webpack_require__"') === -1)
549+
if (code.indexOf('"__webpack_require__"') === -1) {
550+
// dedupe any existing __nccwpck_require__ first
551+
if (code.indexOf('__nccwpck_require2_') !== -1) {
552+
// nth level nesting (we support 9 levels apparently)
553+
for (let i = 9; i > 1; i--) {
554+
if (code.indexOf(`__nccwpck_require${i}_`) === -1)
555+
continue;
556+
if (i === 9)
557+
throw new Error('9 levels of ncc build nesting reached, please post an issue to support this level of ncc build composition.');
558+
code = code.replace(new RegExp(`__nccwpck_require${i}_`, 'g'), `__nccwpck_require${i + 1}_`);
559+
}
560+
}
561+
if (code.indexOf('__nccwpck_require__') !== -1)
562+
code = code.replace(/__nccwpck_require__/g, '__nccwpck_require2_');
550563
code = code.replace(/__webpack_require__/g, '__nccwpck_require__');
564+
}
551565

552566
// for each .js / .mjs / .cjs file in the asset list, build that file with ncc itself
553567
if (!noAssetBuilds) {
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
/******/ (() => { // webpackBootstrap
2+
/******/ var __webpack_modules__ = ({
3+
4+
/***/ 332:
5+
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
6+
7+
/******/ (() => { // webpackBootstrap
8+
/******/ "use strict";
9+
/******/ var __webpack_modules__ = ({
10+
11+
/***/ 622:
12+
/***/ ((module) => {
13+
14+
module.exports = __nccwpck_require__(622);
15+
16+
/***/ })
17+
18+
/******/ });
19+
/************************************************************************/
20+
/******/ // The module cache
21+
/******/ var __webpack_module_cache__ = {};
22+
/******/
23+
/******/ // The require function
24+
/******/ function __nccwpck_require2_(moduleId) {
25+
/******/ // Check if module is in cache
26+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
27+
/******/ if (cachedModule !== undefined) {
28+
/******/ return cachedModule.exports;
29+
/******/ }
30+
/******/ // Create a new module (and put it into the cache)
31+
/******/ var module = __webpack_module_cache__[moduleId] = {
32+
/******/ // no module.id needed
33+
/******/ // no module.loaded needed
34+
/******/ exports: {}
35+
/******/ };
36+
/******/
37+
/******/ // Execute the module function
38+
/******/ var threw = true;
39+
/******/ try {
40+
/******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require2_);
41+
/******/ threw = false;
42+
/******/ } finally {
43+
/******/ if(threw) delete __webpack_module_cache__[moduleId];
44+
/******/ }
45+
/******/
46+
/******/ // Return the exports of the module
47+
/******/ return module.exports;
48+
/******/ }
49+
/******/
50+
/************************************************************************/
51+
/******/ /* webpack/runtime/compat get default export */
52+
/******/ (() => {
53+
/******/ // getDefaultExport function for compatibility with non-harmony modules
54+
/******/ __nccwpck_require2_.n = (module) => {
55+
/******/ var getter = module && module.__esModule ?
56+
/******/ () => (module['default']) :
57+
/******/ () => (module);
58+
/******/ __nccwpck_require2_.d(getter, { a: getter });
59+
/******/ return getter;
60+
/******/ };
61+
/******/ })();
62+
/******/
63+
/******/ /* webpack/runtime/define property getters */
64+
/******/ (() => {
65+
/******/ // define getter functions for harmony exports
66+
/******/ __nccwpck_require2_.d = (exports, definition) => {
67+
/******/ for(var key in definition) {
68+
/******/ if(__nccwpck_require2_.o(definition, key) && !__nccwpck_require2_.o(exports, key)) {
69+
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
70+
/******/ }
71+
/******/ }
72+
/******/ };
73+
/******/ })();
74+
/******/
75+
/******/ /* webpack/runtime/hasOwnProperty shorthand */
76+
/******/ (() => {
77+
/******/ __nccwpck_require2_.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
78+
/******/ })();
79+
/******/
80+
/******/ /* webpack/runtime/make namespace object */
81+
/******/ (() => {
82+
/******/ // define __esModule on exports
83+
/******/ __nccwpck_require2_.r = (exports) => {
84+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
85+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
86+
/******/ }
87+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
88+
/******/ };
89+
/******/ })();
90+
/******/
91+
/******/ /* webpack/runtime/compat */
92+
/******/
93+
/******/ if (typeof __nccwpck_require2_ !== 'undefined') __nccwpck_require2_.ab = __dirname + "/";
94+
/******/
95+
/************************************************************************/
96+
var __webpack_exports__ = {};
97+
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
98+
(() => {
99+
__nccwpck_require2_.r(__webpack_exports__);
100+
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require2_(622);
101+
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require2_.n(path__WEBPACK_IMPORTED_MODULE_0__);
102+
103+
104+
const file = __nccwpck_require2_.ab + "pi-bridge.js";
105+
106+
const obscureRequire = eval(`function obscureRequire (file) {
107+
require(file);
108+
}`);
109+
110+
console.log(obscureRequire(__nccwpck_require2_.ab + "pi-bridge.js"));
111+
112+
})();
113+
114+
module.exports = __webpack_exports__;
115+
/******/ })()
116+
;
117+
118+
119+
/***/ }),
120+
121+
/***/ 622:
122+
/***/ ((module) => {
123+
124+
"use strict";
125+
module.exports = require("path");
126+
127+
/***/ })
128+
129+
/******/ });
130+
/************************************************************************/
131+
/******/ // The module cache
132+
/******/ var __webpack_module_cache__ = {};
133+
/******/
134+
/******/ // The require function
135+
/******/ function __nccwpck_require__(moduleId) {
136+
/******/ // Check if module is in cache
137+
/******/ var cachedModule = __webpack_module_cache__[moduleId];
138+
/******/ if (cachedModule !== undefined) {
139+
/******/ return cachedModule.exports;
140+
/******/ }
141+
/******/ // Create a new module (and put it into the cache)
142+
/******/ var module = __webpack_module_cache__[moduleId] = {
143+
/******/ // no module.id needed
144+
/******/ // no module.loaded needed
145+
/******/ exports: {}
146+
/******/ };
147+
/******/
148+
/******/ // Execute the module function
149+
/******/ var threw = true;
150+
/******/ try {
151+
/******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__);
152+
/******/ threw = false;
153+
/******/ } finally {
154+
/******/ if(threw) delete __webpack_module_cache__[moduleId];
155+
/******/ }
156+
/******/
157+
/******/ // Return the exports of the module
158+
/******/ return module.exports;
159+
/******/ }
160+
/******/
161+
/************************************************************************/
162+
/******/ /* webpack/runtime/compat */
163+
/******/
164+
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";
165+
/******/
166+
/************************************************************************/
167+
/******/
168+
/******/ // startup
169+
/******/ // Load entry module and return exports
170+
/******/ // This entry module is referenced by other modules so it can't be inlined
171+
/******/ var __webpack_exports__ = __nccwpck_require__(332);
172+
/******/ module.exports = __webpack_exports__;
173+
/******/
174+
/******/ })()
175+
;

0 commit comments

Comments
 (0)