Skip to content
Open
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
53 changes: 29 additions & 24 deletions js/eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,30 +82,6 @@ export default [
"@typescript-eslint/no-empty-object-type": "error",
"@typescript-eslint/no-unsafe-function-type": "error",
"@typescript-eslint/prefer-as-const": "error",
// Require node: protocol for Node.js built-in imports (for Deno compatibility)
// This plugin automatically detects ALL Node.js built-ins - no manual list needed!
"node-import/prefer-node-protocol": "error",
},
},
{
files: ["src/**/*.ts", "src/**/*.tsx"],
ignores: [
"src/cli/**",
"src/debug-logger.ts",
"src/framework.ts",
"src/framework2.ts",
"src/isomorph.ts",
"src/sandbox.ts",
"src/template/**",
"src/reporters/**",
"src/prompt-cache/**",
"src/eval-parameters.ts",
"src/wrappers/**",
"src/instrumentation/**",
"src/auto-instrumentations/**",
"src/queue.bench.ts",
],
rules: {
"no-restricted-properties": [
"error",
{
Expand Down Expand Up @@ -139,6 +115,35 @@ export default [
message: "Use debugLogger instead of console for SDK logging.",
},
],
// Require node: protocol for Node.js built-in imports (for Deno compatibility)
// This plugin automatically detects ALL Node.js built-ins - no manual list needed!
"node-import/prefer-node-protocol": "error",
},
},
{
files: ["src/queue.bench.ts"],
rules: {
"no-restricted-properties": "off",
},
},
{
files: ["src/**/*.ts", "src/**/*.tsx"],
ignores: [
"src/cli/**",
"src/debug-logger.ts",
"src/framework.ts",
"src/framework2.ts",
"src/isomorph.ts",
"src/sandbox.ts",
"src/template/**",
"src/reporters/**",
"src/prompt-cache/**",
"src/eval-parameters.ts",
"src/wrappers/**",
"src/instrumentation/**",
"src/auto-instrumentations/**",
],
rules: {
"no-restricted-imports": [
"error",
{
Expand Down
4 changes: 4 additions & 0 deletions js/src/cli/functions/infer-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export async function findCodeDefinition({
if (location.type === "experiment" || location.type === "sandbox") {
const evaluator = outFileModule.evaluators[location.eval_name]?.evaluator;
if (!evaluator) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.warn(
warning(
`Warning: failed to find evaluator for ${location.eval_name}. Will not display preview.`,
Expand All @@ -94,6 +95,7 @@ export async function findCodeDefinition({
}

if (!fn) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.warn(
warning(
`Warning: failed to find ${locationToString(location)}. Will not display preview.`,
Expand All @@ -118,6 +120,7 @@ export async function findCodeDefinition({
}

if (columnNumber === -1) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.warn(
warning(
`Warning: failed to find code definition for ${fn.name}. Will not display preview.`,
Expand Down Expand Up @@ -195,6 +198,7 @@ async function getTsModule() {
try {
tsModule = require("typescript");
} catch {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.warn(
warning(
"Failed to load TypeScript module. Will not use TypeScript to derive preview.",
Expand Down
6 changes: 6 additions & 0 deletions js/src/cli/functions/upload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ export async function uploadHandleBundles({
setCurrent: boolean;
defaultIfExists: IfExists;
}) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.error(
`Processing ${buildResults.length} ${pluralize("file", buildResults.length)}...`,
);
Expand Down Expand Up @@ -276,6 +277,7 @@ export async function uploadHandleBundles({
const numUploaded = uploadResults.length;
const numFailed = uploadResults.filter((result) => !result).length;

// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.error(
`${numUploaded} ${pluralize("file", numUploaded)} uploaded ${
numFailed > 0
Expand Down Expand Up @@ -344,12 +346,14 @@ async function uploadBundles({
);
} catch (e) {
if (showDetailedErrors) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.error(e);
}
const msg =
e instanceof FailedHTTPResponse
? `Unable to upload your code. ${e.status} (${e.text}): ${e.data}`
: `Unable to upload your code. You most likely need to update the API: ${e}`;
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.error(warning(msg));
return false;
}
Expand Down Expand Up @@ -422,12 +426,14 @@ async function uploadBundles({
});
} catch (e) {
if (showDetailedErrors) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.error(e);
}
const msg =
e instanceof FailedHTTPResponse
? `Failed to save function definitions for '${sourceFile}'. ${e.status} (${e.text}): ${e.data}`
: `Failed to save function definitions for '${sourceFile}'. You most likely need to update the API: ${e}`;
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.warn(warning(msg));
return false;
}
Expand Down
21 changes: 21 additions & 0 deletions js/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ async function initExperiment(
fallback: (_text: string, url: string) => url,
})
: "locally";
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.error(
chalk.cyan("▶") +
` Experiment ${chalk.bold(info.experimentName)} is running at ${linkText}`,
Expand Down Expand Up @@ -219,13 +220,17 @@ function buildWatchPluginForEvaluator(
name: "run-evalutator-on-end",
setup(build: esbuild.PluginBuild) {
build.onEnd(async (result) => {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.error(`Done building ${inFile}`);

if (!result.outputFiles) {
if (opts.showDetailedErrors) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.warn(`Failed to compile ${inFile}`);
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.warn(result.errors);
} else {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.warn(`Failed to compile ${inFile}: ${result.errors}`);
}
return;
Expand Down Expand Up @@ -306,6 +311,7 @@ function buildWatchPluginForEvaluator(
)) {
const success = await reporter.reportRun(await Promise.all(results));
if (!success) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.error(error(`Reporter ${reporterName} failed.`));
}
}
Expand Down Expand Up @@ -421,9 +427,12 @@ export function handleBuildFailure({
if (terminateOnFailure) {
throw result.error;
} else if (showDetailedErrors) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.warn(`Failed to compile ${result.sourceFile}`);
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.warn(result.error);
} else {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.warn(
`Failed to compile ${result.sourceFile}: ${result.error.message}`,
);
Expand Down Expand Up @@ -466,6 +475,7 @@ function updateEvaluators(
evaluators.reporters[reporterName] &&
evaluators.reporters[reporterName] !== reporter
) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.warn(
warning(
`Reporter '${reporterName}' already exists. Will skip '${reporterName}' from ${result.sourceFile}.`,
Expand All @@ -486,12 +496,14 @@ async function runAndWatch({
onExit?: () => void;
}) {
const count = Object.keys(handles).length;
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.error(`Watching ${pluralize("file", count, true)}...`);

Object.values(handles).map((handle) => handle.watch());

["SIGINT", "SIGTERM"].forEach((signal: string) => {
process.on(signal, function () {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.error("Stopped watching.");
for (const handle of Object.values(handles)) {
handle.destroy();
Expand Down Expand Up @@ -540,6 +552,7 @@ async function runOnce(

if (opts.list) {
for (const evaluator of evaluators.evaluators) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.log(evaluator.evaluator.evalName);
}
return true;
Expand Down Expand Up @@ -581,13 +594,15 @@ async function runOnce(
}
});

// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.error(
chalk.dim(
`Processing ${chalk.bold(resultPromises.length)} evaluator${resultPromises.length === 1 ? "" : "s"}...`,
),
);
const allEvalsResults = await Promise.all(resultPromises);
opts.progressReporter.stop();
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.error("");

const evalReports: Record<
Expand Down Expand Up @@ -685,6 +700,7 @@ async function collectFiles(
try {
pathStat = fs.lstatSync(inputPath);
} catch (e) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.error(error(`Error reading ${inputPath}: ${e}`));
process.exit(1);
}
Expand All @@ -699,6 +715,7 @@ async function collectFiles(
)
) {
const prefix = mode === "eval" ? ".eval" : "";
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.warn(
warning(
`Reading ${inputPath} because it was specified directly. Rename it to end in ${prefix}.ts or ` +
Expand Down Expand Up @@ -848,6 +865,7 @@ export async function initializeHandles({
for (const inputPath of inputPaths) {
const newFiles = await collectFiles(inputPath, mode);
if (newFiles.length == 0) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.warn(
warning(
`Provided path ${inputPath} is not an eval file or a directory containing eval files, skipping...`,
Expand All @@ -860,6 +878,7 @@ export async function initializeHandles({
}

if (Object.keys(files).length == 0) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.warn(
warning("No eval files were found in any of the provided paths."),
);
Expand Down Expand Up @@ -906,6 +925,7 @@ async function run(args: RunArgs) {
// Load via dotenv library
const loaded = dotenv.config({ path: args.env_file });
if (loaded.error) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.error(error(`Error loading ${args.env_file}: ${loaded.error}`));
process.exit(1);
}
Expand All @@ -930,6 +950,7 @@ async function run(args: RunArgs) {
};

if (args.list && args.watch) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.error(error("Cannot specify both --list and --watch."));
process.exit(1);
}
Expand Down
2 changes: 2 additions & 0 deletions js/src/cli/reporters/eval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ export const fancyReporter: ReporterDef<boolean> = {
);

if (failingResults.length > 0) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.error(
warning(
`Evaluator ${evaluator.evalName} failed with ${pluralize("error", failingResults.length, true)}. This evaluation ("${evaluator.evalName}") will not be fully logged.`,
Expand All @@ -186,6 +187,7 @@ export const fancyReporter: ReporterDef<boolean> = {
}
} else if (verbose) {
for (const result of failingResults) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.error(result);
}
}
Expand Down
1 change: 1 addition & 0 deletions js/src/cli/util/bundle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export async function loadCLIEnv(args: AuthArgs & CommonArgs) {
// Load via dotenv library
const loaded = dotenv.config({ path: args.env_file });
if (loaded.error) {
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.error(error(`Error loading ${args.env_file}: ${loaded.error}`));
process.exit(1);
}
Expand Down
1 change: 1 addition & 0 deletions js/src/cli/util/debug-logging.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function normalizeDebugLoggingArgs<

if (!hasWarnedAboutVerboseFlag) {
hasWarnedAboutVerboseFlag = true;
// eslint-disable-next-line no-restricted-properties -- preserving intentional console usage.
console.warn(warning(VERBOSE_DEPRECATION_MESSAGE));
}

Expand Down
Loading
Loading