镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

[22 regression] Breaks gulp with Cannot assign to read only property 'atime' of object '#<Stats>' #52707

Description

@nicolo-ribaudo

Version

v22.0.0

Platform

Linux

Subsystem

fs

What steps will reproduce the bug?

"use strict";
var fs = require("fs");
var stat = fs.statSync("./package.json")
stat.atime;
stat.atime = 2;

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

It should set stat.atime to 2

What do you see instead?

stat.atime = 2;
           ^

TypeError: Cannot assign to read only property 'atime' of object '#<Stats>'
    at Object.<anonymous> (/home/nic/Documents/dev/github.com/babel/babel/test.js:5:12)
    at Module._compile (node:internal/modules/cjs/loader:1455:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1534:10)
    at Module.load (node:internal/modules/cjs/loader:1265:32)
    at Module._load (node:internal/modules/cjs/loader:1081:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:187:14)
    at node:internal/main/run_main_module:28:49

Additional information

Original bug report: gulpjs/vinyl-fs#350

Caused by #50908

Activity

  1. added
    confirmed-bugIssues and PRs for confirmed bugs.
    fsIssues and PRs related to file-system APIs and the fs module.
    regressionIssues related to regressions.
    on Apr 26, 2024
  2. nicolo-ribaudo commented on Apr 26, 2024

    @nicolo-ribaudo
    ContributorAuthor

    I'm opening a PR

  3. trusktr commented on Apr 26, 2024

    @trusktr
    Contributor

    Is there a workaround for this with Gulp? I would ask over in

    but GitHub blocks me from commenting there (permissions of that repo allow certain people to comment only?).

  4. trusktr commented on Apr 28, 2024

    @trusktr
    Contributor

    I found a workaround for my case (but its common case, so maybe it helps someone):

    I didn't realize new versions of Node.js include recursive and filter options in various fs functions including cp. So I was able to delete gulp and rewrite this gulpfile.js,

    const {src, dest, series} = require('gulp')
    const {promises} = require('fs')
    
    async function mkDist() {
    	try { await promises.mkdir('./dist') } catch (e) { if (e.code !== 'EEXIST') throw e }
    }
    
    function copy() {
    	return src([ './src/**', '!./src/**/*.{ts,tsx}', './src/**/*.d.ts', ]).pipe(dest('./dist/'))
    }
    
    exports.copyAssets = series(mkDist, copy)

    to a plain Node.js script using the relatively new cp function with recursive and filter options:

    import fs from 'fs'
    
    async function mkDist() {
    	try { await fs.promises.mkdir('./dist') } catch (e) { if (e.code !== 'EEXIST') throw e }
    }
    
    await fs.promises.cp('./src', './dist', {
    	recursive: true,
    	filter: (src) => src.endsWith('.tsx') || (src.endsWith('.ts') && !src.endsWith('.d.ts')) ? false : true
    })

    Not bad! It used to be tedious to this sort of thing with plain Node prior to cp+recursive+filter, which I'm sure is why libraries like gulp/vinyl came to exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues and PRs for confirmed bugs.fsIssues and PRs related to file-system APIs and the fs module.regressionIssues related to regressions.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions