module-root-sync
Advanced tools
@@ -42,5 +42,6 @@ "use strict"; | ||
| var options = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {}; | ||
| var name = options.name === undefined ? 'package.json' : options.name; | ||
| var current = dir; | ||
| do { | ||
| var packagePath = _path.default.join(current, 'package.json'); | ||
| var packagePath = _path.default.join(current, name); | ||
| if (existsSync(packagePath)) { | ||
@@ -47,0 +48,0 @@ if (!options.keyExists) return 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 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 { RootOptions } from './types.ts';\n\nexport * from './types.ts';\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":";;;;+BAeA;;;eAAwBA;;;yDAfT;2DACE;qBAaH;;;;;;;;;;;;;;;;;;;AAXd,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;AAKe,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"} | ||
| {"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 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 { RootOptions } from './types.ts';\n\nexport * from './types.ts';\nexport default function moduleRoot(dir: string, options: RootOptions = {}) {\n const name = options.name === undefined ? 'package.json' : options.name;\n\n let current = 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","existsSync","test","fs","accessSync","statSync","_","dir","options","name","undefined","current","packagePath","path","join","keyExists","JSON","parse","readFileSync","next","dirname","Error"],"mappings":";;;;+BAeA;;;eAAwBA;;;yDAfT;2DACE;qBAaH;;;;;;;;;;;;;;;;;;;AAXd,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;AAKe,SAASN,WAAWO,GAAW;QAAEC,UAAAA,iEAAuB,CAAC;IACtE,IAAMC,OAAOD,QAAQC,IAAI,KAAKC,YAAY,iBAAiBF,QAAQC,IAAI;IAEvE,IAAIE,UAAUJ;IACd,GAAG;QACD,IAAMK,cAAcC,aAAI,CAACC,IAAI,CAACH,SAASF;QACvC,IAAIR,WAAWW,cAAc;YAC3B,IAAI,CAACJ,QAAQO,SAAS,EAAE,OAAOJ;YAC/B,IAAIK,KAAKC,KAAK,CAACd,WAAE,CAACe,YAAY,CAACN,aAAa,QAAQ,CAACJ,QAAQO,SAAS,CAAC,KAAKL,WAAW,OAAOC;QAChG;QACA,IAAMQ,OAAON,aAAI,CAACO,OAAO,CAACT;QAC1B,IAAIQ,SAASR,SAAS;QACtBA,UAAUQ;IACZ,QAASR,SAAS;IAClB,MAAM,IAAIU,MAAM;AAClB"} |
| export interface RootOptions { | ||
| name?: string; | ||
| keyExists?: string; | ||
| } |
| export interface RootOptions { | ||
| name?: string; | ||
| keyExists?: string; | ||
| } |
@@ -13,5 +13,6 @@ import fs from 'fs'; | ||
| export default function moduleRoot(dir, options = {}) { | ||
| const name = options.name === undefined ? 'package.json' : options.name; | ||
| let current = dir; | ||
| do { | ||
| const packagePath = path.join(current, 'package.json'); | ||
| const packagePath = path.join(current, name); | ||
| if (existsSync(packagePath)) { | ||
@@ -18,0 +19,0 @@ if (!options.keyExists) return 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 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 { RootOptions } from './types.ts';\n\nexport * from './types.ts';\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;AAExB,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;AAIA,cAAc,aAAa;AAC3B,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"} | ||
| {"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 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 { RootOptions } from './types.ts';\n\nexport * from './types.ts';\nexport default function moduleRoot(dir: string, options: RootOptions = {}) {\n const name = options.name === undefined ? 'package.json' : options.name;\n\n let current = 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","existsSync","test","accessSync","statSync","_","moduleRoot","dir","options","name","undefined","current","packagePath","join","keyExists","JSON","parse","readFileSync","next","dirname","Error"],"mappings":"AAAA,OAAOA,QAAQ,KAAK;AACpB,OAAOC,UAAU,OAAO;AAExB,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;AAIA,cAAc,aAAa;AAC3B,eAAe,SAASC,WAAWC,GAAW,EAAEC,UAAuB,CAAC,CAAC;IACvE,MAAMC,OAAOD,QAAQC,IAAI,KAAKC,YAAY,iBAAiBF,QAAQC,IAAI;IAEvE,IAAIE,UAAUJ;IACd,GAAG;QACD,MAAMK,cAAcZ,KAAKa,IAAI,CAACF,SAASF;QACvC,IAAIR,WAAWW,cAAc;YAC3B,IAAI,CAACJ,QAAQM,SAAS,EAAE,OAAOH;YAC/B,IAAII,KAAKC,KAAK,CAACjB,GAAGkB,YAAY,CAACL,aAAa,QAAQ,CAACJ,QAAQM,SAAS,CAAC,KAAKJ,WAAW,OAAOC;QAChG;QACA,MAAMO,OAAOlB,KAAKmB,OAAO,CAACR;QAC1B,IAAIO,SAASP,SAAS;QACtBA,UAAUO;IACZ,QAASP,QAAS;IAClB,MAAM,IAAIS,MAAM;AAClB"} |
| export interface RootOptions { | ||
| name?: string; | ||
| keyExists?: string; | ||
| } |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"sources":["/Users/kevin/Dev/OpenSource/node/module-root-sync/src/types.ts"],"sourcesContent":["export interface RootOptions {\n keyExists?: string;\n}\n"],"names":[],"mappings":"AAAA,WAEC"} | ||
| {"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"],"names":[],"mappings":"AAAA,WAGC"} |
+1
-1
| { | ||
| "name": "module-root-sync", | ||
| "version": "1.1.15", | ||
| "version": "1.2.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
10567
4.73%100
4.17%