mirror of https://github.com/webpack/webpack.git
fix: handle function exports in webpack module wrapper (#19609)
This commit is contained in:
parent
574a88736d
commit
0af28df145
|
@ -49,7 +49,7 @@ class CreateFakeNamespaceObjectRuntimeModule extends HelperRuntimeModule {
|
|||
`${RuntimeGlobals.makeNamespaceObject}(ns);`,
|
||||
"var def = {};",
|
||||
"leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)];",
|
||||
"for(var current = mode & 2 && value; typeof current == 'object' && !~leafPrototypes.indexOf(current); current = getProto(current)) {",
|
||||
"for(var current = mode & 2 && value; (typeof current == 'object' || typeof current == 'function') && !~leafPrototypes.indexOf(current); current = getProto(current)) {",
|
||||
Template.indent([
|
||||
`Object.getOwnPropertyNames(current).forEach(${runtimeTemplate.expressionFunction(
|
||||
`def[key] = ${runtimeTemplate.returningFunction("value[key]", "")}`,
|
||||
|
|
|
@ -190,10 +190,10 @@ describe("Stats", () => {
|
|||
"assets": Array [
|
||||
Object {
|
||||
"name": "entryB.js",
|
||||
"size": 3081,
|
||||
"size": 3105,
|
||||
},
|
||||
],
|
||||
"assetsSize": 3081,
|
||||
"assetsSize": 3105,
|
||||
"auxiliaryAssets": undefined,
|
||||
"auxiliaryAssetsSize": 0,
|
||||
"childAssets": undefined,
|
||||
|
@ -238,10 +238,10 @@ describe("Stats", () => {
|
|||
"info": Object {
|
||||
"javascriptModule": false,
|
||||
"minimized": true,
|
||||
"size": 3081,
|
||||
"size": 3105,
|
||||
},
|
||||
"name": "entryB.js",
|
||||
"size": 3081,
|
||||
"size": 3105,
|
||||
"type": "asset",
|
||||
},
|
||||
Object {
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
it("Should work with export a function", function(done) {
|
||||
const myModule = require("module");
|
||||
expect(typeof myModule).toBe("function");
|
||||
expect(myModule.builtinModules).toBeDefined();
|
||||
done()
|
||||
});
|
||||
|
||||
it("should work with export a object", function(done) {
|
||||
const myFs = require("fs");
|
||||
expect(typeof myFs).toBe("object");
|
||||
expect(myFs.readFileSync).toBeDefined();
|
||||
done()
|
||||
});
|
|
@ -0,0 +1,7 @@
|
|||
/** @type {import("../../../../types").Configuration} */
|
||||
module.exports = {
|
||||
externals: {
|
||||
module: "commonjs module",
|
||||
fs: "commonjs fs"
|
||||
}
|
||||
};
|
|
@ -0,0 +1 @@
|
|||
export const foo = 'foo'
|
|
@ -0,0 +1,17 @@
|
|||
import { foo } from "./foo.mjs"
|
||||
|
||||
it("Should work with export a function when using CreateFakeNamespaceObjectRuntimeModule", async function(done) {
|
||||
expect(foo).toBe("foo")
|
||||
const myModule = await import("module");
|
||||
// namespace object
|
||||
expect(typeof myModule).toBe("object");
|
||||
expect(myModule.builtinModules).toBeDefined();
|
||||
done()
|
||||
});
|
||||
|
||||
it("Should work with export a object when using CreateFakeNamespaceObjectRuntimeModule", async function(done) {
|
||||
const myFs = await import("fs");
|
||||
expect(typeof myFs).toBe("object");
|
||||
expect(myFs.readFileSync).toBeDefined();
|
||||
done()
|
||||
});
|
|
@ -0,0 +1,7 @@
|
|||
/** @type {import("../../../../types").Configuration} */
|
||||
module.exports = {
|
||||
externals: {
|
||||
module: "commonjs module",
|
||||
fs: "commonjs fs"
|
||||
}
|
||||
};
|
Loading…
Reference in New Issue