pax_global_header 0000666 0000000 0000000 00000000064 15150140533 0014507 g ustar 00root root 0000000 0000000 52 comment=f54fa1599640d35d0130efa2494e5b4056590b0b
npm-write-file-atomic-f54fa15/ 0000775 0000000 0000000 00000000000 15150140533 0016235 5 ustar 00root root 0000000 0000000 npm-write-file-atomic-f54fa15/.commitlintrc.js 0000664 0000000 0000000 00000000566 15150140533 0021364 0 ustar 00root root 0000000 0000000 /* This file is automatically added by @npmcli/template-oss. Do not edit. */
module.exports = {
extends: ['@commitlint/config-conventional'],
rules: {
'type-enum': [2, 'always', ['feat', 'fix', 'docs', 'deps', 'chore']],
'header-max-length': [2, 'always', 80],
'subject-case': [0],
'body-max-line-length': [0],
'footer-max-line-length': [0],
},
}
npm-write-file-atomic-f54fa15/.eslintrc.js 0000664 0000000 0000000 00000000623 15150140533 0020475 0 ustar 00root root 0000000 0000000 /* This file is automatically added by @npmcli/template-oss. Do not edit. */
'use strict'
const { readdirSync: readdir } = require('fs')
const localConfigs = readdir(__dirname)
.filter((file) => file.startsWith('.eslintrc.local.'))
.map((file) => `./${file}`)
module.exports = {
root: true,
ignorePatterns: [
'tap-testdir*/',
],
extends: [
'@npmcli',
...localConfigs,
],
}
npm-write-file-atomic-f54fa15/.github/ 0000775 0000000 0000000 00000000000 15150140533 0017575 5 ustar 00root root 0000000 0000000 npm-write-file-atomic-f54fa15/.github/CODEOWNERS 0000664 0000000 0000000 00000000132 15150140533 0021164 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
* @npm/cli-team
npm-write-file-atomic-f54fa15/.github/ISSUE_TEMPLATE/ 0000775 0000000 0000000 00000000000 15150140533 0021760 5 ustar 00root root 0000000 0000000 npm-write-file-atomic-f54fa15/.github/ISSUE_TEMPLATE/bug.yml 0000664 0000000 0000000 00000002655 15150140533 0023270 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: Bug
description: File a bug/issue
title: "[BUG]
"
labels: [ Bug, Needs Triage ]
body:
- type: checkboxes
attributes:
label: Is there an existing issue for this?
description: Please [search here](./issues) to see if an issue already exists for your problem.
options:
- label: I have searched the existing issues
required: true
- type: textarea
attributes:
label: Current Behavior
description: A clear & concise description of what you're experiencing.
validations:
required: false
- type: textarea
attributes:
label: Expected Behavior
description: A clear & concise description of what you expected to happen.
validations:
required: false
- type: textarea
attributes:
label: Steps To Reproduce
description: Steps to reproduce the behavior.
value: |
1. In this environment...
2. With this config...
3. Run '...'
4. See error...
validations:
required: false
- type: textarea
attributes:
label: Environment
description: |
examples:
- **npm**: 7.6.3
- **Node**: 13.14.0
- **OS**: Ubuntu 20.04
- **platform**: Macbook Pro
value: |
- npm:
- Node:
- OS:
- platform:
validations:
required: false
npm-write-file-atomic-f54fa15/.github/ISSUE_TEMPLATE/config.yml 0000664 0000000 0000000 00000000145 15150140533 0023750 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
blank_issues_enabled: true
npm-write-file-atomic-f54fa15/.github/actions/ 0000775 0000000 0000000 00000000000 15150140533 0021235 5 ustar 00root root 0000000 0000000 npm-write-file-atomic-f54fa15/.github/actions/create-check/ 0000775 0000000 0000000 00000000000 15150140533 0023553 5 ustar 00root root 0000000 0000000 npm-write-file-atomic-f54fa15/.github/actions/create-check/action.yml 0000664 0000000 0000000 00000002720 15150140533 0025554 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: 'Create Check'
inputs:
name:
required: true
token:
required: true
sha:
required: true
check-name:
default: ''
outputs:
check-id:
value: ${{ steps.create-check.outputs.check_id }}
runs:
using: "composite"
steps:
- name: Get Workflow Job
uses: actions/github-script@v7
id: workflow
env:
JOB_NAME: "${{ inputs.name }}"
SHA: "${{ inputs.sha }}"
with:
result-encoding: string
script: |
const { repo: { owner, repo}, runId, serverUrl } = context
const { JOB_NAME, SHA } = process.env
const job = await github.rest.actions.listJobsForWorkflowRun({
owner,
repo,
run_id: runId,
per_page: 100
}).then(r => r.data.jobs.find(j => j.name.endsWith(JOB_NAME)))
return [
`This check is assosciated with ${serverUrl}/${owner}/${repo}/commit/${SHA}.`,
'Run logs:',
job?.html_url || `could not be found for a job ending with: "${JOB_NAME}"`,
].join(' ')
- name: Create Check
uses: LouisBrunner/checks-action@v1.6.0
id: create-check
with:
token: ${{ inputs.token }}
sha: ${{ inputs.sha }}
status: in_progress
name: ${{ inputs.check-name || inputs.name }}
output: |
{"summary":"${{ steps.workflow.outputs.result }}"}
npm-write-file-atomic-f54fa15/.github/actions/install-latest-npm/ 0000775 0000000 0000000 00000000000 15150140533 0024765 5 ustar 00root root 0000000 0000000 npm-write-file-atomic-f54fa15/.github/actions/install-latest-npm/action.yml 0000664 0000000 0000000 00000003406 15150140533 0026770 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: 'Install Latest npm'
description: 'Install the latest version of npm compatible with the Node version'
inputs:
node:
description: 'Current Node version'
required: true
runs:
using: "composite"
steps:
# node 10/12/14 ship with npm@6, which is known to fail when updating itself in windows
- name: Update Windows npm
if: |
runner.os == 'Windows' && (
startsWith(inputs.node, 'v10.') ||
startsWith(inputs.node, 'v12.') ||
startsWith(inputs.node, 'v14.')
)
shell: cmd
run: |
curl -sO https://registry.npmjs.org/npm/-/npm-7.5.4.tgz
tar xf npm-7.5.4.tgz
cd package
node lib/npm.js install --no-fund --no-audit -g ..\npm-7.5.4.tgz
cd ..
rmdir /s /q package
- name: Install Latest npm
shell: bash
env:
NODE_VERSION: ${{ inputs.node }}
working-directory: ${{ runner.temp }}
run: |
MATCH=""
SPECS=("latest" "next-10" "next-9" "next-8" "next-7" "next-6")
echo "node@$NODE_VERSION"
for SPEC in ${SPECS[@]}; do
ENGINES=$(npm view npm@$SPEC --json | jq -r '.engines.node')
echo "Checking if node@$NODE_VERSION satisfies npm@$SPEC ($ENGINES)"
if npx semver -r "$ENGINES" "$NODE_VERSION" > /dev/null; then
MATCH=$SPEC
echo "Found compatible version: npm@$MATCH"
break
fi
done
if [ -z $MATCH ]; then
echo "Could not find a compatible version of npm for node@$NODE_VERSION"
exit 1
fi
npm i --prefer-online --no-fund --no-audit -g npm@$MATCH
- name: npm Version
shell: bash
run: npm -v
npm-write-file-atomic-f54fa15/.github/dependabot.yml 0000664 0000000 0000000 00000000656 15150140533 0022434 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
version: 2
updates:
- package-ecosystem: npm
directory: /
schedule:
interval: daily
target-branch: "main"
allow:
- dependency-type: direct
versioning-strategy: increase-if-necessary
commit-message:
prefix: deps
prefix-development: chore
labels:
- "Dependencies"
open-pull-requests-limit: 10
npm-write-file-atomic-f54fa15/.github/matchers/ 0000775 0000000 0000000 00000000000 15150140533 0021403 5 ustar 00root root 0000000 0000000 npm-write-file-atomic-f54fa15/.github/matchers/tap.json 0000664 0000000 0000000 00000001204 15150140533 0023057 0 ustar 00root root 0000000 0000000 {
"//@npmcli/template-oss": "This file is automatically added by @npmcli/template-oss. Do not edit.",
"problemMatcher": [
{
"owner": "tap",
"pattern": [
{
"regexp": "^\\s*not ok \\d+ - (.*)",
"message": 1
},
{
"regexp": "^\\s*---"
},
{
"regexp": "^\\s*at:"
},
{
"regexp": "^\\s*line:\\s*(\\d+)",
"line": 1
},
{
"regexp": "^\\s*column:\\s*(\\d+)",
"column": 1
},
{
"regexp": "^\\s*file:\\s*(.*)",
"file": 1
}
]
}
]
}
npm-write-file-atomic-f54fa15/.github/settings.yml 0000664 0000000 0000000 00000001377 15150140533 0022170 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
repository:
allow_merge_commit: false
allow_rebase_merge: true
allow_squash_merge: true
squash_merge_commit_title: PR_TITLE
squash_merge_commit_message: PR_BODY
delete_branch_on_merge: true
enable_automated_security_fixes: true
enable_vulnerability_alerts: true
branches:
- name: main
protection:
required_status_checks: null
enforce_admins: true
block_creations: true
required_pull_request_reviews:
required_approving_review_count: 1
require_code_owner_reviews: true
require_last_push_approval: true
dismiss_stale_reviews: true
restrictions:
apps: []
users: []
teams: [ "cli-team" ]
npm-write-file-atomic-f54fa15/.github/workflows/ 0000775 0000000 0000000 00000000000 15150140533 0021632 5 ustar 00root root 0000000 0000000 npm-write-file-atomic-f54fa15/.github/workflows/audit.yml 0000664 0000000 0000000 00000002275 15150140533 0023471 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: Audit
on:
workflow_dispatch:
schedule:
# "At 08:00 UTC (01:00 PT) on Monday" https://crontab.guru/#0_8_*_*_1
- cron: "0 8 * * 1"
permissions:
contents: read
jobs:
audit:
name: Audit Dependencies
if: github.repository_owner == 'npm'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund --package-lock
- name: Run Production Audit
run: npm audit --omit=dev
- name: Run Full Audit
run: npm audit --audit-level=none
npm-write-file-atomic-f54fa15/.github/workflows/ci-release.yml 0000664 0000000 0000000 00000010567 15150140533 0024377 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: CI - Release
on:
workflow_dispatch:
inputs:
ref:
required: true
type: string
default: main
workflow_call:
inputs:
ref:
required: true
type: string
check-sha:
required: true
type: string
permissions:
contents: read
checks: write
jobs:
lint-all:
name: Lint All
if: github.repository_owner == 'npm'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Create Check
id: create-check
if: ${{ inputs.check-sha }}
uses: ./.github/actions/create-check
with:
name: "Lint All"
token: ${{ secrets.GITHUB_TOKEN }}
sha: ${{ inputs.check-sha }}
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Lint
run: npm run lint --ignore-scripts
- name: Post Lint
run: npm run postlint --ignore-scripts
- name: Conclude Check
uses: LouisBrunner/checks-action@v1.6.0
if: steps.create-check.outputs.check-id && always()
with:
token: ${{ secrets.GITHUB_TOKEN }}
conclusion: ${{ job.status }}
check_id: ${{ steps.create-check.outputs.check-id }}
test-all:
name: Test All - ${{ matrix.platform.name }} - ${{ matrix.node-version }}
if: github.repository_owner == 'npm'
strategy:
fail-fast: false
matrix:
platform:
- name: Linux
os: ubuntu-latest
shell: bash
- name: macOS
os: macos-latest
shell: bash
- name: macOS
os: macos-13
shell: bash
node-version:
- 20.17.0
- 20.x
- 22.9.0
- 22.x
exclude:
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 20.17.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 20.x
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 22.9.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 22.x
runs-on: ${{ matrix.platform.os }}
defaults:
run:
shell: ${{ matrix.platform.shell }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ inputs.ref }}
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Create Check
id: create-check
if: ${{ inputs.check-sha }}
uses: ./.github/actions/create-check
with:
name: "Test All - ${{ matrix.platform.name }} - ${{ matrix.node-version }}"
token: ${{ secrets.GITHUB_TOKEN }}
sha: ${{ inputs.check-sha }}
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: ${{ matrix.node-version }}
check-latest: contains(matrix.node-version, '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Add Problem Matcher
run: echo "::add-matcher::.github/matchers/tap.json"
- name: Test
run: npm test --ignore-scripts
- name: Conclude Check
uses: LouisBrunner/checks-action@v1.6.0
if: steps.create-check.outputs.check-id && always()
with:
token: ${{ secrets.GITHUB_TOKEN }}
conclusion: ${{ job.status }}
check_id: ${{ steps.create-check.outputs.check-id }}
npm-write-file-atomic-f54fa15/.github/workflows/ci.yml 0000664 0000000 0000000 00000006021 15150140533 0022747 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: CI
on:
workflow_dispatch:
pull_request:
push:
branches:
- main
schedule:
# "At 09:00 UTC (02:00 PT) on Monday" https://crontab.guru/#0_9_*_*_1
- cron: "0 9 * * 1"
permissions:
contents: read
jobs:
lint:
name: Lint
if: github.repository_owner == 'npm'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Lint
run: npm run lint --ignore-scripts
- name: Post Lint
run: npm run postlint --ignore-scripts
test:
name: Test - ${{ matrix.platform.name }} - ${{ matrix.node-version }}
if: github.repository_owner == 'npm'
strategy:
fail-fast: false
matrix:
platform:
- name: Linux
os: ubuntu-latest
shell: bash
- name: macOS
os: macos-latest
shell: bash
- name: macOS
os: macos-13
shell: bash
node-version:
- 20.17.0
- 20.x
- 22.9.0
- 22.x
exclude:
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 20.17.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 20.x
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 22.9.0
- platform: { name: macOS, os: macos-13, shell: bash }
node-version: 22.x
runs-on: ${{ matrix.platform.os }}
defaults:
run:
shell: ${{ matrix.platform.shell }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: ${{ matrix.node-version }}
check-latest: contains(matrix.node-version, '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Add Problem Matcher
run: echo "::add-matcher::.github/matchers/tap.json"
- name: Test
run: npm test --ignore-scripts
npm-write-file-atomic-f54fa15/.github/workflows/codeql-analysis.yml 0000664 0000000 0000000 00000001606 15150140533 0025450 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: CodeQL
on:
push:
branches:
- main
pull_request:
branches:
- main
schedule:
# "At 10:00 UTC (03:00 PT) on Monday" https://crontab.guru/#0_10_*_*_1
- cron: "0 10 * * 1"
permissions:
contents: read
jobs:
analyze:
name: Analyze
runs-on: ubuntu-latest
permissions:
actions: read
contents: read
security-events: write
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: javascript
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
npm-write-file-atomic-f54fa15/.github/workflows/post-dependabot.yml 0000664 0000000 0000000 00000012004 15150140533 0025442 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: Post Dependabot
on: pull_request
permissions:
contents: write
jobs:
template-oss:
name: template-oss
if: github.repository_owner == 'npm' && github.actor == 'dependabot[bot]'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Fetch Dependabot Metadata
id: metadata
uses: dependabot/fetch-metadata@v1
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
# Dependabot can update multiple directories so we output which directory
# it is acting on so we can run the command for the correct root or workspace
- name: Get Dependabot Directory
if: contains(steps.metadata.outputs.dependency-names, '@npmcli/template-oss')
id: flags
run: |
dependabot_dir="${{ steps.metadata.outputs.directory }}"
if [[ "$dependabot_dir" == "/" || "$dependabot_dir" == "/main" ]]; then
echo "workspace=-iwr" >> $GITHUB_OUTPUT
else
# strip leading slash from directory so it works as a
# a path to the workspace flag
echo "workspace=--workspace ${dependabot_dir#/}" >> $GITHUB_OUTPUT
fi
- name: Apply Changes
if: steps.flags.outputs.workspace
id: apply
run: |
npm run template-oss-apply ${{ steps.flags.outputs.workspace }}
if [[ `git status --porcelain` ]]; then
echo "changes=true" >> $GITHUB_OUTPUT
fi
# This only sets the conventional commit prefix. This workflow can't reliably determine
# what the breaking change is though. If a BREAKING CHANGE message is required then
# this PR check will fail and the commit will be amended with stafftools
if [[ "${{ steps.metadata.outputs.update-type }}" == "version-update:semver-major" ]]; then
prefix='feat!'
else
prefix='chore'
fi
echo "message=$prefix: postinstall for dependabot template-oss PR" >> $GITHUB_OUTPUT
# This step will fail if template-oss has made any workflow updates. It is impossible
# for a workflow to update other workflows. In the case it does fail, we continue
# and then try to apply only a portion of the changes in the next step
- name: Push All Changes
if: steps.apply.outputs.changes
id: push
continue-on-error: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git commit -am "${{ steps.apply.outputs.message }}"
git push
# If the previous step failed, then reset the commit and remove any workflow changes
# and attempt to commit and push again. This is helpful because we will have a commit
# with the correct prefix that we can then --amend with @npmcli/stafftools later.
- name: Push All Changes Except Workflows
if: steps.apply.outputs.changes && steps.push.outcome == 'failure'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git reset HEAD~
git checkout HEAD -- .github/workflows/
git clean -fd .github/workflows/
git commit -am "${{ steps.apply.outputs.message }}"
git push
# Check if all the necessary template-oss changes were applied. Since we continued
# on errors in one of the previous steps, this check will fail if our follow up
# only applied a portion of the changes and we need to followup manually.
#
# Note that this used to run `lint` and `postlint` but that will fail this action
# if we've also shipped any linting changes separate from template-oss. We do
# linting in another action, so we want to fail this one only if there are
# template-oss changes that could not be applied.
- name: Check Changes
if: steps.apply.outputs.changes
run: |
npm exec --offline ${{ steps.flags.outputs.workspace }} -- template-oss-check
- name: Fail on Breaking Change
if: steps.apply.outputs.changes && startsWith(steps.apply.outputs.message, 'feat!')
run: |
echo "This PR has a breaking change. Run 'npx -p @npmcli/stafftools gh template-oss-fix'"
echo "for more information on how to fix this with a BREAKING CHANGE footer."
exit 1
npm-write-file-atomic-f54fa15/.github/workflows/pull-request.yml 0000664 0000000 0000000 00000002737 15150140533 0025030 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: Pull Request
on:
pull_request:
types:
- opened
- reopened
- edited
- synchronize
permissions:
contents: read
jobs:
commitlint:
name: Lint Commits
if: github.repository_owner == 'npm'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Run Commitlint on Commits
id: commit
continue-on-error: true
run: npx --offline commitlint -V --from 'origin/${{ github.base_ref }}' --to ${{ github.event.pull_request.head.sha }}
- name: Run Commitlint on PR Title
if: steps.commit.outcome == 'failure'
env:
PR_TITLE: ${{ github.event.pull_request.title }}
run: echo "$PR_TITLE" | npx --offline commitlint -V
npm-write-file-atomic-f54fa15/.github/workflows/release-integration.yml 0000664 0000000 0000000 00000004163 15150140533 0026322 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: Release Integration
on:
workflow_dispatch:
inputs:
releases:
required: true
type: string
description: 'A json array of releases. Required fields: publish: tagName, publishTag. publish check: pkgName, version'
workflow_call:
inputs:
releases:
required: true
type: string
description: 'A json array of releases. Required fields: publish: tagName, publishTag. publish check: pkgName, version'
secrets:
PUBLISH_TOKEN:
required: true
permissions:
contents: read
id-token: write
jobs:
publish:
name: Publish
runs-on: ubuntu-latest
defaults:
run:
shell: bash
permissions:
id-token: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ fromJSON(inputs.releases)[0].tagName }}
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Set npm authToken
run: npm config set '//registry.npmjs.org/:_authToken'=\${PUBLISH_TOKEN}
- name: Publish
env:
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
RELEASES: ${{ inputs.releases }}
run: |
EXIT_CODE=0
for release in $(echo $RELEASES | jq -r '.[] | @base64'); do
PUBLISH_TAG=$(echo "$release" | base64 --decode | jq -r .publishTag)
npm publish --provenance --tag="$PUBLISH_TAG"
STATUS=$?
if [[ "$STATUS" -eq 1 ]]; then
EXIT_CODE=$STATUS
fi
done
exit $EXIT_CODE
npm-write-file-atomic-f54fa15/.github/workflows/release.yml 0000664 0000000 0000000 00000026106 15150140533 0024002 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
name: Release
on:
push:
branches:
- main
permissions:
contents: write
pull-requests: write
checks: write
jobs:
release:
outputs:
pr: ${{ steps.release.outputs.pr }}
pr-branch: ${{ steps.release.outputs.pr-branch }}
pr-number: ${{ steps.release.outputs.pr-number }}
pr-sha: ${{ steps.release.outputs.pr-sha }}
releases: ${{ steps.release.outputs.releases }}
comment-id: ${{ steps.create-comment.outputs.comment-id || steps.update-comment.outputs.comment-id }}
check-id: ${{ steps.create-check.outputs.check-id }}
name: Release
if: github.repository_owner == 'npm'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Release Please
id: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npx --offline template-oss-release-please --branch="${{ github.ref_name }}" --backport="" --defaultTag="latest"
- name: Create Release Manager Comment Text
if: steps.release.outputs.pr-number
uses: actions/github-script@v7
id: comment-text
with:
result-encoding: string
script: |
const { runId, repo: { owner, repo } } = context
const { data: workflow } = await github.rest.actions.getWorkflowRun({ owner, repo, run_id: runId })
return['## Release Manager', `Release workflow run: ${workflow.html_url}`].join('\n\n')
- name: Find Release Manager Comment
uses: peter-evans/find-comment@v2
if: steps.release.outputs.pr-number
id: found-comment
with:
issue-number: ${{ steps.release.outputs.pr-number }}
comment-author: 'github-actions[bot]'
body-includes: '## Release Manager'
- name: Create Release Manager Comment
id: create-comment
if: steps.release.outputs.pr-number && !steps.found-comment.outputs.comment-id
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ steps.release.outputs.pr-number }}
body: ${{ steps.comment-text.outputs.result }}
- name: Update Release Manager Comment
id: update-comment
if: steps.release.outputs.pr-number && steps.found-comment.outputs.comment-id
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.found-comment.outputs.comment-id }}
body: ${{ steps.comment-text.outputs.result }}
edit-mode: 'replace'
- name: Create Check
id: create-check
uses: ./.github/actions/create-check
if: steps.release.outputs.pr-sha
with:
name: "Release"
token: ${{ secrets.GITHUB_TOKEN }}
sha: ${{ steps.release.outputs.pr-sha }}
update:
needs: release
outputs:
sha: ${{ steps.commit.outputs.sha }}
check-id: ${{ steps.create-check.outputs.check-id }}
name: Update - Release
if: github.repository_owner == 'npm' && needs.release.outputs.pr
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ needs.release.outputs.pr-branch }}
- name: Setup Git User
run: |
git config --global user.email "npm-cli+bot@github.com"
git config --global user.name "npm CLI robot"
- name: Setup Node
uses: actions/setup-node@v4
id: node
with:
node-version: 22.x
check-latest: contains('22.x', '.x')
- name: Install Latest npm
uses: ./.github/actions/install-latest-npm
with:
node: ${{ steps.node.outputs.node-version }}
- name: Install Dependencies
run: npm i --ignore-scripts --no-audit --no-fund
- name: Create Release Manager Checklist Text
id: comment-text
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm exec --offline -- template-oss-release-manager --pr="${{ needs.release.outputs.pr-number }}" --backport="" --defaultTag="latest" --publish
- name: Append Release Manager Comment
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ needs.release.outputs.comment-id }}
body: ${{ steps.comment-text.outputs.result }}
edit-mode: 'append'
- name: Run Post Pull Request Actions
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: npm run rp-pull-request --ignore-scripts --if-present -- --pr="${{ needs.release.outputs.pr-number }}" --commentId="${{ needs.release.outputs.comment-id }}"
- name: Commit
id: commit
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git commit --all --amend --no-edit || true
git push --force-with-lease
echo "sha=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT
- name: Create Check
id: create-check
uses: ./.github/actions/create-check
with:
name: "Update - Release"
check-name: "Release"
token: ${{ secrets.GITHUB_TOKEN }}
sha: ${{ steps.commit.outputs.sha }}
- name: Conclude Check
uses: LouisBrunner/checks-action@v1.6.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
conclusion: ${{ job.status }}
check_id: ${{ needs.release.outputs.check-id }}
ci:
name: CI - Release
needs: [ release, update ]
if: needs.release.outputs.pr
uses: ./.github/workflows/ci-release.yml
with:
ref: ${{ needs.release.outputs.pr-branch }}
check-sha: ${{ needs.update.outputs.sha }}
post-ci:
needs: [ release, update, ci ]
name: Post CI - Release
if: github.repository_owner == 'npm' && needs.release.outputs.pr && always()
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Get CI Conclusion
id: conclusion
run: |
result=""
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
result="failure"
elif [[ "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
result="cancelled"
else
result="success"
fi
echo "result=$result" >> $GITHUB_OUTPUT
- name: Conclude Check
uses: LouisBrunner/checks-action@v1.6.0
with:
token: ${{ secrets.GITHUB_TOKEN }}
conclusion: ${{ steps.conclusion.outputs.result }}
check_id: ${{ needs.update.outputs.check-id }}
post-release:
needs: release
outputs:
comment-id: ${{ steps.create-comment.outputs.comment-id }}
name: Post Release - Release
if: github.repository_owner == 'npm' && needs.release.outputs.releases
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Create Release PR Comment Text
id: comment-text
uses: actions/github-script@v7
env:
RELEASES: ${{ needs.release.outputs.releases }}
with:
result-encoding: string
script: |
const releases = JSON.parse(process.env.RELEASES)
const { runId, repo: { owner, repo } } = context
const issue_number = releases[0].prNumber
const runUrl = `https://github.com/${owner}/${repo}/actions/runs/${runId}`
return [
'## Release Workflow\n',
...releases.map(r => `- \`${r.pkgName}@${r.version}\` ${r.url}`),
`- Workflow run: :arrows_counterclockwise: ${runUrl}`,
].join('\n')
- name: Create Release PR Comment
id: create-comment
uses: peter-evans/create-or-update-comment@v3
with:
issue-number: ${{ fromJSON(needs.release.outputs.releases)[0].prNumber }}
body: ${{ steps.comment-text.outputs.result }}
release-integration:
needs: release
name: Release Integration
if: needs.release.outputs.releases
uses: ./.github/workflows/release-integration.yml
permissions:
contents: read
id-token: write
secrets:
PUBLISH_TOKEN: ${{ secrets.PUBLISH_TOKEN }}
with:
releases: ${{ needs.release.outputs.releases }}
post-release-integration:
needs: [ release, release-integration, post-release ]
name: Post Release Integration - Release
if: github.repository_owner == 'npm' && needs.release.outputs.releases && always()
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Get Post Release Conclusion
id: conclusion
run: |
if [[ "${{ contains(needs.*.result, 'failure') }}" == "true" ]]; then
result="x"
elif [[ "${{ contains(needs.*.result, 'cancelled') }}" == "true" ]]; then
result="heavy_multiplication_x"
else
result="white_check_mark"
fi
echo "result=$result" >> $GITHUB_OUTPUT
- name: Find Release PR Comment
uses: peter-evans/find-comment@v2
id: found-comment
with:
issue-number: ${{ fromJSON(needs.release.outputs.releases)[0].prNumber }}
comment-author: 'github-actions[bot]'
body-includes: '## Release Workflow'
- name: Create Release PR Comment Text
id: comment-text
if: steps.found-comment.outputs.comment-id
uses: actions/github-script@v7
env:
RESULT: ${{ steps.conclusion.outputs.result }}
BODY: ${{ steps.found-comment.outputs.comment-body }}
with:
result-encoding: string
script: |
const { RESULT, BODY } = process.env
const body = [BODY.replace(/(Workflow run: :)[a-z_]+(:)/, `$1${RESULT}$2`)]
if (RESULT !== 'white_check_mark') {
body.push(':rotating_light::rotating_light::rotating_light:')
body.push([
'@npm/cli-team: The post-release workflow failed for this release.',
'Manual steps may need to be taken after examining the workflow output.'
].join(' '))
body.push(':rotating_light::rotating_light::rotating_light:')
}
return body.join('\n\n').trim()
- name: Update Release PR Comment
if: steps.comment-text.outputs.result
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.found-comment.outputs.comment-id }}
body: ${{ steps.comment-text.outputs.result }}
edit-mode: 'replace'
npm-write-file-atomic-f54fa15/.gitignore 0000664 0000000 0000000 00000001050 15150140533 0020221 0 ustar 00root root 0000000 0000000 # This file is automatically added by @npmcli/template-oss. Do not edit.
# ignore everything in the root
/*
!**/.gitignore
!/.commitlintrc.js
!/.eslint.config.js
!/.eslintrc.js
!/.eslintrc.local.*
!/.git-blame-ignore-revs
!/.github/
!/.gitignore
!/.npmrc
!/.prettierignore
!/.prettierrc.js
!/.release-please-manifest.json
!/bin/
!/CHANGELOG*
!/CODE_OF_CONDUCT.md
!/CONTRIBUTING.md
!/docs/
!/lib/
!/LICENSE*
!/map.js
!/package.json
!/README*
!/release-please-config.json
!/scripts/
!/SECURITY.md
!/tap-snapshots/
!/test/
!/tsconfig.json
tap-testdir*/
npm-write-file-atomic-f54fa15/.npmrc 0000664 0000000 0000000 00000000135 15150140533 0017354 0 ustar 00root root 0000000 0000000 ; This file is automatically added by @npmcli/template-oss. Do not edit.
package-lock=false
npm-write-file-atomic-f54fa15/.release-please-manifest.json 0000664 0000000 0000000 00000000023 15150140533 0023674 0 ustar 00root root 0000000 0000000 {
".": "7.0.1"
}
npm-write-file-atomic-f54fa15/CHANGELOG.md 0000664 0000000 0000000 00000013676 15150140533 0020063 0 ustar 00root root 0000000 0000000 # Changelog
## [7.0.1](https://github.com/npm/write-file-atomic/compare/v7.0.0...v7.0.1) (2026-02-26)
### Bug Fixes
* [`da246ef`](https://github.com/npm/write-file-atomic/commit/da246ef6b911f75c236070193eca823df7b9969f) [#229](https://github.com/npm/write-file-atomic/pull/229) use node:crypto instead of imurmurhash (@owlstronaut)
### Dependencies
* [`727e92c`](https://github.com/npm/write-file-atomic/commit/727e92c836515816e454919b526162490a9a9524) [#229](https://github.com/npm/write-file-atomic/pull/229) remove imurmurhash
### Chores
* [`4785863`](https://github.com/npm/write-file-atomic/commit/47858631168a63da5415c57d3538cb567d9b6035) [#221](https://github.com/npm/write-file-atomic/pull/221) bump @npmcli/eslint-config from 5.1.0 to 6.0.0 (#221) (@dependabot[bot])
* [`0c819a3`](https://github.com/npm/write-file-atomic/commit/0c819a347cada1c54065d41410cf683bc60ce3c5) [#223](https://github.com/npm/write-file-atomic/pull/223) bump @npmcli/template-oss from 4.28.0 to 4.28.1 (#223) (@dependabot[bot], @npm-cli-bot)
## [7.0.0](https://github.com/npm/write-file-atomic/compare/v6.0.0...v7.0.0) (2025-10-22)
### ⚠️ BREAKING CHANGES
* `write-file-atomic` now supports node `^20.17.0 || >=22.9.0`
### Bug Fixes
* [`05b67bd`](https://github.com/npm/write-file-atomic/commit/05b67bd54e8c7966619bd07a0d2eaca81261e034) [#219](https://github.com/npm/write-file-atomic/pull/219) align to npm 11 node engine range (#219) (@owlstronaut)
### Chores
* [`52d789d`](https://github.com/npm/write-file-atomic/commit/52d789d21905b83bcb3b93c7cd2750cdc82becc6) [#212](https://github.com/npm/write-file-atomic/pull/212) postinstall workflow updates (#212) (@owlstronaut)
* [`602f2ad`](https://github.com/npm/write-file-atomic/commit/602f2ad71ce4e08357286aa06a2619ce1746f12b) [#218](https://github.com/npm/write-file-atomic/pull/218) bump @npmcli/template-oss from 4.26.0 to 4.27.1 (#218) (@dependabot[bot], @npm-cli-bot)
## [6.0.0](https://github.com/npm/write-file-atomic/compare/v5.0.1...v6.0.0) (2024-09-24)
### ⚠️ BREAKING CHANGES
* `write-file-atomic` now supports node `^18.17.0 || >=20.5.0`
### Bug Fixes
* [`e4db381`](https://github.com/npm/write-file-atomic/commit/e4db381db11ad66e2eba47a801b5fe279923057f) [#208](https://github.com/npm/write-file-atomic/pull/208) align to npm 10 node engine range (@hashtagchris)
### Chores
* [`384ec4c`](https://github.com/npm/write-file-atomic/commit/384ec4c4008cf66b9863999c7b4e0554109968bc) [#208](https://github.com/npm/write-file-atomic/pull/208) run template-oss-apply (@hashtagchris)
* [`1a8883d`](https://github.com/npm/write-file-atomic/commit/1a8883d94a97bef3addf7d77300720f3aacfabbe) [#206](https://github.com/npm/write-file-atomic/pull/206) bump @npmcli/eslint-config from 4.0.5 to 5.0.0 (@dependabot[bot])
* [`73bddd9`](https://github.com/npm/write-file-atomic/commit/73bddd9db182f7a9ec1475a311c57844b4b3f05f) [#194](https://github.com/npm/write-file-atomic/pull/194) linting: no-unused-vars (@lukekarrys)
* [`4a16903`](https://github.com/npm/write-file-atomic/commit/4a169033af04227a898ac14cd90b3358a8d4d37e) [#194](https://github.com/npm/write-file-atomic/pull/194) bump @npmcli/template-oss to 4.22.0 (@lukekarrys)
* [`944e6c2`](https://github.com/npm/write-file-atomic/commit/944e6c2e9d01389514b540e4effa4cc1d786510a) [#207](https://github.com/npm/write-file-atomic/pull/207) postinstall for dependabot template-oss PR (@hashtagchris)
* [`c2c17b7`](https://github.com/npm/write-file-atomic/commit/c2c17b7a9297215cde6bb3c80691563193b986d3) [#207](https://github.com/npm/write-file-atomic/pull/207) bump @npmcli/template-oss from 4.23.1 to 4.23.3 (@dependabot[bot])
## [5.0.1](https://github.com/npm/write-file-atomic/compare/v5.0.0...v5.0.1) (2023-04-26)
### Dependencies
* [`a0daf64`](https://github.com/npm/write-file-atomic/commit/a0daf642b441f3026de36f8d10dae24e46b34f01) [#157](https://github.com/npm/write-file-atomic/pull/157) bump signal-exit from 3.0.7 to 4.0.1 (#157)
## [5.0.0](https://github.com/npm/write-file-atomic/compare/v4.0.2...v5.0.0) (2022-10-10)
### ⚠️ BREAKING CHANGES
* `write-file-atomic` is now compatible with the following semver range for node: `^14.17.0 || ^16.13.0 || >=18.0.0`
### Features
* [`5506c07`](https://github.com/npm/write-file-atomic/commit/5506c076c0421ef2e4ddfc4ee5ed2be5adc809e7) [#122](https://github.com/npm/write-file-atomic/pull/122) postinstall for dependabot template-oss PR (@lukekarrys)
## [4.0.2](https://github.com/npm/write-file-atomic/compare/v4.0.1...v4.0.2) (2022-08-16)
### Bug Fixes
* linting ([#111](https://github.com/npm/write-file-atomic/issues/111)) ([c8ef004](https://github.com/npm/write-file-atomic/commit/c8ef00406ff21056adae06a9b8186d37031d8a95))
### [4.0.1](https://www.github.com/npm/write-file-atomic/compare/v4.0.0...v4.0.1) (2022-02-09)
### Bug Fixes
* remove dupl check for typed arrays ([#96](https://www.github.com/npm/write-file-atomic/issues/96)) ([81a296d](https://www.github.com/npm/write-file-atomic/commit/81a296df8cbed750bc8b41d2b0d725a6a16361f7))
* remove is-typedarray and typedarray-to-buffer ([625526e](https://www.github.com/npm/write-file-atomic/commit/625526e1f190d2599a267839e995b768cf3f69b6))
### Dependencies
* update signal-exit requirement from ^3.0.2 to ^3.0.7 ([0b3ffdb](https://www.github.com/npm/write-file-atomic/commit/0b3ffdb4534b254ac5de8acf02e5b4591e2d92b4))
## [4.0.0](https://www.github.com/npm/write-file-atomic/compare/v3.0.3...v4.0.0) (2022-01-18)
### ⚠ BREAKING CHANGES
* This drops support for node10 and non-LTS versions of node12 and node14
### Bug Fixes
* move to template-oss ([266833d](https://www.github.com/npm/write-file-atomic/commit/266833d868b7626227d25dfbfa694798770bc811))
### dependencies
* typedarray-to-buffer@4.0.0 ([f36ff4f](https://www.github.com/npm/write-file-atomic/commit/f36ff4f5bc21178885f53768268fd9d8b0ba0729))
### Documentation
* **readme:** clean up API/usage syntax ([#90](https://www.github.com/npm/write-file-atomic/issues/90)) ([22c6990](https://www.github.com/npm/write-file-atomic/commit/22c6990a4ce08ddb3cd7e18837997c0acd81daac))
npm-write-file-atomic-f54fa15/CODE_OF_CONDUCT.md 0000664 0000000 0000000 00000000507 15150140533 0021036 0 ustar 00root root 0000000 0000000
All interactions in this repo are covered by the [npm Code of
Conduct](https://docs.npmjs.com/policies/conduct)
The npm cli team may, at its own discretion, moderate, remove, or edit
any interactions such as pull requests, issues, and comments.
npm-write-file-atomic-f54fa15/CONTRIBUTING.md 0000664 0000000 0000000 00000005133 15150140533 0020470 0 ustar 00root root 0000000 0000000
# Contributing
## Code of Conduct
All interactions in the **npm** organization on GitHub are considered to be covered by our standard [Code of Conduct](https://docs.npmjs.com/policies/conduct).
## Reporting Bugs
Before submitting a new bug report please search for an existing or similar report.
Use one of our existing issue templates if you believe you've come across a unique problem.
Duplicate issues, or issues that don't use one of our templates may get closed without a response.
## Pull Request Conventions
### Commits
We use [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/).
When opening a pull request please be sure that either the pull request title, or each commit in the pull request, has one of the following prefixes:
- `feat`: For when introducing a new feature. The result will be a new semver minor version of the package when it is next published.
- `fix`: For bug fixes. The result will be a new semver patch version of the package when it is next published.
- `docs`: For documentation updates. The result will be a new semver patch version of the package when it is next published.
- `chore`: For changes that do not affect the published module. Often these are changes to tests. The result will be *no* change to the version of the package when it is next published (as the commit does not affect the published version).
### Test Coverage
Pull requests made against this repo will run `npm test` automatically. Please make sure tests pass locally before submitting a PR.
Every new feature or bug fix should come with a corresponding test or tests that validate the solutions. Testing also reports on code coverage and will fail if code coverage drops.
### Linting
Linting is also done automatically once tests pass. `npm run lintfix` will fix most linting errors automatically.
Please make sure linting passes before submitting a PR.
## What _not_ to contribute?
### Dependencies
It should be noted that our team does not accept third-party dependency updates/PRs. If you submit a PR trying to update our dependencies we will close it with or without a reference to these contribution guidelines.
### Tools/Automation
Our core team is responsible for the maintenance of the tooling/automation in this project and we ask contributors to not make changes to these when contributing (e.g. `.github/*`, `.eslintrc.json`, `.licensee.json`). Most of those files also have a header at the top to remind folks they are automatically generated. Pull requests that alter these will not be accepted.
npm-write-file-atomic-f54fa15/LICENSE.md 0000664 0000000 0000000 00000001336 15150140533 0017644 0 ustar 00root root 0000000 0000000 Copyright (c) 2015, Rebecca Turner
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
npm-write-file-atomic-f54fa15/README.md 0000664 0000000 0000000 00000006355 15150140533 0017525 0 ustar 00root root 0000000 0000000 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).
### `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**
* chown **Object** default, uid & gid of existing file, if any
* uid **Number**
* gid **Number**
* encoding **String** | **Null** default = 'utf8'
* fsync **Boolean** default = true
* mode **Number** default, from existing file, if any
* tmpfileCreated **Function** called when the tmpfile is created
* callback **Function**
#### 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.
If writeFile completes successfully then, if passed the **chown** option it will change
the ownership of the file. Finally it renames the file back to the filename you specified. If
it encounters errors at any of these steps it will attempt to unlink the temporary file and then
pass the error back to the caller.
If multiple writes are concurrently issued to the same file, the write operations are put into a queue and serialized in the order they were called, using Promises. Writes to different files are still executed in parallel.
If provided, the **chown** option requires both **uid** and **gid** properties or else
you'll get an error. If **chown** is not specified it will default to using
the owner of the previous file. To prevent chown from being ran you can
also pass `false`, in which case the file will be created with the current user's credentials.
If **mode** is not specified, it will default to using the permissions from
an existing file, if any. Expicitly setting this to `false` remove this default, resulting
in a file created with the system default permissions.
If options is a String, it's assumed to be the **encoding** option. The **encoding** option is ignored if **data** is a buffer. It defaults to 'utf8'.
If the **fsync** option is **false**, writeFile will skip the final fsync call.
If the **tmpfileCreated** option is specified it will be called with the name of the tmpfile when created.
Example:
```javascript
writeFileAtomic('message.txt', 'Hello Node', {chown:{uid:100,gid:50}}, function (err) {
if (err) throw err;
console.log('It\'s saved!');
});
```
This function also supports async/await:
```javascript
(async () => {
try {
await writeFileAtomic('message.txt', 'Hello Node', {chown:{uid:100,gid:50}});
console.log('It\'s saved!');
} catch (err) {
console.error(err);
process.exit(1);
}
})();
```
### `writeFileAtomicSync(filename, data, [options])`
#### Description:
The synchronous version of **writeFileAtomic**.
#### Usage:
```js
var writeFileAtomicSync = require('write-file-atomic').sync
writeFileAtomicSync(filename, data, [options])
```
npm-write-file-atomic-f54fa15/SECURITY.md 0000664 0000000 0000000 00000002320 15150140533 0020023 0 ustar 00root root 0000000 0000000
GitHub takes the security of our software products and services seriously, including the open source code repositories managed through our GitHub organizations, such as [GitHub](https://github.com/GitHub).
If you believe you have found a security vulnerability in this GitHub-owned open source repository, you can report it to us in one of two ways.
If the vulnerability you have found is *not* [in scope for the GitHub Bug Bounty Program](https://bounty.github.com/#scope) or if you do not wish to be considered for a bounty reward, please report the issue to us directly through [opensource-security@github.com](mailto:opensource-security@github.com).
If the vulnerability you have found is [in scope for the GitHub Bug Bounty Program](https://bounty.github.com/#scope) and you would like for your finding to be considered for a bounty reward, please submit the vulnerability to us through [HackerOne](https://hackerone.com/github) in order to be eligible to receive a bounty award.
**Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.**
Thanks for helping make GitHub safe for everyone.
npm-write-file-atomic-f54fa15/docs/ 0000775 0000000 0000000 00000000000 15150140533 0017165 5 ustar 00root root 0000000 0000000 npm-write-file-atomic-f54fa15/docs/changelog-pre-4.0.0.md 0000664 0000000 0000000 00000001575 15150140533 0022667 0 ustar 00root root 0000000 0000000 # 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)
npm-write-file-atomic-f54fa15/lib/ 0000775 0000000 0000000 00000000000 15150140533 0017003 5 ustar 00root root 0000000 0000000 npm-write-file-atomic-f54fa15/lib/index.js 0000664 0000000 0000000 00000015222 15150140533 0020452 0 ustar 00root root 0000000 0000000 'use strict'
module.exports = writeFile
module.exports.sync = writeFileSync
module.exports._getTmpname = getTmpname // for testing
module.exports._cleanupOnExit = cleanupOnExit
const fs = require('fs')
const crypto = require('node:crypto')
const { onExit } = require('signal-exit')
const path = require('path')
const { promisify } = require('util')
const activeFiles = {}
// if we run inside of a worker_thread, `process.pid` is not unique
/* istanbul ignore next */
const threadId = (function getId () {
try {
const workerThreads = require('worker_threads')
/// if we are in main thread, this is set to `0`
return workerThreads.threadId
} catch (e) {
// worker_threads are not available, fallback to 0
return 0
}
})()
let invocations = 0
function getTmpname (filename) {
return filename + '.' +
crypto.createHash('sha1')
.update(__filename)
.update(String(process.pid))
.update(String(threadId))
.update(String(++invocations))
.digest()
.readUInt32BE(0)
}
function cleanupOnExit (tmpfile) {
return () => {
try {
fs.unlinkSync(typeof tmpfile === 'function' ? tmpfile() : tmpfile)
} catch {
// ignore errors
}
}
}
function serializeActiveFile (absoluteName) {
return new Promise(resolve => {
// make a queue if it doesn't already exist
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
})
}
// https://github.com/isaacs/node-graceful-fs/blob/master/polyfills.js#L315-L342
function isChownErrOk (err) {
if (err.code === 'ENOSYS') {
return true
}
const nonroot = !process.getuid || process.getuid() !== 0
if (nonroot) {
if (err.code === 'EINVAL' || err.code === 'EPERM') {
return true
}
}
return false
}
async function writeFileAsync (filename, data, options = {}) {
if (typeof options === 'string') {
options = { encoding: options }
}
let fd
let tmpfile
/* istanbul ignore next -- The closure only gets called when onExit triggers */
const removeOnExitHandler = onExit(cleanupOnExit(() => tmpfile))
const absoluteName = path.resolve(filename)
try {
await serializeActiveFile(absoluteName)
const truename = await promisify(fs.realpath)(filename).catch(() => filename)
tmpfile = getTmpname(truename)
if (!options.mode || !options.chown) {
// Either mode or chown is not explicitly set
// Default behavior is to copy it from original file
const stats = await promisify(fs.stat)(truename).catch(() => {})
if (stats) {
if (options.mode == null) {
options.mode = stats.mode
}
if (options.chown == null && process.getuid) {
options.chown = { uid: stats.uid, gid: stats.gid }
}
}
}
fd = await promisify(fs.open)(tmpfile, 'w', options.mode)
if (options.tmpfileCreated) {
await options.tmpfileCreated(tmpfile)
}
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'))
}
if (options.fsync !== false) {
await promisify(fs.fsync)(fd)
}
await promisify(fs.close)(fd)
fd = null
if (options.chown) {
await promisify(fs.chown)(tmpfile, options.chown.uid, options.chown.gid).catch(err => {
if (!isChownErrOk(err)) {
throw err
}
})
}
if (options.mode) {
await promisify(fs.chmod)(tmpfile, options.mode).catch(err => {
if (!isChownErrOk(err)) {
throw err
}
})
}
await promisify(fs.rename)(tmpfile, truename)
} finally {
if (fd) {
await promisify(fs.close)(fd).catch(
/* istanbul ignore next */
() => {}
)
}
removeOnExitHandler()
await promisify(fs.unlink)(tmpfile).catch(() => {})
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]
}
}
}
async function writeFile (filename, data, options, callback) {
if (options instanceof Function) {
callback = options
options = {}
}
const promise = writeFileAsync(filename, data, options)
if (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 = {}
}
try {
filename = fs.realpathSync(filename)
} catch (ex) {
// it's ok, it'll happen on a not yet existing file
}
const tmpfile = getTmpname(filename)
if (!options.mode || !options.chown) {
// Either mode or chown is not explicitly set
// Default behavior is to copy it from original file
try {
const stats = fs.statSync(filename)
options = Object.assign({}, options)
if (!options.mode) {
options.mode = stats.mode
}
if (!options.chown && process.getuid) {
options.chown = { uid: stats.uid, gid: stats.gid }
}
} catch (ex) {
// ignore stat errors
}
}
let fd
const cleanup = cleanupOnExit(tmpfile)
const removeOnExitHandler = onExit(cleanup)
let threw = true
try {
fd = fs.openSync(tmpfile, 'w', options.mode || 0o666)
if (options.tmpfileCreated) {
options.tmpfileCreated(tmpfile)
}
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'))
}
if (options.fsync !== false) {
fs.fsyncSync(fd)
}
fs.closeSync(fd)
fd = null
if (options.chown) {
try {
fs.chownSync(tmpfile, options.chown.uid, options.chown.gid)
} catch (err) {
if (!isChownErrOk(err)) {
throw err
}
}
}
if (options.mode) {
try {
fs.chmodSync(tmpfile, options.mode)
} catch (err) {
if (!isChownErrOk(err)) {
throw err
}
}
}
fs.renameSync(tmpfile, filename)
threw = false
} finally {
if (fd) {
try {
fs.closeSync(fd)
} catch (ex) {
// ignore close errors at this stage, error may have closed fd already.
}
}
removeOnExitHandler()
if (threw) {
cleanup()
}
}
}
npm-write-file-atomic-f54fa15/package.json 0000664 0000000 0000000 00000002544 15150140533 0020530 0 ustar 00root root 0000000 0000000 {
"name": "write-file-atomic",
"version": "7.0.1",
"description": "Write files in an atomic fashion w/configurable ownership",
"main": "./lib/index.js",
"scripts": {
"test": "tap",
"posttest": "npm run lint",
"lint": "npm run eslint",
"postlint": "template-oss-check",
"lintfix": "npm run eslint -- --fix",
"snap": "tap",
"template-oss-apply": "template-oss-apply --force",
"eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\""
},
"repository": {
"type": "git",
"url": "git+https://github.com/npm/write-file-atomic.git"
},
"keywords": [
"writeFile",
"atomic"
],
"author": "GitHub Inc.",
"license": "ISC",
"bugs": {
"url": "https://github.com/npm/write-file-atomic/issues"
},
"homepage": "https://github.com/npm/write-file-atomic",
"dependencies": {
"signal-exit": "^4.0.1"
},
"devDependencies": {
"@npmcli/eslint-config": "^6.0.0",
"@npmcli/template-oss": "4.28.1",
"tap": "^16.0.1"
},
"files": [
"bin/",
"lib/"
],
"engines": {
"node": "^20.17.0 || >=22.9.0"
},
"templateOSS": {
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
"windowsCI": false,
"version": "4.28.1",
"publish": "true"
},
"tap": {
"nyc-arg": [
"--exclude",
"tap-snapshots/**"
]
}
}
npm-write-file-atomic-f54fa15/release-please-config.json 0000664 0000000 0000000 00000001277 15150140533 0023271 0 ustar 00root root 0000000 0000000 {
"group-pull-request-title-pattern": "chore: release ${version}",
"pull-request-title-pattern": "chore: release${component} ${version}",
"changelog-sections": [
{
"type": "feat",
"section": "Features",
"hidden": false
},
{
"type": "fix",
"section": "Bug Fixes",
"hidden": false
},
{
"type": "docs",
"section": "Documentation",
"hidden": false
},
{
"type": "deps",
"section": "Dependencies",
"hidden": false
},
{
"type": "chore",
"section": "Chores",
"hidden": true
}
],
"packages": {
".": {
"package-name": ""
}
},
"prerelease-type": "pre.0"
}
npm-write-file-atomic-f54fa15/test/ 0000775 0000000 0000000 00000000000 15150140533 0017214 5 ustar 00root root 0000000 0000000 npm-write-file-atomic-f54fa15/test/basic.js 0000664 0000000 0000000 00000031232 15150140533 0020634 0 ustar 00root root 0000000 0000000 'use strict'
const t = require('tap')
let expectClose = 0
let closeCalled = 0
let expectCloseSync = 0
let closeSyncCalled = 0
const createErr = code => Object.assign(new Error(code), { code })
let unlinked = []
const writeFileAtomic = t.mock('..', {
fs: {
realpath (filename, cb) {
return cb(null, filename)
},
open (tmpfile, options, mode, cb) {
if (/noopen/.test(tmpfile)) {
return cb(createErr('ENOOPEN'))
}
expectClose++
cb(null, tmpfile)
},
write (fd) {
const cb = arguments[arguments.length - 1]
if (/nowrite/.test(fd)) {
return cb(createErr('ENOWRITE'))
}
cb()
},
fsync (fd, cb) {
if (/nofsync/.test(fd)) {
return cb(createErr('ENOFSYNC'))
}
cb()
},
close (fd, cb) {
closeCalled++
cb()
},
chown (tmpfile, uid, gid, cb) {
if (/nochown/.test(tmpfile)) {
return cb(createErr('ENOCHOWN'))
}
if (/enosys/.test(tmpfile)) {
return cb(createErr('ENOSYS'))
}
if (/einval/.test(tmpfile)) {
return cb(createErr('EINVAL'))
}
if (/eperm/.test(tmpfile)) {
return cb(createErr('EPERM'))
}
cb()
},
chmod (tmpfile, mode, cb) {
if (/nochmod/.test(tmpfile)) {
return cb(createErr('ENOCHMOD'))
}
if (/enosys/.test(tmpfile)) {
return cb(createErr('ENOSYS'))
}
if (/eperm/.test(tmpfile)) {
return cb(createErr('EPERM'))
}
if (/einval/.test(tmpfile)) {
return cb(createErr('EINVAL'))
}
cb()
},
rename (tmpfile, filename, cb) {
if (/norename/.test(tmpfile)) {
return cb(createErr('ENORENAME'))
}
cb()
},
unlink (tmpfile, cb) {
if (/nounlink/.test(tmpfile)) {
return cb(createErr('ENOUNLINK'))
}
cb()
},
stat (tmpfile, cb) {
if (/nostat/.test(tmpfile)) {
return cb(createErr('ENOSTAT'))
}
cb()
},
realpathSync (filename) {
return filename
},
openSync (tmpfile) {
if (/noopen/.test(tmpfile)) {
throw createErr('ENOOPEN')
}
expectCloseSync++
return tmpfile
},
writeSync (fd) {
if (/nowrite/.test(fd)) {
throw createErr('ENOWRITE')
}
},
fsyncSync (fd) {
if (/nofsync/.test(fd)) {
throw createErr('ENOFSYNC')
}
},
closeSync () {
closeSyncCalled++
},
chownSync (tmpfile) {
if (/nochown/.test(tmpfile)) {
throw createErr('ENOCHOWN')
}
if (/enosys/.test(tmpfile)) {
throw createErr('ENOSYS')
}
if (/einval/.test(tmpfile)) {
throw createErr('EINVAL')
}
if (/eperm/.test(tmpfile)) {
throw createErr('EPERM')
}
},
chmodSync (tmpfile) {
if (/nochmod/.test(tmpfile)) {
throw createErr('ENOCHMOD')
}
if (/enosys/.test(tmpfile)) {
throw createErr('ENOSYS')
}
if (/einval/.test(tmpfile)) {
throw createErr('EINVAL')
}
if (/eperm/.test(tmpfile)) {
throw createErr('EPERM')
}
},
renameSync (tmpfile) {
if (/norename/.test(tmpfile)) {
throw createErr('ENORENAME')
}
},
unlinkSync (tmpfile) {
if (/nounlink/.test(tmpfile)) {
throw createErr('ENOUNLINK')
}
unlinked.push(tmpfile)
},
statSync (tmpfile) {
if (/nostat/.test(tmpfile)) {
throw createErr('ENOSTAT')
}
},
},
})
const writeFileAtomicSync = writeFileAtomic.sync
t.test('getTmpname', t => {
const getTmpname = writeFileAtomic._getTmpname
const a = getTmpname('abc.def')
const b = getTmpname('abc.def')
t.not(a, b, 'different invocations of getTmpname get different results')
t.end()
})
t.test('cleanupOnExit', t => {
const file = 'tmpname'
unlinked = []
const cleanup = writeFileAtomic._cleanupOnExit(() => file)
cleanup()
t.strictSame(unlinked, [file], 'cleanup code unlinks')
const cleanup2 = writeFileAtomic._cleanupOnExit('nounlink')
t.doesNotThrow(cleanup2, 'exceptions are caught')
unlinked = []
t.end()
})
t.test('async tests', t => {
t.plan(2)
expectClose = 0
closeCalled = 0
t.teardown(() => {
t.parent.equal(closeCalled, expectClose, 'async tests closed all files')
expectClose = 0
closeCalled = 0
})
t.test('non-root tests', t => {
t.plan(19)
writeFileAtomic('good', 'test', { mode: '0777' }, err => {
t.notOk(err, 'No errors occur when passing in options')
})
writeFileAtomic('good', 'test', 'utf8', err => {
t.notOk(err, 'No errors occur when passing in options as string')
})
writeFileAtomic('good', 'test', undefined, err => {
t.notOk(err, 'No errors occur when NOT passing in options')
})
writeFileAtomic('good', 'test', err => {
t.notOk(err)
})
writeFileAtomic('noopen', 'test', err => {
t.equal(err && err.message, 'ENOOPEN', 'fs.open failures propagate')
})
writeFileAtomic('nowrite', 'test', err => {
t.equal(err && err.message, 'ENOWRITE', 'fs.writewrite failures propagate')
})
writeFileAtomic('nowrite', Buffer.from('test', 'utf8'), err => {
t.equal(err && err.message, 'ENOWRITE', 'fs.writewrite failures propagate for buffers')
})
writeFileAtomic('nochown', 'test', { chown: { uid: 100, gid: 100 } }, err => {
t.equal(err && err.message, 'ENOCHOWN', 'Chown failures propagate')
})
writeFileAtomic('nochown', 'test', err => {
t.notOk(err, 'No attempt to chown when no uid/gid passed in')
})
writeFileAtomic('nochmod', 'test', { mode: parseInt('741', 8) }, err => {
t.equal(err && err.message, 'ENOCHMOD', 'Chmod failures propagate')
})
writeFileAtomic('nofsyncopt', 'test', { fsync: false }, err => {
t.notOk(err, 'fsync skipped if options.fsync is false')
})
writeFileAtomic('norename', 'test', err => {
t.equal(err && err.message, 'ENORENAME', 'Rename errors propagate')
})
writeFileAtomic('norename nounlink', 'test', err => {
t.equal(err && err.message, 'ENORENAME',
'Failure to unlink the temp file does not clobber the original error')
})
writeFileAtomic('nofsync', 'test', err => {
t.equal(err && err.message, 'ENOFSYNC', 'Fsync failures propagate')
})
writeFileAtomic('enosys', 'test', err => {
t.notOk(err, 'No errors on ENOSYS')
})
writeFileAtomic('einval', 'test', { mode: 0o741 }, err => {
t.notOk(err, 'No errors on EINVAL for non root')
})
writeFileAtomic('eperm', 'test', { mode: 0o741 }, err => {
t.notOk(err, 'No errors on EPERM for non root')
})
writeFileAtomic('einval', 'test', { chown: { uid: 100, gid: 100 } }, err => {
t.notOk(err, 'No errors on EINVAL for non root')
})
writeFileAtomic('eperm', 'test', { chown: { uid: 100, gid: 100 } }, err => {
t.notOk(err, 'No errors on EPERM for non root')
})
})
t.test('errors for root', t => {
const { getuid } = process
process.getuid = () => 0
t.teardown(() => {
process.getuid = getuid
})
t.plan(2)
writeFileAtomic('einval', 'test', { chown: { uid: 100, gid: 100 } }, err => {
t.match(err, { code: 'EINVAL' })
})
writeFileAtomic('einval', 'test', { mode: 0o741 }, err => {
t.match(err, { code: 'EINVAL' })
})
})
})
t.test('sync tests', t => {
t.plan(2)
closeSyncCalled = 0
expectCloseSync = 0
t.teardown(() => {
t.parent.equal(closeSyncCalled, expectCloseSync, 'sync closed all files')
expectCloseSync = 0
closeSyncCalled = 0
})
const throws = function (t, shouldthrow, msg, todo) {
let err
try {
todo()
} catch (e) {
err = e
}
t.equal(shouldthrow, err && err.message, msg)
}
const noexception = function (t, msg, todo) {
let err
try {
todo()
} catch (e) {
err = e
}
t.error(err, msg)
}
let tmpfile
t.test('non-root', t => {
t.plan(22)
noexception(t, 'No errors occur when passing in options', () => {
writeFileAtomicSync('good', 'test', { mode: '0777' })
})
noexception(t, 'No errors occur when passing in options as string', () => {
writeFileAtomicSync('good', 'test', 'utf8')
})
noexception(t, 'No errors occur when NOT passing in options', () => {
writeFileAtomicSync('good', 'test')
})
noexception(t, 'fsync never called if options.fsync is falsy', () => {
writeFileAtomicSync('good', 'test', { fsync: false })
})
noexception(t, 'tmpfileCreated is called on success', () => {
writeFileAtomicSync('good', 'test', {
tmpfileCreated (gottmpfile) {
tmpfile = gottmpfile
},
})
t.match(tmpfile, /^good\.\d+$/, 'tmpfileCreated called for success')
})
tmpfile = undefined
throws(t, 'ENOOPEN', 'fs.openSync failures propagate', () => {
writeFileAtomicSync('noopen', 'test', {
tmpfileCreated (gottmpfile) {
tmpfile = gottmpfile
},
})
})
t.equal(tmpfile, undefined, 'tmpfileCreated not called for open failure')
throws(t, 'ENOWRITE', 'fs.writeSync failures propagate', () => {
writeFileAtomicSync('nowrite', 'test', {
tmpfileCreated (gottmpfile) {
tmpfile = gottmpfile
},
})
})
t.match(tmpfile, /^nowrite\.\d+$/, 'tmpfileCreated called for failure after open')
throws(t, 'ENOCHOWN', 'Chown failures propagate', () => {
writeFileAtomicSync('nochown', 'test', { chown: { uid: 100, gid: 100 } })
})
noexception(t, 'No attempt to chown when false passed in', () => {
writeFileAtomicSync('nochown', 'test', { chown: false })
})
noexception(t, 'No errors occured when chown is undefined and original file owner used', () => {
writeFileAtomicSync('chowncopy', 'test', { chown: undefined })
})
throws(t, 'ENORENAME', 'Rename errors propagate', () => {
writeFileAtomicSync('norename', 'test')
})
throws(t, 'ENORENAME',
'Failure to unlink the temp file does not clobber the original error', () => {
writeFileAtomicSync('norename nounlink', 'test')
})
throws(t, 'ENOFSYNC', 'Fsync errors propagate', () => {
writeFileAtomicSync('nofsync', 'test')
})
noexception(t, 'No errors on ENOSYS', () => {
writeFileAtomicSync('enosys', 'test', { chown: { uid: 100, gid: 100 } })
})
noexception(t, 'No errors on EINVAL for non root', () => {
writeFileAtomicSync('einval', 'test', { chown: { uid: 100, gid: 100 } })
})
noexception(t, 'No errors on EPERM for non root', () => {
writeFileAtomicSync('eperm', 'test', { chown: { uid: 100, gid: 100 } })
})
throws(t, 'ENOCHMOD', 'Chmod failures propagate', () => {
writeFileAtomicSync('nochmod', 'test', { mode: 0o741 })
})
noexception(t, 'No errors on EPERM for non root', () => {
writeFileAtomicSync('eperm', 'test', { mode: 0o741 })
})
noexception(t, 'No attempt to chmod when no mode provided', () => {
writeFileAtomicSync('nochmod', 'test', { mode: false })
})
})
t.test('errors for root', t => {
const { getuid } = process
process.getuid = () => 0
t.teardown(() => {
process.getuid = getuid
})
t.plan(2)
throws(t, 'EINVAL', 'Chown error as root user', () => {
writeFileAtomicSync('einval', 'test', { chown: { uid: 100, gid: 100 } })
})
throws(t, 'EINVAL', 'Chmod error as root user', () => {
writeFileAtomicSync('einval', 'test', { mode: 0o741 })
})
})
})
t.test('promises', async t => {
let tmpfile
closeCalled = 0
expectClose = 0
t.teardown(() => {
t.parent.equal(closeCalled, expectClose, 'promises closed all files')
closeCalled = 0
expectClose = 0
})
await writeFileAtomic('good', 'test', {
tmpfileCreated (gottmpfile) {
tmpfile = gottmpfile
},
})
t.match(tmpfile, /^good\.\d+$/, 'tmpfileCreated is called for success')
await writeFileAtomic('good', 'test', {
tmpfileCreated () {
return Promise.resolve()
},
})
await t.rejects(writeFileAtomic('good', 'test', {
tmpfileCreated () {
return Promise.reject(new Error('reject from tmpfileCreated'))
},
}))
await t.rejects(writeFileAtomic('good', 'test', {
tmpfileCreated () {
throw new Error('throw from tmpfileCreated')
},
}))
tmpfile = undefined
await t.rejects(writeFileAtomic('noopen', 'test', {
tmpfileCreated (gottmpfile) {
tmpfile = gottmpfile
},
}))
t.equal(tmpfile, undefined, 'tmpfileCreated is not called on open failure')
await t.rejects(writeFileAtomic('nowrite', 'test', {
tmpfileCreated (gottmpfile) {
tmpfile = gottmpfile
},
}))
t.match(tmpfile, /^nowrite\.\d+$/, 'tmpfileCreated is called if failure is after open')
})
npm-write-file-atomic-f54fa15/test/concurrency.js 0000664 0000000 0000000 00000010320 15150140533 0022100 0 ustar 00root root 0000000 0000000 'use strict'
const t = require('tap')
// defining mock for fs so its functions can be modified
const fs = {
realpath (filename, cb) {
return cb(null, filename)
},
open (tmpfile, options, mode, cb) {
if (/noopen/.test(tmpfile)) {
return cb(new Error('ENOOPEN'))
}
cb(null, tmpfile)
},
write (fd) {
const cb = arguments[arguments.length - 1]
if (/nowrite/.test(fd)) {
return cb(new Error('ENOWRITE'))
}
cb()
},
fsync (fd, cb) {
if (/nofsync/.test(fd)) {
return cb(new Error('ENOFSYNC'))
}
cb()
},
close (fd, cb) {
cb()
},
chown (tmpfile, uid, gid, cb) {
if (/nochown/.test(tmpfile)) {
return cb(new Error('ENOCHOWN'))
}
cb()
},
chmod (tmpfile, mode, cb) {
if (/nochmod/.test(tmpfile)) {
return cb(new Error('ENOCHMOD'))
}
cb()
},
rename (tmpfile, filename, cb) {
if (/norename/.test(tmpfile)) {
return cb(new Error('ENORENAME'))
}
cb()
},
unlink (tmpfile, cb) {
if (/nounlink/.test(tmpfile)) {
return cb(new Error('ENOUNLINK'))
}
cb()
},
stat (tmpfile, cb) {
if (/nostat/.test(tmpfile)) {
return cb(new Error('ENOSTAT'))
}
cb()
},
realpathSync (filename) {
return filename
},
openSync (tmpfile) {
if (/noopen/.test(tmpfile)) {
throw new Error('ENOOPEN')
}
return tmpfile
},
writeSync (fd) {
if (/nowrite/.test(fd)) {
throw new Error('ENOWRITE')
}
},
fsyncSync (fd) {
if (/nofsync/.test(fd)) {
throw new Error('ENOFSYNC')
}
},
closeSync () { },
chownSync (tmpfile) {
if (/nochown/.test(tmpfile)) {
throw new Error('ENOCHOWN')
}
},
chmodSync (tmpfile) {
if (/nochmod/.test(tmpfile)) {
throw new Error('ENOCHMOD')
}
},
renameSync (tmpfile) {
if (/norename/.test(tmpfile)) {
throw new Error('ENORENAME')
}
},
unlinkSync (tmpfile) {
if (/nounlink/.test(tmpfile)) {
throw new Error('ENOUNLINK')
}
},
statSync (tmpfile) {
if (/nostat/.test(tmpfile)) {
throw new Error('ENOSTAT')
}
},
}
const writeFileAtomic = t.mock('..', {
fs: fs,
})
// preserve original functions
const oldRealPath = fs.realpath
const oldRename = fs.rename
t.test('ensure writes to the same file are serial', t => {
let fileInUse = false
const ops = 5 // count for how many concurrent write ops to request
t.plan(ops * 3 + 3)
fs.realpath = (...args) => {
t.notOk(fileInUse, 'file not in use')
fileInUse = true
oldRealPath(...args)
}
fs.rename = (...args) => {
t.ok(fileInUse, 'file in use')
fileInUse = false
oldRename(...args)
}
for (let i = 0; i < ops; i++) {
writeFileAtomic('test', 'test', err => {
if (err) {
t.fail(err)
} else {
t.pass('wrote without error')
}
})
}
setTimeout(() => {
writeFileAtomic('test', 'test', err => {
if (err) {
t.fail(err)
} else {
t.pass('successive writes after delay')
}
})
}, 500)
})
t.test('allow write to multiple files in parallel, but same file writes are serial', t => {
const filesInUse = []
const ops = 5
let wasParallel = false
fs.realpath = (filename, ...args) => {
filesInUse.push(filename)
const firstOccurence = filesInUse.indexOf(filename)
// check for another occurence after the first
t.equal(filesInUse.indexOf(filename, firstOccurence + 1), -1, 'serial writes')
if (filesInUse.length > 1) {
wasParallel = true
} // remember that a parallel operation took place
oldRealPath(filename, ...args)
}
fs.rename = (filename, ...args) => {
filesInUse.splice(filesInUse.indexOf(filename), 1)
oldRename(filename, ...args)
}
t.plan(ops * 2 * 2 + 1)
let opCount = 0
for (let i = 0; i < ops; i++) {
writeFileAtomic('test', 'test', err => {
if (err) {
t.fail(err, 'wrote without error')
} else {
t.pass('wrote without error')
}
})
writeFileAtomic('test2', 'test', err => {
opCount++
if (opCount === ops) {
t.ok(wasParallel, 'parallel writes')
}
if (err) {
t.fail(err, 'wrote without error')
} else {
t.pass('wrote without error')
}
})
}
})
npm-write-file-atomic-f54fa15/test/integration.js 0000664 0000000 0000000 00000021011 15150140533 0022070 0 ustar 00root root 0000000 0000000 'use strict'
const fs = require('fs')
const path = require('path')
const t = require('tap')
const workdir = path.join(__dirname, path.basename(__filename, '.js'))
let testfiles = 0
function tmpFile () {
return path.join(workdir, 'test-' + (++testfiles))
}
function readFile (p) {
return fs.readFileSync(p).toString()
}
function didWriteFileAtomic (t, expected, filename, data, options, callback) {
if (options instanceof Function) {
callback = options
options = null
}
if (!options) {
options = {}
}
const actual = {}
const writeFileAtomic = t.mock('..', {
fs: Object.assign({}, fs, {
chown (chownFilename, uid, gid, cb) {
actual.uid = uid
actual.gid = gid
process.nextTick(cb)
},
stat (statFilename, cb) {
fs.stat(statFilename, (err, stats) => {
if (err) {
return cb(err)
}
cb(null, Object.assign(stats, expected || {}))
})
},
}),
})
return writeFileAtomic(filename, data, options, err => {
t.strictSame(actual, expected, 'ownership is as expected')
callback(err)
})
}
function didWriteFileAtomicSync (t, expected, filename, data, options) {
const actual = {}
const writeFileAtomic = t.mock('..', {
fs: Object.assign({}, fs, {
chownSync (chownFilename, uid, gid) {
actual.uid = uid
actual.gid = gid
},
statSync (statFilename) {
const stats = fs.statSync(statFilename)
return Object.assign(stats, expected || {})
},
}),
})
writeFileAtomic.sync(filename, data, options)
t.strictSame(actual, expected)
}
function currentUser () {
return {
uid: process.getuid(),
gid: process.getgid(),
}
}
t.test('setup', t => {
fs.rmSync(workdir, { recursive: true, force: true })
fs.mkdirSync(workdir, { recursive: true })
t.end()
})
t.test('writes simple file (async)', t => {
t.plan(3)
const file = tmpFile()
didWriteFileAtomic(t, {}, file, '42', err => {
t.error(err, 'no error')
t.equal(readFile(file), '42', 'content ok')
})
})
t.test('writes simple file with encoding (async)', t => {
t.plan(3)
const file = tmpFile()
didWriteFileAtomic(t, {}, file, 'foo', 'utf16le', err => {
t.error(err, 'no error')
t.equal(readFile(file), 'f\u0000o\u0000o\u0000', 'content ok')
})
})
t.test('writes buffers to simple file (async)', t => {
t.plan(3)
const file = tmpFile()
didWriteFileAtomic(t, {}, file, Buffer.from('42'), err => {
t.error(err, 'no error')
t.equal(readFile(file), '42', 'content ok')
})
})
t.test('writes TypedArray to simple file (async)', t => {
t.plan(3)
const file = tmpFile()
didWriteFileAtomic(t, {}, file, new Uint8Array([0x34, 0x32]), err => {
t.error(err, 'no error')
t.equal(readFile(file), '42', 'content ok')
})
})
t.test('writes undefined to simple file (async)', t => {
t.plan(3)
const file = tmpFile()
didWriteFileAtomic(t, {}, file, undefined, err => {
t.error(err, 'no error')
t.equal(readFile(file), '', 'content ok')
})
})
t.test('writes to symlinks without clobbering (async)', t => {
t.plan(5)
const file = tmpFile()
const link = tmpFile()
fs.writeFileSync(file, '42')
fs.symlinkSync(file, link)
didWriteFileAtomic(t, currentUser(), link, '43', err => {
t.error(err, 'no error')
t.equal(readFile(file), '43', 'target content ok')
t.equal(readFile(link), '43', 'link content ok')
t.ok(fs.lstatSync(link).isSymbolicLink(), 'link is link')
})
})
t.test('runs chown on given file (async)', t => {
const file = tmpFile()
didWriteFileAtomic(t, { uid: 42, gid: 43 }, file, '42', { chown: { uid: 42, gid: 43 } }, err => {
t.error(err, 'no error')
t.equal(readFile(file), '42', 'content ok')
t.end()
})
})
t.test('writes simple file with no chown (async)', t => {
t.plan(3)
const file = tmpFile()
didWriteFileAtomic(t, {}, file, '42', { chown: false }, err => {
t.error(err, 'no error')
t.equal(readFile(file), '42', 'content ok')
t.end()
})
})
t.test('runs chmod on given file (async)', t => {
t.plan(5)
const file = tmpFile()
didWriteFileAtomic(t, {}, file, '42', { mode: parseInt('741', 8) }, err => {
t.error(err, 'no error')
const stat = fs.statSync(file)
t.equal(stat.mode, parseInt('100741', 8))
didWriteFileAtomic(t, { uid: 42, gid: 43 }, file, '23',
{ chown: { uid: 42, gid: 43 } }, chownErr => {
t.error(chownErr, 'no error')
})
})
})
t.test('run chmod AND chown (async)', t => {
t.plan(3)
const file = tmpFile()
didWriteFileAtomic(t, { uid: 42, gid: 43 }, file, '42',
{ mode: parseInt('741', 8), chown: { uid: 42, gid: 43 } }, err => {
t.error(err, 'no error')
const stat = fs.statSync(file)
t.equal(stat.mode, parseInt('100741', 8))
})
})
t.test('does not change chmod by default (async)', t => {
t.plan(5)
const file = tmpFile()
didWriteFileAtomic(t, {}, file, '42', { mode: parseInt('741', 8) }, err => {
t.error(err, 'no error')
didWriteFileAtomic(t, currentUser(), file, '43', writeFileError => {
t.error(writeFileError, 'no error')
const stat = fs.statSync(file)
t.equal(stat.mode, parseInt('100741', 8))
})
})
})
t.test('does not change chown by default (async)', t => {
t.plan(6)
const file = tmpFile()
didWriteFileAtomic(t, { uid: 42, gid: 43 }, file, '42',
{ chown: { uid: 42, gid: 43 } }, _setModeOnly)
function _setModeOnly (err) {
t.error(err, 'no error')
didWriteFileAtomic(t, { uid: 42, gid: 43 }, file, '43',
{ mode: parseInt('741', 8) }, _allDefault)
}
function _allDefault (err) {
t.error(err, 'no error')
didWriteFileAtomic(t, { uid: 42, gid: 43 }, file, '43', _noError)
}
function _noError (err) {
t.error(err, 'no error')
}
})
t.test('writes simple file (sync)', t => {
t.plan(2)
const file = tmpFile()
didWriteFileAtomicSync(t, {}, file, '42')
t.equal(readFile(file), '42')
})
t.test('writes simple file with encoding (sync)', t => {
t.plan(2)
const file = tmpFile()
didWriteFileAtomicSync(t, {}, file, 'foo', 'utf16le')
t.equal(readFile(file), 'f\u0000o\u0000o\u0000')
})
t.test('writes simple buffer file (sync)', t => {
t.plan(2)
const file = tmpFile()
didWriteFileAtomicSync(t, {}, file, Buffer.from('42'))
t.equal(readFile(file), '42')
})
t.test('writes simple TypedArray file (sync)', t => {
t.plan(2)
const file = tmpFile()
didWriteFileAtomicSync(t, {}, file, new Uint8Array([0x34, 0x32]))
t.equal(readFile(file), '42')
})
t.test('writes undefined file (sync)', t => {
t.plan(2)
const file = tmpFile()
didWriteFileAtomicSync(t, {}, file, undefined)
t.equal(readFile(file), '')
})
t.test('writes to symlinks without clobbering (sync)', t => {
t.plan(4)
const file = tmpFile()
const link = tmpFile()
fs.writeFileSync(file, '42')
fs.symlinkSync(file, link)
didWriteFileAtomicSync(t, currentUser(), link, '43')
t.equal(readFile(file), '43', 'target content ok')
t.equal(readFile(link), '43', 'link content ok')
t.ok(fs.lstatSync(link).isSymbolicLink(), 'link is link')
})
t.test('runs chown on given file (sync)', t => {
t.plan(1)
const file = tmpFile()
didWriteFileAtomicSync(t, { uid: 42, gid: 43 }, file, '42', { chown: { uid: 42, gid: 43 } })
})
t.test('runs chmod on given file (sync)', t => {
t.plan(3)
const file = tmpFile()
didWriteFileAtomicSync(t, {}, file, '42', { mode: parseInt('741', 8) })
const stat = fs.statSync(file)
t.equal(stat.mode, parseInt('100741', 8))
didWriteFileAtomicSync(t, { uid: 42, gid: 43 }, file, '23', { chown: { uid: 42, gid: 43 } })
})
t.test('runs chown and chmod (sync)', t => {
t.plan(2)
const file = tmpFile()
didWriteFileAtomicSync(t, { uid: 42, gid: 43 }, file, '42',
{ mode: parseInt('741', 8), chown: { uid: 42, gid: 43 } })
const stat = fs.statSync(file)
t.equal(stat.mode, parseInt('100741', 8))
})
t.test('does not change chmod by default (sync)', t => {
t.plan(3)
const file = tmpFile()
didWriteFileAtomicSync(t, {}, file, '42', { mode: parseInt('741', 8) })
didWriteFileAtomicSync(t, currentUser(), file, '43')
const stat = fs.statSync(file)
t.equal(stat.mode, parseInt('100741', 8))
})
t.test('does not change chown by default (sync)', t => {
t.plan(3)
const file = tmpFile()
didWriteFileAtomicSync(t, { uid: 42, gid: 43 }, file, '42', { chown: { uid: 42, gid: 43 } })
didWriteFileAtomicSync(t, { uid: 42, gid: 43 }, file, '43', { mode: parseInt('741', 8) })
didWriteFileAtomicSync(t, { uid: 42, gid: 43 }, file, '44')
})
t.test('cleanup', t => {
fs.rmSync(workdir, { recursive: true, force: true })
t.end()
})