-
Notifications
You must be signed in to change notification settings - Fork 995
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: adds support for ESM and Deno #1708
Merged
Changes from 3 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
f49a5eb
feat!: adds support for ESM and Deno
bcoe 38d2c60
chore: put more work into migration to ESM
bcoe 497bb5d
chore: fix up test command
bcoe 5d2dccb
chore: retire require-main-filename
bcoe 9a77160
chore: minify output code
bcoe d5eab8a
chore: use the latest build of yargs-parser
bcoe 58aac01
chore: walk back decision to minify; pull in cliui
bcoe 9449229
chore: finish isolating APIs that don't work in Deno or browser
bcoe 45c7fe1
chore: continue to abstract Node specific logic
bcoe 6fd8c01
chore: standardize platform shim logic
bcoe 17f4474
chore: reduce package size
bcoe 013b7fc
chore: starting to add some tests for other platforms
bcoe 73a3d72
chore: don't try to compile deno files
bcoe 59e0bd8
chore: pulled in ESMified cliui
bcoe baf5263
test: continuing to build out tests for ESM
bcoe 49a9e14
chore: test whether browser works
bcoe c2fda8a
chore: include browser shim
bcoe 2b00525
chore: include new entrypoints in package
bcoe 58846b2
chore: fix import
bcoe b4e8d2b
chore: slight tweak to example
bcoe 845c68a
chore: implement minimal sprintf for browser
bcoe 803a7d8
feat: expose helper for process args
bcoe 7d80f03
docs: document new functionality
bcoe be3f192
docs: copy edits
bcoe File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
'use strict' | ||
|
||
// Bootstraps yargs in ESM mode: | ||
import escalade from 'escalade/sync' | ||
import { fileURLToPath } from 'url'; | ||
import Parser from 'yargs-parser' | ||
import { dirname, resolve } from 'path' | ||
import { YargsFactory } from './build/lib/yargs-factory.js' | ||
|
||
// TODO: stop using createRequire as soon as we've ported: cliui, y18n, etc. | ||
import { createRequire } from 'module'; | ||
const require = createRequire(import.meta.url); | ||
|
||
const __dirname = dirname(fileURLToPath(import.meta.url)); | ||
|
||
const Yargs = YargsFactory({ | ||
findUp: escalade, | ||
Parser, | ||
require, | ||
requireDirectory: require('require-directory'), | ||
stringWidth: require('string-width'), | ||
y18n: require('y18n')({ | ||
directory: resolve(__dirname, '../locales'), | ||
updateFiles: false | ||
}) | ||
}) | ||
|
||
export default Yargs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
'use strict' | ||
// This file is used to bootstrap yargs for its legacy CommonJS interface: | ||
|
||
import { argsert } from './argsert.js' | ||
import { isPromise } from './utils/is-promise.js' | ||
import { objFilter } from './utils/obj-filter.js' | ||
import { globalMiddlewareFactory } from './middleware.js' | ||
import { parseCommand } from './parse-command.js' | ||
import * as processArgv from './utils/process-argv.js' | ||
import { YargsFactory, rebase } from './yargs-factory.js' | ||
import { YError } from './yerror.js' | ||
|
||
// See https://github.com/yargs/yargs#supported-nodejs-versions for our | ||
// version support policy. The YARGS_MIN_NODE_VERSION is used for testing only. | ||
const minNodeVersion = (process && process.env && process.env.YARGS_MIN_NODE_VERSION) | ||
? Number(process.env.YARGS_MIN_NODE_VERSION) : 10 | ||
if (process && process.version) { | ||
const major = Number(process.version.match(/v([^.]+)/)![1]) | ||
if (major < minNodeVersion) { | ||
throw Error(`yargs supports a minimum Node.js version of ${minNodeVersion}. Read our version support policy: https://github.com/yargs/yargs#supported-nodejs-versions`) | ||
} | ||
} | ||
|
||
// Inject CommonJS dependencies: | ||
const Parser = require('yargs-parser') | ||
const { resolve } = require('path') | ||
const y18n = require('y18n') | ||
const Yargs = YargsFactory({ | ||
findUp: require('escalade/sync'), | ||
Parser, | ||
require: (require as any), | ||
requireDirectory: require('require-directory'), | ||
stringWidth: require('string-width'), | ||
y18n: y18n({ | ||
directory: resolve(__dirname, '../locales'), | ||
updateFiles: false | ||
}) | ||
}) | ||
|
||
export default Object.assign(Yargs, { | ||
argsert, | ||
globalMiddlewareFactory, | ||
isPromise, | ||
objFilter, | ||
parseCommand, | ||
Parser, | ||
processArgv, | ||
rebase, | ||
YError | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@QmarkC if once we port
y18n
andcliui
we'll be getting darn close to an ESM version of yargs.Note that
createRequire
is Node.js specific, so won't port well to other runtimes.