Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | #!/usr/bin/env node
/**
* Capture baseline from a previous package version
*
* Packs the given version via npm pack, extracts it, runs the current
* generate-core-css pipeline on the extracted dist, then captures that
* output as the baseline.
*
* Usage: node capture-baseline-from-version.js <version> --registry <url> [--config <config>] [--keep-temp]
*
* With yarn, use `--` before --registry so yarn passes it through: ... -- --registry <url>
*/
import path from 'node:path';
import fs from 'fs-extra';
import chalk from 'chalk';
import yargs from 'yargs';
import { execSync } from 'node:child_process';
import { pathToFileURL, fileURLToPath } from 'node:url';
import { resolveDistPath } from './lib/baseline-from-version-utils.js';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const argv = yargs(process.argv.slice(2))
.option('package-version', {
alias: 'v',
type: 'string',
description: 'Package version to use (e.g. 2.28.0)',
})
.option('config', {
alias: 'c',
type: 'string',
description: 'Path to validation config file',
default: '.validation/core-css.js',
})
.option('keep-temp', {
type: 'boolean',
description: 'Keep temp pack/extract and generated CSS dirs after run',
default: false,
})
.option('registry', {
alias: 'r',
type: 'string',
description: 'npm registry URL to fetch the package from',
})
.help()
.check((args) => {
const version = args['package-version'] || args._?.[0];
if (!version || typeof version !== 'string') {
throw new Error('Missing required argument: package-version or version');
}
return true;
})
.argv;
// yargs stops at '--', so --registry after '--' lands in argv._. Extract it.
let registry = argv.registry;
if (!registry && Array.isArray(argv._)) {
const idx = argv._.indexOf('--registry');
if (idx >= 0 && argv._[idx + 1] && String(argv._[idx + 1]).startsWith('http')) {
registry = argv._[idx + 1];
}
}
const PACKAGE_NAME = '@salesforce-ux/design-system';
const CWD = process.cwd();
async function main() {
const version = argv['package-version'] || argv._?.[0];
const configPath = path.resolve(CWD, argv.config);
const keepTemp = argv['keep-temp'];
if (!registry) {
console.error(chalk.red(`ā --registry is required.`));
console.error(chalk.gray(` Example: node scripts/validation/capture-baseline-from-version.js 2.30.0-alpha.3 --registry https://nexus-proxy.repo.local.sfdc.net/nexus/content/repositories/npmjs-internal/`));
process.exit(1);
}
if (!fs.existsSync(configPath)) {
console.error(chalk.red(`ā Config file not found: ${configPath}`));
process.exit(1);
}
const configUrl = pathToFileURL(configPath).href;
const configModule = await import(configUrl);
const config = configModule.default || configModule;
const tempBase = path.join(CWD, '.tmp', 'baseline-from-version', version);
const extractDir = path.join(tempBase, 'extract');
const tempCoreCssDir = path.join(tempBase, 'dist-core-css');
fs.ensureDirSync(extractDir);
const tarballName = `salesforce-ux-design-system-${version.replace(/^@?[\w-]+\//, '')}.tgz`;
console.log(chalk.blue(`\nš¦ Capturing baseline from ${PACKAGE_NAME}@${version}\n`));
console.log(chalk.gray(` Config: ${configPath}`));
console.log(chalk.gray(` Registry: ${registry}`));
console.log(chalk.gray(` Temp: ${tempBase}\n`));
const packEnv = { ...process.env, NPM_CONFIG_REGISTRY: registry };
const packCmd = `npm pack "${PACKAGE_NAME}@${version}" --registry "${registry}"`;
console.log(chalk.gray(` Running: ${packCmd}\n`));
try {
execSync(packCmd, {
cwd: CWD,
stdio: ['inherit', 'pipe', 'pipe'],
encoding: 'utf8',
env: packEnv,
shell: true,
});
} catch (err) {
console.error(chalk.red(`ā npm pack failed.`));
const out = [err.stdout, err.stderr].filter(Boolean).join('\n');
if (out) {
const lines = out.split('\n');
const errLines = lines.filter((l) => l.includes('error') || l.includes('ETARGET') || l.includes('notarget'));
console.error(chalk.gray((errLines.length ? errLines : lines.slice(-15)).join('\n')));
}
if (!keepTemp) fs.removeSync(tempBase);
process.exit(1);
}
let packedFile = path.join(CWD, tarballName);
if (!fs.existsSync(packedFile)) {
const found = fs.readdirSync(CWD);
const tgz = found.find((f) => f.endsWith('.tgz') && f.includes(version));
if (tgz) packedFile = path.join(CWD, tgz);
}
if (!fs.existsSync(packedFile)) {
console.error(chalk.red(`ā Tarball not found after pack (expected ${tarballName} in ${CWD}).`));
if (!keepTemp) fs.removeSync(tempBase);
process.exit(1);
}
const destFile = path.join(tempBase, path.basename(packedFile));
fs.moveSync(packedFile, destFile);
packedFile = destFile;
console.log(chalk.blue(' Extracting tarball...'));
try {
execSync(`tar -xzf "${packedFile}" -C "${extractDir}"`, { stdio: 'inherit' });
} catch (err) {
console.error(chalk.red(`ā Failed to extract tarball. On Windows, ensure tar is available (e.g. via Git or WSL).`));
if (!keepTemp) fs.removeSync(tempBase);
process.exit(1);
}
const packageDir = path.join(extractDir, 'package');
if (!fs.existsSync(packageDir)) {
const entries = fs.readdirSync(extractDir);
if (entries.length === 1 && fs.statSync(path.join(extractDir, entries[0])).isDirectory()) {
const singleDistPath = resolveDistPath(path.join(extractDir, entries[0]));
if (singleDistPath) {
await runGenerateAndCapture(singleDistPath, tempCoreCssDir, configPath, tempBase, keepTemp);
return;
}
}
console.error(chalk.red(`ā Expected extract dir structure: ${extractDir}/package not found.`));
if (!keepTemp) fs.removeSync(tempBase);
process.exit(1);
}
const distPath = resolveDistPath(packageDir);
if (!distPath) {
console.error(chalk.red(`ā Could not find dist path (scss/index.scss) under ${packageDir} or ${path.join(packageDir, 'dist')}.`));
if (!keepTemp) fs.removeSync(tempBase);
process.exit(1);
}
console.log(chalk.gray(` Resolved dist: ${distPath}\n`));
await runGenerateAndCapture(distPath, tempCoreCssDir, configPath, tempBase, keepTemp);
}
async function runGenerateAndCapture(distPath, tempCoreCssDir, configPath, tempBase, keepTemp) {
try {
console.log(chalk.blue(' Generating Core CSS from extracted package...'));
const { generateCoreCss } = await import('../core/generate-core-css.js');
await generateCoreCss({
distPath,
distCorePath: tempCoreCssDir,
silent: true,
});
} catch (err) {
console.error(chalk.red('ā generateCoreCss failed:'), err.message);
if (!keepTemp) fs.removeSync(tempBase);
process.exit(1);
}
if (!fs.existsSync(tempCoreCssDir)) {
console.error(chalk.red(`ā Generated CSS dir not found: ${tempCoreCssDir}`));
if (!keepTemp) fs.removeSync(tempBase);
process.exit(1);
}
console.log(chalk.blue(' Capturing baseline...'));
const captureScriptPath = path.resolve(__dirname, 'capture-baseline.js');
const configArg = argv.config;
try {
execSync(
`node "${captureScriptPath}" --config "${configArg}" --source "${tempCoreCssDir}"`,
{ cwd: CWD, stdio: 'inherit' }
);
} catch (err) {
console.error(chalk.red('ā capture-baseline failed.'));
if (!keepTemp) fs.removeSync(tempBase);
process.exit(1);
}
if (!keepTemp) {
fs.removeSync(tempBase);
} else {
console.log(chalk.gray(`\n Temp kept: ${tempBase}`));
}
console.log(chalk.green('\nā
Baseline from version captured. Run release:core-css:compare to validate current build.\n'));
}
main().catch((err) => {
console.error(chalk.red('ā Error:'), err);
process.exit(1);
});
|