@modern-js/utils 1.4.1 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (183) hide show
  1. package/CHANGELOG.md +39 -0
  2. package/compiled/address/index.js +1 -0
  3. package/compiled/address/lib/address.d.ts +28 -0
  4. package/compiled/address/package.json +1 -0
  5. package/compiled/browserslist/index.js +1 -1
  6. package/compiled/dotenv/index.js +1 -0
  7. package/compiled/dotenv/license +23 -0
  8. package/compiled/dotenv/package.json +1 -0
  9. package/compiled/dotenv/types/index.d.ts +59 -0
  10. package/compiled/dotenv-expand/index.d.ts +15 -0
  11. package/compiled/dotenv-expand/index.js +1 -0
  12. package/compiled/dotenv-expand/license +24 -0
  13. package/compiled/dotenv-expand/package.json +1 -0
  14. package/compiled/fast-glob/@nodelib/fs.scandir/out/adapters/fs.d.ts +20 -0
  15. package/compiled/fast-glob/@nodelib/fs.scandir/out/index.d.ts +12 -0
  16. package/compiled/fast-glob/@nodelib/fs.scandir/out/providers/async.d.ts +7 -0
  17. package/compiled/fast-glob/@nodelib/fs.scandir/out/settings.d.ts +20 -0
  18. package/compiled/fast-glob/@nodelib/fs.scandir/out/types/index.d.ts +20 -0
  19. package/compiled/fast-glob/@nodelib/fs.stat/out/adapters/fs.d.ts +13 -0
  20. package/compiled/fast-glob/@nodelib/fs.stat/out/index.d.ts +12 -0
  21. package/compiled/fast-glob/@nodelib/fs.stat/out/providers/async.d.ts +4 -0
  22. package/compiled/fast-glob/@nodelib/fs.stat/out/settings.d.ts +16 -0
  23. package/compiled/fast-glob/@nodelib/fs.stat/out/types/index.d.ts +4 -0
  24. package/compiled/fast-glob/@nodelib/fs.walk/out/index.d.ts +14 -0
  25. package/compiled/fast-glob/@nodelib/fs.walk/out/providers/async.d.ts +12 -0
  26. package/compiled/fast-glob/@nodelib/fs.walk/out/readers/async.d.ts +30 -0
  27. package/compiled/fast-glob/@nodelib/fs.walk/out/readers/reader.d.ts +6 -0
  28. package/compiled/fast-glob/@nodelib/fs.walk/out/settings.d.ts +30 -0
  29. package/compiled/fast-glob/@nodelib/fs.walk/out/types/index.d.ts +8 -0
  30. package/compiled/fast-glob/index.js +37 -0
  31. package/compiled/fast-glob/license +21 -0
  32. package/compiled/fast-glob/out/index.d.ts +27 -0
  33. package/compiled/fast-glob/out/managers/tasks.d.ts +22 -0
  34. package/compiled/fast-glob/out/settings.d.ts +164 -0
  35. package/compiled/fast-glob/out/types/index.d.ts +31 -0
  36. package/compiled/fast-glob/package.json +1 -0
  37. package/compiled/globby/index.d.ts +186 -0
  38. package/compiled/globby/index.js +1 -0
  39. package/compiled/globby/license +9 -0
  40. package/compiled/globby/package.json +1 -0
  41. package/compiled/inquirer/index.d.ts +997 -0
  42. package/compiled/inquirer/index.js +9 -0
  43. package/compiled/inquirer/lib/objects/choice.d.ts +65 -0
  44. package/compiled/inquirer/lib/objects/choices.d.ts +206 -0
  45. package/compiled/inquirer/lib/objects/separator.d.ts +37 -0
  46. package/compiled/inquirer/lib/ui/baseUI.d.ts +37 -0
  47. package/compiled/inquirer/lib/ui/bottom-bar.d.ts +65 -0
  48. package/compiled/inquirer/lib/ui/prompt.d.ts +104 -0
  49. package/compiled/inquirer/license +22 -0
  50. package/compiled/inquirer/package.json +1 -0
  51. package/compiled/inquirer/through/index.d.ts +25 -0
  52. package/compiled/json5/index.js +1 -0
  53. package/compiled/json5/lib/index.d.ts +4 -0
  54. package/compiled/json5/lib/parse.d.ts +15 -0
  55. package/compiled/json5/lib/stringify.d.ts +89 -0
  56. package/compiled/json5/package.json +1 -0
  57. package/compiled/lodash/index.js +4 -8
  58. package/compiled/mime-types/index.d.ts +14 -0
  59. package/compiled/mime-types/index.js +14 -0
  60. package/compiled/mime-types/license +23 -0
  61. package/compiled/mime-types/package.json +1 -0
  62. package/compiled/minimist/index.d.ts +95 -0
  63. package/compiled/minimist/index.js +1 -0
  64. package/compiled/minimist/license +18 -0
  65. package/compiled/minimist/package.json +1 -0
  66. package/compiled/ora/cli-spinners/index.d.ts +125 -0
  67. package/compiled/ora/index.d.ts +277 -0
  68. package/compiled/ora/index.js +3 -0
  69. package/compiled/ora/license +9 -0
  70. package/compiled/ora/package.json +1 -0
  71. package/compiled/semver/classes/comparator.d.ts +17 -0
  72. package/compiled/semver/classes/range.d.ts +21 -0
  73. package/compiled/semver/classes/semver.d.ts +62 -0
  74. package/compiled/semver/functions/clean.d.ts +8 -0
  75. package/compiled/semver/functions/cmp.d.ts +16 -0
  76. package/compiled/semver/functions/coerce.d.ts +12 -0
  77. package/compiled/semver/functions/compare-build.d.ts +16 -0
  78. package/compiled/semver/functions/compare-loose.d.ts +5 -0
  79. package/compiled/semver/functions/compare.d.ts +20 -0
  80. package/compiled/semver/functions/diff.d.ts +13 -0
  81. package/compiled/semver/functions/eq.d.ts +9 -0
  82. package/compiled/semver/functions/gt.d.ts +9 -0
  83. package/compiled/semver/functions/gte.d.ts +9 -0
  84. package/compiled/semver/functions/inc.d.ts +15 -0
  85. package/compiled/semver/functions/lt.d.ts +9 -0
  86. package/compiled/semver/functions/lte.d.ts +8 -0
  87. package/compiled/semver/functions/major.d.ts +9 -0
  88. package/compiled/semver/functions/minor.d.ts +9 -0
  89. package/compiled/semver/functions/neq.d.ts +9 -0
  90. package/compiled/semver/functions/parse.d.ts +12 -0
  91. package/compiled/semver/functions/patch.d.ts +9 -0
  92. package/compiled/semver/functions/prerelease.d.ts +12 -0
  93. package/compiled/semver/functions/rcompare.d.ts +15 -0
  94. package/compiled/semver/functions/rsort.d.ts +9 -0
  95. package/compiled/semver/functions/satisfies.d.ts +14 -0
  96. package/compiled/semver/functions/sort.d.ts +9 -0
  97. package/compiled/semver/functions/valid.d.ts +11 -0
  98. package/compiled/semver/index.d.ts +133 -0
  99. package/compiled/semver/index.js +1 -0
  100. package/compiled/semver/internals/identifiers.d.ts +13 -0
  101. package/compiled/semver/license +15 -0
  102. package/compiled/semver/package.json +1 -0
  103. package/compiled/semver/ranges/gtr.d.ts +14 -0
  104. package/compiled/semver/ranges/intersects.d.ts +13 -0
  105. package/compiled/semver/ranges/ltr.d.ts +14 -0
  106. package/compiled/semver/ranges/max-satisfying.d.ts +14 -0
  107. package/compiled/semver/ranges/min-satisfying.d.ts +14 -0
  108. package/compiled/semver/ranges/min-version.d.ts +10 -0
  109. package/compiled/semver/ranges/outside.d.ts +15 -0
  110. package/compiled/semver/ranges/simplify.d.ts +14 -0
  111. package/compiled/semver/ranges/subset.d.ts +13 -0
  112. package/compiled/semver/ranges/to-comparators.d.ts +9 -0
  113. package/compiled/semver/ranges/valid.d.ts +12 -0
  114. package/compiled/slash/index.d.ts +25 -0
  115. package/compiled/slash/index.js +1 -0
  116. package/compiled/slash/license +9 -0
  117. package/compiled/slash/package.json +1 -0
  118. package/compiled/url-join/index.d.ts +17 -0
  119. package/compiled/url-join/index.js +1 -0
  120. package/compiled/url-join/license +21 -0
  121. package/compiled/url-join/package.json +1 -0
  122. package/dist/alias.js +4 -1
  123. package/dist/analyzeProject.d.ts +1 -0
  124. package/dist/analyzeProject.js +31 -0
  125. package/dist/compiled.d.ts +34 -17
  126. package/dist/compiled.js +59 -21
  127. package/dist/constants.d.ts +1 -1
  128. package/dist/constants.js +1 -1
  129. package/dist/emptyDir.js +4 -13
  130. package/dist/format.js +6 -1
  131. package/dist/getEntryOptions.js +2 -1
  132. package/dist/getPackageManager.js +19 -30
  133. package/dist/getPort.js +3 -12
  134. package/dist/getServerConfig.js +2 -11
  135. package/dist/index.d.ts +2 -2
  136. package/dist/index.js +2 -2
  137. package/dist/logger.d.ts +3 -0
  138. package/dist/logger.js +21 -6
  139. package/dist/monorepo.js +4 -1
  140. package/dist/nodeEnv.js +24 -39
  141. package/dist/prettyInstructions.js +3 -3
  142. package/dist/runtimeExports.js +1 -1
  143. package/dist/{ssrHelpers.d.ts → ssr.d.ts} +3 -0
  144. package/dist/{ssrHelpers.js → ssr.js} +0 -0
  145. package/dist/storage.js +1 -1
  146. package/dist/watch.js +9 -18
  147. package/package.json +41 -35
  148. package/tsconfig.json +1 -0
  149. package/dist/getCacheIdentifier.d.ts +0 -7
  150. package/dist/getCacheIdentifier.js +0 -24
  151. package/modern.config.js +0 -6
  152. package/tests/.eslintrc.js +0 -6
  153. package/tests/__snapshots__/prettyInstructions.test.ts.snap +0 -19
  154. package/tests/applyOptionsChain.test.ts +0 -100
  155. package/tests/compatRequire.test.ts +0 -32
  156. package/tests/debug.test.ts +0 -25
  157. package/tests/ensureAbsolutePath.test.ts +0 -16
  158. package/tests/findExists.test.ts +0 -22
  159. package/tests/fixtures/browserlist/develop/package.json +0 -11
  160. package/tests/fixtures/browserlist/dotfile/.browserslistrc +0 -3
  161. package/tests/fixtures/browserlist/pkg/package.json +0 -7
  162. package/tests/fixtures/compat-require/cjs.js +0 -1
  163. package/tests/fixtures/compat-require/empty.js +0 -1
  164. package/tests/fixtures/compat-require/esm.js +0 -5
  165. package/tests/fixtures/compat-require/foo.js +0 -3
  166. package/tests/fixtures/file-exists/a.ejs +0 -0
  167. package/tests/fixtures/file-exists/a.js/.gitkeep +0 -0
  168. package/tests/fixtures/file-exists/a.mjs +0 -0
  169. package/tests/fixtures/file-exists/a.ts +0 -0
  170. package/tests/format.test.ts +0 -60
  171. package/tests/generateMetaTags.test.ts +0 -19
  172. package/tests/getBrowserslist.test.ts +0 -32
  173. package/tests/getCacheIdentifier.test.ts +0 -37
  174. package/tests/getEntryOptions.test.ts +0 -53
  175. package/tests/index.test.ts +0 -18
  176. package/tests/is.test.ts +0 -27
  177. package/tests/isPlatform.test.ts +0 -19
  178. package/tests/isType.test.ts +0 -85
  179. package/tests/logger.test.ts +0 -53
  180. package/tests/prettyInstructions.test.ts +0 -139
  181. package/tests/removeSlash.test.ts +0 -19
  182. package/tests/tsconfig.json +0 -11
  183. package/tests/wait.ts +0 -38
