@modern-js/utils 2.58.2-alpha.0 → 2.58.3-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. package/dist/cjs/cli/alias.js +1 -1
  2. package/dist/cjs/cli/index.js +3 -1
  3. package/dist/cjs/cli/is/project.js +1 -1
  4. package/dist/cjs/cli/monorepo.js +3 -2
  5. package/dist/cjs/cli/path.js +2 -2
  6. package/dist/cjs/cli/port.js +2 -1
  7. package/dist/cjs/cli/prettyInstructions.js +2 -2
  8. package/dist/cjs/cli/require.js +4 -1
  9. package/dist/cjs/cli/route.js +23 -2
  10. package/dist/cjs/cli/runtimeExports.js +3 -3
  11. package/dist/cjs/cli/version.js +32 -0
  12. package/dist/compiled/better-ajv-errors/index.js +1 -1
  13. package/dist/compiled/recursive-readdir/index.d.ts +21 -0
  14. package/dist/compiled/recursive-readdir/index.js +1 -0
  15. package/dist/compiled/recursive-readdir/license +21 -0
  16. package/dist/compiled/recursive-readdir/package.json +1 -0
  17. package/dist/compiled/webpack-dev-middleware/index.js +7 -0
  18. package/dist/compiled/webpack-dev-middleware/license +20 -0
  19. package/dist/compiled/webpack-dev-middleware/package.json +1 -0
  20. package/dist/compiled/webpack-dev-middleware/types/index.d.ts +262 -0
  21. package/dist/esm/cli/alias.js +1 -1
  22. package/dist/esm/cli/get/data.js +1 -1
  23. package/dist/esm/cli/index.js +1 -0
  24. package/dist/esm/cli/is/project.js +1 -1
  25. package/dist/esm/cli/monorepo.js +3 -2
  26. package/dist/esm/cli/path.js +2 -2
  27. package/dist/esm/cli/port.js +4 -3
  28. package/dist/esm/cli/prettyInstructions.js +2 -2
  29. package/dist/esm/cli/require.js +5 -2
  30. package/dist/esm/cli/route.js +21 -1
  31. package/dist/esm/cli/runtimeExports.js +3 -3
  32. package/dist/esm/cli/version.js +8 -0
  33. package/dist/esm-node/cli/alias.js +1 -1
  34. package/dist/esm-node/cli/get/data.js +1 -1
  35. package/dist/esm-node/cli/index.js +1 -0
  36. package/dist/esm-node/cli/is/project.js +1 -1
  37. package/dist/esm-node/cli/monorepo.js +3 -2
  38. package/dist/esm-node/cli/path.js +2 -2
  39. package/dist/esm-node/cli/port.js +2 -1
  40. package/dist/esm-node/cli/prettyInstructions.js +2 -2
  41. package/dist/esm-node/cli/require.js +4 -1
  42. package/dist/esm-node/cli/route.js +21 -1
  43. package/dist/esm-node/cli/runtimeExports.js +3 -3
  44. package/dist/esm-node/cli/version.js +8 -0
  45. package/dist/types/cli/babel.d.ts +1 -1
  46. package/dist/types/cli/constants.d.ts +1 -1
  47. package/dist/types/cli/get/data.d.ts +1 -1
  48. package/dist/types/cli/index.d.ts +1 -0
  49. package/dist/types/cli/port.d.ts +1 -1
  50. package/dist/types/cli/route.d.ts +1 -0
  51. package/dist/types/cli/version.d.ts +1 -0
  52. package/package.json +4 -4
@@ -2,13 +2,15 @@ import { _ as _async_to_generator } from "@swc/helpers/_/_async_to_generator";
2
2
  import { _ as _instanceof } from "@swc/helpers/_/_instanceof";
3
3
  import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
4
4
  import { _ as _ts_generator } from "@swc/helpers/_/_ts_generator";
5
+ import { isAbsolute } from "node:path";
6
+ import { pathToFileURL } from "node:url";
5
7
  import { findExists } from "./fs";
6
8
  function compatibleRequire(path) {
7
9
  return _compatibleRequire.apply(this, arguments);
8
10
  }
