@rushstack/heft
Version:
Build all your JavaScript projects the same way: A way that works.
159 lines • 6.29 kB
JavaScript
"use strict";
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
// See LICENSE in the project root for license information.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.HeftConfiguration = void 0;
const path = __importStar(require("path"));
const node_core_library_1 = require("@rushstack/node-core-library");
const terminal_1 = require("@rushstack/terminal");
const rig_package_1 = require("@rushstack/rig-package");
const Constants_1 = require("../utilities/Constants");
const RigPackageResolver_1 = require("./RigPackageResolver");
/**
* @public
*/
class HeftConfiguration {
/**
* Project build folder path. This is the folder containing the project's package.json file.
*/
get buildFolderPath() {
return this._buildFolderPath;
}
/**
* {@link HeftConfiguration.buildFolderPath} with all path separators converted to forward slashes.
*/
get slashNormalizedBuildFolderPath() {
if (!this._slashNormalizedBuildFolderPath) {
this._slashNormalizedBuildFolderPath = node_core_library_1.Path.convertToSlashes(this.buildFolderPath);
}
return this._slashNormalizedBuildFolderPath;
}
/**
* The path to the project's "config" folder.
*/
get projectConfigFolderPath() {
if (!this._projectConfigFolderPath) {
this._projectConfigFolderPath = path.join(this.buildFolderPath, Constants_1.Constants.projectConfigFolderName);
}
return this._projectConfigFolderPath;
}
/**
* The project's temporary folder.
*
* @remarks This folder exists at \<project root\>/temp. In general, this folder is used to store temporary
* output from tasks under task-specific subfolders, and is not intended to be directly written to.
* Instead, plugins should write to the directory provided by HeftTaskSession.taskTempFolderPath
*/
get tempFolderPath() {
if (!this._tempFolderPath) {
this._tempFolderPath = path.join(this._buildFolderPath, Constants_1.Constants.tempFolderName);
}
return this._tempFolderPath;
}
/**
* The rig.json configuration for this project, if present.
*/
get rigConfig() {
if (!this._rigConfig) {
throw new node_core_library_1.InternalError('The rigConfig cannot be accessed until HeftConfiguration.checkForRigAsync() has been called');
}
return this._rigConfig;
}
/**
* The rig package resolver, which can be used to rig-resolve a requested package.
*/
get rigPackageResolver() {
if (!this._rigPackageResolver) {
this._rigPackageResolver = new RigPackageResolver_1.RigPackageResolver({
buildFolder: this.buildFolderPath,
projectPackageJson: this.projectPackageJson,
rigConfig: this.rigConfig
});
}
return this._rigPackageResolver;
}
/**
* Terminal instance to facilitate logging.
*/
get globalTerminal() {
return this._globalTerminal;
}
/**
* Terminal provider for the provided terminal.
*/
get terminalProvider() {
return this._terminalProvider;
}
/**
* The Heft tool's package.json
*/
get heftPackageJson() {
return node_core_library_1.PackageJsonLookup.instance.tryLoadPackageJsonFor(__dirname);
}
/**
* The package.json of the project being built
*/
get projectPackageJson() {
return node_core_library_1.PackageJsonLookup.instance.tryLoadPackageJsonFor(this.buildFolderPath);
}
constructor() { }
/**
* Performs the search for rig.json and initializes the `HeftConfiguration.rigConfig` object.
* @internal
*/
async _checkForRigAsync() {
if (!this._rigConfig) {
this._rigConfig = await rig_package_1.RigConfig.loadForProjectFolderAsync({
projectFolderPath: this._buildFolderPath
});
}
}
/**
* @internal
*/
static initialize(options) {
const configuration = new HeftConfiguration();
const packageJsonPath = node_core_library_1.PackageJsonLookup.instance.tryGetPackageJsonFilePathFor(options.cwd);
if (packageJsonPath) {
let buildFolderPath = path.dirname(packageJsonPath);
// On Windows it is possible for the drive letter in the CWD to be lowercase, but the normalized naming is uppercase
// Force it to always be uppercase for consistency.
buildFolderPath =
process.platform === 'win32'
? buildFolderPath.charAt(0).toUpperCase() + buildFolderPath.slice(1)
: buildFolderPath;
configuration._buildFolderPath = buildFolderPath;
}
else {
throw new Error('No package.json file found. Are you in a project folder?');
}
configuration._terminalProvider = options.terminalProvider;
configuration._globalTerminal = new terminal_1.Terminal(options.terminalProvider);
return configuration;
}
}
exports.HeftConfiguration = HeftConfiguration;
//# sourceMappingURL=HeftConfiguration.js.map