@modern-js/utils 1.6.0 → 1.7.1-alpha.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (90) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/compiled/globby/index.d.ts +1 -1
  3. package/compiled/lodash/index.js +4 -8
  4. package/compiled/semver/classes/comparator.d.ts +17 -0
  5. package/compiled/semver/classes/range.d.ts +21 -0
  6. package/compiled/semver/classes/semver.d.ts +62 -0
  7. package/compiled/semver/functions/clean.d.ts +8 -0
  8. package/compiled/semver/functions/cmp.d.ts +16 -0
  9. package/compiled/semver/functions/coerce.d.ts +12 -0
  10. package/compiled/semver/functions/compare-build.d.ts +16 -0
  11. package/compiled/semver/functions/compare-loose.d.ts +5 -0
  12. package/compiled/semver/functions/compare.d.ts +20 -0
  13. package/compiled/semver/functions/diff.d.ts +13 -0
  14. package/compiled/semver/functions/eq.d.ts +9 -0
  15. package/compiled/semver/functions/gt.d.ts +9 -0
  16. package/compiled/semver/functions/gte.d.ts +9 -0
  17. package/compiled/semver/functions/inc.d.ts +15 -0
  18. package/compiled/semver/functions/lt.d.ts +9 -0
  19. package/compiled/semver/functions/lte.d.ts +8 -0
  20. package/compiled/semver/functions/major.d.ts +9 -0
  21. package/compiled/semver/functions/minor.d.ts +9 -0
  22. package/compiled/semver/functions/neq.d.ts +9 -0
  23. package/compiled/semver/functions/parse.d.ts +12 -0
  24. package/compiled/semver/functions/patch.d.ts +9 -0
  25. package/compiled/semver/functions/prerelease.d.ts +12 -0
  26. package/compiled/semver/functions/rcompare.d.ts +15 -0
  27. package/compiled/semver/functions/rsort.d.ts +9 -0
  28. package/compiled/semver/functions/satisfies.d.ts +14 -0
  29. package/compiled/semver/functions/sort.d.ts +9 -0
  30. package/compiled/semver/functions/valid.d.ts +11 -0
  31. package/compiled/semver/index.d.ts +133 -0
  32. package/compiled/semver/index.js +1 -0
  33. package/compiled/semver/internals/identifiers.d.ts +13 -0
  34. package/compiled/semver/license +15 -0
  35. package/compiled/semver/package.json +1 -0
  36. package/compiled/semver/ranges/gtr.d.ts +14 -0
  37. package/compiled/semver/ranges/intersects.d.ts +13 -0
  38. package/compiled/semver/ranges/ltr.d.ts +14 -0
  39. package/compiled/semver/ranges/max-satisfying.d.ts +14 -0
  40. package/compiled/semver/ranges/min-satisfying.d.ts +14 -0
  41. package/compiled/semver/ranges/min-version.d.ts +10 -0
  42. package/compiled/semver/ranges/outside.d.ts +15 -0
  43. package/compiled/semver/ranges/simplify.d.ts +14 -0
  44. package/compiled/semver/ranges/subset.d.ts +13 -0
  45. package/compiled/semver/ranges/to-comparators.d.ts +9 -0
  46. package/compiled/semver/ranges/valid.d.ts +12 -0
  47. package/dist/alias.js +4 -1
  48. package/dist/analyzeProject.js +3 -12
  49. package/dist/compiled.d.ts +1 -0
  50. package/dist/compiled.js +3 -1
  51. package/dist/emptyDir.js +4 -13
  52. package/dist/ensureAbsolutePath.d.ts +1 -1
  53. package/dist/ensureAbsolutePath.js +1 -1
  54. package/dist/findExists.d.ts +1 -1
  55. package/dist/findExists.js +1 -1
  56. package/dist/format.js +11 -6
  57. package/dist/getEntryOptions.js +2 -1
  58. package/dist/getPackageManager.js +19 -30
  59. package/dist/getPort.js +3 -12
  60. package/dist/getServerConfig.js +2 -11
  61. package/dist/logger.d.ts +3 -0
  62. package/dist/logger.js +21 -6
  63. package/dist/monorepo.js +9 -6
  64. package/dist/nodeEnv.js +24 -39
  65. package/dist/prettyInstructions.js +1 -1
  66. package/dist/readTsConfig.js +2 -2
  67. package/dist/runtimeExports.js +1 -1
  68. package/dist/watch.js +9 -18
  69. package/package.json +41 -30
  70. package/tsconfig.json +1 -0
  71. package/compiled/globby/@nodelib/fs.scandir/out/adapters/fs.d.ts +0 -20
  72. package/compiled/globby/@nodelib/fs.scandir/out/index.d.ts +0 -12
  73. package/compiled/globby/@nodelib/fs.scandir/out/providers/async.d.ts +0 -7
  74. package/compiled/globby/@nodelib/fs.scandir/out/settings.d.ts +0 -20
  75. package/compiled/globby/@nodelib/fs.scandir/out/types/index.d.ts +0 -20
  76. package/compiled/globby/@nodelib/fs.stat/out/adapters/fs.d.ts +0 -13
  77. package/compiled/globby/@nodelib/fs.stat/out/index.d.ts +0 -12
  78. package/compiled/globby/@nodelib/fs.stat/out/providers/async.d.ts +0 -4
  79. package/compiled/globby/@nodelib/fs.stat/out/settings.d.ts +0 -16
  80. package/compiled/globby/@nodelib/fs.stat/out/types/index.d.ts +0 -4
  81. package/compiled/globby/@nodelib/fs.walk/out/index.d.ts +0 -14
  82. package/compiled/globby/@nodelib/fs.walk/out/providers/async.d.ts +0 -12
  83. package/compiled/globby/@nodelib/fs.walk/out/readers/async.d.ts +0 -30
  84. package/compiled/globby/@nodelib/fs.walk/out/readers/reader.d.ts +0 -6
  85. package/compiled/globby/@nodelib/fs.walk/out/settings.d.ts +0 -30
  86. package/compiled/globby/@nodelib/fs.walk/out/types/index.d.ts +0 -8
  87. package/compiled/globby/fast-glob/index.d.ts +0 -27
  88. package/compiled/globby/fast-glob/managers/tasks.d.ts +0 -22
  89. package/compiled/globby/fast-glob/settings.d.ts +0 -164
  90. package/compiled/globby/fast-glob/types/index.d.ts +0 -31