package/dist/watch.js CHANGED
@@ -18,15 +18,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
18
18
  __setModuleDefault(result, mod);
19
19
  return result;
20
20
  };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
21
  Object.defineProperty(exports, "__esModule", { value: true });
31
22
  exports.watch = exports.WatchChangeType = void 0;
32
23
  const path = __importStar(require("path"));
@@ -42,20 +33,20 @@ const watch = (watchDir, runTask, ignored = []) => {
42
33
  ignored,
43
34
  });
44
35
  watcher.on('ready', () => (ready = true));
45
- watcher.on('change', (filePath) => __awaiter(void 0, void 0, void 0, function* () {
36
+ watcher.on('change', async (filePath) => {
46
37
  const changedFilePath = path.resolve(filePath);
47
- yield runTask({ changedFilePath, changeType: exports.WatchChangeType.CHANGE });
48
- }));
49
- watcher.on('add', (filePath) => __awaiter(void 0, void 0, void 0, function* () {
38
+ await runTask({ changedFilePath, changeType: exports.WatchChangeType.CHANGE });
39
+ });
40
+ watcher.on('add', async (filePath) => {
50
41
  const changedFilePath = path.resolve(filePath);
51
42
  if (ready) {
52
- yield runTask({ changedFilePath, changeType: exports.WatchChangeType.ADD });
43
+ await runTask({ changedFilePath, changeType: exports.WatchChangeType.ADD });
53
44
  }
54
- }));
55
- watcher.on('unlink', (filePath) => __awaiter(void 0, void 0, void 0, function* () {
45
+ });
46
+ watcher.on('unlink', async (filePath) => {
56
47
  const changedFilePath = path.resolve(filePath);
57
- yield runTask({ changedFilePath, changeType: exports.WatchChangeType.UNLINK });
58
- }));
48
+ await runTask({ changedFilePath, changeType: exports.WatchChangeType.UNLINK });
49
+ });
59
50
  watcher.on('error', err => {
60
51
  throw err;
61
52
  });
