@modern-js/utils 1.2.0 → 1.3.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +36 -0
- package/dist/js/modern/clearConsole.js +1 -1
- package/dist/js/modern/compatRequire.js +5 -0
- package/dist/js/modern/constants.js +4 -18
- package/dist/js/modern/index.js +2 -1
- package/dist/js/modern/prettyInstructions.js +15 -5
- package/dist/js/modern/wait.js +5 -0
- package/dist/js/node/clearConsole.js +1 -1
- package/dist/js/node/compatRequire.js +10 -2
- package/dist/js/node/constants.js +6 -23
- package/dist/js/node/index.js +14 -0
- package/dist/js/node/prettyInstructions.js +15 -5
- package/dist/js/node/wait.js +12 -0
- package/dist/js/treeshaking/clearConsole.js +1 -1
- package/dist/js/treeshaking/compatRequire.js +5 -0
- package/dist/js/treeshaking/constants.js +4 -18
- package/dist/js/treeshaking/index.js +2 -1
- package/dist/js/treeshaking/prettyInstructions.js +17 -6
- package/dist/js/treeshaking/wait.js +8 -0
- package/dist/types/compatRequire.d.ts +2 -1
- package/dist/types/constants.d.ts +1 -16
- package/dist/types/index.d.ts +2 -1
- package/dist/types/wait.d.ts +2 -0
- package/package.json +2 -3
- package/tests/__snapshots__/prettyInstructions.test.ts.snap +19 -0
- package/tests/compatRequire.test.ts +11 -1
- package/tests/fixtures/compat-require/foo.js +3 -0
- package/tests/prettyInstructions.test.ts +139 -0
- package/tests/wait.ts +38 -0
- 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/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
|
-
};
|