@bleedingdev/modern-js-plugin 3.5.0-ultramodern.29 → 3.5.0-ultramodern.30

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,7 +37,8 @@ var __webpack_require__ = {};
37
37
  var __webpack_exports__ = {};
38
38
  __webpack_require__.r(__webpack_exports__);
39
39
  __webpack_require__.d(__webpack_exports__, {
40
- createFileWatcher: ()=>createFileWatcher
40
+ createFileWatcher: ()=>createFileWatcher,
41
+ safeReadFileSync: ()=>safeReadFileSync
41
42
  });
42
43
  const utils_namespaceObject = require("@modern-js/utils");
43
44
  const external_crypto_namespaceObject = require("crypto");
@@ -47,6 +48,14 @@ const external_path_namespaceObject = require("path");
47
48
  const debug = (0, utils_namespaceObject.createDebugger)('watch-files');
48
49
  const hashMap = new Map();
49
50
  const md5 = (data)=>external_crypto_default().createHash('md5').update(data).digest('hex');
51
+ const safeReadFileSync = (filePath)=>{
52
+ try {
53
+ return external_fs_namespaceObject.readFileSync(filePath, 'utf8');
54
+ } catch (err) {
55
+ if (err?.code === 'ENOENT') return;
56
+ throw err;
57
+ }
58
+ };
50
59
  const createFileWatcher = async (appContext)=>{
51
60
  if ((0, utils_namespaceObject.isDevCommand)()) {
52
61
  const { appDirectory } = appContext;
@@ -71,7 +80,9 @@ const createFileWatcher = async (appContext)=>{
71
80
  });
72
81
  watcher.on('change', (changed)=>{
73
82
  const lastHash = hashMap.get(changed);
74
- const currentHash = md5(external_fs_namespaceObject.readFileSync(external_path_namespaceObject.join(appDirectory, changed), 'utf8'));
83
+ const content = safeReadFileSync(external_path_namespaceObject.join(appDirectory, changed));
84
+ if (void 0 === content) return;
85
+ const currentHash = md5(content);
75
86
  if (currentHash !== lastHash) {
76
87
  debug("file change: %s", changed);
77
88
  hashMap.set(changed, currentHash);
@@ -84,7 +95,9 @@ const createFileWatcher = async (appContext)=>{
84
95
  });
85
96
  watcher.on('add', (changed)=>{
86
97
  debug("add file: %s", changed);
87
- const currentHash = md5(external_fs_namespaceObject.readFileSync(external_path_namespaceObject.join(appDirectory, changed), 'utf8'));
98
+ const content = safeReadFileSync(external_path_namespaceObject.join(appDirectory, changed));
99
+ if (void 0 === content) return;
100
+ const currentHash = md5(content);
88
101
  hashMap.set(changed, currentHash);
89
102
  appContext.hooks.onFileChanged.call({
90
103
  filename: changed,
@@ -108,8 +121,10 @@ const createFileWatcher = async (appContext)=>{
108
121
  }
109
122
  };
110
123
  exports.createFileWatcher = __webpack_exports__.createFileWatcher;
124
+ exports.safeReadFileSync = __webpack_exports__.safeReadFileSync;
111
125
  for(var __rspack_i in __webpack_exports__)if (-1 === [
112
- "createFileWatcher"
126
+ "createFileWatcher",
127
+ "safeReadFileSync"
113
128
  ].indexOf(__rspack_i)) exports[__rspack_i] = __webpack_exports__[__rspack_i];
114
129
  Object.defineProperty(exports, '__esModule', {
115
130
  value: true
@@ -5,6 +5,14 @@ import * as __rspack_external_path from "path";
5
5
  const debug = createDebugger('watch-files');
6
6
  const hashMap = new Map();
7
7
  const md5 = (data)=>crypto_0.createHash('md5').update(data).digest('hex');
8
+ const safeReadFileSync = (filePath)=>{
9
+ try {
10
+ return __rspack_external_fs.readFileSync(filePath, 'utf8');
11
+ } catch (err) {
12
+ if (err?.code === 'ENOENT') return;
13
+ throw err;
14
+ }
15
+ };
8
16
  const createFileWatcher = async (appContext)=>{
9
17
  if (isDevCommand()) {
10
18
  const { appDirectory } = appContext;
@@ -29,7 +37,9 @@ const createFileWatcher = async (appContext)=>{
29
37
  });
30
38
  watcher.on('change', (changed)=>{
31
39
  const lastHash = hashMap.get(changed);
32
- const currentHash = md5(__rspack_external_fs.readFileSync(__rspack_external_path.join(appDirectory, changed), 'utf8'));
40
+ const content = safeReadFileSync(__rspack_external_path.join(appDirectory, changed));
41
+ if (void 0 === content) return;
42
+ const currentHash = md5(content);
33
43
  if (currentHash !== lastHash) {
34
44
  debug("file change: %s", changed);
35
45
  hashMap.set(changed, currentHash);
@@ -42,7 +52,9 @@ const createFileWatcher = async (appContext)=>{
42
52
  });
43
53
  watcher.on('add', (changed)=>{
44
54
  debug("add file: %s", changed);
45
- const currentHash = md5(__rspack_external_fs.readFileSync(__rspack_external_path.join(appDirectory, changed), 'utf8'));
55
+ const content = safeReadFileSync(__rspack_external_path.join(appDirectory, changed));
56
+ if (void 0 === content) return;
57
+ const currentHash = md5(content);
46
58
  hashMap.set(changed, currentHash);
47
59
  appContext.hooks.onFileChanged.call({
48
60
  filename: changed,
@@ -65,4 +77,4 @@ const createFileWatcher = async (appContext)=>{
65
77
  return watcher;
66
78
  }
67
79
  };
68
- export { createFileWatcher };
80
+ export { createFileWatcher, safeReadFileSync };
@@ -6,6 +6,14 @@ import * as __rspack_external_path from "path";
6
6
  const debug = createDebugger('watch-files');
7
7
  const hashMap = new Map();
8
8
  const md5 = (data)=>crypto_0.createHash('md5').update(data).digest('hex');
9
+ const safeReadFileSync = (filePath)=>{
10
+ try {
11
+ return __rspack_external_fs.readFileSync(filePath, 'utf8');
12
+ } catch (err) {
13
+ if (err?.code === 'ENOENT') return;
14
+ throw err;
15
+ }
16
+ };
9
17
  const createFileWatcher = async (appContext)=>{
10
18
  if (isDevCommand()) {
11
19
  const { appDirectory } = appContext;
@@ -30,7 +38,9 @@ const createFileWatcher = async (appContext)=>{
30
38
  });
31
39
  watcher.on('change', (changed)=>{
32
40
  const lastHash = hashMap.get(changed);
33
- const currentHash = md5(__rspack_external_fs.readFileSync(__rspack_external_path.join(appDirectory, changed), 'utf8'));
41
+ const content = safeReadFileSync(__rspack_external_path.join(appDirectory, changed));
42
+ if (void 0 === content) return;
43
+ const currentHash = md5(content);
34
44
  if (currentHash !== lastHash) {
35
45
  debug("file change: %s", changed);
36
46
  hashMap.set(changed, currentHash);
@@ -43,7 +53,9 @@ const createFileWatcher = async (appContext)=>{
43
53
  });
44
54
  watcher.on('add', (changed)=>{
45
55
  debug("add file: %s", changed);
46
- const currentHash = md5(__rspack_external_fs.readFileSync(__rspack_external_path.join(appDirectory, changed), 'utf8'));
56
+ const content = safeReadFileSync(__rspack_external_path.join(appDirectory, changed));
57
+ if (void 0 === content) return;
58
+ const currentHash = md5(content);
47
59
  hashMap.set(changed, currentHash);
48
60
  appContext.hooks.onFileChanged.call({
49
61
  filename: changed,
@@ -66,4 +78,4 @@ const createFileWatcher = async (appContext)=>{
66
78
  return watcher;
67
79
  }
68
80
  };
69
- export { createFileWatcher };
81
+ export { createFileWatcher, safeReadFileSync };
@@ -1,3 +1,11 @@
1
1
  import type { InternalContext } from '../../../types';
2
2
  import type { CLIPluginExtends } from '../../../types/cli/plugin';
3
+ /**
4
+ * Editor temp files (e.g. `page.tsx.tmp.<pid>.<hash>`) can be created and
5
+ * deleted within a few milliseconds. chokidar may still deliver a
6
+ * `change`/`add` event after the file is already gone, which would make
7
+ * `fs.readFileSync` throw ENOENT and crash the (unhandled) watcher callback.
8
+ * Treat a vanished file as "nothing to read" instead of rethrowing.
9
+ */
10
+ export declare const safeReadFileSync: (filePath: string) => string | undefined;
3
11
  export declare const createFileWatcher: <Extends extends CLIPluginExtends>(appContext: InternalContext<Extends>) => Promise<import("@modern-js/utils").FSWatcher | undefined>;
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.5.0-ultramodern.29",
20
+ "version": "3.5.0-ultramodern.30",
21
21
  "types": "./dist/types/index.d.ts",
22
22
  "main": "./dist/cjs/index.js",
23
23
  "exports": {
@@ -87,9 +87,9 @@
87
87
  "@rsbuild/core": "2.1.1",
88
88
  "@swc/helpers": "^0.5.23",
89
89
  "jiti": "^2.7.0",
90
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.29",
91
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.29",
92
- "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.5.0-ultramodern.29"
90
+ "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.5.0-ultramodern.30",
91
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.30",
92
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.30"
93
93
  },
94
94
  "devDependencies": {
95
95
  "@rslib/core": "0.23.1",
@@ -97,7 +97,7 @@
97
97
  "@types/react": "^19.2.17",
98
98
  "@typescript/native-preview": "7.0.0-dev.20260628.1",
99
99
  "typescript": "^6.0.3",
100
- "@modern-js/builder": "npm:@bleedingdev/modern-js-builder@3.5.0-ultramodern.29"
100
+ "@modern-js/builder": "npm:@bleedingdev/modern-js-builder@3.5.0-ultramodern.30"
101
101
  },
102
102
  "sideEffects": false,
103
103
  "publishConfig": {