diff --git a/examples/basic-usage.js b/examples/basic-usage.js index 081396c..a2e4545 100644 --- a/examples/basic-usage.js +++ b/examples/basic-usage.js @@ -1,5 +1,5 @@ require('ts-node/register') -const cli = require('../src/index')() +const cli = require('../src/index').cac() cli.option('--type [type]', 'Choose a project type') diff --git a/examples/command-examples.js b/examples/command-examples.js index 5fa49f8..7c25f34 100644 --- a/examples/command-examples.js +++ b/examples/command-examples.js @@ -1,10 +1,10 @@ require('ts-node/register') -const cli = require('../src/index')() +const cli = require('../src/index').cac() cli .command('build', 'Build project') .example('cli build foo.js') - .example(name => { + .example((name) => { return `${name} build foo.js` }) .option('--type [type]', 'Choose a project type') diff --git a/examples/command-options.js b/examples/command-options.js index 0202e08..0b3606d 100644 --- a/examples/command-options.js +++ b/examples/command-options.js @@ -1,5 +1,5 @@ require('ts-node/register') -const cli = require('../src/index')() +const cli = require('../src/index').cac() cli .command('rm ', 'Remove a dir') diff --git a/examples/dot-nested-options.js b/examples/dot-nested-options.js index 9b8eedd..0bad819 100644 --- a/examples/dot-nested-options.js +++ b/examples/dot-nested-options.js @@ -1,12 +1,12 @@ require('ts-node/register') -const cli = require('../src/index')() +const cli = require('../src/index').cac() cli .command('build', 'desc') .option('--env ', 'Set envs') .option('--foo-bar ', 'Set foo bar') .example('--env.API_SECRET xxx') - .action(options => { + .action((options) => { console.log(options) }) diff --git a/examples/help.js b/examples/help.js index e5ad7fb..a948dfb 100644 --- a/examples/help.js +++ b/examples/help.js @@ -1,5 +1,5 @@ require('ts-node/register') -const cli = require('../src/index')() +const cli = require('../src/index').cac() cli.option('--type [type]', 'Choose a project type', { default: 'node', diff --git a/examples/ignore-default-value.js b/examples/ignore-default-value.js index 96daa0b..9286379 100644 --- a/examples/ignore-default-value.js +++ b/examples/ignore-default-value.js @@ -1,12 +1,12 @@ require('ts-node/register') -const cli = require('../src/index')() +const cli = require('../src/index').cac() cli .command('build', 'Build project', { - ignoreOptionDefaultValue: true + ignoreOptionDefaultValue: true, }) .option('--type [type]', 'Choose a project type', { - default: 'node' + default: 'node', }) const parsed = cli.parse() diff --git a/examples/negated-option.js b/examples/negated-option.js index cb4b485..da726c7 100644 --- a/examples/negated-option.js +++ b/examples/negated-option.js @@ -1,5 +1,5 @@ require('ts-node/register') -const cli = require('../src/index')() +const cli = require('../src/index').cac() cli.option('--no-clear-screen', 'Do not clear screen') diff --git a/examples/sub-command.js b/examples/sub-command.js index 4e9e9a6..32a4715 100644 --- a/examples/sub-command.js +++ b/examples/sub-command.js @@ -1,5 +1,5 @@ require('ts-node/register') -const cli = require('../src/index')() +const cli = require('../src/index').cac() cli .command('deploy [path]', 'Deploy to AWS') diff --git a/examples/variadic-arguments.js b/examples/variadic-arguments.js index 155db1b..0fa5b83 100644 --- a/examples/variadic-arguments.js +++ b/examples/variadic-arguments.js @@ -1,5 +1,5 @@ require('ts-node/register') -const cli = require('../src/index')() +const cli = require('../src/index').cac() cli .command('build [...otherFiles]', 'Build your app') diff --git a/index-compat.js b/index-compat.js new file mode 100644 index 0000000..6b8a78d --- /dev/null +++ b/index-compat.js @@ -0,0 +1,11 @@ +const { cac, CAC, Command } = require('./dist/index') + +// For backwards compatibility +module.exports = cac + +Object.assign(module.exports, { + default: cac, + cac, + CAC, + Command, +}) diff --git a/package.json b/package.json index 3a4751b..f0a6498 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "url": "egoist/cac", "type": "git" }, - "main": "dist/index.js", + "main": "index-compat.js", "module": "dist/index.mjs", "types": "dist/index.d.ts", "exports": { @@ -22,7 +22,8 @@ "!**/__test__/**", "/mod.js", "/mod.ts", - "/deno" + "/deno", + "/index-compat.js" ], "scripts": { "test": "jest", diff --git a/scripts/build-deno.ts b/scripts/build-deno.ts index bd98d5f..6bd8928 100644 --- a/scripts/build-deno.ts +++ b/scripts/build-deno.ts @@ -23,12 +23,6 @@ function node2deno(options: { types: typeof Types }): PluginObj { source.value = `https://cdn.skypack.dev/mri` } }, - - IfStatement(path) { - if (path.getSource().includes('@remove-for-deno')) { - path.remove() - } - }, }, } } diff --git a/src/__test__/index.test.ts b/src/__test__/index.test.ts index 34f79ed..6cb8406 100644 --- a/src/__test__/index.test.ts +++ b/src/__test__/index.test.ts @@ -2,6 +2,8 @@ import path from 'path' import execa from 'execa' import cac from '..' +jest.setTimeout(30000) + function example(file: string) { return path.relative( process.cwd(), diff --git a/src/index.ts b/src/index.ts index 3842352..a45a0f4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -8,14 +8,3 @@ const cac = (name = '') => new CAC(name) export default cac export { cac, CAC, Command } - -if (typeof module !== 'undefined') { - // @remove-for-deno - module.exports = cac - Object.assign(module.exports, { - default: cac, - cac, - CAC, - Command, - }) -}