Skip to content

Commit

Permalink
Attempt to fix handlebars-lang#1673
Browse files Browse the repository at this point in the history
- added a test to demonstrate the regression
- use duplicate-arguments-array, which correctly handles --amd --no-amd
- unfortunately this breaks all other valid multi-keys like -k for known helpers :(
  • Loading branch information
ErisDS committed Apr 3, 2020
1 parent 3438891 commit 65d308d
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 138 deletions.
3 changes: 3 additions & 0 deletions bin/handlebars
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#!/usr/bin/env node

const yargs = require('yargs')
.parserConfiguration({
'duplicate-arguments-array': false
})
.usage('Precompile handlebar templates.\nUsage: $0 [template|directory]...')
.option('f', {
type: 'string',
Expand Down
287 changes: 149 additions & 138 deletions tasks/test-bin.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,52 @@ chai.use(require('chai-diff'));
const expect = chai.expect;

const testCases = [
{
binInputParameters: ['-a', 'spec/artifacts/empty.handlebars'],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/empty.amd.js'
},
{
binInputParameters: [
'-a',
'-f',
'TEST_OUTPUT',
'spec/artifacts/empty.handlebars'
],
outputLocation: 'TEST_OUTPUT',
expectedOutputSpec: './spec/expected/empty.amd.js'
},
{
binInputParameters: [
'-a',
'-n',
'CustomNamespace.templates',
'spec/artifacts/empty.handlebars'
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/empty.amd.namespace.js'
},
{
binInputParameters: [
'-a',
'--namespace',
'CustomNamespace.templates',
'spec/artifacts/empty.handlebars'
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/empty.amd.namespace.js'
},
{
binInputParameters: ['-a', '-s', 'spec/artifacts/empty.handlebars'],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/empty.amd.simple.js'
},
{
binInputParameters: ['-a', '-m', 'spec/artifacts/empty.handlebars'],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/empty.amd.min.js'
},
// {
// binInputParameters: ['-a', 'spec/artifacts/empty.handlebars'],
// outputLocation: 'stdout',
// expectedOutputSpec: './spec/expected/empty.amd.js'
// },
// {
// binInputParameters: [
// '-a',
// '-f',
// 'TEST_OUTPUT',
// 'spec/artifacts/empty.handlebars'
// ],
// outputLocation: 'TEST_OUTPUT',
// expectedOutputSpec: './spec/expected/empty.amd.js'
// },
// {
// binInputParameters: [
// '-a',
// '-n',
// 'CustomNamespace.templates',
// 'spec/artifacts/empty.handlebars'
// ],
// outputLocation: 'stdout',
// expectedOutputSpec: './spec/expected/empty.amd.namespace.js'
// },
// {
// binInputParameters: [
// '-a',
// '--namespace',
// 'CustomNamespace.templates',
// 'spec/artifacts/empty.handlebars'
// ],
// outputLocation: 'stdout',
// expectedOutputSpec: './spec/expected/empty.amd.namespace.js'
// },
// {
// binInputParameters: ['-a', '-s', 'spec/artifacts/empty.handlebars'],
// outputLocation: 'stdout',
// expectedOutputSpec: './spec/expected/empty.amd.simple.js'
// },
// {
// binInputParameters: ['-a', '-m', 'spec/artifacts/empty.handlebars'],
// outputLocation: 'stdout',
// expectedOutputSpec: './spec/expected/empty.amd.min.js'
// },
// This test now breaks...
{
binInputParameters: [
'spec/artifacts/known.helpers.handlebars',
Expand All @@ -66,104 +67,114 @@ const testCases = [
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/non.empty.amd.known.helper.js'
},
{
binInputParameters: ['--help'],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/help.menu.txt'
},
{
binInputParameters: ['-v'],
outputLocation: 'stdout',
expectedOutput: require('../package.json').version
},
{
binInputParameters: [
'-a',
'-e',
'hbs',
'./spec/artifacts/non.default.extension.hbs'
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/non.default.extension.amd.js'
},
// {
// binInputParameters: ['--help'],
// outputLocation: 'stdout',
// expectedOutputSpec: './spec/expected/help.menu.txt'
// },
// {
// binInputParameters: ['-v'],
// outputLocation: 'stdout',
// expectedOutput: require('../package.json').version
// },
// {
// binInputParameters: [
// '-a',
// '-e',
// 'hbs',
// './spec/artifacts/non.default.extension.hbs'
// ],
// outputLocation: 'stdout',
// expectedOutputSpec: './spec/expected/non.default.extension.amd.js'
// },
// {
// binInputParameters: [
// '-a',
// '-p',
// './spec/artifacts/partial.template.handlebars'
// ],
// outputLocation: 'stdout',
// expectedOutputSpec: './spec/expected/partial.template.js'
// },
// {
// binInputParameters: ['spec/artifacts/empty.handlebars', '-c'],
// outputLocation: 'stdout',
// expectedOutputSpec: './spec/expected/empty.common.js'
// },
// {
// binInputParameters: [
// 'spec/artifacts/empty.handlebars',
// 'spec/artifacts/empty.handlebars',
// '-a',
// '-n',
// 'someNameSpace'
// ],
// outputLocation: 'stdout',
// expectedOutputSpec: './spec/expected/namespace.amd.js'
// },
// {
// binInputParameters: [
// 'spec/artifacts/empty.handlebars',
// '-h',
// 'some-path/',
// '-a'
// ],
// outputLocation: 'stdout',
// expectedOutputSpec: './spec/expected/handlebar.path.amd.js'
// },
// {
// binInputParameters: [
// 'spec/artifacts/partial.template.handlebars',
// '-r',
// 'spec',
// '-a'
// ],
// outputLocation: 'stdout',
// expectedOutputSpec: './spec/expected/empty.root.amd.js'
// },
// {
// binInputParameters: [
// '-i',
// '<div>1</div>',
// '-i',
// '<div>2</div>',
// '-N',
// 'firstTemplate',
// '-N',
// 'secondTemplate',
// '-a'
// ],
// outputLocation: 'stdout',
// expectedOutputSpec: './spec/expected/empty.name.amd.js'
// },
// {
// binInputParameters: [
// '-i',
// '<div>1</div>',
// '-a',
// '-m',
// '-N',
// 'test',
// '--map',
// './spec/tmp/source.map.amd.txt'
// ],
// outputLocation: 'stdout',
// expectedOutputSpec: './spec/expected/source.map.amd.js'
// },
// {
// binInputParameters: ['./spec/artifacts/bom.handlebars', '-b', '-a'],
// outputLocation: 'stdout',
// expectedOutputSpec: './spec/expected/bom.amd.js'
// },
// Issue #1673
{
binInputParameters: [
'-a',
'-p',
'./spec/artifacts/partial.template.handlebars'
'--amd',
'--no-amd',
'spec/artifacts/empty.handlebars'
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/partial.template.js'
},
{
binInputParameters: ['spec/artifacts/empty.handlebars', '-c'],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/empty.common.js'
},
{
binInputParameters: [
'spec/artifacts/empty.handlebars',
'spec/artifacts/empty.handlebars',
'-a',
'-n',
'someNameSpace'
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/namespace.amd.js'
},
{
binInputParameters: [
'spec/artifacts/empty.handlebars',
'-h',
'some-path/',
'-a'
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/handlebar.path.amd.js'
},
{
binInputParameters: [
'spec/artifacts/partial.template.handlebars',
'-r',
'spec',
'-a'
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/empty.root.amd.js'
},
{
binInputParameters: [
'-i',
'<div>1</div>',
'-i',
'<div>2</div>',
'-N',
'firstTemplate',
'-N',
'secondTemplate',
'-a'
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/empty.name.amd.js'
},
{
binInputParameters: [
'-i',
'<div>1</div>',
'-a',
'-m',
'-N',
'test',
'--map',
'./spec/tmp/source.map.amd.txt'
],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/source.map.amd.js'
},
{
binInputParameters: ['./spec/artifacts/bom.handlebars', '-b', '-a'],
outputLocation: 'stdout',
expectedOutputSpec: './spec/expected/bom.amd.js'
}
];

Expand Down

0 comments on commit 65d308d

Please sign in to comment.