@dword-design/base 15.3.1 → 15.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ import mergeConfigs from "./merge-lint-staged-configs/index.js";
2
+ const baseLintStagedConfig = {
3
+ "*.{json,ts,vue}": "eslint --fix --config eslint.lint-staged.config.ts"
4
+ };
5
+ export default function () {
6
+ return this.config.lintStagedConfig ? mergeConfigs(baseLintStagedConfig, this.config.lintStagedConfig) : baseLintStagedConfig;
7
+ }
@@ -0,0 +1,8 @@
1
+ import type { Configuration } from 'lint-staged';
2
+ /**
3
+ * Safely merges two lint-staged configs by expanding overlapping globs
4
+ * and merging commands for each normalized glob pattern.
5
+ * Avoids race conditions by combining commands per unique glob.
6
+ */
7
+ declare const mergeConfigs: (configA: Configuration, configB: Configuration) => Configuration;
8
+ export default mergeConfigs;
@@ -0,0 +1,74 @@
1
+ import braces from "braces";
2
+ import sortKeys from "sort-keys";
3
+ const createBracePattern = expandedGlobs => {
4
+ if (expandedGlobs.length <= 1) return null;
5
+ const sortedGlobs = [...expandedGlobs].sort();
6
+ const globParts = sortedGlobs.map(glob => {
7
+ const lastDotIndex = glob.lastIndexOf(".");
8
+ if (lastDotIndex === -1) return null;
9
+ return {
10
+ extension: glob.slice(Math.max(0, lastDotIndex + 1)),
11
+ prefix: glob.slice(0, Math.max(0, lastDotIndex))
12
+ };
13
+ });
14
+ if (globParts.includes(null)) return null;
15
+ const prefix = globParts[0].prefix;
16
+ if (!globParts.every(part => part.prefix === prefix)) return null;
17
+ const extensions = globParts.map(part => part.extension);
18
+ return `${prefix}.{${extensions.join(",")}}`;
19
+ };
20
+ const mergeConfigs = (configA, configB) => {
21
+ const expandedMap = /* @__PURE__ */new Map();
22
+ const originalToExpanded = /* @__PURE__ */new Map();
23
+ const expandedToOriginals = /* @__PURE__ */new Map();
24
+ for (const config of [configA, configB]) {
25
+ for (const [glob, cmds] of Object.entries(config)) {
26
+ const commands = Array.isArray(cmds) ? cmds : [cmds];
27
+ const expandedGlobs = braces.expand(glob);
28
+ originalToExpanded.set(glob, expandedGlobs);
29
+ for (const expandedGlob of expandedGlobs) {
30
+ if (!expandedToOriginals.has(expandedGlob)) {
31
+ expandedToOriginals.set(expandedGlob, /* @__PURE__ */new Set());
32
+ }
33
+ expandedToOriginals.get(expandedGlob).add(glob);
34
+ if (!expandedMap.has(expandedGlob)) {
35
+ expandedMap.set(expandedGlob, /* @__PURE__ */new Set());
36
+ }
37
+ for (const cmd of commands) {
38
+ expandedMap.get(expandedGlob).add(cmd);
39
+ }
40
+ }
41
+ }
42
+ }
43
+ const result = {};
44
+ const processedExpanded = /* @__PURE__ */new Set();
45
+ const originalGlobs = [...originalToExpanded.keys()];
46
+ for (const originalGlob of originalGlobs) {
47
+ const expandedGlobs = originalToExpanded.get(originalGlob);
48
+ const unprocessedExpanded = expandedGlobs.filter(eg => !processedExpanded.has(eg));
49
+ if (unprocessedExpanded.length > 1) {
50
+ const firstExpanded = unprocessedExpanded[0];
51
+ const firstCommands = expandedMap.get(firstExpanded);
52
+ const sameCommandsExpanded = unprocessedExpanded.filter(eg => {
53
+ const commands = expandedMap.get(eg);
54
+ return commands.size === firstCommands.size && [...firstCommands].every(cmd => commands.has(cmd));
55
+ });
56
+ if (sameCommandsExpanded.length > 1) {
57
+ const pattern = createBracePattern(sameCommandsExpanded);
58
+ if (pattern) {
59
+ const commandsArray = [...firstCommands];
60
+ result[pattern] = commandsArray.length === 1 ? commandsArray[0] : commandsArray;
61
+ for (const eg of sameCommandsExpanded) processedExpanded.add(eg);
62
+ }
63
+ }
64
+ }
65
+ }
66
+ for (const [expandedGlob, commands] of expandedMap) {
67
+ if (!processedExpanded.has(expandedGlob)) {
68
+ const commandsArray = [...commands];
69
+ result[expandedGlob] = commandsArray.length === 1 ? commandsArray[0] : commandsArray;
70
+ }
71
+ }
72
+ return sortKeys(result);
73
+ };
74
+ export default mergeConfigs;
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ import getGitignoreConfig from "./get-generated-files/get-gitignore/index.js";
31
31
  import getGitpodConfig from "./get-generated-files/get-gitpod/index.js";
32
32
  import getGitpodDockerfile from "./get-generated-files/get-gitpod-dockerfile.js";
33
33
  import getLicenseString from "./get-generated-files/get-license-string.js";
34
- import getLintStaged from "./get-generated-files/get-lint-staged.js";
34
+ import getLintStaged from "./get-generated-files/get-lint-staged/index.js";
35
35
  import getPackageConfig from "./get-generated-files/get-package-config/index.js";
36
36
  import getReadmeString from "./get-generated-files/get-readme-string/index.js";
37
37
  import getReleaseConfig from "./get-generated-files/get-release/index.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dword-design/base",
3
- "version": "15.3.1",
3
+ "version": "15.3.3",
4
4
  "description": "Base package for projects.",
5
5
  "repository": "dword-design/base",
6
6
  "funding": "https://github.com/sponsors/dword-design",
@@ -43,12 +43,13 @@
43
43
  "@semantic-release/changelog": "^6.0.3",
44
44
  "@semantic-release/git": "^10.0.1",
45
45
  "ajv": "^8.17.1",
46
+ "braces": "^3.0.3",
46
47
  "c8": "^10.0.0",
47
48
  "change-case": "^5.4.4",
48
49
  "commitizen": "^4.3.1",
49
50
  "cosmiconfig": "^9.0.0",
50
51
  "cz-conventional-changelog": "^3.3.0",
51
- "depcheck": "npm:@dword-design/depcheck@^0.0.7",
52
+ "depcheck": "npm:@dword-design/depcheck@^0.0.9",
52
53
  "depcheck-detector-bin-name": "^1.0.2",
53
54
  "depcheck-detector-execa": "^4.0.3",
54
55
  "depcheck-detector-package-name": "^3.0.4",
@@ -1,6 +0,0 @@
1
- export default function () {
2
- return {
3
- "*.{json,ts,vue}": "eslint --fix --config eslint.lint-staged.config.ts",
4
- ...this.config.lintStaged
5
- };
6
- }