UNPKG

@supernovaio/cli

Version:

Supernova.io Command Line Interface

68 lines (63 loc) 2.89 kB
!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[n]="e7086882-97b4-535e-bb9d-c1abe5110ef2")}catch(e){}}(); import fs from "node:fs/promises"; const NPM_TOKEN_PLACEHOLDER = "${NPM_TOKEN}"; const NPMRC_AUTH_CONFIG_KEY_PATTERN = /(?:^|:)(?:_auth|_authToken|_password)$/i; const dockerfileTemplateTarball = ` FROM node:22-slim RUN apt-get update && apt-get install -y curl && apt-get clean && rm -rf /var/lib/apt/lists/* WORKDIR /home/user COPY . . RUN{{ npmTokenSecretMount }} npm i RUN node docker-scripts/extract-private-packages-tarball.js RUN{{ npmTokenSecretMount }} if [ -f .supernova-private-deps-rewritten ]; then npm i; fi `; export function buildTemplateUploadDockerfile(npmToken) { const npmTokenSecretMount = npmToken ? ` --mount=type=secret,id=NPM_TOKEN export NPM_TOKEN="$(cat /run/secrets/NPM_TOKEN)" &&` : ""; return dockerfileTemplateTarball.replaceAll("{{ npmTokenSecretMount }}", npmTokenSecretMount); } export function validateTemplateUploadNpmrcContent(npmrc, npmToken) { if (npmrc.includes(NPM_TOKEN_PLACEHOLDER) && !npmToken) { throw new Error(`.npmrc references ${NPM_TOKEN_PLACEHOLDER}. Pass --npmToken so Docker can resolve it safely.`); } const lines = npmrc.split(/\r?\n/); for (const [index, rawLine] of lines.entries()) { const line = rawLine.trim(); if (!line || line.startsWith("#") || line.startsWith(";")) continue; const equalsIndex = line.indexOf("="); if (equalsIndex === -1) continue; const key = line.slice(0, equalsIndex).trim(); const value = stripNpmrcValueQuotes(line.slice(equalsIndex + 1).trim()); if (!NPMRC_AUTH_CONFIG_KEY_PATTERN.test(key)) continue; if (!value || value === NPM_TOKEN_PLACEHOLDER) continue; throw new Error(`.npmrc contains a literal npm credential on line ${index + 1}. Use ${NPM_TOKEN_PLACEHOLDER} in .npmrc and pass --npmToken instead.`); } } export async function validateTemplateUploadNpmrcFile(npmrcPath, npmToken) { if (!(await fileExists(npmrcPath))) return; const npmrc = await fs.readFile(npmrcPath, "utf8"); validateTemplateUploadNpmrcContent(npmrc, npmToken); } function stripNpmrcValueQuotes(value) { if ((value.startsWith('"') && value.endsWith('"')) || (value.startsWith("'") && value.endsWith("'"))) { return value.slice(1, -1); } return value; } async function fileExists(filePath) { try { await fs.access(filePath); return true; } catch { return false; } } //# sourceMappingURL=template-upload-npmrc.js.map //# debugId=e7086882-97b4-535e-bb9d-c1abe5110ef2