Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"source-map-support": "^0.5.20",
"split": "1.0.1",
"string-length": "3.1.0",
"tar": "6.2.1",
"tar": "7.5.3",
"tmp": "0.2.4",
"typescript": "^5.7.2",
"typescript-eslint": "^8.18.2",
Expand Down
91 changes: 43 additions & 48 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 6 additions & 5 deletions src/__tests__/prepare-dry-run.e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ function normalizeOutput(output: string): string {
// Remove ANSI color codes
// eslint-disable-next-line no-control-regex -- Need to match ANSI escape sequences
.replace(/\x1b\[[0-9;]*m/g, '')
// Remove node deprecation warnings (must be before hash normalization)
.replace(/\(node:\d+\)[^\n]*DeprecationWarning[^\n]*\n?/g, '')
.replace(/\(node:\d+\)[^\n]*\n/g, '')
.replace(/\(Use `node --trace-warnings.*\n/g, '')
.replace(/\(Use `node --trace-deprecation.*\n/g, '')
.replace(/Support for loading ES Module.*\n/g, '')
// Normalize temp directory paths
.replace(/\/tmp\/craft-[a-z0-9-]+/g, '/tmp/craft-XXXXX')
// Normalize commit hashes (7-40 hex chars)
Expand All @@ -129,11 +135,6 @@ function normalizeOutput(output: string): string {
.replace(/craft-dry-run-[a-f0-9]+/g, 'craft-dry-run-XXXXX')
// Normalize line counts that might vary
.replace(/@@ -\d+,\d+ \+\d+,\d+ @@/g, '@@ -X,Y +X,Y @@')
// Remove node warnings and experimental warnings
.replace(/\(node:\d+\)[^\n]*\n/g, '')
.replace(/\(Use `node --trace-warnings.*\n/g, '')
.replace(/\(Use `node --trace-deprecation.*\n/g, '')
.replace(/Support for loading ES Module.*\n/g, '')
// Normalize PID references
.replace(/node:\d+/g, 'node:PID')
// Normalize branch names (main vs master)
Expand Down
28 changes: 16 additions & 12 deletions src/utils/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createHash, Hash } from 'crypto';
import * as fs from 'fs';
import * as path from 'path';
import split from 'split';
import tar from 'tar';
import * as tar from 'tar';
import extract from 'extract-zip';

import { logger } from '../logger';
Expand Down Expand Up @@ -62,10 +62,10 @@ function processError(
args?: string[],
options?: any,
stdout?: string,
stderr?: string
stderr?: string,
): Error {
const error = new Error(
`Process "${command}" errored with code ${code}\n\nSTDOUT: ${stdout}\n\nSTDERR:${stderr}`
`Process "${command}" errored with code ${code}\n\nSTDOUT: ${stdout}\n\nSTDERR:${stderr}`,
) as any;
error.code = code;
error.args = args;
Expand All @@ -84,7 +84,7 @@ function processError(
*/
export function replaceEnvVariable(
arg: string,
env: Record<string, any>
env: Record<string, any>,
): string {
if (!env || !arg || arg[0] !== '$') {
return arg;
Expand Down Expand Up @@ -131,12 +131,16 @@ export async function spawnProcess(
command: string,
args: string[] = [],
options: SpawnOptions = {},
spawnProcessOptions: SpawnProcessOptions = {}
spawnProcessOptions: SpawnProcessOptions = {},
): Promise<Buffer | undefined> {
const argsString = args.map(arg => `"${arg}"`).join(' ');

// Allow spawning in worktree mode (isolated environment) or when explicitly enabled
if (isDryRun() && !spawnProcessOptions.enableInDryRunMode && !isInWorktreeMode()) {
if (
isDryRun() &&
!spawnProcessOptions.enableInDryRunMode &&
!isInWorktreeMode()
) {
logger.info('[dry-run] Not spawning process:', `${command} ${argsString}`);
return undefined;
}
Expand All @@ -160,7 +164,7 @@ export async function spawnProcess(

// Do a shell-like replacement of arguments that look like environment variables
const processedArgs = args.map(arg =>
replaceEnvVariable(arg, { ...process.env, ...options.env })
replaceEnvVariable(arg, { ...process.env, ...options.env }),
);

// Allow child to accept input (use 'pipe' for stdin if we need to write to it)
Expand Down Expand Up @@ -219,7 +223,7 @@ export async function calculateChecksum(
algorithm?: HashAlgorithm;
/** Hash format */
format?: HashOutputFormat;
}
},
): Promise<string> {
const { algorithm = HashAlgorithm.SHA256, format = HashOutputFormat.Hex } =
options || {};
Expand Down Expand Up @@ -267,7 +271,7 @@ function getPotentialPaths(fileName: string): string[] {
.replace(/"/g, '')
.split(path.delimiter)
.map(chunk =>
envExt.split(path.delimiter).map(ext => path.join(chunk, fileName + ext))
envExt.split(path.delimiter).map(ext => path.join(chunk, fileName + ext)),
)
.reduce((a, b) => a.concat(b));
}
Expand Down Expand Up @@ -330,7 +334,7 @@ export function checkExecutableIsPresent(name: string): void {
*/
export async function extractSourcesFromTarStream(
stream: NodeJS.ReadableStream,
dir: string
dir: string,
): Promise<void> {
return new Promise<void>((resolve, reject) => {
try {
Expand All @@ -356,7 +360,7 @@ export async function extractSourcesFromTarStream(
*/
export async function extractZipArchive(
filePath: string,
dir: string
dir: string,
): Promise<void> {
await extract(filePath, { dir: dir });
}
Expand All @@ -373,7 +377,7 @@ export async function extractZipArchive(
export function catchKeyboardInterrupt(maxTimeDiff = 1000): void {
if (process.env.CRAFT_CATCH_KEYBOARD_INTERRUPT !== '1') {
logger.debug(
'Catching Ctrl-C is disabled by default. See https://github.com/getsentry/craft/issues/21'
'Catching Ctrl-C is disabled by default. See https://github.com/getsentry/craft/issues/21',
);
return;
}
Expand Down
Loading