module-root-sync
Advanced tools
@@ -40,3 +40,4 @@ "use strict"; | ||
| }; | ||
| function moduleRoot(dir, options) { | ||
| function moduleRoot(dir) { | ||
| var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}; | ||
| var current = dir; | ||
@@ -46,3 +47,3 @@ do { | ||
| if (existsSync(packagePath)) { | ||
| if (!options || options.keyExists === undefined) return current; | ||
| if (!options.keyExists) return current; | ||
| if (JSON.parse(_fs.default.readFileSync(packagePath, 'utf8'))[options.keyExists] !== undefined) return current; | ||
@@ -49,0 +50,0 @@ } |
@@ -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';\nconst existsSync = (test) => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\nexport * from './types';\nexport default function moduleRoot(dir, options) {\n let current = dir;\n do {\n const packagePath = path.join(current, 'package.json');\n if (existsSync(packagePath)) {\n if (!options || options.keyExists === undefined) 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","existsSync","test","fs","accessSync","statSync","_","dir","options","current","packagePath","path","join","keyExists","undefined","JSON","parse","readFileSync","next","dirname","Error"],"mappings":";;;;+BAWA;;;eAAwBA;;;yDAXT;2DACE;qBASH;;;;;;;;;;;;;;;;;;;AARd,IAAMC,aAAa,SAACC;IAClB,IAAI;QACDC,CAAAA,WAAE,CAACC,UAAU,IAAID,WAAE,CAACE,QAAQ,AAAD,EAAGH;QAC/B,OAAO;IACT,EAAE,OAAOI,GAAG;QACV,OAAO;IACT;AACF;AAEe,SAASN,WAAWO,GAAG,EAAEC,OAAO;IAC7C,IAAIC,UAAUF;IACd,GAAG;QACD,IAAMG,cAAcC,aAAI,CAACC,IAAI,CAACH,SAAS;QACvC,IAAIR,WAAWS,cAAc;YAC3B,IAAI,CAACF,WAAWA,QAAQK,SAAS,KAAKC,WAAW,OAAOL;YACxD,IAAIM,KAAKC,KAAK,CAACb,WAAE,CAACc,YAAY,CAACP,aAAa,QAAQ,CAACF,QAAQK,SAAS,CAAC,KAAKC,WAAW,OAAOL;QAChG;QACA,IAAMS,OAAOP,aAAI,CAACQ,OAAO,CAACV;QAC1B,IAAIS,SAAST,SAAS;QACtBA,UAAUS;IACZ,QAAST,SAAS;IAClB,MAAM,IAAIW,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';\nconst existsSync = (test) => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\nimport type { RootOptions } from './types';\nexport * from './types';\nexport default function moduleRoot(dir: string, options: RootOptions = {}) {\n let current = dir;\n do {\n const packagePath = path.join(current, 'package.json');\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","existsSync","test","fs","accessSync","statSync","_","dir","options","current","packagePath","path","join","keyExists","JSON","parse","readFileSync","undefined","next","dirname","Error"],"mappings":";;;;+BAYA;;;eAAwBA;;;yDAZT;2DACE;qBAUH;;;;;;;;;;;;;;;;;;;AATd,IAAMC,aAAa,SAACC;IAClB,IAAI;QACDC,CAAAA,WAAE,CAACC,UAAU,IAAID,WAAE,CAACE,QAAQ,AAAD,EAAGH;QAC/B,OAAO;IACT,EAAE,OAAOI,GAAG;QACV,OAAO;IACT;AACF;AAGe,SAASN,WAAWO,GAAW;QAAEC,UAAAA,iEAAuB,CAAC;IACtE,IAAIC,UAAUF;IACd,GAAG;QACD,IAAMG,cAAcC,aAAI,CAACC,IAAI,CAACH,SAAS;QACvC,IAAIR,WAAWS,cAAc;YAC3B,IAAI,CAACF,QAAQK,SAAS,EAAE,OAAOJ;YAC/B,IAAIK,KAAKC,KAAK,CAACZ,WAAE,CAACa,YAAY,CAACN,aAAa,QAAQ,CAACF,QAAQK,SAAS,CAAC,KAAKI,WAAW,OAAOR;QAChG;QACA,IAAMS,OAAOP,aAAI,CAACQ,OAAO,CAACV;QAC1B,IAAIS,SAAST,SAAS;QACtBA,UAAUS;IACZ,QAAST,SAAS;IAClB,MAAM,IAAIW,MAAM;AAClB"} |
@@ -12,3 +12,3 @@ import fs from 'fs'; | ||
| export * from './types.mjs'; | ||
| export default function moduleRoot(dir, options) { | ||
| export default function moduleRoot(dir, options = {}) { | ||
| let current = dir; | ||
@@ -18,3 +18,3 @@ do { | ||
| if (existsSync(packagePath)) { | ||
| if (!options || options.keyExists === undefined) return current; | ||
| if (!options.keyExists) return current; | ||
| if (JSON.parse(fs.readFileSync(packagePath, 'utf8'))[options.keyExists] !== undefined) return current; | ||
@@ -21,0 +21,0 @@ } |
@@ -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';\nconst existsSync = (test) => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\nexport * from './types';\nexport default function moduleRoot(dir, options) {\n let current = dir;\n do {\n const packagePath = path.join(current, 'package.json');\n if (existsSync(packagePath)) {\n if (!options || options.keyExists === undefined) 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","existsSync","test","accessSync","statSync","_","moduleRoot","dir","options","current","packagePath","join","keyExists","undefined","JSON","parse","readFileSync","next","dirname","Error"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,MAAMC,aAAa,CAACC;IAClB,IAAI;QACDH,CAAAA,GAAGI,UAAU,IAAIJ,GAAGK,QAAQ,AAAD,EAAGF;QAC/B,OAAO;IACT,EAAE,OAAOG,GAAG;QACV,OAAO;IACT;AACF;AACA,cAAc,UAAU;AACxB,eAAe,SAASC,WAAWC,GAAG,EAAEC,OAAO;IAC7C,IAAIC,UAAUF;IACd,GAAG;QACD,MAAMG,cAAcV,KAAKW,IAAI,CAACF,SAAS;QACvC,IAAIR,WAAWS,cAAc;YAC3B,IAAI,CAACF,WAAWA,QAAQI,SAAS,KAAKC,WAAW,OAAOJ;YACxD,IAAIK,KAAKC,KAAK,CAAChB,GAAGiB,YAAY,CAACN,aAAa,QAAQ,CAACF,QAAQI,SAAS,CAAC,KAAKC,WAAW,OAAOJ;QAChG;QACA,MAAMQ,OAAOjB,KAAKkB,OAAO,CAACT;QAC1B,IAAIQ,SAASR,SAAS;QACtBA,UAAUQ;IACZ,QAASR,QAAS;IAClB,MAAM,IAAIU,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';\nconst existsSync = (test) => {\n try {\n (fs.accessSync || fs.statSync)(test);\n return true;\n } catch (_) {\n return false;\n }\n};\nimport type { RootOptions } from './types';\nexport * from './types';\nexport default function moduleRoot(dir: string, options: RootOptions = {}) {\n let current = dir;\n do {\n const packagePath = path.join(current, 'package.json');\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","existsSync","test","accessSync","statSync","_","moduleRoot","dir","options","current","packagePath","join","keyExists","JSON","parse","readFileSync","undefined","next","dirname","Error"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AACxB,MAAMC,aAAa,CAACC;IAClB,IAAI;QACDH,CAAAA,GAAGI,UAAU,IAAIJ,GAAGK,QAAQ,AAAD,EAAGF;QAC/B,OAAO;IACT,EAAE,OAAOG,GAAG;QACV,OAAO;IACT;AACF;AAEA,cAAc,UAAU;AACxB,eAAe,SAASC,WAAWC,GAAW,EAAEC,UAAuB,CAAC,CAAC;IACvE,IAAIC,UAAUF;IACd,GAAG;QACD,MAAMG,cAAcV,KAAKW,IAAI,CAACF,SAAS;QACvC,IAAIR,WAAWS,cAAc;YAC3B,IAAI,CAACF,QAAQI,SAAS,EAAE,OAAOH;YAC/B,IAAII,KAAKC,KAAK,CAACf,GAAGgB,YAAY,CAACL,aAAa,QAAQ,CAACF,QAAQI,SAAS,CAAC,KAAKI,WAAW,OAAOP;QAChG;QACA,MAAMQ,OAAOjB,KAAKkB,OAAO,CAACT;QAC1B,IAAIQ,SAASR,SAAS;QACtBA,UAAUQ;IACZ,QAASR,QAAS;IAClB,MAAM,IAAIU,MAAM;AAClB"} |
@@ -0,2 +1,3 @@ | ||
| import type { RootOptions } from './types'; | ||
| export * from './types'; | ||
| export default function moduleRoot(dir: any, options: any): any; | ||
| export default function moduleRoot(dir: string, options?: RootOptions): string; |
+1
-1
| { | ||
| "name": "module-root-sync", | ||
| "version": "1.0.4", | ||
| "version": "1.1.0", | ||
| "description": "Finds the directory that the modules resides in", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
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
9933
1.88%90
2.27%