Skip to content

Commit 3031567

Browse files
mark-wiemerCopilot
andauthored
fix: add package.json exports to avoid DEP0151 warning (#6168)
* fix: add package.json exports to avoid DEP0151 warning Add an explicit exports map so Node stops falling back to deprecated default index lookups for ESM package resolution. Keep the wildcard subpath export to preserve existing deep imports and browser bundle accessibility. Fixes: #6147 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * format --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
1 parent 7450ed4 commit 3031567

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@
3131
"homepage": "https://mochajs.org/",
3232
"logo": "https://cldup.com/S9uQ-cOLYz.svg",
3333
"notifyLogo": "https://ibin.co/4QuRuGjXvl36.png",
34+
"exports": {
35+
".": "./index.js",
36+
"./*": "./*"
37+
},
3438
"bin": {
3539
"mocha": "./bin/mocha.js"
3640
},
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
"use strict";
2+
3+
const fs = require("node:fs");
4+
const os = require("node:os");
5+
const path = require("node:path");
6+
const { invokeNode } = require("./helpers.cjs");
7+
8+
describe("package entrypoint", function () {
9+
it("should resolve the package root without DEP0151 warnings", async function () {
10+
const repoRoot = path.resolve(__dirname, "..", "..");
11+
const tempDir = fs.mkdtempSync(
12+
path.join(os.tmpdir(), "mocha-package-root-"),
13+
);
14+
const packageDir = path.join(tempDir, "node_modules", "mocha");
15+
16+
fs.mkdirSync(path.dirname(packageDir), { recursive: true });
17+
18+
try {
19+
if (process.platform === "win32") {
20+
fs.symlinkSync(repoRoot, packageDir, "junction");
21+
} else {
22+
fs.symlinkSync(repoRoot, packageDir);
23+
}
24+
25+
const result = await new Promise((resolve, reject) => {
26+
invokeNode(
27+
[
28+
"--input-type=module",
29+
"-e",
30+
"import {describe, it} from 'mocha'; console.log(typeof describe, typeof it);",
31+
],
32+
(err, res) => {
33+
if (err) {
34+
reject(err);
35+
return;
36+
}
37+
resolve(res);
38+
},
39+
{ cwd: tempDir, stdio: ["ignore", "pipe", "pipe"] },
40+
);
41+
});
42+
43+
expect(result.code, "to be", 0);
44+
expect(result.output, "to contain", "function function");
45+
expect(result.output, "not to contain", "DEP0151");
46+
} finally {
47+
fs.rmSync(tempDir, { recursive: true, force: true });
48+
}
49+
});
50+
});

0 commit comments

Comments
 (0)