@rushstack/node-core-library
Advanced tools
Comparing version 3.50.1 to 3.50.2
@@ -8,5 +8,5 @@ // This file is read by tools that parse documentation comments conforming to the TSDoc standard. | ||
"packageName": "@microsoft/api-extractor", | ||
"packageVersion": "7.28.0" | ||
"packageVersion": "7.29.0" | ||
} | ||
] | ||
} |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import * as child_process from 'child_process'; | ||
@@ -3,0 +4,0 @@ import { EnvironmentMap } from './EnvironmentMap'; |
/// <reference types="node" /> | ||
/// <reference types="node" /> | ||
import * as fs from 'fs'; | ||
@@ -3,0 +4,0 @@ import { NewlineKind, Encoding } from './Text'; |
@@ -134,4 +134,10 @@ import { IPackageJson, INodePackageJson } from './IPackageJson'; | ||
loadNodePackageJson(jsonFilename: string): INodePackageJson; | ||
private _loadPackageJsonInner; | ||
/** | ||
* Try to load a package.json file as an INodePackageJson, | ||
* returning undefined if the found file does not contain a `name` field. | ||
*/ | ||
private _tryLoadNodePackageJsonInner; | ||
private _tryGetPackageFolderFor; | ||
} | ||
//# sourceMappingURL=PackageJsonLookup.d.ts.map |
@@ -212,8 +212,48 @@ "use strict"; | ||
loadNodePackageJson(jsonFilename) { | ||
if (!FileSystem_1.FileSystem.exists(jsonFilename)) { | ||
throw new Error(`Input file not found: ${jsonFilename}`); | ||
return this._loadPackageJsonInner(jsonFilename); | ||
} | ||
_loadPackageJsonInner(jsonFilename, errorsToIgnore) { | ||
const loadResult = this._tryLoadNodePackageJsonInner(jsonFilename); | ||
if (loadResult.error && (errorsToIgnore === null || errorsToIgnore === void 0 ? void 0 : errorsToIgnore.has(loadResult.error))) { | ||
return undefined; | ||
} | ||
switch (loadResult.error) { | ||
case 'FILE_NOT_FOUND': { | ||
throw new Error(`Input file not found: ${jsonFilename}`); | ||
} | ||
case 'MISSING_NAME_FIELD': { | ||
throw new Error(`Error reading "${jsonFilename}":\n The required field "name" was not found`); | ||
} | ||
case 'OTHER_ERROR': { | ||
throw loadResult.errorObject; | ||
} | ||
default: { | ||
return loadResult.packageJson; | ||
} | ||
} | ||
} | ||
/** | ||
* Try to load a package.json file as an INodePackageJson, | ||
* returning undefined if the found file does not contain a `name` field. | ||
*/ | ||
_tryLoadNodePackageJsonInner(jsonFilename) { | ||
// Since this will be a cache key, follow any symlinks and get an absolute path | ||
// to minimize duplication. (Note that duplication can still occur due to e.g. character case.) | ||
const normalizedFilePath = FileSystem_1.FileSystem.getRealPath(jsonFilename); | ||
let normalizedFilePath; | ||
try { | ||
normalizedFilePath = FileSystem_1.FileSystem.getRealPath(jsonFilename); | ||
} | ||
catch (e) { | ||
if (FileSystem_1.FileSystem.isNotExistError(e)) { | ||
return { | ||
error: 'FILE_NOT_FOUND' | ||
}; | ||
} | ||
else { | ||
return { | ||
error: 'OTHER_ERROR', | ||
errorObject: e | ||
}; | ||
} | ||
} | ||
let packageJson = this._packageJsonCache.get(normalizedFilePath); | ||
@@ -225,3 +265,5 @@ if (!packageJson) { | ||
if (!loadedPackageJson.name) { | ||
throw new Error(`Error reading "${jsonFilename}":\n The required field "name" was not found`); | ||
return { | ||
error: 'MISSING_NAME_FIELD' | ||
}; | ||
} | ||
@@ -253,3 +295,5 @@ if (this._loadExtraFields) { | ||
} | ||
return packageJson; | ||
return { | ||
packageJson | ||
}; | ||
} | ||
@@ -263,4 +307,6 @@ // Recursive part of the algorithm from tryGetPackageFolderFor() | ||
} | ||
// Is resolvedFileOrFolderPath itself a folder with a package.json file? If so, return it. | ||
if (FileSystem_1.FileSystem.exists(path.join(resolvedFileOrFolderPath, Constants_1.FileConstants.PackageJson))) { | ||
// Is resolvedFileOrFolderPath itself a folder with a valid package.json file? If so, return it. | ||
const packageJsonFilePath = `${resolvedFileOrFolderPath}/${Constants_1.FileConstants.PackageJson}`; | ||
const packageJson = this._loadPackageJsonInner(packageJsonFilePath, new Set(['FILE_NOT_FOUND', 'MISSING_NAME_FIELD'])); | ||
if (packageJson) { | ||
this._packageFolderCache.set(resolvedFileOrFolderPath, resolvedFileOrFolderPath); | ||
@@ -267,0 +313,0 @@ return resolvedFileOrFolderPath; |
{ | ||
"name": "@rushstack/node-core-library", | ||
"version": "3.50.1", | ||
"version": "3.50.2", | ||
"description": "Core libraries that every NodeJS toolchain project should use", | ||
@@ -26,4 +26,4 @@ "main": "lib/index.js", | ||
"@rushstack/eslint-config": "3.0.0", | ||
"@rushstack/heft": "0.45.14", | ||
"@rushstack/heft-node-rig": "1.9.15", | ||
"@rushstack/heft": "0.47.0", | ||
"@rushstack/heft-node-rig": "1.10.0", | ||
"@types/fs-extra": "7.0.0", | ||
@@ -30,0 +30,0 @@ "@types/heft-jest": "1.0.1", |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1015797
13324