liferay-npm-bundler-preset-reactjs
Version:
liferay npm bundler preset react
82 lines (81 loc) • 2.66 kB
JavaScript
"use strict";
/**
* SPDX-FileCopyrightText: © 2020 Liferay, Inc. <https://liferay.com>
* SPDX-License-Identifier: LGPL-3.0-or-later
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = __importDefault(require("path"));
const file_path_1 = __importDefault(require("./file-path"));
const project_1 = __importDefault(require("./project"));
/**
* A package descriptor class to identify directories containing packages.
*/
class PkgDesc {
/**
* @param name name of package
* @param version version number
* @param pkgPath directory where package lives (or null if it is the root
* package)
* @param forceRoot create a root package even if dir is not null
*/
constructor(name, version, pkgPath, forceRoot = false) {
this._name = name;
this._version = version;
if (!pkgPath) {
pkgPath = project_1.default.dir.asNative;
this._id = PkgDesc.ROOT_ID;
}
else if (forceRoot) {
this._id = PkgDesc.ROOT_ID;
}
else {
this._id = `${name}@${version}`;
}
let pkgPrjRelPath = project_1.default.dir.relative(pkgPath).asNative;
// Because path.join('.', 'x') returns 'x', not './x' we need to prepend
// './' by hand :-(
pkgPrjRelPath =
pkgPrjRelPath === '' ? '.' : `.${path_1.default.sep}${pkgPrjRelPath}`;
this._dir = new file_path_1.default(pkgPrjRelPath);
this._clean = true;
}
/**
* Clone this object and optionally modify some of its fields.
* @param dir override package directory path or FilePath
* @return a clone of this (perhaps modified) package descriptor
*/
clone({ dir } = {}) {
return new PkgDesc(this.name, this.version, dir ? dir.toString() : this._dir.toString(), this.isRoot);
}
/**
* Get directory where package lives referenced to `project.dir`. Note that
* it always start with `./` so that it can be used in `path.join()` calls.
*/
get dir() {
return this._dir;
}
get clean() {
return this._clean;
}
set clean(clean) {
this._clean = clean;
}
get id() {
return this._id;
}
get name() {
return this._name;
}
get version() {
return this._version;
}
get isRoot() {
return this.id === PkgDesc.ROOT_ID;
}
}
exports.default = PkgDesc;
/** Well known id for the root package */
PkgDesc.ROOT_ID = '/';