Skip to content

Commit f4a5ce4

Browse files
committed
refactor(dependencies): upgrade dependencies and migrate code
1 parent c11eba9 commit f4a5ce4

33 files changed

+3332
-2423
lines changed

.prettierrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"semi": false,
3-
"singleQuote": true
3+
"singleQuote": true,
4+
"trailingComma": "none"
45
}

demo/package.json

+8-9
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@
1313
"dependencies": {
1414
"aspect-ratio": "^2.1.1",
1515
"brotli-size": "^4.0.0",
16-
"cli-progress": "^3.4.0",
16+
"cli-progress": "^3.8.2",
1717
"convert-hrtime": "^3.0.0",
18-
"data-uri-to-buffer": "^3.0.0",
19-
"execa": "3.1.0",
20-
"fs-extra": "^8.0.1",
18+
"data-uri-to-buffer": "^3.0.1",
19+
"execa": "4.0.2",
20+
"fs-extra": "^9.0.1",
2121
"gzip-size": "^5.1.1",
22-
"htm": "^2.1.1",
22+
"htm": "^3.0.4",
2323
"lqip": "^2.1.0",
24-
"mozjpeg": "^6.0.1",
24+
"mozjpeg": "^7.0.0",
2525
"pretty-bytes": "^5.2.0",
2626
"probe-image-size": "^5.0.0",
27-
"sharp": "^0.23.4",
27+
"sharp": "^0.25.4",
2828
"sqip": "^1.0.0-alpha.31",
2929
"sqip-legacy": "npm:sqip@legacy",
3030
"sqip-plugin-blur": "^1.0.0-alpha.32",
@@ -36,7 +36,6 @@
3636
"vhtml": "^2.2.0"
3737
},
3838
"devDependencies": {
39-
"gh-pages": "^2.1.1",
40-
"nodemon": "^2.0.2"
39+
"gh-pages": "^3.1.0"
4140
}
4241
}

demo/scripts/config.js

