@modern-js/utils 3.11.3 → 3.12.0

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.
@@ -70,7 +70,7 @@ const getCoreJsVersion = (corejsPkgPath)=>{
70
70
  const { version } = external_compiled_js_namespaceObject.fs.readJSONSync(corejsPkgPath);
71
71
  const [major, minor] = version.split('.');
72
72
  return `${major}.${minor}`;
73
- } catch (err) {
73
+ } catch {
74
74
  return '3';
75
75
  }
76
76
  };
@@ -28,6 +28,7 @@ var __webpack_require__ = {};
28
28
  var __webpack_exports__ = {};
29
29
  __webpack_require__.r(__webpack_exports__);
30
30
  __webpack_require__.d(__webpack_exports__, {
31
+ getSSGEntryOptions: ()=>getSSGEntryOptions,
31
32
  isSSGEntry: ()=>isSSGEntry,
32
33
  isSSR: ()=>isSSR,
33
34
  isServiceWorker: ()=>isServiceWorker,
@@ -56,18 +57,16 @@ const isServiceWorker = (config)=>{
56
57
  if (deploy?.worker?.ssr && (output?.ssg || isSSR(config))) return true;
57
58
  return false;
58
59
  };
59
- const isSSGEntry = (config, entryName, entrypoints)=>{
60
- const { output, source } = config;
61
- const single = isSingleEntry(entrypoints, source?.mainEntryName);
62
- if (single) {
63
- const byEntries = output?.ssgByEntries;
64
- return Boolean(output?.ssg) || byEntries && !(0, external_type_js_namespaceObject.isEmpty)(byEntries);
65
- }
66
- const byEntries = output?.ssgByEntries;
67
- if (!byEntries || (0, external_type_js_namespaceObject.isEmpty)(byEntries)) return false;
68
- return Boolean(byEntries[entryName]);
60
+ const getSSGEntryOptions = (entryName, ssg, ssgByEntries)=>{
61
+ if (ssgByEntries && !(0, external_type_js_namespaceObject.isEmpty)(ssgByEntries)) return ssgByEntries[entryName];
62
+ return Array.isArray(ssg) ? ssg.at(-1) : ssg;
63
+ };
64
+ const isSSGEntry = (config, entryName, _entrypoints)=>{
65
+ const { ssg, ssgByEntries } = config?.output ?? {};
66
+ return Boolean(getSSGEntryOptions(entryName, ssg, ssgByEntries));
69
67
  };
70
68
  const isSingleEntry = (entrypoints, mainEntryName = external_constants_js_namespaceObject.MAIN_ENTRY_NAME)=>1 === entrypoints.length && entrypoints[0].entryName === mainEntryName;
69
+ exports.getSSGEntryOptions = __webpack_exports__.getSSGEntryOptions;
71
70
  exports.isSSGEntry = __webpack_exports__.isSSGEntry;
72
71
  exports.isSSR = __webpack_exports__.isSSR;
73
72
  exports.isServiceWorker = __webpack_exports__.isServiceWorker;
@@ -75,6 +74,7 @@ exports.isSingleEntry = __webpack_exports__.isSingleEntry;
75
74
  exports.isUseRsc = __webpack_exports__.isUseRsc;
76
75
  exports.isUseSSRBundle = __webpack_exports__.isUseSSRBundle;
77
76
  for(var __rspack_i in __webpack_exports__)if (-1 === [
77
+ "getSSGEntryOptions",
78
78
  "isSSGEntry",
79
79
  "isSSR",
80
80
  "isServiceWorker",
@@ -72,7 +72,7 @@ const isPackageInstalled = (name, resolvePaths)=>{
72
72
  try {
73
73
  (0, external_require_js_namespaceObject.tryResolve)(name, ...(0, external_ensure_js_namespaceObject.ensureArray)(resolvePaths));
74
74
  return true;
75
- } catch (err) {
75
+ } catch {
76
76
  return false;
77
77
  }
78
78
  };
@@ -49,7 +49,7 @@ async function canUseNpm() {
49
49
  env: process.env
50
50
  });
51
51
  return true;
52
- } catch (e) {
52
+ } catch {
53
53
  return false;
54
54
  }
55
55
  }
@@ -61,7 +61,7 @@ async function canUseYarn() {
61
61
  env: process.env
62
62
  });
63
63
  return true;
64
- } catch (e) {
64
+ } catch {
65
65
  return false;
66
66
  }
67
67
  }
@@ -73,7 +73,7 @@ async function canUsePnpm() {
73
73
  env: process.env
74
74
  });
75
75
  return true;
76
- } catch (e) {
76
+ } catch {
77
77
  return false;
78
78
  }
79
79
  }
@@ -64,8 +64,8 @@ async function compatibleRequireCJS(path, interop = true) {
64
64
  const requiredModule = require(path);
65
65
  return interop && requiredModule?.__esModule ? requiredModule.default : requiredModule;
66
66
  } catch (err) {
67
- if ('ERR_REQUIRE_ESM' === err.code) return await compatibleRequireESM(path, interop);
68
- else throw err;
67
+ if (err?.code === 'ERR_REQUIRE_ESM' || err?.code === 'ERR_REQUIRE_ASYNC_MODULE') return await compatibleRequireESM(path, interop);
68
+ throw err;
69
69
  }
