-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.stale
Description
Is your feature request related to a problem? Please describe.
i am author of npm-package istanbul-lite.
when creating coverage-reports and artifacts,
its common to lazily write data to file-directories that have yet to be created.
Describe the solution you'd like
add extra boolean <options>.mkdirp
to functions fs.writeFile
and fs.writeFileSync
,
that will lazily create missing file-directories when writing to file.
the common-use-case are:
- lazily generate directories when writing coverage-report of instrumented files
- lazily generate directories when writing artifacts in ci and testing
- lazily generate directories when scaffolding new web-projects
Describe alternatives you've considered
i currently use this helper-function in all my projects,
to lazily generate directories when writing artifacts and coverage-reports.
function fsWriteFileWithMkdirpSync (file, data) {
/*
* this function will sync write <data> to <file> with "mkdir -p"
*/
let fs;
// do nothing if module does not exist
try {
fs = require("fs");
} catch (ignore) {
return;
}
// try to write file
try {
fs.writeFileSync(file, data);
return true;
} catch (ignore) {
// mkdir -p
fs.mkdirSync(require("path").dirname(file), {
recursive: true
});
// rewrite file
fs.writeFileSync(file, data);
return true;
}
};
himself65 and Kloovencjihrig
Metadata
Metadata
Assignees
Labels
feature requestIssues that request new features to be added to Node.js.Issues that request new features to be added to Node.js.fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.stale