module-root-sync
Advanced tools
+19
-4
@@ -66,12 +66,27 @@ "use strict"; | ||
| }; | ||
| /** | ||
| * Check if a package.json is synthetic (no `name` field). | ||
| * Synthetic package.json files typically only contain `type` for module system hints. | ||
| */ var isSyntheticPackage = function(filePath) { | ||
| try { | ||
| var content = JSON.parse(_fs.default.readFileSync(filePath, 'utf8')); | ||
| return !('name' in content); | ||
| } catch (_) { | ||
| return false; | ||
| } | ||
| }; | ||
| function moduleRoot(dir) { | ||
| var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}; | ||
| var name = options.name === undefined ? 'package.json' : options.name; | ||
| var isPackageJson = name === 'package.json'; | ||
| var skipSynthetic = isPackageJson && !options.includeSynthetic; | ||
| // Convert file:// URL to path if needed | ||
| var current = fileURLToPath(dir); | ||
| do { | ||
| var packagePath = _path.default.join(current, name); | ||
| if (existsSync(packagePath)) { | ||
| if (!options.keyExists) return current; | ||
| if (JSON.parse(_fs.default.readFileSync(packagePath, 'utf8'))[options.keyExists] !== undefined) return current; | ||
| var filePath = _path.default.join(current, name); | ||
| if (existsSync(filePath)) { | ||
| // Skip synthetic package.json files unless includeSynthetic is true | ||
| if (!skipSynthetic || !isSyntheticPackage(filePath)) { | ||
| return current; | ||
| } | ||
| } | ||
@@ -78,0 +93,0 @@ var next = _path.default.dirname(current); |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/module-root-sync/src/index.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nconst existsSync = (test: string): boolean => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\n\nimport type { PathLike } from './types.ts';\n\n/**\n * Convert file:// URL to filesystem path\n * Node 0.8 compatible (no url.fileURLToPath available)\n * Accepts string paths, string file URLs, or URL objects\n */\nconst fileURLToPath = (input: PathLike): string => {\n // Handle URL objects by extracting href\n const urlString = typeof input === 'string' ? input : input.href;\n\n // Check if it's a file URL (use indexOf for Node 0.8 compat)\n if (urlString.indexOf('file://') !== 0) {\n return urlString; // Not a file URL, return as-is\n }\n\n // Remove file:// prefix\n let filepath = urlString.slice(7);\n\n // Handle Windows: file:///C:/path -> C:/path\n if (filepath.charAt(0) === '/' && filepath.charAt(2) === ':') {\n filepath = filepath.slice(1);\n }\n\n // Decode URL-encoded characters (%20 -> space, etc.)\n filepath = decodeURIComponent(filepath);\n\n // Convert forward slashes to backslashes on Windows\n if (isWindows) {\n filepath = filepath.split('/').join('\\\\');\n }\n\n return filepath;\n};\n\nimport type { RootOptions } from './types.ts';\n\nexport * from './types.ts';\nexport default function moduleRoot(dir: PathLike, options: RootOptions = {}) {\n const name = options.name === undefined ? 'package.json' : options.name;\n\n // Convert file:// URL to path if needed\n let current = fileURLToPath(dir);\n do {\n const packagePath = path.join(current, name);\n if (existsSync(packagePath)) {\n if (!options.keyExists) return current;\n if (JSON.parse(fs.readFileSync(packagePath, 'utf8'))[options.keyExists] !== undefined) return current;\n }\n const next = path.dirname(current);\n if (next === current) break;\n current = next;\n } while (current);\n throw new Error('Root not found');\n}\n"],"names":["moduleRoot","isWindows","process","platform","test","env","OSTYPE","existsSync","fs","accessSync","statSync","_","fileURLToPath","input","urlString","href","indexOf","filepath","slice","charAt","decodeURIComponent","split","join","dir","options","name","undefined","current","packagePath","path","keyExists","JSON","parse","readFileSync","next","dirname","Error"],"mappings":";;;;+BAoDA;;;eAAwBA;;;yDApDT;2DACE;qBAkDH;;;;;;;;;;;;;;;;;;;AAhDd,IAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAE3F,IAAMC,aAAa,SAACH;IAClB,IAAI;QACDI,CAAAA,WAAE,CAACC,UAAU,IAAID,WAAE,CAACE,QAAQ,AAAD,EAAGN;QAC/B,OAAO;IACT,EAAE,OAAOO,GAAG;QACV,OAAO;IACT;AACF;AAIA;;;;CAIC,GACD,IAAMC,gBAAgB,SAACC;IACrB,wCAAwC;IACxC,IAAMC,YAAY,OAAOD,UAAU,WAAWA,QAAQA,MAAME,IAAI;IAEhE,6DAA6D;IAC7D,IAAID,UAAUE,OAAO,CAAC,eAAe,GAAG;QACtC,OAAOF,WAAW,+BAA+B;IACnD;IAEA,wBAAwB;IACxB,IAAIG,WAAWH,UAAUI,KAAK,CAAC;IAE/B,6CAA6C;IAC7C,IAAID,SAASE,MAAM,CAAC,OAAO,OAAOF,SAASE,MAAM,CAAC,OAAO,KAAK;QAC5DF,WAAWA,SAASC,KAAK,CAAC;IAC5B;IAEA,qDAAqD;IACrDD,WAAWG,mBAAmBH;IAE9B,oDAAoD;IACpD,IAAIhB,WAAW;QACbgB,WAAWA,SAASI,KAAK,CAAC,KAAKC,IAAI,CAAC;IACtC;IAEA,OAAOL;AACT;AAKe,SAASjB,WAAWuB,GAAa;QAAEC,UAAAA,iEAAuB,CAAC;IACxE,IAAMC,OAAOD,QAAQC,IAAI,KAAKC,YAAY,iBAAiBF,QAAQC,IAAI;IAEvE,wCAAwC;IACxC,IAAIE,UAAUf,cAAcW;IAC5B,GAAG;QACD,IAAMK,cAAcC,aAAI,CAACP,IAAI,CAACK,SAASF;QACvC,IAAIlB,WAAWqB,cAAc;YAC3B,IAAI,CAACJ,QAAQM,SAAS,EAAE,OAAOH;YAC/B,IAAII,KAAKC,KAAK,CAACxB,WAAE,CAACyB,YAAY,CAACL,aAAa,QAAQ,CAACJ,QAAQM,SAAS,CAAC,KAAKJ,WAAW,OAAOC;QAChG;QACA,IAAMO,OAAOL,aAAI,CAACM,OAAO,CAACR;QAC1B,IAAIO,SAASP,SAAS;QACtBA,UAAUO;IACZ,QAASP,SAAS;IAClB,MAAM,IAAIS,MAAM;AAClB"} | ||
| {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/module-root-sync/src/index.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nconst existsSync = (test: string): boolean => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\n\nimport type { PathLike } from './types.ts';\n\n/**\n * Convert file:// URL to filesystem path\n * Node 0.8 compatible (no url.fileURLToPath available)\n * Accepts string paths, string file URLs, or URL objects\n */\nconst fileURLToPath = (input: PathLike): string => {\n // Handle URL objects by extracting href\n const urlString = typeof input === 'string' ? input : input.href;\n\n // Check if it's a file URL (use indexOf for Node 0.8 compat)\n if (urlString.indexOf('file://') !== 0) {\n return urlString; // Not a file URL, return as-is\n }\n\n // Remove file:// prefix\n let filepath = urlString.slice(7);\n\n // Handle Windows: file:///C:/path -> C:/path\n if (filepath.charAt(0) === '/' && filepath.charAt(2) === ':') {\n filepath = filepath.slice(1);\n }\n\n // Decode URL-encoded characters (%20 -> space, etc.)\n filepath = decodeURIComponent(filepath);\n\n // Convert forward slashes to backslashes on Windows\n if (isWindows) {\n filepath = filepath.split('/').join('\\\\');\n }\n\n return filepath;\n};\n\nimport type { RootOptions } from './types.ts';\n\nexport * from './types.ts';\n\n/**\n * Check if a package.json is synthetic (no `name` field).\n * Synthetic package.json files typically only contain `type` for module system hints.\n */\nconst isSyntheticPackage = (filePath: string): boolean => {\n try {\n const content = JSON.parse(fs.readFileSync(filePath, 'utf8'));\n return !('name' in content);\n } catch (_) {\n return false;\n }\n};\n\nexport default function moduleRoot(dir: PathLike, options: RootOptions = {}) {\n const name = options.name === undefined ? 'package.json' : options.name;\n const isPackageJson = name === 'package.json';\n const skipSynthetic = isPackageJson && !options.includeSynthetic;\n\n // Convert file:// URL to path if needed\n let current = fileURLToPath(dir);\n do {\n const filePath = path.join(current, name);\n if (existsSync(filePath)) {\n // Skip synthetic package.json files unless includeSynthetic is true\n if (!skipSynthetic || !isSyntheticPackage(filePath)) {\n return current;\n }\n }\n const next = path.dirname(current);\n if (next === current) break;\n current = next;\n } while (current);\n throw new Error('Root not found');\n}\n"],"names":["moduleRoot","isWindows","process","platform","test","env","OSTYPE","existsSync","fs","accessSync","statSync","_","fileURLToPath","input","urlString","href","indexOf","filepath","slice","charAt","decodeURIComponent","split","join","isSyntheticPackage","filePath","content","JSON","parse","readFileSync","dir","options","name","undefined","isPackageJson","skipSynthetic","includeSynthetic","current","path","next","dirname","Error"],"mappings":";;;;+BAkEA;;;eAAwBA;;;yDAlET;2DACE;qBAkDH;;;;;;;;;;;;;;;;;;;AAhDd,IAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAE3F,IAAMC,aAAa,SAACH;IAClB,IAAI;QACDI,CAAAA,WAAE,CAACC,UAAU,IAAID,WAAE,CAACE,QAAQ,AAAD,EAAGN;QAC/B,OAAO;IACT,EAAE,OAAOO,GAAG;QACV,OAAO;IACT;AACF;AAIA;;;;CAIC,GACD,IAAMC,gBAAgB,SAACC;IACrB,wCAAwC;IACxC,IAAMC,YAAY,OAAOD,UAAU,WAAWA,QAAQA,MAAME,IAAI;IAEhE,6DAA6D;IAC7D,IAAID,UAAUE,OAAO,CAAC,eAAe,GAAG;QACtC,OAAOF,WAAW,+BAA+B;IACnD;IAEA,wBAAwB;IACxB,IAAIG,WAAWH,UAAUI,KAAK,CAAC;IAE/B,6CAA6C;IAC7C,IAAID,SAASE,MAAM,CAAC,OAAO,OAAOF,SAASE,MAAM,CAAC,OAAO,KAAK;QAC5DF,WAAWA,SAASC,KAAK,CAAC;IAC5B;IAEA,qDAAqD;IACrDD,WAAWG,mBAAmBH;IAE9B,oDAAoD;IACpD,IAAIhB,WAAW;QACbgB,WAAWA,SAASI,KAAK,CAAC,KAAKC,IAAI,CAAC;IACtC;IAEA,OAAOL;AACT;AAMA;;;CAGC,GACD,IAAMM,qBAAqB,SAACC;IAC1B,IAAI;QACF,IAAMC,UAAUC,KAAKC,KAAK,CAACnB,WAAE,CAACoB,YAAY,CAACJ,UAAU;QACrD,OAAO,CAAE,CAAA,UAAUC,OAAM;IAC3B,EAAE,OAAOd,GAAG;QACV,OAAO;IACT;AACF;AAEe,SAASX,WAAW6B,GAAa;QAAEC,UAAAA,iEAAuB,CAAC;IACxE,IAAMC,OAAOD,QAAQC,IAAI,KAAKC,YAAY,iBAAiBF,QAAQC,IAAI;IACvE,IAAME,gBAAgBF,SAAS;IAC/B,IAAMG,gBAAgBD,iBAAiB,CAACH,QAAQK,gBAAgB;IAEhE,wCAAwC;IACxC,IAAIC,UAAUxB,cAAciB;IAC5B,GAAG;QACD,IAAML,WAAWa,aAAI,CAACf,IAAI,CAACc,SAASL;QACpC,IAAIxB,WAAWiB,WAAW;YACxB,oEAAoE;YACpE,IAAI,CAACU,iBAAiB,CAACX,mBAAmBC,WAAW;gBACnD,OAAOY;YACT;QACF;QACA,IAAME,OAAOD,aAAI,CAACE,OAAO,CAACH;QAC1B,IAAIE,SAASF,SAAS;QACtBA,UAAUE;IACZ,QAASF,SAAS;IAClB,MAAM,IAAII,MAAM;AAClB"} |
| export interface RootOptions { | ||
| name?: string; | ||
| keyExists?: string; | ||
| /** Include synthetic package.json files (only `type` field, no `name`). Default: false */ | ||
| includeSynthetic?: boolean; | ||
| } | ||
| /** A filesystem path string or file:// URL (string or URL object) */ | ||
| export type PathLike = string | URL; |
| export interface RootOptions { | ||
| name?: string; | ||
| keyExists?: string; | ||
| /** Include synthetic package.json files (only `type` field, no `name`). Default: false */ | ||
| includeSynthetic?: boolean; | ||
| } | ||
| /** A filesystem path string or file:// URL (string or URL object) */ | ||
| export type PathLike = string | URL; |
+19
-4
@@ -38,11 +38,26 @@ import fs from 'fs'; | ||
| export * from './types.js'; | ||
| /** | ||
| * Check if a package.json is synthetic (no `name` field). | ||
| * Synthetic package.json files typically only contain `type` for module system hints. | ||
| */ const isSyntheticPackage = (filePath)=>{ | ||
| try { | ||
| const content = JSON.parse(fs.readFileSync(filePath, 'utf8')); | ||
| return !('name' in content); | ||
| } catch (_) { | ||
| return false; | ||
| } | ||
| }; | ||
| export default function moduleRoot(dir, options = {}) { | ||
| const name = options.name === undefined ? 'package.json' : options.name; | ||
| const isPackageJson = name === 'package.json'; | ||
| const skipSynthetic = isPackageJson && !options.includeSynthetic; | ||
| // Convert file:// URL to path if needed | ||
| let current = fileURLToPath(dir); | ||
| do { | ||
| const packagePath = path.join(current, name); | ||
| if (existsSync(packagePath)) { | ||
| if (!options.keyExists) return current; | ||
| if (JSON.parse(fs.readFileSync(packagePath, 'utf8'))[options.keyExists] !== undefined) return current; | ||
| const filePath = path.join(current, name); | ||
| if (existsSync(filePath)) { | ||
| // Skip synthetic package.json files unless includeSynthetic is true | ||
| if (!skipSynthetic || !isSyntheticPackage(filePath)) { | ||
| return current; | ||
| } | ||
| } | ||
@@ -49,0 +64,0 @@ const next = path.dirname(current); |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/module-root-sync/src/index.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nconst existsSync = (test: string): boolean => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\n\nimport type { PathLike } from './types.ts';\n\n/**\n * Convert file:// URL to filesystem path\n * Node 0.8 compatible (no url.fileURLToPath available)\n * Accepts string paths, string file URLs, or URL objects\n */\nconst fileURLToPath = (input: PathLike): string => {\n // Handle URL objects by extracting href\n const urlString = typeof input === 'string' ? input : input.href;\n\n // Check if it's a file URL (use indexOf for Node 0.8 compat)\n if (urlString.indexOf('file://') !== 0) {\n return urlString; // Not a file URL, return as-is\n }\n\n // Remove file:// prefix\n let filepath = urlString.slice(7);\n\n // Handle Windows: file:///C:/path -> C:/path\n if (filepath.charAt(0) === '/' && filepath.charAt(2) === ':') {\n filepath = filepath.slice(1);\n }\n\n // Decode URL-encoded characters (%20 -> space, etc.)\n filepath = decodeURIComponent(filepath);\n\n // Convert forward slashes to backslashes on Windows\n if (isWindows) {\n filepath = filepath.split('/').join('\\\\');\n }\n\n return filepath;\n};\n\nimport type { RootOptions } from './types.ts';\n\nexport * from './types.ts';\nexport default function moduleRoot(dir: PathLike, options: RootOptions = {}) {\n const name = options.name === undefined ? 'package.json' : options.name;\n\n // Convert file:// URL to path if needed\n let current = fileURLToPath(dir);\n do {\n const packagePath = path.join(current, name);\n if (existsSync(packagePath)) {\n if (!options.keyExists) return current;\n if (JSON.parse(fs.readFileSync(packagePath, 'utf8'))[options.keyExists] !== undefined) return current;\n }\n const next = path.dirname(current);\n if (next === current) break;\n current = next;\n } while (current);\n throw new Error('Root not found');\n}\n"],"names":["fs","path","isWindows","process","platform","test","env","OSTYPE","existsSync","accessSync","statSync","_","fileURLToPath","input","urlString","href","indexOf","filepath","slice","charAt","decodeURIComponent","split","join","moduleRoot","dir","options","name","undefined","current","packagePath","keyExists","JSON","parse","readFileSync","next","dirname","Error"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AAExB,MAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAE3F,MAAMC,aAAa,CAACH;IAClB,IAAI;QACDL,CAAAA,GAAGS,UAAU,IAAIT,GAAGU,QAAQ,AAAD,EAAGL;QAC/B,OAAO;IACT,EAAE,OAAOM,GAAG;QACV,OAAO;IACT;AACF;AAIA;;;;CAIC,GACD,MAAMC,gBAAgB,CAACC;IACrB,wCAAwC;IACxC,MAAMC,YAAY,OAAOD,UAAU,WAAWA,QAAQA,MAAME,IAAI;IAEhE,6DAA6D;IAC7D,IAAID,UAAUE,OAAO,CAAC,eAAe,GAAG;QACtC,OAAOF,WAAW,+BAA+B;IACnD;IAEA,wBAAwB;IACxB,IAAIG,WAAWH,UAAUI,KAAK,CAAC;IAE/B,6CAA6C;IAC7C,IAAID,SAASE,MAAM,CAAC,OAAO,OAAOF,SAASE,MAAM,CAAC,OAAO,KAAK;QAC5DF,WAAWA,SAASC,KAAK,CAAC;IAC5B;IAEA,qDAAqD;IACrDD,WAAWG,mBAAmBH;IAE9B,oDAAoD;IACpD,IAAIf,WAAW;QACbe,WAAWA,SAASI,KAAK,CAAC,KAAKC,IAAI,CAAC;IACtC;IAEA,OAAOL;AACT;AAIA,cAAc,aAAa;AAC3B,eAAe,SAASM,WAAWC,GAAa,EAAEC,UAAuB,CAAC,CAAC;IACzE,MAAMC,OAAOD,QAAQC,IAAI,KAAKC,YAAY,iBAAiBF,QAAQC,IAAI;IAEvE,wCAAwC;IACxC,IAAIE,UAAUhB,cAAcY;IAC5B,GAAG;QACD,MAAMK,cAAc5B,KAAKqB,IAAI,CAACM,SAASF;QACvC,IAAIlB,WAAWqB,cAAc;YAC3B,IAAI,CAACJ,QAAQK,SAAS,EAAE,OAAOF;YAC/B,IAAIG,KAAKC,KAAK,CAAChC,GAAGiC,YAAY,CAACJ,aAAa,QAAQ,CAACJ,QAAQK,SAAS,CAAC,KAAKH,WAAW,OAAOC;QAChG;QACA,MAAMM,OAAOjC,KAAKkC,OAAO,CAACP;QAC1B,IAAIM,SAASN,SAAS;QACtBA,UAAUM;IACZ,QAASN,QAAS;IAClB,MAAM,IAAIQ,MAAM;AAClB"} | ||
| {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/module-root-sync/src/index.ts"],"sourcesContent":["import fs from 'fs';\nimport path from 'path';\n\nconst isWindows = process.platform === 'win32' || /^(msys|cygwin)$/.test(process.env.OSTYPE);\n\nconst existsSync = (test: string): boolean => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\n\nimport type { PathLike } from './types.ts';\n\n/**\n * Convert file:// URL to filesystem path\n * Node 0.8 compatible (no url.fileURLToPath available)\n * Accepts string paths, string file URLs, or URL objects\n */\nconst fileURLToPath = (input: PathLike): string => {\n // Handle URL objects by extracting href\n const urlString = typeof input === 'string' ? input : input.href;\n\n // Check if it's a file URL (use indexOf for Node 0.8 compat)\n if (urlString.indexOf('file://') !== 0) {\n return urlString; // Not a file URL, return as-is\n }\n\n // Remove file:// prefix\n let filepath = urlString.slice(7);\n\n // Handle Windows: file:///C:/path -> C:/path\n if (filepath.charAt(0) === '/' && filepath.charAt(2) === ':') {\n filepath = filepath.slice(1);\n }\n\n // Decode URL-encoded characters (%20 -> space, etc.)\n filepath = decodeURIComponent(filepath);\n\n // Convert forward slashes to backslashes on Windows\n if (isWindows) {\n filepath = filepath.split('/').join('\\\\');\n }\n\n return filepath;\n};\n\nimport type { RootOptions } from './types.ts';\n\nexport * from './types.ts';\n\n/**\n * Check if a package.json is synthetic (no `name` field).\n * Synthetic package.json files typically only contain `type` for module system hints.\n */\nconst isSyntheticPackage = (filePath: string): boolean => {\n try {\n const content = JSON.parse(fs.readFileSync(filePath, 'utf8'));\n return !('name' in content);\n } catch (_) {\n return false;\n }\n};\n\nexport default function moduleRoot(dir: PathLike, options: RootOptions = {}) {\n const name = options.name === undefined ? 'package.json' : options.name;\n const isPackageJson = name === 'package.json';\n const skipSynthetic = isPackageJson && !options.includeSynthetic;\n\n // Convert file:// URL to path if needed\n let current = fileURLToPath(dir);\n do {\n const filePath = path.join(current, name);\n if (existsSync(filePath)) {\n // Skip synthetic package.json files unless includeSynthetic is true\n if (!skipSynthetic || !isSyntheticPackage(filePath)) {\n return current;\n }\n }\n const next = path.dirname(current);\n if (next === current) break;\n current = next;\n } while (current);\n throw new Error('Root not found');\n}\n"],"names":["fs","path","isWindows","process","platform","test","env","OSTYPE","existsSync","accessSync","statSync","_","fileURLToPath","input","urlString","href","indexOf","filepath","slice","charAt","decodeURIComponent","split","join","isSyntheticPackage","filePath","content","JSON","parse","readFileSync","moduleRoot","dir","options","name","undefined","isPackageJson","skipSynthetic","includeSynthetic","current","next","dirname","Error"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AAExB,MAAMC,YAAYC,QAAQC,QAAQ,KAAK,WAAW,kBAAkBC,IAAI,CAACF,QAAQG,GAAG,CAACC,MAAM;AAE3F,MAAMC,aAAa,CAACH;IAClB,IAAI;QACDL,CAAAA,GAAGS,UAAU,IAAIT,GAAGU,QAAQ,AAAD,EAAGL;QAC/B,OAAO;IACT,EAAE,OAAOM,GAAG;QACV,OAAO;IACT;AACF;AAIA;;;;CAIC,GACD,MAAMC,gBAAgB,CAACC;IACrB,wCAAwC;IACxC,MAAMC,YAAY,OAAOD,UAAU,WAAWA,QAAQA,MAAME,IAAI;IAEhE,6DAA6D;IAC7D,IAAID,UAAUE,OAAO,CAAC,eAAe,GAAG;QACtC,OAAOF,WAAW,+BAA+B;IACnD;IAEA,wBAAwB;IACxB,IAAIG,WAAWH,UAAUI,KAAK,CAAC;IAE/B,6CAA6C;IAC7C,IAAID,SAASE,MAAM,CAAC,OAAO,OAAOF,SAASE,MAAM,CAAC,OAAO,KAAK;QAC5DF,WAAWA,SAASC,KAAK,CAAC;IAC5B;IAEA,qDAAqD;IACrDD,WAAWG,mBAAmBH;IAE9B,oDAAoD;IACpD,IAAIf,WAAW;QACbe,WAAWA,SAASI,KAAK,CAAC,KAAKC,IAAI,CAAC;IACtC;IAEA,OAAOL;AACT;AAIA,cAAc,aAAa;AAE3B;;;CAGC,GACD,MAAMM,qBAAqB,CAACC;IAC1B,IAAI;QACF,MAAMC,UAAUC,KAAKC,KAAK,CAAC3B,GAAG4B,YAAY,CAACJ,UAAU;QACrD,OAAO,CAAE,CAAA,UAAUC,OAAM;IAC3B,EAAE,OAAOd,GAAG;QACV,OAAO;IACT;AACF;AAEA,eAAe,SAASkB,WAAWC,GAAa,EAAEC,UAAuB,CAAC,CAAC;IACzE,MAAMC,OAAOD,QAAQC,IAAI,KAAKC,YAAY,iBAAiBF,QAAQC,IAAI;IACvE,MAAME,gBAAgBF,SAAS;IAC/B,MAAMG,gBAAgBD,iBAAiB,CAACH,QAAQK,gBAAgB;IAEhE,wCAAwC;IACxC,IAAIC,UAAUzB,cAAckB;IAC5B,GAAG;QACD,MAAMN,WAAWvB,KAAKqB,IAAI,CAACe,SAASL;QACpC,IAAIxB,WAAWgB,WAAW;YACxB,oEAAoE;YACpE,IAAI,CAACW,iBAAiB,CAACZ,mBAAmBC,WAAW;gBACnD,OAAOa;YACT;QACF;QACA,MAAMC,OAAOrC,KAAKsC,OAAO,CAACF;QAC1B,IAAIC,SAASD,SAAS;QACtBA,UAAUC;IACZ,QAASD,QAAS;IAClB,MAAM,IAAIG,MAAM;AAClB"} |
| export interface RootOptions { | ||
| name?: string; | ||
| keyExists?: string; | ||
| /** Include synthetic package.json files (only `type` field, no `name`). Default: false */ | ||
| includeSynthetic?: boolean; | ||
| } | ||
| /** A filesystem path string or file:// URL (string or URL object) */ | ||
| export type PathLike = string | URL; |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/module-root-sync/src/types.ts"],"sourcesContent":["export interface RootOptions {\n name?: string;\n keyExists?: string;\n}\n\n/** A filesystem path string or file:// URL (string or URL object) */\nexport type PathLike = string | URL;\n"],"names":[],"mappings":"AAKA,mEAAmE,GACnE,WAAoC"} | ||
| {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/module-root-sync/src/types.ts"],"sourcesContent":["export interface RootOptions {\n name?: string;\n /** Include synthetic package.json files (only `type` field, no `name`). Default: false */\n includeSynthetic?: boolean;\n}\n\n/** A filesystem path string or file:// URL (string or URL object) */\nexport type PathLike = string | URL;\n"],"names":[],"mappings":"AAMA,mEAAmE,GACnE,WAAoC"} |
+1
-1
| { | ||
| "name": "module-root-sync", | ||
| "version": "1.2.8", | ||
| "version": "2.0.0", | ||
| "description": "Finds the directory that the modules resides in", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
+38
-1
| ## module-root-sync | ||
| Finds the directory that the modules resides in. | ||
| Finds the directory that the module resides in. | ||
@@ -9,7 +9,44 @@ ```typescript | ||
| const root = moduleRoot(import.meta.filename); | ||
| ``` | ||
| ### Options | ||
| ```typescript | ||
| interface RootOptions { | ||
| name?: string; // Custom marker filename (default: 'package.json') | ||
| includeSynthetic?: boolean; // Include synthetic package.json files (default: false) | ||
| } | ||
| ``` | ||
| ### Synthetic package.json Detection | ||
| By default, `moduleRoot` skips "synthetic" package.json files that only exist to specify the module system (e.g., `{ "type": "module" }`). These are commonly found in `dist/esm` or `dist/cjs` directories. | ||
| A package.json is considered synthetic if it has no `name` field. | ||
| ```typescript | ||
| // Default: skips synthetic package.json, finds real one | ||
| const root = moduleRoot(import.meta.filename); | ||
| // Include synthetic package.json files | ||
| const root = moduleRoot(import.meta.filename, { includeSynthetic: true }); | ||
| // Custom marker file (synthetic detection only applies to package.json) | ||
| const root = moduleRoot(import.meta.filename, { name: 'tsconfig.json' }); | ||
| ``` | ||
| ### Migration from v1.x | ||
| The `keyExists` option has been removed. If you were using `keyExists: 'name'` to skip synthetic packages, this is now the default behavior. | ||
| ```typescript | ||
| // v1.x | ||
| const root = moduleRoot(dir, { keyExists: 'name' }); | ||
| // v2.x (same behavior, now default) | ||
| const root = moduleRoot(dir); | ||
| ``` | ||
| ### Documentation | ||
| [API Docs](https://kmalakoff.github.io/module-root-sync/) |
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
21653
23.93%192
20%52
246.67%