zephex 2.0.16 → 2.1.1

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.
@@ -149,21 +149,107 @@ function filePolyfill(path) {
149
149
  text: async () => readFile(path, "utf8")
150
150
  };
151
151
  }
152
+ function globToRegExp(pattern) {
153
+ let re = "";
154
+ let i = 0;
155
+ while (i < pattern.length) {
156
+ const c = pattern[i];
157
+ if (c === "*") {
158
+ if (pattern[i + 1] === "*") {
159
+ if (pattern[i + 2] === "/") {
160
+ re += "(?:.*/)?";
161
+ i += 3;
162
+ continue;
163
+ }
164
+ re += ".*";
165
+ i += 2;
166
+ continue;
167
+ }
168
+ re += "[^/]*";
169
+ i++;
170
+ continue;
171
+ }
172
+ if (c === "?") {
173
+ re += "[^/]";
174
+ i++;
175
+ continue;
176
+ }
177
+ if (c === "{") {
178
+ const close = pattern.indexOf("}", i);
179
+ if (close > i) {
180
+ const parts = pattern.slice(i + 1, close).split(",").map((s) => s.replace(/[.+^${}()|[\]\\]/g, "\\$&"));
181
+ re += "(?:" + parts.join("|") + ")";
182
+ i = close + 1;
183
+ continue;
184
+ }
185
+ }
186
+ if (/[.+^${}()|[\]\\]/.test(c)) {
187
+ re += "\\" + c;
188
+ } else {
189
+ re += c;
190
+ }
191
+ i++;
192
+ }
193
+ return new RegExp("^" + re + "$");
194
+ }
152
195
 
153
196
  class GlobPolyfill {
154
197
  pattern;
198
+ regex;
155
199
  constructor(pattern) {
156
200
  this.pattern = pattern;
201
+ this.regex = globToRegExp(pattern);
157
202
  }
158
203
  async* scan(opts) {
159
- const { glob } = await import("node:fs/promises");
160
- const cwd = opts?.cwd ?? process.cwd();
161
- for await (const entry of glob(this.pattern, { cwd })) {
162
- if (opts?.absolute) {
163
- const { resolve } = await import("node:path");
164
- yield resolve(cwd, entry);
165
- } else {
166
- yield entry;
204
+ const cwd = (typeof opts === "string" ? opts : opts?.cwd) ?? process.cwd();
205
+ const absolute = typeof opts === "string" ? false : opts?.absolute ?? false;
206
+ const { readdir } = await import("node:fs/promises");
207
+ const { resolve, sep } = await import("node:path");
208
+ const SKIP = new Set([
209
+ "node_modules",
210
+ ".git",
211
+ ".next",
212
+ ".turbo",
213
+ ".cache",
214
+ "dist",
215
+ "build",
216
+ "out",
217
+ "coverage",
218
+ "__pycache__",
219
+ ".venv",
220
+ "venv",
221
+ "target",
222
+ ".idea",
223
+ ".vscode"
224
+ ]);
225
+ let entries;
226
+ try {
227
+ entries = await readdir(cwd, {
228
+ recursive: true,
229
+ withFileTypes: true
230
+ });
231
+ } catch {
232
+ return;
233
+ }
234
+ for (const ent of entries) {
235
+ if (typeof ent.isFile === "function" && !ent.isFile())
236
+ continue;
237
+ const parent = ent.parentPath ?? ent.path ?? cwd;
238
+ const fullPath = parent.endsWith(sep) ? parent + ent.name : parent + sep + ent.name;
239
+ let rel = fullPath.startsWith(cwd) ? fullPath.slice(cwd.length).replace(/^[\\/]+/, "") : fullPath;
240
+ rel = rel.split(sep).join("/");
241
+ const segs = rel.split("/");
242
+ let pruned = false;
243
+ for (const s of segs) {
244
+ if (SKIP.has(s)) {
245
+ pruned = true;
246
+ break;
247
+ }
248
+ }
249
+ if (pruned)
250
+ continue;
251
+ if (this.regex.test(rel)) {
252
+ yield absolute ? resolve(cwd, rel) : rel;
167
253
  }
168
254
  }
169
255
  }
@@ -194,15 +280,31 @@ class CryptoHasherPolyfill {
194
280
  }
195
281
  function ensureBunPolyfill() {
196
282
  const g = globalThis;
197
- if (typeof g.Bun !== "undefined")
283
+ if (typeof g.Bun === "undefined") {
284
+ g.Bun = {
285
+ file: filePolyfill,
286
+ spawn: spawnPolyfill,
287
+ JSONL: { parse: jsonlParsePolyfill },
288
+ Glob: GlobPolyfill,
289
+ CryptoHasher: CryptoHasherPolyfill
290
+ };
198
291
  return;
199
- g.Bun = {
200
- file: filePolyfill,
201
- spawn: spawnPolyfill,
202
- JSONL: { parse: jsonlParsePolyfill },
203
- Glob: GlobPolyfill,
204
- CryptoHasher: CryptoHasherPolyfill
205
- };
292
+ }
293
+ if (typeof g.Bun.Glob !== "function") {
294
+ g.Bun.Glob = GlobPolyfill;
295
+ }
296
+ if (typeof g.Bun.file !== "function") {
297
+ g.Bun.file = filePolyfill;
298
+ }
299
+ if (typeof g.Bun.spawn !== "function") {
300
+ g.Bun.spawn = spawnPolyfill;
301
+ }
302
+ if (!g.Bun.JSONL || typeof g.Bun.JSONL.parse !== "function") {
303
+ g.Bun.JSONL = { parse: jsonlParsePolyfill };
304
+ }
305
+ if (typeof g.Bun.CryptoHasher !== "function") {
306
+ g.Bun.CryptoHasher = CryptoHasherPolyfill;
307
+ }
206
308
  }
207
309
  var init_bun_polyfill = __esm(() => {
208
310
  ensureBunPolyfill();