+5-13
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,7 @@ const variants = [
3636
`,
3737
resultFileType: 'jpg',
3838
task: async ({ path, dist }) => {
39-
const rawThumbnail = await sharp(path)
40-
.resize(300)
41-
.jpeg()
42-
.toBuffer()
39+
const rawThumbnail = await sharp(path).resize(300).jpeg().toBuffer()
4340
const tmpPath = resolve(
4441
tmpdir(),
4542
`sqip-demo-tmp-thumbnail-${Date.now()}.jpg`
@@ -71,17 +68,14 @@ const variants = [
7168
title: 'LQIP custom',
7269
description: html`
7370
<p>
74-
32px thumbnail generated with <a href="https://sharp.dimens.io/en/stable/">sharp</a>,
75-
minified with
71+
32px thumbnail generated with
72+
<a href="https://sharp.dimens.io/en/stable/">sharp</a>, minified with
7673
<a href="https://github.com/mozilla/mozjpeg">mozjpeg</a>
7774
</p>
7875
`,
7976
resultFileType: 'jpg',
8077
task: async ({ path, dist }) => {
81-
const rawThumbnail = await sharp(path)
82-
.resize(32)
83-
.jpeg()
84-
.toBuffer()
78+
const rawThumbnail = await sharp(path).resize(32).jpeg().toBuffer()
8579
const tmpPath = resolve(tmpdir(), `sqip-demo-tmp-lqip-${Date.now()}.jpg`)
8680
await writeFile(tmpPath, rawThumbnail)
8781
await execa(mozjpeg, ['-outfile', dist, tmpPath])
@@ -108,9 +102,7 @@ const variants = [
108102
{
109103
name: 'sqip',
110104
title: 'SQIP default',
111-
description: html`
112-
<p>Just the default settings</p>
113-
`,
105+
description: html` <p>Just the default settings</p> `,
114106
config: { input: 'path/to/file.jpg' },
115107
resultFileType: 'svg',
116108
task: async ({ path, dist }) => {

demo/scripts/generate-dataset.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@ function getSizes(input) {
2525
}
2626
}
2727

28-
(async () => {
28+
;(async () => {
2929
// read the images
3030
const allFiles = await readdir(ORIGINAL)
31-
const imageFiles = allFiles.filter(file => {
31+
const imageFiles = allFiles.filter((file) => {
3232
const { ext } = parse(file)
3333
return ['.jpg', '.png'].includes(ext)
3434
})

demo/scripts/generate-html.js

+9-20
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ const Row = ({ image }) => {
102102

103103
return html`
104104
<tr>
105-
${results.map(result => {
105+
${results.map((result) => {
106106
return html`
107107
<${VariantResult}
108108
...${result}
@@ -142,9 +142,7 @@ const Row = ({ image }) => {
142142
<thead>
143143
<tr>
144144
${variants.map(({ title }) => {
145-
return html`
146-
<th>${title}</th>
147-
`
145+
return html` <th>${title}</th> `
148146
})}
149147
</tr>
150148
<tr>
@@ -177,29 +175,20 @@ const Row = ({ image }) => {
177175
>
178176
</p>
179177
${config &&
180-
html`
181-
<details>
182-
<summary>config:</summary>
183-
<pre><code>${JSON.stringify(
184-
config,
185-
null,
186-
2
187-
)}</code></pre>
188-
</details>
189-
`}
178+
html`
179+
<details>
180+
<summary>config:</summary>
181+
<pre><code>${JSON.stringify(config, null, 2)}</code></pre>
182+
</details>
183+
`}
190184
</div>
191185
</td>
192186
`
193187
})}
194188
</tr>
195189
</thead>
196190
<tbody>
197-
${images.map(
198-
image =>
199-
html`
200-
<${Row} image="${image}" />
201-
`
202-
)}
191+
${images.map((image) => html` <${Row} image="${image}" /> `)}
203192
</tbody>
204193
</table>
205194
`)

demo/scripts/template.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module.exports = content => `
1+
module.exports = (content) => `
22
<html>
33
<head>
44
<meta charset="UTF-8" />

package.json

+21-22
Original file line numberDiff line numberDiff line change
@@ -12,31 +12,30 @@
1212
"test:e2e": "TERM=xterm jest --testPathPattern='e2e/*'",
1313
"test:e2e:watch": "TERM=xterm jest --testPathPattern='e2e/*' --watch",
1414
"lint": "eslint packages/*/src",
15-
"format": "lerna exec 'prettier --write src/**/*.js __tests__/**/*.js'"
15+
"format": "lerna exec 'prettier --write src/**/*.js __tests__/**/*.js'",
16+
"check-dependencies": "lerna exec --ignore sqip-demo \"pwd && npx depcheck --ignore-dirs 'dist' .\" --no-bail --concurrency 1"
1617
},
1718
"devDependencies": {
18-
"@babel/cli": "^7.7.7",
19-
"@babel/core": "^7.7.7",
20-
"@babel/preset-env": "^7.7.7",
21-
"babel-core": "^7.0.0-bridge.0",
22-
"babel-eslint": "^10.0.3",
23-
"babel-jest": "^24.9.0",
19+
"@babel/cli": "^7.10.3",
20+
"@babel/core": "^7.10.3",
21+
"@babel/preset-env": "^7.10.3",
22+
"babel-eslint": "^10.1.0",
23+
"babel-jest": "^26.0.1",
2424
"babel-plugin-add-module-exports": "^1.0.0",
25-
"babel-plugin-dynamic-import-node": "^2.2.0",
26-
"codecov": "^3.6.1",
27-
"core-js": "^3.6.0",
28-
"cz-conventional-changelog": "^3.0.2",
29-
"eslint": "^6.8.0",
30-
"eslint-config-prettier": "^6.7.0",
31-
"eslint-plugin-import": "^2.19.1",
32-
"eslint-plugin-jest": "^23.1.1",
33-
"eslint-plugin-node": "^10.0.0",
34-
"eslint-plugin-prettier": "^3.1.2",
25+
"babel-plugin-dynamic-import-node": "^2.3.3",
26+
"codecov": "^3.7.0",
27+
"cz-conventional-changelog": "^3.2.0",
28+
"eslint": "^7.3.0",
29+
"eslint-config-prettier": "^6.11.0",
30+
"eslint-plugin-import": "^2.21.2",
31+
"eslint-plugin-jest": "^23.16.0",
32+
"eslint-plugin-node": "^11.1.0",
33+
"eslint-plugin-prettier": "^3.1.4",
3534
"eslint-plugin-promise": "^4.0.1",
36-
"husky": "^3.1.0",
37-
"jest": "^24.9.0",
38-
"lerna": "^3.19.0",
39-
"prettier": "^1.19.1"
35+
"husky": "^4.2.5",
36+
"jest": "^26.0.1",
37+
"lerna": "^3.22.1",
38+
"prettier": "^2.0.5"
4039
},
4140
"jest": {
4241
"verbose": true,
@@ -56,7 +55,7 @@
5655
"husky": {
5756
"hooks": {
5857
"pre-commit": "npm run lint",
59-
"pre-push": "npm run test"
58+
"pre-push": "npm run test && npm run check-dependencies"
6059
}
6160
},
6261
"config": {

packages/sqip-cli/__tests__/e2e/__snapshots__/sqip-cli-e2e.test.js.snap

+4-8
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ exports[`cli api --help shows help screen to user 1`] = `
5858
`;
5959

6060
exports[`cli api no config exists programm and shows help 1`] = `
61-
"
61+
"Command failed with exit code 1: node /Users/bene/dev/opensource/sqip/packages/sqip-cli/dist/wrapper.js
62+
63+
Please provide the following arguments: input
64+
6265
sqip CLI
6366
6467
Usage: sqip --input [path]
@@ -111,12 +114,5 @@ exports[`cli api no config exists programm and shows help 1`] = `
111114
112115
Save input.jpg as result.svg with 25 shapes and no blur
113116
$ sqip -i input.jpg -n 25 -b 0 -o result.svg
114-
115-
"
116-
`;
117-
118-
exports[`cli api no config exists programm and shows help 2`] = `
119-
"
120-
Please provide the following arguments: input
121117
"
122118
`;

packages/sqip-cli/__tests__/e2e/sqip-cli-e2e.test.js

+11-12
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,11 @@ function isValidStdout(stdout) {
3131

3232
describe('cli api', () => {
3333
test('no config exists programm and shows help', async () => {
34-
try {
35-
await execa(cliCmd, [cliPath], {
34+
await expect(() =>
35+
execa(cliCmd, [cliPath], {
3636
stripFinalNewline: true
3737
})
38-
throw new Error('cli should exit with help message')
39-
} catch (err) {
40-
expect(err.stdout).toMatchSnapshot()
41-
expect(err.stderr).toMatchSnapshot()
42-
expect(err.code).toBe(1)
43-
}
38+
).rejects.toThrowErrorMatchingSnapshot()
4439
})
4540
test('--help shows help screen to user', async () => {
4641
const { stdout } = await execa(cliCmd, [cliPath, '--help'], {
@@ -49,9 +44,13 @@ describe('cli api', () => {
4944
expect(stdout).toMatchSnapshot()
5045
})
5146
test('no output will not show stored at hint', async () => {
52-
const { stdout } = await execa(cliCmd, [cliPath, '--input', inputFile, '-p', 'pixels'], {
53-
stripFinalNewline: true
54-
})
47+
const { stdout } = await execa(
48+
cliCmd,
49+
[cliPath, '--input', inputFile, '-p', 'pixels'],
50+
{
51+
stripFinalNewline: true
52+
}
53+
)
5554

5655
expect(stdout).not.toMatch(/Stored at:/)
5756
})
@@ -64,7 +63,7 @@ describe('cli api', () => {
6463
}
6564
)
6665

67-
expect(stdout).toMatch("")
66+
expect(stdout).toMatch('')
6867
})
6968
test('-o save result to file and basic svg structure is applied', async () => {
7069
const outputFile = resolve(

packages/sqip-cli/__tests__/e2e/sqip-plugin-primitive-e2e.test.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('primitive e2e/integration tests', () => {
6363
expect(types.length).toBeGreaterThanOrEqual(1)
6464
expect(
6565
parseFloat(firstPrimitive.attribs['fill-opacity']).toFixed(1)
66-
).toEqual("0.5")
66+
).toEqual('0.5')
6767
expect(backgroundRect.attribs['fill']).toEqual(darkMuted)
6868

6969
await remove(outputFile)
@@ -76,7 +76,21 @@ describe('primitive e2e/integration tests', () => {
7676
)
7777
const { stdout } = await execa(
7878
cliCmd,
79-
[cliPath, '-i', inputFile, '-o', outputFile, '-p', 'primitive', '-n', 5, '--primitive-background', '#123456', '--primitive-alpha', '64' ],
79+
[
80+
cliPath,
81+
'-i',
82+
inputFile,
83+
'-o',
84+
outputFile,
85+
'-p',
86+
'primitive',
87+
'-n',
88+
5,
89+
'--primitive-background',
90+
'#123456',
91+
'--primitive-alpha',
92+
'64'
93+
],
8094
{
8195
stripFinalNewline: true
8296
}

packages/sqip-cli/__tests__/unit/__snapshots__/sqip-cli.test.js.snap

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ Array [
1919
--version string Show version number
2020
-p, --plugins string[] One or more plugins. E.g. \\"-p primitive blur\\"
2121
-i, --input string
22-
[1m-o[22m, [1m--output[22m [4mstring[24m Save the resulting SVG to a file. The svg result
23-
will be returned by default.
22+
[1m-o[22m, [1m--output[22m [4mstring[24m Define the path of the resulting file. By default
23+
SQIP will guess the output file name.
2424
-w, --width number Width of the resulting file. Negative values and 0
2525
will fall back to original image width.
2626
--silent Supress all output
@@ -98,8 +98,8 @@ Array [
9898
--version string Show version number
9999
-p, --plugins string[] One or more plugins. E.g. \\"-p primitive blur\\"
100100
-i, --input string
101-
[1m-o[22m, [1m--output[22m [4mstring[24m Save the resulting SVG to a file. The svg result
102-
will be returned by default.
101+
[1m-o[22m, [1m--output[22m [4mstring[24m Define the path of the resulting file. By default
102+
SQIP will guess the output file name.
103103
-w, --width number Width of the resulting file. Negative values and 0
104104
will fall back to original image width.
105105
--silent Supress all output

packages/sqip-cli/__tests__/unit/sqip-cli.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import semver from 'semver'
55

66
jest.mock('sqip', () => {
77
const sqipMock = jest.fn()
8-
sqipMock.resolvePlugins = jest.fn(plugins =>
9-
plugins.map(plugin => ({
8+
sqipMock.resolvePlugins = jest.fn((plugins) =>
9+
plugins.map((plugin) => ({
1010
name: plugin,
1111
Plugin: { cliOptions: [] }
1212
}))

packages/sqip-cli/package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
"sqip-plugin-svgo": "^1.0.0-alpha.32"
3838
},
3939
"devDependencies": {
40-
"fs-extra": "^8.0.1",
41-
"semver": "^7.1.1"
40+
"cheerio": "^1.0.0-rc.3",
41+
"execa": "^4.0.2",
42+
"fs-extra": "^9.0.1",
43+
"semver": "^7.3.2"
4244
}
4345
}

packages/sqip-cli/src/wrapper.js

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#!/usr/bin/env node
22

33
import sqipCLI from './sqip-cli'
4-
54
;(async () => {
65
await sqipCLI()
76
})()

packages/sqip-plugin-blur/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
"url": "https://github.com/axe312ger/sqip/issues"
2525
},
2626
"dependencies": {
27-
"debug": "^4.1.1",
2827
"sqip": "^1.0.0-alpha.31"
2928
}
3029
}

0 commit comments

Comments
 (0)