Skip to content

Commit 46b2114

Browse files
committedOct 12, 2021
fix: remove module.exports statement from esm build
1 parent 0815980 commit 46b2114

14 files changed

+29
-32
lines changed
 

‎examples/basic-usage.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require('ts-node/register')
2-
const cli = require('../src/index')()
2+
const cli = require('../src/index').cac()
33

44
cli.option('--type [type]', 'Choose a project type')
55

‎examples/command-examples.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
require('ts-node/register')
2-
const cli = require('../src/index')()
2+
const cli = require('../src/index').cac()
33

44
cli
55
.command('build', 'Build project')
66
.example('cli build foo.js')
7-
.example(name => {
7+
.example((name) => {
88
return `${name} build foo.js`
99
})
1010
.option('--type [type]', 'Choose a project type')

‎examples/command-options.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require('ts-node/register')
2-
const cli = require('../src/index')()
2+
const cli = require('../src/index').cac()
33

44
cli
55
.command('rm <dir>', 'Remove a dir')

‎examples/dot-nested-options.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
require('ts-node/register')
2-
const cli = require('../src/index')()
2+
const cli = require('../src/index').cac()
33

44
cli
55
.command('build', 'desc')
66
.option('--env <env>', 'Set envs')
77
.option('--foo-bar <value>', 'Set foo bar')
88
.example('--env.API_SECRET xxx')
9-
.action(options => {
9+
.action((options) => {
1010
console.log(options)
1111
})
1212

‎examples/help.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require('ts-node/register')
2-
const cli = require('../src/index')()
2+
const cli = require('../src/index').cac()
33

44
cli.option('--type [type]', 'Choose a project type', {
55
default: 'node',

‎examples/ignore-default-value.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
require('ts-node/register')
2-
const cli = require('../src/index')()
2+
const cli = require('../src/index').cac()
33

44
cli
55
.command('build', 'Build project', {
6-
ignoreOptionDefaultValue: true
6+
ignoreOptionDefaultValue: true,
77
})
88
.option('--type [type]', 'Choose a project type', {
9-
default: 'node'
9+
default: 'node',
1010
})
1111

1212
const parsed = cli.parse()

‎examples/negated-option.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require('ts-node/register')
2-
const cli = require('../src/index')()
2+
const cli = require('../src/index').cac()
33

44
cli.option('--no-clear-screen', 'Do not clear screen')
55

‎examples/sub-command.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require('ts-node/register')
2-
const cli = require('../src/index')()
2+
const cli = require('../src/index').cac()
33

44
cli
55
.command('deploy [path]', 'Deploy to AWS')

‎examples/variadic-arguments.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
require('ts-node/register')
2-
const cli = require('../src/index')()
2+
const cli = require('../src/index').cac()
33

44
cli
55
.command('build <entry> [...otherFiles]', 'Build your app')

‎index-compat.js

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const { cac, CAC, Command } = require('./dist/index')
2+
3+
// For backwards compatibility
4+
module.exports = cac
5+
6+
Object.assign(module.exports, {
7+
default: cac,
8+
cac,
9+
CAC,
10+
Command,
11+
})

‎package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"url": "egoist/cac",
77
"type": "git"
88
},
9-
"main": "dist/index.js",
9+
"main": "index-compat.js",
1010
"module": "dist/index.mjs",
1111
"types": "dist/index.d.ts",
1212
"exports": {
@@ -22,7 +22,8 @@
2222
"!**/__test__/**",
2323
"/mod.js",
2424
"/mod.ts",
25-
"/deno"
25+
"/deno",
26+
"/index-compat.js"
2627
],
2728
"scripts": {
2829
"test": "jest",

‎scripts/build-deno.ts

-6
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ function node2deno(options: { types: typeof Types }): PluginObj {
2323
source.value = `https://cdn.skypack.dev/mri`
2424
}
2525
},
26-
27-
IfStatement(path) {
28-
if (path.getSource().includes('@remove-for-deno')) {
29-
path.remove()
30-
}
31-
},
3226
},
3327
}
3428
}

‎src/__test__/index.test.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import path from 'path'
22
import execa from 'execa'
33
import cac from '..'
44

5+
jest.setTimeout(30000)
6+
57
function example(file: string) {
68
return path.relative(
79
process.cwd(),

‎src/index.ts

-11
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,3 @@ const cac = (name = '') => new CAC(name)
88

99
export default cac
1010
export { cac, CAC, Command }
11-
12-
if (typeof module !== 'undefined') {
13-
// @remove-for-deno
14-
module.exports = cac
15-
Object.assign(module.exports, {
16-
default: cac,
17-
cac,
18-
CAC,
19-
Command,
20-
})
21-
}

0 commit comments

Comments
 (0)
Please sign in to comment.