@catladder/pipeline
Version:
Panter workflow for cloud CI/CD and DevOps
87 lines (86 loc) • 3.51 kB
JavaScript
;
var __read = this && this.__read || function (o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o),
r,
ar = [],
e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
} catch (error) {
e = {
error: error
};
} finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
} finally {
if (e) throw e.error;
}
}
return ar;
};
var __spreadArray = this && this.__spreadArray || function (to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
};
var __importDefault = this && this.__importDefault || function (mod) {
return mod && mod.__esModule ? mod : {
"default": mod
};
};
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getNodeCache = exports.getNodeModulesCache = exports.getYarnCache = void 0;
var lodash_1 = require("lodash");
var path_1 = require("path");
var slugify_1 = __importDefault(require("slugify"));
var getYarnCache = function (context, policy) {
if (policy === void 0) {
policy = "pull-push";
}
var componentIsInWorkspace = context.type === "component" && context.packageManagerInfo.componentIsInWorkspace;
return [{
scope: componentIsInWorkspace ? "global" : "buildDir",
pathMode: componentIsInWorkspace ? "absolute" : "relative",
key: "yarn",
policy: policy,
paths: [".yarn"]
}];
};
exports.getYarnCache = getYarnCache;
var getNodeModulesCache = function (context, policy) {
var _a;
if (policy === void 0) {
policy = "pull-push";
}
var componentIsInWorkspace = context.type === "component" && context.packageManagerInfo.componentIsInWorkspace;
// We intentionally do not use the contents of yarn.lock as a cache key, as yarn install should always guarantee that the files are updated, but it can still use part of the cache if not all packages are up-to-date.
// It would slow down all pipelines whenever one adds a new dependency as it will need to download all node_modules again.
return [{
scope: "global",
pathMode: "absolute",
// if component is in a shared workspace, use workspace cache. use individual cache else
key: componentIsInWorkspace ? "node-modules-workspace" : (0, slugify_1.default)(context.build.dir) + "-node-modules",
// we use the dirname, not the component name, because in certain cases we have two apps in the same directory and want to share the cache, e.g. when having storybook in the same package.json
policy: policy,
paths: __spreadArray([], __read(componentIsInWorkspace ? (0, lodash_1.uniq)(__spreadArray(["node_modules"], __read((_a = context.packageManagerInfo.workspaces.map(function (w) {
return (0, path_1.join)(w.location, "node_modules");
})) !== null && _a !== void 0 ? _a : []), false)) : [(0, path_1.join)(context.build.dir, "node_modules")]), false)
}];
};
exports.getNodeModulesCache = getNodeModulesCache;
var getNodeCache = function (context, policy) {
if (policy === void 0) {
policy = "pull-push";
}
return __spreadArray(__spreadArray([], __read((0, exports.getYarnCache)(context, policy)), false), __read((0, exports.getNodeModulesCache)(context, policy)), false);
};
exports.getNodeCache = getNodeCache;