refactor: replace fs-extra with node:fs (#1772)

* spec: add devDependencies "tmp"
This commit is contained in:
エリス
2025-01-29 10:39:11 +09:00
committed by GitHub
parent b623311efa
commit e012478537
20 changed files with 188 additions and 164 deletions
+8 -8
View File
@@ -14,7 +14,7 @@
*
*/
const fs = require('fs-extra');
const fs = require('node:fs');
const path = require('node:path');
const isPathInside = require('is-path-inside');
const events = require('cordova-common').events;
@@ -166,13 +166,13 @@ const handlers = {
scriptContent = 'cordova.define("' + moduleName + '", function(require, exports, module) {\n' + scriptContent + '\n});\n';
const wwwDest = path.resolve(project.www, 'plugins', plugin.id, obj.src);
fs.ensureDirSync(path.dirname(wwwDest));
fs.mkdirSync(path.dirname(wwwDest), { recursive: true });
fs.writeFileSync(wwwDest, scriptContent, 'utf-8');
if (options && options.usePlatformWww) {
// CB-11022 copy file to both directories if usePlatformWww is specified
const platformWwwDest = path.resolve(project.platformWww, 'plugins', plugin.id, obj.src);
fs.ensureDirSync(path.dirname(platformWwwDest));
fs.mkdirSync(path.dirname(platformWwwDest), { recursive: true });
fs.writeFileSync(platformWwwDest, scriptContent, 'utf-8');
}
},
@@ -217,11 +217,11 @@ function copyFile (plugin_dir, src, project_dir, dest, link) {
// check that dest path is located in project directory
if (!isPathInside(dest, project_dir)) { throw new CordovaError('Destination "' + dest + '" for source file "' + src + '" is located outside the project'); }
fs.ensureDirSync(path.dirname(dest));
fs.mkdirSync(path.dirname(dest), { recursive: true });
if (link) {
symlinkFileOrDirTree(src, dest);
} else {
fs.copySync(src, dest);
fs.cpSync(src, dest, { recursive: true });
}
}
@@ -235,11 +235,11 @@ function copyNewFile (plugin_dir, src, project_dir, dest, link) {
function symlinkFileOrDirTree (src, dest) {
if (fs.existsSync(dest)) {
fs.removeSync(dest);
fs.rmSync(dest, { recursive: true, force: true });
}
if (fs.statSync(src).isDirectory()) {
fs.ensureDirSync(path.dirname(dest));
fs.mkdirSync(path.dirname(dest), { recursive: true });
fs.readdirSync(src).forEach(function (entry) {
symlinkFileOrDirTree(path.join(src, entry), path.join(dest, entry));
});
@@ -249,7 +249,7 @@ function symlinkFileOrDirTree (src, dest) {
}
function removeFile (file) {
fs.removeSync(file);
fs.rmSync(file);
}
// Sometimes we want to remove some java, and prune any unnecessary empty directories