From 103acebe2f3a96c0f8dcffdfd69c189e24df982f Mon Sep 17 00:00:00 2001 From: kdysput Date: Mon, 17 Jun 2024 13:45:26 +0200 Subject: [PATCH 01/13] Apply default formatting proposed by prettier latest --- .../attributes/WindowAttributeProvider.ts | 5 +++- .../src/main/ipc/ReadableIpcStream.ts | 6 ++++- .../modules/BacktraceMainElectronModule.ts | 11 +++++--- .../src/main/modules/IpcAttachment.ts | 6 ++++- .../src/renderer/ipc/WritableIpcStream.ts | 5 +++- .../renderer/modules/IpcReportSubmission.ts | 5 +++- .../renderer/modules/IpcSummedMetricsQueue.ts | 5 +++- .../node/src/BacktraceNodeRequestHandler.ts | 4 +-- .../attachment/BacktraceBufferAttachment.ts | 5 +++- .../src/attachment/BacktraceFileAttachment.ts | 5 +++- packages/node/tests/_mocks/fileSystem.ts | 4 +-- .../src/attributes/NativeAttributeProvider.ts | 5 +++- .../src/handlers/UnhandledExceptionHandler.ts | 4 +-- .../android/AndroidUnhandledException.ts | 6 ++++- .../sdk-core/src/common/abortInterfaces.ts | 8 +++--- .../OverwritingArrayIterator.ts | 6 ++++- .../attachment/BacktraceStringAttachment.ts | 5 +++- .../BacktraceUint8ArrayAttachment.ts | 5 +++- .../model/data/BacktraceSubmissionResult.ts | 5 +++- .../model/http/BacktraceReportSubmission.ts | 5 +++- .../modules/attribute/FileAttributeManager.ts | 5 +++- .../database/BacktraceDatabaseFileRecord.ts | 5 +++- .../BacktraceDatabaseFileStorageProvider.ts | 5 +++- .../src/modules/metrics/BacktraceMetrics.ts | 11 +++++--- packages/sdk-core/tests/_mocks/fileSystem.ts | 13 ++++++---- scripts/gitRelease.ts | 25 +++++++++++-------- scripts/release.ts | 21 +++++++++------- scripts/syncVersions.ts | 11 +++++--- tools/cli/src/sourcemaps/process.ts | 2 +- tools/cli/src/sourcemaps/run.ts | 10 ++++---- tools/cli/src/sourcemaps/upload.ts | 6 ++--- tools/sourcemap-tools/src/SymbolUploader.ts | 5 +++- 32 files changed, 154 insertions(+), 75 deletions(-) diff --git a/packages/electron/src/main/attributes/WindowAttributeProvider.ts b/packages/electron/src/main/attributes/WindowAttributeProvider.ts index 9d2bcf35..9ed8c322 100644 --- a/packages/electron/src/main/attributes/WindowAttributeProvider.ts +++ b/packages/electron/src/main/attributes/WindowAttributeProvider.ts @@ -17,7 +17,10 @@ export interface WindowAttributeProviderOptions { } export class WindowAttributeProvider implements BacktraceAttributeProvider { - constructor(private readonly _window: BrowserWindow, private readonly _options?: WindowAttributeProviderOptions) {} + constructor( + private readonly _window: BrowserWindow, + private readonly _options?: WindowAttributeProviderOptions, + ) {} public readonly type = 'dynamic'; diff --git a/packages/electron/src/main/ipc/ReadableIpcStream.ts b/packages/electron/src/main/ipc/ReadableIpcStream.ts index b1d08ea9..081630c9 100644 --- a/packages/electron/src/main/ipc/ReadableIpcStream.ts +++ b/packages/electron/src/main/ipc/ReadableIpcStream.ts @@ -7,7 +7,11 @@ import { ipcHandshake } from '../../common/ipc/ipcHandshake'; export class ReadableIpcStream extends Readable { private _isConnected = false; - constructor(private readonly _name: string, private readonly _ipc: IpcTransport, opts?: ReadableOptions) { + constructor( + private readonly _name: string, + private readonly _ipc: IpcTransport, + opts?: ReadableOptions, + ) { super(opts); const close = () => this.destroy(); diff --git a/packages/electron/src/main/modules/BacktraceMainElectronModule.ts b/packages/electron/src/main/modules/BacktraceMainElectronModule.ts index 415be21f..eb6d3971 100644 --- a/packages/electron/src/main/modules/BacktraceMainElectronModule.ts +++ b/packages/electron/src/main/modules/BacktraceMainElectronModule.ts @@ -121,8 +121,11 @@ export class BacktraceMainElectronModule implements BacktraceModule { } function toStringDictionary(record: Record): Record { - return Object.keys(record).reduce((obj, key) => { - obj[key] = record[key]?.toString() ?? ''; - return obj; - }, {} as Record); + return Object.keys(record).reduce( + (obj, key) => { + obj[key] = record[key]?.toString() ?? ''; + return obj; + }, + {} as Record, + ); } diff --git a/packages/electron/src/main/modules/IpcAttachment.ts b/packages/electron/src/main/modules/IpcAttachment.ts index 7feeb2d9..68b89219 100644 --- a/packages/electron/src/main/modules/IpcAttachment.ts +++ b/packages/electron/src/main/modules/IpcAttachment.ts @@ -4,7 +4,11 @@ import { IpcTransport } from '../../common'; import { ReadableIpcStream } from '../ipc/ReadableIpcStream'; export class IpcAttachment implements BacktraceAttachment { - constructor(public readonly name: string, private readonly _id: string, private readonly _ipc: IpcTransport) {} + constructor( + public readonly name: string, + private readonly _id: string, + private readonly _ipc: IpcTransport, + ) {} public get(): Readable { return new ReadableIpcStream(this._id, this._ipc); diff --git a/packages/electron/src/renderer/ipc/WritableIpcStream.ts b/packages/electron/src/renderer/ipc/WritableIpcStream.ts index 8662fd98..43c62d4d 100644 --- a/packages/electron/src/renderer/ipc/WritableIpcStream.ts +++ b/packages/electron/src/renderer/ipc/WritableIpcStream.ts @@ -15,7 +15,10 @@ export class WritableIpcStream extends WritableStream { class WritableIpcStreamSink implements UnderlyingSink { private _isPaused = false; - constructor(private readonly _name: string, private readonly _ipc: IpcTransport) { + constructor( + private readonly _name: string, + private readonly _ipc: IpcTransport, + ) { this._ipc.on(IpcEvents.streamEvent(_name, 'pause'), () => (this._isPaused = true)); this._ipc.on(IpcEvents.streamEvent(_name, 'resume'), () => (this._isPaused = false)); } diff --git a/packages/electron/src/renderer/modules/IpcReportSubmission.ts b/packages/electron/src/renderer/modules/IpcReportSubmission.ts index c727e75d..0c294eb7 100644 --- a/packages/electron/src/renderer/modules/IpcReportSubmission.ts +++ b/packages/electron/src/renderer/modules/IpcReportSubmission.ts @@ -14,7 +14,10 @@ import { IpcRpc } from '../../common/ipc/IpcRpc'; import { WritableIpcStream } from '../ipc/WritableIpcStream'; export class IpcReportSubmission implements BacktraceReportSubmission { - constructor(private readonly _ipcRpc: IpcRpc, private readonly _ipcTransport: IpcTransport) {} + constructor( + private readonly _ipcRpc: IpcRpc, + private readonly _ipcTransport: IpcTransport, + ) {} public send( data: BacktraceData, diff --git a/packages/electron/src/renderer/modules/IpcSummedMetricsQueue.ts b/packages/electron/src/renderer/modules/IpcSummedMetricsQueue.ts index 8330c40c..71bf621d 100644 --- a/packages/electron/src/renderer/modules/IpcSummedMetricsQueue.ts +++ b/packages/electron/src/renderer/modules/IpcSummedMetricsQueue.ts @@ -7,7 +7,10 @@ export class IpcSummedMetricsQueue implements MetricsQueue { public readonly submissionUrl = ''; public readonly maximumEvents = -1; - constructor(private readonly _ipcTransport: IpcTransport, private readonly _ipcRpc: IpcRpc) {} + constructor( + private readonly _ipcTransport: IpcTransport, + private readonly _ipcRpc: IpcRpc, + ) {} public add(event: SummedEvent): void { this._ipcTransport.emit(IpcEvents.addSummedMetric, event); diff --git a/packages/node/src/BacktraceNodeRequestHandler.ts b/packages/node/src/BacktraceNodeRequestHandler.ts index ecb98a54..c3f4b52e 100644 --- a/packages/node/src/BacktraceNodeRequestHandler.ts +++ b/packages/node/src/BacktraceNodeRequestHandler.ts @@ -112,8 +112,8 @@ export class BacktraceNodeRequestHandler implements BacktraceRequestHandler { this.reason instanceof Error ? this.reason : typeof this.reason === 'string' - ? new Error(this.reason) - : new Error('Operation cancelled.'); + ? new Error(this.reason) + : new Error('Operation cancelled.'); request.destroy(reason); } diff --git a/packages/node/src/attachment/BacktraceBufferAttachment.ts b/packages/node/src/attachment/BacktraceBufferAttachment.ts index b9e8de58..fa423fc7 100644 --- a/packages/node/src/attachment/BacktraceBufferAttachment.ts +++ b/packages/node/src/attachment/BacktraceBufferAttachment.ts @@ -1,7 +1,10 @@ import { BacktraceAttachment } from '@backtrace/sdk-core'; export class BacktraceBufferAttachment implements BacktraceAttachment { - constructor(public readonly name: string, public readonly buffer: Buffer) {} + constructor( + public readonly name: string, + public readonly buffer: Buffer, + ) {} public get(): Buffer { return this.buffer; } diff --git a/packages/node/src/attachment/BacktraceFileAttachment.ts b/packages/node/src/attachment/BacktraceFileAttachment.ts index cad54a49..e1cc04ac 100644 --- a/packages/node/src/attachment/BacktraceFileAttachment.ts +++ b/packages/node/src/attachment/BacktraceFileAttachment.ts @@ -6,7 +6,10 @@ import { Readable } from 'stream'; export class BacktraceFileAttachment implements CoreBacktraceFileAttachment { public readonly name: string; - constructor(public readonly filePath: string, name?: string) { + constructor( + public readonly filePath: string, + name?: string, + ) { this.name = name ?? path.basename(this.filePath); } diff --git a/packages/node/tests/_mocks/fileSystem.ts b/packages/node/tests/_mocks/fileSystem.ts index f1c631ae..f7934b96 100644 --- a/packages/node/tests/_mocks/fileSystem.ts +++ b/packages/node/tests/_mocks/fileSystem.ts @@ -27,8 +27,8 @@ export function mockStreamFileSystem(files?: Record): MockedFile const str = Buffer.isBuffer(chunk) ? chunk.toString('utf-8') : typeof chunk === 'string' - ? chunk - : String(chunk).toString(); + ? chunk + : String(chunk).toString(); const fullPath = path.resolve(p); if (!fs.files[fullPath]) { diff --git a/packages/react-native/src/attributes/NativeAttributeProvider.ts b/packages/react-native/src/attributes/NativeAttributeProvider.ts index 8f9dcec7..62e32ec9 100644 --- a/packages/react-native/src/attributes/NativeAttributeProvider.ts +++ b/packages/react-native/src/attributes/NativeAttributeProvider.ts @@ -3,7 +3,10 @@ import { NativeModules } from 'react-native'; export class NativeAttributeProvider implements BacktraceAttributeProvider { private readonly _provider: { get(): Record }; - constructor(private readonly _name: string, public readonly type: 'scoped' | 'dynamic') { + constructor( + private readonly _name: string, + public readonly type: 'scoped' | 'dynamic', + ) { this._provider = NativeModules?.[this._name]; } diff --git a/packages/react-native/src/handlers/UnhandledExceptionHandler.ts b/packages/react-native/src/handlers/UnhandledExceptionHandler.ts index 7143dd48..a631d457 100644 --- a/packages/react-native/src/handlers/UnhandledExceptionHandler.ts +++ b/packages/react-native/src/handlers/UnhandledExceptionHandler.ts @@ -96,8 +96,8 @@ export class UnhandledExceptionHandler implements ExceptionHandler { message = cachedPrettyFormat ? cachedPrettyFormat(rejection) : typeof rejection === 'string' - ? rejection - : JSON.stringify({ ...rejection }); + ? rejection + : JSON.stringify({ ...rejection }); } const warning = diff --git a/packages/react-native/src/handlers/android/AndroidUnhandledException.ts b/packages/react-native/src/handlers/android/AndroidUnhandledException.ts index f6002f1b..32c4f882 100644 --- a/packages/react-native/src/handlers/android/AndroidUnhandledException.ts +++ b/packages/react-native/src/handlers/android/AndroidUnhandledException.ts @@ -1,5 +1,9 @@ export class AndroidUnhandledException extends Error { - constructor(public readonly name: string, public readonly message: string, public readonly stack: string) { + constructor( + public readonly name: string, + public readonly message: string, + public readonly stack: string, + ) { super(message); } } diff --git a/packages/sdk-core/src/common/abortInterfaces.ts b/packages/sdk-core/src/common/abortInterfaces.ts index ebdb9444..350e8ca1 100644 --- a/packages/sdk-core/src/common/abortInterfaces.ts +++ b/packages/sdk-core/src/common/abortInterfaces.ts @@ -4,10 +4,10 @@ function getGlobal(key: K): (typeof window)[K] | return typeof window !== 'undefined' ? window[key as keyof typeof window] : typeof global !== 'undefined' - ? global[key as keyof typeof global] - : typeof self !== 'undefined' - ? self[key as keyof typeof self] - : undefined; + ? global[key as keyof typeof global] + : typeof self !== 'undefined' + ? self[key as keyof typeof self] + : undefined; } export type OriginalAbortController = AbortController; diff --git a/packages/sdk-core/src/dataStructures/OverwritingArrayIterator.ts b/packages/sdk-core/src/dataStructures/OverwritingArrayIterator.ts index 879656d8..b0f9abc8 100644 --- a/packages/sdk-core/src/dataStructures/OverwritingArrayIterator.ts +++ b/packages/sdk-core/src/dataStructures/OverwritingArrayIterator.ts @@ -1,7 +1,11 @@ export class OverwritingArrayIterator implements IterableIterator { private _index?: number; - constructor(private readonly _source: T[], private readonly _offset: number, private readonly _size: number) {} + constructor( + private readonly _source: T[], + private readonly _offset: number, + private readonly _size: number, + ) {} [Symbol.iterator](): IterableIterator { return new OverwritingArrayIterator(this._source, this._offset, this._size); diff --git a/packages/sdk-core/src/model/attachment/BacktraceStringAttachment.ts b/packages/sdk-core/src/model/attachment/BacktraceStringAttachment.ts index 55df171a..dafaa0ec 100644 --- a/packages/sdk-core/src/model/attachment/BacktraceStringAttachment.ts +++ b/packages/sdk-core/src/model/attachment/BacktraceStringAttachment.ts @@ -1,7 +1,10 @@ import { BacktraceAttachment } from './BacktraceAttachment'; export class BacktraceStringAttachment implements BacktraceAttachment { - constructor(public readonly name: string, public readonly data: string) {} + constructor( + public readonly name: string, + public readonly data: string, + ) {} public get(): string { return this.data; diff --git a/packages/sdk-core/src/model/attachment/BacktraceUint8ArrayAttachment.ts b/packages/sdk-core/src/model/attachment/BacktraceUint8ArrayAttachment.ts index de66c3f9..79561389 100644 --- a/packages/sdk-core/src/model/attachment/BacktraceUint8ArrayAttachment.ts +++ b/packages/sdk-core/src/model/attachment/BacktraceUint8ArrayAttachment.ts @@ -1,7 +1,10 @@ import { BacktraceAttachment } from './BacktraceAttachment'; export class BacktraceUint8ArrayAttachment implements BacktraceAttachment { - constructor(public readonly name: string, public readonly data: Uint8Array) {} + constructor( + public readonly name: string, + public readonly data: Uint8Array, + ) {} public get(): Blob { return new Blob([this.data.buffer]); diff --git a/packages/sdk-core/src/model/data/BacktraceSubmissionResult.ts b/packages/sdk-core/src/model/data/BacktraceSubmissionResult.ts index be3486a8..1ab35fe1 100644 --- a/packages/sdk-core/src/model/data/BacktraceSubmissionResult.ts +++ b/packages/sdk-core/src/model/data/BacktraceSubmissionResult.ts @@ -10,7 +10,10 @@ export class BacktraceReportSubmissionResult { private _result?: T; private constructor(response: T); private constructor(_status: BacktraceSubmissionStatus, _message?: string); - private constructor(statusOrResponse: T | BacktraceSubmissionStatus, public readonly message?: string) { + private constructor( + statusOrResponse: T | BacktraceSubmissionStatus, + public readonly message?: string, + ) { if (this.isSubmissionResponse(statusOrResponse)) { this.status = statusOrResponse; return; diff --git a/packages/sdk-core/src/model/http/BacktraceReportSubmission.ts b/packages/sdk-core/src/model/http/BacktraceReportSubmission.ts index 76ac02cb..5d174915 100644 --- a/packages/sdk-core/src/model/http/BacktraceReportSubmission.ts +++ b/packages/sdk-core/src/model/http/BacktraceReportSubmission.ts @@ -17,7 +17,10 @@ export interface BacktraceReportSubmission { export class RequestBacktraceReportSubmission { private readonly _submissionUrl: string; - constructor(options: BacktraceConfiguration, private readonly _requestHandler: BacktraceRequestHandler) { + constructor( + options: BacktraceConfiguration, + private readonly _requestHandler: BacktraceRequestHandler, + ) { this._submissionUrl = SubmissionUrlInformation.toJsonReportSubmissionUrl(options.url, options.token); } diff --git a/packages/sdk-core/src/modules/attribute/FileAttributeManager.ts b/packages/sdk-core/src/modules/attribute/FileAttributeManager.ts index a38dc8ce..3a97541e 100644 --- a/packages/sdk-core/src/modules/attribute/FileAttributeManager.ts +++ b/packages/sdk-core/src/modules/attribute/FileAttributeManager.ts @@ -9,7 +9,10 @@ const ATTRIBUTE_FILE_NAME = 'bt-attributes'; export class FileAttributeManager implements BacktraceModule { private _attributeManager?: AttributeManager; - constructor(private readonly _fileSystem: FileSystem, private _fileName?: string) {} + constructor( + private readonly _fileSystem: FileSystem, + private _fileName?: string, + ) {} public static create(fileSystem: FileSystem) { return new FileAttributeManager(fileSystem); diff --git a/packages/sdk-core/src/modules/database/BacktraceDatabaseFileRecord.ts b/packages/sdk-core/src/modules/database/BacktraceDatabaseFileRecord.ts index adb896c0..1b9c79e0 100644 --- a/packages/sdk-core/src/modules/database/BacktraceDatabaseFileRecord.ts +++ b/packages/sdk-core/src/modules/database/BacktraceDatabaseFileRecord.ts @@ -11,7 +11,10 @@ export class BacktraceDatabaseFileRecord implements BacktraceDatabaseRecord { public readonly timestamp: number; public locked: boolean; - private constructor(record: BacktraceDatabaseRecord, public readonly attachments: BacktraceAttachment[]) { + private constructor( + record: BacktraceDatabaseRecord, + public readonly attachments: BacktraceAttachment[], + ) { this.data = record.data; this.id = record.id; this.count = record.count; diff --git a/packages/sdk-core/src/modules/database/BacktraceDatabaseFileStorageProvider.ts b/packages/sdk-core/src/modules/database/BacktraceDatabaseFileStorageProvider.ts index be812428..2d0e728e 100644 --- a/packages/sdk-core/src/modules/database/BacktraceDatabaseFileStorageProvider.ts +++ b/packages/sdk-core/src/modules/database/BacktraceDatabaseFileStorageProvider.ts @@ -9,7 +9,10 @@ export class BacktraceDatabaseFileStorageProvider implements BacktraceDatabaseSt private _enabled = true; private readonly RECORD_SUFFIX = '-record.json'; - private constructor(private readonly _fileSystem: FileSystem, private readonly _path: string) {} + private constructor( + private readonly _fileSystem: FileSystem, + private readonly _path: string, + ) {} /** * Create a provider if provided options are valid diff --git a/packages/sdk-core/src/modules/metrics/BacktraceMetrics.ts b/packages/sdk-core/src/modules/metrics/BacktraceMetrics.ts index 2031c9fc..d5959687 100644 --- a/packages/sdk-core/src/modules/metrics/BacktraceMetrics.ts +++ b/packages/sdk-core/src/modules/metrics/BacktraceMetrics.ts @@ -126,10 +126,13 @@ export class BacktraceMetrics implements BacktraceModule { private convertAttributes(attributes: Record) { return Object.keys(attributes) .filter((n) => attributes[n] != null) - .reduce((acc, n) => { - acc[n] = attributes[n]?.toString(); - return acc; - }, {} as Record); + .reduce( + (acc, n) => { + acc[n] = attributes[n]?.toString(); + return acc; + }, + {} as Record, + ); } private async handleAbort(fn: () => Promise): Promise { diff --git a/packages/sdk-core/tests/_mocks/fileSystem.ts b/packages/sdk-core/tests/_mocks/fileSystem.ts index ce50f192..983585ff 100644 --- a/packages/sdk-core/tests/_mocks/fileSystem.ts +++ b/packages/sdk-core/tests/_mocks/fileSystem.ts @@ -10,10 +10,13 @@ export type MockedFileSystem = { export function mockFileSystem(files?: Record): MockedFileSystem { const fs = Object.entries(files ?? {}) .map(([k, v]) => [path.resolve(k), v]) - .reduce((obj, [k, v]) => { - obj[k] = v; - return obj; - }, {} as Record); + .reduce( + (obj, [k, v]) => { + obj[k] = v; + return obj; + }, + {} as Record, + ); function readDir(dir: string) { return Object.keys(fs) @@ -53,7 +56,7 @@ export function mockFileSystem(files?: Record): MockedFileSystem filePath: p, name: path.basename(p), get: jest.fn().mockReturnValue(fs[path.resolve(p)]), - } as BacktraceFileAttachment), + }) as BacktraceFileAttachment, ), }; } diff --git a/scripts/gitRelease.ts b/scripts/gitRelease.ts index ddbc1ea1..a9dac42f 100755 --- a/scripts/gitRelease.ts +++ b/scripts/gitRelease.ts @@ -41,8 +41,8 @@ function updateVersion( rawIdentifierBase === '0' || rawIdentifierBase === '1' ? rawIdentifierBase : rawIdentifierBase === 'false' - ? false - : undefined; + ? false + : undefined; const result = semver.inc(version, versionOrRelease as ReleaseType, identifier, identifierBase); if (result == null) { @@ -73,16 +73,19 @@ async function main() { throw new Error('second argument must be a version or release type'); } - const optionValues = options.reduce((val, k) => { - const opt = argv.find((v) => v.startsWith(`${k}=`)); - if (opt) { - val[k] = opt.replace(`${k}=`, ''); - } else { - val[k] = argv.includes(k); - } + const optionValues = options.reduce( + (val, k) => { + const opt = argv.find((v) => v.startsWith(`${k}=`)); + if (opt) { + val[k] = opt.replace(`${k}=`, ''); + } else { + val[k] = argv.includes(k); + } - return val; - }, {} as Record<(typeof options)[number], boolean | string>); + return val; + }, + {} as Record<(typeof options)[number], boolean | string>, + ); const dryRun = optionValues['--dry-run']; if (dryRun) { diff --git a/scripts/release.ts b/scripts/release.ts index 89878279..526706a4 100755 --- a/scripts/release.ts +++ b/scripts/release.ts @@ -22,16 +22,19 @@ async function main() { throw new Error('first argument must be a package.json path'); } - const optionValues = options.reduce((val, k) => { - const opt = argv.find((v) => v.startsWith(`${k}=`)); - if (opt) { - val[k] = opt.replace(`${k}=`, ''); - } else { - val[k] = argv.includes(k); - } + const optionValues = options.reduce( + (val, k) => { + const opt = argv.find((v) => v.startsWith(`${k}=`)); + if (opt) { + val[k] = opt.replace(`${k}=`, ''); + } else { + val[k] = argv.includes(k); + } - return val; - }, {} as Record<(typeof options)[number], boolean | string>); + return val; + }, + {} as Record<(typeof options)[number], boolean | string>, + ); const dryRun = optionValues['--dry-run']; if (dryRun) { diff --git a/scripts/syncVersions.ts b/scripts/syncVersions.ts index 7ffdef9c..69092e2c 100755 --- a/scripts/syncVersions.ts +++ b/scripts/syncVersions.ts @@ -65,10 +65,13 @@ function updateVersions(packageJson: PackageJson, currentVersions: Record { - obj[pj.name] = pj.version; - return obj; - }, {} as Record); + const currentVersions = workspacePackageJsons.reduce( + (obj, pj) => { + obj[pj.name] = pj.version; + return obj; + }, + {} as Record, + ); for (const packageJsonPath of packageJsonPathsToSync) { const packageJson = await loadPackageJson(packageJsonPath); diff --git a/tools/cli/src/sourcemaps/process.ts b/tools/cli/src/sourcemaps/process.ts index 2da49c34..348c1f90 100644 --- a/tools/cli/src/sourcemaps/process.ts +++ b/tools/cli/src/sourcemaps/process.ts @@ -215,7 +215,7 @@ export function processSource(force: boolean) { source: { ...asset.source, content: result.source }, sourceMap: { ...asset.sourceMap, content: result.sourceMap }, debugId: result.debugId, - } as ProcessedSourceAndSourceMap), + }) as ProcessedSourceAndSourceMap, ), ); }; diff --git a/tools/cli/src/sourcemaps/run.ts b/tools/cli/src/sourcemaps/run.ts index b4fbbe14..4766f203 100644 --- a/tools/cli/src/sourcemaps/run.ts +++ b/tools/cli/src/sourcemaps/run.ts @@ -261,7 +261,7 @@ export async function runSourcemapCommands({ opts, logger, getHelpMessage }: Com logTraceAssets('processing source and sourcemap'), processSource(processOptions.force ?? false), logDebugAssets('processed source and sourcemap'), - (result) => ({ ...result, processed: true } as SourceAndSourceMap & AssetResult), + (result) => ({ ...result, processed: true }) as SourceAndSourceMap & AssetResult, ) : pass, addSources @@ -273,9 +273,9 @@ export async function runSourcemapCommands({ opts, logger, getHelpMessage }: Com R.map(logDebugAsset('source added to sourcemap')), R.map( ({ content }) => - ({ ...assets, sourceMap: { ...assets.sourceMap, content } } as SourceAndSourceMap), + ({ ...assets, sourceMap: { ...assets.sourceMap, content } }) as SourceAndSourceMap, ), - R.map((result) => ({ ...result, sourceAdded: true } as SourceAndSourceMap & AssetResult)), + R.map((result) => ({ ...result, sourceAdded: true }) as SourceAndSourceMap & AssetResult), ) : Ok, R.map( @@ -340,8 +340,8 @@ export async function runSourcemapCommands({ opts, logger, getHelpMessage }: Com uploadOptions['dry-run'] ? Ok({ rxid: '' }) : assets.length - ? saveArchiveCommand(assets) - : Ok(null), + ? saveArchiveCommand(assets) + : Ok(null), ), R.map( logInfo((result: UploadResult | null) => diff --git a/tools/cli/src/sourcemaps/upload.ts b/tools/cli/src/sourcemaps/upload.ts index efc2b8ac..0f5dbeec 100644 --- a/tools/cli/src/sourcemaps/upload.ts +++ b/tools/cli/src/sourcemaps/upload.ts @@ -290,8 +290,8 @@ export async function uploadSourcemaps({ opts, logger, getHelpMessage }: Command assets, }) : assets.length - ? saveArchiveCommand(assets) - : Ok({ rxid: '', assets }), + ? saveArchiveCommand(assets) + : Ok({ rxid: '', assets }), ), R.map(output(logger)), ), @@ -340,7 +340,7 @@ export function uploadAssets(uploadUrl: string, options: SymbolUploaderOptions) export function saveAssets(outputPath: string) { return function saveAssets(assets: AssetWithContent[]): Promise { const stream = fs.createWriteStream(outputPath); - return pipe(stream, pipeAssets(assets), () => ({ rxid: outputPath } as UploadResult)); + return pipe(stream, pipeAssets(assets), () => ({ rxid: outputPath }) as UploadResult); }; } diff --git a/tools/sourcemap-tools/src/SymbolUploader.ts b/tools/sourcemap-tools/src/SymbolUploader.ts index 58ec2302..28e88f5b 100644 --- a/tools/sourcemap-tools/src/SymbolUploader.ts +++ b/tools/sourcemap-tools/src/SymbolUploader.ts @@ -30,7 +30,10 @@ export interface SymbolRequest { export class SymbolUploader { private readonly _url: URL; - constructor(url: string | URL, private readonly _options?: SymbolUploaderOptions) { + constructor( + url: string | URL, + private readonly _options?: SymbolUploaderOptions, + ) { this._url = new URL(url); } From d4288afa957ed448ddec949e53de670ce881bf95 Mon Sep 17 00:00:00 2001 From: kdysput Date: Mon, 17 Jun 2024 13:50:03 +0200 Subject: [PATCH 02/13] Force to use prettierrc.json --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 3c9df4a4..6df2a0b8 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "build": "tsc -b ./tsconfig.packages.json && npm run build --ws --if-present", "clean": "tsc -b --clean && rimraf \"lib\" && npm run clean --ws --if-present", "format": "prettier --write \"**/*.ts\"", - "format:check": "prettier --check \"**/*.ts\"", + "format:check": "prettier --check \"**/*.ts\" --config .prettierrc.json", "lint": "eslint . --ext .ts", "rebuild": "npm run clean && npm run build", "watch": "tsc -b ./tsconfig.packages.json -w", From cdb18d8c43a1401f7cdfec4e04b9ef3b84e3c3ec Mon Sep 17 00:00:00 2001 From: kdysput Date: Mon, 17 Jun 2024 13:55:14 +0200 Subject: [PATCH 03/13] Print file structure --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 84925544..374b4618 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -55,6 +55,7 @@ jobs: node-version: 18.x - run: npm ci - run: npm run build + - run: ls - run: npm run lint - run: npm run format:check - run: npm test From f8232aa3c78cbca9b6a45583731d5d1c3e5c1886 Mon Sep 17 00:00:00 2001 From: kdysput Date: Mon, 17 Jun 2024 14:02:19 +0200 Subject: [PATCH 04/13] Escape file name --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6df2a0b8..b81ff43a 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "build": "tsc -b ./tsconfig.packages.json && npm run build --ws --if-present", "clean": "tsc -b --clean && rimraf \"lib\" && npm run clean --ws --if-present", "format": "prettier --write \"**/*.ts\"", - "format:check": "prettier --check \"**/*.ts\" --config .prettierrc.json", + "format:check": "prettier --check \"**/*.ts\" --config \".prettierrc.json\"", "lint": "eslint . --ext .ts", "rebuild": "npm run clean && npm run build", "watch": "tsc -b ./tsconfig.packages.json -w", From 8e9d79c6f1cbadef9b74c4472ce670d1eafd80ed Mon Sep 17 00:00:00 2001 From: kdysput Date: Mon, 17 Jun 2024 14:05:49 +0200 Subject: [PATCH 05/13] Auto end of line --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index b81ff43a..6757a807 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "build": "tsc -b ./tsconfig.packages.json && npm run build --ws --if-present", "clean": "tsc -b --clean && rimraf \"lib\" && npm run clean --ws --if-present", "format": "prettier --write \"**/*.ts\"", - "format:check": "prettier --check \"**/*.ts\" --config \".prettierrc.json\"", + "format:check": "prettier --check \"**/*.ts\" --config \".prettierrc.json\" --end-of-line auto", "lint": "eslint . --ext .ts", "rebuild": "npm run clean && npm run build", "watch": "tsc -b ./tsconfig.packages.json -w", From a673d9774ae74339b62a69a8003d7a2fe6aaf3bb Mon Sep 17 00:00:00 2001 From: kdysput Date: Mon, 17 Jun 2024 14:14:29 +0200 Subject: [PATCH 06/13] Use powershell --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 374b4618..c283d0de 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -55,7 +55,7 @@ jobs: node-version: 18.x - run: npm ci - run: npm run build - - run: ls - run: npm run lint - run: npm run format:check - run: npm test + shell: pwsh From 1aa8657e8b7cc0109952223ff93e5266e6323c13 Mon Sep 17 00:00:00 2001 From: kdysput Date: Mon, 17 Jun 2024 14:16:26 +0200 Subject: [PATCH 07/13] Correct YAML --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index c283d0de..f38cc7dd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -58,4 +58,4 @@ jobs: - run: npm run lint - run: npm run format:check - run: npm test - shell: pwsh + shell: pwsh From aaeeca99065e58e60651704a6b16773435803f38 Mon Sep 17 00:00:00 2001 From: kdysput Date: Mon, 17 Jun 2024 14:23:29 +0200 Subject: [PATCH 08/13] Use win-node-env --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index f38cc7dd..830005d1 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,5 +57,6 @@ jobs: - run: npm run build - run: npm run lint - run: npm run format:check + - run: npm install -g win-node-env - run: npm test shell: pwsh From 23ae359aa5342060b3177d96fc3360e58df2afa2 Mon Sep 17 00:00:00 2001 From: kdysput Date: Mon, 17 Jun 2024 14:23:45 +0200 Subject: [PATCH 09/13] Do not require powershell if not needed --- .github/workflows/test.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 830005d1..b41c3745 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -59,4 +59,3 @@ jobs: - run: npm run format:check - run: npm install -g win-node-env - run: npm test - shell: pwsh From 20adeaf4ef1d4de53847f4a910f35e497d2a956e Mon Sep 17 00:00:00 2001 From: kdysput Date: Mon, 17 Jun 2024 14:59:03 +0200 Subject: [PATCH 10/13] Remove changes that dont belong to this pull request --- .github/workflows/test.yml | 1 - package.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b41c3745..84925544 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -57,5 +57,4 @@ jobs: - run: npm run build - run: npm run lint - run: npm run format:check - - run: npm install -g win-node-env - run: npm test diff --git a/package.json b/package.json index 6757a807..3c9df4a4 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "build": "tsc -b ./tsconfig.packages.json && npm run build --ws --if-present", "clean": "tsc -b --clean && rimraf \"lib\" && npm run clean --ws --if-present", "format": "prettier --write \"**/*.ts\"", - "format:check": "prettier --check \"**/*.ts\" --config \".prettierrc.json\" --end-of-line auto", + "format:check": "prettier --check \"**/*.ts\"", "lint": "eslint . --ext .ts", "rebuild": "npm run clean && npm run build", "watch": "tsc -b ./tsconfig.packages.json -w", From a0a2562ebfacd1a2f60a8d24be1565b30a5164b5 Mon Sep 17 00:00:00 2001 From: Sebastian Alex Date: Mon, 17 Jun 2024 14:39:06 +0200 Subject: [PATCH 11/13] use cross-env for setting NODE_ENV variables --- examples/sdk/node/package.json | 2 +- package-lock.json | 19 +++++++++++++++++++ package.json | 1 + packages/browser/package.json | 4 ++-- packages/electron/package.json | 4 ++-- packages/nestjs/package.json | 4 ++-- packages/node/package.json | 4 ++-- packages/react-native/package.json | 2 +- packages/react/package.json | 4 ++-- packages/sdk-core/package.json | 2 +- tools/cli/package.json | 4 ++-- tools/rollup-plugin/package.json | 2 +- tools/sourcemap-tools/package.json | 2 +- tools/vite-plugin/package.json | 2 +- tools/webpack-plugin/package.json | 6 +++--- 15 files changed, 41 insertions(+), 21 deletions(-) diff --git a/examples/sdk/node/package.json b/examples/sdk/node/package.json index f8f7d020..444545d1 100644 --- a/examples/sdk/node/package.json +++ b/examples/sdk/node/package.json @@ -12,7 +12,7 @@ "clean": "rimraf \"lib\"", "format": "prettier --write '**/*.ts'", "lint": "eslint . --ext .ts", - "start": "NODE_ENV=production node ./lib/index.js", + "start": "cross-env NODE_ENV=production node ./lib/index.js", "watch": "tsc -w" }, "repository": { diff --git a/package-lock.json b/package-lock.json index 236a15e6..640194b3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,7 @@ "@types/semver": "^7.5.3", "@typescript-eslint/eslint-plugin": "^5.59.7", "@typescript-eslint/parser": "^5.59.7", + "cross-env": "^7.0.3", "eslint": "^8.41.0", "eslint-config-prettier": "^8.8.0", "eslint-plugin-import": "^2.27.5", @@ -7012,6 +7013,24 @@ "dev": true, "license": "MIT" }, + "node_modules/cross-env": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/cross-env/-/cross-env-7.0.3.tgz", + "integrity": "sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==", + "dev": true, + "dependencies": { + "cross-spawn": "^7.0.1" + }, + "bin": { + "cross-env": "src/bin/cross-env.js", + "cross-env-shell": "src/bin/cross-env-shell.js" + }, + "engines": { + "node": ">=10.14", + "npm": ">=6", + "yarn": ">=1" + } + }, "node_modules/cross-spawn": { "version": "7.0.3", "license": "MIT", diff --git a/package.json b/package.json index 3c9df4a4..47248feb 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "@types/semver": "^7.5.3", "@typescript-eslint/eslint-plugin": "^5.59.7", "@typescript-eslint/parser": "^5.59.7", + "cross-env": "^7.0.3", "eslint": "^8.41.0", "eslint-config-prettier": "^8.8.0", "eslint-plugin-import": "^2.27.5", diff --git a/packages/browser/package.json b/packages/browser/package.json index 6ce26f15..82fcc41b 100644 --- a/packages/browser/package.json +++ b/packages/browser/package.json @@ -10,9 +10,9 @@ "clean": "rimraf \"lib\"", "format": "prettier --write '**/*.ts'", "lint": "eslint . --ext .ts", - "prepublishOnly": "NODE_ENV=production npm run build", + "prepublishOnly": "cross-env NODE_ENV=production npm run build", "watch": "webpack -w", - "test": "NODE_ENV=test jest" + "test": "cross-env NODE_ENV=test jest" }, "repository": { "type": "git", diff --git a/packages/electron/package.json b/packages/electron/package.json index 95c1f084..9b0727b1 100644 --- a/packages/electron/package.json +++ b/packages/electron/package.json @@ -9,9 +9,9 @@ "clean": "rimraf common main renderer", "format": "prettier --write '**/*.ts'", "lint": "eslint src --ext .ts", - "prepublishOnly": "NODE_ENV=production npm run build", + "prepublishOnly": "cross-env NODE_ENV=production npm run build", "watch": "webpack -w", - "test": "NODE_ENV=test jest --passWithNoTests" + "test": "cross-env NODE_ENV=test jest --passWithNoTests" }, "keywords": [ "Error", diff --git a/packages/nestjs/package.json b/packages/nestjs/package.json index 1eb6344a..cf56409a 100644 --- a/packages/nestjs/package.json +++ b/packages/nestjs/package.json @@ -9,9 +9,9 @@ "clean": "rimraf \"lib\"", "format": "prettier --write '**/*.ts'", "lint": "eslint . --ext .ts", - "prepublishOnly": "NODE_ENV=production npm run build", + "prepublishOnly": "cross-env NODE_ENV=production npm run build", "watch": "webpack -w", - "test": "NODE_ENV=test jest --passWithNoTests" + "test": "cross-env NODE_ENV=test jest --passWithNoTests" }, "engines": { "node": ">=14" diff --git a/packages/node/package.json b/packages/node/package.json index fe21cd72..488e9e06 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -9,9 +9,9 @@ "clean": "rimraf \"lib\"", "format": "prettier --write '**/*.ts'", "lint": "eslint . --ext .ts", - "prepublishOnly": "NODE_ENV=production npm run build", + "prepublishOnly": "cross-env NODE_ENV=production npm run build", "watch": "webpack -w", - "test": "NODE_ENV=test jest" + "test": "cross-env NODE_ENV=test jest" }, "engines": { "node": ">=14" diff --git a/packages/react-native/package.json b/packages/react-native/package.json index ed6d32dd..b428a4fd 100644 --- a/packages/react-native/package.json +++ b/packages/react-native/package.json @@ -31,7 +31,7 @@ "clean": "rimraf \"lib\"", "format:check": "eslint \"**/*.{js,ts,tsx}\"", "prepublishOnly": "bob build", - "test": "NODE_ENV=test jest" + "test": "cross-env NODE_ENV=test jest" }, "keywords": [ "Error", diff --git a/packages/react/package.json b/packages/react/package.json index 2fae1456..0b00c732 100644 --- a/packages/react/package.json +++ b/packages/react/package.json @@ -8,9 +8,9 @@ "clean": "rimraf \"lib\"", "format": "prettier --write '**/*.ts'", "lint": "eslint . --ext .ts", - "prepublishOnly": "NODE_ENV=production npm run build", + "prepublishOnly": "cross-env NODE_ENV=production npm run build", "watch": "webpack -w", - "test": "NODE_ENV=test jest" + "test": "cross-env NODE_ENV=test jest" }, "repository": { "type": "git", diff --git a/packages/sdk-core/package.json b/packages/sdk-core/package.json index 5cd009cf..4ecd1c20 100644 --- a/packages/sdk-core/package.json +++ b/packages/sdk-core/package.json @@ -10,7 +10,7 @@ "format": "prettier --write '**/*.ts'", "lint": "eslint . --ext .ts", "watch": "tsc -w", - "test": "NODE_ENV=test jest" + "test": "cross-env NODE_ENV=test jest" }, "repository": { "type": "git", diff --git a/tools/cli/package.json b/tools/cli/package.json index b644cc5b..cc572d6a 100644 --- a/tools/cli/package.json +++ b/tools/cli/package.json @@ -15,10 +15,10 @@ "clean": "tsc -b --clean && rimraf \"lib\"", "format": "prettier --write '**/*.ts'", "lint": "eslint . --ext .ts", - "prepublishOnly": "NODE_ENV=production npm run build", + "prepublishOnly": "cross-env NODE_ENV=production npm run build", "watch": "tsc -w", "start": "node lib/index.js", - "test": "NODE_ENV=test jest" + "test": "cross-env NODE_ENV=test jest" }, "repository": { "type": "git", diff --git a/tools/rollup-plugin/package.json b/tools/rollup-plugin/package.json index be50dd38..bfe0cb09 100644 --- a/tools/rollup-plugin/package.json +++ b/tools/rollup-plugin/package.json @@ -12,7 +12,7 @@ "build:rollup": "rollup --config rollup.config.js", "clean": "tsc -b ./tsconfig.build.json --clean && rimraf \"lib\"", "format": "prettier --write '**/*.ts'", - "prepublishOnly": "NODE_ENV=production npm run build", + "prepublishOnly": "cross-env NODE_ENV=production npm run build", "lint": "eslint . --ext .ts", "watch": "tsc -b ./tsconfig.build.json -w" }, diff --git a/tools/sourcemap-tools/package.json b/tools/sourcemap-tools/package.json index ffcd0e3c..9fedef48 100644 --- a/tools/sourcemap-tools/package.json +++ b/tools/sourcemap-tools/package.json @@ -13,7 +13,7 @@ "format": "prettier --write '**/*.ts'", "lint": "eslint . --ext .ts", "watch": "tsc -w", - "test": "NODE_ENV=test jest" + "test": "cross-env NODE_ENV=test jest" }, "repository": { "type": "git", diff --git a/tools/vite-plugin/package.json b/tools/vite-plugin/package.json index fb97d93b..d0066625 100644 --- a/tools/vite-plugin/package.json +++ b/tools/vite-plugin/package.json @@ -12,7 +12,7 @@ "build:vite": "vite build --config vite.config.js", "clean": "tsc -b ./tsconfig.build.json --clean && rimraf \"lib\"", "format": "prettier --write '**/*.ts'", - "prepublishOnly": "NODE_ENV=production npm run build", + "prepublishOnly": "cross-env NODE_ENV=production npm run build", "lint": "eslint . --ext .ts", "watch": "tsc -b ./tsconfig.build.json -w" }, diff --git a/tools/webpack-plugin/package.json b/tools/webpack-plugin/package.json index 7d44b9d3..05b64f57 100644 --- a/tools/webpack-plugin/package.json +++ b/tools/webpack-plugin/package.json @@ -13,11 +13,11 @@ "clean": "tsc -b ./tsconfig.build.json --clean && rimraf \"lib\"", "format": "prettier --write '**/*.ts'", "lint": "eslint . --ext .ts", - "prepublishOnly": "NODE_ENV=production npm run build", + "prepublishOnly": "cross-env NODE_ENV=production npm run build", "watch": "tsc -b ./tsconfig.build.json -w", "test:e2e": "npm run test:e2e:webpackv5 && npm run test:e2e:webpackv4", - "test:e2e:webpackv4": "NODE_ENV=test jest --config ./webpack4.e2e.jest.config.js", - "test:e2e:webpackv5": "NODE_ENV=test jest --config ./e2e.jest.config.js" + "test:e2e:webpackv4": "cross-env NODE_ENV=test jest --config ./webpack4.e2e.jest.config.js", + "test:e2e:webpackv5": "cross-env NODE_ENV=test jest --config ./e2e.jest.config.js" }, "repository": { "type": "git", From a34aa2bf6de1f4f7dff7a3d7112608d438a9d019 Mon Sep 17 00:00:00 2001 From: Sebastian Alex Date: Mon, 17 Jun 2024 15:05:37 +0200 Subject: [PATCH 12/13] cli: fix test errors on Windows --- tools/cli/tests/_helpers/common.ts | 16 ++++++++++ tools/cli/tests/_helpers/matchers.ts | 6 ++++ .../cli/tests/sourcemaps/add-sources.spec.ts | 31 ++++++++++--------- tools/cli/tests/sourcemaps/process.spec.ts | 22 ++++++------- tools/cli/tests/sourcemaps/run.spec.ts | 19 ++++++------ tools/cli/tests/sourcemaps/upload.spec.ts | 14 ++++----- 6 files changed, 66 insertions(+), 42 deletions(-) create mode 100644 tools/cli/tests/_helpers/matchers.ts diff --git a/tools/cli/tests/_helpers/common.ts b/tools/cli/tests/_helpers/common.ts index f2354c10..a664b88b 100644 --- a/tools/cli/tests/_helpers/common.ts +++ b/tools/cli/tests/_helpers/common.ts @@ -1,4 +1,5 @@ import { Ok, Result, SymbolUploader, UploadResult } from '@backtrace/sourcemap-tools'; +import path from 'path'; import { Transform } from 'stream'; export function getHelpMessage() { @@ -37,3 +38,18 @@ export function expectAllKeysToChange>(obj1: T expect(value1).not.toEqual(value2); } } + +export function expectSamePaths(actual: string[], expected: string[]) { + const actualAbsolute = actual.map(p => path.resolve(p)) + const expectedAbsolute = expected.map(p => path.resolve(p)) + + expect(actualAbsolute).toEqual(expect.arrayContaining(expectedAbsolute)) +} + +export function pathTuple(a: string, b: string) { + if (process.platform === 'win32') { + return `${a}::${b}` + } else { + return `${a}:${b}` + } +} diff --git a/tools/cli/tests/_helpers/matchers.ts b/tools/cli/tests/_helpers/matchers.ts new file mode 100644 index 00000000..42ad6652 --- /dev/null +++ b/tools/cli/tests/_helpers/matchers.ts @@ -0,0 +1,6 @@ +import 'jest-extended'; +import path from 'path'; + +export function expectPath(expected: string) { + return expect.toSatisfy((actual) => path.resolve(expected) === path.resolve(actual)) + } diff --git a/tools/cli/tests/sourcemaps/add-sources.spec.ts b/tools/cli/tests/sourcemaps/add-sources.spec.ts index 49a2a143..7da0665a 100644 --- a/tools/cli/tests/sourcemaps/add-sources.spec.ts +++ b/tools/cli/tests/sourcemaps/add-sources.spec.ts @@ -3,7 +3,8 @@ import assert from 'assert'; import { glob } from 'glob'; import { CliLogger } from '../../src/logger'; import { addSourcesToSourcemaps } from '../../src/sourcemaps/add-sources'; -import { expectAllKeysToChange, filterKeys, getHelpMessage } from '../_helpers/common'; +import { expectAllKeysToChange, expectSamePaths, filterKeys, getHelpMessage, pathTuple } from '../_helpers/common'; +import { expectPath } from '../_helpers/matchers'; import { expectHashesToChange, hashEachFile, hashFiles, withWorkingCopy } from '../_helpers/testFiles'; describe('add-sources', () => { @@ -26,7 +27,7 @@ describe('add-sources', () => { assert(result.isOk(), result.data as string); const expected = await glob(`${workingDir}/*.js.map`); - expect(result.data.map((d) => d.path)).toEqual(expect.arrayContaining(expected)); + expectSamePaths(result.data.map((d) => d.path), expected) }), ); @@ -45,7 +46,7 @@ describe('add-sources', () => { assert(result.isOk(), result.data as string); const expected = await glob(`${workingDir}/entry*.js.map`); - expect(result.data.map((d) => d.path)).toEqual(expect.arrayContaining(expected)); + expectSamePaths(result.data.map((d) => d.path), expected) }), ); }); @@ -83,7 +84,7 @@ describe('add-sources', () => { const files = await glob(`${workingDir}/*.js.map`); for (const file of files) { - expect(spy).toBeCalledWith(expect.anything(), file, expect.any(Boolean)); + expect(spy).toBeCalledWith(expect.anything(), expectPath(file), expect.any(Boolean)); } }), ); @@ -171,7 +172,7 @@ describe('add-sources', () => { const files = await glob(`${workingDir}/*.js.map`); for (const file of files) { - expect(spy).toBeCalledWith(expect.anything(), file, expect.any(Boolean)); + expect(spy).toBeCalledWith(expect.anything(), expectPath(file), expect.any(Boolean)); } }), ); @@ -230,7 +231,7 @@ describe('add-sources', () => { const files = await glob(`${workingDir}/*.js.map`); for (const file of files) { - expect(spy).toBeCalledWith(expect.anything(), file, expect.any(Boolean)); + expect(spy).toBeCalledWith(expect.anything(), expectPath(file), expect.any(Boolean)); } }), ); @@ -413,7 +414,7 @@ describe('add-sources', () => { const files = await glob(`${workingDir}/*.js.map`); for (const file of files) { - expect(spy).toBeCalledWith(expect.anything(), file, expect.any(Boolean)); + expect(spy).toBeCalledWith(expect.anything(), expectPath(file), expect.any(Boolean)); } }), ); @@ -472,7 +473,7 @@ describe('add-sources', () => { const files = await glob(`${workingDir}/*.js.map`); for (const file of files) { - expect(spy).toBeCalledWith(expect.anything(), file, expect.any(Boolean)); + expect(spy).toBeCalledWith(expect.anything(), expectPath(file), expect.any(Boolean)); } }), ); @@ -507,8 +508,8 @@ describe('add-sources', () => { getHelpMessage, opts: { path: [ - `${workingDir}/entry1.js:${workingDir}/sourcemap1.js.map`, - `${workingDir}/entry2.js:${workingDir}/sourcemap2.js.map`, + pathTuple(`${workingDir}/entry1.js`, `${workingDir}/sourcemap1.js.map`), + pathTuple(`${workingDir}/entry2.js`, `${workingDir}/sourcemap2.js.map`), ], }, }); @@ -527,8 +528,8 @@ describe('add-sources', () => { getHelpMessage, opts: { path: [ - `${workingDir}/entry1.js:${workingDir}/sourcemap1.js.map`, - `${workingDir}/entry2.js:${workingDir}/sourcemap2.js.map`, + pathTuple(`${workingDir}/entry1.js`, `${workingDir}/sourcemap1.js.map`), + pathTuple(`${workingDir}/entry2.js`, `${workingDir}/sourcemap2.js.map`), ], }, }); @@ -537,7 +538,7 @@ describe('add-sources', () => { const files = await glob(`${workingDir}/*.js.map`); for (const file of files) { - expect(spy).toBeCalledWith(expect.anything(), file, expect.any(Boolean)); + expect(spy).toBeCalledWith(expect.anything(), expectPath(file), expect.any(Boolean)); } }), ); @@ -552,8 +553,8 @@ describe('add-sources', () => { getHelpMessage, opts: { path: [ - `${workingDir}/entry1.js:${workingDir}/sourcemap1.js.map`, - `${workingDir}/entry2.js:${workingDir}/sourcemap2.js.map`, + pathTuple(`${workingDir}/entry1.js`, `${workingDir}/sourcemap1.js.map`), + pathTuple(`${workingDir}/entry2.js`, `${workingDir}/sourcemap2.js.map`), ], }, }); diff --git a/tools/cli/tests/sourcemaps/process.spec.ts b/tools/cli/tests/sourcemaps/process.spec.ts index 509b8c0c..93c9b82e 100644 --- a/tools/cli/tests/sourcemaps/process.spec.ts +++ b/tools/cli/tests/sourcemaps/process.spec.ts @@ -4,7 +4,7 @@ import { glob } from 'glob'; import 'jest-extended'; import { CliLogger } from '../../src/logger'; import { processSources } from '../../src/sourcemaps/process'; -import { expectAllKeysToChange, filterKeys, getHelpMessage } from '../_helpers/common'; +import { expectAllKeysToChange, expectSamePaths, filterKeys, getHelpMessage, pathTuple } from '../_helpers/common'; import { expectHashesToChange, hashEachFile, hashFiles, readEachFile, withWorkingCopy } from '../_helpers/testFiles'; export const expectAnythingOrNothing = () => expect.toBeOneOf([expect.anything(), undefined, null]); @@ -25,7 +25,7 @@ describe('process', () => { assert(result.isOk(), result.data as string); const expected = await glob(`${workingDir}/*.js`); - expect(result.data.map((d) => d.source.path)).toEqual(expect.arrayContaining(expected)); + expectSamePaths(result.data.map((d) => d.source.path), expected) }), ); @@ -44,7 +44,7 @@ describe('process', () => { assert(result.isOk(), result.data as string); const expected = await glob(`${workingDir}/entry*.js`); - expect(result.data.map((d) => d.source.path)).toEqual(expect.arrayContaining(expected)); + expectSamePaths(result.data.map((d) => d.source.path), expected) }), ); }); @@ -686,8 +686,8 @@ describe('process', () => { getHelpMessage, opts: { path: [ - `${workingDir}/entry1.js:${workingDir}/sourcemap1.js.map`, - `${workingDir}/entry2.js:${workingDir}/sourcemap2.js.map`, + pathTuple(`${workingDir}/entry1.js`, `${workingDir}/sourcemap1.js.map`), + pathTuple(`${workingDir}/entry2.js`, `${workingDir}/sourcemap2.js.map`), ], }, }); @@ -709,8 +709,8 @@ describe('process', () => { getHelpMessage, opts: { path: [ - `${workingDir}/entry1.js:${workingDir}/sourcemap1.js.map`, - `${workingDir}/entry2.js:${workingDir}/sourcemap2.js.map`, + pathTuple(`${workingDir}/entry1.js`, `${workingDir}/sourcemap1.js.map`), + pathTuple(`${workingDir}/entry2.js`, `${workingDir}/sourcemap2.js.map`), ], }, }); @@ -738,8 +738,8 @@ describe('process', () => { getHelpMessage, opts: { path: [ - `${workingDir}/entry1.js:${workingDir}/sourcemap1.js.map`, - `${workingDir}/entry2.js:${workingDir}/sourcemap2.js.map`, + pathTuple(`${workingDir}/entry1.js`, `${workingDir}/sourcemap1.js.map`), + pathTuple(`${workingDir}/entry2.js`, `${workingDir}/sourcemap2.js.map`), ], }, }); @@ -761,8 +761,8 @@ describe('process', () => { getHelpMessage, opts: { path: [ - `${workingDir}/entry1.js:${workingDir}/sourcemap1.js.map`, - `${workingDir}/entry2.js:${workingDir}/sourcemap2.js.map`, + pathTuple(`${workingDir}/entry1.js`, `${workingDir}/sourcemap1.js.map`), + pathTuple(`${workingDir}/entry2.js`, `${workingDir}/sourcemap2.js.map`), ], }, }); diff --git a/tools/cli/tests/sourcemaps/run.spec.ts b/tools/cli/tests/sourcemaps/run.spec.ts index 5331e680..35e5e1cc 100644 --- a/tools/cli/tests/sourcemaps/run.spec.ts +++ b/tools/cli/tests/sourcemaps/run.spec.ts @@ -10,7 +10,8 @@ import * as addSourcesCmd from '../../src/sourcemaps/add-sources'; import * as processCmd from '../../src/sourcemaps/process'; import { runSourcemapCommands } from '../../src/sourcemaps/run'; import * as uploadCmd from '../../src/sourcemaps/upload'; -import { getHelpMessage, mockUploader } from '../_helpers/common'; +import { getHelpMessage, mockUploader, pathTuple } from '../_helpers/common'; +import { expectPath } from '../_helpers/matchers'; import { hashFiles, withWorkingCopy } from '../_helpers/testFiles'; async function mockOptions(workingDir: string, options: CliOptions) { @@ -53,7 +54,7 @@ describe('run', () => { const expected = [...(await glob(`${workingDir}/*.js`)), ...(await glob(`${workingDir}/*.js.map`))]; expect(result.data.flatMap((d) => [d.source.path, d.sourceMap.path])).toEqual( - expect.arrayContaining(expected), + expect.arrayContaining(expected.map(expectPath)), ); }), ); @@ -89,7 +90,7 @@ describe('run', () => { ...(await glob(`${workingDir}/entry*.js.map`)), ]; expect(result.data.flatMap((d) => [d.source.path, d.sourceMap.path])).toEqual( - expect.arrayContaining(expected), + expect.arrayContaining(expected.map(expectPath)), ); }), ); @@ -172,7 +173,7 @@ describe('run', () => { const files = await glob(`${workingDir}/*.js`); for (const file of files) { expect(innerProcess).toBeCalledWith( - expect.objectContaining({ source: expect.objectContaining({ path: file }) }), + expect.objectContaining({ source: expect.objectContaining({ path: expectPath(file) }) }), ); } }), @@ -284,7 +285,7 @@ describe('run', () => { const files = await glob(`${workingDir}/*.js.map`); for (const file of files) { - expect(innerAddSources).toBeCalledWith(expect.objectContaining({ path: file })); + expect(innerAddSources).toBeCalledWith(expect.objectContaining({ path: expectPath(file) })); } }), ); @@ -499,7 +500,7 @@ describe('run', () => { const expected = [...(await glob(`${workingDir}/*.js`)), ...(await glob(`${workingDir}/*.js.map`))]; expect(result.data.flatMap((d) => [d.source.path, d.sourceMap.path])).toEqual( - expect.arrayContaining(expected), + expect.arrayContaining(expected.map(expectPath)), ); }), ); @@ -533,7 +534,7 @@ describe('run', () => { const expected = [...(await glob(`${workingDir}/*.js`)), ...(await glob(`${workingDir}/*.js.map`))]; expect(result.data.flatMap((d) => [d.source.path, d.sourceMap.path])).toEqual( - expect.arrayContaining(expected), + expect.arrayContaining(expected.map(e => expectPath(e))), ); }), ); @@ -563,7 +564,7 @@ describe('run', () => { logger: new CliLogger({ level: 'output', silent: true }), getHelpMessage, opts: { - path: [`${entry1Path}:${sourcemap1Path}`, `${entry2Path}:${sourcemap2Path}`], + path: [pathTuple(entry1Path, sourcemap1Path), pathTuple(entry2Path, sourcemap2Path)], config, }, }); @@ -572,7 +573,7 @@ describe('run', () => { const expected = [entry1Path, entry2Path, sourcemap1Path, sourcemap2Path]; expect(result.data.flatMap((d) => [d.source.path, d.sourceMap.path])).toEqual( - expect.arrayContaining(expected), + expect.arrayContaining(expected.map(expectPath)), ); }), ); diff --git a/tools/cli/tests/sourcemaps/upload.spec.ts b/tools/cli/tests/sourcemaps/upload.spec.ts index 785bdd57..6f18a718 100644 --- a/tools/cli/tests/sourcemaps/upload.spec.ts +++ b/tools/cli/tests/sourcemaps/upload.spec.ts @@ -6,7 +6,7 @@ import { glob } from 'glob'; import path from 'path'; import { CliLogger } from '../../src/logger'; import { uploadSourcemaps } from '../../src/sourcemaps/upload'; -import { getHelpMessage, mockUploader } from '../_helpers/common'; +import { getHelpMessage, mockUploader, pathTuple } from '../_helpers/common'; import { withWorkingCopy } from '../_helpers/testFiles'; describe('upload', () => { @@ -541,8 +541,8 @@ describe('upload', () => { getHelpMessage, opts: { path: [ - `${workingDir}/entry1.js:${workingDir}/sourcemap1.js.map`, - `${workingDir}/entry2.js:${workingDir}/sourcemap2.js.map`, + pathTuple(`${workingDir}/entry1.js`, `${workingDir}/sourcemap1.js.map`), + pathTuple(`${workingDir}/entry2.js`, `${workingDir}/sourcemap2.js.map`), ], url: 'https://test', }, @@ -563,8 +563,8 @@ describe('upload', () => { getHelpMessage, opts: { path: [ - `${workingDir}/entry1.js:${workingDir}/sourcemap1.js.map`, - `${workingDir}/entry2.js:${workingDir}/sourcemap2.js.map`, + pathTuple(`${workingDir}/entry1.js`, `${workingDir}/sourcemap1.js.map`), + pathTuple(`${workingDir}/entry2.js`, `${workingDir}/sourcemap2.js.map`), ], url: 'https://test', }, @@ -593,8 +593,8 @@ describe('upload', () => { getHelpMessage, opts: { path: [ - `${workingDir}/entry1.js:${workingDir}/sourcemap1.js.map`, - `${workingDir}/entry2.js:${workingDir}/sourcemap2.js.map`, + pathTuple(`${workingDir}/entry1.js`, `${workingDir}/sourcemap1.js.map`), + pathTuple(`${workingDir}/entry2.js`, `${workingDir}/sourcemap2.js.map`), ], url: 'https://test', }, From f3cd5150bce68d7e34c90efa5c4b247b00899e41 Mon Sep 17 00:00:00 2001 From: kdysput Date: Mon, 17 Jun 2024 15:23:45 +0200 Subject: [PATCH 13/13] Apply formatting --- tools/cli/tests/_helpers/common.ts | 10 +++++----- tools/cli/tests/_helpers/matchers.ts | 4 ++-- tools/cli/tests/sourcemaps/add-sources.spec.ts | 10 ++++++++-- tools/cli/tests/sourcemaps/process.spec.ts | 10 ++++++++-- tools/cli/tests/sourcemaps/run.spec.ts | 2 +- 5 files changed, 24 insertions(+), 12 deletions(-) diff --git a/tools/cli/tests/_helpers/common.ts b/tools/cli/tests/_helpers/common.ts index a664b88b..67ba14ab 100644 --- a/tools/cli/tests/_helpers/common.ts +++ b/tools/cli/tests/_helpers/common.ts @@ -40,16 +40,16 @@ export function expectAllKeysToChange>(obj1: T } export function expectSamePaths(actual: string[], expected: string[]) { - const actualAbsolute = actual.map(p => path.resolve(p)) - const expectedAbsolute = expected.map(p => path.resolve(p)) + const actualAbsolute = actual.map((p) => path.resolve(p)); + const expectedAbsolute = expected.map((p) => path.resolve(p)); - expect(actualAbsolute).toEqual(expect.arrayContaining(expectedAbsolute)) + expect(actualAbsolute).toEqual(expect.arrayContaining(expectedAbsolute)); } export function pathTuple(a: string, b: string) { if (process.platform === 'win32') { - return `${a}::${b}` + return `${a}::${b}`; } else { - return `${a}:${b}` + return `${a}:${b}`; } } diff --git a/tools/cli/tests/_helpers/matchers.ts b/tools/cli/tests/_helpers/matchers.ts index 42ad6652..84027519 100644 --- a/tools/cli/tests/_helpers/matchers.ts +++ b/tools/cli/tests/_helpers/matchers.ts @@ -2,5 +2,5 @@ import 'jest-extended'; import path from 'path'; export function expectPath(expected: string) { - return expect.toSatisfy((actual) => path.resolve(expected) === path.resolve(actual)) - } + return expect.toSatisfy((actual) => path.resolve(expected) === path.resolve(actual)); +} diff --git a/tools/cli/tests/sourcemaps/add-sources.spec.ts b/tools/cli/tests/sourcemaps/add-sources.spec.ts index 7da0665a..d86356d6 100644 --- a/tools/cli/tests/sourcemaps/add-sources.spec.ts +++ b/tools/cli/tests/sourcemaps/add-sources.spec.ts @@ -27,7 +27,10 @@ describe('add-sources', () => { assert(result.isOk(), result.data as string); const expected = await glob(`${workingDir}/*.js.map`); - expectSamePaths(result.data.map((d) => d.path), expected) + expectSamePaths( + result.data.map((d) => d.path), + expected, + ); }), ); @@ -46,7 +49,10 @@ describe('add-sources', () => { assert(result.isOk(), result.data as string); const expected = await glob(`${workingDir}/entry*.js.map`); - expectSamePaths(result.data.map((d) => d.path), expected) + expectSamePaths( + result.data.map((d) => d.path), + expected, + ); }), ); }); diff --git a/tools/cli/tests/sourcemaps/process.spec.ts b/tools/cli/tests/sourcemaps/process.spec.ts index 93c9b82e..bcfbf046 100644 --- a/tools/cli/tests/sourcemaps/process.spec.ts +++ b/tools/cli/tests/sourcemaps/process.spec.ts @@ -25,7 +25,10 @@ describe('process', () => { assert(result.isOk(), result.data as string); const expected = await glob(`${workingDir}/*.js`); - expectSamePaths(result.data.map((d) => d.source.path), expected) + expectSamePaths( + result.data.map((d) => d.source.path), + expected, + ); }), ); @@ -44,7 +47,10 @@ describe('process', () => { assert(result.isOk(), result.data as string); const expected = await glob(`${workingDir}/entry*.js`); - expectSamePaths(result.data.map((d) => d.source.path), expected) + expectSamePaths( + result.data.map((d) => d.source.path), + expected, + ); }), ); }); diff --git a/tools/cli/tests/sourcemaps/run.spec.ts b/tools/cli/tests/sourcemaps/run.spec.ts index 35e5e1cc..05025ac0 100644 --- a/tools/cli/tests/sourcemaps/run.spec.ts +++ b/tools/cli/tests/sourcemaps/run.spec.ts @@ -534,7 +534,7 @@ describe('run', () => { const expected = [...(await glob(`${workingDir}/*.js`)), ...(await glob(`${workingDir}/*.js.map`))]; expect(result.data.flatMap((d) => [d.source.path, d.sourceMap.path])).toEqual( - expect.arrayContaining(expected.map(e => expectPath(e))), + expect.arrayContaining(expected.map((e) => expectPath(e))), ); }), );