|
1 | 1 | "use strict"; |
2 | 2 |
|
| 3 | +const fs = require("node:fs"); |
| 4 | +const os = require("node:os"); |
| 5 | +const path = require("node:path"); |
3 | 6 | const { resolve } = require("node:path"); |
4 | 7 | const { pathToFileURL } = require("node:url"); |
5 | 8 | const { cleanStderr, run } = require("../../../utils/test-utils"); |
@@ -40,6 +43,24 @@ describe("basic config file", () => { |
40 | 43 | expect(stdout).toBeTruthy(); |
41 | 44 | }); |
42 | 45 |
|
| 46 | + it("should load a configuration path as a module specifier and not run it as code", async () => { |
| 47 | + const marker = path.join( |
| 48 | + fs.mkdtempSync(path.join(os.tmpdir(), "webpack-cli-config-path-")), |
| 49 | + "executed", |
| 50 | + ); |
| 51 | + const configPath = `file:///webpack.config.js"),require("node:fs").writeFileSync(${JSON.stringify(marker)},""),import("file:///webpack.config.js`; |
| 52 | + |
| 53 | + try { |
| 54 | + const { exitCode, stderr } = await run(__dirname, ["-c", configPath]); |
| 55 | + |
| 56 | + expect(exitCode).toBe(2); |
| 57 | + expect(stderr).toContain("Failed to load"); |
| 58 | + expect(fs.existsSync(marker)).toBe(false); |
| 59 | + } finally { |
| 60 | + fs.rmSync(path.dirname(marker), { recursive: true, force: true }); |
| 61 | + } |
| 62 | + }); |
| 63 | + |
43 | 64 | it("should build and not throw error with a basic using weird path", async () => { |
44 | 65 | const { exitCode, stderr, stdout } = await run(__dirname, [ |
45 | 66 | "-c", |
|
0 commit comments