+16
-14
@@ -137,12 +137,13 @@ "use strict"; | ||
| validateFilePath(filepath); | ||
| const { base, ext } = path.parse(filepath); | ||
| const absPath = path.resolve(process.cwd(), filepath); | ||
| const { base, ext } = path.parse(absPath); | ||
| const loaderKey = ext || 'noExt'; | ||
| const loader = loaders[loaderKey]; | ||
| validateLoader(loader, loaderKey); | ||
| const content = String(await fsReadFileAsync(filepath)); | ||
| const content = String(await fsReadFileAsync(absPath)); | ||
| if (base === 'package.json') { | ||
| const pkg = await loader(filepath, content); | ||
| const pkg = await loader(absPath, content); | ||
| return transform({ | ||
| config: getPackageProp(packageProp, pkg), | ||
| filepath, | ||
| filepath: absPath, | ||
| }); | ||
@@ -152,3 +153,3 @@ } | ||
| config: null, | ||
| filepath, | ||
| filepath: absPath, | ||
| }; | ||
@@ -159,3 +160,3 @@ const isEmpty = content.trim() === ''; | ||
| config: undefined, | ||
| filepath, | ||
| filepath: absPath, | ||
| isEmpty: true, | ||
@@ -165,3 +166,3 @@ }); | ||
| ? undefined | ||
| : await loader(filepath, content); | ||
| : await loader(absPath, content); | ||
| return transform(isEmpty ? { ...result, isEmpty, config: undefined } : result); | ||
@@ -221,12 +222,13 @@ }, | ||
| validateFilePath(filepath); | ||
| const { base, ext } = path.parse(filepath); | ||
| const absPath = path.resolve(process.cwd(), filepath); | ||
| const { base, ext } = path.parse(absPath); | ||
| const loaderKey = ext || 'noExt'; | ||
| const loader = loaders[loaderKey]; | ||
| validateLoader(loader, loaderKey); | ||
| const content = String(fs.readFileSync(filepath)); | ||
| const content = String(fs.readFileSync(absPath)); | ||
| if (base === 'package.json') { | ||
| const pkg = loader(filepath, content); | ||
| const pkg = loader(absPath, content); | ||
| return transform({ | ||
| config: getPackageProp(packageProp, pkg), | ||
| filepath, | ||
| filepath: absPath, | ||
| }); | ||
@@ -236,3 +238,3 @@ } | ||
| config: null, | ||
| filepath, | ||
| filepath: absPath, | ||
| }; | ||
@@ -242,7 +244,7 @@ const isEmpty = content.trim() === ''; | ||
| return transform({ | ||
| filepath, | ||
| filepath: absPath, | ||
| config: undefined, | ||
| isEmpty: true, | ||
| }); | ||
| result.config = isEmpty ? undefined : loader(filepath, content); | ||
| result.config = isEmpty ? undefined : loader(absPath, content); | ||
| return transform(isEmpty ? { ...result, isEmpty, config: undefined } : result); | ||
@@ -249,0 +251,0 @@ }, |
+11
-11
| { | ||
| "name": "lilconfig", | ||
| "version": "2.0.3", | ||
| "version": "2.0.4", | ||
| "description": "A zero-dependency alternative to cosmiconfig", | ||
@@ -32,14 +32,14 @@ "main": "dist/index.js", | ||
| "devDependencies": { | ||
| "@types/jest": "^26.0.23", | ||
| "@types/jest": "^27.0.2", | ||
| "@types/node": "^14.17.2", | ||
| "@typescript-eslint/eslint-plugin": "^4.26.0", | ||
| "@typescript-eslint/parser": "^4.26.0", | ||
| "cosmiconfig": "7.0.0", | ||
| "eslint": "^7.28.0", | ||
| "@typescript-eslint/eslint-plugin": "^5.3.0", | ||
| "@typescript-eslint/parser": "^5.3.0", | ||
| "cosmiconfig": "^7.0.1", | ||
| "eslint": "^8.1.0", | ||
| "eslint-config-prettier": "^8.3.0", | ||
| "eslint-plugin-prettier": "^3.4.0", | ||
| "jest": "^26.6.3", | ||
| "prettier": "^2.3.1", | ||
| "ts-jest": "^26.5.6", | ||
| "typescript": "^4.3.2" | ||
| "eslint-plugin-prettier": "^4.0.0", | ||
| "jest": "^27.3.1", | ||
| "prettier": "^2.4.1", | ||
| "ts-jest": "^27.0.7", | ||
| "typescript": "^4.4.4" | ||
| }, | ||
@@ -46,0 +46,0 @@ "engines": { |
+7
-6
@@ -70,11 +70,12 @@ # Lilconfig ⚙️ | ||
| function loadYaml(filepath, content) { | ||
| return yaml.parse(content); | ||
| } | ||
| const options = { | ||
| loaders: { | ||
| '.yaml': (filepath, content) => { | ||
| return yaml.parse(content); | ||
| }, | ||
| '.yaml': loadYaml, | ||
| '.yml': loadYaml, | ||
| // loader for files with no extension | ||
| noExt: (filepath, content) => { | ||
| return yaml.parse(content); | ||
| } | ||
| noExt: loadYaml | ||
| } | ||
@@ -81,0 +82,0 @@ }; |
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
14779
0.99%285
0.71%94
1.08%