@modern-js/utils 1.1.6 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +23 -0
- package/dist/js/modern/constants.js +2 -1
- package/dist/js/modern/getBrowserslist.js +1 -1
- package/dist/js/modern/prettyInstructions.js +1 -1
- package/dist/js/node/constants.js +2 -1
- package/dist/js/node/getBrowserslist.js +2 -2
- package/dist/js/node/prettyInstructions.js +1 -1
- package/dist/js/treeshaking/constants.js +2 -1
- package/dist/js/treeshaking/getBrowserslist.js +1 -1
- package/dist/js/treeshaking/prettyInstructions.js +1 -1
- package/dist/types/getBrowserslist.d.ts +1 -1
- package/jest.config.js +8 -0
- package/package.json +18 -12
- package/tests/applyOptionsChain.test.ts +1 -1
- package/tests/compatRequire.test.ts +1 -1
- package/tests/debug.test.ts +4 -2
- package/tests/ensureAbsolutePath.test.ts +1 -1
- package/tests/findExists.test.ts +1 -1
- package/tests/getBrowserslist.test.ts +1 -1
- package/tests/getCacheIdentifier.test.ts +1 -1
- package/tests/getEntryOptions.test.ts +1 -1
- package/tests/index.test.ts +1 -1
- package/tests/logger.test.ts +1 -1
- package/tests/removeSlash.test.ts +1 -1
- package/tests/tsconfig.json +1 -3
- package/tsconfig.json +1 -3
- package/src/FileSizeReporter.ts +0 -181
- package/src/alias.ts +0 -90
- package/src/applyOptionsChain.ts +0 -44
- package/src/chalk.ts +0 -3
- package/src/clearConsole.ts +0 -5
- package/src/compatRequire.ts +0 -25
- package/src/constants.ts +0 -262
- package/src/debug.ts +0 -8
- package/src/ensureAbsolutePath.ts +0 -10
- package/src/findExists.ts +0 -15
- package/src/formatWebpackMessages.ts +0 -131
- package/src/generateMetaTags.ts +0 -75
- package/src/getBrowserslist.ts +0 -6
- package/src/getCacheIdentifier.ts +0 -30
- package/src/getEntryOptions.ts +0 -37
- package/src/getPackageManager.ts +0 -30
- package/src/getPort.ts +0 -62
- package/src/import.ts +0 -10
- package/src/index.ts +0 -31
- package/src/is/index.ts +0 -78
- package/src/is/node-env.ts +0 -9
- package/src/is/platform.ts +0 -7
- package/src/is/type.ts +0 -43
- package/src/logger.ts +0 -184
- package/src/monorepo.ts +0 -106
- package/src/nodeEnv.ts +0 -28
- package/src/path.ts +0 -9
- package/src/pkgUp.ts +0 -3
- package/src/prettyInstructions.ts +0 -88
- package/src/printBuildError.ts +0 -47
- package/src/readTsConfig.ts +0 -21
- package/src/removeSlash.ts +0 -6
- package/src/runtimeExports.ts +0 -68
- package/src/types.d.ts +0 -1
- package/src/watch.ts +0 -56
package/src/printBuildError.ts
DELETED
@@ -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 */
|
package/src/readTsConfig.ts
DELETED
@@ -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
|
-
};
|
package/src/removeSlash.ts
DELETED
package/src/runtimeExports.ts
DELETED
@@ -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
|
-
};
|