@bleedingdev/modern-js-plugin 3.5.0-ultramodern.8 → 3.5.0-ultramodern.80

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.
@@ -47,6 +47,7 @@ const external_jiti_namespaceObject = require("jiti");
47
47
  const external_path_namespaceObject = require("path");
48
48
  var external_path_default = /*#__PURE__*/ __webpack_require__.n(external_path_namespaceObject);
49
49
  const getConfigFilePath = (appDirectory, configFilePath)=>{
50
+ if (false === configFilePath) return false;
50
51
  if (external_path_default().isAbsolute(configFilePath)) return configFilePath;
51
52
  return external_path_default().resolve(appDirectory, configFilePath);
52
53
  };
@@ -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
@@ -2,6 +2,7 @@ import { compatibleRequire, fs, globby } from "@modern-js/utils";
2
2
  import { createJiti } from "jiti";
3
3
  import path from "path";
4
4
  const getConfigFilePath = (appDirectory, configFilePath)=>{
5
+ if (false === configFilePath) return false;
5
6
  if (path.isAbsolute(configFilePath)) return configFilePath;
6
7
  return path.resolve(appDirectory, configFilePath);
7
8
  };
@@ -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 };
@@ -5,6 +5,7 @@ import path from "path";
5
5
  import { fileURLToPath as __rspack_fileURLToPath } from "node:url";
6
6
  var __rspack_import_meta_filename__ = __rspack_fileURLToPath(import.meta.url);
7
7
  const getConfigFilePath = (appDirectory, configFilePath)=>{
8
+ if (false === configFilePath) return false;
8
9
  if (path.isAbsolute(configFilePath)) return configFilePath;
9
10
  return path.resolve(appDirectory, configFilePath);
10
11
  };
@@ -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 };
@@ -7,7 +7,7 @@ interface ContextParams<Extends extends CLIPluginExtends> {
7
7
  }
