Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix duplicated web scripts options #362

Merged
merged 2 commits into from
May 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 9 additions & 22 deletions packages/web-scripts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,13 @@ program
.option('--no-types', 'do not build types target')
.action((...args) => {
const cmd = getCommand(args);
const rest = getPositionalArgs(args);
const { esm, types, cjs } = getOpts(cmd);
const t: BuildTaskDesc = {
name: 'build',
esm,
types,
cjs,
restOptions: [...parseRestOptions(cmd), ...rest],
restOptions: parseRestOptions(cmd),
};

handlePromiseResult(buildTask(t));
Expand All @@ -76,12 +75,11 @@ program
.option('--config [path]', 'path to jest config')
.action((...args) => {
const cmd = getCommand(args);
const rest = getPositionalArgs(args);
const { config } = getOpts(cmd);
const t: TestTaskDesc = {
name: 'test',
config,
restOptions: [...parseRestOptions(cmd), ...rest],
restOptions: parseRestOptions(cmd),
};

const result = testTask(t);
Expand All @@ -99,14 +97,13 @@ program
.option('--no-stylecheck', "do not run Prettier's style check")
.action((...args) => {
const cmd = getCommand(args);
const rest = getPositionalArgs(args);
const { stylecheck, typecheck, config } = getOpts(cmd);
const t: LintTaskDesc = {
name: 'lint',
config,
stylecheck,
typecheck,
restOptions: [...parseRestOptions(cmd), ...rest],
restOptions: parseRestOptions(cmd),
};

handlePromiseResult(lintTask(t));
Expand All @@ -123,13 +120,12 @@ program
)
.action((...args) => {
const cmd = getCommand(args);
const rest = getPositionalArgs(args);
const { config, path } = getOpts(cmd);
const t: FormatTaskDesc = {
name: 'format',
config,
path,
restOptions: [...parseRestOptions(cmd), ...rest],
restOptions: parseRestOptions(cmd),
};

handleSpawnResult(formatTask(t));
Expand All @@ -146,7 +142,6 @@ program
.option('--no-typecheck', 'Do not type check using TypeScript')
.action((...args) => {
const cmd = getCommand(args);
const rest = getPositionalArgs(args);
const {
tests,
typecheck,
Expand All @@ -161,7 +156,7 @@ program
jestConfig,
eslintConfig,
prettierConfig,
restOptions: [...parseRestOptions(cmd), ...rest],
restOptions: parseRestOptions(cmd),
};

handlePromiseResult(precommitTask(t));
Expand Down Expand Up @@ -195,12 +190,11 @@ program
)
.action((...args) => {
const cmd = getCommand(args);
const rest = getPositionalArgs(args);
const { threshold } = getOpts(cmd);
const t: AuditTaskDesc = {
name: 'audit',
threshold,
restOptions: [...parseRestOptions(cmd), ...rest],
restOptions: parseRestOptions(cmd),
};

handlePromiseResult(auditTask(t));
Expand All @@ -217,12 +211,11 @@ program
)
.action((...args) => {
const cmd = getCommand(args);
const rest = getPositionalArgs(args);
const { path } = getOpts(cmd);
const t: CommitTaskDesc = {
name: 'commit',
path,
restOptions: [...parseRestOptions(cmd), ...rest],
restOptions: parseRestOptions(cmd),
};

try {
Expand All @@ -243,12 +236,11 @@ program
)
.action((...args) => {
const cmd = getCommand(args);
const rest = getPositionalArgs(args);
const { config } = getOpts(cmd);
const t: CommitMsgTaskDesc = {
name: 'commitmsg',
config,
restOptions: [...parseRestOptions(cmd), ...rest],
restOptions: parseRestOptions(cmd),
};

handleSpawnResult(commitMsgTask(t));
Expand All @@ -260,10 +252,9 @@ program
.description('Run semantic-release')
.action((...args) => {
const cmd = getCommand(args);
const rest = getPositionalArgs(args);
const t: ReleaseTaskDesc = {
name: 'release',
restOptions: [...parseRestOptions(cmd), ...rest],
restOptions: parseRestOptions(cmd),
};

handleSpawnResult(releaseTask(t));
Expand Down Expand Up @@ -297,10 +288,6 @@ function getCommand(args: any[]): Command {
return args[0] as Command;
}

function getPositionalArgs(args: any[]): string[] {
return args.slice(1) as string[];
}

function getOpts(cmd: Command): { [key: string]: any } {
return cmd.opts();
}
Expand Down
2 changes: 1 addition & 1 deletion packages/web-scripts/src/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ describe('integration tests', () => {

async function testScripts(
buildArgs: string[] = [],
lintArgs: string[] = [],
lintArgs: string[] = ['--ignore-path=.gitignore', '--format=checkstyle'],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added reproduction from #341 as a failing test, though I guess it's a bit random to be testing with these specific options set. Perhaps better broken out as a separate test.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is good for now - we have a separate backlog task to break this IT up into something more manageable for all of the scripts.

) {
try {
rimraf.sync(join(PKG_ROOT, 'cjs'));
Expand Down