esm.mjs
1.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
'use strict'
import { notStrictEqual, strictEqual } from 'assert'
import cliui from 'cliui'
import escalade from 'escalade/sync'
import { format, inspect } from 'util'
import { readFileSync } from 'fs'
import { fileURLToPath } from 'url';
import Parser from 'yargs-parser'
import { basename, dirname, extname, relative, resolve } from 'path'
import { getProcessArgvBin } from '../../build/lib/utils/process-argv.js'
import { YError } from '../../build/lib/yerror.js'
import y18n from 'y18n'
const REQUIRE_ERROR = 'require is not supported by ESM'
const REQUIRE_DIRECTORY_ERROR = 'loading a directory of commands is not supported yet for ESM'
const mainFilename = fileURLToPath(import.meta.url).split('node_modules')[0]
const __dirname = fileURLToPath(import.meta.url)
export default {
assert: {
notStrictEqual,
strictEqual
},
cliui,
findUp: escalade,
getEnv: (key) => {
return process.env[key]
},
inspect,
getCallerFile: () => {
throw new YError(REQUIRE_DIRECTORY_ERROR)
},
getProcessArgvBin,
mainFilename: mainFilename || process.cwd(),
Parser,
path: {
basename,
dirname,
extname,
relative,
resolve
},
process: {
argv: () => process.argv,
cwd: process.cwd,
execPath: () => process.execPath,
exit: process.exit,
nextTick: process.nextTick,
stdColumns: typeof process.stdout.columns !== 'undefined' ? process.stdout.columns : null
},
readFileSync,
require: () => {
throw new YError(REQUIRE_ERROR)
},
requireDirectory: () => {
throw new YError(REQUIRE_DIRECTORY_ERROR)
},
stringWidth: (str) => {
return [...str].length
},
y18n: y18n({
directory: resolve(__dirname, '../../../locales'),
updateFiles: false
})
}