8
8
  export declare function initAppContext<Extends extends CLIPluginExtends>(params: {
9
9
  packageName: string;
10
- configFile: string;
10
+ configFile: string | false;
11
11
  command: string;
12
12
  appDirectory: string;
13
13
  metaName: string;
@@ -1,2 +1,2 @@
1
1
  import type { LoadedConfig } from '../types';
2
- export declare function createLoadedConfig<T>(appDirectory: string, configFilePath: string, otherConfig?: T): Promise<LoadedConfig<T>>;
2
+ export declare function createLoadedConfig<T>(appDirectory: string, configFilePath: string | false, otherConfig?: T): Promise<LoadedConfig<T>>;
@@ -1,4 +1,4 @@
1
- export declare const getConfigFilePath: (appDirectory: string, configFilePath: string) => string;
1
+ export declare const getConfigFilePath: (appDirectory: string, configFilePath: string | false) => string | false;
2
2
  /**
3
3
  *
4
4
  * @param targetDir target dir
@@ -17,9 +17,9 @@ export declare const clearFilesOverTime: (targetDir: string, overtime: number) =
17
17
  * @returns {any} - The loaded module object
18
18
  */
19
19
  export declare const loadTypeScriptFile: (filePath: string) => any;
20
- export declare const loadConfig: <T>(appDirectory: string, configFile: string) => Promise<{
20
+ export declare const loadConfig: <T>(appDirectory: string, configFile: string | false) => Promise<{
21
21
  packageName: string;
22
- configFile: string;
22
+ configFile: string | false;
23
23
  config?: T;
24
24
  pkgConfig?: T;
25
25
  }>;
@@ -14,13 +14,13 @@ export interface CLIOptions<Extends extends CLIPluginExtends = {
14
14
  * other config, overrides config file content
15
15
  */
16
16
  config?: Extends['config'];
17
- configFile: string;
17
+ configFile: string | false;
18
18
  internalPlugins?: Plugin[];
19
19
  handleSetupResult?: (params: any, api: Record<string, any>) => Promise<void> | void;
20
20
  }
21
21
  export type LoadedConfig<T> = {
22
22
  packageName: string;
23
- configFile: string;
23
+ configFile: string | false;
24
24
  config: T;
25
25
  pkgConfig?: T;
26
26
  jsConfig?: T;
@@ -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>;
@@ -12,7 +12,7 @@ export interface Entrypoint {
12
12
  export type AppContext<Extends extends CLIPluginExtends> = {
13
13
  metaName: string;
14
14
  packageName: string;
15
- configFile: string;
15
+ configFile: string | false;
16
16
  command: string;
17
17
  isProd: boolean;
18
18
  appDirectory: string;
package/package.json CHANGED
@@ -17,13 +17,12 @@
17
17
  "modern",
18
18
  "modern.js"
19
19
  ],
20
- "version": "3.5.0-ultramodern.8",
20
+ "version": "3.5.0-ultramodern.80",
21
21
  "types": "./dist/types/index.d.ts",
22
22
  "main": "./dist/cjs/index.js",
23
23
  "exports": {
24
24
  ".": {
25
25
  "types": "./dist/types/index.d.ts",
26
- "modern:source": "./src/index.ts",
27
26
  "node": {
28
27
  "module": "./dist/esm/index.mjs",
29
28
  "import": "./dist/esm-node/index.mjs",
@@ -33,7 +32,6 @@
33
32
  },
34
33
  "./run": {
35
34
  "types": "./dist/types/cli/run/index.d.ts",
36
- "modern:source": "./src/cli/run/index.ts",
37
35
  "node": {
38
36
  "import": "./dist/esm-node/cli/run/index.mjs",
39
37
  "require": "./dist/cjs/cli/run/index.js"
@@ -42,7 +40,6 @@
42
40
  },
43
41
  "./cli": {
44
42
  "types": "./dist/types/cli/index.d.ts",
45
- "modern:source": "./src/cli/index.ts",
46
43
  "node": {
47
44
  "import": "./dist/esm-node/cli/index.mjs",
48
45
  "require": "./dist/cjs/cli/index.js"
@@ -51,12 +48,10 @@
51
48
  },
52
49
  "./runtime": {
53
50
  "types": "./dist/types/runtime/index.d.ts",
54
- "modern:source": "./src/runtime/index.tsx",
55
51
  "default": "./dist/esm/runtime/index.mjs"
56
52
  },
57
53
  "./server": {
58
54
  "types": "./dist/types/server/index.d.ts",
59
- "modern:source": "./src/server/index.ts",
60
55
  "node": {
61
56
  "import": "./dist/esm-node/server/index.mjs",
62
57
  "require": "./dist/cjs/server/index.js"
@@ -84,24 +79,23 @@
84
79
  }
85
80
  },
86
81
  "dependencies": {
87
- "@rsbuild/core": "2.1.1",
82
+ "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.5.0-ultramodern.80",
83
+ "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.80",
84
+ "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.80",
85
+ "@rsbuild/core": "2.1.5",
88
86
  "@swc/helpers": "^0.5.23",
89
- "jiti": "^2.7.0",
90
- "@modern-js/runtime-utils": "npm:@bleedingdev/modern-js-runtime-utils@3.5.0-ultramodern.8",
91
- "@modern-js/utils": "npm:@bleedingdev/modern-js-utils@3.5.0-ultramodern.8",
92
- "@modern-js/types": "npm:@bleedingdev/modern-js-types@3.5.0-ultramodern.8"
87
+ "jiti": "^2.7.0"
93
88
  },
94
89
  "devDependencies": {
95
- "@rslib/core": "0.23.1",
96
- "@types/node": "^26.0.1",
90
+ "@modern-js/builder": "npm:@bleedingdev/modern-js-builder@3.5.0-ultramodern.80",
91
+ "@rslib/core": "0.23.2",
92
+ "@types/node": "^26.1.1",
97
93
  "@types/react": "^19.2.17",
98
- "@typescript/native-preview": "7.0.0-dev.20260628.1",
99
- "typescript": "^6.0.3",
100
- "@modern-js/builder": "npm:@bleedingdev/modern-js-builder@3.5.0-ultramodern.8"
94
+ "@typescript/native-preview": "7.0.0-dev.20260707.2",
95
+ "typescript": "^7.0.2"
101
96
  },
102
97
  "sideEffects": false,
103
98
  "publishConfig": {
104
- "registry": "https://registry.npmjs.org/",
105
99
  "access": "public"
106
100
  },
107
101
  "scripts": {