@modern-js/utils 2.65.3 → 2.65.5

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.
Files changed (48) hide show
  1. package/dist/cjs/cli/is/project.js +27 -25
  2. package/dist/compiled/ajv/codegen.js +1 -0
  3. package/dist/compiled/ajv/index.js +9 -0
  4. package/dist/compiled/ajv/license +22 -0
  5. package/dist/compiled/ajv/package.json +1 -0
  6. package/dist/compiled/ajv/types/ajv.d.ts +16 -0
  7. package/dist/compiled/ajv/types/compile/codegen/code.d.ts +40 -0
  8. package/dist/compiled/ajv/types/compile/codegen/index.d.ts +79 -0
  9. package/dist/compiled/ajv/types/compile/codegen/scope.d.ts +79 -0
  10. package/dist/compiled/ajv/types/compile/errors.d.ts +13 -0
  11. package/dist/compiled/ajv/types/compile/index.d.ts +80 -0
  12. package/dist/compiled/ajv/types/compile/ref_error.d.ts +6 -0
  13. package/dist/compiled/ajv/types/compile/resolve.d.ts +12 -0
  14. package/dist/compiled/ajv/types/compile/rules.d.ts +28 -0
  15. package/dist/compiled/ajv/types/compile/util.d.ts +40 -0
  16. package/dist/compiled/ajv/types/compile/validate/index.d.ts +42 -0
  17. package/dist/compiled/ajv/types/compile/validate/subschema.d.ts +47 -0
  18. package/dist/compiled/ajv/types/core.d.ts +173 -0
  19. package/dist/compiled/ajv/types/runtime/validation_error.d.ts +7 -0
  20. package/dist/compiled/ajv/types/types/index.d.ts +183 -0
  21. package/dist/compiled/ajv/types/types/json-schema.d.ts +124 -0
  22. package/dist/compiled/ajv/types/types/jtd-schema.d.ts +169 -0
  23. package/dist/compiled/ajv/types/vocabularies/errors.d.ts +1 -0
  24. package/dist/compiled/ajv/uri-js.d.ts +59 -0
  25. package/dist/compiled/ajv-keywords/index.d.ts +1 -0
  26. package/dist/compiled/ajv-keywords/index.js +1 -0
  27. package/dist/compiled/ajv-keywords/license +21 -0
  28. package/dist/compiled/ajv-keywords/package.json +1 -0
  29. package/dist/compiled/better-ajv-errors/index.d.ts +1 -0
  30. package/dist/compiled/better-ajv-errors/index.js +1 -0
  31. package/dist/compiled/better-ajv-errors/license +13 -0
  32. package/dist/compiled/better-ajv-errors/package.json +1 -0
  33. package/dist/compiled/recursive-readdir/index.d.ts +21 -0
  34. package/dist/compiled/recursive-readdir/index.js +1 -0
  35. package/dist/compiled/recursive-readdir/license +21 -0
  36. package/dist/compiled/recursive-readdir/package.json +1 -0
  37. package/dist/compiled/schema-utils3/index.d.ts +1 -0
  38. package/dist/compiled/schema-utils3/index.js +3 -0
  39. package/dist/compiled/schema-utils3/license +20 -0
  40. package/dist/compiled/schema-utils3/package.json +1 -0
  41. package/dist/compiled/webpack-dev-middleware/index.js +7 -0
  42. package/dist/compiled/webpack-dev-middleware/license +20 -0
  43. package/dist/compiled/webpack-dev-middleware/package.json +1 -0
  44. package/dist/compiled/webpack-dev-middleware/types/index.d.ts +262 -0
  45. package/dist/esm/cli/is/project.js +26 -19
  46. package/dist/esm-node/cli/is/project.js +26 -25
  47. package/dist/types/cli/is/project.d.ts +1 -0
  48. package/package.json +5 -6
