diff --git a/packages/snaps-utils/jest.config.js b/packages/snaps-utils/jest.config.js index 28aac828f2..e1cb61249e 100644 --- a/packages/snaps-utils/jest.config.js +++ b/packages/snaps-utils/jest.config.js @@ -18,10 +18,10 @@ module.exports = deepmerge(baseConfig, { ], coverageThreshold: { global: { - branches: 94.38, - functions: 98.93, - lines: 98.9, - statements: 98.9, + branches: 94.36, + functions: 98.92, + lines: 98.99, + statements: 98.99, }, }, testTimeout: 2500, diff --git a/packages/snaps-utils/src/virtual-file/VirtualFile.ts b/packages/snaps-utils/src/virtual-file/VirtualFile.ts index 57bcc68290..2c65464549 100644 --- a/packages/snaps-utils/src/virtual-file/VirtualFile.ts +++ b/packages/snaps-utils/src/virtual-file/VirtualFile.ts @@ -1,16 +1,15 @@ // TODO(ritave): Move into separate package @metamask/vfile / @metamask/utils + @metamask/to-vfile when passes code review // TODO(ritave): Streaming vfile contents similar to vinyl maybe? -// TODO(ritave): Move fixing manifest to write messages to vfile similar to unified instead of throwing "ProgrammaticallyFixableErrors". -// Better yet, move manifest fixing into eslint fixing altogether +// TODO(ritave): Move fixing manifest in cli and bundler plugins to write messages to vfile +// similar to unified instead of throwing "ProgrammaticallyFixableErrors". +// +// Using https://github.com/vfile/vfile would be helpful, but they only support ESM and we need to support CommonJS. +// https://github.com/gulpjs/vinyl is also good, but they normalize paths, which we can't do, because +// we're calculating checksums based on original path. import { assert, hasProperty } from '@metamask/utils'; -import { Infer, instance, is, union } from 'superstruct'; import { deepClone } from '../deep-clone'; -// Using https://github.com/vfile/vfile would be helpful, but they only support ESM. -// https://github.com/gulpjs/vinyl is also good, but they normalize paths, which we can't do, because -// we're calculating checksums based on original path. - /** * This map registers the type of the `data` key of a `VFile`. * @@ -40,36 +39,10 @@ export type Options = { result?: Result; }; -const TypedArrayStruct = union([ - instance(Int8Array), - instance(Uint8Array), - instance(Uint8ClampedArray), - instance(Int16Array), - instance(Uint16Array), - instance(Int32Array), - instance(Uint32Array), - instance(Float32Array), - instance(Float64Array), - instance(BigInt64Array), - instance(BigUint64Array), -]); - -export type TypedArray = Infer; - -/** - * Returns whether the given parameter is one of TypedArray subtypes. - * - * @param value - Object to check. - * @returns Whether the parameter is TypeArray subtype. - */ -export function isTypedArray(value: unknown): value is TypedArray { - return is(value, TypedArrayStruct); -} - export class VirtualFile { constructor(value?: Compatible) { let options: Options; - if (typeof value === 'string' || isTypedArray(value)) { + if (typeof value === 'string' || value instanceof Uint8Array) { options = { value }; } else { options = value as Options;