@modern-js/utils 2.18.0 → 2.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/{alias.js → cli/alias.js} +3 -3
  3. package/dist/cjs/{applyOptionsChain.js → cli/applyOptionsChain.js} +6 -5
  4. package/dist/cjs/{babel.js → cli/babel.js} +3 -3
  5. package/dist/cjs/cli/common.js +26 -0
  6. package/dist/cjs/{constants.js → cli/constants/index.js} +14 -2
  7. package/dist/cjs/{readTsConfig.js → cli/ensure.js} +10 -9
  8. package/dist/cjs/cli/fs.js +29 -0
  9. package/dist/cjs/{getEntryOptions.js → cli/get/config.js} +2 -2
  10. package/dist/cjs/cli/get/data.js +112 -0
  11. package/dist/cjs/cli/get/index.js +46 -0
  12. package/dist/cjs/cli/index.js +41 -0
  13. package/dist/cjs/{is/index.js → cli/is/config.js} +2 -43
  14. package/dist/cjs/{is/nodeEnv.js → cli/is/env.js} +3 -1
  15. package/dist/cjs/cli/is/index.js +22 -0
  16. package/dist/cjs/cli/is/project.js +92 -0
  17. package/dist/cjs/{is → cli/is}/type.js +3 -1
  18. package/dist/cjs/{logger.js → cli/logger.js} +1 -1
  19. package/dist/cjs/{monorepo.js → cli/monorepo.js} +1 -1
  20. package/dist/cjs/{nodeEnv.js → cli/package.js} +8 -1
  21. package/dist/cjs/{path.js → cli/path.js} +8 -2
  22. package/dist/cjs/{pathSerializer.js → cli/pathSerializer.js} +1 -1
  23. package/dist/cjs/{getPort.js → cli/port.js} +1 -1
  24. package/dist/cjs/{prettyInstructions.js → cli/prettyInstructions.js} +1 -2
  25. package/dist/cjs/{printBuildError.js → cli/print.js} +1 -1
  26. package/dist/cjs/{compatRequire.js → cli/require.js} +21 -3
  27. package/dist/cjs/{routes.js → cli/routes.js} +4 -11
  28. package/dist/cjs/{runtimeExports.js → cli/runtimeExports.js} +1 -1
  29. package/dist/cjs/cli/watch.js +61 -0
  30. package/dist/cjs/index.js +1 -42
  31. package/dist/cjs/runtime/router.js +19 -0
  32. package/dist/cjs/{ssr.js → runtime-node/index.js} +3 -1
  33. package/dist/esm/{alias.js → cli/alias.js} +2 -2
  34. package/dist/esm/{applyOptionsChain.js → cli/applyOptionsChain.js} +2 -1
  35. package/dist/esm/{babel.js → cli/babel.js} +1 -1
  36. package/dist/esm/cli/common.js +10 -0
  37. package/dist/esm/{constants.js → cli/constants/index.js} +1 -1
  38. package/dist/esm/{ensureAbsolutePath.js → cli/ensure.js} +8 -0
  39. package/dist/esm/{findExists.js → cli/fs.js} +6 -1
  40. package/dist/esm/{getEntryOptions.js → cli/get/config.js} +2 -2
  41. package/dist/esm/cli/get/data.js +86 -0
  42. package/dist/esm/cli/get/index.js +13 -0
  43. package/dist/esm/cli/index.js +24 -0
  44. package/dist/esm/{is/index.js → cli/is/config.js} +1 -21
  45. package/dist/esm/{is/nodeEnv.js → cli/is/env.js} +1 -0
  46. package/dist/esm/cli/is/index.js +5 -0
  47. package/dist/esm/cli/is/project.js +67 -0
  48. package/dist/esm/{is → cli/is}/type.js +1 -0
  49. package/dist/esm/{logger.js → cli/logger.js} +1 -1
  50. package/dist/esm/{monorepo.js → cli/monorepo.js} +1 -1
  51. package/dist/esm/{nodeEnv.js → cli/package.js} +7 -1
  52. package/dist/esm/{path.js → cli/path.js} +4 -1
  53. package/dist/esm/{pathSerializer.js → cli/pathSerializer.js} +1 -1
  54. package/dist/esm/{getPort.js → cli/port.js} +1 -1
  55. package/dist/esm/{prettyInstructions.js → cli/prettyInstructions.js} +2 -2
  56. package/dist/esm/{printBuildError.js → cli/print.js} +1 -1
  57. package/dist/esm/{compatRequire.js → cli/require.js} +18 -1
  58. package/dist/esm/{routes.js → cli/routes.js} +2 -2
  59. package/dist/esm/{runtimeExports.js → cli/runtimeExports.js} +1 -1
  60. package/dist/esm/{watch.js → cli/watch.js} +2 -2
  61. package/dist/esm/index.js +1 -42
  62. package/dist/esm/runtime/router.js +2 -0
  63. package/dist/esm/{ssr.js → runtime-node/index.js} +1 -0
  64. package/dist/types/{applyOptionsChain.d.ts → cli/applyOptionsChain.d.ts} +1 -1
  65. package/dist/types/{debug.d.ts → cli/common.d.ts} +3 -1
  66. package/dist/types/{constants.d.ts → cli/constants/index.d.ts} +2 -6
  67. package/dist/types/{ensureAbsolutePath.d.ts → cli/ensure.d.ts} +2 -1
  68. package/dist/types/{findExists.d.ts → cli/fs.d.ts} +2 -1
  69. package/dist/types/cli/get/data.d.ts +9 -0
  70. package/dist/types/cli/get/index.d.ts +4 -0
  71. package/dist/types/cli/index.d.ts +24 -0
  72. package/dist/types/cli/is/config.d.ts +30 -0
  73. package/dist/types/{is/nodeEnv.d.ts → cli/is/env.d.ts} +2 -1
  74. package/dist/types/cli/is/index.d.ts +5 -0
  75. package/dist/types/cli/is/project.d.ts +25 -0
  76. package/dist/types/{is → cli/is}/type.d.ts +9 -1
  77. package/dist/types/{logger.d.ts → cli/logger.d.ts} +1 -1
  78. package/dist/types/cli/package.d.ts +4 -0
  79. package/dist/types/{path.d.ts → cli/path.d.ts} +5 -2
  80. package/dist/types/{prettyInstructions.d.ts → cli/prettyInstructions.d.ts} +0 -3
  81. package/dist/types/{compatRequire.d.ts → cli/require.d.ts} +9 -1
  82. package/dist/types/cli/routes.d.ts +1 -0
  83. package/dist/types/{watch.d.ts → cli/watch.d.ts} +1 -1
  84. package/dist/types/index.d.ts +2 -43
  85. package/dist/types/runtime/router.d.ts +2 -0
  86. package/dist/types/{ssr.d.ts → runtime-node/index.d.ts} +2 -1
  87. package/package.json +56 -93
  88. package/dist/cjs/FileSizeReporter.js +0 -139
  89. package/dist/cjs/analyzeProject.js +0 -68
  90. package/dist/cjs/clearConsole.js +0 -13
  91. package/dist/cjs/debug.js +0 -10
  92. package/dist/cjs/emptyDir.js +0 -14
  93. package/dist/cjs/ensureAbsolutePath.js +0 -15
  94. package/dist/cjs/ensureArray.js +0 -16
  95. package/dist/cjs/findExists.js +0 -22
  96. package/dist/cjs/getBrowserslist.js +0 -24
  97. package/dist/cjs/getCoreJsVersion.js +0 -58
  98. package/dist/cjs/getPackageManager.js +0 -42
  99. package/dist/cjs/getServerConfig.js +0 -55
  100. package/dist/cjs/getTargetDir.js +0 -53
  101. package/dist/cjs/plugin.js +0 -28
  102. package/dist/cjs/react.js +0 -30
  103. package/dist/cjs/removeSlash.js +0 -19
  104. package/dist/cjs/resolve.js +0 -57
  105. package/dist/cjs/types.js +0 -4
  106. package/dist/cjs/version.js +0 -43
  107. package/dist/cjs/wait.js +0 -11
  108. package/dist/cjs/watch.js +0 -96
  109. package/dist/esm/FileSizeReporter.js +0 -121
  110. package/dist/esm/analyzeProject.js +0 -13
  111. package/dist/esm/clearConsole.js +0 -5
  112. package/dist/esm/debug.js +0 -2
  113. package/dist/esm/emptyDir.js +0 -6
  114. package/dist/esm/ensureArray.js +0 -8
  115. package/dist/esm/getBrowserslist.js +0 -9
  116. package/dist/esm/getCoreJsVersion.js +0 -10
  117. package/dist/esm/getPackageManager.js +0 -29
  118. package/dist/esm/getServerConfig.js +0 -7
  119. package/dist/esm/getTargetDir.js +0 -5
  120. package/dist/esm/plugin.js +0 -20
  121. package/dist/esm/react.js +0 -17
  122. package/dist/esm/readTsConfig.js +0 -9
  123. package/dist/esm/removeSlash.js +0 -3
  124. package/dist/esm/resolve.js +0 -41
  125. package/dist/esm/types.js +0 -1
  126. package/dist/esm/version.js +0 -23
  127. package/dist/esm/wait.js +0 -4
  128. package/dist/types/FileSizeReporter.d.ts +0 -16
  129. package/dist/types/analyzeProject.d.ts +0 -2
  130. package/dist/types/clearConsole.d.ts +0 -1
  131. package/dist/types/emptyDir.d.ts +0 -1
  132. package/dist/types/ensureArray.d.ts +0 -1
  133. package/dist/types/getBrowserslist.d.ts +0 -2
  134. package/dist/types/getCoreJsVersion.d.ts +0 -1
  135. package/dist/types/getPackageManager.d.ts +0 -1
  136. package/dist/types/getServerConfig.d.ts +0 -1
  137. package/dist/types/getTargetDir.d.ts +0 -1
  138. package/dist/types/is/index.d.ts +0 -58
  139. package/dist/types/nodeEnv.d.ts +0 -3
  140. package/dist/types/plugin.d.ts +0 -2
  141. package/dist/types/react.d.ts +0 -1
  142. package/dist/types/readTsConfig.d.ts +0 -2
  143. package/dist/types/removeSlash.d.ts +0 -3
  144. package/dist/types/resolve.d.ts +0 -13
  145. package/dist/types/routes.d.ts +0 -2
  146. package/dist/types/types.d.ts +0 -1
  147. package/dist/types/version.d.ts +0 -2
  148. package/dist/types/wait.d.ts +0 -2
  149. /package/dist/cjs/{commands.js → cli/commands.js} +0 -0
  150. /package/dist/cjs/{chainId.js → cli/constants/chainId.js} +0 -0
  151. /package/dist/cjs/{generateMetaTags.js → cli/generateMetaTags.js} +0 -0
  152. /package/dist/cjs/{is → cli/is}/platform.js +0 -0
  153. /package/dist/cjs/{testUtils.js → cli/test.js} +0 -0
  154. /package/dist/cjs/{universal → runtime}/nestedRoutes.js +0 -0
  155. /package/dist/cjs/{universal → runtime}/remixRouter.js +0 -0
  156. /package/dist/cjs/{runtime → runtime-browser}/index.js +0 -0
  157. /package/dist/cjs/{runtime → runtime-browser}/parsed.js +0 -0
  158. /package/dist/cjs/{universal → runtime-node}/serialize.js +0 -0
  159. /package/dist/cjs/{storage.js → runtime-node/storage.js} +0 -0
  160. /package/dist/esm/{commands.js → cli/commands.js} +0 -0
  161. /package/dist/esm/{chainId.js → cli/constants/chainId.js} +0 -0
  162. /package/dist/esm/{generateMetaTags.js → cli/generateMetaTags.js} +0 -0
  163. /package/dist/esm/{is → cli/is}/platform.js +0 -0
  164. /package/dist/esm/{testUtils.js → cli/test.js} +0 -0
  165. /package/dist/esm/{universal → runtime}/nestedRoutes.js +0 -0
  166. /package/dist/esm/{universal → runtime}/remixRouter.js +0 -0
  167. /package/dist/esm/{runtime → runtime-browser}/index.js +0 -0
  168. /package/dist/esm/{runtime → runtime-browser}/parsed.js +0 -0
  169. /package/dist/esm/{universal → runtime-node}/serialize.js +0 -0
  170. /package/dist/esm/{storage.js → runtime-node/storage.js} +0 -0
  171. /package/dist/types/{alias.d.ts → cli/alias.d.ts} +0 -0
  172. /package/dist/types/{babel.d.ts → cli/babel.d.ts} +0 -0
  173. /package/dist/types/{commands.d.ts → cli/commands.d.ts} +0 -0
  174. /package/dist/types/{chainId.d.ts → cli/constants/chainId.d.ts} +0 -0
  175. /package/dist/types/{generateMetaTags.d.ts → cli/generateMetaTags.d.ts} +0 -0
  176. /package/dist/types/{getEntryOptions.d.ts → cli/get/config.d.ts} +0 -0
  177. /package/dist/types/{is → cli/is}/platform.d.ts +0 -0
  178. /package/dist/types/{monorepo.d.ts → cli/monorepo.d.ts} +0 -0
  179. /package/dist/types/{pathSerializer.d.ts → cli/pathSerializer.d.ts} +0 -0
  180. /package/dist/types/{getPort.d.ts → cli/port.d.ts} +0 -0
  181. /package/dist/types/{printBuildError.d.ts → cli/print.d.ts} +0 -0
  182. /package/dist/types/{runtimeExports.d.ts → cli/runtimeExports.d.ts} +0 -0
  183. /package/dist/types/{testUtils.d.ts → cli/test.d.ts} +0 -0
  184. /package/dist/types/{universal → runtime}/nestedRoutes.d.ts +0 -0
  185. /package/dist/types/{universal → runtime}/remixRouter.d.ts +0 -0
  186. /package/dist/types/{runtime → runtime-browser}/index.d.ts +0 -0
  187. /package/dist/types/{runtime → runtime-browser}/parsed.d.ts +0 -0
  188. /package/dist/types/{universal → runtime-node}/serialize.d.ts +0 -0
  189. /package/dist/types/{storage.d.ts → runtime-node/storage.d.ts} +0 -0
