| 1 | 'use strict'
|
|---|
| 2 |
|
|---|
| 3 | import { notStrictEqual, strictEqual } from 'assert'
|
|---|
| 4 | import cliui from 'cliui'
|
|---|
| 5 | import escalade from 'escalade/sync'
|
|---|
| 6 | import { format, 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 | execPath: () => process.execPath,
|
|---|
| 49 | exit: process.exit,
|
|---|
| 50 | nextTick: process.nextTick,
|
|---|
| 51 | stdColumns: typeof process.stdout.columns !== 'undefined' ? process.stdout.columns : null
|
|---|
| 52 | },
|
|---|
| 53 | readFileSync,
|
|---|
| 54 | require: () => {
|
|---|
| 55 | throw new YError(REQUIRE_ERROR)
|
|---|
| 56 | },
|
|---|
| 57 | requireDirectory: () => {
|
|---|
| 58 | throw new YError(REQUIRE_DIRECTORY_ERROR)
|
|---|
| 59 | },
|
|---|
| 60 | stringWidth: (str) => {
|
|---|
| 61 | return [...str].length
|
|---|
| 62 | },
|
|---|
| 63 | y18n: y18n({
|
|---|
| 64 | directory: resolve(__dirname, '../../../locales'),
|
|---|
| 65 | updateFiles: false
|
|---|
| 66 | })
|
|---|
| 67 | }
|
|---|