UNPKG

@catladder/cli

Version:

Panter cli tool for cloud CI/CD and DevOps

61 lines (60 loc) 2.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getDockerAppCopyAndBuildScript = exports.getYarnInstall = exports.ensureNodeVersion = void 0; const BashExpression_1 = require("../../bash/BashExpression"); const utils_1 = require("../../utils"); const gitlab_1 = require("../../utils/gitlab"); const YARN_INSTALL_CLASSIC = `yarn install --frozen-lockfile`; // FIXME: check why and when rebuild is needed const YARN_BERRY_PROD_REBUILD = `yarn workspaces focus --production && yarn rebuild`; const getYarnInstallCommand = (context) => { if (context.packageManagerInfo.isClassic) { return YARN_INSTALL_CLASSIC; } return `yarn install --immutable`; }; const ensureNodeVersion = (context) => (0, gitlab_1.collapseableSection)("nodeinstall", "Ensure node version")([ "if [ -f ~/.nvm/nvm.sh ]; then source ~/.nvm/nvm.sh; fi", "if command -v nvm &> /dev/null && [ -f ./.nvmrc ]; then nvm install; fi", ]); exports.ensureNodeVersion = ensureNodeVersion; const getYarnInstall = (context, options) => { const postInstall = context.type !== "workspace" && context.build.type !== "disabled" && "postInstall" in context.build.config ? context.build.config.postInstall : null; return [ ...(0, exports.ensureNodeVersion)(context), ...(0, gitlab_1.collapseableSection)("yarninstall", "Yarn install")([getYarnInstallCommand(context)]), ...(postInstall && !(options === null || options === void 0 ? void 0 : options.noCustomPostInstall) ? (0, gitlab_1.collapseableSection)("postinstall", "Custom post install")((0, utils_1.ensureArray)(postInstall)) : []), ]; }; exports.getYarnInstall = getYarnInstall; const DOCKER_COPY_FILES = `COPY --chown=node:node $APP_DIR .`; const getDockerAppCopyAndBuildScript = (context) => { if (context.packageManagerInfo.isClassic) { return new BashExpression_1.BashExpression(` RUN ${YARN_INSTALL_CLASSIC} --production --ignore-scripts ${DOCKER_COPY_FILES} RUN ${YARN_INSTALL_CLASSIC} --production `.trim()); } // yarn >= 4 ships with build in plugins, see https://github.com/yarnpkg/berry/pull/4253 // trying to import those fail on this version const doesNotShipWithBuiltInPlugins = ["2", "3"].some((v) => context.packageManagerInfo.version.startsWith(v)); const maybeAddWorkspaceToolsCommand = doesNotShipWithBuiltInPlugins ? "RUN yarn plugin import workspace-tools" : ""; // copy first everything and then install // rebuild first does not work as it will run postinstall and that might require files in the app return new BashExpression_1.BashExpression(` ${DOCKER_COPY_FILES} ${maybeAddWorkspaceToolsCommand} RUN ${YARN_BERRY_PROD_REBUILD} `.trim()); }; exports.getDockerAppCopyAndBuildScript = getDockerAppCopyAndBuildScript; //# sourceMappingURL=yarn.js.map