webpack test and add empty prototype prop to module (#3421)

This commit is contained in:
Dylan Conway
2023-06-26 19:16:59 -07:00
committed by GitHub
parent 4be15cff02
commit 4e4cae0fc3
6 changed files with 57 additions and 4 deletions

View File

@@ -142,10 +142,10 @@ void generateNodeModuleModule(JSC::JSGlobalObject *globalObject,
exportValues.append(
jsCast<Zig::GlobalObject *>(globalObject)->lazyRequireCacheObject());
exportNames.append(JSC::Identifier::fromString(vm, "builtinModules"_s));
exportNames.append(JSC::Identifier::fromString(vm, "prototype"_s));
exportValues.append(constructEmptyObject(globalObject));
exportNames.append(JSC::Identifier::fromString(vm, "globalPaths"_s));
exportValues.append(JSC::constructEmptyArray(globalObject, 0));
exportNames.append(JSC::Identifier::fromString(vm, "builtinModules"_s));
JSC::JSArray *builtinModules = JSC::JSArray::create(
vm,
@@ -167,5 +167,8 @@ void generateNodeModuleModule(JSC::JSGlobalObject *globalObject,
builtinModules->putDirectIndex(globalObject, 6,
JSC::jsString(vm, String("bun:sqlite"_s)));
exportValues.append(builtinModules);
exportNames.append(JSC::Identifier::fromString(vm, "globalPaths"_s));
exportValues.append(JSC::constructEmptyArray(globalObject, 0));
}
} // namespace Zig

View File

@@ -0,0 +1,7 @@
{
"name": "webpack-test",
"version": "2.0.0",
"dependencies": {
"webpack": "5.88.0"
}
}

11
test/js/third_party/webpack/test.js vendored Normal file
View File

@@ -0,0 +1,11 @@
import { world } from "./world.js";
function component() {
const element = document.createElement("div");
element.innerHTML = "hello " + world();
return element;
}
document.body.appendChild(component());

View File

@@ -0,0 +1,27 @@
import { bunExe, bunEnv } from "harness";
import { existsSync, rmdirSync } from "fs";
import { join } from "path";
afterEach(() => {
rmdirSync(join(import.meta.dir, "dist"), { recursive: true });
});
test("webpack works", () => {
Bun.spawnSync({
cmd: [bunExe(), "-b", "webpack", "--entry", "./test.js", "-o", "./dist/test1/main.js"],
cwd: import.meta.dir,
env: bunEnv,
});
expect(existsSync(join(import.meta.dir, "dist", "test1/main.js"))).toBe(true);
});
test("webpack --watch works", async () => {
Bun.spawnSync({
cmd: ["timeout", "3", bunExe(), "-b", "webpack", "--entry", "./test.js", "-o", "./dist/test2/main.js", "--watch"],
cwd: import.meta.dir,
env: bunEnv,
});
expect(existsSync(join(import.meta.dir, "dist", "test2/main.js"))).toBe(true);
});

3
test/js/third_party/webpack/world.js vendored Normal file
View File

@@ -0,0 +1,3 @@
export function world() {
return "world";
}

View File

@@ -23,7 +23,9 @@
"svelte": "^3.55.1",
"typescript": "^5.0.2",
"undici": "^5.20.0",
"vitest": "^0.32.2"
"vitest": "^0.32.2",
"webpack": "5.88.0",
"webpack-cli": "4.7.2"
},
"private": true,
"scripts": {