@edgeros/fs 0.1.1 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Makefile ADDED
@@ -0,0 +1,32 @@
1
+ .PHONY: build compile install clean publish ts-clean
2
+
3
+ JSRE_MODULES_DIR = ./jsre_modules
4
+ NODE_MODULES = ./node_modules
5
+ JSRE_DEPENDENCIES = @edgeros/jsre-types @edgeros/jsre-tape
6
+ TS_OUTDIR= ./dist
7
+
8
+ install:
9
+ npm i
10
+
11
+ ts-clean:
12
+ rm -rf $(TS_OUTDIR)
13
+
14
+ compile: ts-clean
15
+ tsc
16
+
17
+ build: compile
18
+ for dep in $(JSRE_DEPENDENCIES); do \
19
+ mkdir -p $(JSRE_MODULES_DIR)/$$dep && \
20
+ cp -r $(NODE_MODULES)/$$dep/* $(JSRE_MODULES_DIR)/$$dep; \
21
+ done
22
+
23
+ clean:
24
+ rm -rf ./dist
25
+ rm -rf ./node_modules
26
+ rm -rf ./jsre_modules
27
+
28
+ publish: compile
29
+ cp .npmrc $(TS_OUTDIR)/
30
+ cp package.json $(TS_OUTDIR)/
31
+ cp README.md $(TS_OUTDIR)/
32
+ cd $(TS_OUTDIR) && npm publish
@@ -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.1",
4
- "files": [
5
- "src",
6
- "package.json",
7
- "tsconfig.json"
8
- ],
3
+ "version": "0.1.3",
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",
@@ -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 './src/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
@@ -15,9 +15,6 @@
15
15
  "baseUrl": "."
16
16
  },
17
17
  "include": [
18
- "*",
19
- ],
20
- "exclude": [
21
- "tests/**/*"
18
+ "src/**/*",
22
19
  ]
23
20
  }