@modern-js/utils 1.1.6 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/dist/js/modern/constants.js +2 -1
  3. package/dist/js/modern/getBrowserslist.js +1 -1
  4. package/dist/js/modern/prettyInstructions.js +1 -1
  5. package/dist/js/node/constants.js +2 -1
  6. package/dist/js/node/getBrowserslist.js +2 -2
  7. package/dist/js/node/prettyInstructions.js +1 -1
  8. package/dist/js/treeshaking/constants.js +2 -1
  9. package/dist/js/treeshaking/getBrowserslist.js +1 -1
  10. package/dist/js/treeshaking/prettyInstructions.js +1 -1
  11. package/dist/types/getBrowserslist.d.ts +1 -1
  12. package/jest.config.js +8 -0
  13. package/package.json +18 -12
  14. package/tests/applyOptionsChain.test.ts +1 -1
  15. package/tests/compatRequire.test.ts +1 -1
  16. package/tests/debug.test.ts +4 -2
  17. package/tests/ensureAbsolutePath.test.ts +1 -1
  18. package/tests/findExists.test.ts +1 -1
  19. package/tests/getBrowserslist.test.ts +1 -1
  20. package/tests/getCacheIdentifier.test.ts +1 -1
  21. package/tests/getEntryOptions.test.ts +1 -1
  22. package/tests/index.test.ts +1 -1
  23. package/tests/logger.test.ts +1 -1
  24. package/tests/removeSlash.test.ts +1 -1
  25. package/tests/tsconfig.json +1 -3
  26. package/tsconfig.json +1 -3
  27. package/src/FileSizeReporter.ts +0 -181
  28. package/src/alias.ts +0 -90
  29. package/src/applyOptionsChain.ts +0 -44
  30. package/src/chalk.ts +0 -3
  31. package/src/clearConsole.ts +0 -5
  32. package/src/compatRequire.ts +0 -25
  33. package/src/constants.ts +0 -262
  34. package/src/debug.ts +0 -8
  35. package/src/ensureAbsolutePath.ts +0 -10
  36. package/src/findExists.ts +0 -15
  37. package/src/formatWebpackMessages.ts +0 -131
  38. package/src/generateMetaTags.ts +0 -75
  39. package/src/getBrowserslist.ts +0 -6
  40. package/src/getCacheIdentifier.ts +0 -30
  41. package/src/getEntryOptions.ts +0 -37
  42. package/src/getPackageManager.ts +0 -30
  43. package/src/getPort.ts +0 -62
  44. package/src/import.ts +0 -10
  45. package/src/index.ts +0 -31
  46. package/src/is/index.ts +0 -78
  47. package/src/is/node-env.ts +0 -9
  48. package/src/is/platform.ts +0 -7
  49. package/src/is/type.ts +0 -43
  50. package/src/logger.ts +0 -184
  51. package/src/monorepo.ts +0 -106
  52. package/src/nodeEnv.ts +0 -28
  53. package/src/path.ts +0 -9
  54. package/src/pkgUp.ts +0 -3
  55. package/src/prettyInstructions.ts +0 -88
  56. package/src/printBuildError.ts +0 -47
  57. package/src/readTsConfig.ts +0 -21
  58. package/src/removeSlash.ts +0 -6
  59. package/src/runtimeExports.ts +0 -68
  60. package/src/types.d.ts +0 -1
  61. package/src/watch.ts +0 -56
