utils/node_modules/@rushstack/rig-package/lib/RigConfig.js.map
2024-02-07 01:33:07 -05:00

1 line
25 KiB
Plaintext

{"version":3,"file":"RigConfig.js","sourceRoot":"","sources":["../src/RigConfig.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3D,2CAA6B;AAC7B,uCAAyB;AACzB,qDAAuC;AACvC,8EAAoD;AAEpD,uCAAoC;AAwKpC;;;;GAIG;AACH,MAAa,SAAS;IAqEpB,YAAoB,OAA0B;QAC5C,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,QAAQ,EAAE,cAAc,EAAE,UAAU,GAAG,SAAS,EAAE,GAAG,OAAO,CAAC;QAElG,IAAI,CAAC,yBAAyB,GAAG,iBAAiB,CAAC;QACnD,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;QAEzD,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,cAAc,GAAG,cAAc,CAAC;QACrC,IAAI,CAAC,UAAU,GAAG,UAAU,CAAC;QAE7B,IAAI,IAAI,CAAC,QAAQ,EAAE;YACjB,IAAI,CAAC,yBAAyB,GAAG,WAAW,GAAG,IAAI,CAAC,UAAU,CAAC;SAChE;aAAM;YACL,IAAI,CAAC,yBAAyB,GAAG,EAAE,CAAC;SACrC;IACH,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,KAAK,gBAAgB;QAChC,IAAI,SAAS,CAAC,iBAAiB,KAAK,SAAS,EAAE;YAC7C,MAAM,iBAAiB,GAAW,EAAE,CAAC,YAAY,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,QAAQ,EAAE,CAAC;YACvF,SAAS,CAAC,iBAAiB,GAAG,IAAI,CAAC,KAAK,CAAC,iBAAiB,CAAC,CAAC;SAC7D;QACD,OAAO,SAAS,C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AkB,GAAW,iCAAiC,CAAC;AAEvF;;;;;;;;;GASG;AACW,wBAAc,GAAW,IAAI,CAAC,OAAO,CAAC,SAAS,EAAE,2BAA2B,CAAC,CAAC;AAC7E,2BAAiB,GAAuB,SAAS,CAAC;AAEzC,sBAAY,GAA2B,IAAI,GAAG,EAAE,CAAC;AAxB9D,8BAAS","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport * as path from 'path';\nimport * as fs from 'fs';\nimport * as nodeResolve from 'resolve';\nimport stripJsonComments from 'strip-json-comments';\n\nimport { Helpers } from './Helpers';\n\n/**\n * Represents the literal contents of the `config/rig.json` file.\n *\n * @public\n */\nexport interface IRigConfigJson {\n /**\n * The name of the rig package to use.\n *\n * @remarks\n * The name must be a valid NPM package name, and must end with the `-rig` suffix.\n *\n * Example: `example-rig`\n */\n rigPackageName: string;\n\n /**\n * Specify which rig profile to use from the rig package.\n *\n * @remarks\n * The name must consist of lowercase alphanumeric words separated by hyphens, for example `\"sample-profile\"`.\n * If the `\"rigProfile\"` is not specified, then the profile name `\"default\"` will be used.\n *\n * Example: `example-profile`\n */\n rigProfile?: string;\n}\n\ninterface IRigConfigOptions {\n projectFolderPath: string;\n\n rigFound: boolean;\n filePath: string;\n rigPackageName: string;\n rigProfile?: string;\n}\n\n/**\n * Options for {@link RigConfig.loadForProjectFolder}.\n *\n * @public\n */\nexport interface ILoadForProjectFolderOptions {\n /**\n * The path to the folder of the project to be analyzed. This folder should contain a `package.json` file.\n */\n projectFolderPath: string;\n\n /**\n * If specified, instead of loading the `config/rig.json` from disk, this object will be substituted instead.\n */\n overrideRigJsonObject?: IRigConfigJson;\n\n /**\n * If specified, force a fresh load instead of returning a cached entry, if one existed.\n */\n bypassCache?: boolean;\n}\n\n/**\n * This is the main API for loading the `config/rig.json` file format.\n *\n * @public\n */\nexport interface IRigConfig {\n /**\n * The project folder path that was passed to {@link RigConfig.loadForProjectFolder},\n * which maybe an absolute or relative path.\n *\n * @remarks\n * Example: `.`\n */\n readonly projectFolderOriginalPath: string;\n\n /**\n * The absolute path for the project folder path that was passed to {@link RigConfig.loadForProjectFolder}.\n *\n * @remarks\n * Example: `/path/to/your-project`\n */\n readonly projectFolderPath: string;\n\n /**\n * Returns `true` if `config/rig.json` was found, or `false` otherwise.\n */\n readonly rigFound: boolean;\n\n /**\n * The full path to the `rig.json` file that was found, or `\"\"` if none was found.\n *\n * @remarks\n * Example: `/path/to/your-project/config/rig.json`\n */\n readonly filePath: string;\n\n /**\n * The `\"rigPackageName\"` field from `rig.json`, or `\"\"` if the file was not found.\n *\n * @remarks\n * The name must be a valid NPM package name, and must end with the `-rig` suffix.\n *\n * Example: `example-rig`\n */\n readonly rigPackageName: string;\n\n /**\n * The `\"rigProfile\"` value that was loaded from `rig.json`, or `\"\"` if the file was not found.\n *\n * @remarks\n * The name must consist of lowercase alphanumeric words separated by hyphens, for example `\"sample-profile\"`.\n * If the `rig.json` file exists, but the `\"rigProfile\"` is not specified, then the profile\n * name will be `\"default\"`.\n *\n * Example: `example-profile`\n */\n readonly rigProfile: string;\n\n /**\n * The relative path to the rig profile specified by `rig.json`, or `\"\"` if the file was not found.\n *\n * @remarks\n * Example: `profiles/example-profile`\n */\n readonly relativeProfileFolderPath: string;\n\n /**\n * Performs Node.js module resolution to locate the rig package folder, then returns the absolute path\n * of the rig profile folder specified by `rig.json`.\n *\n * @remarks\n * If no `rig.json` file was found, then this method throws an error. The first time this method\n * is called, the result is cached and will be returned by all subsequent calls.\n *\n * Example: `/path/to/your-project/node_modules/example-rig/profiles/example-profile`\n */\n getResolvedProfileFolder(): string;\n\n /**\n * An async variant of {@link IRigConfig.getResolvedProfileFolder}\n */\n getResolvedProfileFolderAsync(): Promise<string>;\n\n /**\n * This lookup first checks for the specified relative path under `projectFolderPath`; if it does\n * not exist there, then it checks in the resolved rig profile folder. If the file is found,\n * its absolute path is returned. Otherwise, `undefined` is returned.\n *\n * @remarks\n * For example, suppose the rig profile is:\n *\n * `/path/to/your-project/node_modules/example-rig/profiles/example-profile`\n *\n * And suppose `configFileRelativePath` is `folder/file.json`. Then the following locations will be checked:\n *\n * `/path/to/your-project/folder/file.json`\n *\n * `/path/to/your-project/node_modules/example-rig/profiles/example-profile/folder/file.json`\n */\n tryResolveConfigFilePath(configFileRelativePath: string): string | undefined;\n\n /**\n * An async variant of {@link IRigConfig.tryResolveConfigFilePath}\n */\n tryResolveConfigFilePathAsync(configFileRelativePath: string): Promise<string | undefined>;\n}\n\n/**\n * {@inheritdoc IRigConfig}\n *\n * @public\n */\nexport class RigConfig implements IRigConfig {\n // For syntax details, see PackageNameParser from @rushstack/node-core-library\n private static readonly _packageNameRegExp: RegExp = /^(@[A-Za-z0-9\\-_\\.]+\\/)?[A-Za-z0-9\\-_\\.]+$/;\n\n // Rig package names must have the \"-rig\" suffix.\n // Also silently accept \"-rig-test\" for our build test projects.\n private static readonly _rigNameRegExp: RegExp = /-rig(-test)?$/;\n\n // Profiles must be lowercase alphanumeric words separated by hyphens\n private static readonly _profileNameRegExp: RegExp = /^[a-z0-9_\\.]+(\\-[a-z0-9_\\.]+)*$/;\n\n /**\n * Returns the absolute path of the `rig.schema.json` JSON schema file for `config/rig.json`,\n * which is bundled with this NPM package.\n *\n * @remarks\n * The `RigConfig` class already performs schema validation when loading `rig.json`; however\n * this schema file may be useful for integration with other validation tools.\n *\n * @public\n */\n public static jsonSchemaPath: string = path.resolve(__dirname, './schemas/rig.schema.json');\n private static _jsonSchemaObject: object | undefined = undefined;\n\n private static readonly _configCache: Map<string, RigConfig> = new Map();\n\n /**\n * {@inheritdoc IRigConfig.projectFolderOriginalPath}\n */\n public readonly projectFolderOriginalPath: string;\n\n /**\n * {@inheritdoc IRigConfig.projectFolderPath}\n */\n public readonly projectFolderPath: string;\n\n /**\n * {@inheritdoc IRigConfig.rigFound}\n */\n public readonly rigFound: boolean;\n\n /**\n * {@inheritdoc IRigConfig.filePath}\n */\n public readonly filePath: string;\n\n /**\n * {@inheritdoc IRigConfig.rigPackageName}\n */\n public readonly rigPackageName: string;\n\n /**\n * {@inheritdoc IRigConfig.rigProfile}\n */\n public readonly rigProfile: string;\n\n /**\n * {@inheritdoc IRigConfig.relativeProfileFolderPath}\n */\n public readonly relativeProfileFolderPath: string;\n\n // Example: /path/to/your-project/node_modules/example-rig/\n // If the value is `undefined`, then getResolvedProfileFolder() has not calculated it yet\n private _resolvedRigPackageFolder: string | undefined;\n\n // Example: /path/to/your-project/node_modules/example-rig/profiles/example-profile\n // If the value is `undefined`, then getResolvedProfileFolder() has not calculated it yet\n private _resolvedProfileFolder: string | undefined;\n\n private constructor(options: IRigConfigOptions) {\n const { projectFolderPath, rigFound, filePath, rigPackageName, rigProfile = 'default' } = options;\n\n this.projectFolderOriginalPath = projectFolderPath;\n this.projectFolderPath = path.resolve(projectFolderPath);\n\n this.rigFound = rigFound;\n this.filePath = filePath;\n this.rigPackageName = rigPackageName;\n this.rigProfile = rigProfile;\n\n if (this.rigFound) {\n this.relativeProfileFolderPath = 'profiles/' + this.rigProfile;\n } else {\n this.relativeProfileFolderPath = '';\n }\n }\n\n /**\n * The JSON contents of the {@link RigConfig.jsonSchemaPath} file.\n *\n * @remarks\n * The JSON object will be lazily loaded when this property getter is accessed, and the result\n * will be cached.\n * Accessing this property may make a synchronous filesystem call.\n */\n public static get jsonSchemaObject(): object {\n if (RigConfig._jsonSchemaObject === undefined) {\n const jsonSchemaContent: string = fs.readFileSync(RigConfig.jsonSchemaPath).toString();\n RigConfig._jsonSchemaObject = JSON.parse(jsonSchemaContent);\n }\n return RigConfig._jsonSchemaObject!;\n }\n\n /**\n * Use this method to load the `config/rig.json` file for a given project.\n *\n * @remarks\n * If the file cannot be found, an empty `RigConfig` object will be returned with {@link RigConfig.rigFound}\n * equal to `false`.\n */\n public static loadForProjectFolder(options: ILoadForProjectFolderOptions): RigConfig {\n const { overrideRigJsonObject, projectFolderPath } = options;\n\n const fromCache: RigConfig | undefined =\n !options.bypassCache && !overrideRigJsonObject\n ? RigConfig._configCache.get(projectFolderPath)\n : undefined;\n\n if (fromCache) {\n return fromCache;\n }\n\n const rigConfigFilePath: string = path.join(projectFolderPath, 'config/rig.json');\n\n let config: RigConfig | undefined;\n let json: IRigConfigJson | undefined = overrideRigJsonObject;\n try {\n if (!json) {\n const rigConfigFileContent: string = fs.readFileSync(rigConfigFilePath).toString();\n json = JSON.parse(stripJsonComments(rigConfigFileContent)) as IRigConfigJson;\n }\n RigConfig._validateSchema(json);\n } catch (error) {\n config = RigConfig._handleConfigError(error as Error, projectFolderPath, rigConfigFilePath);\n }\n\n if (!config) {\n config = new RigConfig({\n projectFolderPath: projectFolderPath,\n\n rigFound: true,\n filePath: rigConfigFilePath,\n rigPackageName: json!.rigPackageName,\n rigProfile: json!.rigProfile\n });\n }\n\n if (!overrideRigJsonObject) {\n RigConfig._configCache.set(projectFolderPath, config);\n }\n return config;\n }\n\n /**\n * An async variant of {@link RigConfig.loadForProjectFolder}\n */\n public static async loadForProjectFolderAsync(options: ILoadForProjectFolderOptions): Promise<RigConfig> {\n const { overrideRigJsonObject, projectFolderPath } = options;\n\n const fromCache: RigConfig | false | undefined =\n !options.bypassCache && !overrideRigJsonObject && RigConfig._configCache.get(projectFolderPath);\n\n if (fromCache) {\n return fromCache;\n }\n\n const rigConfigFilePath: string = path.join(projectFolderPath, 'config/rig.json');\n\n let config: RigConfig | undefined;\n let json: IRigConfigJson | undefined = overrideRigJsonObject;\n try {\n if (!json) {\n const rigConfigFileContent: string = (await fs.promises.readFile(rigConfigFilePath)).toString();\n json = JSON.parse(stripJsonComments(rigConfigFileContent)) as IRigConfigJson;\n }\n\n RigConfig._validateSchema(json);\n } catch (error) {\n config = RigConfig._handleConfigError(error as Error, projectFolderPath, rigConfigFilePath);\n }\n\n if (!config) {\n config = new RigConfig({\n projectFolderPath: projectFolderPath,\n\n rigFound: true,\n filePath: rigConfigFilePath,\n rigPackageName: json!.rigPackageName,\n rigProfile: json!.rigProfile\n });\n }\n\n if (!overrideRigJsonObject) {\n RigConfig._configCache.set(projectFolderPath, config);\n }\n return config;\n }\n\n private static _handleConfigError(\n error: NodeJS.ErrnoException,\n projectFolderPath: string,\n rigConfigFilePath: string\n ): RigConfig {\n if (error.code !== 'ENOENT' && error.code !== 'ENOTDIR') {\n throw new Error(error.message + '\\nError loading config file: ' + rigConfigFilePath);\n }\n\n // File not found, i.e. no rig config\n return new RigConfig({\n projectFolderPath,\n\n rigFound: false,\n filePath: '',\n rigPackageName: '',\n rigProfile: ''\n });\n }\n\n /**\n * {@inheritdoc IRigConfig.getResolvedProfileFolder}\n */\n public getResolvedProfileFolder(): string {\n if (this._resolvedRigPackageFolder === undefined) {\n if (!this.rigFound) {\n throw new Error('Cannot resolve the rig package because no rig was specified for this project');\n }\n\n const rigPackageJsonModuleSpecifier: string = `${this.rigPackageName}/package.json`;\n const resolveOptions: nodeResolve.Opts = { basedir: this.projectFolderPath };\n const resolvedRigPackageJsonPath: string = nodeResolve.sync(\n rigPackageJsonModuleSpecifier,\n resolveOptions\n );\n\n this._resolvedRigPackageFolder = path.dirname(resolvedRigPackageJsonPath);\n }\n\n if (this._resolvedProfileFolder === undefined) {\n this._resolvedProfileFolder = path.join(this._resolvedRigPackageFolder, this.relativeProfileFolderPath);\n\n if (!fs.existsSync(this._resolvedProfileFolder)) {\n throw new Error(\n `The rig profile \"${this.rigProfile}\" is not defined` +\n ` by the rig package \"${this.rigPackageName}\"`\n );\n }\n }\n\n return this._resolvedProfileFolder;\n }\n\n /**\n * {@inheritdoc IRigConfig.getResolvedProfileFolderAsync}\n */\n public async getResolvedProfileFolderAsync(): Promise<string> {\n if (this._resolvedRigPackageFolder === undefined) {\n if (!this.rigFound) {\n throw new Error('Cannot resolve the rig package because no rig was specified for this project');\n }\n\n const rigPackageJsonModuleSpecifier: string = `${this.rigPackageName}/package.json`;\n const resolveOptions: nodeResolve.Opts = { basedir: this.projectFolderPath };\n const resolvedRigPackageJsonPath: string = await Helpers.nodeResolveAsync(\n rigPackageJsonModuleSpecifier,\n resolveOptions\n );\n\n this._resolvedRigPackageFolder = path.dirname(resolvedRigPackageJsonPath);\n }\n\n if (this._resolvedProfileFolder === undefined) {\n this._resolvedProfileFolder = path.join(this._resolvedRigPackageFolder, this.relativeProfileFolderPath);\n\n if (!(await Helpers.fsExistsAsync(this._resolvedProfileFolder))) {\n throw new Error(\n `The rig profile \"${this.rigProfile}\" is not defined` +\n ` by the rig package \"${this.rigPackageName}\"`\n );\n }\n }\n\n return this._resolvedProfileFolder;\n }\n\n /**\n * {@inheritdoc IRigConfig.tryResolveConfigFilePath}\n */\n public tryResolveConfigFilePath(configFileRelativePath: string): string | undefined {\n if (!Helpers.isDownwardRelative(configFileRelativePath)) {\n throw new Error('The configFileRelativePath is not a relative path: ' + configFileRelativePath);\n }\n\n const localPath: string = path.join(this.projectFolderPath, configFileRelativePath);\n if (fs.existsSync(localPath)) {\n return localPath;\n }\n if (this.rigFound) {\n const riggedPath: string = path.join(this.getResolvedProfileFolder(), configFileRelativePath);\n if (fs.existsSync(riggedPath)) {\n return riggedPath;\n }\n }\n return undefined;\n }\n\n /**\n * {@inheritdoc IRigConfig.tryResolveConfigFilePathAsync}\n */\n public async tryResolveConfigFilePathAsync(configFileRelativePath: string): Promise<string | undefined> {\n if (!Helpers.isDownwardRelative(configFileRelativePath)) {\n throw new Error('The configFileRelativePath is not a relative path: ' + configFileRelativePath);\n }\n\n const localPath: string = path.join(this.projectFolderPath, configFileRelativePath);\n if (await Helpers.fsExistsAsync(localPath)) {\n return localPath;\n }\n if (this.rigFound) {\n const riggedPath: string = path.join(\n await this.getResolvedProfileFolderAsync(),\n configFileRelativePath\n );\n if (await Helpers.fsExistsAsync(riggedPath)) {\n return riggedPath;\n }\n }\n return undefined;\n }\n\n private static _validateSchema(json: IRigConfigJson): void {\n for (const key of Object.getOwnPropertyNames(json)) {\n switch (key) {\n case '$schema':\n case 'rigPackageName':\n case 'rigProfile':\n break;\n default:\n throw new Error(`Unsupported field ${JSON.stringify(key)}`);\n }\n }\n if (!json.rigPackageName) {\n throw new Error('Missing required field \"rigPackageName\"');\n }\n\n if (!RigConfig._packageNameRegExp.test(json.rigPackageName)) {\n throw new Error(\n `The \"rigPackageName\" value is not a valid NPM package name: ${JSON.stringify(json.rigPackageName)}`\n );\n }\n\n if (!RigConfig._rigNameRegExp.test(json.rigPackageName)) {\n throw new Error(\n `The \"rigPackageName\" value is missing the \"-rig\" suffix: ` + JSON.stringify(json.rigProfile)\n );\n }\n\n if (json.rigProfile !== undefined) {\n if (!RigConfig._profileNameRegExp.test(json.rigProfile)) {\n throw new Error(\n `The profile name must consist of lowercase alphanumeric words separated by hyphens: ` +\n JSON.stringify(json.rigProfile)\n );\n }\n }\n }\n}\n"]}