package/dist/format.js CHANGED
@@ -92,22 +92,27 @@ function formatWebpackMessages(json) {
92
92
  exports.formatWebpackMessages = formatWebpackMessages;
93
93
  /* eslint-enable no-param-reassign */
94
94
  function formatProxyOptions(proxyOptions) {
95
- const formatedProxy = [];
95
+ const formattedProxy = [];
96
96
  if (!Array.isArray(proxyOptions)) {
97
97
  if ('target' in proxyOptions) {
98
- formatedProxy.push(proxyOptions);
98
+ formattedProxy.push(proxyOptions);
99
99
  }
100
100
  else {
101
- Array.prototype.push.apply(formatedProxy, Object.keys(proxyOptions).reduce((total, source) => {
101
+ Array.prototype.push.apply(formattedProxy, Object.keys(proxyOptions).reduce((total, source) => {
102
102
  const option = proxyOptions[source];
103
- total.push(Object.assign({ context: source, changeOrigin: true, logLevel: 'warn' }, (typeof option === 'string' ? { target: option } : option)));
103
+ total.push({
104
+ context: source,
105
+ changeOrigin: true,
106
+ logLevel: 'warn',
107
+ ...(typeof option === 'string' ? { target: option } : option),
108
+ });
104
109
  return total;
105
110
  }, []));
106
111
  }
107
112
  }
108
113
  else {
109
- formatedProxy.push(...proxyOptions);
114
+ formattedProxy.push(...proxyOptions);
110
115
  }
111
- return formatedProxy;
116
+ return formattedProxy;
112
117
  }
113
118
  exports.formatProxyOptions = formatProxyOptions;
@@ -15,7 +15,8 @@ const getEntryOptions = (name, baseOptions, optionsByEntries, packageName) => {
15
15
  // eslint-disable-next-line no-nested-ternary
16
16
  return optionsByEntry !== undefined
17
17
  ? (0, is_1.isPlainObject)(optionsByEntry) && (0, is_1.isPlainObject)(baseOptions)
18
- ? Object.assign(Object.assign({}, baseOptions), optionsByEntry) : optionsByEntry
18
+ ? { ...baseOptions, ...optionsByEntry }
19
+ : optionsByEntry
19
20
  : baseOptions;
20
21
  }
21
22
  else {
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -18,30 +9,28 @@ const path_1 = __importDefault(require("path"));
18
9
  const compiled_1 = require("./compiled");
19
10
  const nodeEnv_1 = require("./nodeEnv");
20
11
  const MAX_TIMES = 5;
21
- function getPackageManager(cwd = process.cwd()) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- let appDirectory = cwd;
24
- let times = 0;
25
- while (os_1.default.homedir() !== appDirectory && times < MAX_TIMES) {
26
- times++;
27
- if (compiled_1.fs.existsSync(path_1.default.resolve(appDirectory, 'pnpm-lock.yaml'))) {
28
- return 'pnpm';
29
- }
30
- if (compiled_1.fs.existsSync(path_1.default.resolve(appDirectory, 'yarn.lock'))) {
31
- return 'yarn';
32
- }
33
- if (compiled_1.fs.existsSync(path_1.default.resolve(appDirectory, 'package-lock.json'))) {
34
- return 'npm';
35
- }
36
- appDirectory = path_1.default.join(appDirectory, '..');
37
- }
38
- if (yield (0, nodeEnv_1.canUsePnpm)()) {
12
+ async function getPackageManager(cwd = process.cwd()) {
13
+ let appDirectory = cwd;
14
+ let times = 0;
15
+ while (os_1.default.homedir() !== appDirectory && times < MAX_TIMES) {
16
+ times++;
17
+ if (compiled_1.fs.existsSync(path_1.default.resolve(appDirectory, 'pnpm-lock.yaml'))) {
39
18
  return 'pnpm';
40
19
  }
41
- if (yield (0, nodeEnv_1.canUseYarn)()) {
20
+ if (compiled_1.fs.existsSync(path_1.default.resolve(appDirectory, 'yarn.lock'))) {
42
21
  return 'yarn';
43
22
  }
44
- return 'npm';
45
- });
23
+ if (compiled_1.fs.existsSync(path_1.default.resolve(appDirectory, 'package-lock.json'))) {
24
+ return 'npm';
25
+ }
26
+ appDirectory = path_1.default.join(appDirectory, '..');
27
+ }
28
+ if (await (0, nodeEnv_1.canUsePnpm)()) {
29
+ return 'pnpm';
30
+ }
31
+ if (await (0, nodeEnv_1.canUseYarn)()) {
32
+ return 'yarn';
33
+ }
34
+ return 'npm';
46
35
  }
47
36
  exports.getPackageManager = getPackageManager;
package/dist/getPort.js CHANGED
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -23,7 +14,7 @@ const logger_1 = require("./logger");
23
14
  * @returns Available port number.
24
15
  */
25
16
  /* eslint-disable no-param-reassign, @typescript-eslint/no-loop-func */
26
- const getPort = (port, tryLimits = 20) => __awaiter(void 0, void 0, void 0, function* () {
17
+ const getPort = async (port, tryLimits = 20) => {
27
18
  if (typeof port === 'string') {
28
19
  port = parseInt(port, 10);
29
20
  }
@@ -32,7 +23,7 @@ const getPort = (port, tryLimits = 20) => __awaiter(void 0, void 0, void 0, func
32
23
  let attempts = 0;
33
24
  while (!found && attempts <= tryLimits) {
34
25
  try {
35
- yield new Promise((resolve, reject) => {
26
+ await new Promise((resolve, reject) => {
36
27
  const server = net_1.default.createServer();
37
28
  server.unref();
38
29
  server.on('error', reject);
@@ -57,6 +48,6 @@ const getPort = (port, tryLimits = 20) => __awaiter(void 0, void 0, void 0, func
57
48
  logger_1.logger.info(compiled_1.chalk.red(`Something is already running on port ${original}. ${compiled_1.chalk.yellow(`Use port ${port} instead.`)}`));
58
49
  }
59
50
  return port;
60
- });
51
+ };
61
52
  exports.getPort = getPort;
62
53
  /* eslint-enable no-param-reassign, @typescript-eslint/no-loop-func */
@@ -18,22 +18,13 @@ 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.getServerConfig = void 0;
32
23
  const path = __importStar(require("path"));
33
24
  const constants_1 = require("./constants");
34
25
  const findExists_1 = require("./findExists");
35
- const getServerConfig = (appDirectory, configFile) => __awaiter(void 0, void 0, void 0, function* () {
26
+ const getServerConfig = async (appDirectory, configFile) => {
36
27
  const configFilePath = (0, findExists_1.findExists)(constants_1.CONFIG_FILE_EXTENSIONS.map(extension => path.resolve(appDirectory, `${configFile}${extension}`)));
37
28
  return configFilePath;
38
- });
29
+ };
39
30
  exports.getServerConfig = getServerConfig;
package/dist/logger.d.ts CHANGED
@@ -12,6 +12,7 @@ interface InstanceConfiguration {
12
12
  }
13
13
  interface ConstructorOptions {
14
14
  config?: InstanceConfiguration;
15
+ level?: string;
15
16
  types?: Record<string, LoggerConfiguration>;
16
17
  }
17
18
  declare type LoggerFunction = (message?: number | string | Error, ...args: any[]) => void;
@@ -42,6 +43,7 @@ declare const LOG_TYPES: {
42
43
  };
43
44
  declare class Logger {
44
45
  private readonly logCount;
46
+ private readonly level;
45
47
  private history;
46
48
  private readonly config;
47
49
  private readonly types;
@@ -59,5 +61,6 @@ declare type LoggerInterface = {
59
61
  [key in keyof typeof LOG_TYPES]: LoggerFunction;
60
62
  };
61
63
  declare const logger: Logger & LoggerInterface;
64
+ export { Logger };
62
65
  export { logger };
63
66
  export type { LoggerInterface };
package/dist/logger.js CHANGED
@@ -3,9 +3,16 @@ 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.logger = void 0;
6
+ exports.logger = exports.Logger = void 0;
7
7
  const chalk_1 = __importDefault(require("../compiled/chalk"));
8
8
  const { grey, underline } = chalk_1.default;
9
+ const LOG_LEVEL = {
10
+ error: 0,
11
+ warn: 1,
12
+ info: 2,
13
+ debug: 3,
14
+ log: 4,
15
+ };
9
16
  const LOG_TYPES = {
10
17
  error: {
11
18
  color: 'red',
@@ -27,7 +34,7 @@ const LOG_TYPES = {
27
34
  label: 'debug',
28
35
  level: 'debug',
29
36
  },
30
- log: { level: 'info' },
37
+ log: { level: 'log' },
31
38
  };
32
39
  const DEFAULT_CONFIG = {
33
40
  displayLabel: true,
@@ -38,8 +45,12 @@ class Logger {
38
45
  constructor(options = {}) {
39
46
  this.logCount = 200;
40
47
  this.history = {};
41
- this.config = Object.assign(Object.assign({}, DEFAULT_CONFIG), (options.config || {}));
42
- this.types = Object.assign(Object.assign({}, LOG_TYPES), (options.types || {}));
48
+ this.level = options.level || LOG_TYPES.log.level;
49
+ this.config = { ...DEFAULT_CONFIG, ...(options.config || {}) };
50
+ this.types = {
51
+ ...LOG_TYPES,
52
+ ...(options.types || {}),
53
+ };
43
54
  this.longestLabel = this.getLongestLabel();
44
55
  Object.keys(this.types).forEach(type => {
45
56
  this[type] = this._log.bind(this, type);
@@ -54,12 +65,15 @@ class Logger {
54
65
  this.history[type].shift();
55
66
  }
56
67
  }
57
- _log(type, message) {
68
+ _log(type, message, ...args) {
58
69
  if (message === undefined) {
59
70
  // eslint-disable-next-line no-console
60
71
  console.log();
61
72
  return;
62
73
  }
74
+ if (LOG_LEVEL[type] > LOG_LEVEL[this.level]) {
75
+ return;
76
+ }
63
77
  let label = '';
64
78
  let text = '';
65
79
  const logType = this.types[type];
@@ -94,7 +108,7 @@ class Logger {
94
108
  }
95
109
  const log = label.length > 0 ? `${label} ${text}` : text;
96
110
  // eslint-disable-next-line no-console
97
- console.log(log);
111
+ console.log(log, ...args);
98
112
  }
99
113
  getLongestLabel() {
100
114
  let longestLabel = '';
@@ -123,6 +137,7 @@ class Logger {
123
137
  }
124
138
  }
125
139
  }
140
+ exports.Logger = Logger;
126
141
  const logger = new Logger();
127
142
  exports.logger = logger;
128
143
  logger.Logger = Logger;
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 WOKRSPACES_FILES = {
11
+ const WORKSPACES_FILES = {
12
12
  YARN: 'package.json',
13
13
  PNPM: 'pnpm-workspaces.yaml',
14
14
  LERNA: 'lerna.json',
15
15
  };
16
- const isLerna = (root) => fs_1.default.existsSync(path_1.default.join(root, WOKRSPACES_FILES.LERNA));
16
+ const isLerna = (root) => fs_1.default.existsSync(path_1.default.join(root, WORKSPACES_FILES.LERNA));
17
17
  exports.isLerna = isLerna;
18
18
  const isYarnWorkspaces = (root) => {
19
19
  var _a;
20
- const pkg = path_1.default.join(root, WOKRSPACES_FILES.YARN);
20
+ const pkg = path_1.default.join(root, WORKSPACES_FILES.YARN);
21
21
  if (!fs_1.default.existsSync(pkg)) {
22
22
  return false;
23
23
  }
@@ -25,13 +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, WOKRSPACES_FILES.PNPM));
28
+ const isPnpmWorkspaces = (root) => fs_1.default.existsSync(path_1.default.join(root, WORKSPACES_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
33
  const json = JSON.parse(fs_1.default.readFileSync(path_1.default.join(root, 'package.json'), 'utf8'));
34
- const deps = Object.assign(Object.assign({}, (json.dependencies || {})), (json.devDependencies || {}));
34
+ const deps = {
35
+ ...(json.dependencies || {}),
36
+ ...(json.devDependencies || {}),
37
+ };
35
38
  return Boolean(deps['@modern-js/monorepo-tools']);
36
39
  };
37
40
  exports.isModernjsMonorepo = isModernjsMonorepo;
@@ -59,7 +62,7 @@ const getMonorepoPackages = (root) => {
59
62
  ({ packages } = json);
60
63
  }
61
64
  else {
62
- ({ packages } = compiled_1.yaml.load(fs_1.default.readFileSync(path_1.default.join(root, WOKRSPACES_FILES.PNPM), 'utf8')));
65
+ ({ packages } = compiled_1.yaml.load(fs_1.default.readFileSync(path_1.default.join(root, WORKSPACES_FILES.PNPM), 'utf8')));
63
66
  }
64
67
  if (packages) {
65
68
  return packages
package/dist/nodeEnv.js CHANGED
@@ -1,49 +1,34 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.canUsePnpm = exports.canUseYarn = exports.canUseNpm = void 0;
13
4
  const compiled_1 = require("./compiled");
14
- function canUseNpm() {
15
- return __awaiter(this, void 0, void 0, function* () {
16
- try {
17
- yield (0, compiled_1.execa)('npm', ['--version'], { env: process.env });
18
- return true;
19
- }
20
- catch (e) {
21
- return false;
22
- }
23
- });
5
+ async function canUseNpm() {
6
+ try {
7
+ await (0, compiled_1.execa)('npm', ['--version'], { env: process.env });
8
+ return true;
9
+ }
10
+ catch (e) {
11
+ return false;
12
+ }
24
13
  }
25
14
  exports.canUseNpm = canUseNpm;
26
- function canUseYarn() {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- try {
29
- yield (0, compiled_1.execa)('yarn', ['--version'], { env: process.env });
30
- return true;
31
- }
32
- catch (e) {
33
- return false;
34
- }
35
- });
15
+ async function canUseYarn() {
16
+ try {
17
+ await (0, compiled_1.execa)('yarn', ['--version'], { env: process.env });
18
+ return true;
19
+ }
20
+ catch (e) {
21
+ return false;
22
+ }
36
23
  }
37
24
  exports.canUseYarn = canUseYarn;
38
- function canUsePnpm() {
39
- return __awaiter(this, void 0, void 0, function* () {
40
- try {
41
- yield (0, compiled_1.execa)('pnpm', ['--version'], { env: process.env });
42
- return true;
43
- }
44
- catch (e) {
45
- return false;
46
- }
47
- });
25
+ async function canUsePnpm() {
26
+ try {
27
+ await (0, compiled_1.execa)('pnpm', ['--version'], { env: process.env });
28
+ return true;
29
+ }
30
+ catch (e) {
31
+ return false;
32
+ }
48
33
  }
49
34
  exports.canUsePnpm = canUsePnpm;
@@ -57,7 +57,7 @@ const prettyInstructions = (appContext, config) => {
57
57
  });
58
58
  message += '\n';
59
59
  message += compiled_1.chalk.cyanBright(' λ (Server) server-side renders at runtime\n');
60
- message += compiled_1.chalk.cyanBright(' ○ (Static) client-side rendered as static HTML\n');
60
+ message += compiled_1.chalk.cyanBright(' ○ (Static) client-side renders as static HTML\n');
61
61
  }
62
62
  return message;
63
63
  };
@@ -6,13 +6,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.readTsConfigByFile = exports.readTsConfig = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
8
  const readTsConfig = (root) => {
9
- // import typescript from 'typescript' cause eslint fromat error.
9
+ // import typescript from 'typescript' cause eslint format error.
10
10
  const typescript = require('typescript');
11
11
  return typescript.readConfigFile(path_1.default.resolve(root, './tsconfig.json'), typescript.sys.readFile).config;
12
12
  };
13
13
  exports.readTsConfig = readTsConfig;
14
14
  const readTsConfigByFile = (filename) => {
15
- // import typescript from 'typescript' cause eslint fromat error.
15
+ // import typescript from 'typescript' cause eslint format error.
16
16
  const typescript = require('typescript');
17
17
  return typescript.readConfigFile(path_1.default.resolve(filename), typescript.sys.readFile).config;
18
18
  };
@@ -41,7 +41,7 @@ exports.createRuntimeExportsUtils = memo((pwd = '', namespace, ts = false) => {
41
41
  compiled_1.fs.appendFileSync(entryExportTsFile, `${statement.replace('.js', '.d')}\n`);
42
42
  }
43
43
  }
44
- catch (_a) {
44
+ catch {
45
45
  // FIXME:
46
46
  }
47
47
  };
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,7 +11,7 @@
11
11
  "modern",
12
12
  "modern.js"
13
13
  ],
14
- "version": "1.6.0",
14
+ "version": "1.7.1-alpha.1",
15
15
  "jsnext:source": "./src/index.ts",
16
16
  "types": "./dist/index.d.ts",
17
17
  "main": "./dist/index.js",
@@ -19,30 +19,23 @@
19
19
  "jsnext:modern": "./dist/index.js",
20
20
  "_comment": "Provide ESM and CJS exports, ESM is used by runtime package, for treeshaking",
21
21
  "exports": {
22
- ".": {
23
- "jsnext:source": "./src/index.ts",
24
- "default": "./dist/index.js"
25
- },
26
- "./format": {
27
- "jsnext:source": "./src/format.ts",
28
- "default": "./dist/format.js"
29
- },
30
- "./constants": {
31
- "jsnext:source": "./src/constants.ts",
32
- "default": "./dist/constants.js"
33
- },
34
- "./ssr": {
35
- "jsnext:source": "./src/ssr.ts",
36
- "default": "./dist/ssr.js"
37
- },
38
- "./lodash": {
39
- "jsnext:source": "./compiled/lodash/index.js",
40
- "default": "./compiled/lodash/index.js"
41
- },
42
- "./strip-ansi": {
43
- "jsnext:source": "./compiled/strip-ansi/index.js",
44
- "default": "./compiled/strip-ansi/index.js"
45
- }
22
+ ".": "./dist/index.js",
23
+ "./format": "./dist/format.js",
24
+ "./constants": "./dist/constants.js",
25
+ "./ssr": "./dist/ssr.js",
26
+ "./chalk": "./compiled/chalk/index.js",
27
+ "./json5": "./compiled/json5/index.js",
28
+ "./semver": "./compiled/semver/index.js",
29
+ "./lodash": "./compiled/lodash/index.js",
30
+ "./globby": "./compiled/globby/index.js",
31
+ "./fast-glob": "./compiled/fast-glob/index.js",
32
+ "./gzip-size": "./compiled/gzip-size/index.js",
33
+ "./mime-types": "./compiled/mime-types/index.js",
34
+ "./strip-ansi": "./compiled/strip-ansi/index.js"
35
+ },
36
+ "publishConfig": {
37
+ "registry": "https://registry.npmjs.org/",
38
+ "access": "public"
46
39
  },
47
40
  "typesVersions": {
48
41
  "*": {
@@ -55,9 +48,30 @@
55
48
  "ssr": [
56
49
  "./dist/ssr.d.ts"
57
50
  ],
51
+ "chalk": [
52
+ "./compiled/chalk/index.d.ts"
53
+ ],
54
+ "json5": [
55
+ "./compiled/json5/index.d.ts"
56
+ ],
57
+ "semver": [
58
+ "./compiled/semver/index.d.ts"
59
+ ],
58
60
  "lodash": [
59
61
  "./compiled/lodash/index.d.ts"
60
62
  ],
63
+ "globby": [
64
+ "./compiled/globby/index.d.ts"
65
+ ],
66
+ "fast-glob": [
67
+ "./compiled/fast-glob/index.d.ts"
68
+ ],
69
+ "gzip-size": [
70
+ "./compiled/gzip-size/index.d.ts"
71
+ ],
72
+ "mime-types": [
73
+ "./compiled/mime-types/index.d.ts"
74
+ ],
61
75
  "strip-ansi": [
62
76
  "./compiled/strip-ansi/index.d.ts"
63
77
  ]
@@ -65,10 +79,11 @@
65
79
  },
66
80
  "dependencies": {
67
81
  "caniuse-lite": "^1.0.30001332",
82
+ "lodash": "^4.17.21",
68
83
  "typescript": "^4"
69
84
  },
70
85
  "devDependencies": {
71
- "@modern-js/types": "1.5.1",
86
+ "@modern-js/types": "1.5.2",
72
87
  "@scripts/build": "0.0.0",
73
88
  "@scripts/jest-config": "0.0.0",
74
89
  "@types/jest": "^26",
@@ -77,10 +92,6 @@
77
92
  "webpack": "^5.71.0"
78
93
  },
79
94
  "sideEffects": false,
80
- "publishConfig": {
81
- "registry": "https://registry.npmjs.org/",
82
- "access": "public"
83
- },
84
95
  "scripts": {
85
96
  "new": "modern new",
86
97
  "dev": "tsc --watch",
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,20 +0,0 @@
1
- import type * as fsStat from '../../../@nodelib/fs.stat';
2
- import type { Dirent, ErrnoException } from '../types';
3
- export interface ReaddirAsynchronousMethod {
4
- (filepath: string, options: {
5
- withFileTypes: true;
6
- }, callback: (error: ErrnoException | null, files: Dirent[]) => void): void;
7
- (filepath: string, callback: (error: ErrnoException | null, files: string[]) => void): void;
8
- }
9
- export interface ReaddirSynchronousMethod {
10
- (filepath: string, options: {
11
- withFileTypes: true;
12
- }): Dirent[];
13
- (filepath: string): string[];
14
- }
15
- export declare type FileSystemAdapter = fsStat.FileSystemAdapter & {
16
- readdir: ReaddirAsynchronousMethod;
17
- readdirSync: ReaddirSynchronousMethod;
18
- };
19
- export declare const FILE_SYSTEM_ADAPTER: FileSystemAdapter;
20
- export declare function createFileSystemAdapter(fsMethods?: Partial<FileSystemAdapter>): FileSystemAdapter;
@@ -1,12 +0,0 @@
1
- import type { FileSystemAdapter, ReaddirAsynchronousMethod, ReaddirSynchronousMethod } from './adapters/fs';
2
- import * as async from './providers/async';
3
- import Settings, { Options } from './settings';
4
- import type { Dirent, Entry } from './types';
5
- declare type AsyncCallback = async.AsyncCallback;
6
- declare function scandir(path: string, callback: AsyncCallback): void;
7
- declare function scandir(path: string, optionsOrSettings: Options | Settings, callback: AsyncCallback): void;
8
- declare namespace scandir {
9
- function __promisify__(path: string, optionsOrSettings?: Options | Settings): Promise<Entry[]>;
10
- }
11
- declare function scandirSync(path: string, optionsOrSettings?: Options | Settings): Entry[];
12
- export { scandir, scandirSync, Settings, AsyncCallback, Dirent, Entry, FileSystemAdapter, ReaddirAsynchronousMethod, ReaddirSynchronousMethod, Options };
@@ -1,7 +0,0 @@
1
- /// <reference types="node" />
2
- import type Settings from '../settings';
3
- import type { Entry } from '../types';
4
- export declare type AsyncCallback = (error: NodeJS.ErrnoException, entries: Entry[]) => void;
5
- export declare function read(directory: string, settings: Settings, callback: AsyncCallback): void;
6
- export declare function readdirWithFileTypes(directory: string, settings: Settings, callback: AsyncCallback): void;
7
- export declare function readdir(directory: string, settings: Settings, callback: AsyncCallback): void;