pax_global_header00006660000000000000000000000064150764617610014527gustar00rootroot0000000000000052 comment=b473b1578b8506d0dee9eab2f0e547296c4de5d3 npm-fs-b473b15/000077500000000000000000000000001507646176100132605ustar00rootroot00000000000000npm-fs-b473b15/.commitlintrc.js000066400000000000000000000005661507646176100164070ustar00rootroot00000000000000/* 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-fs-b473b15/.eslintrc.js000066400000000000000000000006231507646176100155200ustar00rootroot00000000000000/* 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-fs-b473b15/.github/000077500000000000000000000000001507646176100146205ustar00rootroot00000000000000npm-fs-b473b15/.github/CODEOWNERS000066400000000000000000000001321507646176100162070ustar00rootroot00000000000000# This file is automatically added by @npmcli/template-oss. Do not edit. * @npm/cli-team npm-fs-b473b15/.github/ISSUE_TEMPLATE/000077500000000000000000000000001507646176100170035ustar00rootroot00000000000000npm-fs-b473b15/.github/ISSUE_TEMPLATE/bug.yml000066400000000000000000000026551507646176100203130ustar00rootroot00000000000000# 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-fs-b473b15/.github/ISSUE_TEMPLATE/config.yml����������������������������������������������������0000664�0000000�0000000�00000000145�15076461761�0020773�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# This file is automatically added by @npmcli/template-oss. Do not edit. blank_issues_enabled: true ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/.github/actions/���������������������������������������������������������������������0000775�0000000�0000000�00000000000�15076461761�0016260�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/.github/actions/create-check/��������������������������������������������������������0000775�0000000�0000000�00000000000�15076461761�0020576�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/.github/actions/create-check/action.yml����������������������������������������������0000664�0000000�0000000�00000002720�15076461761�0022577�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-fs-b473b15/.github/actions/install-latest-npm/��������������������������������������������������0000775�0000000�0000000�00000000000�15076461761�0022010�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/.github/actions/install-latest-npm/action.yml����������������������������������������0000664�0000000�0000000�00000003406�15076461761�0024013�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-fs-b473b15/.github/dependabot.yml���������������������������������������������������������������0000664�0000000�0000000�00000000656�15076461761�0017457�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-fs-b473b15/.github/matchers/��������������������������������������������������������������������0000775�0000000�0000000�00000000000�15076461761�0016426�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/.github/matchers/tap.json������������������������������������������������������������0000664�0000000�0000000�00000001204�15076461761�0020102�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-fs-b473b15/.github/settings.yml�����������������������������������������������������������������0000664�0000000�0000000�00000001377�15076461761�0017213�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-fs-b473b15/.github/workflows/�������������������������������������������������������������������0000775�0000000�0000000�00000000000�15076461761�0016655�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/.github/workflows/audit.yml����������������������������������������������������������0000664�0000000�0000000�00000002275�15076461761�0020514�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-fs-b473b15/.github/workflows/ci-release.yml�����������������������������������������������������0000664�0000000�0000000�00000010707�15076461761�0021416�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 - name: Windows os: windows-latest shell: cmd 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-fs-b473b15/.github/workflows/ci.yml�������������������������������������������������������������0000664�0000000�0000000�00000006141�15076461761�0017775�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 - name: Windows os: windows-latest shell: cmd 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-fs-b473b15/.github/workflows/codeql-analysis.yml������������������������������������������������0000664�0000000�0000000�00000001606�15076461761�0022473�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-fs-b473b15/.github/workflows/post-dependabot.yml������������������������������������������������0000664�0000000�0000000�00000012004�15076461761�0022465�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-fs-b473b15/.github/workflows/pull-request.yml���������������������������������������������������0000664�0000000�0000000�00000002737�15076461761�0022053�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-fs-b473b15/.github/workflows/release-integration.yml��������������������������������������������0000664�0000000�0000000�00000004163�15076461761�0023345�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-fs-b473b15/.github/workflows/release.yml��������������������������������������������������������0000664�0000000�0000000�00000026106�15076461761�0021025�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-fs-b473b15/.gitignore���������������������������������������������������������������������������0000664�0000000�0000000�00000001050�15076461761�0015244�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-fs-b473b15/.npmrc�������������������������������������������������������������������������������0000664�0000000�0000000�00000000135�15076461761�0014377�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������; This file is automatically added by @npmcli/template-oss. Do not edit. package-lock=false �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/.release-please-manifest.json��������������������������������������������������������0000664�0000000�0000000�00000000023�15076461761�0020717�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ ".": "5.0.0" } �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/CHANGELOG.md�������������������������������������������������������������������������0000664�0000000�0000000�00000014353�15076461761�0015077�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# Changelog ## [5.0.0](https://github.com/npm/fs/compare/v4.0.0...v5.0.0) (2025-10-23) ### ⚠️ BREAKING CHANGES * `@npmcli/fs` now supports node `^20.17.0 || >=22.9.0` ### Bug Fixes * [`f3b5996`](https://github.com/npm/fs/commit/f3b5996ae144c740c2238f5bb4960d9df896e242) [#133](https://github.com/npm/fs/pull/133) align to npm 11 node engine range (@owlstronaut) ### Chores * [`397d379`](https://github.com/npm/fs/commit/397d379a24aee08cb5e248c5294aec77f40411b4) [#135](https://github.com/npm/fs/pull/135) align tests with nodejs behavior change (@owlstronaut) * [`1be67ee`](https://github.com/npm/fs/commit/1be67ee39cd1363f7a47619b22574603817bf6ed) [#133](https://github.com/npm/fs/pull/133) template-oss-apply (@owlstronaut) * [`4f74601`](https://github.com/npm/fs/commit/4f74601489a9c258642630bef4fbb083c21ff36e) [#126](https://github.com/npm/fs/pull/126) postinstall workflow updates (#126) (@owlstronaut) * [`3cbc2b2`](https://github.com/npm/fs/commit/3cbc2b29923127c9ad9d3833fee1eafb41fc005a) [#132](https://github.com/npm/fs/pull/132) bump @npmcli/template-oss from 4.26.0 to 4.27.1 (#132) (@dependabot[bot], @npm-cli-bot) ## [4.0.0](https://github.com/npm/fs/compare/v3.1.1...v4.0.0) (2024-09-11) ### ⚠️ BREAKING CHANGES * `@npmcli/fs` now supports node `^18.17.0 || >=20.5.0` ### Bug Fixes * [`618ca23`](https://github.com/npm/fs/commit/618ca236ab9a8e8fe515707efa6c51869badff22) [#121](https://github.com/npm/fs/pull/121) align to npm 10 node engine range (@hashtagchris) ### Chores * [`1c67142`](https://github.com/npm/fs/commit/1c6714216afb9469f2add2e2f13cf0eaf241299d) [#123](https://github.com/npm/fs/pull/123) enable auto publish (@hashtagchris) * [`83f4580`](https://github.com/npm/fs/commit/83f45800994afddaa472ceac15ff8600a89ae7ca) [#121](https://github.com/npm/fs/pull/121) run template-oss-apply (@hashtagchris) * [`65bff4e`](https://github.com/npm/fs/commit/65bff4ea1d681d3a3009c9a554961a205c36114a) [#119](https://github.com/npm/fs/pull/119) bump @npmcli/eslint-config from 4.0.5 to 5.0.0 (@dependabot[bot]) * [`6dd91fc`](https://github.com/npm/fs/commit/6dd91fc020f098d513cb96ab4379ab9b8d667d37) [#120](https://github.com/npm/fs/pull/120) postinstall for dependabot template-oss PR (@hashtagchris) * [`72176f8`](https://github.com/npm/fs/commit/72176f81fd7adf8da9fd31339ee7b2ee9ee352bf) [#120](https://github.com/npm/fs/pull/120) bump @npmcli/template-oss from 4.23.1 to 4.23.3 (@dependabot[bot]) ## [3.1.1](https://github.com/npm/fs/compare/v3.1.0...v3.1.1) (2024-05-03) ### Documentation * [`2cb7474`](https://github.com/npm/fs/commit/2cb74741359bc3712d08760aebe1c25cc0f42f3d) [#91](https://github.com/npm/fs/pull/91) fix the example for readdirScoped (#91) (@aminya) ### Chores * [`237e7c6`](https://github.com/npm/fs/commit/237e7c696658e2617a4e0198990cd01c3f3a5746) [#106](https://github.com/npm/fs/pull/106) bump @npmcli/template-oss to 4.22.0 (@lukekarrys) * [`456d343`](https://github.com/npm/fs/commit/456d3438ed24509a4703b984cc5679977f55ae6f) [#106](https://github.com/npm/fs/pull/106) postinstall for dependabot template-oss PR (@lukekarrys) * [`5b0f7c6`](https://github.com/npm/fs/commit/5b0f7c6de9052ddba37df5cc2a1cbfc5dda40efc) [#105](https://github.com/npm/fs/pull/105) bump @npmcli/template-oss from 4.21.3 to 4.21.4 (@dependabot[bot]) ## [3.1.0](https://github.com/npm/fs/compare/v3.0.0...v3.1.0) (2022-11-03) ### Features * [`ecbb150`](https://github.com/npm/fs/commit/ecbb1507e0f6af546c17719426807ec3716c5b54) [#63](https://github.com/npm/fs/pull/63) port @npmcli/move-file (#63) (@lukekarrys) * [`1268710`](https://github.com/npm/fs/commit/126871003bd0fcf615ac15621b11fec03e76ed2d) [#62](https://github.com/npm/fs/pull/62) add readdirScoped method (@lukekarrys) ## [3.0.0](https://github.com/npm/fs/compare/v2.1.2...v3.0.0) (2022-10-11) ### ⚠️ BREAKING CHANGES * this package no longer exports the full set of core fs functions * this removes the `owner` option from all methods that previously supported it, as well as the `withOwner` and `withOwnerSync` methods * `@npmcli/fs` is now compatible with the following semver range for node: `^14.17.0 || ^16.13.0 || >=18.0.0` ### Features * [`b788931`](https://github.com/npm/fs/commit/b78893107ae447c4ac65182aef24d9f39a46cd45) [#54](https://github.com/npm/fs/pull/54) remove custom promisification in favor of fs/promises (#54) (@nlf) * [`e666309`](https://github.com/npm/fs/commit/e66630906e0796fe0cd5fdda970f1be30243fb1c) [#53](https://github.com/npm/fs/pull/53) remove owner related code as well as stale polyfills (#53) (@nlf) * [`895d205`](https://github.com/npm/fs/commit/895d205502851ce1707b3ed0c1935e414c10be6b) [#46](https://github.com/npm/fs/pull/46) postinstall for dependabot template-oss PR (@lukekarrys) ## [2.1.2](https://github.com/npm/fs/compare/v2.1.1...v2.1.2) (2022-08-15) ### Bug Fixes * linting ([#37](https://github.com/npm/fs/issues/37)) ([816bb74](https://github.com/npm/fs/commit/816bb74233cb029188e5236deea4dc58fbb70a94)) ## [2.1.1](https://github.com/npm/fs/compare/v2.1.0...v2.1.1) (2022-07-20) ### Bug Fixes * remove polyfills which are out of range of our engines ([#35](https://github.com/npm/fs/issues/35)) ([be1e7b2](https://github.com/npm/fs/commit/be1e7b262de3e1cf6b2803173094c73676446fd7)) ## [2.1.0](https://www.github.com/npm/fs/compare/v2.0.1...v2.1.0) (2022-03-21) ### Features * add withOwner and withOwnerSync methods ([#21](https://www.github.com/npm/fs/issues/21)) ([40ee281](https://www.github.com/npm/fs/commit/40ee28171138070fc28914689a190bf0727af555)) ### [2.0.1](https://www.github.com/npm/fs/compare/v2.0.0...v2.0.1) (2022-02-23) ### Bug Fixes * add repo entry to package.json ([#10](https://www.github.com/npm/fs/issues/10)) ([eb723e4](https://www.github.com/npm/fs/commit/eb723e44cbddd1d5c568fdfb1297a18672c41085)) ## [2.0.0](https://www.github.com/npm/fs/compare/v1.1.1...v2.0.0) (2022-02-23) ### ⚠ BREAKING CHANGES * This removes support for node 10 and non-LTS versions of 12 and 14 ### Bug Fixes * update @npmcli/template-oss ([#9](https://www.github.com/npm/fs/issues/9)) ([7dae6fd](https://www.github.com/npm/fs/commit/7dae6fdf461a1fff7c38943feb3b43315a25c5e3)) ### Dependencies * update @gar/promisify requirement from ^1.0.1 to ^1.1.3 ([#14](https://www.github.com/npm/fs/issues/14)) ([e24e318](https://www.github.com/npm/fs/commit/e24e318fc024255923e5821cd19c817c9eec73b5)) �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/CODE_OF_CONDUCT.md�������������������������������������������������������������������0000664�0000000�0000000�00000000507�15076461761�0016061�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<!-- This file is automatically added by @npmcli/template-oss. Do not edit. --> 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-fs-b473b15/CONTRIBUTING.md����������������������������������������������������������������������0000664�0000000�0000000�00000005133�15076461761�0015513�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<!-- This file is automatically added by @npmcli/template-oss. Do not edit. --> # 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-fs-b473b15/LICENSE.md���������������������������������������������������������������������������0000664�0000000�0000000�00000001436�15076461761�0014670�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<!-- This file is automatically added by @npmcli/template-oss. Do not edit. --> ISC License Copyright npm, Inc. 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 NPM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NPM 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-fs-b473b15/README.md����������������������������������������������������������������������������0000664�0000000�0000000�00000004775�15076461761�0014554�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������# @npmcli/fs polyfills, and extensions, of the core `fs` module. ## Features - `fs.cp` polyfill for node < 16.7.0 - `fs.withTempDir` added - `fs.readdirScoped` added - `fs.moveFile` added ## `fs.withTempDir(root, fn, options) -> Promise` ### Parameters - `root`: the directory in which to create the temporary directory - `fn`: a function that will be called with the path to the temporary directory - `options` - `tmpPrefix`: a prefix to be used in the generated directory name ### Usage The `withTempDir` function creates a temporary directory, runs the provided function (`fn`), then removes the temporary directory and resolves or rejects based on the result of `fn`. ```js const fs = require('@npmcli/fs') const os = require('os') // this function will be called with the full path to the temporary directory // it is called with `await` behind the scenes, so can be async if desired. const myFunction = async (tempPath) => { return 'done!' } const main = async () => { const result = await fs.withTempDir(os.tmpdir(), myFunction) // result === 'done!' } main() ``` ## `fs.readdirScoped(root) -> Promise` ### Parameters - `root`: the directory to read ### Usage Like `fs.readdir` but handling `@org/module` dirs as if they were a single entry. ```javascript const { readdirScoped } = require('@npmcli/fs') const entries = await readdirScoped('node_modules') // entries will be something like: ['a', '@org/foo', '@org/bar'] ``` ## `fs.moveFile(source, dest, options) -> Promise` A fork of [move-file](https://github.com/sindresorhus/move-file) with support for Common JS. ### Highlights - Promise API. - Supports moving a file across partitions and devices. - Optionally prevent overwriting an existing file. - Creates non-existent destination directories for you. - Automatically recurses when source is a directory. ### Parameters - `source`: File, or directory, you want to move. - `dest`: Where you want the file or directory moved. - `options` - `overwrite` (`boolean`, default: `true`): Overwrite existing destination file(s). ### Usage The built-in [`fs.rename()`](https://nodejs.org/api/fs.html#fs_fs_rename_oldpath_newpath_callback) is just a JavaScript wrapper for the C `rename(2)` function, which doesn't support moving files across partitions or devices. This module is what you would have expected `fs.rename()` to be. ```js const { moveFile } = require('@npmcli/fs'); (async () => { await moveFile('source/unicorn.png', 'destination/unicorn.png'); console.log('The file has been moved'); })(); ``` ���npm-fs-b473b15/SECURITY.md��������������������������������������������������������������������������0000664�0000000�0000000�00000002320�15076461761�0015046�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������<!-- This file is automatically added by @npmcli/template-oss. Do not edit. --> 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-fs-b473b15/lib/���������������������������������������������������������������������������������0000775�0000000�0000000�00000000000�15076461761�0014026�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/lib/common/��������������������������������������������������������������������������0000775�0000000�0000000�00000000000�15076461761�0015316�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/lib/common/get-options.js������������������������������������������������������������0000664�0000000�0000000�00000001020�15076461761�0020115�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������// given an input that may or may not be an object, return an object that has // a copy of every defined property listed in 'copy'. if the input is not an // object, assign it to the property named by 'wrap' const getOptions = (input, { copy, wrap }) => { const result = {} if (input && typeof input === 'object') { for (const prop of copy) { if (input[prop] !== undefined) { result[prop] = input[prop] } } } else { result[wrap] = input } return result } module.exports = getOptions ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/lib/common/node.js�������������������������������������������������������������������0000664�0000000�0000000�00000000265�15076461761�0016604�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������const semver = require('semver') const satisfies = (range) => { return semver.satisfies(process.version, range, { includePrerelease: true }) } module.exports = { satisfies, } �������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/lib/cp/������������������������������������������������������������������������������0000775�0000000�0000000�00000000000�15076461761�0014430�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/lib/cp/LICENSE�����������������������������������������������������������������������0000664�0000000�0000000�00000002074�15076461761�0015440�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������(The MIT License) Copyright (c) 2011-2017 JP Richardson Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/lib/cp/errors.js���������������������������������������������������������������������0000664�0000000�0000000�00000006504�15076461761�0016307�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������'use strict' const { inspect } = require('util') // adapted from node's internal/errors // https://github.com/nodejs/node/blob/c8a04049/lib/internal/errors.js // close copy of node's internal SystemError class. class SystemError { constructor (code, prefix, context) { // XXX context.code is undefined in all constructors used in cp/polyfill // that may be a bug copied from node, maybe the constructor should use // `code` not `errno`? nodejs/node#41104 let message = `${prefix}: ${context.syscall} returned ` + `${context.code} (${context.message})` if (context.path !== undefined) { message += ` ${context.path}` } if (context.dest !== undefined) { message += ` => ${context.dest}` } this.code = code Object.defineProperties(this, { name: { value: 'SystemError', enumerable: false, writable: true, configurable: true, }, message: { value: message, enumerable: false, writable: true, configurable: true, }, info: { value: context, enumerable: true, configurable: true, writable: false, }, errno: { get () { return context.errno }, set (value) { context.errno = value }, enumerable: true, configurable: true, }, syscall: { get () { return context.syscall }, set (value) { context.syscall = value }, enumerable: true, configurable: true, }, }) if (context.path !== undefined) { Object.defineProperty(this, 'path', { get () { return context.path }, set (value) { context.path = value }, enumerable: true, configurable: true, }) } if (context.dest !== undefined) { Object.defineProperty(this, 'dest', { get () { return context.dest }, set (value) { context.dest = value }, enumerable: true, configurable: true, }) } } toString () { return `${this.name} [${this.code}]: ${this.message}` } [Symbol.for('nodejs.util.inspect.custom')] (_recurseTimes, ctx) { return inspect(this, { ...ctx, getters: true, customInspect: false, }) } } function E (code, message) { module.exports[code] = class NodeError extends SystemError { constructor (ctx) { super(code, message, ctx) } } } E('ERR_FS_CP_DIR_TO_NON_DIR', 'Cannot overwrite directory with non-directory') E('ERR_FS_CP_EEXIST', 'Target already exists') E('ERR_FS_CP_EINVAL', 'Invalid src or dest') E('ERR_FS_CP_FIFO_PIPE', 'Cannot copy a FIFO pipe') E('ERR_FS_CP_NON_DIR_TO_DIR', 'Cannot overwrite non-directory with directory') E('ERR_FS_CP_SOCKET', 'Cannot copy a socket file') E('ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY', 'Cannot overwrite symlink in subdirectory of self') E('ERR_FS_CP_UNKNOWN', 'Cannot copy an unknown file type') E('ERR_FS_EISDIR', 'Path is a directory') module.exports.ERR_INVALID_ARG_TYPE = class ERR_INVALID_ARG_TYPE extends Error { constructor (name, expected, actual) { super() this.code = 'ERR_INVALID_ARG_TYPE' this.message = `The ${name} argument must be ${expected}. Received ${typeof actual}` } } ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/lib/cp/index.js����������������������������������������������������������������������0000664�0000000�0000000�00000001267�15076461761�0016103�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������const fs = require('fs/promises') const getOptions = require('../common/get-options.js') const node = require('../common/node.js') const polyfill = require('./polyfill.js') // node 16.7.0 added fs.cp const useNative = node.satisfies('>=16.7.0') const cp = async (src, dest, opts) => { const options = getOptions(opts, { copy: ['dereference', 'errorOnExist', 'filter', 'force', 'preserveTimestamps', 'recursive'], }) // the polyfill is tested separately from this module, no need to hack // process.version to try to trigger it just for coverage // istanbul ignore next return useNative ? fs.cp(src, dest, options) : polyfill(src, dest, options) } module.exports = cp �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/lib/cp/polyfill.js�������������������������������������������������������������������0000664�0000000�0000000�00000027721�15076461761�0016631�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������// this file is a modified version of the code in node 17.2.0 // which is, in turn, a modified version of the fs-extra module on npm // node core changes: // - Use of the assert module has been replaced with core's error system. // - All code related to the glob dependency has been removed. // - Bring your own custom fs module is not currently supported. // - Some basic code cleanup. // changes here: // - remove all callback related code // - drop sync support // - change assertions back to non-internal methods (see options.js) // - throws ENOTDIR when rmdir gets an ENOENT for a path that exists in Windows 'use strict' const { ERR_FS_CP_DIR_TO_NON_DIR, ERR_FS_CP_EEXIST, ERR_FS_CP_EINVAL, ERR_FS_CP_FIFO_PIPE, ERR_FS_CP_NON_DIR_TO_DIR, ERR_FS_CP_SOCKET, ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY, ERR_FS_CP_UNKNOWN, ERR_FS_EISDIR, ERR_INVALID_ARG_TYPE, } = require('./errors.js') const { constants: { errno: { EEXIST, EISDIR, EINVAL, ENOTDIR, }, }, } = require('os') const { chmod, copyFile, lstat, mkdir, readdir, readlink, stat, symlink, unlink, utimes, } = require('fs/promises') const { dirname, isAbsolute, join, parse, resolve, sep, toNamespacedPath, } = require('path') const { fileURLToPath } = require('url') const defaultOptions = { dereference: false, errorOnExist: false, filter: undefined, force: true, preserveTimestamps: false, recursive: false, } async function cp (src, dest, opts) { if (opts != null && typeof opts !== 'object') { throw new ERR_INVALID_ARG_TYPE('options', ['Object'], opts) } return cpFn( toNamespacedPath(getValidatedPath(src)), toNamespacedPath(getValidatedPath(dest)), { ...defaultOptions, ...opts }) } function getValidatedPath (fileURLOrPath) { const path = fileURLOrPath != null && fileURLOrPath.href && fileURLOrPath.origin ? fileURLToPath(fileURLOrPath) : fileURLOrPath return path } async function cpFn (src, dest, opts) { // Warn about using preserveTimestamps on 32-bit node // istanbul ignore next if (opts.preserveTimestamps && process.arch === 'ia32') { const warning = 'Using the preserveTimestamps option in 32-bit ' + 'node is not recommended' process.emitWarning(warning, 'TimestampPrecisionWarning') } const stats = await checkPaths(src, dest, opts) const { srcStat, destStat } = stats await checkParentPaths(src, srcStat, dest) if (opts.filter) { return handleFilter(checkParentDir, destStat, src, dest, opts) } return checkParentDir(destStat, src, dest, opts) } async function checkPaths (src, dest, opts) { const { 0: srcStat, 1: destStat } = await getStats(src, dest, opts) if (destStat) { if (areIdentical(srcStat, destStat)) { throw new ERR_FS_CP_EINVAL({ message: 'src and dest cannot be the same', path: dest, syscall: 'cp', errno: EINVAL, }) } if (srcStat.isDirectory() && !destStat.isDirectory()) { throw new ERR_FS_CP_DIR_TO_NON_DIR({ message: `cannot overwrite directory ${src} ` + `with non-directory ${dest}`, path: dest, syscall: 'cp', errno: EISDIR, }) } if (!srcStat.isDirectory() && destStat.isDirectory()) { throw new ERR_FS_CP_NON_DIR_TO_DIR({ message: `cannot overwrite non-directory ${src} ` + `with directory ${dest}`, path: dest, syscall: 'cp', errno: ENOTDIR, }) } } if (srcStat.isDirectory() && isSrcSubdir(src, dest)) { throw new ERR_FS_CP_EINVAL({ message: `cannot copy ${src} to a subdirectory of self ${dest}`, path: dest, syscall: 'cp', errno: EINVAL, }) } return { srcStat, destStat } } function areIdentical (srcStat, destStat) { return destStat.ino && destStat.dev && destStat.ino === srcStat.ino && destStat.dev === srcStat.dev } function getStats (src, dest, opts) { const statFunc = opts.dereference ? (file) => stat(file, { bigint: true }) : (file) => lstat(file, { bigint: true }) return Promise.all([ statFunc(src), statFunc(dest).catch((err) => { // istanbul ignore next: unsure how to cover. if (err.code === 'ENOENT') { return null } // istanbul ignore next: unsure how to cover. throw err }), ]) } async function checkParentDir (destStat, src, dest, opts) { const destParent = dirname(dest) const dirExists = await pathExists(destParent) if (dirExists) { return getStatsForCopy(destStat, src, dest, opts) } await mkdir(destParent, { recursive: true }) return getStatsForCopy(destStat, src, dest, opts) } function pathExists (dest) { return stat(dest).then( () => true, // istanbul ignore next: not sure when this would occur (err) => (err.code === 'ENOENT' ? false : Promise.reject(err))) } // Recursively check if dest parent is a subdirectory of src. // It works for all file types including symlinks since it // checks the src and dest inodes. It starts from the deepest // parent and stops once it reaches the src parent or the root path. async function checkParentPaths (src, srcStat, dest) { const srcParent = resolve(dirname(src)) const destParent = resolve(dirname(dest)) if (destParent === srcParent || destParent === parse(destParent).root) { return } let destStat try { destStat = await stat(destParent, { bigint: true }) } catch (err) { // istanbul ignore else: not sure when this would occur if (err.code === 'ENOENT') { return } // istanbul ignore next: not sure when this would occur throw err } if (areIdentical(srcStat, destStat)) { throw new ERR_FS_CP_EINVAL({ message: `cannot copy ${src} to a subdirectory of self ${dest}`, path: dest, syscall: 'cp', errno: EINVAL, }) } return checkParentPaths(src, srcStat, destParent) } const normalizePathToArray = (path) => resolve(path).split(sep).filter(Boolean) // Return true if dest is a subdir of src, otherwise false. // It only checks the path strings. function isSrcSubdir (src, dest) { const srcArr = normalizePathToArray(src) const destArr = normalizePathToArray(dest) return srcArr.every((cur, i) => destArr[i] === cur) } async function handleFilter (onInclude, destStat, src, dest, opts, cb) { const include = await opts.filter(src, dest) if (include) { return onInclude(destStat, src, dest, opts, cb) } } function startCopy (destStat, src, dest, opts) { if (opts.filter) { return handleFilter(getStatsForCopy, destStat, src, dest, opts) } return getStatsForCopy(destStat, src, dest, opts) } async function getStatsForCopy (destStat, src, dest, opts) { const statFn = opts.dereference ? stat : lstat const srcStat = await statFn(src) // istanbul ignore else: can't portably test FIFO if (srcStat.isDirectory() && opts.recursive) { return onDir(srcStat, destStat, src, dest, opts) } else if (srcStat.isDirectory()) { throw new ERR_FS_EISDIR({ message: `${src} is a directory (not copied)`, path: src, syscall: 'cp', errno: EINVAL, }) } else if (srcStat.isFile() || srcStat.isCharacterDevice() || srcStat.isBlockDevice()) { return onFile(srcStat, destStat, src, dest, opts) } else if (srcStat.isSymbolicLink()) { return onLink(destStat, src, dest) } else if (srcStat.isSocket()) { throw new ERR_FS_CP_SOCKET({ message: `cannot copy a socket file: ${dest}`, path: dest, syscall: 'cp', errno: EINVAL, }) } else if (srcStat.isFIFO()) { throw new ERR_FS_CP_FIFO_PIPE({ message: `cannot copy a FIFO pipe: ${dest}`, path: dest, syscall: 'cp', errno: EINVAL, }) } // istanbul ignore next: should be unreachable throw new ERR_FS_CP_UNKNOWN({ message: `cannot copy an unknown file type: ${dest}`, path: dest, syscall: 'cp', errno: EINVAL, }) } function onFile (srcStat, destStat, src, dest, opts) { if (!destStat) { return _copyFile(srcStat, src, dest, opts) } return mayCopyFile(srcStat, src, dest, opts) } async function mayCopyFile (srcStat, src, dest, opts) { if (opts.force) { await unlink(dest) return _copyFile(srcStat, src, dest, opts) } else if (opts.errorOnExist) { throw new ERR_FS_CP_EEXIST({ message: `${dest} already exists`, path: dest, syscall: 'cp', errno: EEXIST, }) } } async function _copyFile (srcStat, src, dest, opts) { await copyFile(src, dest) if (opts.preserveTimestamps) { return handleTimestampsAndMode(srcStat.mode, src, dest) } return setDestMode(dest, srcStat.mode) } async function handleTimestampsAndMode (srcMode, src, dest) { // Make sure the file is writable before setting the timestamp // otherwise open fails with EPERM when invoked with 'r+' // (through utimes call) if (fileIsNotWritable(srcMode)) { await makeFileWritable(dest, srcMode) return setDestTimestampsAndMode(srcMode, src, dest) } return setDestTimestampsAndMode(srcMode, src, dest) } function fileIsNotWritable (srcMode) { return (srcMode & 0o200) === 0 } function makeFileWritable (dest, srcMode) { return setDestMode(dest, srcMode | 0o200) } async function setDestTimestampsAndMode (srcMode, src, dest) { await setDestTimestamps(src, dest) return setDestMode(dest, srcMode) } function setDestMode (dest, srcMode) { return chmod(dest, srcMode) } async function setDestTimestamps (src, dest) { // The initial srcStat.atime cannot be trusted // because it is modified by the read(2) system call // (See https://nodejs.org/api/fs.html#fs_stat_time_values) const updatedSrcStat = await stat(src) return utimes(dest, updatedSrcStat.atime, updatedSrcStat.mtime) } function onDir (srcStat, destStat, src, dest, opts) { if (!destStat) { return mkDirAndCopy(srcStat.mode, src, dest, opts) } return copyDir(src, dest, opts) } async function mkDirAndCopy (srcMode, src, dest, opts) { await mkdir(dest) await copyDir(src, dest, opts) return setDestMode(dest, srcMode) } async function copyDir (src, dest, opts) { const dir = await readdir(src) for (let i = 0; i < dir.length; i++) { const item = dir[i] const srcItem = join(src, item) const destItem = join(dest, item) const { destStat } = await checkPaths(srcItem, destItem, opts) await startCopy(destStat, srcItem, destItem, opts) } } async function onLink (destStat, src, dest) { let resolvedSrc = await readlink(src) if (!isAbsolute(resolvedSrc)) { resolvedSrc = resolve(dirname(src), resolvedSrc) } if (!destStat) { return symlink(resolvedSrc, dest) } let resolvedDest try { resolvedDest = await readlink(dest) } catch (err) { // Dest exists and is a regular file or directory, // Windows may throw UNKNOWN error. If dest already exists, // fs throws error anyway, so no need to guard against it here. // istanbul ignore next: can only test on windows if (err.code === 'EINVAL' || err.code === 'UNKNOWN') { return symlink(resolvedSrc, dest) } // istanbul ignore next: should not be possible throw err } if (!isAbsolute(resolvedDest)) { resolvedDest = resolve(dirname(dest), resolvedDest) } if (isSrcSubdir(resolvedSrc, resolvedDest)) { throw new ERR_FS_CP_EINVAL({ message: `cannot copy ${resolvedSrc} to a subdirectory of self ` + `${resolvedDest}`, path: dest, syscall: 'cp', errno: EINVAL, }) } // Do not copy if src is a subdir of dest since unlinking // dest in this case would result in removing src contents // and therefore a broken symlink would be created. const srcStat = await stat(src) if (srcStat.isDirectory() && isSrcSubdir(resolvedDest, resolvedSrc)) { throw new ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY({ message: `cannot overwrite ${resolvedDest} with ${resolvedSrc}`, path: dest, syscall: 'cp', errno: EINVAL, }) } return copyLink(resolvedSrc, dest) } async function copyLink (resolvedSrc, dest) { await unlink(dest) return symlink(resolvedSrc, dest) } module.exports = cp �����������������������������������������������npm-fs-b473b15/lib/index.js�������������������������������������������������������������������������0000664�0000000�0000000�00000000414�15076461761�0015472�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������'use strict' const cp = require('./cp/index.js') const withTempDir = require('./with-temp-dir.js') const readdirScoped = require('./readdir-scoped.js') const moveFile = require('./move-file.js') module.exports = { cp, withTempDir, readdirScoped, moveFile, } ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/lib/move-file.js���������������������������������������������������������������������0000664�0000000�0000000�00000004351�15076461761�0016252�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������const { dirname, join, resolve, relative, isAbsolute } = require('path') const fs = require('fs/promises') const pathExists = async path => { try { await fs.access(path) return true } catch (er) { return er.code !== 'ENOENT' } } const moveFile = async (source, destination, options = {}, root = true, symlinks = []) => { if (!source || !destination) { throw new TypeError('`source` and `destination` file required') } options = { overwrite: true, ...options, } if (!options.overwrite && await pathExists(destination)) { throw new Error(`The destination file exists: ${destination}`) } await fs.mkdir(dirname(destination), { recursive: true }) try { await fs.rename(source, destination) } catch (error) { if (error.code === 'EXDEV' || error.code === 'EPERM') { const sourceStat = await fs.lstat(source) if (sourceStat.isDirectory()) { const files = await fs.readdir(source) await Promise.all(files.map((file) => moveFile(join(source, file), join(destination, file), options, false, symlinks) )) } else if (sourceStat.isSymbolicLink()) { symlinks.push({ source, destination }) } else { await fs.copyFile(source, destination) } } else { throw error } } if (root) { await Promise.all(symlinks.map(async ({ source: symSource, destination: symDestination }) => { let target = await fs.readlink(symSource) // junction symlinks in windows will be absolute paths, so we need to // make sure they point to the symlink destination if (isAbsolute(target)) { target = resolve(symDestination, relative(symSource, target)) } // try to determine what the actual file is so we can create the correct // type of symlink in windows let targetStat = 'file' try { targetStat = await fs.stat(resolve(dirname(symSource), target)) if (targetStat.isDirectory()) { targetStat = 'junction' } } catch { // targetStat remains 'file' } await fs.symlink( target, symDestination, targetStat ) })) await fs.rm(source, { recursive: true, force: true }) } } module.exports = moveFile ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/lib/readdir-scoped.js����������������������������������������������������������������0000664�0000000�0000000�00000000657�15076461761�0017261�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������const { readdir } = require('fs/promises') const { join } = require('path') const readdirScoped = async (dir) => { const results = [] for (const item of await readdir(dir)) { if (item.startsWith('@')) { for (const scopedItem of await readdir(join(dir, item))) { results.push(join(item, scopedItem)) } } else { results.push(item) } } return results } module.exports = readdirScoped ���������������������������������������������������������������������������������npm-fs-b473b15/lib/with-temp-dir.js�����������������������������������������������������������������0000664�0000000�0000000�00000001604�15076461761�0017057�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������const { join, sep } = require('path') const getOptions = require('./common/get-options.js') const { mkdir, mkdtemp, rm } = require('fs/promises') // create a temp directory, ensure its permissions match its parent, then call // the supplied function passing it the path to the directory. clean up after // the function finishes, whether it throws or not const withTempDir = async (root, fn, opts) => { const options = getOptions(opts, { copy: ['tmpPrefix'], }) // create the directory await mkdir(root, { recursive: true }) const target = await mkdtemp(join(`${root}${sep}`, options.tmpPrefix || '')) let err let result try { result = await fn(target) } catch (_err) { err = _err } try { await rm(target, { force: true, recursive: true }) } catch { // ignore errors } if (err) { throw err } return result } module.exports = withTempDir ����������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/package.json�������������������������������������������������������������������������0000664�0000000�0000000�00000002316�15076461761�0015550�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������{ "name": "@npmcli/fs", "version": "5.0.0", "description": "filesystem utilities for the npm cli", "main": "lib/index.js", "files": [ "bin/", "lib/" ], "scripts": { "snap": "tap", "test": "tap", "npmclilint": "npmcli-lint", "lint": "npm run eslint", "lintfix": "npm run eslint -- --fix", "posttest": "npm run lint", "postsnap": "npm run lintfix --", "postlint": "template-oss-check", "template-oss-apply": "template-oss-apply --force", "eslint": "eslint \"**/*.{js,cjs,ts,mjs,jsx,tsx}\"" }, "repository": { "type": "git", "url": "git+https://github.com/npm/fs.git" }, "keywords": [ "npm", "oss" ], "author": "GitHub Inc.", "license": "ISC", "devDependencies": { "@npmcli/eslint-config": "^5.0.0", "@npmcli/template-oss": "4.27.1", "tap": "^16.0.1" }, "dependencies": { "semver": "^7.3.5" }, "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.", "version": "4.27.1", "publish": true }, "tap": { "nyc-arg": [ "--exclude", "tap-snapshots/**" ] } } ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/release-please-config.json�����������������������������������������������������������0000664�0000000�0000000�00000001277�15076461761�0020314�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-fs-b473b15/test/��������������������������������������������������������������������������������0000775�0000000�0000000�00000000000�15076461761�0014237�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/test/common/�������������������������������������������������������������������������0000775�0000000�0000000�00000000000�15076461761�0015527�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/test/common/get-options.js�����������������������������������������������������������0000664�0000000�0000000�00000001120�15076461761�0020327�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������const t = require('tap') const getOptions = require('../../lib/common/get-options.js') t.test('copies named properties in an object', async (t) => { const input = { one: 'one', two: 'two', three: 'three', } const result = getOptions(input, { copy: ['one', 'two'], }) t.same(result, { one: 'one', two: 'two' }, 'only copied named properties') }) t.test('wraps non-object values in named property', async (t) => { const input = 'bar' const result = getOptions(input, { wrap: 'foo', }) t.same(result, { foo: 'bar' }, 'wrapped non-object in object') }) ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/test/common/node.js������������������������������������������������������������������0000664�0000000�0000000�00000000754�15076461761�0017020�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������const t = require('tap') const node = require('../../lib/common/node.js') // strip off leading 'v' const version = process.version.slice(1) const major = Number(version.split('.')[0]) t.test('returns true if range matches', async (t) => { const range = `^${major}` t.equal(node.satisfies(range), true, 'range matches') }) t.test('returns false if range does not match', async (t) => { const range = `^${major + 1}` t.equal(node.satisfies(range), false, 'range does not match') }) ��������������������npm-fs-b473b15/test/cp/�����������������������������������������������������������������������������0000775�0000000�0000000�00000000000�15076461761�0014641�5����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/test/cp/errors.js��������������������������������������������������������������������0000664�0000000�0000000�00000004131�15076461761�0016512�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������const t = require('tap') const { ERR_FS_EISDIR } = require('../../lib/cp/errors') const { constants: { errno: { EISDIR, EIO } } } = require('os') const { inspect } = require('util') t.test('message with path and dest', async t => { const err = new ERR_FS_EISDIR({ path: 'path', dest: 'dest', syscall: 'cp', code: EISDIR, message: 'failed', }) t.equal(err.message, `Path is a directory: cp returned ${EISDIR} (failed) path => dest`) }) t.test('message without path or dest', async t => { const err = new ERR_FS_EISDIR({ syscall: 'cp', code: EISDIR, message: 'failed', }) t.equal(err.message, `Path is a directory: cp returned ${EISDIR} (failed)`) }) t.test('errno is alias for info.errno', async t => { const err = new ERR_FS_EISDIR({ errno: EISDIR }) t.equal(err.errno, EISDIR) t.equal(err.info.errno, EISDIR) err.errno = EIO t.equal(err.errno, EIO) t.equal(err.info.errno, EIO) }) t.test('syscall is alias for info.syscall', async t => { const err = new ERR_FS_EISDIR({ syscall: 'cp' }) t.equal(err.syscall, 'cp') t.equal(err.info.syscall, 'cp') err.syscall = 'readlink' t.equal(err.syscall, 'readlink') t.equal(err.info.syscall, 'readlink') }) t.test('path is alias for info.path', async t => { const err = new ERR_FS_EISDIR({ path: 'first' }) t.equal(err.path, 'first') t.equal(err.info.path, 'first') err.path = 'second' t.equal(err.path, 'second') t.equal(err.info.path, 'second') }) t.test('dest is alias for info.dest', async t => { const err = new ERR_FS_EISDIR({ dest: 'first' }) t.equal(err.dest, 'first') t.equal(err.info.dest, 'first') err.dest = 'second' t.equal(err.dest, 'second') t.equal(err.info.dest, 'second') }) t.test('toString', async t => { const err = new ERR_FS_EISDIR({ syscall: 'cp', code: EISDIR, message: 'failed', }) t.equal(err.toString(), `SystemError [ERR_FS_EISDIR]: Path is a directory: cp returned ${EISDIR} (failed)`) }) t.test('inspect', async t => { const err = new ERR_FS_EISDIR({ syscall: 'cp', errno: EISDIR, message: 'failed', }) t.ok(inspect(err)) }) ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/test/cp/index.js���������������������������������������������������������������������0000664�0000000�0000000�00000001402�15076461761�0016303�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������const { stat } = require('fs/promises') const { join } = require('path') const t = require('tap') const cp = require('../../lib/cp/index.js') t.test('can copy a file', async (t) => { const dir = t.testdir({ file: 'some random file', }) const src = join(dir, 'file') const dest = join(dir, 'dest') await cp(src, dest) const exists = await stat(dest).then(() => true).catch(() => false) t.equal(exists, true, 'dest exits') }) t.test('can copy a directory', async (t) => { const dir = t.testdir({ directory: {}, }) const src = join(dir, 'directory') const dest = join(dir, 'dest') await cp(src, dest, { recursive: true }) const exists = await stat(dest).then(() => true).catch(() => false) t.equal(exists, true, 'dest exists') }) ��������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/test/cp/polyfill.js������������������������������������������������������������������0000664�0000000�0000000�00000026051�15076461761�0017035�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������const fs = require('fs') const { lstatSync, mkdirSync, readdirSync, readFileSync, readlinkSync, symlinkSync, statSync, writeFileSync, } = fs const net = require('net') const { join } = require('path') const { pathToFileURL } = require('url') const t = require('tap') const cp = require('../../lib/cp/polyfill') const isWindows = process.platform === 'win32' const tmpdir = t.testdir({ 'kitchen-sink': { a: { b: { 'index.js': 'module.exports = { purpose: "testing copy" };', 'README2.md': '# Hello', }, c: { d: { 'index.js': 'module.exports = { purpose: "testing copy" };', 'README3.md': '# Hello', }, }, 'index.js': 'module.exports = { purpose: "testing copy" };', 'README2.md': '# Hello', }, 'index.js': 'module.exports = { purpose: "testing copy" };', 'README.md': '# Hello', }, }) const kitchenSink = join(tmpdir, 'kitchen-sink') let dirc = 0 function nextdir () { return join(tmpdir, `copy_${++dirc}`) } t.test('It copies a nested folder structure with files and folders.', async t => { const src = kitchenSink const dest = nextdir() await cp(src, dest, { recursive: true }) assertDirEquivalent(t, src, dest) }) t.test('It does not throw errors when directory is copied over and force is false.', async t => { const src = nextdir() mkdirSync(join(src, 'a', 'b'), { recursive: true }) writeFileSync(join(src, 'README.md'), 'hello world', 'utf8') const dest = nextdir() await cp(src, dest, { dereference: true, recursive: true }) const initialStat = lstatSync(join(dest, 'README.md')) await cp(src, dest, { dereference: true, force: false, recursive: true, }) // File should not have been copied over, so access times will be identical: const finalStat = lstatSync(join(dest, 'README.md')) t.equal(finalStat.ctime.getTime(), initialStat.ctime.getTime()) }) t.test('It overwrites existing files if force is true.', async t => { const src = kitchenSink const dest = nextdir() mkdirSync(dest, { recursive: true }) writeFileSync(join(dest, 'README.md'), '# Goodbye', 'utf8') await cp(src, dest, { recursive: true }) assertDirEquivalent(t, src, dest) const content = readFileSync(join(dest, 'README.md'), 'utf8') t.equal(content.trim(), '# Hello') }) t.test('It can overwrite directory when dereference is true and force is false', async t => { const src = kitchenSink const dest = nextdir() const destFile = join(dest, 'a/b/README2.md') await cp(src, dest, { dereference: true, recursive: true }) await cp(src, dest, { dereference: true, recursive: true, }) const stat = lstatSync(destFile) t.ok(stat.isFile()) }) t.test('It copies file itself, rather than symlink, when dereference is true.', async t => { const src = nextdir() mkdirSync(src, { recursive: true }) writeFileSync(join(src, 'foo.js'), 'foo', 'utf8') symlinkSync(join(src, 'foo.js'), join(src, 'bar.js')) const dest = nextdir() mkdirSync(dest, { recursive: true }) const destFile = join(dest, 'foo.js') await cp(join(src, 'bar.js'), destFile, { dereference: true }) const stat = lstatSync(destFile) t.ok(stat.isFile()) }) t.test('It copies relative symlinks', async t => { const src = nextdir() mkdirSync(src, { recursive: true }) writeFileSync(join(src, 'foo.js'), 'foo', 'utf8') symlinkSync('./foo.js', join(src, 'bar.js')) const dest = nextdir() const destFile = join(dest, 'bar.js') mkdirSync(dest, { recursive: true }) writeFileSync(join(dest, 'foo.js'), 'foo', 'utf8') symlinkSync('./foo.js', destFile) await cp(src, dest, { recursive: true }) const stat = lstatSync(destFile) t.ok(stat.isSymbolicLink()) }) t.test('It returns error when src and dest are identical.', async t => { t.rejects( cp(kitchenSink, kitchenSink), { code: 'ERR_FS_CP_EINVAL' }) }) t.test('It returns error if symlink in src points to location in dest.', async t => { const src = nextdir() mkdirSync(src, { recursive: true }) const dest = nextdir() mkdirSync(dest) symlinkSync(dest, join(src, 'link')) await cp(src, dest, { recursive: true }) t.rejects( cp(src, dest, { recursive: true }), { code: 'ERR_FS_CP_EINVAL' }) }) t.test('It returns error if symlink in dest points to location in src.', async t => { const src = nextdir() mkdirSync(join(src, 'a', 'b'), { recursive: true }) symlinkSync(join(src, 'a', 'b'), join(src, 'a', 'c')) const dest = nextdir() mkdirSync(join(dest, 'a'), { recursive: true }) symlinkSync(src, join(dest, 'a', 'c')) t.rejects( cp(src, dest, { recursive: true }), { code: 'ERR_FS_CP_SYMLINK_TO_SUBDIRECTORY' }) }) t.test('It returns error if parent directory of symlink in dest points to src.', async t => { const src = nextdir() mkdirSync(join(src, 'a'), { recursive: true }) const dest = nextdir() // Create symlink in dest pointing to src. const destLink = join(dest, 'b') mkdirSync(dest, { recursive: true }) symlinkSync(src, destLink) t.rejects( cp(src, join(dest, 'b', 'c')), { code: 'ERR_FS_CP_EINVAL' }) }) t.test('It returns error if attempt is made to copy directory to file.', async t => { const src = nextdir() mkdirSync(src, { recursive: true }) const dest = join(kitchenSink, 'README.md') t.rejects( cp(src, dest), { code: 'ERR_FS_CP_DIR_TO_NON_DIR' }) }) t.test('It allows file to be copied to a file path.', async t => { const srcFile = join(kitchenSink, 'README.md') const destFile = join(nextdir(), 'index.js') await cp(srcFile, destFile, { dereference: true }) const stat = lstatSync(destFile) t.ok(stat.isFile()) }) t.test('It returns error if directory copied without recursive flag.', async t => { const src = kitchenSink const dest = nextdir() t.rejects( cp(src, dest), { code: 'ERR_FS_EISDIR' }) }) t.test('It returns error if attempt is made to copy file to directory.', async t => { const src = join(kitchenSink, 'README.md') const dest = nextdir() mkdirSync(dest, { recursive: true }) t.rejects( cp(src, dest), { code: 'ERR_FS_CP_NON_DIR_TO_DIR' }) }) t.test('It returns error if attempt is made to copy to subdirectory of self.', async t => { const src = kitchenSink const dest = join(kitchenSink, 'a') t.rejects( cp(src, dest), { code: 'ERR_FS_CP_EINVAL' }) }) t.test('It returns an error if attempt is made to copy socket.', { skip: isWindows }, async t => { const dest = nextdir() const sock = `${process.pid}.sock` const server = net.createServer() server.listen(sock) t.teardown(() => server.close()) t.rejects( cp(sock, dest), { code: 'ERR_FS_CP_SOCKET' }) }) t.test('It copies timestamps from src to dest if preserveTimestamps is true.', async t => { const src = kitchenSink const dest = nextdir() await cp(src, dest, { preserveTimestamps: true, recursive: true, }) assertDirEquivalent(t, src, dest) const srcStat = lstatSync(join(src, 'index.js')) const destStat = lstatSync(join(dest, 'index.js')) t.equal(srcStat.mtime.getTime(), destStat.mtime.getTime()) }) t.test('It applies filter function.', async t => { const src = kitchenSink const dest = nextdir() await cp(src, dest, { filter: (path) => { const pathStat = statSync(path) return pathStat.isDirectory() || path.endsWith('.js') }, dereference: true, recursive: true, }) const destEntries = [] collectEntries(dest, destEntries) for (const entry of destEntries) { t.equal( entry.isDirectory() || entry.name.endsWith('.js'), true ) } }) t.test('It supports async filter function.', async t => { const src = kitchenSink const dest = nextdir() await cp(src, dest, { filter: async (path) => { const pathStat = statSync(path) return pathStat.isDirectory() || path.endsWith('.js') }, dereference: true, recursive: true, }) const destEntries = [] collectEntries(dest, destEntries) for (const entry of destEntries) { t.equal( entry.isDirectory() || entry.name.endsWith('.js'), true ) } }) t.test('It errors on overwrite if force is false and errorOnExist is true', async t => { const src = kitchenSink const dest = nextdir() await cp(src, dest, { recursive: true }) t.rejects( cp(src, dest, { dereference: true, errorOnExist: true, force: false, recursive: true, }), { code: 'ERR_FS_CP_EEXIST' }) }) t.test('It returns EEXIST error if attempt is made to copy symlink over file.', async t => { const src = nextdir() mkdirSync(join(src, 'a', 'b'), { recursive: true }) symlinkSync(join(src, 'a', 'b'), join(src, 'a', 'c')) const dest = nextdir() mkdirSync(join(dest, 'a'), { recursive: true }) writeFileSync(join(dest, 'a', 'c'), 'hello', 'utf8') t.rejects( cp(src, dest, { recursive: true }), { code: 'EEXIST' }) }) t.test('It makes file writeable when updating timestamp, if not writeable.', async t => { const src = nextdir() mkdirSync(src, { recursive: true }) const dest = nextdir() mkdirSync(dest, { recursive: true }) writeFileSync(join(src, 'foo.txt'), 'foo', { mode: 0o444 }) await cp(src, dest, { preserveTimestamps: true, recursive: true, }) assertDirEquivalent(t, src, dest) const srcStat = lstatSync(join(src, 'foo.txt')) const destStat = lstatSync(join(dest, 'foo.txt')) t.equal(srcStat.mtime.getTime(), destStat.mtime.getTime()) }) t.test('It copies link if it does not point to folder in src.', async t => { const src = nextdir() mkdirSync(join(src, 'a', 'b'), { recursive: true }) symlinkSync(src, join(src, 'a', 'c')) const dest = nextdir() mkdirSync(join(dest, 'a'), { recursive: true }) symlinkSync(dest, join(dest, 'a', 'c')) await cp(src, dest, { recursive: true }) const link = readlinkSync(join(dest, 'a', 'c')) t.equal(link, src) }) t.test('It accepts file URL as src and dest.', async t => { const src = kitchenSink const dest = nextdir() await cp(pathToFileURL(src), pathToFileURL(dest), { recursive: true }) assertDirEquivalent(t, src, dest) }) t.test('It throws if options is not object.', async t => { t.rejects( () => cp('a', 'b', 'hello'), { code: 'ERR_INVALID_ARG_TYPE' }) }) function assertDirEquivalent (t, dir1, dir2) { const dir1Entries = [] collectEntries(dir1, dir1Entries) const dir2Entries = [] collectEntries(dir2, dir2Entries) t.equal(dir1Entries.length, dir2Entries.length) for (const entry1 of dir1Entries) { const entry2 = dir2Entries.find((entry) => { return entry.name === entry1.name }) t.ok(entry2, `entry ${entry2.name} not copied`) if (entry1.isFile()) { t.ok(entry2.isFile(), `${entry2.name} was not file`) } else if (entry1.isDirectory()) { t.ok(entry2.isDirectory(), `${entry2.name} was not directory`) } else if (entry1.isSymbolicLink()) { t.ok(entry2.isSymbolicLink(), `${entry2.name} was not symlink`) } } } function collectEntries (dir, dirEntries) { const newEntries = readdirSync(dir, { withFileTypes: true }) for (const entry of newEntries) { if (entry.isDirectory()) { collectEntries(join(dir, entry.name), dirEntries) } } dirEntries.push(...newEntries) } ���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/test/move-file.js��������������������������������������������������������������������0000664�0000000�0000000�00000023003�15076461761�0016456�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������const fs = require('fs/promises') const fsSync = require('fs') const { join } = require('path') const t = require('tap') const moveFile = require('../lib/move-file.js') const fixture = '🦄' // Node.js 22.20.0+ removed trailing backslash from Windows junctions // https://github.com/nodejs/node/pull/59847 const nodeVersion = process.versions.node.split('.').map(Number) const hasTrailingSlashFix = nodeVersion[0] > 22 || (nodeVersion[0] === 22 && nodeVersion[1] >= 20) t.test('missing `source` or `destination` throws', t => t.rejects(moveFile())) t.test('move a file', async t => { const dir = t.testdir({ src: fixture, }) const dest = `${dir}/dest` await moveFile(`${dir}/src`, dest) t.equal(fsSync.readFileSync(dest, 'utf8'), fixture) }) t.test('move a directory', async t => { const dir = t.testdir({ src: { one: fixture, two: fixture, sub: { three: fixture, four: fixture, five: t.fixture('symlink', './four'), }, link: t.fixture('symlink', './sub'), }, }) const dest = `${dir}/dest` await moveFile(`${dir}/src`, dest) const destStat = fsSync.statSync(dest) t.ok(destStat.isDirectory(), 'created a directory') t.equal(fsSync.readFileSync(`${dest}/one`, 'utf8'), fixture, 'copied file one') t.equal(fsSync.readFileSync(`${dest}/two`, 'utf8'), fixture, 'copied file two') const subStat = fsSync.statSync(`${dest}/sub`) t.ok(subStat.isDirectory(), 'created the subdirectory') t.equal(fsSync.readFileSync(`${dest}/sub/three`, 'utf8'), fixture, 'copied file three') t.equal(fsSync.readFileSync(`${dest}/sub/four`, 'utf8'), fixture, 'copied file four') t.ok(fsSync.lstatSync(`${dest}/sub/five`).isSymbolicLink(), 'created a file symbolic link') t.equal(fsSync.realpathSync(`${dest}/sub/five`), join(dest, 'sub/four'), 'created file symlink') t.equal(fsSync.readFileSync(`${dest}/sub/five`, 'utf8'), fixture, 'copied file four') t.ok(fsSync.lstatSync(`${dest}/link`).isSymbolicLink(), 'created a directory symbolic link') }) t.test('other types of errors fail', async t => { const randoError = new Error() randoError.code = 'ERANDO' const moveFileWithError = t.mock('../lib/move-file.js', { 'fs/promises': { ...fs, rename: async () => { throw randoError }, }, }) const dir = t.testdir({ src: fixture, }) const dest = `${dir}/dest` await t.rejects(() => moveFileWithError(`${dir}/src`, dest), randoError) }) t.test('move a file across devices', async t => { const exdevError = new Error() exdevError.code = 'EXDEV' const moveFileWithError = t.mock('../lib/move-file.js', { 'fs/promises': { ...fs, rename: async () => { throw exdevError }, }, }) const dir = t.testdir({ src: fixture, }) const dest = `${dir}/dest` await moveFileWithError(`${dir}/src`, dest) t.equal(fsSync.readFileSync(dest, 'utf8'), fixture) }) t.test('move a file across devices (EPERM)', async t => { const exdevError = new Error() exdevError.code = 'EPERM' const moveFileWithError = t.mock('../lib/move-file.js', { 'fs/promises': { ...fs, rename: async () => { throw exdevError }, }, }) const dir = t.testdir({ src: fixture, }) const dest = `${dir}/dest` await moveFileWithError(`${dir}/src`, dest) t.equal(fsSync.readFileSync(dest, 'utf8'), fixture) }) t.test('move a directory across devices', async t => { const exdevError = new Error() exdevError.code = 'EXDEV' const moveFileWithError = t.mock('../lib/move-file.js', { 'fs/promises': { ...fs, rename: async () => { throw exdevError }, }, }) const dir = t.testdir({ src: { one: fixture, two: fixture, sub: { three: fixture, four: fixture, five: t.fixture('symlink', './four'), reallysub: { six: t.fixture('symlink', '../one'), }, }, link: t.fixture('symlink', './sub'), abs: t.fixture('symlink', process.cwd()), }, }) const dest = `${dir}/dest` await moveFileWithError(`${dir}/src`, dest) t.ok(fsSync.statSync(dest).isDirectory(), 'created a directory') t.equal(fsSync.readFileSync(`${dest}/one`, 'utf8'), fixture, 'copied file one') t.equal(fsSync.readFileSync(`${dest}/two`, 'utf8'), fixture, 'copied file two') t.ok(fsSync.statSync(`${dest}/sub`).isDirectory(), 'created the subdirectory') t.equal(fsSync.readFileSync(`${dest}/sub/three`, 'utf8'), fixture, 'copied file three') t.equal(fsSync.readFileSync(`${dest}/sub/four`, 'utf8'), fixture, 'copied file four') t.ok(fsSync.lstatSync(`${dest}/sub/five`).isSymbolicLink(), 'created a file symbolic link') t.equal(fsSync.readlinkSync(`${dest}/sub/five`).replace(/\\/g, '/'), './four', 'created file symlink') t.ok(fsSync.lstatSync(`${dest}/link`).isSymbolicLink(), 'created a directory symbolic link') // below assertion varies for windows because junctions are absolute paths const expectedLink = (process.platform === 'win32' && !hasTrailingSlashFix) ? join(dest, 'sub\\') : (process.platform === 'win32' ? join(dest, 'sub') : './sub') t.equal( fsSync.readlinkSync(`${dest}/link`), expectedLink, 'created the directory symbolic link with the correct target' ) t.ok(fsSync.lstatSync(`${dest}/sub/reallysub`).isDirectory(), 'created the innermost subdirectory') t.ok(fsSync.lstatSync(`${dest}/sub/reallysub/six`).isSymbolicLink(), 'created the innermost symlink') t.equal( fsSync.readlinkSync(`${dest}/sub/reallysub/six`).replace(/\\/g, '/'), '../one', 'created the symlink with the appropriate target' ) t.ok(fsSync.lstatSync(`${dest}/abs`).isSymbolicLink(), 'created the absolute path symlink') const expectedAbs = (process.platform === 'win32' && !hasTrailingSlashFix) ? `${process.cwd()}\\` : process.cwd() t.equal( fsSync.readlinkSync(`${dest}/abs`), expectedAbs, 'kept the correct absolute path' ) }) t.test('move a directory across devices (EPERM)', async t => { const exdevError = new Error() exdevError.code = 'EXDEV' const moveFileWithError = t.mock('../lib/move-file.js', { 'fs/promises': { ...fs, rename: async () => { throw exdevError }, }, }) const dir = t.testdir({ src: { one: fixture, two: fixture, sub: { three: fixture, four: fixture, five: t.fixture('symlink', './four'), reallysub: { six: t.fixture('symlink', '../one'), }, }, link: t.fixture('symlink', './sub'), abs: t.fixture('symlink', process.cwd()), }, }) const dest = `${dir}/dest` await moveFileWithError(`${dir}/src`, dest) t.ok(fsSync.statSync(dest).isDirectory(), 'created a directory') t.equal(fsSync.readFileSync(`${dest}/one`, 'utf8'), fixture, 'copied file one') t.equal(fsSync.readFileSync(`${dest}/two`, 'utf8'), fixture, 'copied file two') t.ok(fsSync.statSync(`${dest}/sub`).isDirectory(), 'created the subdirectory') t.equal(fsSync.readFileSync(`${dest}/sub/three`, 'utf8'), fixture, 'copied file three') t.equal(fsSync.readFileSync(`${dest}/sub/four`, 'utf8'), fixture, 'copied file four') t.ok(fsSync.lstatSync(`${dest}/sub/five`).isSymbolicLink(), 'created a file symbolic link') t.equal( fsSync.readlinkSync(`${dest}/sub/five`).replace(/\\/g, '/'), './four', 'created file symlink') t.ok(fsSync.lstatSync(`${dest}/link`).isSymbolicLink(), 'created a directory symbolic link') // below assertion varies for windows because junctions are absolute paths const expectedLinkEperm = (process.platform === 'win32' && !hasTrailingSlashFix) ? join(dest, 'sub\\') : (process.platform === 'win32' ? join(dest, 'sub') : './sub') t.equal( fsSync.readlinkSync(`${dest}/link`), expectedLinkEperm, 'created the directory symbolic link with the correct target' ) t.ok( fsSync.lstatSync(`${dest}/sub/reallysub`).isDirectory(), 'created the innermost subdirectory') t.ok( fsSync.lstatSync(`${dest}/sub/reallysub/six`).isSymbolicLink(), 'created the innermost symlink') t.equal( fsSync.readlinkSync(`${dest}/sub/reallysub/six`).replace(/\\/g, '/'), '../one', 'created the symlink with the appropriate target' ) t.ok(fsSync.lstatSync(`${dest}/abs`).isSymbolicLink(), 'created the absolute path symlink') const expectedAbsEperm = (process.platform === 'win32' && !hasTrailingSlashFix) ? `${process.cwd()}\\` : process.cwd() t.equal( fsSync.readlinkSync(`${dest}/abs`), expectedAbsEperm, 'kept the correct absolute path' ) }) t.test('overwrite option', async t => { const dir = t.testdir({ src: 'x', dest: 'y', }) await t.rejects(moveFile(`${dir}/src`, `${dir}/dest`, { overwrite: false })) t.equal(fsSync.readFileSync(`${dir}/dest`, 'utf8'), 'y') await moveFile(`${dir}/src`, `${dir}/dest`) t.equal(fsSync.readFileSync(`${dir}/dest`, 'utf8'), 'x') }) t.test('overwrite option with non-ENOENT access error', async t => { const dir = t.testdir({ src: 'x', }) const er = Object.assign(new Error('its there, just bad'), { code: 'ETHEREBUTBAD', }) const moveFileWithError = t.mock('../lib/move-file.js', { 'fs/promises': { ...fs, access: async () => { throw er }, }, }) await t.rejects(moveFileWithError(`${dir}/src`, `${dir}/dest`, { overwrite: false })) // it actually isn't there tho, so this fails, obviously t.throws(() => fsSync.readFileSync(`${dir}/dest`, 'utf8'), 'y') await moveFileWithError(`${dir}/src`, `${dir}/dest`) t.equal(fsSync.readFileSync(`${dir}/dest`, 'utf8'), 'x') }) �����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������npm-fs-b473b15/test/readdir-scoped.js���������������������������������������������������������������0000664�0000000�0000000�00000000636�15076461761�0017467�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������const t = require('tap') const readdir = require('../lib/readdir-scoped.js') const { join } = require('path') t.test('readdir scoped', async (t) => { const dir = t.testdir({ '@org': { x: {}, y: {} }, '@scope': { x: {}, y: {} }, a: { x: {}, y: {} }, b: { x: {}, y: {} }, }) t.same( await readdir(dir), ['@org/x', '@org/y', '@scope/x', '@scope/y', 'a', 'b'].map((a) => join(a)) ) }) ��������������������������������������������������������������������������������������������������npm-fs-b473b15/test/with-temp-dir.js����������������������������������������������������������������0000664�0000000�0000000�00000004760�15076461761�0017276�0����������������������������������������������������������������������������������������������������ustar�00root����������������������������root����������������������������0000000�0000000������������������������������������������������������������������������������������������������������������������������������������������������������������������������const { lstat } = require('fs/promises') const { normalize } = require('path') const t = require('tap') const withTempDir = require('../lib/with-temp-dir.js') t.test('creates a temp directory and passes it to provided function', async (t) => { // normalize is necessary until https://github.com/tapjs/libtap/pull/40 is shipped const root = normalize(t.testdir()) const rootStat = await lstat(root) let tempDir await withTempDir(root, async (dir) => { tempDir = dir t.type(dir, 'string') t.ok(dir.startsWith(root), 'dir is contained within the root') const stat = await lstat(dir) t.ok(stat.isDirectory(), 'dir is an actual directory') t.equal(stat.uid, rootStat.uid, 'temp directory has same owning user') t.equal(stat.gid, rootStat.gid, 'temp directory has same owning group') }) await t.rejects(lstat(tempDir), { code: 'ENOENT' }, 'temp directory was removed') }) t.test('result from provided function bubbles out', async (t) => { // normalize is necessary until https://github.com/tapjs/libtap/pull/40 is shipped const root = normalize(t.testdir()) const rootStat = await lstat(root) let tempDir const result = await withTempDir(root, async (dir) => { tempDir = dir t.type(dir, 'string') t.ok(dir.startsWith(root), 'dir is contained within the root') const stat = await lstat(dir) t.ok(stat.isDirectory(), 'dir is an actual directory') t.equal(stat.uid, rootStat.uid, 'temp directory has same owning user') t.equal(stat.gid, rootStat.gid, 'temp directory has same owning group') return 'finished' }) t.equal(result, 'finished', 'resolved value is returned') await t.rejects(lstat(tempDir), { code: 'ENOENT' }, 'temp directory was removed') }) t.test('cleans up when provided function rejects', async (t) => { // normalize is necessary until https://github.com/tapjs/libtap/pull/40 is shipped const root = normalize(t.testdir()) const rootStat = await lstat(root) let tempDir await t.rejects(withTempDir(root, async (dir) => { tempDir = dir t.type(dir, 'string') t.ok(dir.startsWith(root), 'dir is contained within the root') const stat = await lstat(dir) t.ok(stat.isDirectory(), 'dir is an actual directory') t.equal(stat.uid, rootStat.uid, 'temp directory has same owning user') t.equal(stat.gid, rootStat.gid, 'temp directory has same owning group') throw new Error('this is bad') }), { message: 'this is bad' }) await t.rejects(lstat(tempDir), { code: 'ENOENT' }, 'temp directory was removed') }) ����������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������