@modern-js/runtime-utils 2.65.3-alpha.0 → 2.65.4

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.
@@ -37,34 +37,44 @@ var import_storer = require("./storer");
37
37
  class FileReader {
38
38
  async readFile(path, encoding = "utf-8") {
39
39
  const { fs } = this;
40
- const cache = await this.storage.get(path);
41
- if (cache === null) {
42
- return null;
43
- }
44
- if (cache) {
45
- return this.encodingContent(cache, encoding);
46
- }
47
- const isExistFile = await new Promise((resolve) => {
48
- fs.stat(path, (err, stats) => {
49
- if (err) {
50
- resolve(false);
51
- return;
52
- }
53
- if (stats.isFile()) {
54
- resolve(true);
55
- } else {
56
- resolve(false);
57
- }
40
+ const _readfile = this._readFileFactory(fs);
41
+ return _readfile(path, encoding);
42
+ }
43
+ async readFileFromSystem(path, encoding = "utf-8") {
44
+ const _readfile = this._readFileFactory(import_fs_extra.default);
45
+ return _readfile(path, encoding);
46
+ }
47
+ _readFileFactory(fs) {
48
+ return async (path, encoding = "utf-8") => {
49
+ const cache = await this.storage.get(path);
50
+ if (cache === null) {
51
+ return null;
52
+ }
53
+ if (cache) {
54
+ return this.encodingContent(cache, encoding);
55
+ }
56
+ const isExistFile = await new Promise((resolve) => {
57
+ fs.stat(path, (err, stats) => {
58
+ if (err) {
59
+ resolve(false);
60
+ return;
61
+ }
62
+ if (stats.isFile()) {
63
+ resolve(true);
64
+ } else {
65
+ resolve(false);
66
+ }
67
+ });
58
68
  });
59
- });
60
- if (isExistFile) {
61
- const content = await fs.promises.readFile(path);
62
- this.storage.set(path, content);
63
- return this.encodingContent(content, encoding);
64
- } else {
65
- this.storage.set(path, null);
66
- return null;
67
- }
69
+ if (isExistFile) {
70
+ const content = await fs.promises.readFile(path);
71
+ this.storage.set(path, content);
72
+ return this.encodingContent(content, encoding);
73
+ } else {
74
+ this.storage.set(path, null);
75
+ return null;
76
+ }
77
+ };
68
78
  }
69
79
  /**
70
80
  * Clear the fileCache entriely.
@@ -15,76 +15,110 @@ var FileReader = /* @__PURE__ */ function() {
15
15
  var encoding = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "utf-8";
16
16
  var _this = this;
17
17
  return _async_to_generator(function() {
18
- var fs, cache, isExistFile, content;
18
+ var fs, _readfile;
19
19
  return _ts_generator(this, function(_state) {
20
- switch (_state.label) {
21
- case 0:
22
- fs = _this.fs;
23
- return [
24
- 4,
25
- _this.storage.get(path)
26
- ];
27
- case 1:
28
- cache = _state.sent();
29
- if (cache === null) {
20
+ fs = _this.fs;
21
+ _readfile = _this._readFileFactory(fs);
22
+ return [
23
+ 2,
24
+ _readfile(path, encoding)
25
+ ];
26
+ });
27
+ })();
28
+ };
29
+ _proto.readFileFromSystem = function readFileFromSystem(path) {
30
+ var encoding = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "utf-8";
31
+ var _this = this;
32
+ return _async_to_generator(function() {
33
+ var _readfile;
34
+ return _ts_generator(this, function(_state) {
35
+ _readfile = _this._readFileFactory(Fs);
36
+ return [
37
+ 2,
38
+ _readfile(path, encoding)
39
+ ];
40
+ });
41
+ })();
42
+ };
43
+ _proto._readFileFactory = function _readFileFactory(fs) {
44
+ var _this = this;
45
+ return function() {
46
+ var _ref = _async_to_generator(function(path) {
47
+ var encoding, cache, isExistFile, content;
48
+ var _arguments = arguments;
49
+ return _ts_generator(this, function(_state) {
50
+ switch (_state.label) {
51
+ case 0:
52
+ encoding = _arguments.length > 1 && _arguments[1] !== void 0 ? _arguments[1] : "utf-8";
53
+ return [
54
+ 4,
55
+ _this.storage.get(path)
56
+ ];
57
+ case 1:
58
+ cache = _state.sent();
59
+ if (cache === null) {
60
+ return [
61
+ 2,
62
+ null
63
+ ];
64
+ }
65
+ if (cache) {
66
+ return [
67
+ 2,
68
+ _this.encodingContent(cache, encoding)
69
+ ];
70
+ }
71
+ return [
72
+ 4,
73
+ new Promise(function(resolve) {
74
+ fs.stat(path, function(err, stats) {
75
+ if (err) {
76
+ resolve(false);
77
+ return;
78
+ }
79
+ if (stats.isFile()) {
80
+ resolve(true);
81
+ } else {
82
+ resolve(false);
83
+ }
84
+ });
85
+ })
86
+ ];
87
+ case 2:
88
+ isExistFile = _state.sent();
89
+ if (!isExistFile)
90
+ return [
91
+ 3,
92
+ 4
93
+ ];
94
+ return [
95
+ 4,
96
+ fs.promises.readFile(path)
97
+ ];
98
+ case 3:
99
+ content = _state.sent();
100
+ _this.storage.set(path, content);
30
101
  return [
31
102
  2,
32
- null
103
+ _this.encodingContent(content, encoding)
33
104
  ];
34
- }
35
- if (cache) {
105
+ case 4:
106
+ _this.storage.set(path, null);
36
107
  return [
37
108
  2,
38
- _this.encodingContent(cache, encoding)
109
+ null
39
110
  ];
40
- }
41
- return [
42
- 4,
43
- new Promise(function(resolve) {
44
- fs.stat(path, function(err, stats) {
45
- if (err) {
46
- resolve(false);
47
- return;
48
- }
49
- if (stats.isFile()) {
50
- resolve(true);
51
- } else {
52
- resolve(false);
53
- }
54
- });
55
- })
56
- ];
57
- case 2:
58
- isExistFile = _state.sent();
59
- if (!isExistFile)
111
+ case 5:
60
112
  return [
61
- 3,
62
- 4
113
+ 2
63
114
  ];
64
- return [
65
- 4,
66
- fs.promises.readFile(path)
67
- ];
68
- case 3:
69
- content = _state.sent();
70
- _this.storage.set(path, content);
71
- return [
72
- 2,
73
- _this.encodingContent(content, encoding)
74
- ];
75
- case 4:
76
- _this.storage.set(path, null);
77
- return [
78
- 2,
79
- null
80
- ];
81
- case 5:
82
- return [
83
- 2
84
- ];
85
- }
115
+ }
116
+ });
86
117
  });
87
- })();
118
+ return function(path) {
119
+ return _ref.apply(this, arguments);
120
+ };
121
+ }();
88
122
  };
89
123
  _proto.reset = function reset(fs) {
90
124
  var _this_storage_clear, _this_storage;
@@ -3,34 +3,44 @@ import { createMemoryStorage } from "./storer";
3
3
  class FileReader {
4
4
  async readFile(path, encoding = "utf-8") {
5
5
  const { fs } = this;
6
- const cache = await this.storage.get(path);
7
- if (cache === null) {
8
- return null;
9
- }
10
- if (cache) {
11
- return this.encodingContent(cache, encoding);
12
- }
13
- const isExistFile = await new Promise((resolve) => {
14
- fs.stat(path, (err, stats) => {
15
- if (err) {
16
- resolve(false);
17
- return;
18
- }
19
- if (stats.isFile()) {
20
- resolve(true);
21
- } else {
22
- resolve(false);
23
- }
6
+ const _readfile = this._readFileFactory(fs);
7
+ return _readfile(path, encoding);
8
+ }
9
+ async readFileFromSystem(path, encoding = "utf-8") {
10
+ const _readfile = this._readFileFactory(Fs);
11
+ return _readfile(path, encoding);
12
+ }
13
+ _readFileFactory(fs) {
14
+ return async (path, encoding = "utf-8") => {
15
+ const cache = await this.storage.get(path);
16
+ if (cache === null) {
17
+ return null;
18
+ }
19
+ if (cache) {
20
+ return this.encodingContent(cache, encoding);
21
+ }
22
+ const isExistFile = await new Promise((resolve) => {
23
+ fs.stat(path, (err, stats) => {
24
+ if (err) {
25
+ resolve(false);
26
+ return;
27
+ }
28
+ if (stats.isFile()) {
29
+ resolve(true);
30
+ } else {
31
+ resolve(false);
32
+ }
33
+ });
24
34
  });
25
- });
26
- if (isExistFile) {
27
- const content = await fs.promises.readFile(path);
28
- this.storage.set(path, content);
29
- return this.encodingContent(content, encoding);
30
- } else {
31
- this.storage.set(path, null);
32
- return null;
33
- }
35
+ if (isExistFile) {
36
+ const content = await fs.promises.readFile(path);
37
+ this.storage.set(path, content);
38
+ return this.encodingContent(content, encoding);
39
+ } else {
40
+ this.storage.set(path, null);
41
+ return null;
42
+ }
43
+ };
34
44
  }
35
45
  /**
36
46
  * Clear the fileCache entriely.
@@ -1,4 +1,6 @@
1
1
  /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import type { Buffer } from 'buffer';
2
4
  import Fs from '@modern-js/utils/fs-extra';
3
5
  import type { Storage } from './storer/storage';
4
6
  export declare class FileReader {
@@ -7,6 +9,9 @@ export declare class FileReader {
7
9
  constructor(storage: Storage<Buffer | null>);
8
10
  readFile(path: string, encoding?: 'utf-8'): Promise<string | null>;
9
11
  readFile(path: string, encoding?: 'buffer'): Promise<Buffer | null>;
12
+ readFileFromSystem(path: string, encoding?: 'utf-8'): Promise<string | null>;
13
+ readFileFromSystem(path: string, encoding?: 'buffer'): Promise<Buffer | null>;
14
+ _readFileFactory(fs: typeof Fs): (path: string, encoding?: 'utf-8' | 'buffer') => Promise<string | Buffer | null>;
10
15
  /**
11
16
  * Clear the fileCache entriely.
12
17
  */
@@ -6,11 +6,19 @@ declare const storage: {
6
6
  monitors?: Monitors | undefined;
7
7
  headers?: IncomingHttpHeaders | undefined;
8
8
  request?: Request | undefined;
9
+ responseProxy?: {
10
+ headers: Record<string, string>;
11
+ status: number;
12
+ } | undefined;
9
13
  }, cb: () => O | Promise<O>) => Promise<O>;
10
14
  useContext: () => {
11
15
  monitors?: Monitors | undefined;
12
16
  headers?: IncomingHttpHeaders | undefined;
13
17
  request?: Request | undefined;
18
+ responseProxy?: {
19
+ headers: Record<string, string>;
20
+ status: number;
21
+ } | undefined;
14
22
  };
15
23
  };
16
24
  type Storage = typeof storage;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.65.3-alpha.0",
18
+ "version": "2.65.4",
19
19
  "_comment": "Provide ESM and CJS exports, ESM is used by runtime package, for treeshaking",
20
20
  "exports": {
21
21
  "./router": {
@@ -91,7 +91,8 @@
91
91
  },
92
92
  "publishConfig": {
93
93
  "registry": "https://registry.npmjs.org/",
94
- "access": "public"
94
+ "access": "public",
95
+ "provenance": true
95
96
  },
96
97
  "typesVersions": {
97
98
  "*": {
@@ -145,8 +146,8 @@
145
146
  "lru-cache": "^10.4.3",
146
147
  "react-router-dom": "6.27.0",
147
148
  "serialize-javascript": "^6.0.0",
148
- "@modern-js/types": "2.65.2",
149
- "@modern-js/utils": "2.65.2"
149
+ "@modern-js/types": "2.65.4",
150
+ "@modern-js/utils": "2.65.4"
150
151
  },
151
152
  "peerDependencies": {
152
153
  "react": ">=17.0.0",
@@ -168,8 +169,8 @@
168
169
  "react": "^18.3.1",
169
170
  "react-dom": "^18.3.1",
170
171
  "typescript": "^5",
171
- "@scripts/build": "2.65.2",
172
- "@scripts/jest-config": "2.65.2"
172
+ "@scripts/build": "2.65.4",
173
+ "@scripts/jest-config": "2.65.4"
173
174
  },
174
175
  "sideEffects": false,
175
176
  "scripts": {