gulp-emu
Version:
Gulp plugin for ecmarkup
54 lines • 2.11 kB
JavaScript
;
/*!
* Copyright 2021 Ron Buckton (rbuckton@chronicles.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEcmarkupModule = exports.setEcmarkup = void 0;
const semver = require("semver");
const path = require("path");
function resolveEcmarkupModule(packagePath) {
if (!path.isAbsolute(packagePath) || path.basename(packagePath) !== "package.json") {
throw new TypeError("Expected an absolute path to 'package.json'");
}
const packageJson = require(packagePath);
if (packageJson.name !== "ecmarkup") {
throw new Error("Invalid ecmarkup package reference.");
}
const pathname = path.dirname(packagePath);
const version = packageJson.version;
const mode = semver.satisfies(version, ">= 18.0.0") ? "v18" :
semver.satisfies(version, ">= 7.0.0") ? "v7" :
"v3";
const module = require(pathname);
return {
path: pathname,
version,
mode,
module
};
}
const ecmarkupModule = resolveEcmarkupModule(require.resolve("ecmarkup/package.json"));
let currentEcmarkupModule = ecmarkupModule;
/* @internal */
function setEcmarkup(packagePath) {
currentEcmarkupModule = packagePath ? resolveEcmarkupModule(packagePath) : ecmarkupModule;
}
exports.setEcmarkup = setEcmarkup;
/* @internal */
function getEcmarkupModule() {
return currentEcmarkupModule;
}
exports.getEcmarkupModule = getEcmarkupModule;
//# sourceMappingURL=ecmarkupModule.js.map