Skip to content

Commit

Permalink
fix: remove module.exports statement from esm build
Browse files Browse the repository at this point in the history
  • Loading branch information
egoist committed Oct 12, 2021
1 parent 0815980 commit 46b2114
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 32 deletions.
2 changes: 1 addition & 1 deletion examples/basic-usage.js
Original file line number Diff line number Diff line change
@@ -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')

Expand Down
4 changes: 2 additions & 2 deletions examples/command-examples.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
2 changes: 1 addition & 1 deletion examples/command-options.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require('ts-node/register')
const cli = require('../src/index')()
const cli = require('../src/index').cac()

cli
.command('rm <dir>', 'Remove a dir')
Expand Down
4 changes: 2 additions & 2 deletions examples/dot-nested-options.js
Original file line number Diff line number Diff line change
@@ -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 <env>', 'Set envs')
.option('--foo-bar <value>', 'Set foo bar')
.example('--env.API_SECRET xxx')
.action(options => {
.action((options) => {
console.log(options)
})

Expand Down
2 changes: 1 addition & 1 deletion examples/help.js
Original file line number Diff line number Diff line change
@@ -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',
Expand Down
6 changes: 3 additions & 3 deletions examples/ignore-default-value.js
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
2 changes: 1 addition & 1 deletion examples/negated-option.js
Original file line number Diff line number Diff line change
@@ -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')

Expand Down
2 changes: 1 addition & 1 deletion examples/sub-command.js
Original file line number Diff line number Diff line change
@@ -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')
Expand Down
2 changes: 1 addition & 1 deletion examples/variadic-arguments.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require('ts-node/register')
const cli = require('../src/index')()
const cli = require('../src/index').cac()

cli
.command('build <entry> [...otherFiles]', 'Build your app')
Expand Down
11 changes: 11 additions & 0 deletions index-compat.js
Original file line number Diff line number Diff line change
@@ -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,
})
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand All @@ -22,7 +22,8 @@
"!**/__test__/**",
"/mod.js",
"/mod.ts",
"/deno"
"/deno",
"/index-compat.js"
],
"scripts": {
"test": "jest",
Expand Down
6 changes: 0 additions & 6 deletions scripts/build-deno.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
},
},
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/__test__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
11 changes: 0 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}

0 comments on commit 46b2114

Please sign in to comment.