@edgeros/fs 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- package/eslint.config.js +45 -0
- package/package.json +2 -8
- package/src/_require.ts +21 -0
- package/src/fs.ts +40 -0
- package/src/index.ts +1 -0
- package/src/jsre/fs.js +44 -0
- package/src/node/fs.ts +20 -0
- package/tsconfig.json +20 -15
package/eslint.config.js
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
const { parse } = require('@typescript-eslint/parser')
|
2
|
+
const stylistic = require('@stylistic/eslint-plugin')
|
3
|
+
|
4
|
+
const files = [
|
5
|
+
'src/**/*.ts',
|
6
|
+
'src/**/*.js',
|
7
|
+
]
|
8
|
+
|
9
|
+
module.exports = (async () => {
|
10
|
+
const { default: love} = await import('eslint-config-love')
|
11
|
+
|
12
|
+
return [
|
13
|
+
{
|
14
|
+
ignores: [
|
15
|
+
'coverage/**',
|
16
|
+
'src/deps/jsre/**',
|
17
|
+
],
|
18
|
+
},
|
19
|
+
{
|
20
|
+
files,
|
21
|
+
languageOptions: {
|
22
|
+
parser: parse,
|
23
|
+
},
|
24
|
+
...love,
|
25
|
+
}, {
|
26
|
+
files,
|
27
|
+
...stylistic.configs.customize({
|
28
|
+
braceStyle: '1tbs'
|
29
|
+
}),
|
30
|
+
}, {
|
31
|
+
rules: {
|
32
|
+
'@typescript-eslint/explicit-function-return-type': 'off',
|
33
|
+
'@typescript-eslint/no-magic-numbers': 'off',
|
34
|
+
'@typescript-eslint/no-invalid-void-type': 'off',
|
35
|
+
'@typescript-eslint/no-unsafe-type-assertion': 'off',
|
36
|
+
'@typescript-eslint/no-unsafe-return': 'off',
|
37
|
+
'@typescript-eslint/strict-boolean-expressions': 'off',
|
38
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
39
|
+
'@typescript-eslint/prefer-nullish-coalescing': 'off',
|
40
|
+
'@typescript-eslint/prefer-destructuring': 'off',
|
41
|
+
'promise/avoid-new': 'off',
|
42
|
+
},
|
43
|
+
},
|
44
|
+
]
|
45
|
+
})()
|
package/package.json
CHANGED
@@ -1,15 +1,9 @@
|
|
1
1
|
{
|
2
2
|
"name": "@edgeros/fs",
|
3
|
-
"version": "0.1.
|
4
|
-
"
|
5
|
-
"src",
|
6
|
-
"package.json",
|
7
|
-
"tsconfig.json"
|
8
|
-
],
|
3
|
+
"version": "0.1.4",
|
4
|
+
"main" :"index.js",
|
9
5
|
"scripts": {
|
10
6
|
"build": "npx tsc",
|
11
|
-
"prepare": "npm run build",
|
12
|
-
"postinstall": "npm run build",
|
13
7
|
"lint": "npx eslint ."
|
14
8
|
},
|
15
9
|
"type": "commonjs",
|
package/src/_require.ts
ADDED
@@ -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/src/index.ts
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
export * from './fs'
|
package/src/jsre/fs.js
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
const fs = require('fs')
|
2
|
+
|
3
|
+
const brokerFs = {
|
4
|
+
|
5
|
+
createWriteStream: (path, options) => fs.createWriteStream(path, options),
|
6
|
+
|
7
|
+
stat: async (path) => await new Promise((resolve, reject) => {
|
8
|
+
try {
|
9
|
+
const stats = fs.statSync(path)
|
10
|
+
resolve(stats)
|
11
|
+
} catch (error) {
|
12
|
+
reject(new Error((error).message))
|
13
|
+
}
|
14
|
+
}),
|
15
|
+
|
16
|
+
rename: async (oldPath, newPath) => {
|
17
|
+
await new Promise((resolve, reject) => {
|
18
|
+
fs.rename(oldPath, newPath, (err) => {
|
19
|
+
if (err) {
|
20
|
+
reject(err)
|
21
|
+
} else {
|
22
|
+
resolve(undefined)
|
23
|
+
}
|
24
|
+
})
|
25
|
+
})
|
26
|
+
},
|
27
|
+
|
28
|
+
mkdir: async (path, options) => {
|
29
|
+
await new Promise((resolve, reject) => {
|
30
|
+
fs.mkdir(path, options, (err) => {
|
31
|
+
if (err) {
|
32
|
+
reject(err)
|
33
|
+
} else {
|
34
|
+
resolve(undefined)
|
35
|
+
}
|
36
|
+
})
|
37
|
+
})
|
38
|
+
},
|
39
|
+
mkdirSync: (path, options) => {
|
40
|
+
fs.mkdir(path, options.mode, !!options.recursive)
|
41
|
+
},
|
42
|
+
}
|
43
|
+
|
44
|
+
module.exports = brokerFs
|
package/src/node/fs.ts
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
import * as fs from 'fs/promises'
|
2
|
+
import { type PathLike, type WriteStream, createWriteStream, mkdirSync } from 'fs'
|
3
|
+
|
4
|
+
export interface BrokerFs {
|
5
|
+
createWriteStream: (options?: any) => WriteStream
|
6
|
+
stat: (path: PathLike) => Promise<any>
|
7
|
+
rename: (oldPath: PathLike, newPath: any) => Promise<void>
|
8
|
+
mkdir: (path: PathLike, options?: string | number) => Promise<void>
|
9
|
+
mkdirSync: (path: PathLike, options: string | number) => void
|
10
|
+
}
|
11
|
+
const brokerFs: BrokerFs = {
|
12
|
+
...fs,
|
13
|
+
createWriteStream,
|
14
|
+
stat: fs.stat,
|
15
|
+
rename: fs.rename,
|
16
|
+
mkdir: fs.mkdir,
|
17
|
+
mkdirSync,
|
18
|
+
}
|
19
|
+
|
20
|
+
export default brokerFs
|
package/tsconfig.json
CHANGED
@@ -1,23 +1,28 @@
|
|
1
1
|
{
|
2
|
-
"extends": "@tsconfig/node20/tsconfig.json",
|
3
2
|
"compilerOptions": {
|
4
|
-
|
5
|
-
"
|
6
|
-
"
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
"
|
11
|
-
"
|
12
|
-
"
|
13
|
-
|
14
|
-
|
15
|
-
|
3
|
+
/* Language and Environment */
|
4
|
+
"target": "es6", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */
|
5
|
+
"lib": [
|
6
|
+
"es6"
|
7
|
+
], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
|
8
|
+
/* Modules */
|
9
|
+
"module": "commonjs", /* Specify what module code is generated. */
|
10
|
+
"rootDir": "./src", /* Specify the root folder within your source files. */
|
11
|
+
"typeRoots": [
|
12
|
+
"./node_modules/@edgeros/jsre-types",
|
13
|
+
"./node_modules/@types",
|
14
|
+
], /* Specify multiple folders that act like './node_modules/@types'. */
|
15
|
+
"allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
16
|
+
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
17
|
+
"outDir": "dist", /* Specify an output folder for all emitted files. */
|
18
|
+
"esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */
|
19
|
+
"forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */
|
20
|
+
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
16
21
|
},
|
17
22
|
"include": [
|
18
|
-
"
|
23
|
+
"src/*",
|
19
24
|
],
|
20
25
|
"exclude": [
|
21
|
-
"
|
26
|
+
"node_modules",
|
22
27
|
]
|
23
28
|
}
|