Update ava to 4.3.3

The [release notes](https://github.com/avajs/ava/releases/tag/v4.3.3)
mention compatibility with Node 18.8.
This commit is contained in:
Henry Mercer 2022-09-02 18:02:07 +01:00
parent 21530f507f
commit bea5e4b220
160 changed files with 2647 additions and 2263 deletions

View file

@ -1,32 +0,0 @@
# 3.0.0
* Implement options.tmpfileCreated callback.
* Drop Node.js 6, modernize code, return Promise from async function.
* Support write TypedArray's like in node fs.writeFile.
* Remove graceful-fs dependency.
# 2.4.3
* Ignore errors raised by `fs.closeSync` when cleaning up after a write
error.
# 2.4.2
* A pair of patches to fix some fd leaks. We would leak fds with sync use
when errors occured and with async use any time fsync was not in use. (#34)
# 2.4.1
* Fix a bug where `signal-exit` instances would be leaked. This was fixed when addressing #35.
# 2.4.0
## Features
* Allow chown and mode options to be set to false to disable the defaulting behavior. (#20)
* Support passing encoding strings in options slot for compat with Node.js API. (#31)
* Add support for running inside of worker threads (#37)
## Fixes
* Remove unneeded call when returning success (#36)

View file

@ -4,8 +4,14 @@ write-file-atomic
This is an extension for node's `fs.writeFile` that makes its operation
atomic and allows you set ownership (uid/gid of the file).
### var writeFileAtomic = require('write-file-atomic')<br>writeFileAtomic(filename, data, [options], [callback])
### `writeFileAtomic(filename, data, [options], [callback])`
#### Description:
Atomically and asynchronously writes data to a file, replacing the file if it already
exists. data can be a string or a buffer.
#### Options:
* filename **String**
* data **String** | **Buffer**
* options **Object** | **String**
@ -18,8 +24,12 @@ atomic and allows you set ownership (uid/gid of the file).
* tmpfileCreated **Function** called when the tmpfile is created
* callback **Function**
Atomically and asynchronously writes data to a file, replacing the file if it already
exists. data can be a string or a buffer.
#### Usage:
```js
var writeFileAtomic = require('write-file-atomic')
writeFileAtomic(filename, data, [options], [callback])
```
The file is initially named `filename + "." + murmurhex(__filename, process.pid, ++invocations)`.
Note that `require('worker_threads').threadId` is used in addition to `process.pid` if running inside of a worker thread.
@ -67,6 +77,15 @@ This function also supports async/await:
})();
```
### var writeFileAtomicSync = require('write-file-atomic').sync<br>writeFileAtomicSync(filename, data, [options])
### `writeFileAtomicSync(filename, data, [options])`
#### Description:
The synchronous version of **writeFileAtomic**.
#### Usage:
```js
var writeFileAtomicSync = require('write-file-atomic').sync
writeFileAtomicSync(filename, data, [options])
```

View file

@ -8,8 +8,6 @@ const fs = require('fs')
const MurmurHash3 = require('imurmurhash')
const onExit = require('signal-exit')
const path = require('path')
const isTypedArray = require('is-typedarray')
const typedArrayToBuffer = require('typedarray-to-buffer')
const { promisify } = require('util')
const activeFiles = {}
@ -41,17 +39,23 @@ function cleanupOnExit (tmpfile) {
return () => {
try {
fs.unlinkSync(typeof tmpfile === 'function' ? tmpfile() : tmpfile)
} catch (_) {}
} catch {
// ignore errors
}
}
}
function serializeActiveFile (absoluteName) {
return new Promise(resolve => {
// make a queue if it doesn't already exist
if (!activeFiles[absoluteName]) activeFiles[absoluteName] = []
if (!activeFiles[absoluteName]) {
activeFiles[absoluteName] = []
}
activeFiles[absoluteName].push(resolve) // add this job to the queue
if (activeFiles[absoluteName].length === 1) resolve() // kick off the first one
if (activeFiles[absoluteName].length === 1) {
resolve()
} // kick off the first one
})
}
@ -106,10 +110,7 @@ async function writeFileAsync (filename, data, options = {}) {
if (options.tmpfileCreated) {
await options.tmpfileCreated(tmpfile)
}
if (isTypedArray(data)) {
data = typedArrayToBuffer(data)
}
if (Buffer.isBuffer(data)) {
if (ArrayBuffer.isView(data)) {
await promisify(fs.write)(fd, data, 0, data.length, 0)
} else if (data != null) {
await promisify(fs.write)(fd, String(data), 0, String(options.encoding || 'utf8'))
@ -151,11 +152,13 @@ async function writeFileAsync (filename, data, options = {}) {
activeFiles[absoluteName].shift() // remove the element added by serializeSameFile
if (activeFiles[absoluteName].length > 0) {
activeFiles[absoluteName][0]() // start next job if one is pending
} else delete activeFiles[absoluteName]
} else {
delete activeFiles[absoluteName]
}
}
}
function writeFile (filename, data, options, callback) {
async function writeFile (filename, data, options, callback) {
if (options instanceof Function) {
callback = options
options = {}
@ -163,15 +166,23 @@ function writeFile (filename, data, options, callback) {
const promise = writeFileAsync(filename, data, options)
if (callback) {
promise.then(callback, callback)
try {
const result = await promise
return callback(result)
} catch (err) {
return callback(err)
}
}
return promise
}
function writeFileSync (filename, data, options) {
if (typeof options === 'string') options = { encoding: options }
else if (!options) options = {}
if (typeof options === 'string') {
options = { encoding: options }
} else if (!options) {
options = {}
}
try {
filename = fs.realpathSync(filename)
} catch (ex) {
@ -206,10 +217,7 @@ function writeFileSync (filename, data, options) {
if (options.tmpfileCreated) {
options.tmpfileCreated(tmpfile)
}
if (isTypedArray(data)) {
data = typedArrayToBuffer(data)
}
if (Buffer.isBuffer(data)) {
if (ArrayBuffer.isView(data)) {
fs.writeSync(fd, data, 0, data.length, 0)
} else if (data != null) {
fs.writeSync(fd, String(data), 0, String(options.encoding || 'utf8'))

View file

@ -1,26 +1,29 @@
{
"name": "write-file-atomic",
"version": "3.0.3",
"version": "4.0.2",
"description": "Write files in an atomic fashion w/configurable ownership",
"main": "index.js",
"main": "./lib/index.js",
"scripts": {
"test": "tap",
"posttest": "npm run lint",
"lint": "standard",
"postlint": "rimraf chowncopy good nochmod nochown nofsync nofsyncopt noopen norename \"norename nounlink\" nowrite",
"lint": "eslint \"**/*.js\"",
"postlint": "template-oss-check",
"preversion": "npm test",
"postversion": "npm publish",
"prepublishOnly": "git push origin --follow-tags"
"prepublishOnly": "git push origin --follow-tags",
"lintfix": "npm run lint -- --fix",
"snap": "tap",
"template-oss-apply": "template-oss-apply --force"
},
"repository": {
"type": "git",
"url": "git://github.com/npm/write-file-atomic.git"
"url": "https://github.com/npm/write-file-atomic.git"
},
"keywords": [
"writeFile",
"atomic"
],
"author": "Rebecca Turner <me@re-becca.org> (http://re-becca.org)",
"author": "GitHub Inc.",
"license": "ISC",
"bugs": {
"url": "https://github.com/npm/write-file-atomic/issues"
@ -28,21 +31,25 @@
"homepage": "https://github.com/npm/write-file-atomic",
"dependencies": {
"imurmurhash": "^0.1.4",
"is-typedarray": "^1.0.0",
"signal-exit": "^3.0.2",
"typedarray-to-buffer": "^3.1.5"
"signal-exit": "^3.0.7"
},
"devDependencies": {
"mkdirp": "^0.5.1",
"require-inject": "^1.4.4",
"rimraf": "^2.6.3",
"standard": "^14.3.1",
"tap": "^14.10.6"
"@npmcli/eslint-config": "^3.0.1",
"@npmcli/template-oss": "3.5.0",
"mkdirp": "^1.0.4",
"rimraf": "^3.0.2",
"tap": "^16.0.1"
},
"files": [
"index.js"
"bin/",
"lib/"
],
"tap": {
"100": true
"engines": {
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"windowsCI": false,
"version": "3.5.0"
}
}