70
70
  }
71
71
  async function compatibleRequire(path, interop = true) {
@@ -23,7 +23,7 @@ const getCoreJsVersion = (corejsPkgPath)=>{
23
23
  const { version } = fs.readJSONSync(corejsPkgPath);
24
24
  const [major, minor] = version.split('.');
25
25
  return `${major}.${minor}`;
26
- } catch (err) {
26
+ } catch {
27
27
  return '3';
28
28
  }
29
29
  };
@@ -19,16 +19,13 @@ const isServiceWorker = (config)=>{
19
19
  if (deploy?.worker?.ssr && (output?.ssg || isSSR(config))) return true;
20
20
  return false;
21
21
  };
22
- const isSSGEntry = (config, entryName, entrypoints)=>{
23
- const { output, source } = config;
24
- const single = isSingleEntry(entrypoints, source?.mainEntryName);
25
- if (single) {
26
- const byEntries = output?.ssgByEntries;
27
- return Boolean(output?.ssg) || byEntries && !isEmpty(byEntries);
28
- }
29
- const byEntries = output?.ssgByEntries;
30
- if (!byEntries || isEmpty(byEntries)) return false;
31
- return Boolean(byEntries[entryName]);
22
+ const getSSGEntryOptions = (entryName, ssg, ssgByEntries)=>{
23
+ if (ssgByEntries && !isEmpty(ssgByEntries)) return ssgByEntries[entryName];
24
+ return Array.isArray(ssg) ? ssg.at(-1) : ssg;
25
+ };
26
+ const isSSGEntry = (config, entryName, _entrypoints)=>{
27
+ const { ssg, ssgByEntries } = config?.output ?? {};
28
+ return Boolean(getSSGEntryOptions(entryName, ssg, ssgByEntries));
32
29
  };
33
30
  const isSingleEntry = (entrypoints, mainEntryName = MAIN_ENTRY_NAME)=>1 === entrypoints.length && entrypoints[0].entryName === mainEntryName;
34
- export { isSSGEntry, isSSR, isServiceWorker, isSingleEntry, isUseRsc, isUseSSRBundle };
31
+ export { getSSGEntryOptions, isSSGEntry, isSSR, isServiceWorker, isSingleEntry, isUseRsc, isUseSSRBundle };
@@ -20,7 +20,7 @@ const isPackageInstalled = (name, resolvePaths)=>{
20
20
  try {
21
21
  tryResolve(name, ...ensureArray(resolvePaths));
22
22
  return true;
23
- } catch (err) {
23
+ } catch {
24
24
  return false;
25
25
  }
26
26
  };
@@ -13,7 +13,7 @@ async function canUseNpm() {
13
13
  env: process.env
14
14
  });
15
15
  return true;
16
- } catch (e) {
16
+ } catch {
17
17
  return false;
18
18
  }
19
19
  }
@@ -25,7 +25,7 @@ async function canUseYarn() {
25
25
  env: process.env
26
26
  });
27
27
  return true;
28
- } catch (e) {
28
+ } catch {
29
29
  return false;
30
30
  }
31
31
  }
@@ -37,7 +37,7 @@ async function canUsePnpm() {
37
37
  env: process.env
38
38
  });
39
39
  return true;
40
- } catch (e) {
40
+ } catch {
41
41
  return false;
42
42
  }
43
43
  }
@@ -67,7 +67,7 @@ const tryResolveESM = (name, ...resolvePath)=>{
67
67
  ]);
68
68
  for (const p of resolvePath)try {
69
69
  return moduleResolve(name, pathToFileURL(`${p}/`), conditions, false).pathname.replace(/^\/(\w)\:/, '$1:');
70
- } catch (err) {}
70
+ } catch {}
71
71
  const err = new Error(`Can not find module ${name}.`);
72
72
  err.code = 'MODULE_NOT_FOUND';
73
73
  throw err;
@@ -24,7 +24,7 @@ const getCoreJsVersion = (corejsPkgPath)=>{
24
24
  const { version } = fs.readJSONSync(corejsPkgPath);
25
25
  const [major, minor] = version.split('.');
26
26
  return `${major}.${minor}`;
27
- } catch (err) {
27
+ } catch {
28
28
  return '3';
29
29
  }
30
30
  };
@@ -20,16 +20,13 @@ const isServiceWorker = (config)=>{
20
20
  if (deploy?.worker?.ssr && (output?.ssg || isSSR(config))) return true;
21
21
  return false;
22
22
  };