@@ -1,47 +0,0 @@
1
- /* eslint-disable eslint-comments/no-unlimited-disable */
2
- /* eslint-disable */
3
- /**
4
- * Copyright (c) 2015-present, Facebook, Inc.
5
- *
6
- * This source code is licensed under the MIT license found in the
7
- * LICENSE file at
8
- * https://github.com/facebook/create-react-app/blob/master/LICENSE
9
- */
10
-
11
- // Modified by Chao Xu (xuchaobei)
12
-
13
- import chalk from 'chalk';
14
- import { logger } from './logger';
15
-
16
- export function printBuildError(err: Error) {
17
- const message = err != null && err.message;
18
- const stack = err != null && err.stack;
19
-
20
- // Add more helpful message for Terser error
21
- if (
22
- stack &&
23
- typeof message === 'string' &&
24
- message.indexOf('from Terser') !== -1
25
- ) {
26
- try {
27
- const matched = /(.+)\[(.+):(.+),(.+)\]\[.+\]/.exec(stack);
28
- if (!matched) {
29
- throw new Error('Using errors for control flow is bad.');
30
- }
31
- const problemPath = matched[2];
32
- const line = matched[3];
33
- const column = matched[4];
34
- logger.error(
35
- `Failed to minify the code from this file: \n\n ${chalk.yellow(
36
- `\t${problemPath}:${line}${column !== '0' ? ':' + column : ''}`
37
- )}\n`
38
- );
39
- } catch (ignored) {
40
- logger.error(`Failed to minify the bundle. ${err}\n`);
41
- }
42
- } else {
43
- logger.error((message || err) + '\n');
44
- }
45
- logger.log();
46
- };
47
- /* eslint-enable */
@@ -1,21 +0,0 @@
1
- import path from 'path';
2
-
3
- export const readTsConfig = (root: string) => {
4
- // import typescript from 'typescript' cause eslint fromat error.
5
- const typescript = require('typescript');
6
-
7
- return typescript.readConfigFile(
8
- path.resolve(root, './tsconfig.json'),
9
- typescript.sys.readFile,
10
- ).config;
11
- };
12
-
13
- export const readTsConfigByFile = (filename: string) => {
14
- // import typescript from 'typescript' cause eslint fromat error.
15
- const typescript = require('typescript');
16
-
17
- return typescript.readConfigFile(
18
- path.resolve(filename),
19
- typescript.sys.readFile,
20
- ).config;
21
- };
@@ -1,6 +0,0 @@
1
- export const removeLeadingSlash = (s: string): string => s.replace(/^\/+/, '');
2
-
3
- export const removeTailSlash = (s: string): string => s.replace(/\/+$/, '');
4
-
5
- export const removeSlash = (s: string): string =>
6
- removeLeadingSlash(removeTailSlash(s));
@@ -1,68 +0,0 @@
1
- import path from 'path';
2
- import fs from 'fs-extra';
3
- import { normalizeOutputPath } from './path';
4
-
5
- const memo = <T extends (...args: any[]) => any>(fn: T) => {
6
- const cache = new Map();
7
-
8
- return (...params: Parameters<T>): ReturnType<T> => {
9
- const stringifiedParams = JSON.stringify(params);
10
- const cachedResult = cache.get(stringifiedParams);
11
-
12
- if (cachedResult) {
13
- return cachedResult;
14
- }
15
-
16
- const res = fn(...params);
17
- cache.set(stringifiedParams, res);
18
-
19
- return res;
20
- };
21
- };
22
-
23
- export const createRuntimeExportsUtils = memo(
24
- (pwd = '', namespace: string, ts = false) => {
25
- const entryExportFile = path.join(
26
- pwd,
27
- `.runtime-exports/${namespace ? `${namespace}.js` : 'index.js'}`,
28
- );
29
- const entryExportTsFile = path.join(
30
- pwd,
31
- `.runtime-exports/${namespace ? `${namespace}.d.ts` : 'index.d.ts'}`,
32
- );
33
-
34
- // const ensure = () => {
35
- // if (!fs.existsSync(entryExportFile)) {
36
- // fs.outputFileSync(entryExportFile, '');
37
- // }
38
- // fs.ensureFileSync(entryExportFile);
39
- // };
40
-
41
- const addExport = (statement: string) => {
42
- // eslint-disable-next-line no-param-reassign
43
- statement = normalizeOutputPath(statement);
44
- try {
45
- fs.ensureFileSync(entryExportFile);
46
- fs.ensureFileSync(entryExportTsFile);
47
-
48
- if (!fs.readFileSync(entryExportFile, 'utf8').includes(statement)) {
49
- fs.appendFileSync(entryExportFile, `${statement}\n`);
50
- ts &&
51
- fs.appendFileSync(
52
- entryExportTsFile,
53
- `${statement.replace('.js', '.d')}\n`,
54
- );
55
- }
56
- } catch {
57
- // FIXME:
58
- }
59
- };
60
-
61
- const getPath = () => entryExportFile;
62
-
63
- return {
64
- addExport,
65
- getPath,
66
- };
67
- },
68
- );
package/src/types.d.ts DELETED
@@ -1 +0,0 @@
1
- declare module 'browserslist/node';
package/src/watch.ts DELETED
@@ -1,56 +0,0 @@
1
- import * as path from 'path';
2
- import { Import } from './import';
3
-
4
- const chokidar: typeof import('chokidar') = Import.lazy('chokidar', require);
5
-
6
- export type WatchChangeTypeValueT = 'add' | 'unlink' | 'change';
7
-
8
- export const WatchChangeType: Record<
9
- 'ADD' | 'UNLINK' | 'CHANGE',
10
- WatchChangeTypeValueT
11
- > = {
12
- ADD: 'add',
13
- UNLINK: 'unlink',
14
- CHANGE: 'change',
15
- };
16
-
17
- type RunTaskType = (option: {
18
- changedFilePath: string;
19
- changeType: WatchChangeTypeValueT;
20
- }) => void | Promise<void>;
21
-
22
- export const watch = (
23
- watchDir: string | string[],
24
- runTask: RunTaskType,
25
- ignored: string[] = [],
26
- ) => {
27
- let ready = false;
28
- const watcher = chokidar.watch(watchDir, {
29
- ignored,
30
- });
31
-
32
- watcher.on('ready', () => (ready = true));
33
-
34
- watcher.on('change', async filePath => {
35
- const changedFilePath = path.resolve(filePath);
36
- await runTask({ changedFilePath, changeType: WatchChangeType.CHANGE });
37
- });
38
-
39
- watcher.on('add', async filePath => {
40
- const changedFilePath = path.resolve(filePath);
41
- if (ready) {
42
- await runTask({ changedFilePath, changeType: WatchChangeType.ADD });
43
- }
44
- });
45
-
46
- watcher.on('unlink', async filePath => {
47
- const changedFilePath = path.resolve(filePath);
48
- await runTask({ changedFilePath, changeType: WatchChangeType.UNLINK });
49
- });
50
-
51
- watcher.on('error', err => {
52
- throw err;
53
- });
54
-
55
- return watcher;
56
- };