mirror of
https://github.com/morluto/rea.git
synced 2026-11-19 21:23:45 +00:00
* fix(source-map): share bounded structural inspection with local analysis Refs #12135 * fix(javascript): retain relative URL traversal and decline unusable map paths * fix(javascript): retain source content beyond coordinate admission
88 lines
3.1 KiB
TypeScript
88 lines
3.1 KiB
TypeScript
import { expect } from "vitest";
|
|
|
|
import { createTestTempDirectory } from "../../fixtures/temporaryDirectory.js";
|
|
import { cliTest } from "../../support/cli/cliFixture.js";
|
|
import {
|
|
analyzeJavaScriptDirectory,
|
|
runNodeJsonControl,
|
|
} from "../../support/cli/javascriptApplication.js";
|
|
import { writeFixtureFiles } from "../../support/javascriptApplicationFixture.js";
|
|
|
|
cliTest.for(["CLI", "stdio MCP"] as const)(
|
|
"resolves proven createRequire filenames from their own directory through %s",
|
|
async (surface, { cli }) => {
|
|
const root = await createTestTempDirectory("rea-create-require-base-");
|
|
await writeFixtureFiles(root, {
|
|
"main.mjs": `import { createRequire } from "node:module";
|
|
const nested = createRequire(new URL("./nested/anchor.cjs", import.meta.url));
|
|
const current = createRequire(import.meta.url);
|
|
console.log(JSON.stringify([nested("./dep.cjs"), current("./dep.cjs")]));`,
|
|
"dep.cjs": 'module.exports = "root";',
|
|
"nested/anchor.cjs": "",
|
|
"nested/dep.cjs": 'module.exports = "nested";',
|
|
});
|
|
|
|
expect(await runNodeJsonControl(root, "main.mjs")).toEqual([
|
|
"nested",
|
|
"root",
|
|
]);
|
|
const { graph } = await analyzeJavaScriptDirectory(surface, cli, root);
|
|
const dependencies = graph.edges
|
|
.filter(
|
|
({ relation, properties }) =>
|
|
relation === "imports" &&
|
|
properties.specifier === "./dep.cjs" &&
|
|
properties.kind === "require",
|
|
)
|
|
.map(({ properties }) => ({
|
|
resolution_base_path: properties.resolution_base_path,
|
|
resolved_path: properties.resolved_path,
|
|
}));
|
|
expect(dependencies).toHaveLength(2);
|
|
expect(dependencies).toEqual(
|
|
expect.arrayContaining([
|
|
{
|
|
resolution_base_path: "./nested/anchor.cjs",
|
|
resolved_path: "nested/dep.cjs",
|
|
},
|
|
{ resolution_base_path: null, resolved_path: "dep.cjs" },
|
|
]),
|
|
);
|
|
},
|
|
);
|
|
|
|
cliTest.for(["CLI", "stdio MCP"] as const)(
|
|
"retains a parent in a createRequire filename that re-enters a same-named directory through %s",
|
|
async (surface, { cli }) => {
|
|
const root = await createTestTempDirectory("rea-create-require-parent-");
|
|
await writeFixtureFiles(root, {
|
|
"app/main.mjs": `import { createRequire } from "node:module";
|
|
const sibling = createRequire(new URL("../source/anchor.cjs", import.meta.url));
|
|
console.log(JSON.stringify(sibling("./dep.cjs")));`,
|
|
"app/dep.cjs": 'module.exports = "app";',
|
|
"source/dep.cjs": 'module.exports = "source";',
|
|
});
|
|
|
|
expect(await runNodeJsonControl(root, "app/main.mjs")).toBe("source");
|
|
const { graph } = await analyzeJavaScriptDirectory(surface, cli, root);
|
|
expect(
|
|
graph.edges
|
|
.filter(
|
|
({ relation, properties }) =>
|
|
relation === "imports" &&
|
|
properties.specifier === "./dep.cjs" &&
|
|
properties.kind === "require",
|
|
)
|
|
.map(({ properties }) => ({
|
|
resolution_base_path: properties.resolution_base_path,
|
|
resolved_path: properties.resolved_path,
|
|
})),
|
|
).toEqual([
|
|
{
|
|
resolution_base_path: "../source/anchor.cjs",
|
|
resolved_path: "source/dep.cjs",
|
|
},
|
|
]);
|
|
},
|
|
);
|