@file-services/node
Advanced tools
Comparing version 6.0.0 to 7.0.0
@@ -13,4 +13,2 @@ "use strict"; | ||
const watch_service_js_1 = require("./watch-service.js"); | ||
const nodeMajor = parseInt(process.versions.node, 10); | ||
const needsStatPolyfill = nodeMajor < 14; | ||
const caseSensitive = !fs_1.default.existsSync(__filename.toUpperCase()); | ||
@@ -23,3 +21,2 @@ const fsPromisesExists = (0, util_1.promisify)(fs_1.default.exists); | ||
function createBaseNodeFs(options) { | ||
var _a, _b; | ||
return { | ||
@@ -32,8 +29,4 @@ ...path_1.default, | ||
...fs_1.default, | ||
statSync: needsStatPolyfill ? statSync : fs_1.default.statSync, | ||
lstatSync: needsStatPolyfill ? lstatSync : fs_1.default.lstatSync, | ||
rmSync: (_a = fs_1.default.rmSync) !== null && _a !== void 0 ? _a : rmSync, | ||
promises: { | ||
...fs_1.default.promises, | ||
rm: (_b = fs_1.default.promises.rm) !== null && _b !== void 0 ? _b : rm, | ||
exists: fsPromisesExists, | ||
@@ -44,64 +37,2 @@ }, | ||
exports.createBaseNodeFs = createBaseNodeFs; | ||
function statSync(path, options) { | ||
var _a; | ||
try { | ||
return fs_1.default.statSync(path, options); | ||
} | ||
catch (e) { | ||
const throwIfNoEntry = (_a = options === null || options === void 0 ? void 0 : options.throwIfNoEntry) !== null && _a !== void 0 ? _a : true; | ||
if (throwIfNoEntry) { | ||
throw e; | ||
} | ||
else { | ||
return undefined; | ||
} | ||
} | ||
} | ||
function lstatSync(path, options) { | ||
var _a; | ||
try { | ||
return fs_1.default.lstatSync(path, options); | ||
} | ||
catch (e) { | ||
const throwIfNoEntry = (_a = options === null || options === void 0 ? void 0 : options.throwIfNoEntry) !== null && _a !== void 0 ? _a : true; | ||
if (throwIfNoEntry) { | ||
throw e; | ||
} | ||
else { | ||
return undefined; | ||
} | ||
} | ||
} | ||
function rmSync(path, { force, recursive } = {}) { | ||
if (recursive) { | ||
// when recursive is specified, we want to be able to delete both files and directories | ||
// we use rmdirSync in that case, as we know it exists and handles both cases in recursive mode | ||
if (!force) { | ||
// when force isn't specified, we want this function to throw if the path doesn't exist | ||
// since recursive rmdirSync never throws, we call statSync that throws ENOENT if path doesn't exist | ||
fs_1.default.statSync(path); | ||
} | ||
fs_1.default.rmdirSync(path, { recursive }); | ||
} | ||
else if (!force || fs_1.default.existsSync(path)) { | ||
// we check force or existance of path to match error throwing behavior | ||
fs_1.default.unlinkSync(path); | ||
} | ||
} | ||
async function rm(path, { force, recursive } = {}) { | ||
if (recursive) { | ||
// when recursive is specified, we want to be able to delete both files and directories | ||
// we use rmdir in that case, as we know it exists and handles both cases in recursive mode | ||
if (!force) { | ||
// when force isn't specified, we want this function to reject if the path doesn't exist | ||
// since recursive rmdir never rejects, we call stat that rejects ENOENT if path doesn't exist | ||
await fs_1.default.promises.stat(path); | ||
} | ||
await fs_1.default.promises.rmdir(path, { recursive }); | ||
} | ||
else if (!force || (await fsPromisesExists(path))) { | ||
// we check force or existance of path to match error rejection behavior | ||
await fs_1.default.promises.unlink(path); | ||
} | ||
} | ||
//# sourceMappingURL=node-fs.js.map |
{ | ||
"name": "@file-services/node", | ||
"description": "Node.js file system implementation.", | ||
"version": "6.0.0", | ||
"version": "7.0.0", | ||
"main": "dist/index.js", | ||
@@ -11,4 +11,4 @@ "scripts": { | ||
"dependencies": { | ||
"@file-services/types": "^6.0.0", | ||
"@file-services/utils": "^6.0.0" | ||
"@file-services/types": "^7.0.0", | ||
"@file-services/utils": "^7.0.0" | ||
}, | ||
@@ -22,3 +22,3 @@ "files": [ | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=14" | ||
}, | ||
@@ -25,0 +25,0 @@ "license": "MIT", |
@@ -7,14 +7,5 @@ import fs from 'fs'; | ||
import { createFileSystem } from '@file-services/utils'; | ||
import type { | ||
IBaseFileSystem, | ||
IFileSystem, | ||
IFileSystemPath, | ||
IFileSystemStats, | ||
RmOptions, | ||
StatSyncOptions, | ||
} from '@file-services/types'; | ||
import type { IBaseFileSystem, IFileSystem, IFileSystemPath } from '@file-services/types'; | ||
import { NodeWatchService, INodeWatchServiceOptions } from './watch-service.js'; | ||
const nodeMajor = parseInt(process.versions.node, 10); | ||
const needsStatPolyfill = nodeMajor < 14; | ||
const caseSensitive = !fs.existsSync(__filename.toUpperCase()); | ||
@@ -39,8 +30,4 @@ const fsPromisesExists = promisify(fs.exists); | ||
...fs, | ||
statSync: needsStatPolyfill ? statSync : fs.statSync, | ||
lstatSync: needsStatPolyfill ? lstatSync : fs.lstatSync, | ||
rmSync: fs.rmSync ?? rmSync, // node 12 fallback | ||
promises: { | ||
...fs.promises, | ||
rm: fs.promises.rm ?? rm, // node 12 fallback | ||
exists: fsPromisesExists, | ||
@@ -50,63 +37,1 @@ }, | ||
} | ||
function statSync(path: string, options?: StatSyncOptions & { throwIfNoEntry?: true }): IFileSystemStats; | ||
function statSync(path: string, options: StatSyncOptions & { throwIfNoEntry: false }): IFileSystemStats | undefined; | ||
function statSync(path: string, options?: StatSyncOptions): IFileSystemStats | undefined { | ||
try { | ||
return fs.statSync(path, options); | ||
} catch (e) { | ||
const throwIfNoEntry = options?.throwIfNoEntry ?? true; | ||
if (throwIfNoEntry) { | ||
throw e; | ||
} else { | ||
return undefined; | ||
} | ||
} | ||
} | ||
function lstatSync(path: string, options?: StatSyncOptions & { throwIfNoEntry?: true }): IFileSystemStats; | ||
function lstatSync(path: string, options: StatSyncOptions & { throwIfNoEntry: false }): IFileSystemStats | undefined; | ||
function lstatSync(path: string, options?: StatSyncOptions): IFileSystemStats | undefined { | ||
try { | ||
return fs.lstatSync(path, options); | ||
} catch (e) { | ||
const throwIfNoEntry = options?.throwIfNoEntry ?? true; | ||
if (throwIfNoEntry) { | ||
throw e; | ||
} else { | ||
return undefined; | ||
} | ||
} | ||
} | ||
function rmSync(path: string, { force, recursive }: RmOptions = {}): void { | ||
if (recursive) { | ||
// when recursive is specified, we want to be able to delete both files and directories | ||
// we use rmdirSync in that case, as we know it exists and handles both cases in recursive mode | ||
if (!force) { | ||
// when force isn't specified, we want this function to throw if the path doesn't exist | ||
// since recursive rmdirSync never throws, we call statSync that throws ENOENT if path doesn't exist | ||
fs.statSync(path); | ||
} | ||
fs.rmdirSync(path, { recursive }); | ||
} else if (!force || fs.existsSync(path)) { | ||
// we check force or existance of path to match error throwing behavior | ||
fs.unlinkSync(path); | ||
} | ||
} | ||
async function rm(path: string, { force, recursive }: RmOptions = {}): Promise<void> { | ||
if (recursive) { | ||
// when recursive is specified, we want to be able to delete both files and directories | ||
// we use rmdir in that case, as we know it exists and handles both cases in recursive mode | ||
if (!force) { | ||
// when force isn't specified, we want this function to reject if the path doesn't exist | ||
// since recursive rmdir never rejects, we call stat that rejects ENOENT if path doesn't exist | ||
await fs.promises.stat(path); | ||
} | ||
await fs.promises.rmdir(path, { recursive }); | ||
} else if (!force || (await fsPromisesExists(path))) { | ||
// we check force or existance of path to match error rejection behavior | ||
await fs.promises.unlink(path); | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28675
501
+ Added@file-services/types@7.4.0(transitive)
+ Added@file-services/utils@7.4.0(transitive)
- Removed@file-services/types@6.0.0(transitive)
- Removed@file-services/utils@6.0.0(transitive)
Updated@file-services/types@^7.0.0
Updated@file-services/utils@^7.0.0