forked from nrwl/nx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): nx build --graph file.json should work in subdirectories (n…
- Loading branch information
1 parent
c4b9a82
commit 322ecf7
Showing
9 changed files
with
153 additions
and
46 deletions.
There are no files selected for viewing
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
112 changes: 112 additions & 0 deletions
112
packages/nx/src/command-line/run/command-object.spec.ts
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,112 @@ | ||
import yargs = require('yargs'); | ||
import { withOverrides } from '../yargs-utils/shared-options'; | ||
import { yargsNxInfixCommand, yargsRunCommand } from './command-object'; | ||
|
||
describe('run-one command setup', () => { | ||
it('should parse simple infix and `run` notation equivalently', () => { | ||
const infixOptions = getParsedInfixArgs(['serve', 'myapp']); | ||
const runOptions = getParsedRunArgs(['run', 'myapp:serve']); | ||
|
||
compareArgs(infixOptions, runOptions); | ||
}); | ||
|
||
it.each(['--array=1,2,3', '--array=1 2 3', '--array=1 --array=2 --array=3'])( | ||
'should read arrays (%s)', | ||
(args) => { | ||
const infixArgs = getParsedInfixArgs([ | ||
'serve', | ||
'myapp', | ||
...args.split(' '), | ||
]); | ||
const runArgs = getParsedRunArgs([ | ||
'run', | ||
'myapp:serve', | ||
...args.split(' '), | ||
]); | ||
|
||
compareArgs(infixArgs, runArgs); | ||
} | ||
); | ||
|
||
describe('infix notation', () => { | ||
it('should handle flags passed after project', () => { | ||
const parsed = getParsedInfixArgs([ | ||
'serve', | ||
'myapp', | ||
'--prod', | ||
'--configuration=production', | ||
]); | ||
|
||
expect(parsed.target).toEqual('serve'); | ||
expect(parsed.project).toEqual('myapp'); | ||
expect(parsed.configuration).toEqual('production'); | ||
expect(parsed.prod).toEqual(true); | ||
}); | ||
|
||
it('should handle flags passed before project', () => { | ||
const parsed = getParsedInfixArgs([ | ||
'serve', | ||
'--prod', | ||
'--configuration=production', | ||
'myapp', | ||
]); | ||
|
||
expect(parsed.target).toEqual('serve'); | ||
expect(parsed.project).toEqual('myapp'); | ||
expect(parsed.configuration).toEqual('production'); | ||
expect(parsed.prod).toEqual(true); | ||
}); | ||
|
||
it('should parse with missing project', () => { | ||
const parsed = getParsedArgs(['serve', '--prod'], yargsNxInfixCommand); | ||
|
||
expect(parsed.target).toEqual('serve'); | ||
expect(parsed.project).toEqual(undefined); | ||
expect(parsed.configuration).toEqual(undefined); | ||
expect(parsed.prod).toEqual(true); | ||
}); | ||
}); | ||
}); | ||
|
||
function compareArgs(a: any, b: any) { | ||
delete a['_']; | ||
delete b['_']; | ||
// delete a['__overrides_unparsed__']; | ||
// delete b['__overrides_unparsed__']; | ||
if (a['target'] && a['project']) { | ||
a['project:target:configuration'] = `${a['project']}:${a['target']}`; | ||
delete a['project']; | ||
delete a['target']; | ||
} | ||
if (b['target'] && b['project']) { | ||
b['project:target:configuration'] = `${b['project']}:${b['target']}`; | ||
delete b['project']; | ||
delete b['target']; | ||
} | ||
expect(a).toEqual(b); | ||
} | ||
|
||
function getParsedInfixArgs(args: string[]) { | ||
return getParsedArgs(args, yargsNxInfixCommand, 0); | ||
} | ||
|
||
function getParsedRunArgs(args: string[]) { | ||
return getParsedArgs(args, yargsRunCommand); | ||
} | ||
|
||
function getParsedArgs( | ||
args: string[], | ||
command: yargs.CommandModule, | ||
withOverridesLevel = 1 | ||
) { | ||
let parsedArgs: any; | ||
yargs(args) | ||
.command({ | ||
...command, | ||
handler: (args) => { | ||
parsedArgs = withOverrides({ ...args }, withOverridesLevel); | ||
}, | ||
}) | ||
.parse(); | ||
return parsedArgs; | ||
} |
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