9
11
  function _compatibleRequire() {
10
12
  _compatibleRequire = _async_to_generator(function(path) {
11
- var interop, requiredModule, err;
13
+ var interop, requiredModule, err, modulePath;
12
14
  var _arguments = arguments;
13
15
  return _ts_generator(this, function(_state) {
14
16
  switch (_state.label) {
@@ -40,9 +42,10 @@ function _compatibleRequire() {
40
42
  3,
41
43
  4
42
44
  ];
45
+ modulePath = isAbsolute(path) ? pathToFileURL(path).href : path;
43
46
  return [
44
47
  4,
45
- import(path)
48
+ import(modulePath)
46
49
  ];
47
50
  case 3:
48
51
  requiredModule = _state.sent();
@@ -38,7 +38,27 @@ function filterRoutesLoader(routes) {
38
38
  });
39
39
  return newRoutes;
40
40
  }
41
+ function markRoutes(routes, routeIds) {
42
+ return routes.map(function(route) {
43
+ if (route.type !== "nested") {
44
+ return route;
45
+ }
46
+ if (route.children && route.children.length > 0) {
47
+ route.children = markRoutes(route.children, routeIds);
48
+ }
49
+ if (route.children && route.children.length > 0) {
50
+ route.inValidSSRRoute = route.children.every(function(child) {
51
+ var _child_inValidSSRRoute;
52
+ return (_child_inValidSSRRoute = child.inValidSSRRoute) !== null && _child_inValidSSRRoute !== void 0 ? _child_inValidSSRRoute : false;
53
+ });
54
+ } else if (route.id) {
55
+ route.inValidSSRRoute = !routeIds.includes(route.id);
56
+ }
57
+ return route;
58
+ });
59
+ }
41
60
  export {
42
61
  filterRoutesForServer,
43
- filterRoutesLoader
62
+ filterRoutesLoader,
63
+ markRoutes
44
64
  };
@@ -22,11 +22,11 @@ var createRuntimeExportsUtils = memo(function() {
22
22
  var pwd = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : "", namespace = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "index";
23
23
  var entryExportFile = path.join(pwd, ".runtime-exports/".concat(namespace, ".js"));
24
24
  var addExport = function(statement) {
25
- statement = normalizeOutputPath(statement);
25
+ var statementStr = normalizeOutputPath(statement);
26
26
  try {
27
27
  fs.ensureFileSync(entryExportFile);
28
- if (!fs.readFileSync(entryExportFile, "utf8").includes(statement)) {
29
- fs.appendFileSync(entryExportFile, "".concat(statement, "\n"));
28
+ if (!fs.readFileSync(entryExportFile, "utf8").includes(statementStr)) {
29
+ fs.appendFileSync(entryExportFile, "".concat(statementStr, "\n"));
30
30
  }
31
31
  } catch (e) {
32
32
  }
@@ -0,0 +1,8 @@
1
+ function isVersionAtLeast1819() {
2
+ var nodeVersion = process.versions.node;
3
+ var versionArr = nodeVersion.split(".").map(Number);
4
+ return versionArr[0] > 18 || versionArr[0] === 18 && versionArr[1] >= 19;
5
+ }
6
+ export {
7
+ isVersionAtLeast1819
8
+ };
@@ -1,7 +1,7 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
- import { readTsConfigByFile } from "./get";
4
3
  import { applyOptionsChain } from "./applyOptionsChain";
4
+ import { readTsConfigByFile } from "./get";
5
5
  const mergeAlias = (alias) => applyOptionsChain({}, alias);
6
6
  const getAliasConfig = (aliasOption, option) => {
7
7
  var _tsconfig_compilerOptions, _tsconfig_compilerOptions1;
@@ -1,6 +1,6 @@
1
1
  import os from "os";
2
2
  import path from "path";
3
- import { browserslist, fs, json5 } from "../../compiled";
3
+ import { fs, browserslist, json5 } from "../../compiled";
4
4
  import { INTERNAL_CLI_PLUGINS } from "../constants";
5
5
  import { isDepExists } from "../is";
6
6
  import { canUsePnpm, canUseYarn } from "../package";
@@ -20,3 +20,4 @@ export * from "./watch";
20
20
  export * from "./config";
21
21
  export * from "./action";
22
22
  export * from "./route";
23
+ export * from "./version";
@@ -1,7 +1,7 @@
1
1
  import path from "path";
2
2
  import pkgUp from "../../../compiled/pkg-up";
3
- import { getArgv } from "../commands";
4
3
  import { fs, minimist, semver } from "../../compiled";
4
+ import { getArgv } from "../commands";
5
5
  import { createDebugger } from "../common";
6
6
  import { ensureArray } from "../ensure";
7
7
  const debug = createDebugger("judge-depExists");
@@ -21,14 +21,15 @@ const isPnpmWorkspaces = (root) => fs.existsSync(path.join(root, WORKSPACE_FILES
21
21
  const isMonorepo = (root) => isLerna(root) || isYarnWorkspaces(root) || isPnpmWorkspaces(root);
22
22
  const findMonorepoRoot = (appDirectory, maxDepth = PACKAGE_MAX_DEPTH) => {
23
23
  let inMonorepo = false;
24
+ let monorepoRoot = appDirectory;
24
25
  for (let depth = 0; depth < maxDepth; depth++) {
25
26
  if (isMonorepo(appDirectory)) {
26
27
  inMonorepo = true;
27
28
  break;
28
29
  }
29
- appDirectory = path.dirname(appDirectory);
30
+ monorepoRoot = path.dirname(appDirectory);
30
31
  }
31
- return inMonorepo ? appDirectory : void 0;
32
+ return inMonorepo ? monorepoRoot : void 0;
32
33
  };
33
34
  const getMonorepoPackages = (root) => {
34
35
  let packages = [];
@@ -1,6 +1,6 @@
1
- import path from "path";
2
- import os from "os";
3
1
  import fs from "fs";
2
+ import os from "os";
3
+ import path from "path";
4
4
  import { nanoid, upath } from "../compiled";
5
5
  const isPathString = (test) => path.posix.basename(test) !== test || path.win32.basename(test) !== test;
6
6
  const isRelativePath = (test) => /^\.\.?($|[\\/])/.test(test);
@@ -1,7 +1,8 @@
1
1
  import net from "net";
2
2
  import { chalk } from "../compiled";
3
3
  import { logger } from "./logger";
4
- const getPort = async (port, { tryLimits = 20, strictPort = false, slient = false } = {}) => {
4
+ const getPort = async (expectPort, { tryLimits = 20, strictPort = false, slient = false } = {}) => {
5
+ let port = expectPort;
5
6
  if (typeof port === "string") {
6
7
  port = parseInt(port, 10);
7
8
  }
@@ -1,8 +1,8 @@
1
- import os from "os";
2
1
  import { isIPv6 } from "net";
2
+ import os from "os";
3
3
  import { chalk } from "../compiled";
4
- import { isDev, isSingleEntry } from "./is";
5
4
  import { DEFAULT_DEV_HOST } from "./constants";
5
+ import { isDev, isSingleEntry } from "./is";
6
6
  const normalizeUrl = (url) => url.replace(/([^:]\/)\/+/g, "$1");
7
7
  const getIpv4Interfaces = () => {
8
8
  const interfaces = os.networkInterfaces();
@@ -1,3 +1,5 @@
1
+ import { isAbsolute } from "node:path";
2
+ import { pathToFileURL } from "node:url";
1
3
  import { findExists } from "./fs";
2
4
  async function compatibleRequire(path, interop = true) {
3
5
  if (path.endsWith(".json")) {
@@ -8,7 +10,8 @@ async function compatibleRequire(path, interop = true) {
8
10
  requiredModule = require(path);
9
11
  } catch (err) {
10
12
  if (err.code === "ERR_REQUIRE_ESM" || err instanceof SyntaxError) {
11
- requiredModule = await import(path);
13
+ const modulePath = isAbsolute(path) ? pathToFileURL(path).href : path;
14
+ requiredModule = await import(modulePath);
12
15
  return interop ? requiredModule.default : requiredModule;
13
16
  } else {
14
17
  throw err;
@@ -34,7 +34,27 @@ function filterRoutesLoader(routes) {
34
34
  }).filter((route) => route !== null);
35
35
  return newRoutes;
36
36
  }
37
+ function markRoutes(routes, routeIds) {
38
+ return routes.map((route) => {
39
+ if (route.type !== "nested") {
40
+ return route;
41
+ }
42
+ if (route.children && route.children.length > 0) {
43
+ route.children = markRoutes(route.children, routeIds);
44
+ }
45
+ if (route.children && route.children.length > 0) {
46
+ route.inValidSSRRoute = route.children.every((child) => {
47
+ var _child_inValidSSRRoute;
48
+ return (_child_inValidSSRRoute = child.inValidSSRRoute) !== null && _child_inValidSSRRoute !== void 0 ? _child_inValidSSRRoute : false;
49
+ });
50
+ } else if (route.id) {
51
+ route.inValidSSRRoute = !routeIds.includes(route.id);
52
+ }
53
+ return route;
54
+ });
55
+ }
37
56
  export {
38
57
  filterRoutesForServer,
39
- filterRoutesLoader
58
+ filterRoutesLoader,
59
+ markRoutes
40
60
  };
@@ -17,11 +17,11 @@ const memo = (fn) => {
17
17
  const createRuntimeExportsUtils = memo((pwd = "", namespace = "index") => {
18
18
  const entryExportFile = path.join(pwd, `.runtime-exports/${namespace}.js`);
19
19
  const addExport = (statement) => {
20
- statement = normalizeOutputPath(statement);
20
+ const statementStr = normalizeOutputPath(statement);
21
21
  try {
22
22
  fs.ensureFileSync(entryExportFile);
23
- if (!fs.readFileSync(entryExportFile, "utf8").includes(statement)) {
24
- fs.appendFileSync(entryExportFile, `${statement}
23
+ if (!fs.readFileSync(entryExportFile, "utf8").includes(statementStr)) {
24
+ fs.appendFileSync(entryExportFile, `${statementStr}
25
25
  `);
26
26
  }
27
27
  } catch {
@@ -0,0 +1,8 @@
1
+ function isVersionAtLeast1819() {
2
+ const nodeVersion = process.versions.node;
3
+ const versionArr = nodeVersion.split(".").map(Number);
4
+ return versionArr[0] > 18 || versionArr[0] === 18 && versionArr[1] >= 19;
5
+ }
6
+ export {
7
+ isVersionAtLeast1819
8
+ };
@@ -1,3 +1,3 @@
1
- import { BabelConfig, BabelConfigUtils, BabelTransformOptions } from '@modern-js/types';
1
+ import type { BabelConfig, BabelConfigUtils, BabelTransformOptions } from '@modern-js/types';
2
2
  export declare const getBabelUtils: (config: BabelTransformOptions) => BabelConfigUtils;
3
3
  export declare const applyUserBabelConfig: (defaultOptions: BabelTransformOptions, userBabelConfig?: BabelConfig | BabelConfig[], extraBabelUtils?: Partial<BabelConfigUtils>) => BabelTransformOptions;
@@ -1,4 +1,4 @@
1
- import { InternalPlugins } from '@modern-js/types';
1
+ import type { InternalPlugins } from '@modern-js/types';
2
2
  export { NESTED_ROUTE_SPEC_FILE, MAIN_ENTRY_NAME, ROUTE_SPEC_FILE, SERVER_BUNDLE_DIRECTORY, SERVER_RENDER_FUNCTION_NAME, SERVER_PLUGIN_BFF, SERVER_PLUGIN_EXPRESS, SERVER_PLUGIN_KOA, SERVER_PLUGIN_SERVER, SERVER_PLUGIN_POLYFILL, } from '../universal/constants';
3
3
  export declare const JS_EXTENSIONS: string[];
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { InternalPlugins } from '@modern-js/types';
1
+ import type { InternalPlugins } from '@modern-js/types';
2
2
  export declare function getPackageManager(cwd?: string): Promise<"pnpm" | "npm" | "yarn">;
3
3
  export declare const getCoreJsVersion: (corejsPkgPath: string) => string;
4
4
  export declare const getAntdMajorVersion: (appDirectory: string) => number | null;
@@ -20,3 +20,4 @@ export * from './watch';
20
20
  export * from './config';
21
21
  export * from './action';
22
22
  export * from './route';
23
+ export * from './version';
@@ -5,7 +5,7 @@
5
5
  * @param strictPort - Whether to throw an error when the port is occupied.
6
6
  * @returns Available port number.
7
7
  */
8
- export declare const getPort: (port: string | number, { tryLimits, strictPort, slient, }?: {
8
+ export declare const getPort: (expectPort: string | number, { tryLimits, strictPort, slient, }?: {
9
9
  tryLimits?: number | undefined;
10
10
  strictPort?: boolean | undefined;
11
11
  slient?: boolean | undefined;
@@ -1,3 +1,4 @@
1
1
  import type { NestedRouteForCli, PageRoute } from '@modern-js/types';
2
2
  export declare function filterRoutesForServer(routes: (NestedRouteForCli | PageRoute)[]): (NestedRouteForCli | PageRoute)[];
3
3
  export declare function filterRoutesLoader(routes: (NestedRouteForCli | PageRoute)[]): (NestedRouteForCli | PageRoute)[];
4
+ export declare function markRoutes(routes: (NestedRouteForCli | PageRoute)[], routeIds: string[]): (NestedRouteForCli | PageRoute)[];
@@ -0,0 +1 @@
1
+ export declare function isVersionAtLeast1819(): boolean;
package/package.json CHANGED
@@ -15,7 +15,7 @@
15
15
  "modern",
16
16
  "modern.js"
17
17
  ],
18
- "version": "2.58.2-alpha.0",
18
+ "version": "2.58.3-alpha.0",
19
19
  "jsnext:source": "./src/index.ts",
20
20
  "types": "./dist/types/index.d.ts",
21
21
  "main": "./dist/cjs/index.js",
@@ -162,9 +162,9 @@
162
162
  "jest": "^29",
163
163
  "typescript": "^5",
164
164
  "webpack": "^5.93.0",
165
- "@scripts/build": "2.58.1",
166
- "@modern-js/types": "2.58.1",
167
- "@scripts/jest-config": "2.58.1"
165
+ "@scripts/build": "2.58.2",
166
+ "@modern-js/types": "2.58.2",
167
+ "@scripts/jest-config": "2.58.2"
168
168
  },
169
169
  "sideEffects": false,
170
170
  "scripts": {