@@ -41,7 +41,7 @@ const isWebOnly = async () => {
41
41
  const isVersionBeyond17 = (version) => {
42
42
  return semver.gte(semver.minVersion(version), "17.0.0");
43
43
  };
44
- const isBeyondReact17 = (cwd) => {
44
+ const getReactVersion = (cwd) => {
45
45
  const pkgPath = pkgUp.sync({
46
46
  cwd
47
47
  });
@@ -56,42 +56,43 @@ const isBeyondReact17 = (cwd) => {
56
56
  if (typeof deps.react !== "string") {
57
57
  return false;
58
58
  }
59
- return isVersionBeyond17(deps.react);
60
- };
61
- const isSupportAutomaticJsx = (cwd) => {
62
- const pkgPath = pkgUp.sync({
63
- cwd
64
- });
65
- if (!pkgPath) {
59
+ try {
60
+ const reactPath = require.resolve("react/package.json", {
61
+ paths: [
62
+ cwd
63
+ ]
64
+ });
65
+ const reactVersion = JSON.parse(fs.readFileSync(reactPath, "utf8")).version;
66
+ return reactVersion;
67
+ } catch (error) {
68
+ console.error("Failed to resolve React version:", error);
66
69
  return false;
67
70
  }
68
- const pkgInfo = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
69
- const deps = {
70
- ...pkgInfo.devDependencies,
71
- ...pkgInfo.dependencies
72
- };
73
- if (typeof deps.react !== "string") {
71
+ };
72
+ const isBeyondReact17 = (cwd) => {
73
+ const reactVersion = getReactVersion(cwd);
74
+ if (!reactVersion) {
74
75
  return false;
75
76
  }
76
- return semver.satisfies(semver.minVersion(deps.react), ">=16.14.0");
77
+ return isVersionBeyond17(reactVersion);
77
78
  };
78
- const isReact18 = (cwd = process.cwd()) => {
79
- const pkgPath = path.join(cwd, "package.json");
80
- if (!fs.existsSync(pkgPath)) {
79
+ const isSupportAutomaticJsx = (cwd) => {
80
+ const reactVersion = getReactVersion(cwd);
81
+ if (!reactVersion) {
81
82
  return false;
82
83
  }
83
- const pkgInfo = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
84
- const deps = {
85
- ...pkgInfo.devDependencies,
86
- ...pkgInfo.dependencies
87
- };
88
- if (typeof deps.react !== "string") {
84
+ return semver.satisfies(semver.minVersion(reactVersion), ">=16.14.0");
85
+ };
86
+ const isReact18 = (cwd = process.cwd()) => {
87
+ const reactVersion = getReactVersion(cwd);
88
+ if (!reactVersion) {
89
89
  return false;
90
90
  }
91
- return semver.gte(semver.minVersion(deps.react), "18.0.0");
91
+ return semver.gte(semver.minVersion(reactVersion), "18.0.0");
92
92
  };
93
93
  const isTypescript = (root) => fs.existsSync(path.resolve(root, "./tsconfig.json"));
94
94
  export {
95
+ getReactVersion,
95
96
  isApiOnly,
96
97
  isBeyondReact17,
97
98
  isDepExists,
@@ -23,6 +23,7 @@ export declare const isPackageInstalled: (name: string, resolvePaths: string | s
23
23
  export declare const isApiOnly: (appDirectory: string, entryDir?: string, apiDir?: string) => Promise<boolean>;
24
24
  export declare const isWebOnly: () => Promise<boolean>;
25
25
  export declare const isVersionBeyond17: (version: string) => boolean;
26
+ export declare const getReactVersion: (cwd: string) => string | false;
26
27
  /**
27
28
  * @deprecated Use {@link isSupportAutomaticJsx} to check if the project supports automatic JSX instead.
28
29
  */
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.65.3",
18
+ "version": "2.65.5",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -103,8 +103,7 @@
103
103
  },
104
104
  "publishConfig": {
105
105
  "registry": "https://registry.npmjs.org/",
106
- "access": "public",
107
- "provenance": true
106
+ "access": "public"
108
107
  },
109
108
  "typesVersions": {
110
109
  "*": {
@@ -191,9 +190,9 @@
191
190
  "jest": "^29",
192
191
  "typescript": "^5",
193
192
  "webpack": "^5.98.0",
194
- "@modern-js/types": "2.65.3",
195
- "@scripts/jest-config": "2.65.3",
196
- "@scripts/build": "2.65.3"
193
+ "@scripts/build": "2.65.5",
194
+ "@modern-js/types": "2.65.5",
195
+ "@scripts/jest-config": "2.65.5"
197
196
  },
198
197
  "sideEffects": false,
199
198
  "scripts": {