Skip to content

Commit

Permalink
Merge pull request #1 from hildjj/dependencies
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
hildjj committed Nov 18, 2021
2 parents 1bcf4be + 7ff28bf commit e455c85
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 36 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Expand Up @@ -2,5 +2,5 @@

module.exports = {
root: true,
extends: '@cto.af'
extends: '@cto.af',
}
8 changes: 4 additions & 4 deletions .github/workflows/node.js.yml
Expand Up @@ -6,7 +6,7 @@ on:
branches:
- '*'
pull_request:
branches: [master]
branches: [main]

jobs:
build:
Expand All @@ -15,7 +15,7 @@ jobs:

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

steps:
- uses: actions/checkout@v2
Expand All @@ -34,9 +34,9 @@ jobs:
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-${{ matrix.node-version }}-
- name: Install pnpm
uses: pnpm/action-setup@v1.2.1
uses: pnpm/action-setup@v2.0.1
with:
version: 5.17.2
version: 6.22.2
run_install: true
- name: Test ${{ matrix.node-version }}
run: npm run coverage
Expand Down
4 changes: 3 additions & 1 deletion bin/data-colon.js
Expand Up @@ -5,7 +5,9 @@ const fs = require('fs')
const dataUri = require('strong-data-uri')
const mime = require('mime')
const commander = require('commander')
const {Buffer} = require('buffer')

// Examples:
// decode: data-colon data:foo
// encode: data-colon filename
// decode: data-colon < filename-starting-with-data:
Expand Down Expand Up @@ -48,7 +50,7 @@ function readStdin(cb) {
}

function encode(buf) {
// encode only throws on bad input types, which can't happen here.
// Encode only throws on bad input types, which can't happen here.
OUTPUT.write(dataUri.encode(buf, media))
OUTPUT.write('\n')
}
Expand Down
14 changes: 8 additions & 6 deletions package.json
Expand Up @@ -7,6 +7,7 @@
},
"scripts": {
"test": "ava",
"lint": "eslint . --ext js",
"coverage": "nyc -r lcov npm test"
},
"repository": {
Expand All @@ -26,18 +27,19 @@
},
"homepage": "https://github.com/hildjj/data-colon",
"dependencies": {
"commander": "^7.1.0",
"mime": "^2.5.2",
"commander": "^8.3.0",
"mime": "^3.0.0",
"strong-data-uri": "^1.0.6"
},
"engines": {
"node": ">=10.18"
"node": ">=12.21"
},
"devDependencies": {
"@cto.af/eslint-config": "^0.0.3",
"@cto.af/eslint-config": "^0.0.12",
"ava": "^3.15.0",
"eslint": "^7.20.0",
"eslint-plugin-ava": "^11.0.0",
"eslint": "^8.2.0",
"eslint-plugin-ava": "^13.1.0",
"eslint-plugin-jsdoc": "^37.0.3",
"eslint-plugin-node": "^11.1.0",
"nyc": "^15.1.0"
}
Expand Down
5 changes: 5 additions & 0 deletions test/.eslintrc.js
@@ -0,0 +1,5 @@
'use strict'

module.exports = {
extends: '@cto.af/eslint-config/ava',
}
49 changes: 25 additions & 24 deletions test/exec.ava.js
Expand Up @@ -6,6 +6,7 @@ const path = require('path')
const util = require('util')
const fs = require('fs')
const os = require('os')
const {Buffer} = require('buffer')

const readFile = util.promisify(fs.readFile)
const writeFile = util.promisify(fs.writeFile)
Expand All @@ -14,12 +15,12 @@ const rmdir = util.promisify(fs.rmdir)
const pkg = require('../package.json')

