Skip to content
This repository has been archived by the owner on Mar 15, 2024. It is now read-only.

Fixes for dog fooding #202

Merged
merged 17 commits into from
Mar 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ rules:
# complexity
# computed-property-spacing: [error, never] >> Prettier
consistent-return: error
consistent-this: [error, self]
consistent-this: [error, that]
# constructor-super: error >> Class are disabled by no-restricted-syntax
curly: [error, all]
# default-case >> SwitchStatement disabled by no-restricted-syntax
Expand Down
1 change: 1 addition & 0 deletions components/.ordering
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ hash
patch
peer
file
load
time
group
prompts
Expand Down
4 changes: 0 additions & 4 deletions components/agent/default/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import {
formatResolvePayload as formatFrontendResolvePayload,
formatRejectPayload as formatFrontendRejectPayload,
formatYieldPayload as formatFrontendYieldPayload,
formatResumePayload as formatFrontendResumePayload,
formatRequestPayload as formatFrontendRequestPayload,
formatResponsePayload as formatFrontendResponsePayload,
formatQueryPayload as formatFrontendQueryPayload,
Expand Down Expand Up @@ -177,9 +176,6 @@ export const formatRejectPayload = generateFormatPayload(
export const formatYieldPayload = generateFormatPayload(
formatFrontendYieldPayload,
);
export const formatResumePayload = generateFormatPayload(
formatFrontendResumePayload,
);
export const formatRequestPayload = generateFormatPayload(
formatFrontendRequestPayload,
);
Expand Down
8 changes: 7 additions & 1 deletion components/classmap/default/module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,13 @@ export const createModule = ({
};

export const lookupModuleClosure = (
{ estree: { filename }, infos, references },
{
estree: {
loc: { filename },
},
infos,
references,
},
position,
) => {
const position_string = stringifyPosition(position);
Expand Down
6 changes: 3 additions & 3 deletions components/command/node/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ export const compileConfigurationCommandAsync = async (configuration, env) => {
const {
"recursive-process-recording": recursive,
recorder,
agent: { directory },
agent: { directory: self },
command: { tokens },
"command-options": options,
} = configuration;
Expand All @@ -125,13 +125,13 @@ export const compileConfigurationCommandAsync = async (configuration, env) => {
(recorder_recursive === null || recorder_recursive === recursive) &&
name === recorder,
);
const [exec, ...argv] = await hookCommandAsync(tokens, directory);
const [exec, ...argv] = await hookCommandAsync(tokens, self, options.cwd);
return {
exec,
argv,
options: {
...options,
env: hookEnvironment(env, directory),
env: hookEnvironment(env, self, options.cwd),
},
};
};
45 changes: 6 additions & 39 deletions components/command/node/jest-config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,54 +3,21 @@ import { createRequire } from "node:module";
import { hasOwnProperty } from "../../util/index.mjs";
import { logError, logDebug } from "../../log/index.mjs";
import { ExternalAppmapError } from "../../error/index.mjs";
import { self_directory } from "../../self/index.mjs";
import {
convertFileUrlToPath,
convertPathToFileUrl,
} from "../../path/index.mjs";
import { getLastUrlExtension, toAbsoluteUrl } from "../../url/index.mjs";
import { loadAsync, isLoadMissingError } from "../../load/index.mjs";
import { convertPathToFileUrl } from "../../path/index.mjs";
import { toAbsoluteUrl } from "../../url/index.mjs";

const {
URL,
JSON: { parse: parseJSON },
} = globalThis;

// The location of require does not matter because it will only load file urls.
const require = createRequire(self_directory);

const loadConfigModuleAsync = async (url) => {
if (getLastUrlExtension(url) === ".mjs") {
return (await import(new URL(url))).default;
} else {
return require(convertFileUrlToPath(url));
}
};

const loadConfigFileAsync = async (url, strict) => {
try {
if (getLastUrlExtension(url) === ".json") {
return parseJSON(await readFileAsync(new URL(url), "utf8"));
} else {
const config = await loadConfigModuleAsync(url);
if (typeof config === "function") {
return await config();
} else {
return config;
}
}
return await loadAsync(url);
} catch (error) {
if (
hasOwnProperty(error, "code") &&
(error.code === "ENOENT" ||
error.code === "ERR_MODULE_NOT_FOUND" ||
error.code === "MODULE_NOT_FOUND")
) {
if (strict) {
logError("Cannot find jest configuration file at %j", url);
throw new ExternalAppmapError("Cannot find jest configuration file");
} else {
return null;
}
if (!strict && isLoadMissingError(error)) {
return null;
} else {
logError(
"Failed to load jest configuration file at %j >> %O",
Expand Down
192 changes: 13 additions & 179 deletions components/command/node/jest-config.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,7 @@ const { URL } = globalThis;
const home = toAbsoluteUrl(`${getUuid()}/`, getTmpUrl());
await mkdirAsync(new URL(home));

//////////////////////
// Explicit >> JSON //
//////////////////////

// Missing //

// Explicit >> Missing //
await assertReject(
loadJestConfigAsync(
{
Expand All @@ -29,38 +24,27 @@ await assertReject(
root: "file:///A:/root/",
},
),
/^ExternalAppmapError: Cannot find jest configuration file$/u,
);

// Invalid //

await writeFileAsync(
new URL("invalid.config.json", home),
"invalid-json",
"utf8",
/^ExternalAppmapError: Failed to load jest configuration file$/u,
);

await assertReject(
loadJestConfigAsync(
{
config: "invalid.config.json",
},
// Implicit >> Missing //
assertDeepEqual(
await loadJestConfigAsync(
{},
{
base: home,
root: "file:///A:/root/",
base: "file:///A:/base/",
root: home,
},
),
/^ExternalAppmapError: Failed to load jest configuration file$/u,
{},
);

// Valid //

// Explicit >> Present //
await writeFileAsync(
new URL("valid.config.json", home),
`{"filename": "valid.config.json"}`,
"utf8",
);

assertDeepEqual(
await loadJestConfigAsync(
{
Expand All @@ -74,167 +58,17 @@ assertDeepEqual(
{ filename: "valid.config.json" },
);

/////////////////////
// Explicit >> CJS //
/////////////////////

// Missing //

await assertReject(
loadJestConfigAsync(
{
config: "missing.config.cjs",
},
{
base: home,
root: "file:///A:/root/",
},
),
/^ExternalAppmapError: Cannot find jest configuration file$/u,
);

// Invalid //

await writeFileAsync(
new URL("invalid.config.cjs", home),
"invalid cjs",
"utf8",
);

await assertReject(
loadJestConfigAsync(
{
config: "invalid.config.cjs",
},
{
base: home,
root: "file:///A:/root/",
},
),
/^ExternalAppmapError: Failed to load jest configuration file$/u,
);

// Valid //

await writeFileAsync(
new URL("valid.config.cjs", home),
`
const { basename } = require("node:path");
module.exports = { filename: basename(__filename) };
`,
"utf8",
);

assertDeepEqual(
await loadJestConfigAsync(
{
config: "valid.config.cjs",
},
{
base: home,
root: "file:///A:/root/",
},
),
{ filename: "valid.config.cjs" },
);

////////////////////
// Explict >> ESM //
////////////////////

// Missing //

await assertReject(
loadJestConfigAsync(
{
config: "missing.config.esm",
},
{
base: home,
root: "file:///A:/root/",
},
),
/^ExternalAppmapError: Cannot find jest configuration file$/u,
);

// Invalid //

await writeFileAsync(
new URL("invalid.config.mjs", home),
"invalid esm",
"utf8",
);

await assertReject(
loadJestConfigAsync(
{
config: "invalid.config.mjs",
},
{
base: home,
root: "file:///A:/root/",
},
),
/^ExternalAppmapError: Failed to load jest configuration file$/u,
);

// Valid //

await writeFileAsync(
new URL("valid.config.mjs", home),
`
import { basename } from "node:path";
import { fileURLToPath } from "node:url";
export default () => ({
filename: basename(fileURLToPath(import.meta.url)),
});
`,
"utf8",
);

assertDeepEqual(
await loadJestConfigAsync(
{
config: "valid.config.mjs",
},
{
base: home,
root: "file:///A:/root/",
},
),
{ filename: "valid.config.mjs" },
);

//////////////
// Implicit //
//////////////

// Missing //

assertDeepEqual(
await loadJestConfigAsync(
{},
{
base: "file:///A:/base/",
root: home,
},
),
{},
);

// Config //

// Implicit >> Present //
await writeFileAsync(
new URL("jest.config.json", home),
`{"filename": "jest.config.json"}`,
"utf8",
);

assertDeepEqual(
await loadJestConfigAsync(
{},
{
base: "file:///A:/base/",
base: "file://A:/base/",
root: home,
},
),
Expand Down Expand Up @@ -281,7 +115,7 @@ assertDeepEqual(

await assertReject(
resolveJestPresetAsync({ preset: "./missing-jest-preset.json" }, home),
/^ExternalAppmapError: Cannot find jest configuration file$/u,
/^ExternalAppmapError: Failed to load jest configuration file$/u,
);

await assertReject(
Expand Down
Loading