@modern-js/utils 1.7.3 → 1.7.6

Sign up to get free protection for your applications and to get access to all the features.
package/dist/monorepo.js CHANGED
@@ -8,16 +8,16 @@ const fs_1 = __importDefault(require("fs"));
8
8
  const path_1 = __importDefault(require("path"));
9
9
  const compiled_1 = require("./compiled");
10
10
  const PACKAGE_MAX_DEPTH = 5;
11
- const WORKSPACES_FILES = {
11
+ const WORKSPACE_FILES = {
12
12
  YARN: 'package.json',
13
- PNPM: 'pnpm-workspaces.yaml',
13
+ PNPM: 'pnpm-workspace.yaml',
14
14
  LERNA: 'lerna.json',
15
15
  };
16
- const isLerna = (root) => fs_1.default.existsSync(path_1.default.join(root, WORKSPACES_FILES.LERNA));
16
+ const isLerna = (root) => fs_1.default.existsSync(path_1.default.join(root, WORKSPACE_FILES.LERNA));
17
17
  exports.isLerna = isLerna;
18
18
  const isYarnWorkspaces = (root) => {
19
19
  var _a;
20
- const pkg = path_1.default.join(root, WORKSPACES_FILES.YARN);
20
+ const pkg = path_1.default.join(root, WORKSPACE_FILES.YARN);
21
21
  if (!fs_1.default.existsSync(pkg)) {
22
22
  return false;
23
23
  }
@@ -25,12 +25,16 @@ const isYarnWorkspaces = (root) => {
25
25
  return Boolean((_a = json.workspaces) === null || _a === void 0 ? void 0 : _a.packages);
26
26
  };
27
27
  exports.isYarnWorkspaces = isYarnWorkspaces;
28
- const isPnpmWorkspaces = (root) => fs_1.default.existsSync(path_1.default.join(root, WORKSPACES_FILES.PNPM));
28
+ const isPnpmWorkspaces = (root) => fs_1.default.existsSync(path_1.default.join(root, WORKSPACE_FILES.PNPM));
29
29
  exports.isPnpmWorkspaces = isPnpmWorkspaces;
30
30
  const isMonorepo = (root) => (0, exports.isLerna)(root) || (0, exports.isYarnWorkspaces)(root) || (0, exports.isPnpmWorkspaces)(root);
31
31
  exports.isMonorepo = isMonorepo;
32
32
  const isModernjsMonorepo = (root) => {
33
- const json = JSON.parse(fs_1.default.readFileSync(path_1.default.join(root, 'package.json'), 'utf8'));
33
+ const pkgJsonPath = path_1.default.join(root, 'package.json');
34
+ if (!fs_1.default.existsSync(pkgJsonPath)) {
35
+ return false;
36
+ }
37
+ const json = JSON.parse(fs_1.default.readFileSync(pkgJsonPath, 'utf8'));
34
38
  const deps = {
35
39
  ...(json.dependencies || {}),
36
40
  ...(json.devDependencies || {}),
@@ -62,7 +66,7 @@ const getMonorepoPackages = (root) => {
62
66
  ({ packages } = json);
63
67
  }
64
68
  else {
65
- ({ packages } = compiled_1.yaml.load(fs_1.default.readFileSync(path_1.default.join(root, WORKSPACES_FILES.PNPM), 'utf8')));
69
+ ({ packages } = compiled_1.yaml.load(fs_1.default.readFileSync(path_1.default.join(root, WORKSPACE_FILES.PNPM), 'utf8')));
66
70
  }
67
71
  if (packages) {
68
72
  return packages
@@ -1,6 +1,9 @@
1
+ /// <reference types="node" />
2
+ import os from 'os';
1
3
  interface EntryPoint {
2
4
  entryName: string;
3
5
  }
4
6
  export declare const isSingleEntry: (entrypoints: EntryPoint[]) => boolean;
7
+ export declare const getIpv4Interfaces: () => os.NetworkInterfaceInfo[];
5
8
  export declare const prettyInstructions: (appContext: any, config: any) => string;
6
9
  export {};
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.prettyInstructions = exports.isSingleEntry = void 0;
6
+ exports.prettyInstructions = exports.getIpv4Interfaces = exports.isSingleEntry = void 0;
7
7
  const os_1 = __importDefault(require("os"));
8
8
  const compiled_1 = require("./compiled");
9
9
  const is_1 = require("./is");
@@ -11,20 +11,27 @@ const is_1 = require("./is");
11
11
  const isSingleEntry = (entrypoints) => entrypoints.length === 1 && entrypoints[0].entryName === 'main';
12
12
  exports.isSingleEntry = isSingleEntry;
13
13
  const normalizeUrl = (url) => url.replace(/([^:]\/)\/+/g, '$1');
14
- const getAddressUrls = (protocol = 'http', port) => {
14
+ const getIpv4Interfaces = () => {
15
15
  const interfaces = os_1.default.networkInterfaces();
16
16
  const ipv4Interfaces = [];
17
17
  Object.keys(interfaces).forEach(key => {
18
18
  interfaces[key].forEach(detail => {
19
- if (detail.family === 'IPv4') {
19
+ // 'IPv4' is in Node <= 17, from 18 it's a number 4 or 6
20
+ const familyV4Value = typeof detail.family === 'string' ? 'IPv4' : 4;
21
+ if (detail.family === familyV4Value) {
20
22
  ipv4Interfaces.push(detail);
21
23
  }
22
24
  });
23
25
  });
26
+ return ipv4Interfaces;
27
+ };
28
+ exports.getIpv4Interfaces = getIpv4Interfaces;
29
+ const getAddressUrls = (protocol = 'http', port) => {
30
+ const ipv4Interfaces = (0, exports.getIpv4Interfaces)();
24
31
  return ipv4Interfaces.reduce((memo, detail) => {
25
32
  let type = 'Network: ';
26
33
  let url = `${protocol}://${detail.address}:${port}`;
27
- if (detail.address.includes(`localhost`)) {
34
+ if (detail.address.includes(`localhost`) || detail.internal) {
28
35
  type = 'Local: ';
29
36
  url = `${protocol}://localhost:${port}`;
30
37
  }
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.7.3",
14
+ "version": "1.7.6",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/index.d.ts",
17
17
  "main": "./dist/index.js",
@@ -32,7 +32,9 @@
32
32
  "./gzip-size": "./compiled/gzip-size/index.js",
33
33
  "./mime-types": "./compiled/mime-types/index.js",
34
34
  "./strip-ansi": "./compiled/strip-ansi/index.js",
35
- "./browserslist": "./compiled/browserslist/index.js"
35
+ "./browserslist": "./compiled/browserslist/index.js",
36
+ "./webpack-chain": "./compiled/webpack-chain/index.js",
37
+ "./tsconfig-paths": "./compiled/tsconfig-paths/index.js"
36
38
  },
37
39
  "publishConfig": {
38
40
  "registry": "https://registry.npmjs.org/",
@@ -78,6 +80,12 @@
78
80
  ],
79
81
  "browserslist": [
80
82
  "./compiled/browserslist/index.d.ts"
83
+ ],
84
+ "webpack-chain": [
85
+ "./compiled/webpack-chain/types/index.d.ts"
86
+ ],
87
+ "tsconfig-paths": [
88
+ "./compiled/tsconfig-paths/lib/index.d.ts"
81
89
  ]
82
90
  }
83
91
  },
@@ -86,7 +94,7 @@
86
94
  "lodash": "^4.17.21"
87
95
  },
88
96
  "devDependencies": {
89
- "@modern-js/types": "1.5.3",
97
+ "@modern-js/types": "1.5.4",
90
98
  "@scripts/build": "0.0.0",
91
99
  "@scripts/jest-config": "0.0.0",
92
100
  "@types/jest": "^27",
@@ -101,7 +109,6 @@
101
109
  "command": "tsc",
102
110
  "files": [
103
111
  "src/**/*",
104
- "compiled/**/*.js",
105
112
  "tsconfig.json",
106
113
  "package.json"
107
114
  ],
@@ -113,9 +120,9 @@
113
120
  "command": "jest --passWithNoTests",
114
121
  "files": [
115
122
  "src/**/*",
116
- "compiled/**/*.js",
117
123
  "tsconfig.json",
118
- "package.json"
124
+ "package.json",
125
+ "tests/**/*"
119
126
  ],
120
127
  "output": []
121
128
  }