UNPKG

@techmely/utils

Version:

Collection of helpful JavaScript / TypeScript utils

182 lines (176 loc) 5.82 kB
import { __esm, __commonJS, __require } from './chunk-NYLAFCGV.mjs'; // ../../node_modules/fsevents/fsevents.node var fsevents_default; var init_fsevents = __esm({ "../../node_modules/fsevents/fsevents.node"() { fsevents_default = "./fsevents-X6WP4TKM.node"; } }); // node-file:/Users/techmely/Desktop/Code/_self/essential-packages/node_modules/fsevents/fsevents.node var require_fsevents = __commonJS({ "node-file:/Users/techmely/Desktop/Code/_self/essential-packages/node_modules/fsevents/fsevents.node"(exports, module) { init_fsevents(); try { module.exports = __require(fsevents_default); } catch { } } }); // ../../node_modules/fsevents/vfs.js var require_vfs = __commonJS({ "../../node_modules/fsevents/vfs.js"(exports, module) { var path = __require("path"); var pnpApi = null; try { pnpApi = __require("pnpapi"); } catch { } function getVirtualLookupFn(pnpApi2) { const reverseMap = /* @__PURE__ */ new Map(); for (const locator of pnpApi2.getAllLocators()) { const pkg = pnpApi2.getPackageInformation(locator); console.assert(pkg, `The package information should be available`); const resolvedLocation = pnpApi2.resolveVirtual(pkg.packageLocation); if (resolvedLocation === null) continue; const aliases = reverseMap.get(resolvedLocation) || [resolvedLocation]; reverseMap.set(resolvedLocation, aliases); aliases.push(pkg.packageLocation); } const keys = [...reverseMap.keys()].sort((a, b) => { return b.length - a.length; }); return (p) => { const prefix = keys.find((candidate) => p.startsWith(candidate)); if (typeof prefix === `undefined`) return [p]; const sub = p.substr(prefix.length); return reverseMap.get(prefix).map((alias) => { return alias + sub; }); }; } if (pnpApi != null) { const resolveVirtualAliases = getVirtualLookupFn(pnpApi); module.exports = class FsePnp { constructor(p) { this.normalizedPath = path.resolve(p); this.resolvedPath = pnpApi.resolveVirtual(this.normalizedPath) || this.normalizedPath; } transpose(p) { if (this.resolvedPath !== null) { return this.normalizedPath + p.substr(this.resolvedPath.length); } else { return p; } } wrap(fn) { return (path2, ...args) => { for (const entry of resolveVirtualAliases(path2)) { fn(this.transpose(entry), ...args); } }; } }; } else { module.exports = class FsePnp { constructor(p) { this.resolvedPath = p; } wrap(fn) { return fn; } }; } } }); // ../../node_modules/fsevents/fsevents.js var require_fsevents2 = __commonJS({ "../../node_modules/fsevents/fsevents.js"(exports) { if (process.platform !== "darwin") { throw new Error(`Module 'fsevents' is not compatible with platform '${process.platform}'`); } var Native = require_fsevents(); var events = Native.constants; function watch(path, since, handler) { if (typeof path !== "string") { throw new TypeError(`fsevents argument 1 must be a string and not a ${typeof path}`); } if ("function" === typeof since && "undefined" === typeof handler) { handler = since; since = Native.flags.SinceNow; } if (typeof since !== "number") { throw new TypeError(`fsevents argument 2 must be a number and not a ${typeof since}`); } if (typeof handler !== "function") { throw new TypeError(`fsevents argument 3 must be a function and not a ${typeof handler}`); } let VFS = require_vfs(); let vfs = new VFS(path); let instance = Native.start(Native.global, vfs.resolvedPath, since, vfs.wrap(handler)); if (!instance) throw new Error(`could not watch: ${path}`); return () => { const result = instance ? Promise.resolve(instance).then(Native.stop) : Promise.resolve(void 0); instance = void 0; return result; }; } function getInfo(path, flags) { return { path, flags, event: getEventType(flags), type: getFileType(flags), changes: getFileChanges(flags) }; } function getFileType(flags) { if (events.ItemIsFile & flags) return "file"; if (events.ItemIsDir & flags) return "directory"; if (events.MustScanSubDirs & flags) return "directory"; if (events.ItemIsSymlink & flags) return "symlink"; } function anyIsTrue(obj) { for (let key in obj) { if (obj[key]) return true; } return false; } function getEventType(flags) { if (events.ItemRemoved & flags) return "deleted"; if (events.ItemRenamed & flags) return "moved"; if (events.ItemCreated & flags) return "created"; if (events.ItemModified & flags) return "modified"; if (events.RootChanged & flags) return "root-changed"; if (events.ItemCloned & flags) return "cloned"; if (anyIsTrue(flags)) return "modified"; return "unknown"; } function getFileChanges(flags) { return { inode: !!(events.ItemInodeMetaMod & flags), finder: !!(events.ItemFinderInfoMod & flags), access: !!(events.ItemChangeOwner & flags), xattrs: !!(events.ItemXattrMod & flags) }; } exports.watch = watch; exports.getInfo = getInfo; exports.constants = events; } }); export { require_fsevents2 as require_fsevents };