Skip to content

Commit b97cc00

Browse files
committed
fix: changed config loading to lazy, changed package.json key search
Signed-off-by: prisis <[email protected]>
1 parent 0c29d6b commit b97cc00

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

packages/lint-staged-config/src/config.ts

+8-16
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,43 @@
1+
import { createRequire } from "node:module";
2+
13
import { hasDependency, hasDevDependency } from "@anolilab/package-json-utils";
24
import type { Config } from "lint-staged";
35

4-
import eslintConfig from "./groups/eslint";
5-
import jsonConfig from "./groups/json";
6-
import markdownConfig from "./groups/markdown";
7-
import secretlintConfig from "./groups/secretlint";
8-
import stylesheetsConfig from "./groups/stylesheets";
9-
import testsConfig from "./groups/tests";
10-
import typescriptConfig from "./groups/typescript";
116
import anolilabLintStagedConfig from "./utils/lint-staged-config";
127

8+
const require = createRequire(import.meta.url);
9+
1310
type Groups = {
14-
config: Config;
1511
configName: string;
1612
dependencies: string[];
1713
}[];
1814

1915
const groups: Groups = [
2016
{
21-
config: eslintConfig,
2217
configName: "eslint",
2318
dependencies: ["eslint"],
2419
},
2520
{
26-
config: jsonConfig,
2721
configName: "json",
2822
dependencies: ["prettier"],
2923
},
3024
{
31-
config: markdownConfig,
3225
configName: "markdown",
3326
dependencies: ["markdownlint-cli", "markdownlint-cli2"],
3427
},
3528
{
36-
config: secretlintConfig,
3729
configName: "secretlint",
3830
dependencies: ["secretlint"],
3931
},
4032
{
41-
config: stylesheetsConfig,
4233
configName: "stylesheets",
4334
dependencies: ["stylelint"],
4435
},
4536
{
46-
config: testsConfig,
4737
configName: "tests",
4838
dependencies: ["vite", "jest", "ava"],
4939
},
5040
{
51-
config: typescriptConfig,
5241
configName: "typescript",
5342
dependencies: ["typescript"],
5443
},
@@ -60,7 +49,7 @@ const loadedPluginsNames: string[] = [];
6049
const possiblePlugins: Record<string, Record<string, boolean>> = {};
6150

6251
groups.forEach((plugin) => {
63-
const { config, configName, dependencies } = plugin;
52+
const { configName, dependencies } = plugin;
6453

6554
// eslint-disable-next-line security/detect-object-injection
6655
if ((anolilabLintStagedConfig as unknown as Record<string, Record<string, false | undefined>>)["plugin"]?.[configName] !== false) {
@@ -73,6 +62,9 @@ groups.forEach((plugin) => {
7362
});
7463

7564
if (foundDependencies.length > 0) {
65+
// eslint-disable-next-line security/detect-non-literal-require,import/no-dynamic-require
66+
const config = require(`./groups/${configName}`) as Config;
67+
7668
loadedPlugins = { ...loadedPlugins, ...config };
7769
loadedPluginsNames.push(configName);
7870
} else {

packages/lint-staged-config/src/groups/json.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,7 @@ const group: Config = {
1010
[`**/*.{${["json", "json5", "jsonc"].join(",")}}`]: (filenames: string[]) => [`${getPackageManager()} exec prettier --write ${concatFiles(filenames)}`],
1111
...(hasSortPackageJson
1212
? {
13-
"package.json,{packages,apps}/*/package.json": (filenames: string[]) => [
14-
`${getPackageManager()} exec sort-package-json ${concatFiles(filenames)}`,
15-
],
13+
"**/package.json": (filenames: string[]) => [`${getPackageManager()} exec sort-package-json ${concatFiles(filenames)}`],
1614
}
1715
: {}),
1816
};

0 commit comments

Comments
 (0)