@modern-js/utils 2.7.0 → 2.7.1-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -19,8 +19,8 @@ Please follow [Quick Start](https://modernjs.dev/en/guides/get-started/quick-sta
19
19
 
20
20
  ## Contributing
21
21
 
22
- Please read the [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md).
22
+ Please read the [Contributing Guide](https://github.com/web-infra-dev/modern.js/blob/main/CONTRIBUTING.md).
23
23
 
24
24
  ## License
25
25
 
26
- Modern.js is [MIT licensed](https://github.com/modern-js-dev/modern.js/blob/main/LICENSE).
26
+ Modern.js is [MIT licensed](https://github.com/web-infra-dev/modern.js/blob/main/LICENSE).
@@ -1 +1,2 @@
1
- export declare const isApiOnly: (appDirectory: string, entryDir?: string) => Promise<boolean>;
1
+ export declare const isApiOnly: (appDirectory: string, entryDir?: string) => Promise<boolean>;
2
+ export declare const isWebOnly: () => Promise<boolean>;
@@ -47,7 +47,8 @@ var __async = (__this, __arguments, generator) => {
47
47
  };
48
48
  var analyzeProject_exports = {};
49
49
  __export(analyzeProject_exports, {
50
- isApiOnly: () => isApiOnly
50
+ isApiOnly: () => isApiOnly,
51
+ isWebOnly: () => isWebOnly
51
52
  });
52
53
  module.exports = __toCommonJS(analyzeProject_exports);
53
54
  var path = __toESM(require("path"));
@@ -58,7 +59,12 @@ const isApiOnly = (appDirectory, entryDir) => __async(void 0, null, function* ()
58
59
  const options = (0, import_compiled.minimist)(process.argv.slice(2));
59
60
  return !existSrc || Boolean(options["api-only"]);
60
61
  });
62
+ const isWebOnly = () => __async(void 0, null, function* () {
63
+ const options = (0, import_compiled.minimist)(process.argv.slice(2));
64
+ return Boolean(options["web-only"]);
65
+ });
61
66
  // Annotate the CommonJS export names for ESM import in node:
62
67
  0 && (module.exports = {
63
- isApiOnly
68
+ isApiOnly,
69
+ isWebOnly
64
70
  });
@@ -1,3 +1,6 @@
1
+ interface EntryPoint {
2
+ entryName: string;
3
+ }
1
4
  /**
2
5
  * Check if the package name is in dependencies or devDependencies.
3
6
  *
@@ -5,6 +8,7 @@
5
8
  * @param name - Package name.
6
9
  * @returns True if the name is in dependencies or devDependencies, false otherwise.
7
10
  */
11
+
8
12
  export declare const isDepExists: (appDirectory: string, name: string) => boolean;
9
13
  /**
10
14
  * Is typescript project.
@@ -47,6 +51,8 @@ export declare const isRouterV5: (config: {
47
51
  } | boolean;
48
52
  };
49
53
  }) => boolean;
54
+ export declare const isSSGEntry: (config: any, entryName: string, entrypoints: EntryPoint[]) => boolean;
55
+ export declare const isSingleEntry: (entrypoints: EntryPoint[]) => boolean;
50
56
  export * from './nodeEnv';
51
57
  export * from './platform';
52
58
  export * from './type';
package/dist/is/index.js CHANGED
@@ -32,8 +32,10 @@ __export(is_exports, {
32
32
  isEmpty: () => isEmpty,
33
33
  isFastRefresh: () => isFastRefresh,
34
34
  isRouterV5: () => isRouterV5,
35
+ isSSGEntry: () => isSSGEntry,
35
36
  isSSR: () => isSSR,
36
37
  isServiceWorker: () => isServiceWorker,
38
+ isSingleEntry: () => isSingleEntry,
37
39
  isTypescript: () => isTypescript,
38
40
  isUseSSRBundle: () => isUseSSRBundle
39
41
  });
@@ -91,14 +93,22 @@ const isRouterV5 = (config) => {
91
93
  var _a, _b, _c;
92
94
  return typeof ((_a = config.runtime) == null ? void 0 : _a.router) !== "boolean" && ((_c = (_b = config == null ? void 0 : config.runtime) == null ? void 0 : _b.router) == null ? void 0 : _c.mode) === "react-router-5";
93
95
  };
96
+ const isSSGEntry = (config, entryName, entrypoints) => {
97
+ const ssgConfig = config.output.ssg;
98
+ const useSSG = isSingleEntry(entrypoints) ? Boolean(ssgConfig) : ssgConfig === true || typeof (ssgConfig == null ? void 0 : ssgConfig[0]) === "function" || Boolean(ssgConfig == null ? void 0 : ssgConfig[entryName]);
99
+ return useSSG;
100
+ };
101
+ const isSingleEntry = (entrypoints) => entrypoints.length === 1 && entrypoints[0].entryName === "main";
94
102
  // Annotate the CommonJS export names for ESM import in node:
95
103
  0 && (module.exports = {
96
104
  isDepExists,
97
105
  isEmpty,
98
106
  isFastRefresh,
99
107
  isRouterV5,
108
+ isSSGEntry,
100
109
  isSSR,
101
110
  isServiceWorker,
111
+ isSingleEntry,
102
112
  isTypescript,
103
113
  isUseSSRBundle
104
114
  });
@@ -1,13 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import os from 'os';
3
- interface EntryPoint {
4
- entryName: string;
5
- }
6
- export declare const isSingleEntry: (entrypoints: EntryPoint[]) => boolean;
7
3
  export declare const getIpv4Interfaces: () => os.NetworkInterfaceInfo[];
8
4
  export declare const getAddressUrls: (protocol: string | undefined, port: number) => {
9
5
  type: string;
10
6
  url: string;
11
7
  }[];
12
- export declare const prettyInstructions: (appContext: any, config: any) => string;
13
- export {};
8
+ export declare const prettyInstructions: (appContext: any, config: any) => string;
@@ -29,14 +29,12 @@ var prettyInstructions_exports = {};
29
29
  __export(prettyInstructions_exports, {
30
30
  getAddressUrls: () => getAddressUrls,
31
31
  getIpv4Interfaces: () => getIpv4Interfaces,
32
- isSingleEntry: () => isSingleEntry,
33
32
  prettyInstructions: () => prettyInstructions
34
33
  });
35
34
  module.exports = __toCommonJS(prettyInstructions_exports);
36
35
  var import_os = __toESM(require("os"));
37
36
  var import_compiled = require("./compiled");
38
37
  var import_is = require("./is");
39
- const isSingleEntry = (entrypoints) => entrypoints.length === 1 && entrypoints[0].entryName === "main";
40
38
  const normalizeUrl = (url) => url.replace(/([^:]\/)\/+/g, "$1");
41
39
  const getIpv4Interfaces = () => {
42
40
  const interfaces = import_os.default.networkInterfaces();
@@ -75,7 +73,7 @@ const prettyInstructions = (appContext, config) => {
75
73
  );
76
74
  const routes = !apiOnly ? serverRoutes.filter((route) => route.entryName) : serverRoutes;
77
75
  let message = "App running at:\n\n";
78
- if (isSingleEntry(entrypoints) || apiOnly) {
76
+ if ((0, import_is.isSingleEntry)(entrypoints) || apiOnly) {
79
77
  message += urls.map(
80
78
  ({ type, url }) => ` ${import_compiled.chalk.bold(`> ${type.padEnd(10)}`)}${import_compiled.chalk.cyanBright(
81
79
  normalizeUrl(`${url}/${routes[0].urlPath}`)
@@ -113,6 +111,5 @@ const prettyInstructions = (appContext, config) => {
113
111
  0 && (module.exports = {
114
112
  getAddressUrls,
115
113
  getIpv4Interfaces,
116
- isSingleEntry,
117
114
  prettyInstructions
118
115
  });
package/package.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "name": "@modern-js/utils",
3
3
  "description": "A Progressive React Framework for modern web development.",
4
4
  "homepage": "https://modernjs.dev",
5
- "bugs": "https://github.com/modern-js-dev/modern.js/issues",
6
- "repository": "modern-js-dev/modern.js",
5
+ "bugs": "https://github.com/web-infra-dev/modern.js/issues",
6
+ "repository": "web-infra-dev/modern.js",
7
7
  "license": "MIT",
8
8
  "keywords": [
9
9
  "react",
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "2.7.0",
14
+ "version": "2.7.1-alpha.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/index.d.ts",
17
17
  "main": "./dist/index.js",
@@ -161,15 +161,15 @@
161
161
  "react": ">=17.0.0",
162
162
  "react-dom": ">=17.0.0",
163
163
  "react-router-dom": "^6.8.1",
164
+ "@modern-js/types": "2.7.0",
165
+ "@scripts/build": "2.7.0",
166
+ "@scripts/jest-config": "2.7.0",
164
167
  "@types/jest": "^27",
165
168
  "@types/node": "^14",
166
169
  "jest": "^27",
167
170
  "typescript": "^4",
168
171
  "webpack": "^5.75.0",
169
- "@types/serialize-javascript": "^5.0.1",
170
- "@modern-js/types": "2.7.0",
171
- "@scripts/jest-config": "2.7.0",
172
- "@scripts/build": "2.7.0"
172
+ "@types/serialize-javascript": "^5.0.1"
173
173
  },
174
174
  "sideEffects": false,
175
175
  "scripts": {