@lerna/publish
Version:
Publish packages in the current project
101 lines (100 loc) • 4.02 kB
JavaScript
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var make_file_finder_exports = {};
__export(make_file_finder_exports, {
makeFileFinder: () => makeFileFinder,
makeSyncFileFinder: () => makeSyncFileFinder
});
module.exports = __toCommonJS(make_file_finder_exports);
var import_globby = __toESM(require("globby"));
var import_p_map = __toESM(require("p-map"));
var import_path = __toESM(require("path"));
var import_validation_error = require("../validation-error");
function normalize(results) {
return results.map((fp) => import_path.default.normalize(fp));
}
function getGlobOpts(rootPath, packageConfigs) {
const globOpts = {
cwd: rootPath,
absolute: true,
expandDirectories: false,
followSymbolicLinks: false
};
if (packageConfigs.some((cfg) => cfg.indexOf("**") > -1)) {
if (packageConfigs.some((cfg) => cfg.indexOf("node_modules") > -1)) {
throw new import_validation_error.ValidationError(
"EPKGCONFIG",
"An explicit node_modules package path does not allow globstars (**)"
);
}
globOpts.ignore = [
// allow globs like "packages/**",
// but avoid picking up node_modules/**/package.json
"**/node_modules/**"
];
}
return globOpts;
}
function makeFileFinder(rootPath, packageConfigs) {
const globOpts = getGlobOpts(rootPath, packageConfigs);
return (fileName, fileMapper, customGlobOpts) => {
const options = Object.assign({}, customGlobOpts, globOpts);
const promise = (0, import_p_map.default)(
Array.from(packageConfigs).sort(),
(globPath) => {
let chain = (0, import_globby.default)(import_path.default.posix.join(globPath, fileName), options);
chain = chain.then((results) => results.sort());
chain = chain.then(normalize);
if (fileMapper) {
chain = chain.then(fileMapper);
}
return chain;
},
{ concurrency: 4 }
);
return promise.then((results) => results.reduce((acc, result) => acc.concat(result), []));
};
}
function makeSyncFileFinder(rootPath, packageConfigs) {
const globOpts = getGlobOpts(rootPath, packageConfigs);
return (fileName, fileMapper, customGlobOpts) => {
const options = Object.assign({}, customGlobOpts, globOpts);
const patterns = packageConfigs.map((globPath) => import_path.default.posix.join(globPath, fileName)).sort();
let results = import_globby.default.sync(patterns, options);
results = normalize(results);
if (fileMapper) {
results = results.map(fileMapper);
}
return results;
};
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
makeFileFinder,
makeSyncFileFinder
});