directory-lint 2.0.0 → 2.0.2

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.
package/dist/index.cjs CHANGED
@@ -117,6 +117,10 @@ var DirectoryLint = class {
117
117
  this.backend.writeFile(fullPath, node.content === void 0 ? "" : node.content);
118
118
  }
119
119
  }
120
+ result.paths[name] = {
121
+ path: fullPath,
122
+ type: node.type
123
+ };
120
124
  }
121
125
  }
122
126
  return result;
@@ -127,29 +131,46 @@ var DirectoryLint = class {
127
131
  paths: {}
128
132
  };
129
133
  const items = this.backend.getAllItems(cwd);
130
- for (const [pattern, node] of Object.entries(schema)) {
134
+ const processedNames = /* @__PURE__ */ new Set();
135
+ const sortedEntries = Object.entries(schema).sort(([a], [b]) => {
136
+ const aHasWildcard = a.includes("*");
137
+ const bHasWildcard = b.includes("*");
138
+ if (!aHasWildcard && bHasWildcard) return -1;
139
+ if (aHasWildcard && !bHasWildcard) return 1;
140
+ return 0;
141
+ });
142
+ for (const [pattern, node] of sortedEntries) {
131
143
  const regex = this.patternToRegex(pattern);
132
- const matchedItems = items.filter((item) => regex.test(item.name));
133
- if (matchedItems.length === 0 && node.required !== false) throw new InvalidStructure(pattern);
144
+ const matchedItems = items.filter(
145
+ (item) => regex.test(item.name) && !processedNames.has(item.name)
146
+ );
147
+ const isRequired = node.required ?? true;
148
+ if (matchedItems.length === 0 && isRequired) throw new InvalidStructure(pattern);
134
149
  for (const { name, type } of matchedItems) {
135
150
  if (options?.ignore.includes(name)) continue;
151
+ processedNames.add(name);
136
152
  const fullPath = (0, import_path.join)(cwd, name);
137
153
  if (node.type === "directory") {
138
- let childrenResult = void 0;
139
154
  if (type !== "directory") throw new InvalidStructure(fullPath);
140
- else if (node.children) {
155
+ let childrenResult = void 0;
156
+ if (node.children) {
141
157
  childrenResult = await this.validate(fullPath, node.children, options);
142
158
  }
143
159
  result.paths[name] = {
144
160
  path: fullPath,
145
161
  name,
146
- type: node.type,
162
+ type: "directory",
147
163
  ...childrenResult?.paths && { children: childrenResult.paths }
148
164
  };
149
165
  } else if (node.type === "file") {
150
166
  if (type !== "file") throw new InvalidStructure(fullPath);
151
167
  const content = this.backend.readFile(fullPath);
152
168
  if (node.validate ? !node.validate(content) : false) throw new InvalidContent(fullPath);
169
+ result.paths[name] = {
170
+ path: fullPath,
171
+ name,
172
+ type: "file"
173
+ };
153
174
  }
154
175
  }
155
176
  }
package/dist/index.js CHANGED
@@ -77,6 +77,10 @@ var DirectoryLint = class {
77
77
  this.backend.writeFile(fullPath, node.content === void 0 ? "" : node.content);
78
78
  }
79
79
  }
80
+ result.paths[name] = {
81
+ path: fullPath,
82
+ type: node.type
83
+ };
80
84
  }
81
85
  }
82
86
  return result;
@@ -87,29 +91,46 @@ var DirectoryLint = class {
87
91
  paths: {}
88
92
  };
89
93
  const items = this.backend.getAllItems(cwd);
90
- for (const [pattern, node] of Object.entries(schema)) {
94
+ const processedNames = /* @__PURE__ */ new Set();
95
+ const sortedEntries = Object.entries(schema).sort(([a], [b]) => {
96
+ const aHasWildcard = a.includes("*");
97
+ const bHasWildcard = b.includes("*");
98
+ if (!aHasWildcard && bHasWildcard) return -1;
99
+ if (aHasWildcard && !bHasWildcard) return 1;
100
+ return 0;
101
+ });
102
+ for (const [pattern, node] of sortedEntries) {
91
103
  const regex = this.patternToRegex(pattern);
92
- const matchedItems = items.filter((item) => regex.test(item.name));
93
- if (matchedItems.length === 0 && node.required !== false) throw new InvalidStructure(pattern);
104
+ const matchedItems = items.filter(
105
+ (item) => regex.test(item.name) && !processedNames.has(item.name)
106
+ );
107
+ const isRequired = node.required ?? true;
108
+ if (matchedItems.length === 0 && isRequired) throw new InvalidStructure(pattern);
94
109
  for (const { name, type } of matchedItems) {
95
110
  if (options?.ignore.includes(name)) continue;
111
+ processedNames.add(name);
96
112
  const fullPath = join(cwd, name);
97
113
  if (node.type === "directory") {
98
- let childrenResult = void 0;
99
114
  if (type !== "directory") throw new InvalidStructure(fullPath);
100
- else if (node.children) {
115
+ let childrenResult = void 0;
116
+ if (node.children) {
101
117
  childrenResult = await this.validate(fullPath, node.children, options);
102
118
  }
103
119
  result.paths[name] = {
104
120
  path: fullPath,
105
121
  name,
106
- type: node.type,
122
+ type: "directory",
107
123
  ...childrenResult?.paths && { children: childrenResult.paths }
108
124
  };
109
125
  } else if (node.type === "file") {
110
126
  if (type !== "file") throw new InvalidStructure(fullPath);
111
127
  const content = this.backend.readFile(fullPath);
112
128
  if (node.validate ? !node.validate(content) : false) throw new InvalidContent(fullPath);
129
+ result.paths[name] = {
130
+ path: fullPath,
131
+ name,
132
+ type: "file"
133
+ };
113
134
  }
114
135
  }
115
136
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "directory-lint",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "Directory Lint",
5
5
  "license": "MIT",
6
6
  "author": "Henry Vilani",