@modern-js/utils 1.7.6 → 1.7.9-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -1,6 +1,2 @@
1
- export declare const applyOptionsChain: <T, U>(defaults: T, options?: T | (T | ((config: T, utils?: U | undefined) => void | T))[] | ((config: T, utils?: U | undefined) => void | T) | undefined, utils?: U | undefined, mergeFn?: {
2
- <T_1, U_1>(target: T_1, source: U_1): T_1 & U_1;
3
- <T_2, U_2, V>(target: T_2, source1: U_2, source2: V): T_2 & U_2 & V;
4
- <T_3, U_3, V_1, W>(target: T_3, source1: U_3, source2: V_1, source3: W): T_3 & U_3 & V_1 & W;
5
- (target: object, ...sources: any[]): any;
6
- }) => T;
1
+ export declare function applyOptionsChain<T, U>(defaults: T, options?: T | ((config: T, utils?: U) => T | void) | Array<T | ((config: T, utils?: U) => T | void)>, utils?: U, mergeFn?: typeof Object.assign): T;
2
+ export declare function applyOptionsChain<T, U>(defaults: T, options: T | ((config: T, utils: U) => T | void) | Array<T | ((config: T, utils: U) => T | void)>, utils: U, mergeFn?: typeof Object.assign): T;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.applyOptionsChain = void 0;
4
4
  // eslint-disable-next-line import/no-useless-path-segments
5
5
  const index_1 = require("./index");
6
- const applyOptionsChain = (defaults, options, utils, mergeFn = Object.assign) => {
6
+ function applyOptionsChain(defaults, options, utils, mergeFn = Object.assign) {
7
7
  if (!options) {
8
8
  return defaults;
9
9
  }
@@ -20,11 +20,11 @@ const applyOptionsChain = (defaults, options, utils, mergeFn = Object.assign) =>
20
20
  }
21
21
  }
22
22
  else if (Array.isArray(options)) {
23
- return options.reduce((memo, cur) => (0, exports.applyOptionsChain)(memo, cur, utils, mergeFn), defaults);
23
+ return options.reduce((memo, cur) => applyOptionsChain(memo, cur, utils, mergeFn), defaults);
24
24
  }
25
25
  else {
26
26
  throw new Error(`applyOptionsChain error:\ndefault options is: ${JSON.stringify(defaults)}`);
27
27
  }
28
28
  return defaults;
29
- };
29
+ }
30
30
  exports.applyOptionsChain = applyOptionsChain;
@@ -31,6 +31,7 @@ export type { SignaleOptions } from '../compiled/signale';
31
31
  export type { IOptions as GlobOptions } from '../compiled/glob';
32
32
  export type { GlobbyOptions } from '../compiled/globby';
33
33
  export type { FSWatcher, WatchOptions } from '../compiled/chokidar';
