Something went wrong. Try again.
Monorepo for the nibling.run platform
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273// Resolver v2 acceptance proofs: package.json exports conditions, legacy main// fallback, package boundary enforcement, and the fs write path.import { test, expect } from "@playwright/test";import { guestLines } from "./guest";
test("bare package resolves through its exports map; legacy main fallback works; fs write round-trips", async ({ page }) => { await page.goto("/demo/index.html"); // 'leftpad' → exports {".": "./index.js"}; 'shouty' → no exports, main lib/loud.js; // writeFileSync('/app/echo.txt') then readFileSync back through the same mailbox. await expect(page.locator("#out")).toContainText(/Hello, .+!/, { timeout: 15_000 }); await expect(page.locator("#out")).toContainText("echo: written by node:fs", { timeout: 15_000 }); await expect(page.locator("#exit")).toHaveText("0", { timeout: 15_000 });});
test("subpath outside the exports map is refused at the package boundary", async ({ page }) => { await page.goto("/demo/not-exported.html"); await expect(page.locator("#err")).toContainText("ERR_PACKAGE_PATH_NOT_EXPORTED", { timeout: 15_000 }); await expect(page.locator("#exit")).toHaveText("1", { timeout: 15_000 });});
test("an exports object of bare conditions is the package's main export", async ({ page }) => { // merge-descriptors 2 (an Express dependency) ships exactly this shape. const lines = await guestLines(page, { "/app/node_modules/sugar/package.json": JSON.stringify({ name: "sugar", exports: { types: "./index.d.ts", default: "./index.js" } }), "/app/node_modules/sugar/index.js": 'module.exports = "sugar main";\n', "/app/node_modules/arr/package.json": JSON.stringify({ name: "arr", exports: [{ require: "./a.cjs" }, "./b.cjs"] }), "/app/node_modules/arr/a.cjs": 'module.exports = "arr a";\n', "/app/main.cjs": 'console.log(require("sugar"), require("arr"));\ntry { require("sugar/index.js"); } catch (e) { console.log(e.code); }\n', }, "/app/main.cjs"); expect(lines).toEqual(["sugar main arr a", "ERR_PACKAGE_PATH_NOT_EXPORTED"]);});
test("nested conditions in an exports target resolve per kind", async ({ page }) => { const pkg = JSON.stringify({ name: "dual", exports: { ".": { import: { types: "./index.d.mts", default: "./index.mjs" }, require: { types: "./index.d.cts", default: "./index.cjs" }, }, }, }); const lines = await guestLines(page, { "/app/node_modules/dual/package.json": pkg, "/app/node_modules/dual/index.mjs": 'export const kind = "esm";\n', "/app/node_modules/dual/index.cjs": 'exports.kind = "cjs";\n', "/app/main.mjs": 'import { kind } from "dual";\nimport { viaRequire } from "./req.cjs";\nconsole.log(kind, viaRequire());\n', "/app/req.cjs": 'exports.viaRequire = () => require("dual").kind;\n', }, "/app/main.mjs"); expect(lines).toEqual(["esm cjs"]);});
test("subpath patterns expand their * and the most specific pattern wins", async ({ page }) => { // hono ships "./utils/*"; the expected line is what Node v24.16 printed for this tree. const pkg = JSON.stringify({ name: "pat", exports: { "./*": "./root/*.js", "./utils/*": { import: "./dist/utils/*.js", require: "./dist/cjs/utils/*.js" }, }, }); const lines = await guestLines(page, { "/app/node_modules/pat/package.json": pkg, "/app/node_modules/pat/dist/utils/package.json": '{"type":"module"}', "/app/node_modules/pat/dist/utils/mime.js": 'export const m = "esm mime";\n', "/app/node_modules/pat/dist/cjs/utils/mime.js": 'exports.m = "cjs mime";\n', "/app/node_modules/pat/root/a/b.js": 'module.exports = "root a/b";\n', "/app/main.mjs": 'import { m } from "pat/utils/mime";\nimport { viaRequire } from "./req.cjs";\nconsole.log(m, viaRequire());\n', "/app/req.cjs": 'exports.viaRequire = () => [require("pat/utils/mime").m, require("pat/a/b")].join(" ");\n', }, "/app/main.mjs"); expect(lines).toEqual(["esm mime cjs mime root a/b"]);});