@edgeros/fs 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
package/package.json ADDED
@@ -0,0 +1,31 @@
1
+ {
2
+ "name": "@edgeros/fs",
3
+ "version": "0.0.1",
4
+ "files": [
5
+ "src",
6
+ "package.json",
7
+ "tsconfig.json"
8
+ ],
9
+ "scripts": {
10
+ "build": "npx tsc",
11
+ "prepare": "npm run build",
12
+ "postinstall": "npm run build",
13
+ "lint": "npx eslint ."
14
+ },
15
+ "type": "commonjs",
16
+ "author": "liweikang@acoinfo.com",
17
+ "license": "MIT",
18
+ "devDependencies": {
19
+ "@stylistic/eslint-plugin": "^2.12.1",
20
+ "@tsconfig/node20": "^20.1.4",
21
+ "@types/node": "^20.1.4",
22
+ "@typescript-eslint/parser": "^8.18.2",
23
+ "eslint": "^9.17.0",
24
+ "eslint-config-love": "^113.0.0",
25
+ "husky": "^9.1.7",
26
+ "@types/jest": "^29.5.14",
27
+ "ts-jest": "^29.2.5",
28
+ "typescript": "^5.7.2",
29
+ "typescript-eslint": "^8.18.2"
30
+ }
31
+ }
@@ -0,0 +1,21 @@
1
+ // eslint-disable @typescript-eslint/no-unnecessary-type-parameters -- ignore
2
+ const isJSRE = () => {
3
+ try {
4
+ // eslint-disable-next-line @typescript-eslint/no-require-imports -- ignore
5
+ require('iosched')
6
+ } catch (e) {
7
+ return false
8
+ }
9
+
10
+ return true
11
+ }
12
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-parameters -- ignore
13
+ export default function<T = any> (moduleName: string): T {
14
+ if (isJSRE()) {
15
+ // eslint-disable-next-line @typescript-eslint/no-require-imports -- require is needed for dynamic imports
16
+ return require(`./jsre/${moduleName}`)
17
+ } else {
18
+ // eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-unsafe-member-access -- require is needed for dynamic imports and accessing default export
19
+ return require(`./node/${moduleName}`).default
20
+ }
21
+ }
package/src/fs.ts ADDED
@@ -0,0 +1,40 @@
1
+ import _require from './_require'
2
+ import type { PathLike, WriteStream, Stats } from 'fs'
3
+ export default _require<IFs>('fs')
4
+ export type { WriteStream } from 'fs'
5
+ export interface IFs {
6
+ WriteStream: WriteStream
7
+ createWriteStream: (path: PathLike, options?: StreamOptions) => WriteStream
8
+ stat: (path: PathLike) => Promise<Stats>
9
+ rename: (oldPath: PathLike, newPath: PathLike) => Promise<void>
10
+ mkdir: (path: PathLike, options?: any) => Promise<void>
11
+ mkdirSync: (path: PathLike, options: any) => void
12
+ }
13
+
14
+ export function createWriteStream(path: PathLike, options?: StreamOptions): WriteStream {
15
+ return _require<IFs>('fs').createWriteStream(path, options)
16
+ }
17
+
18
+ export async function stat(path: PathLike): Promise<Stats> {
19
+ return await _require<IFs>('fs').stat(path)
20
+ }
21
+
22
+ export async function rename(oldPath: PathLike, newPath: PathLike): Promise<void> {
23
+ await _require<IFs>('fs').rename(oldPath, newPath)
24
+ }
25
+
26
+ export async function mkdir(path: PathLike, options?: any): Promise<void> {
27
+ await _require<IFs>('fs').mkdir(path, options)
28
+ }
29
+
30
+ export function mkdirSync(path: PathLike, options: any): void {
31
+ _require<IFs>('fs').mkdirSync(path, options)
32
+ }
33
+
34
+ interface StreamOptions {
35
+ flags?: string | undefined
36
+ mode?: string | undefined
37
+ start?: number | undefined
38
+ autoClose?: boolean | undefined
39
+ emitClose?: boolean | undefined
40
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "extends": "@tsconfig/node20/tsconfig.json",
3
+ "compilerOptions": {
4
+ "declaration": true,
5
+ "outDir": "dist",
6
+ "inlineSourceMap": true,
7
+ "inlineSources": true,
8
+ "experimentalDecorators": true,
9
+ "emitDecoratorMetadata": true,
10
+ "allowJs": true,
11
+ "checkJs": false,
12
+ "strictNullChecks": true,
13
+ "module": "commonjs",
14
+ "moduleResolution": "node",
15
+ "baseUrl": "."
16
+ },
17
+ "include": [
18
+ "src/**/*",
19
+ ],
20
+ "exclude": [
21
+ "tests/**/*"
22
+ ]
23
+ }