package/package.json CHANGED
@@ -11,12 +11,13 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.4.1",
14
+ "version": "1.7.0",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/index.d.ts",
17
17
  "main": "./dist/index.js",
18
18
  "module": "./dist/index.js",
19
19
  "jsnext:modern": "./dist/index.js",
20
+ "_comment": "Provide ESM and CJS exports, ESM is used by runtime package, for treeshaking",
20
21
  "exports": {
21
22
  ".": {
22
23
  "jsnext:source": "./src/index.ts",
@@ -30,14 +31,19 @@
30
31
  "jsnext:source": "./src/constants.ts",
31
32
  "default": "./dist/constants.js"
32
33
  },
33
- "./lodash": {
34
- "jsnext:source": "./compiled/lodash/index.js",
35
- "default": "./compiled/lodash/index.js"
34
+ "./ssr": {
35
+ "jsnext:source": "./src/ssr.ts",
36
+ "default": "./dist/ssr.js"
36
37
  },
37
- "./strip-ansi": {
38
- "jsnext:source": "./compiled/strip-ansi/index.js",
39
- "default": "./compiled/strip-ansi/index.js"
40
- }
38
+ "./chalk": "./compiled/chalk/index.js",
39
+ "./json5": "./compiled/json5/index.js",
40
+ "./semver": "./compiled/semver/index.js",
41
+ "./lodash": "./compiled/lodash/index.js",
42
+ "./globby": "./compiled/globby/index.js",
43
+ "./fast-glob": "./compiled/fast-glob/index.js",
44
+ "./gzip-size": "./compiled/gzip-size/index.js",
45
+ "./mime-types": "./compiled/mime-types/index.js",
46
+ "./strip-ansi": "./compiled/strip-ansi/index.js"
41
47
  },
42
48
  "typesVersions": {
43
49
  "*": {
@@ -47,50 +53,50 @@
47
53
  "constants": [
48
54
  "./dist/constants.d.ts"
49
55
  ],
56
+ "ssr": [
57
+ "./dist/ssr.d.ts"
58
+ ],
59
+ "chalk": [
60
+ "./compiled/chalk/index.d.ts"
61
+ ],
62
+ "json5": [
63
+ "./compiled/json5/index.d.ts"
64
+ ],
65
+ "semver": [
66
+ "./compiled/semver/index.d.ts"
67
+ ],
50
68
  "lodash": [
51
69
  "./compiled/lodash/index.d.ts"
52
70
  ],
71
+ "globby": [
72
+ "./compiled/globby/index.d.ts"
73
+ ],
74
+ "fast-glob": [
75
+ "./compiled/fast-glob/index.d.ts"
76
+ ],
77
+ "gzip-size": [
78
+ "./compiled/gzip-size/index.d.ts"
79
+ ],
80
+ "mime-types": [
81
+ "./compiled/mime-types/index.d.ts"
82
+ ],
53
83
  "strip-ansi": [
54
84
  "./compiled/strip-ansi/index.d.ts"
55
85
  ]
56
86
  }
57
87
  },
58
88
  "dependencies": {
59
- "@babel/runtime": "^7",
89
+ "caniuse-lite": "^1.0.30001332",
90
+ "lodash": "^4.17.21",
60
91
  "typescript": "^4"
61
92
  },
62
93
  "devDependencies": {
63
- "@modern-js/types": "^1.4.0",
94
+ "@modern-js/types": "1.5.2",
64
95
  "@scripts/build": "0.0.0",
65
96
  "@scripts/jest-config": "0.0.0",
66
- "@types/debug": "4.1.7",
67
- "@types/fs-extra": "9.0.13",
68
- "@types/glob": "^7.1.4",
69
97
  "@types/jest": "^26",
70
- "@types/js-yaml": "4.0.5",
71
- "@types/lodash": "4.14.181",
72
98
  "@types/node": "^14",
73
- "@types/recursive-readdir": "2.2.0",
74
- "@types/signale": "1.4.4",
75
- "browserslist": "4.20.2",
76
- "chalk": "4.1.2",
77
- "chokidar": "3.5.3",
78
- "commander": "8.3.0",
79
- "debug": "4.3.4",
80
- "execa": "5.1.1",
81
- "filesize": "8.0.7",
82
- "fs-extra": "10.0.1",
83
- "glob": "7.2.0",
84
- "gzip-size": "6.0.0",
85
- "import-lazy": "4.0.0",
86
99
  "jest": "^27",
87
- "js-yaml": "4.1.0",
88
- "lodash": "4.17.21",
89
- "pkg-up": "3.1.0",
90
- "recursive-readdir": "2.2.2",
91
- "signale": "1.4.0",
92
- "strip-ansi": "6.0.1",
93
- "upath": "2.0.1",
94
100
  "webpack": "^5.71.0"
95
101
  },
96
102
  "sideEffects": false,
package/tsconfig.json CHANGED
@@ -1,6 +1,7 @@
1
1
  {
2
2
  "extends": "@modern-js/tsconfig/base",
3
3
  "compilerOptions": {
4
+ "target": "ES2019",
4
5
  "declaration": true,
5
6
  "outDir": "./dist",
6
7
  "baseUrl": "./",
@@ -1,7 +0,0 @@
1
- /**
2
- * Generate cache identifier from some packages and config files.
3
- */
4
- export declare function getCacheIdentifier(packages: {
5
- name: string;
6
- version: string;
7
- }[], _files?: string[]): string;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCacheIdentifier = void 0;
4
- const is_1 = require("./is");
5
- /**
6
- * Generate cache identifier from some packages and config files.
7
- */
8
- function getCacheIdentifier(packages, _files) {
9
- /* eslint-disable no-nested-ternary */
10
- let cacheIdentifier = (0, is_1.isProd)()
11
- ? 'production'
12
- : (0, is_1.isDev)()
13
- ? 'development'
14
- : (0, is_1.isTest)()
15
- ? 'test'
16
- : '';
17
- /* eslint-enable no-nested-ternary */
18
- for (const { name, version } of packages) {
19
- cacheIdentifier += `:${name}@${version}`;
20
- }
21
- // TODO: config file hash
22
- return cacheIdentifier;
23
- }
24
- exports.getCacheIdentifier = getCacheIdentifier;
package/modern.config.js DELETED
@@ -1,6 +0,0 @@
1
- /** @type {import('@modern-js/module-tools').UserConfig} */
2
- module.exports = {
3
- output: {
4
- disableSourceMap: true,
5
- },
6
- };
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- extends: ['@modern-js'],
3
- parserOptions: {
4
- project: require.resolve('./tsconfig.json'),
5
- },
6
- };
@@ -1,19 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`prettyInstructions The src directory does not exist 1`] = `
4
- "App running at:
5
-
6
- > Network: http://127.0.0.1:8080/api
7
- > Network: http://11.11.111.11:8080/api
8
- > Network: http://10.100.100.100:8080/api
9
- "
10
- `;
11
-
12
- exports[`prettyInstructions basic usage 1`] = `
13
- "App running at:
14
-
15
- > Network: http://127.0.0.1:8080/
16
- > Network: http://11.11.111.11:8080/
17
- > Network: http://10.100.100.100:8080/
18
- "
19
- `;
@@ -1,100 +0,0 @@
1
- import { applyOptionsChain } from '../src/applyOptionsChain';
2
-
3
- describe('apply options chain', () => {
4
- test(`should return default options`, () => {
5
- expect(applyOptionsChain({ default: 'a' })).toEqual({ default: 'a' });
6
- });
7
-
8
- test(`should merge default options`, () => {
9
- expect(
10
- applyOptionsChain(
11
- { name: 'a' },
12
- {
13
- name: 'b',
14
- custom: 'c',
15
- },
16
- ),
17
- ).toEqual({
18
- name: 'b',
19
- custom: 'c',
20
- });
21
- });
22
-
23
- test(`should support custom merge function`, () => {
24
- const merge = (target: any, source: any) => {
25
- for (const key in source) {
26
- if (target.hasOwnProperty(key)) {
27
- target[key] += source[key];
28
- } else {
29
- target[key] = source[key];
30
- }
31
- }
32
- return target;
33
- };
34
-
35
- expect(
36
- applyOptionsChain(
37
- {
38
- a: 1,
39
- b: 'b',
40
- },
41
- {
42
- a: 2,
43
- b: 'b',
44
- c: 'c',
45
- },
46
- {},
47
- merge,
48
- ),
49
- ).toEqual({
50
- a: 3,
51
- b: 'bb',
52
- c: 'c',
53
- });
54
- });
55
-
56
- test(`should support funciton or object array`, () => {
57
- const defaults = { a: 'a' };
58
-
59
- const options = [
60
- { b: 'b' },
61
- (o: any, { add }: { add: any }) => {
62
- o.c = add(1, 2);
63
- },
64
- (o: any) => ({
65
- ...o,
66
- d: 'd',
67
- }),
68
- { e: 'e' },
69
- ];
70
- expect(
71
- applyOptionsChain(defaults, options as any, {
72
- add: (a: any, b: any) => a + b,
73
- }),
74
- ).toEqual({
75
- a: 'a',
76
- b: 'b',
77
- c: 3,
78
- d: 'd',
79
- e: 'e',
80
- });
81
- });
82
-
83
- test(`should throw error`, () => {
84
- expect(() => {
85
- applyOptionsChain(1, 2);
86
- }).toThrow(/^applyOptionsChain error:/);
87
- });
88
-
89
- test(`should log warning about function result`, () => {
90
- let outputs = '';
91
- /* eslint-disable no-console */
92
- console.log = jest.fn(input => (outputs += input));
93
- /* eslint-enable no-console */
94
- applyOptionsChain({ name: 'a' } as any, [() => 111]);
95
-
96
- expect(outputs).toContain(
97
- 'Function should mutate the config and return nothing, Or return a cloned or merged version of config object.',
98
- );
99
- });
100
- });
@@ -1,32 +0,0 @@
1
- import path from 'path';
2
- import { compatRequire, cleanRequireCache } from '../src/compatRequire';
3
-
4
- describe('compat require', () => {
5
- const fixturePath = path.resolve(__dirname, './fixtures/compat-require');
6
-
7
- test(`should support default property`, () => {
8
- expect(compatRequire(path.join(fixturePath, 'esm.js'))).toEqual({
9
- name: 'esm',
10
- });
11
- });
12
-
13
- test(`should support commonjs module`, () => {
14
- expect(compatRequire(path.join(fixturePath, 'cjs.js'))).toEqual({
15
- name: 'cjs',
16
- });
17
- });
18
-
19
- test(`should return null`, () => {
20
- expect(compatRequire(path.join(fixturePath, 'empty.js'))).toEqual(null);
21
- });
22
-
23
- test('should clearn cache after fn', () => {
24
- const foo = module.require('./fixtures/compat-require/foo');
25
- const requirePath = require.resolve('./fixtures/compat-require/foo.js');
26
- expect(foo.name).toBe('foo');
27
- expect(require.cache[requirePath]).toBeDefined();
28
- cleanRequireCache([requirePath]);
29
- jest.resetModules();
30
- expect(require.cache[requirePath]).toBeUndefined();
31
- });
32
- });
@@ -1,25 +0,0 @@
1
- import { debug } from '../src/compiled';
2
- import { stripAnsi } from '../src';
3
- import { createDebugger } from '../src/debug';
4
-
5
- describe('debug utility', () => {
6
- test('should return file path', () => {
7
- const debug1 = createDebugger('test');
8
-
9
- const debug2 = createDebugger('test2');
10
-
11
- debug.enable('modern-js:test2');
12
-
13
- debug.log = (...args) => {
14
- // XXX: args[0] 的内容有时候是 ' \x1B[38;5;167;1mmodern-js:test2 \x1B[0m22222' 这种格式
15
- expect(stripAnsi(args[0])).toContain('modern-js:test2 22222');
16
- };
17
-
18
- debug1('11111');
19
- debug2('22222');
20
-
21
- expect(debug2.enabled).toBe(true);
22
-
23
- expect(debug1.enabled).toBe(false);
24
- });
25
- });
@@ -1,16 +0,0 @@
1
- import path from 'path';
2
- import { ensureAbsolutePath } from '../src/ensureAbsolutePath';
3
-
4
- describe('ensure absolute file path', () => {
5
- test('should return filePath directly', () => {
6
- expect(
7
- path.isAbsolute(ensureAbsolutePath('/a/b', '/a/b/c/d/e.jsx')),
8
- ).toBeTruthy();
9
- });
10
-
11
- test(`should resolve absolute path`, () => {
12
- expect(
13
- path.isAbsolute(ensureAbsolutePath('/a/b', 'c/d/e.jsx')),
14
- ).toBeTruthy();
15
- });
16
- });
@@ -1,22 +0,0 @@
1
- import path from 'path';
2
- import { findExists } from '../src/findExists';
3
-
4
- describe('find first exists file', () => {
5
- const fixturePath = path.resolve(__dirname, './fixtures/file-exists');
6
-
7
- test('should return file path', () => {
8
- expect(
9
- findExists(
10
- ['.js', '.ts', '.ejs', '.mjs'].map(ext =>
11
- path.join(fixturePath, `a${ext}`),
12
- ),
13
- ),
14
- ).toEqual(path.join(fixturePath, 'a.ts'));
15
- });
16
-
17
- test('should return false when no file exists', () => {
18
- expect(
19
- findExists(['.jsx'].map(ext => path.join(fixturePath, `a${ext}`))),
20
- ).toBe(false);
21
- });
22
- });
@@ -1,11 +0,0 @@
1
- {
2
- "name": "test-browserlist-develop",
3
- "browserslist": {
4
- "development": [
5
- "last 1 chrome version"
6
- ],
7
- "production": [
8
- "IOS 7"
9
- ]
10
- }
11
- }
@@ -1,3 +0,0 @@
1
- defaults
2
- not IE 11
3
- maintained node versions
@@ -1,7 +0,0 @@
1
- {
2
- "name": "test-browserlist-pkg",
3
- "browserslist": [
4
- "not IE 11",
5
- "maintained node versions"
6
- ]
7
- }
@@ -1 +0,0 @@
1
- module.exports = { name: 'cjs' };
@@ -1 +0,0 @@
1
- module.exports = null;
@@ -1,5 +0,0 @@
1
- Object.defineProperty(exports, '__esModule', { value: true });
2
-
3
- const _default = { name: 'esm' };
4
-
5
- exports.default = _default;
@@ -1,3 +0,0 @@
1
- module.exports = {
2
- name: 'foo',
3
- };
File without changes
File without changes
File without changes
File without changes
@@ -1,60 +0,0 @@
1
- import { formatProxyOptions } from '../src/format';
2
-
3
- describe('test format', () => {
4
- it('should format correctly use simply options', async () => {
5
- const proxy = {
6
- '/simple': `http://localhost`,
7
- };
8
-
9
- const options = formatProxyOptions(proxy);
10
- expect(options).toEqual([
11
- {
12
- context: '/simple',
13
- changeOrigin: true,
14
- logLevel: 'warn',
15
- target: 'http://localhost',
16
- },
17
- ]);
18
- });
19
-
20
- it('should format correctly use simply options', async () => {
21
- const proxy = {
22
- '/simple-obj': {
23
- target: `http://localhost`,
24
- },
25
- };
26
- const options = formatProxyOptions(proxy);
27
- expect(options).toEqual([
28
- {
29
- context: '/simple-obj',
30
- changeOrigin: true,
31
- logLevel: 'warn',
32
- target: 'http://localhost',
33
- },
34
- ]);
35
- });
36
-
37
- it('should format correctly use simply options', async () => {
38
- const proxy = {
39
- context: '/context',
40
- target: `http://localhost`,
41
- };
42
- const options = formatProxyOptions(proxy);
43
- expect(options).toEqual([
44
- { context: '/context', target: 'http://localhost' },
45
- ]);
46
- });
47
-
48
- it('should format correctly use simply options', async () => {
49
- const proxy = [
50
- {
51
- context: '/array',
52
- target: `http://localhost`,
53
- },
54
- ];
55
- const options = formatProxyOptions(proxy);
56
- expect(options).toEqual([
57
- { context: '/array', target: 'http://localhost' },
58
- ]);
59
- });
60
- });
@@ -1,19 +0,0 @@
1
- import { generateMetaTags } from '../src/generateMetaTags';
2
-
3
- describe('generateMetaTags', () => {
4
- it('should return empty string when params is empty', () => {
5
- expect(generateMetaTags()).toEqual('');
6
- });
7
-
8
- it('should generate meta tag correctly', () => {
9
- const options = {
10
- foo: {
11
- name: 'viewport',
12
- content: 'width=500, initial-scale=1',
13
- },
14
- };
15
- expect(generateMetaTags(options).trim()).toEqual(
16
- '<meta name="viewport" content="width=500, initial-scale=1">',
17
- );
18
- });
19
- });
@@ -1,32 +0,0 @@
1
- import path from 'path';
2
- import { getBrowserslist, defaults } from '../src/getBrowserslist';
3
-
4
- describe('get browserslist', () => {
5
- const fixture = path.resolve(__dirname, './fixtures/browserlist');
6
-
7
- test(`should load browserslist from package.json`, () => {
8
- expect(getBrowserslist(path.join(fixture, 'pkg'))).toEqual([
9
- 'not IE 11',
10
- 'maintained node versions',
11
- ]);
12
- });
13
-
14
- test(`should load browerslist from .browserslistrc`, () => {
15
- expect(getBrowserslist(path.join(fixture, 'dotfile'))).toEqual([
16
- 'defaults',
17
- 'not IE 11',
18
- 'maintained node versions',
19
- ]);
20
- });
21
-
22
- test(`should load browserslist base on environment`, () => {
23
- process.env.NODE_ENV = 'development';
24
- expect(getBrowserslist(path.join(fixture, 'develop'))).toEqual([
25
- 'last 1 chrome version',
26
- ]);
27
- });
28
-
29
- test(`should return default browserslist config`, () => {
30
- expect(getBrowserslist(path.join(fixture))).toEqual(defaults);
31
- });
32
- });
@@ -1,37 +0,0 @@
1
- import { getCacheIdentifier } from '../src/getCacheIdentifier';
2
-
3
- describe('get cache identifier', () => {
4
- test('should use package name and version', () => {
5
- expect(
6
- getCacheIdentifier([
7
- {
8
- name: 'package-a',
9
- version: '0.1.0',
10
- },
11
- {
12
- name: 'package-b',
13
- version: '1.0.1',
14
- },
15
- ]),
16
- ).toEqual(`test:package-a@0.1.0:package-b@1.0.1`);
17
- });
18
-
19
- test(`should return identifier with node environment`, () => {
20
- const packages = [
21
- {
22
- name: 'a',
23
- version: '0.1.0',
24
- },
25
- ];
26
-
27
- process.env.NODE_ENV = 'development';
28
- expect(getCacheIdentifier(packages)).toEqual('development:a@0.1.0');
29
-
30
- process.env.NODE_ENV = 'production';
31
- expect(getCacheIdentifier(packages)).toEqual('production:a@0.1.0');
32
-
33
- process.env.NODE_ENV = '';
34
-
35
- expect(getCacheIdentifier(packages)).toEqual(`:a@0.1.0`);
36
- });
37
- });