Skip to content

Commit

Permalink
feat!: support eslint-remote-tester@4
Browse files Browse the repository at this point in the history
  • Loading branch information
AriPerkkio committed Jun 2, 2024
1 parent 0ce936c commit ae5892e
Show file tree
Hide file tree
Showing 23 changed files with 1,178 additions and 4,266 deletions.
80 changes: 36 additions & 44 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ var __commonJS = (callback, module2) => () => {
}
return module2.exports;
};
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, {get: all[name], enumerable: true});
};
var __exportStar = (target, module2, desc) => {
if (module2 && typeof module2 === "object" || typeof module2 === "function") {
for (let key of __getOwnPropNames(module2))
Expand Down Expand Up @@ -25521,13 +25517,9 @@ var require_compare = __commonJS((exports2, module2) => {
module2.exports = compare;
});

// src/index.ts
__markAsModule(exports);
__export(exports, {
__handleForTests: () => __handleForTests
});
var import_fs2 = __toModule(require("fs"));
var import_path3 = __toModule(require("path"));
// src/run-action.ts
var import_fs = __toModule(require("fs"));
var import_path2 = __toModule(require("path"));
var core3 = __toModule(require_core());

// src/github-client.ts
Expand Down Expand Up @@ -25607,8 +25599,8 @@ async function sleep(timeMs) {
var github_client_default = new GithubClient();

// src/run-tester.ts
var import_fs = __toModule(require("fs"));
var import_path2 = __toModule(require("path"));
var import_node_fs = __toModule(require("node:fs"));
var import_node_path = __toModule(require("node:path"));
var import_exec = __toModule(require_exec());

// src/peer-dependencies.ts
Expand All @@ -25617,27 +25609,28 @@ var import_compare = __toModule(require_compare());
var core2 = __toModule(require_core());
var DEPENDENCY_TO_INFO = {
"eslint-remote-tester": {
minVersion: "2.1.1",
minVersion: "3.0.0",
exportPath: "eslint-remote-tester/dist/exports-for-compare-action",
packageJsonPath: "eslint-remote-tester/package.json",
bin: "eslint-remote-tester"
}
};
var PATH_PREFIX = "./node_modules/";
var ESLINT_REMOTE_TESTER_BIN = PATH_PREFIX + ".bin/" + DEPENDENCY_TO_INFO["eslint-remote-tester"].bin;
function requirePeerDependency(dependency) {
async function importPeerDependency(dependency) {
const {minVersion, exportPath, packageJsonPath} = DEPENDENCY_TO_INFO[dependency];
let packageJson;
try {
packageJson = require(import_path.default.resolve(PATH_PREFIX + packageJsonPath));
} catch (e) {
throw new Error(`Unable to require ${packageJsonPath}`);
packageJson = await Promise.resolve().then(() => __toModule(require(import_path.default.resolve(PATH_PREFIX + packageJsonPath))));
} catch (error2) {
core2.error(`Unable to import ${packageJsonPath}`);
throw error2;
}
if ((0, import_compare.default)(packageJson.version, minVersion) === -1) {
throw new Error(`Peer dependency ${dependency} must be ${minVersion} or above. Found version ${packageJson.version}.`);
}
try {
return require(import_path.default.resolve(PATH_PREFIX + exportPath));
return await Promise.resolve().then(() => __toModule(require(import_path.default.resolve(PATH_PREFIX + exportPath))));
} catch (e) {
core2.error(`Unable to require peerDependency ${dependency}`);
throw e;
Expand Down Expand Up @@ -25665,12 +25658,12 @@ var CONFIGURATION_TEMPLATE_BASE = `
}
`;
var CONFIGURATION_TEMPLATE_JS = (pathToUsersConfiguration) => `// Generated by eslint-remote-tester-run-action
const fs = require('fs');
import * as fs from 'node:fs';

// Load user's eslint-remote-tester.config.js
const usersConfig = require('${pathToUsersConfiguration}');
import usersConfig from '${pathToUsersConfiguration}';

module.exports = {
export default {
...usersConfig,
${CONFIGURATION_TEMPLATE_BASE}
};
Expand All @@ -25690,24 +25683,19 @@ const config: Config = {
export default config;
`;
async function runTester(configLocation) {
const usersConfigLocation = import_path2.default.resolve(configLocation);
if (!import_fs.default.existsSync(ESLINT_REMOTE_TESTER_BIN)) {
throw new Error(`Missing eslint-remote-tester. Expected it to be available at ${import_path2.default.resolve(ESLINT_REMOTE_TESTER_BIN)}`);
const usersConfigLocation = import_node_path.default.resolve(configLocation);
if (!import_node_fs.default.existsSync(ESLINT_REMOTE_TESTER_BIN)) {
throw new Error(`Missing eslint-remote-tester. Expected it to be available at ${import_node_path.default.resolve(ESLINT_REMOTE_TESTER_BIN)}`);
}
if (!import_fs.default.existsSync(usersConfigLocation)) {
if (!import_node_fs.default.existsSync(usersConfigLocation)) {
throw new Error(`Unable to find eslint-remote-tester config with path ${usersConfigLocation}`);
}
const extension = usersConfigLocation.split(".").pop();
const configTemplate = extension === "ts" ? CONFIGURATION_TEMPLATE_TS : CONFIGURATION_TEMPLATE_JS;
const createdConfig = `${INTERNAL_CONFIG}.${extension}`;
import_fs.default.writeFileSync(createdConfig, configTemplate(usersConfigLocation));
const {loadConfig, validateConfig} = requirePeerDependency("eslint-remote-tester");
let config;
try {
config = loadConfig(import_path2.default.resolve(createdConfig));
} catch (e) {
throw e;
}
import_node_fs.default.writeFileSync(createdConfig, configTemplate(usersConfigLocation));
const {loadConfig, validateConfig} = await importPeerDependency("eslint-remote-tester");
const config = await loadConfig(import_node_path.default.resolve(createdConfig));
await validateConfig(config, false);
await (0, import_exec.exec)(`${ESLINT_REMOTE_TESTER_BIN} --config ${createdConfig}`, [], {
ignoreReturnCode: true,
Expand All @@ -25719,7 +25707,8 @@ async function runTester(configLocation) {
var RESULTS_MAX_LENGH = 62e3;
var filterUniqueTruthy = (item, index, array) => item != null && array.indexOf(item) === index;
var formatRule = (rule) => "\n- `" + rule + "`";
var ERROR_TEMPLATE = (error2) => `Something went wrong. This is likely an internal error of \`eslint-remote-tester-run-action\`.
function createError(error2) {
return `Something went wrong. This is likely an internal error of \`eslint-remote-tester-run-action\`.

<details>
<summary>Click to expand</summary>
Expand All @@ -25730,8 +25719,9 @@ ${error2.stack}

</details>
`;
var COMMENT_TEMPLATE = (results, repositoryCount, maxResultCount) => {
const {RESULT_PARSER_TO_COMPARE_TEMPLATE} = requirePeerDependency("eslint-remote-tester");
}
async function createComment(results, repositoryCount, maxResultCount) {
const {RESULT_PARSER_TO_COMPARE_TEMPLATE} = await importPeerDependency("eslint-remote-tester");
const template = RESULT_PARSER_TO_COMPARE_TEMPLATE.markdown.results;
const limitReached = results.length > maxResultCount;
const limitedResults = results.slice(0, maxResultCount);
Expand All @@ -25750,27 +25740,27 @@ Rules:${rules.filter(Boolean).map(formatRule).join("")}
${limitedResults.map(template).join("\n").slice(0, RESULTS_MAX_LENGH)}
</details>
`;
};
}

// src/index.ts
// src/run-action.ts
async function run() {
try {
const eslintRemoteTesterConfig = core3.getInput("eslint-remote-tester-config", {required: true});
const maxResultCount = core3.getInput("max-result-count");
const workingDirectory = core3.getInput("working-directory");
if (workingDirectory) {
process.chdir(import_path3.default.join(process.cwd(), workingDirectory));
process.chdir(import_path2.default.join(process.cwd(), workingDirectory));
}
await core3.group("Running eslint-remote-tester", () => runTester(eslintRemoteTesterConfig));
const resultCount = await core3.group("Posting results", async () => {
const testResults = JSON.parse(import_fs2.default.readFileSync(RESULTS_TMP, "utf8"));
const testResults = JSON.parse(import_fs.default.readFileSync(RESULTS_TMP, "utf8"));
core3.info(`Scanned ${testResults.repositoryCount} repositories`);
const results = testResults.results || [];
if (results.length === 0) {
core3.info("Skipping result posting due to 0 results");
return results.length;
}
const resultsComment = COMMENT_TEMPLATE(results, testResults.repositoryCount, parseInt(maxResultCount));
const resultsComment = await createComment(results, testResults.repositoryCount, parseInt(maxResultCount));
await github_client_default.postResults(resultsComment);
return results.length;
});
Expand All @@ -25779,7 +25769,9 @@ async function run() {
}
} catch (error2) {
core3.setFailed(error2.message);
await github_client_default.postResults(ERROR_TEMPLATE(error2));
await github_client_default.postResults(createError(error2));
}
}
var __handleForTests = run();

// src/index.ts
run();
6 changes: 4 additions & 2 deletions esbuild.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const { build } = require('esbuild');
import esbuild from 'esbuild';

/** @type {import('esbuild/lib/main').BuildOptions} */
const options = {
Expand All @@ -14,13 +14,15 @@ const options = {
'node:stream',
'node:util',
'node:events',
'node:fs',
'node:path',
],
platform: 'node',
outdir: 'dist',
outbase: 'src',
};

build(options).catch(err => {
esbuild.build(options).catch(err => {
process.stderr.write(err.stderr);
process.exit(1);
});
7 changes: 0 additions & 7 deletions jest.config.js

This file was deleted.

12 changes: 5 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.1",
"description": "GitHub Action for running eslint-remote-tester",
"main": "dist/index.js",
"type": "module",
"repository": "https://github.com/AriPerkkio/eslint-remote-tester-run-action",
"homepage": "https://github.com/AriPerkkio/eslint-remote-tester-run-action",
"bugs": "https://github.com/AriPerkkio/eslint-remote-tester-run-action",
Expand All @@ -14,33 +15,30 @@
"build": "node esbuild.config.js",
"lint": "eslint --max-warnings=0",
"typecheck": "tsc --noEmit",
"test": "jest"
"test": "vitest"
},
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/exec": "^1.0.4",
"@actions/github": "^4.0.0",
"eslint-remote-tester": "^2.1.1",
"eslint-remote-tester": "https://pkg.pr.new/eslint-remote-tester@92f4e8a",
"semver": "^7.3.4"
},
"devDependencies": {
"@commitlint/cli": "^11.0.0",
"@commitlint/config-conventional": "^11.0.0",
"@eslint/js": "^9.4.0",
"@types/eslint": "^8.56.10",
"@types/jest": "^26.0.20",
"@types/node": "^14.14.21",
"@types/semver": "^7.3.4",
"esbuild": "^0.8.33",
"eslint": "^9.4.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-prettier": "^5.1.3",
"jest": "24",
"msw": "^0.26.0",
"prettier": "^3.2.5",
"ts-jest": "24",
"ts-node": "^10.4.0",
"typescript": "^5.4.5",
"typescript-eslint": "^7.11.0"
"typescript-eslint": "^7.11.0",
"vitest": "^1.6.0"
}
}
Loading

0 comments on commit ae5892e

Please sign in to comment.