/
githubmirror
/
webpack
Обзор
Документация
Войти
/
githubmirror
/
webpack
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
test/configCases/externals/node-prefix/index.js
32 строки
1 KB
Alexander Akait
Respect the node: prefix for node.js core modules used as externals (#21286)
26 июн 2026, 18:55
Не верифицирован
26 июн 2026, 18:55
54fa902
Код
Авторство
О чём код?
const fs = require("node:fs"); const path = require("node:path"); const outputPath = __STATS__.children[__STATS_I__].outputPath; const source = fs.readFileSync( path.join(outputPath, `bundle${__STATS_I__}.js`), "utf-8" ); // Built dynamically so the forbidden phrase never appears verbatim in this file, // which is itself embedded into the bundle being inspected. const ext = (name) => `module.exports = require(${JSON.stringify(name)})`; const prefixed = (name) => `${"node"}:${name}`; it("should resolve the node built-ins at runtime regardless of the prefix", () => { expect(typeof fs.readFileSync).toBe("function"); expect(typeof path.join).toBe("function"); }); if (__STATS_I__ === 0) { it("should strip the `node:` prefix when the target lacks support", () => { expect(source).toContain(ext("fs")); expect(source).toContain(ext("path")); expect(source).not.toContain(ext(prefixed("fs"))); expect(source).not.toContain(ext(prefixed("path"))); }); } else { it("should keep the `node:` prefix verbatim when the target supports it", () => { expect(source).toContain(ext(prefixed("fs"))); expect(source).toContain(ext(prefixed("path"))); }); }