async function withTempDir(f) {
const dir = await mkdtemp(path.join(os.tmpdir(), pkg.name) + '-')
const dir = await mkdtemp(`${path.join(os.tmpdir(), pkg.name)}-`)
try {
await f(dir)
} finally {
if (parseFloat(process.version.slice(1)) >= 12.10) {
// if you use a more-modern node, I won't leave files in /tmp.
// If you use a more-modern node, I won't leave files in /tmp.
// win-win.
await rmdir(dir, {recursive: true})
} else {
Expand All @@ -35,17 +36,17 @@ function exec(bin, opts = {}) {
args: [],
encoding: 'utf8',
env: {},
...opts
...opts,
}
return new Promise((resolve, reject) => {
bin = path.join(__dirname, '..', 'bin', bin + '.js')
bin = path.join(__dirname, '..', 'bin', `${bin}.js`)
const env = {
...process.env,
...opts.env
...opts.env,
}
const c = spawn(bin, opts.args, {
stdio: 'pipe',
env
env,
})
c.on('error', reject)
const bufs = []
Expand All @@ -54,13 +55,13 @@ function exec(bin, opts = {}) {
c.on('close', code => {
const buf = Buffer.concat(bufs)
const str = buf.toString(opts.encoding)
if (code !== 0) {
if (code === 0) {
resolve(str)
} else {
const err = new Error(`process fail, code ${code}`)
err.buf = buf
err.str = str
reject(err)
} else {
resolve(str)
}
})
c.on('exit', (code, signal) => {
Expand All @@ -78,7 +79,7 @@ function exec(bin, opts = {}) {

test('help', async t => {
const txt = await exec('data-colon', {
args: ['-h']
args: ['-h'],
})
t.is(txt, `\
Usage: data-colon [options] [fileOrURI...]
Expand All @@ -92,32 +93,32 @@ Options:

test('version', async t => {
const txt = await exec('data-colon', {
args: ['-V']
args: ['-V'],
})
t.is(txt, pkg.version + '\n')
t.is(txt, `${pkg.version}\n`)
})

test('decode', async t => {
let txt = await exec('data-colon', {
args: ['data:text/plain;base64,aGVsbG8gd29ybGQ=']
args: ['data:text/plain;base64,aGVsbG8gd29ybGQ='],
})
t.is(txt, 'hello world')
txt = await exec('data-colon', {
stdin: 'data:text/plain;base64,aGVsbG8gd29ybGQ='
stdin: 'data:text/plain;base64,aGVsbG8gd29ybGQ=',
})
t.is(txt, 'hello world')

await t.throwsAsync(async() => {
await exec('data-colon', {
args: ['data:text/plain,hello\nworld']
args: ['data:text/plain,hello\nworld'],
})
})
})

test('encode', async t => {
const txt = await exec('data-colon', {
args: ['-m', 'text/plain'],
stdin: 'hello world'
stdin: 'hello world',
})
t.is(txt, 'data:text/plain;base64,aGVsbG8gd29ybGQ=\n')
})
Expand All @@ -128,18 +129,18 @@ test('round trip', async t => {
const bar = path.join(dir, 'bar.json')
await writeFile(foo, JSON.stringify({
foo: 1,
bar: [true, null]
bar: [true, null],
}, null, 2))
let txt = await exec('data-colon', {
args: [foo]
args: [foo],
})
t.is(
txt,
'data:application/json;base64,' +
'ewogICJmb28iOiAxLAogICJiYXIiOiBbCiAgICB0cnVlLAogICAgbnVsbAogIF0KfQ==\n'
)
txt = await exec('data-colon', {
args: [foo, '-m', 'text/plain']
args: [foo, '-m', 'text/plain'],
})
t.is(
txt,
Expand All @@ -148,27 +149,27 @@ test('round trip', async t => {
)
await t.throwsAsync(async() => {
await exec('data-colon', {
args: [foo + '-DOES_NOT_EXIST']
args: [`${foo}-DOES_NOT_EXIST`],
})
})
await exec('data-colon', {
args: [foo, '-o', bar]
args: [foo, '-o', bar],
})
t.is(
await readFile(bar, 'utf8'),
'data:application/json;base64,' +
'ewogICJmb28iOiAxLAogICJiYXIiOiBbCiAgICB0cnVlLAogICAgbnVsbAogIF0KfQ==\n'
)
await exec('data-colon', {
args: [bar, '-o', foo]
args: [bar, '-o', foo],
})
t.deepEqual(JSON.parse(await readFile(foo, 'utf8')), {
foo: 1,
bar: [true, null]
bar: [true, null],
})
await writeFile(foo, '{}')
t.is(await exec('data-colon', {
args: [foo]
args: [foo],
}), 'data:application/json;base64,e30=\n')
})
})

0 comments on commit e455c85

Please sign in to comment.