Skip to content

Commit

Permalink
Use native ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
1000ch committed Oct 22, 2021
1 parent c67769c commit 62635e1
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ jobs:
strategy:
matrix:
node-version:
- 16
- 14
- 12
- 10
os:
- ubuntu-latest
- macos-latest
Expand Down
6 changes: 3 additions & 3 deletions cli.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env node
'use strict';
const {spawn} = require('child_process');
const pngout = require('.');
import {spawn} from 'node:child_process';
import process from 'node:process';
import pngout from './index.js';

const input = process.argv.slice(2);

Expand Down
5 changes: 3 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
'use strict';
module.exports = require('./lib').path();
import lib from './lib/index.js';

export default lib.path();
15 changes: 9 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
'use strict';
const path = require('path');
const BinWrapper = require('bin-wrapper');
const pkg = require('../package.json');
import fs from 'node:fs';
import process from 'node:process';
import {fileURLToPath} from 'node:url';
import BinWrapper from 'bin-wrapper';

const pkg = JSON.parse(fs.readFileSync(new URL('../package.json', import.meta.url)));
const url = `https://raw.github.com/imagemin/pngout-bin/v${pkg.version}/vendor/`;

module.exports = new BinWrapper()
const binWrapper = new BinWrapper()
.src(`${url}osx/pngout`, 'darwin')
.src(`${url}linux/x86/pngout`, 'linux', 'x86')
.src(`${url}linux/x64/pngout`, 'linux', 'x64')
.src(`${url}freebsd/x86/pngout`, 'freebsd', 'x86')
.src(`${url}freebsd/x64/pngout`, 'freebsd', 'x64')
.src(`${url}win32/pngout.exe`, 'win32')
.dest(path.resolve(__dirname, '../vendor'))
.dest(fileURLToPath(new URL('../vendor', import.meta.url)))
.use(process.platform === 'win32' ? 'pngout.exe' : 'pngout');

export default binWrapper;
11 changes: 5 additions & 6 deletions lib/install.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
'use strict';
const path = require('path');
const bin = require('.');
import {fileURLToPath} from 'node:url';
import bin from './index.js';

const args = [
path.join(__dirname, '../test/fixtures/test.png'),
path.join(__dirname, '../test/fixtures/test-optimized.png'),
fileURLToPath(new URL('../test/fixtures/test.png', import.meta.url)),
fileURLToPath(new URL('../test/fixtures/test-optimized.png', import.meta.url)),
'-s4',
'-c6',
'-y'
'-y',
];

bin.run(args).then(() => {
Expand Down
15 changes: 8 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
"description": "pngout wrapper that makes it seamlessly available as a local dependency",
"license": "MIT",
"repository": "imagemin/pngout-bin",
"type": "module",
"author": {
"name": "1000ch",
"email": "shogo.sensui@gmail.com",
"name": "Shogo Sensui",
"email": "shogosensui@gmail.com",
"url": "github.com/1000ch"
},
"maintainers": [
Expand All @@ -29,7 +30,7 @@
"pngout": "cli.js"
},
"engines": {
"node": ">=10"
"node": "^12.20.0 || ^14.13.1 || >=16.0.0"
},
"scripts": {
"postinstall": "node lib/install.js",
Expand All @@ -55,10 +56,10 @@
"bin-wrapper": "^4.0.0"
},
"devDependencies": {
"ava": "^3.8.0",
"ava": "^3.15.0",
"compare-size": "^3.0.0",
"execa": "^4.0.0",
"tempy": "^0.5.0",
"xo": "^0.30.0"
"execa": "^5.1.1",
"tempy": "^2.0.0",
"xo": "^0.45.0"
}
}
8 changes: 4 additions & 4 deletions readme.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# pngout-bin ![GitHub Actions Status](https://github.com/imagemin/pngout-bin/workflows/test/badge.svg?branch=master)
# pngout-bin ![GitHub Actions Status](https://github.com/imagemin/pngout-bin/workflows/test/badge.svg)

> [pngout](http://advsys.net/ken/util/pngout.htm) optimizes the size of PNG files losslessly
Expand All @@ -15,10 +15,10 @@ $ npm install --save pngout-bin
## Usage

```js
const {execFile} = require('child_process');
const pngout = require('pngout-bin');
import {execFile} from 'node:child_process';
import pngout from 'pngout-bin';

execFile(pngout, ['input.png', 'output.png', '-s0', '-k0', '-f0'], err => {
execFile(pngout, ['input.png', 'output.png', '-s0', '-k0', '-f0'], error => {
console.log('Image minified!');
});
```
Expand Down
18 changes: 9 additions & 9 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
'use strict';
const path = require('path');
const test = require('ava');
const execa = require('execa');
const tempy = require('tempy');
const compareSize = require('compare-size');
const pngout = require('..');
import path from 'node:path';
import {fileURLToPath} from 'node:url';
import test from 'ava';
import execa from 'execa';
import tempy from 'tempy';
import compareSize from 'compare-size';
import pngout from '../index.js';

test('minify a PNG', async t => {
const temporary = tempy.directory();
const src = path.join(__dirname, 'fixtures/test.png');
const src = fileURLToPath(new URL('fixtures/test.png', import.meta.url));
const dest = path.join(temporary, 'test.png');
const args = [
src,
dest,
'-s4',
'-c6',
'-y'
'-y',
];

await execa(pngout, args);
Expand Down

0 comments on commit 62635e1

Please sign in to comment.