Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nicolo-ribaudo opened this issue Apr 26, 2024 · 3 comments · Fixed by #52708
Labels
confirmed-bug Issues with confirmed bugs. fs Issues and PRs related to the fs subsystem / file system. regression Issues related to regressions.

Comments

@nicolo-ribaudo
Copy link
Contributor

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

@RedYetiDev RedYetiDev added confirmed-bug Issues with confirmed bugs. fs Issues and PRs related to the fs subsystem / file system. regression Issues related to regressions. labels Apr 26, 2024
@nicolo-ribaudo
Copy link
Contributor Author

I'm opening a PR

@trusktr
Copy link
Contributor

trusktr commented Apr 26, 2024

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?).

@trusktr
Copy link
Contributor

trusktr commented Apr 28, 2024

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
Labels
confirmed-bug Issues with confirmed bugs. fs Issues and PRs related to the fs subsystem / file system. regression Issues related to regressions.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants