Skip to content
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
3 changes: 3 additions & 0 deletions src/asset-relocator.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ const staticModules = Object.assign(Object.create(null), {
default: os,
...os
},
'node:path': undefined, // point to the same reference as "path" below
'node-pre-gyp': pregyp,
'node-pre-gyp/lib/pre-binding': pregyp,
'node-pre-gyp/lib/pre-binding.js': pregyp,
Expand All @@ -223,6 +224,8 @@ const staticModules = Object.assign(Object.create(null), {
default: RESOLVE_FROM
}
});
staticModules["node:path"] = staticModules.path;

const globalBindings = {
MONGOOSE_DRIVER_PATH: undefined,
URL: URL
Expand Down
1 change: 1 addition & 0 deletions test/project-chunking/assets/asset4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asset4
1 change: 1 addition & 0 deletions test/project-chunking/assets/asset5.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asset5
1 change: 1 addition & 0 deletions test/project-chunking/assets/asset6.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asset6
8 changes: 8 additions & 0 deletions test/project-chunking/chunk3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const fs = require('node:fs');
const path = require('node:path');
const { resolve } = require('node:path');

console.log(fs.readFileSync(path.join(__dirname, 'assets/asset4.txt')).toString());

console.log(fs.readFileSync(path.resolve(__dirname, 'assets/asset5.txt')).toString());
console.log(fs.readFileSync(resolve(__dirname, 'assets/asset6.txt')).toString());
3 changes: 2 additions & 1 deletion test/project-chunking/expected.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@

const fs = require('fs');

expect([16, 17]).toContain(output.length);
expect([26, 27]).toContain(output.length);

// check relative asset references worked out
expect(fs.readFileSync(__dirname + "/dist/modules/main.js").toString()).toContain(`ab+"asset`);
expect(fs.readFileSync(__dirname + "/dist/modules/chunk.js").toString()).toContain(`ab+"asset`);
expect(fs.readFileSync(__dirname + "/dist/modules/chunks/758.js").toString()).toContain(`ab+"asset`);
expect(fs.readFileSync(__dirname + "/dist/modules/chunks/151.js").toString()).toContain(`ab+"asset`);
4 changes: 2 additions & 2 deletions test/project-chunking/main.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const fs = require('fs');
console.log('Main file');
console.log(fs.readFileSync(__dirname + '/asset1/asset.txt').toString());
require.ensure('./chunk2', function () {

});
require.ensure('./chunk2', function () {});
require.ensure('./chunk3', function () {});
1 change: 1 addition & 0 deletions test/project-chunking/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = {
chunk: './chunk.js'
},
output: {
clean: true,
filename: 'modules/[name].js',
chunkFilename: 'modules/chunks/[name].js',
path: __dirname + '/dist'
Expand Down
1 change: 1 addition & 0 deletions test/unit/path-resolve-prefixed/asset1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asset1
1 change: 1 addition & 0 deletions test/unit/path-resolve-prefixed/asset2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asset2
8 changes: 8 additions & 0 deletions test/unit/path-resolve-prefixed/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const path = require("node:path");
const { resolve } = require("node:path");

fs.createReadStream(path.resolve(__dirname, "asset1.txt"));
fs.readFileSync(resolve(__dirname, "asset2.txt"));

fs.createReadStream(path.resolve(__dirname + "/asset1.txt"));
fs.readFileSync(resolve(__dirname + "/asset2.txt"));
59 changes: 59 additions & 0 deletions test/unit/path-resolve-prefixed/output-coverage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({

/***/ 411:
/***/ ((module) => {

"use strict";
module.exports = require("node:path");

/***/ })

/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/asset-relocator-loader */
/******/ if (typeof __webpack_require__ !== 'undefined') __webpack_require__.ab = __dirname + "/";
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
const path = __webpack_require__(411);
const { resolve } = __webpack_require__(411);

fs.createReadStream(__webpack_require__.ab + "asset1.txt");
fs.readFileSync(__webpack_require__.ab + "asset2.txt");

fs.createReadStream(__webpack_require__.ab + "asset1.txt");
fs.readFileSync(__webpack_require__.ab + "asset2.txt");

})();

module.exports = __webpack_exports__;
/******/ })()
;
59 changes: 59 additions & 0 deletions test/unit/path-resolve-prefixed/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({

/***/ 411:
/***/ ((module) => {

"use strict";
module.exports = require("node:path");

/***/ })

/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/asset-relocator-loader */
/******/ if (typeof __webpack_require__ !== 'undefined') __webpack_require__.ab = __dirname + "/";
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
const path = __webpack_require__(411);
const { resolve } = __webpack_require__(411);

fs.createReadStream(__webpack_require__.ab + "asset1.txt");
fs.readFileSync(__webpack_require__.ab + "asset2.txt");

fs.createReadStream(__webpack_require__.ab + "asset1.txt");
fs.readFileSync(__webpack_require__.ab + "asset2.txt");

})();

module.exports = __webpack_exports__;
/******/ })()
;
1 change: 1 addition & 0 deletions test/unit/path-resolve/asset1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asset1
1 change: 1 addition & 0 deletions test/unit/path-resolve/asset2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
asset2
8 changes: 8 additions & 0 deletions test/unit/path-resolve/input.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const path = require("path");
const { resolve } = require("path");

fs.createReadStream(path.resolve(__dirname, "asset1.txt"));
fs.readFileSync(resolve(__dirname, "asset2.txt"));

fs.createReadStream(path.resolve(__dirname + "/asset1.txt"));
fs.readFileSync(resolve(__dirname + "/asset2.txt"));
59 changes: 59 additions & 0 deletions test/unit/path-resolve/output-coverage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({

/***/ 17:
/***/ ((module) => {

"use strict";
module.exports = require("path");

/***/ })

/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/asset-relocator-loader */
/******/ if (typeof __webpack_require__ !== 'undefined') __webpack_require__.ab = __dirname + "/";
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
const path = __webpack_require__(17);
const { resolve } = __webpack_require__(17);

fs.createReadStream(__webpack_require__.ab + "asset1.txt");
fs.readFileSync(__webpack_require__.ab + "asset2.txt");

fs.createReadStream(__webpack_require__.ab + "asset1.txt");
fs.readFileSync(__webpack_require__.ab + "asset2.txt");

})();

module.exports = __webpack_exports__;
/******/ })()
;
59 changes: 59 additions & 0 deletions test/unit/path-resolve/output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/******/ (() => { // webpackBootstrap
/******/ var __webpack_modules__ = ({

/***/ 17:
/***/ ((module) => {

"use strict";
module.exports = require("path");

/***/ })

/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/asset-relocator-loader */
/******/ if (typeof __webpack_require__ !== 'undefined') __webpack_require__.ab = __dirname + "/";
/******/
/************************************************************************/
var __webpack_exports__ = {};
// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk.
(() => {
const path = __webpack_require__(17);
const { resolve } = __webpack_require__(17);

fs.createReadStream(__webpack_require__.ab + "asset1.txt");
fs.readFileSync(__webpack_require__.ab + "asset2.txt");

fs.createReadStream(__webpack_require__.ab + "asset1.txt");
fs.readFileSync(__webpack_require__.ab + "asset2.txt");

})();

module.exports = __webpack_exports__;
/******/ })()
;