@edgeros/fs 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@edgeros/fs",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "files": [
5
5
  "src",
6
6
  "package.json",
package/tsconfig.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "baseUrl": "."
16
16
  },
17
17
  "include": [
18
- "src/**/*",
18
+ "src/**/*", "_require.ts", "fs.ts",
19
19
  ],
20
20
  "exclude": [
21
21
  "tests/**/*"
package/src/_require.ts DELETED
@@ -1,21 +0,0 @@
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 DELETED
@@ -1,40 +0,0 @@
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
- }