Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: reduce dependency pain by moving to better maintained libs #342

Merged
merged 5 commits into from
Mar 2, 2024
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
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
"@types/jest": "27.5.2",
"@typescript-eslint/eslint-plugin": "6.21.0",
"@typescript-eslint/parser": "6.21.0",
"@vibrant/color": "^3.2.1-alpha.1",
"codecov": "3.8.3",
"cz-conventional-changelog": "3.3.0",
"eslint": "8.56.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
import SvgPlugin from '../../src/sqip-plugin-blur'

import { Swatch } from '@vibrant/color'
import type { SqipImageMetadata } from 'sqip/src/sqip'
import { mockedMetadata } from 'sqip'

const mockedMetadata: SqipImageMetadata = {
filename: 'mocked',
mimeType: 'image/mocked',
width: 1024,
height: 640,
type: 'svg',
originalHeight: 1024,
originalWidth: 640,
palette: {
DarkMuted: new Swatch([4, 2, 0], 420),
DarkVibrant: new Swatch([4, 2, 1], 421),
LightMuted: new Swatch([4, 2, 2], 422),
LightVibrant: new Swatch([4, 2, 3], 423),
Muted: new Swatch([4, 2, 4], 424),
Vibrant: new Swatch([4, 2, 5], 425)
}
}
const mockedConfig = {
input: 'mocked',
output: 'mocked',
Expand Down
3 changes: 0 additions & 3 deletions packages/sqip-plugin-blur/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,5 @@
},
"dependencies": {
"sqip": "^1.0.0-alpha.43"
},
"peerDependencies": {
"@vibrant/color": "3.2.1-alpha.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ import { readFileSync } from 'fs'

import sqipPluginBlurhash from '../../src/sqip-plugin-blurhash'

import { Swatch } from '@vibrant/color'

import { SqipImageMetadata } from 'sqip/src/sqip'
import { SqipImageMetadata, mockedMetadata } from 'sqip'

const FILE_DEMO_BEACH = resolve(
__dirname,
Expand All @@ -16,24 +14,6 @@ const FILE_DEMO_BEACH = resolve(
)
const fileContent = readFileSync(FILE_DEMO_BEACH)

const mockedSwatch = new Swatch([4, 2, 0], 420)
const mockedMetadata: SqipImageMetadata = {
filename: 'mocked',
mimeType: 'image/mocked',
height: 32,
width: 32,
originalHeight: 0,
originalWidth: 0,
palette: {
DarkMuted: mockedSwatch,
DarkVibrant: mockedSwatch,
LightMuted: mockedSwatch,
LightVibrant: mockedSwatch,
Muted: mockedSwatch,
Vibrant: mockedSwatch
},
type: 'pixel'
}
const mockedConfig = {
input: 'mocked',
output: 'mocked',
Expand All @@ -47,10 +27,16 @@ describe('sqip-plugin-blurhash', () => {
options: {},
sqipConfig: mockedConfig
})
const result = await plugin.apply(fileContent, mockedMetadata)

expect(mockedMetadata.blurhash).toMatchSnapshot()
expect(mockedMetadata.dataURIBase64).toMatchSnapshot()
const blurhashMockedMetadata: SqipImageMetadata = {
...mockedMetadata,
height: 32,
width: 32,
type: 'pixel'
}
const result = await plugin.apply(fileContent, blurhashMockedMetadata)

expect(blurhashMockedMetadata.blurhash).toMatchSnapshot()
expect(blurhashMockedMetadata.dataURIBase64).toMatchSnapshot()
expect(result.length).toBe(284)
})

Expand All @@ -60,10 +46,16 @@ describe('sqip-plugin-blurhash', () => {
options: {},
sqipConfig: mockedConfig
})
const result = await plugin.apply(fileContent, mockedMetadata)

expect(mockedMetadata.blurhash).toMatchSnapshot()
expect(mockedMetadata.dataURIBase64).toMatchSnapshot()
const blurhashMockedMetadata: SqipImageMetadata = {
...mockedMetadata,
height: 32,
width: 32,
type: 'pixel'
}
const result = await plugin.apply(fileContent, blurhashMockedMetadata)

expect(blurhashMockedMetadata.blurhash).toMatchSnapshot()
expect(blurhashMockedMetadata.dataURIBase64).toMatchSnapshot()
expect(result.length).toBe(285)
})
})
3 changes: 1 addition & 2 deletions packages/sqip-plugin-blurhash/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"sqip": "^1.0.0-alpha.43"
},
"devDependencies": {
"@types/jsdom": "^21.1.6",
"@vibrant/color": "^3.2.1-alpha.1"
"@types/jsdom": "^21.1.6"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ Object {
"dataURI": "data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3e%3ccircle cx='50' cy='50' r='40' fill='red' stroke='black' stroke-width='3'/%3e%3c/svg%3e",
"dataURIBase64": "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxMDAgMTAwIj48Y2lyY2xlIGN4PSI1MCIgY3k9IjUwIiByPSI0MCIgZmlsbD0icmVkIiBzdHJva2U9IiMwMDAiIHN0cm9rZS13aWR0aD0iMyIvPjwvc3ZnPg==",
"filename": "mocked",
"height": 0,
"height": 640,
"mimeType": "image/mocked",
"originalHeight": 0,
"originalWidth": 0,
"originalHeight": 1024,
"originalWidth": 640,
"palette": Object {
"DarkMuted": Object {
"population": 420,
Expand Down Expand Up @@ -60,6 +60,6 @@ Object {
},
},
"type": "svg",
"width": 0,
"width": 1024,
}
`;
Original file line number Diff line number Diff line change
@@ -1,29 +1,11 @@
import sqipPluginDataUri from '../../src/sqip-plugin-data-uri'

import { Swatch } from '@vibrant/color'
import { SqipImageMetadata } from 'sqip/src/sqip'
import { mockedMetadata } from 'sqip'

const EXAMPLE_SVG = Buffer.from(
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><circle cx="50" cy="50" r="40" fill="red" stroke="#000" stroke-width="3"/></svg>'
)

const mockedMetadata: SqipImageMetadata = {
filename: 'mocked',
mimeType: 'image/mocked',
height: 0,
width: 0,
originalHeight: 0,
originalWidth: 0,
palette: {
DarkMuted: new Swatch([4, 2, 0], 420),
DarkVibrant: new Swatch([4, 2, 1], 421),
LightMuted: new Swatch([4, 2, 2], 422),
LightVibrant: new Swatch([4, 2, 3], 423),
Muted: new Swatch([4, 2, 4], 424),
Vibrant: new Swatch([4, 2, 5], 425)
},
type: 'svg'
}
const mockedConfig = {
input: 'mocked',
output: 'mocked',
Expand Down
3 changes: 0 additions & 3 deletions packages/sqip-plugin-data-uri/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,5 @@
"dependencies": {
"mini-svg-data-uri": "^1.4.4",
"sqip": "^1.0.0-alpha.43"
},
"peerDependencies": {
"@vibrant/color": "3.2.1-alpha.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ import { readFileSync } from 'fs'

import sqipPluginPixels from '../../src/sqip-plugin-pixels'

import { Swatch } from '@vibrant/color'

import cheerio from 'cheerio'
import { SqipImageMetadata } from 'sqip/src/sqip'
import { SqipImageMetadata, mockedMetadata } from 'sqip'

const pixelMockedMetadata: SqipImageMetadata = {
...mockedMetadata,
type: 'pixel'
}

const FILE_DEMO_BEACH = resolve(
__dirname,
Expand All @@ -17,24 +20,6 @@ const FILE_DEMO_BEACH = resolve(
)
const fileContent = readFileSync(FILE_DEMO_BEACH)

const mockedSwatch = new Swatch([4, 2, 0], 420)
const mockedMetadata: SqipImageMetadata = {
filename: 'mocked',
mimeType: 'image/mocked',
height: 0,
width: 0,
originalHeight: 0,
originalWidth: 0,
palette: {
DarkMuted: mockedSwatch,
DarkVibrant: mockedSwatch,
LightMuted: mockedSwatch,
LightVibrant: mockedSwatch,
Muted: mockedSwatch,
Vibrant: mockedSwatch
},
type: 'pixel'
}
const mockedConfig = {
input: 'mocked',
output: 'mocked',
Expand All @@ -48,7 +33,7 @@ describe('sqip-plugin-pixels', () => {
options: {},
sqipConfig: mockedConfig
})
const metadata = {...mockedMetadata}
const metadata = { ...pixelMockedMetadata }
const result = await plugin.apply(fileContent, metadata)

const $ = cheerio.load(result, { xml: true })
Expand All @@ -70,7 +55,7 @@ describe('sqip-plugin-pixels', () => {
options: {},
sqipConfig: mockedConfig
})
const metadata = {...mockedMetadata}
const metadata = { ...pixelMockedMetadata }
const result = await plugin.apply(fileContent, metadata)

const $ = cheerio.load(result, { xml: true })
Expand Down
3 changes: 0 additions & 3 deletions packages/sqip-plugin-pixels/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,5 @@
},
"devDependencies": {
"cheerio": "1.0.0-rc.12"
},
"peerDependencies": {
"@vibrant/color": "3.2.1-alpha.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ import { resolve } from 'path'
import { readFileSync } from 'fs'

import cheerio from 'cheerio'
import { Swatch } from '@vibrant/color'

import sqipPluginPotrace from '../../src/sqip-plugin-potrace'
import { SqipImageMetadata } from 'sqip/src/sqip'
import { SqipImageMetadata, mockedMetadata } from 'sqip'

const potraceMockedMetadata: SqipImageMetadata = {
...mockedMetadata,
type: 'pixel'
}

const FILE_DEMO_BEACH = resolve(
__dirname,
Expand All @@ -16,23 +20,6 @@ const FILE_DEMO_BEACH = resolve(
)
const fileContent = readFileSync(FILE_DEMO_BEACH)

const mockedMetadata: SqipImageMetadata = {
filename: 'mocked',
mimeType: 'image/mocked',
height: 0,
width: 0,
originalHeight: 0,
originalWidth: 0,
palette: {
DarkMuted: new Swatch([4, 2, 0], 420),
DarkVibrant: new Swatch([4, 2, 1], 421),
LightMuted: new Swatch([4, 2, 2], 422),
LightVibrant: new Swatch([4, 2, 3], 423),
Muted: new Swatch([4, 2, 4], 424),
Vibrant: new Swatch([4, 2, 5], 425)
},
type: 'pixel'
}
const mockedConfig = {
input: 'mocked',
output: 'mocked',
Expand All @@ -46,7 +33,7 @@ describe('sqip-plugin-potrace', () => {
options: {},
sqipConfig: mockedConfig
})
const metadata = {...mockedMetadata}
const metadata = { ...potraceMockedMetadata }
const result = await plugin.apply(fileContent, metadata)

const $ = cheerio.load(result, { xml: true })
Expand All @@ -69,7 +56,7 @@ describe('sqip-plugin-potrace', () => {
options: {},
sqipConfig: mockedConfig
})
const metadata = {...mockedMetadata}
const metadata = { ...potraceMockedMetadata }
const result = await plugin.apply(fileContent, metadata)

const $ = cheerio.load(result, { xml: true })
Expand All @@ -95,7 +82,7 @@ describe('sqip-plugin-potrace', () => {
options: {},
sqipConfig: mockedConfig
})
const metadata = {...mockedMetadata}
const metadata = { ...potraceMockedMetadata }
const result = await plugin.apply(fileContent, metadata)

const $ = cheerio.load(result, { xml: true })
Expand Down
5 changes: 1 addition & 4 deletions packages/sqip-plugin-potrace/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@
"url": "https://github.com/axe312ger/sqip/issues"
},
"dependencies": {
"potrace": "^2.1.6",
"@gatsbyjs/potrace": "^3.0.0",
"sqip": "^1.0.0-alpha.43"
},
"devDependencies": {
"cheerio": "1.0.0-rc.12"
},
"peerDependencies": {
"@vibrant/color": "3.2.1-alpha.1"
}
}
2 changes: 1 addition & 1 deletion packages/sqip-plugin-potrace/src/sqip-plugin-potrace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
SqipImageMetadata
} from 'sqip'

import potrace, { PotraceDefaultOptions } from 'potrace'
import potrace, { PotraceDefaultOptions } from '@gatsbyjs/potrace'

const trace = promisify(potrace.trace)
const posterize = promisify(potrace.posterize)
Expand Down
2 changes: 1 addition & 1 deletion packages/sqip-plugin-potrace/typings/potrace/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
declare module 'potrace' {
declare module '@gatsbyjs/potrace' {
export interface PotraceDefaultOptions {
turnPolicy: string
turdSize: number
Expand Down
Loading