@rushstack/rig-package
Advanced tools
Comparing version
@@ -5,2 +5,14 @@ { | ||
{ | ||
"version": "0.3.0", | ||
"tag": "@rushstack/rig-package_v0.3.0", | ||
"date": "Fri, 27 Aug 2021 00:07:25 GMT", | ||
"comments": { | ||
"minor": [ | ||
{ | ||
"comment": "Cache rig.json reads" | ||
} | ||
] | ||
} | ||
}, | ||
{ | ||
"version": "0.2.13", | ||
@@ -7,0 +19,0 @@ "tag": "@rushstack/rig-package_v0.2.13", |
# Change Log - @rushstack/rig-package | ||
This log was last generated on Mon, 12 Jul 2021 23:08:26 GMT and should not be manually modified. | ||
This log was last generated on Fri, 27 Aug 2021 00:07:25 GMT and should not be manually modified. | ||
## 0.3.0 | ||
Fri, 27 Aug 2021 00:07:25 GMT | ||
### Minor changes | ||
- Cache rig.json reads | ||
## 0.2.13 | ||
@@ -6,0 +13,0 @@ Mon, 12 Jul 2021 23:08:26 GMT |
@@ -12,3 +12,2 @@ /** | ||
/** | ||
@@ -28,2 +27,6 @@ * Options for {@link RigConfig.loadForProjectFolder}. | ||
overrideRigJsonObject?: IRigConfigJson; | ||
/** | ||
* If specified, force a fresh load instead of returning a cached entry, if one existed. | ||
*/ | ||
bypassCache?: boolean; | ||
} | ||
@@ -79,2 +82,3 @@ | ||
private static _jsonSchemaObject; | ||
private static readonly _configCache; | ||
/** | ||
@@ -157,2 +161,3 @@ * The project folder path that was passed to {@link RigConfig.loadForProjectFolder}, | ||
static loadForProjectFolderAsync(options: ILoadForProjectFolderOptions): Promise<RigConfig>; | ||
private static _handleConfigError; | ||
/** | ||
@@ -159,0 +164,0 @@ * Performs Node.js module resolution to locate the rig package folder, then returns the absolute path |
@@ -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.16.1" | ||
"packageVersion": "7.18.2" | ||
} | ||
] | ||
} |
@@ -41,2 +41,6 @@ /** | ||
overrideRigJsonObject?: IRigConfigJson; | ||
/** | ||
* If specified, force a fresh load instead of returning a cached entry, if one existed. | ||
*/ | ||
bypassCache?: boolean; | ||
} | ||
@@ -64,2 +68,3 @@ /** | ||
private static _jsonSchemaObject; | ||
private static readonly _configCache; | ||
/** | ||
@@ -142,2 +147,3 @@ * The project folder path that was passed to {@link RigConfig.loadForProjectFolder}, | ||
static loadForProjectFolderAsync(options: ILoadForProjectFolderOptions): Promise<RigConfig>; | ||
private static _handleConfigError; | ||
/** | ||
@@ -144,0 +150,0 @@ * Performs Node.js module resolution to locate the rig package folder, then returns the absolute path |
@@ -40,8 +40,9 @@ "use strict"; | ||
constructor(options) { | ||
this.projectFolderOriginalPath = options.projectFolderPath; | ||
this.projectFolderPath = path.resolve(options.projectFolderPath); | ||
this.rigFound = options.rigFound; | ||
this.filePath = options.filePath; | ||
this.rigPackageName = options.rigPackageName; | ||
this.rigProfile = options.rigProfile; | ||
const { projectFolderPath, rigFound, filePath, rigPackageName, rigProfile = 'default' } = options; | ||
this.projectFolderOriginalPath = projectFolderPath; | ||
this.projectFolderPath = path.resolve(projectFolderPath); | ||
this.rigFound = rigFound; | ||
this.filePath = filePath; | ||
this.rigPackageName = rigPackageName; | ||
this.rigProfile = rigProfile; | ||
if (this.rigFound) { | ||
@@ -77,18 +78,14 @@ this.relativeProfileFolderPath = 'profiles/' + this.rigProfile; | ||
static loadForProjectFolder(options) { | ||
const rigConfigFilePath = path.join(options.projectFolderPath, 'config/rig.json'); | ||
let json; | ||
const { overrideRigJsonObject, projectFolderPath } = options; | ||
const fromCache = !options.bypassCache && !overrideRigJsonObject | ||
? RigConfig._configCache.get(projectFolderPath) | ||
: undefined; | ||
if (fromCache) { | ||
return fromCache; | ||
} | ||
const rigConfigFilePath = path.join(projectFolderPath, 'config/rig.json'); | ||
let config; | ||
let json = overrideRigJsonObject; | ||
try { | ||
if (options.overrideRigJsonObject) { | ||
json = options.overrideRigJsonObject; | ||
} | ||
else { | ||
if (!fs.existsSync(rigConfigFilePath)) { | ||
return new RigConfig({ | ||
projectFolderPath: options.projectFolderPath, | ||
rigFound: false, | ||
filePath: '', | ||
rigPackageName: '', | ||
rigProfile: '' | ||
}); | ||
} | ||
if (!json) { | ||
const rigConfigFileContent = fs.readFileSync(rigConfigFilePath).toString(); | ||
@@ -100,11 +97,17 @@ json = JSON.parse(strip_json_comments_1.default(rigConfigFileContent)); | ||
catch (error) { | ||
throw new Error(error.message + '\nError loading config file: ' + rigConfigFilePath); | ||
config = RigConfig._handleConfigError(error, projectFolderPath, rigConfigFilePath); | ||
} | ||
return new RigConfig({ | ||
projectFolderPath: options.projectFolderPath, | ||
rigFound: true, | ||
filePath: rigConfigFilePath, | ||
rigPackageName: json.rigPackageName, | ||
rigProfile: json.rigProfile || 'default' | ||
}); | ||
if (!config) { | ||
config = new RigConfig({ | ||
projectFolderPath: projectFolderPath, | ||
rigFound: true, | ||
filePath: rigConfigFilePath, | ||
rigPackageName: json.rigPackageName, | ||
rigProfile: json.rigProfile | ||
}); | ||
} | ||
if (!overrideRigJsonObject) { | ||
RigConfig._configCache.set(projectFolderPath, config); | ||
} | ||
return config; | ||
} | ||
@@ -115,18 +118,12 @@ /** | ||
static async loadForProjectFolderAsync(options) { | ||
const rigConfigFilePath = path.join(options.projectFolderPath, 'config/rig.json'); | ||
let json; | ||
const { overrideRigJsonObject, projectFolderPath } = options; | ||
const fromCache = !options.bypassCache && !overrideRigJsonObject && RigConfig._configCache.get(projectFolderPath); | ||
if (fromCache) { | ||
return fromCache; | ||
} | ||
const rigConfigFilePath = path.join(projectFolderPath, 'config/rig.json'); | ||
let config; | ||
let json = overrideRigJsonObject; | ||
try { | ||
if (options.overrideRigJsonObject) { | ||
json = options.overrideRigJsonObject; | ||
} | ||
else { | ||
if (!(await Helpers_1.Helpers.fsExistsAsync(rigConfigFilePath))) { | ||
return new RigConfig({ | ||
projectFolderPath: options.projectFolderPath, | ||
rigFound: false, | ||
filePath: '', | ||
rigPackageName: '', | ||
rigProfile: '' | ||
}); | ||
} | ||
if (!json) { | ||
const rigConfigFileContent = (await fs.promises.readFile(rigConfigFilePath)).toString(); | ||
@@ -138,10 +135,29 @@ json = JSON.parse(strip_json_comments_1.default(rigConfigFileContent)); | ||
catch (error) { | ||
config = RigConfig._handleConfigError(error, projectFolderPath, rigConfigFilePath); | ||
} | ||
if (!config) { | ||
config = new RigConfig({ | ||
projectFolderPath: projectFolderPath, | ||
rigFound: true, | ||
filePath: rigConfigFilePath, | ||
rigPackageName: json.rigPackageName, | ||
rigProfile: json.rigProfile | ||
}); | ||
} | ||
if (!overrideRigJsonObject) { | ||
RigConfig._configCache.set(projectFolderPath, config); | ||
} | ||
return config; | ||
} | ||
static _handleConfigError(error, projectFolderPath, rigConfigFilePath) { | ||
if (error.code !== 'ENOENT' && error.code !== 'ENOTDIR') { | ||
throw new Error(error.message + '\nError loading config file: ' + rigConfigFilePath); | ||
} | ||
// File not found, i.e. no rig config | ||
return new RigConfig({ | ||
projectFolderPath: options.projectFolderPath, | ||
rigFound: true, | ||
filePath: rigConfigFilePath, | ||
rigPackageName: json.rigPackageName, | ||
rigProfile: json.rigProfile || 'default' | ||
projectFolderPath, | ||
rigFound: false, | ||
filePath: '', | ||
rigPackageName: '', | ||
rigProfile: '' | ||
}); | ||
@@ -299,2 +315,3 @@ } | ||
RigConfig._jsonSchemaObject = undefined; | ||
RigConfig._configCache = new Map(); | ||
//# sourceMappingURL=RigConfig.js.map |
{ | ||
"name": "@rushstack/rig-package", | ||
"version": "0.2.13", | ||
"version": "0.3.0", | ||
"description": "A system for sharing tool configurations between projects without duplicating config files.", | ||
@@ -17,4 +17,4 @@ "main": "lib/index.js", | ||
"@rushstack/eslint-config": "2.4.0", | ||
"@rushstack/heft-node-rig": "1.0.31", | ||
"@rushstack/heft": "0.32.0", | ||
"@rushstack/heft-node-rig": "1.1.11", | ||
"@rushstack/heft": "0.34.6", | ||
"@types/heft-jest": "1.0.1", | ||
@@ -21,0 +21,0 @@ "@types/node": "10.17.13", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
82430
4.17%1046
4.08%