@storm-software/eslint
Version:
A package containing the base ESLint configuration used by Storm Software across many projects.
76 lines (73 loc) • 2.55 kB
JavaScript
import { init_esm_shims } from './chunk-QO5ZXGIE.js';
import { isPackageExists } from 'local-pkg';
import process from 'node:process';
import { fileURLToPath } from 'node:url';
// src/utils/helpers.ts
init_esm_shims();
var scopeUrl = fileURLToPath(new URL(".", import.meta.url));
var isCwdInScope = isPackageExists("@storm-software/eslint");
var parserPlain = {
meta: {
name: "parser-plain"
},
parseForESLint: (code) => ({
ast: {
body: [],
comments: [],
loc: { end: code.length, start: 0 },
range: [0, code.length],
tokens: [],
type: "Program"
},
scopeManager: null,
services: { isPlain: true },
visitorKeys: {
Program: []
}
})
};
function isInGitHooksOrLintStaged() {
return !!(process.env.GIT_PARAMS || process.env.VSCODE_GIT_COMMAND || process.env.npm_lifecycle_script?.startsWith("lint-staged") || process.env.npm_lifecycle_script?.startsWith("lefthook") || process.env.npm_lifecycle_script === "push");
}
function isInEditorEnv() {
if (process.env.CI) return false;
if (isInGitHooksOrLintStaged()) return false;
return !!(process.env.VSCODE_PID || process.env.VSCODE_CWD || process.env.JETBRAINS_IDE || process.env.VIM || process.env.NVIM);
}
async function interopDefault(m) {
const resolved = await m;
return resolved.default || resolved;
}
function isPackageInScope(name) {
return isPackageExists(name, { paths: [scopeUrl] });
}
async function ensurePackages(packages) {
if (process.env.CI || process.stdout.isTTY === false || isCwdInScope === false)
return;
const nonExistingPackages = packages.filter(
(i) => i && !isPackageInScope(i)
);
if (nonExistingPackages.length === 0) return;
const p = await import('@clack/prompts');
const result = await p.confirm({
message: `${nonExistingPackages.length === 1 ? "Package is" : "Packages are"} required for this config: ${nonExistingPackages.join(
", "
)}. Do you want to install them?`
});
if (result)
await import('@antfu/install-pkg').then(
(i) => i.installPackage(nonExistingPackages, { dev: true })
);
}
function renameRules(rules, map) {
return Object.fromEntries(
Object.entries(rules).map(([key, value]) => {
for (const [from, to] of Object.entries(map)) {
if (key.startsWith(`${from}/`))
return [to + key.slice(from.length), value];
}
return [key, value];
})
);
}
export { ensurePackages, interopDefault, isInEditorEnv, isInGitHooksOrLintStaged, isPackageInScope, parserPlain, renameRules };