34
+ export type { ExecaError } from '../compiled/execa';
34
35
  /**
35
36
  * Lazy import some expensive modules that will slow down startup speed.
36
37
  * Notice that `csmith-tools build` can not bundle lazy imported modules.
@@ -0,0 +1 @@
1
+ export declare const ensureArray: <T>(params: T | T[]) => T[];
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureArray = void 0;
4
+ const ensureArray = (params) => {
5
+ if (Array.isArray(params)) {
6
+ return params;
7
+ }
8
+ return [params];
9
+ };
10
+ exports.ensureArray = ensureArray;
@@ -13,4 +13,4 @@ export declare type MetaAttributes = {
13
13
  export interface MetaOptions {
14
14
  [name: string]: string | false | MetaAttributes;
15
15
  }
16
- export declare const generateMetaTags: (metaOptions?: MetaOptions | undefined) => string;
16
+ export declare const generateMetaTags: (metaOptions?: MetaOptions) => string;
@@ -1 +1 @@
1
- export declare const getEntryOptions: <T>(name: string, baseOptions?: T | undefined, optionsByEntries?: Record<string, T> | undefined, packageName?: string | undefined) => T | undefined;
1
+ export declare const getEntryOptions: <T>(name: string, baseOptions?: T | undefined, optionsByEntries?: Record<string, T> | undefined, packageName?: string) => T | undefined;
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/dist/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export * from './is';
8
8
  export * from './compatRequire';
9
9
  export * from './logger';
10
10
  export * from './constants';
11
+ export * from './ensureArray';
11
12
  export * from './ensureAbsolutePath';
12
13
  export * from './clearConsole';
13
14
  export * from './applyOptionsChain';
@@ -30,5 +31,6 @@ export * from './wait';
30
31
  export * from './emptyDir';
31
32
  export * from './getServerConfig';
32
33
  export * from './ssr';
34
+ export * from './tryResolve';
33
35
  export * from './analyzeProject';
34
36
  export * from './chainId';
package/dist/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -20,6 +24,7 @@ __exportStar(require("./is"), exports);
20
24
  __exportStar(require("./compatRequire"), exports);
21
25
  __exportStar(require("./logger"), exports);
22
26
  __exportStar(require("./constants"), exports);
27
+ __exportStar(require("./ensureArray"), exports);
23
28
  __exportStar(require("./ensureAbsolutePath"), exports);
24
29
  __exportStar(require("./clearConsole"), exports);
25
30
  __exportStar(require("./applyOptionsChain"), exports);
@@ -42,5 +47,6 @@ __exportStar(require("./wait"), exports);
42
47
  __exportStar(require("./emptyDir"), exports);
43
48
  __exportStar(require("./getServerConfig"), exports);
44
49
  __exportStar(require("./ssr"), exports);
50
+ __exportStar(require("./tryResolve"), exports);
45
51
  __exportStar(require("./analyzeProject"), exports);
46
52
  __exportStar(require("./chainId"), exports);
package/dist/is/index.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/dist/path.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export declare const isRelativePath: (test: string) => boolean;
2
2
  export declare const normalizeOutputPath: (s: string) => string;
3
- export declare const normalizeToPosixPath: (p: string) => string;
3
+ export declare const normalizeToPosixPath: (p: string | undefined) => string;
package/dist/path.js CHANGED
@@ -10,5 +10,5 @@ const isRelativePath = (test) => /^\.\.?($|[\\/])/.test(test);
10
10
  exports.isRelativePath = isRelativePath;
11
11
  const normalizeOutputPath = (s) => s.replace(/\\/g, '\\\\');
12
12
  exports.normalizeOutputPath = normalizeOutputPath;
13
- const normalizeToPosixPath = (p) => compiled_1.upath.normalizeSafe(path_1.default.normalize(p));
13
+ const normalizeToPosixPath = (p) => compiled_1.upath.normalizeSafe(path_1.default.normalize(p || ''));
14
14
  exports.normalizeToPosixPath = normalizeToPosixPath;
package/dist/storage.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -0,0 +1,11 @@
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
+ export declare const isPackageInstalled: (name: string, resolvePaths: string | string[]) => boolean;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isPackageInstalled = exports.tryResolve = void 0;
4
+ const ensureArray_1 = require("./ensureArray");
5
+ /**
6
+ * Try to resolve npm package entry file path.
7
+ * @param name - Package name.
8
+ * @param resolvePath - Path to resolve dependencies.
9
+ * @returns Resolved file path.
10
+ */
11
+ const tryResolve = (name, resolvePath) => {
12
+ let filePath = '';
13
+ try {
14
+ filePath = require.resolve(name, { paths: [resolvePath] });
15
+ delete require.cache[filePath];
16
+ }
17
+ catch (err) {
18
+ if (err.code === 'MODULE_NOT_FOUND') {
19
+ throw new Error(`Can not find module ${name}.`);
20
+ }
21
+ throw err;
22
+ }
23
+ return filePath;
24
+ };
25
+ exports.tryResolve = tryResolve;
26
+ /**
27
+ * Try to resolve npm package, return true if package is installed.
28
+ */
29
+ const isPackageInstalled = (name, resolvePaths) => {
30
+ try {
31
+ require.resolve(name, { paths: (0, ensureArray_1.ensureArray)(resolvePaths) });
32
+ return true;
33
+ }
34
+ catch (err) {
35
+ return false;
36
+ }
37
+ };
38
+ exports.isPackageInstalled = isPackageInstalled;
package/dist/watch.js CHANGED
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.7.6",
14
+ "version": "1.7.9-alpha.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/index.d.ts",
17
17
  "main": "./dist/index.js",
@@ -23,6 +23,7 @@
23
23
  "./format": "./dist/format.js",
24
24
  "./constants": "./dist/constants.js",
25
25
  "./ssr": "./dist/ssr.js",
26
+ "./glob": "./compiled/glob/index.js",
26
27
  "./chalk": "./compiled/chalk/index.js",
27
28
  "./json5": "./compiled/json5/index.js",
28
29
  "./semver": "./compiled/semver/index.js",
@@ -51,6 +52,9 @@
51
52
  "ssr": [
52
53
  "./dist/ssr.d.ts"
53
54
  ],
55
+ "glob": [
56
+ "./compiled/glob/index.d.ts"
57
+ ],
54
58
  "chalk": [
55
59
  "./compiled/chalk/index.d.ts"
56
60
  ],
@@ -94,7 +98,7 @@
94
98
  "lodash": "^4.17.21"
95
99
  },
96
100
  "devDependencies": {
97
- "@modern-js/types": "1.5.4",
101
+ "@modern-js/types": "1.5.5-alpha.0",
98
102
  "@scripts/build": "0.0.0",
99
103
  "@scripts/jest-config": "0.0.0",
100
104
  "@types/jest": "^27",