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