23
- const isSSGEntry = (config, entryName, entrypoints)=>{
24
- const { output, source } = config;
25
- const single = isSingleEntry(entrypoints, source?.mainEntryName);
26
- if (single) {
27
- const byEntries = output?.ssgByEntries;
28
- return Boolean(output?.ssg) || byEntries && !isEmpty(byEntries);
29
- }
30
- const byEntries = output?.ssgByEntries;
31
- if (!byEntries || isEmpty(byEntries)) return false;
32
- return Boolean(byEntries[entryName]);
23
+ const getSSGEntryOptions = (entryName, ssg, ssgByEntries)=>{
24
+ if (ssgByEntries && !isEmpty(ssgByEntries)) return ssgByEntries[entryName];
25
+ return Array.isArray(ssg) ? ssg.at(-1) : ssg;
26
+ };
27
+ const isSSGEntry = (config, entryName, _entrypoints)=>{
28
+ const { ssg, ssgByEntries } = config?.output ?? {};
29
+ return Boolean(getSSGEntryOptions(entryName, ssg, ssgByEntries));
33
30
  };
34
31
  const isSingleEntry = (entrypoints, mainEntryName = MAIN_ENTRY_NAME)=>1 === entrypoints.length && entrypoints[0].entryName === mainEntryName;
35
- export { isSSGEntry, isSSR, isServiceWorker, isSingleEntry, isUseRsc, isUseSSRBundle };
32
+ export { getSSGEntryOptions, isSSGEntry, isSSR, isServiceWorker, isSingleEntry, isUseRsc, isUseSSRBundle };
@@ -21,7 +21,7 @@ const isPackageInstalled = (name, resolvePaths)=>{
21
21
  try {
22
22
  tryResolve(name, ...ensureArray(resolvePaths));
23
23
  return true;
24
- } catch (err) {
24
+ } catch {
25
25
  return false;
26
26
  }
27
27
  };
@@ -14,7 +14,7 @@ async function canUseNpm() {
14
14
  env: process.env
15
15
  });
16
16
  return true;
17
- } catch (e) {
17
+ } catch {
18
18
  return false;
19
19
  }
20
20
  }
@@ -26,7 +26,7 @@ async function canUseYarn() {
26
26
  env: process.env
27
27
  });
28
28
  return true;
29
- } catch (e) {
29
+ } catch {
30
30
  return false;
31
31
  }
32
32
  }
@@ -38,7 +38,7 @@ async function canUsePnpm() {
38
38
  env: process.env
39
39
  });
40
40
  return true;
41
- } catch (e) {
41
+ } catch {
42
42
  return false;
43
43
  }
44
44
  }
@@ -68,7 +68,7 @@ const tryResolveESM = (name, ...resolvePath)=>{
68
68
  ]);
69
69
  for (const p of resolvePath)try {
70
70
  return moduleResolve(name, pathToFileURL(`${p}/`), conditions, false).pathname.replace(/^\/(\w)\:/, '$1:');
71
- } catch (err) {}
71
+ } catch {}
72
72
  const err = new Error(`Can not find module ${name}.`);
73
73
  err.code = 'MODULE_NOT_FOUND';
74
74
  throw err;
@@ -1,3 +1,4 @@
1
+ import type { SSGConfig, SSGMultiEntryOptions } from '@modern-js/types';
1
2
  interface EntryPoint {
2
3
  entryName: string;
3
4
  }
@@ -17,6 +18,7 @@ export declare const isUseRsc: (config: any) => boolean;
17
18
  * @returns Whether to use worker deploy.
18
19
  */
19
20
  export declare const isServiceWorker: (config: any) => boolean;
20
- export declare const isSSGEntry: (config: any, entryName: string, entrypoints: EntryPoint[]) => any;
21
+ export declare const getSSGEntryOptions: (entryName: string, ssg: SSGConfig | SSGConfig[] | undefined, ssgByEntries?: SSGMultiEntryOptions) => SSGConfig | undefined;
22
+ export declare const isSSGEntry: (config: any, entryName: string, _entrypoints?: EntryPoint[]) => boolean;
21
23
  export declare const isSingleEntry: (entrypoints: EntryPoint[], mainEntryName?: string) => boolean;
22
24
  export {};
@@ -1,7 +1,7 @@
1
1
  export declare function isString(str: any): str is string;
2
2
  export declare function isUndefined(obj: any): obj is undefined;
3
3
  export declare function isArray(obj: unknown): obj is any[];
4
- export declare function isFunction(func: any): func is Function;
4
+ export declare function isFunction(func: any): func is (...args: any[]) => any;
5
5
  export declare function isObject(obj: unknown): obj is Record<string, any>;
6
6
  export declare function isPlainObject(obj: unknown): obj is Record<string, any>;
7
7
  export declare function isPromise(obj: any): obj is Promise<any>;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "3.11.3",
18
+ "version": "3.12.0",
19
19
  "types": "./dist/types/index.d.ts",
20
20
  "main": "./dist/cjs/index.js",
21
21
  "module": "./dist/esm/index.mjs",
@@ -145,9 +145,9 @@
145
145
  "@types/node": "^20",
146
146
  "happy-dom": "^21.0.4",
147
147
  "typescript": "^5",
148
- "@modern-js/rslib": "3.11.3",
149
- "@modern-js/types": "3.11.3",
150
- "@scripts/rstest-config": "2.66.7"
148
+ "@modern-js/types": "3.12.0",
149
+ "@modern-js/rslib": "3.12.0",
150
+ "@scripts/rstest-config": "2.66.8"
151
151
  },
152
152
  "peerDependencies": {
153
153
  "react": "^19.3.1",