@@ -1,9 +0,0 @@
1
- import path from "path";
2
- import { fs, json5 } from "./compiled";
3
- export const readTsConfig = (root) => {
4
- return readTsConfigByFile(path.resolve(root, "./tsconfig.json"));
5
- };
6
- export const readTsConfigByFile = (filename) => {
7
- const content = fs.readFileSync(path.resolve(filename), "utf-8");
8
- return json5.parse(content);
9
- };
@@ -1,3 +0,0 @@
1
- export const removeLeadingSlash = (s) => s.replace(/^\/+/, "");
2
- export const removeTailSlash = (s) => s.replace(/\/+$/, "");
3
- export const removeSlash = (s) => removeLeadingSlash(removeTailSlash(s));
@@ -1,41 +0,0 @@
1
- import { ensureArray } from "./ensureArray";
2
- export const tryResolve = (name, resolvePath) => {
3
- let filePath = "";
4
- try {
5
- filePath = require.resolve(name, {
6
- paths: [
7
- resolvePath
8
- ]
9
- });
10
- delete require.cache[filePath];
11
- } catch (err) {
12
- if (err.code === "MODULE_NOT_FOUND") {
13
- throw new Error(`Can not find module ${name}.`);
14
- }
15
- throw err;
16
- }
17
- return filePath;
18
- };
19
- export const isPackageInstalled = (name, resolvePaths) => {
20
- try {
21
- require.resolve(name, {
22
- paths: ensureArray(resolvePaths)
23
- });
24
- return true;
25
- } catch (err) {
26
- return false;
27
- }
28
- };
29
- export const getAntdMajorVersion = (appDirectory) => {
30
- try {
31
- const pkgJsonPath = require.resolve("antd/package.json", {
32
- paths: [
33
- appDirectory
34
- ]
35
- });
36
- const { version } = require(pkgJsonPath);
37
- return Number(version.split(".")[0]);
38
- } catch (err) {
39
- return null;
40
- }
41
- };
package/dist/esm/types.js DELETED
@@ -1 +0,0 @@
1
- export {};
@@ -1,23 +0,0 @@
1
- import path from "path";
2
- import { fs, execa, semver } from "./compiled";
3
- export async function getPnpmVersion() {
4
- const { stdout } = await execa("pnpm", [
5
- "--version"
6
- ]);
7
- return stdout;
8
- }
9
- export const isReact18 = (cwd) => {
10
- const pkgPath = path.join(cwd, "package.json");
11
- if (!fs.existsSync(pkgPath)) {
12
- return false;
13
- }
14
- const pkgInfo = JSON.parse(fs.readFileSync(pkgPath, "utf8"));
15
- const deps = {
16
- ...pkgInfo.devDependencies,
17
- ...pkgInfo.dependencies
18
- };
19
- if (typeof deps.react !== "string") {
20
- return false;
21
- }
22
- return semver.satisfies(semver.minVersion(deps.react), ">=18.0.0");
23
- };
package/dist/esm/wait.js DELETED
@@ -1,4 +0,0 @@
1
- const wait = (time = 0) => new Promise((resolve) => {
2
- setTimeout(resolve, time);
3
- });
4
- export { wait };
@@ -1,16 +0,0 @@
1
- /**
2
- * Copyright (c) 2015-present, Facebook, Inc.
3
- *
4
- * This source code is licensed under the MIT license found in the
5
- * LICENSE file at
6
- * https://github.com/facebook/create-react-app/blob/master/LICENSE
7
- */
8
- declare function printFileSizesAfterBuild(webpackStats: any, previousSizeMap: {
9
- root: string;
10
- sizes: Record<string, number[]>;
11
- }, buildFolder: string, maxBundleGzipSize: number, maxChunkGzipSize: number): void;
12
- declare function measureFileSizesBeforeBuild(buildFolder: string): Promise<{
13
- root: string;
14
- sizes: Record<string, number[]>;
15
- }>;
16
- export { measureFileSizesBeforeBuild, printFileSizesAfterBuild };
@@ -1,2 +0,0 @@
1
- export declare const isApiOnly: (appDirectory: string, entryDir?: string) => Promise<boolean>;
2
- export declare const isWebOnly: () => Promise<boolean>;
@@ -1 +0,0 @@
1
- export declare const clearConsole: () => void;
@@ -1 +0,0 @@
1
- export declare const emptyDir: (dir: string) => Promise<void>;
@@ -1 +0,0 @@
1
- export declare const ensureArray: <T>(params: T | T[]) => T[];
@@ -1,2 +0,0 @@
1
- export declare const defaults: string[];
2
- export declare const getBrowserslist: (appDirectory: string) => string[];
@@ -1 +0,0 @@
1
- export declare const getCoreJsVersion: (corejsPkgPath: string) => string;
@@ -1 +0,0 @@
1
- export declare function getPackageManager(cwd?: string): Promise<"npm" | "yarn" | "pnpm">;
@@ -1 +0,0 @@
1
- export declare const getServerConfig: (appDirectory: string, configFile: string) => Promise<string | false>;
@@ -1 +0,0 @@
1
- export declare const getTargetDir: (from: string, baseDir: string, targetBaseDir: string) => string;
@@ -1,58 +0,0 @@
1
- interface EntryPoint {
2
- entryName: string;
3
- }
4
- /**
5
- * Check if the package name is in dependencies or devDependencies.
6
- *
7
- * @param appDirectory - Project root directory.
8
- * @param name - Package name.
9
- * @returns True if the name is in dependencies or devDependencies, false otherwise.
10
- */
11
-
12
- export declare const isDepExists: (appDirectory: string, name: string) => boolean;
13
- /**
14
- * Is typescript project.
15
- *
16
- * @param root - App directory.
17
- * @returns Whether to use typescript.
18
- */
19
-
20
- export declare const isTypescript: (root: string) => boolean;
21
- /**
22
- * Is Empty object
23
- *
24
- * @param o - Any object.
25
- * @returns Whether it is empty object.
26
- */
27
-
28
- export declare const isEmpty: (o: Record<string, unknown>) => boolean;
29
- /**
30
- * Is SSR project
31
- *
32
- * @param config - User config.
33
- * @returns Whether to use server side render.
34
- */
35
-
36
- export declare const isSSR: (config: any) => boolean;
37
- export declare const isUseSSRBundle: (config: any) => boolean;
38
- /**
39
- * Is Worker project
40
- *
41
- * @param config - User config.
42
- * @returns Whether to use worker deploy.
43
- */
44
-
45
- export declare const isServiceWorker: (config: any) => boolean;
46
- export declare const isFastRefresh: () => boolean;
47
- export declare const isRouterV5: (config: {
48
- runtime?: {
49
- router?: {
50
- mode?: string;
51
- } | boolean;
52
- };
53
- }) => boolean;
54
- export declare const isSSGEntry: (config: any, entryName: string, entrypoints: EntryPoint[]) => boolean;
55
- export declare const isSingleEntry: (entrypoints: EntryPoint[]) => boolean;
56
- export * from './nodeEnv';
57
- export * from './platform';
58
- export * from './type';
@@ -1,3 +0,0 @@
1
- export declare function canUseNpm(): Promise<boolean>;
2
- export declare function canUseYarn(): Promise<boolean>;
3
- export declare function canUsePnpm(): Promise<boolean>;
@@ -1,2 +0,0 @@
1
- import { InternalPlugins } from '@modern-js/types';
2
- export declare function getInternalPlugins(appDirectory: string, internalPlugins?: InternalPlugins): string[];
@@ -1 +0,0 @@
1
- export declare const isBeyondReact17: (cwd: string) => boolean;
@@ -1,2 +0,0 @@
1
- export declare const readTsConfig: (root: string) => any;
2
- export declare const readTsConfigByFile: (filename: string) => any;
@@ -1,3 +0,0 @@
1
- export declare const removeLeadingSlash: (s: string) => string;
2
- export declare const removeTailSlash: (s: string) => string;
3
- export declare const removeSlash: (s: string) => string;
@@ -1,13 +0,0 @@
1
- /**
2
- * Try to resolve npm package entry file path.
3
- * @param name - Package name.
4
- * @param resolvePath - Path to resolve dependencies.
5
- * @returns Resolved file path.
6
- */
7
- export declare const tryResolve: (name: string, resolvePath: string) => string;
8
- /**
9
- * Try to resolve npm package, return true if package is installed.
10
- */
11
-
12
- export declare const isPackageInstalled: (name: string, resolvePaths: string | string[]) => boolean;
13
- export declare const getAntdMajorVersion: (appDirectory: string) => number | null;
@@ -1,2 +0,0 @@
1
- export declare const getPathWithoutExt: (filename: string) => string;
2
- export declare const getRouteId: (componentPath: string, routesDir: string, entryName: string) => string;
@@ -1 +0,0 @@
1
- export type Falsy = false | null | undefined | 0 | '';
@@ -1,2 +0,0 @@
1
- export declare function getPnpmVersion(): Promise<string>;
2
- export declare const isReact18: (cwd: string) => boolean;
@@ -1,2 +0,0 @@
1
- declare const wait: (time?: number) => Promise<unknown>;
2
- export { wait };
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes