@storm-software/eslint
Version:
⚡ A package containing the base ESLint configuration used by Storm Software across many projects.
100 lines (97 loc) • 2.9 kB
JavaScript
import {
__name
} from "./chunk-SHUYVCID.js";
// src/utils/helpers.ts
import { isPackageExists } from "local-pkg";
import process from "node:process";
import { fileURLToPath } from "node:url";
var scopeUrl = fileURLToPath(new URL(".", import.meta.url));
var isCwdInScope = isPackageExists("@storm-stack/eslint");
var parserPlain = {
meta: {
name: "parser-plain"
},
parseForESLint: /* @__PURE__ */ __name((code) => ({
ast: {
body: [],
comments: [],
loc: {
end: code.length,
start: 0
},
range: [
0,
code.length
],
tokens: [],
type: "Program"
},
scopeManager: null,
services: {
isPlain: true
},
visitorKeys: {
Program: []
}
}), "parseForESLint")
};
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");
}
__name(isInGitHooksOrLintStaged, "isInGitHooksOrLintStaged");
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);
}
__name(isInEditorEnv, "isInEditorEnv");
async function interopDefault(m) {
const resolved = await m;
return resolved.default || resolved;
}
__name(interopDefault, "interopDefault");
function isPackageInScope(name) {
return isPackageExists(name, {
paths: [
scopeUrl
]
});
}
__name(isPackageInScope, "isPackageInScope");
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
}));
}
__name(ensurePackages, "ensurePackages");
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
];
}));
}
__name(renameRules, "renameRules");
export {
parserPlain,
isInGitHooksOrLintStaged,
isInEditorEnv,
interopDefault,
isPackageInScope,
ensurePackages,
renameRules
};