Geen omschrijving
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

esm.mjs 1.7KB

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