Skip to content

Commit

Permalink
Use native ESM and update dependencies (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
1000ch authored Sep 12, 2021
1 parent beba5b2 commit 35866f7
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 75 deletions.
78 changes: 20 additions & 58 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,64 +1,26 @@
name: test

on:
push:
branches:
- master
pull_request:
branches:
- master

- push
- pull_request
jobs:
linux:
runs-on: ubuntu-latest

test:
name: Node.js ${{ matrix.node-version }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
node-version: [10.x, 12.x, 14.x]

node-version:
- 12
- 14
- 16
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
env:
CI: true

macos:
runs-on: macos-latest

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
env:
CI: true

windows:
runs-on: windows-latest

strategy:
matrix:
node-version: [10.x, 12.x, 14.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
env:
CI: true
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
10 changes: 6 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';
const isSvg = require('is-svg');
const {optimize} = require('svgo');
import {Buffer} from 'node:buffer';
import isSvg from 'is-svg';
import {optimize} from 'svgo';

module.exports = options => async buffer => {
const imageminSvgo = options => async buffer => {
options = {multipass: true, ...options};

if (!isSvg(buffer)) {
Expand All @@ -16,3 +16,5 @@ module.exports = options => async buffer => {
const {data} = optimize(buffer, options);
return Buffer.from(data);
};

export default imageminSvgo;
11 changes: 6 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
"description": "SVGO imagemin plugin",
"license": "MIT",
"repository": "imagemin/imagemin-svgo",
"type": "module",
"funding": {
"url": "https://github.com/sindresorhus/imagemin-svgo?sponsor=1"
},
"engines": {
"node": ">=10"
"node": ">=12.20"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -26,11 +27,11 @@
"svgo"
],
"dependencies": {
"is-svg": "^4.2.1",
"svgo": "^2.1.0"
"is-svg": "^4.3.1",
"svgo": "^2.5.0"
},
"devDependencies": {
"ava": "^3.8.0",
"xo": "^0.30.0"
"ava": "^3.15.0",
"xo": "^0.44.0"
}
}
20 changes: 12 additions & 8 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
const test = require('ava');
const imageminSvgo = require('.');
const {extendDefaultPlugins} = require('svgo');
import test from 'ava';
import imageminSvgo from './index.js';

test('optimize a SVG', async t => {
t.is((await imageminSvgo()('<svg><style> circle {} </style></svg>')).toString(), '<svg><style/></svg>');
const data = (await imageminSvgo()('<svg><script></script></svg>')).toString();

t.is(data, '<svg><script/></svg>');
});

test('support SVGO options', async t => {
const data = (await imageminSvgo({
plugins: extendDefaultPlugins([{
name: 'removeStyleElement'
}])
})('<svg><style> circle {} </style></svg>')).toString();
plugins: [{
name: 'preset-default',
}, {
name: 'removeScriptElement',
active: true,
}],
})('<svg><script></script></svg>')).toString();

t.is(data, '<svg/>');
});
Expand Down

0 comments on commit 35866f7

Please sign in to comment.