Skip to content

Commit cbe0c5e

Browse files
committed
Add error message for unsupported options in watch mode
1 parent 17a9adf commit cbe0c5e

File tree

2 files changed

+45
-2
lines changed

2 files changed

+45
-2
lines changed

src/__tests__/configureRollpkg.test.ts

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,41 @@ describe('fails with incorrect configuration', () => {
4747
cwd: '/',
4848
}),
4949
).rejects.toThrowErrorMatchingInlineSnapshot(
50-
`"rollpkg requires a \\"build\\" or \\"watch\\" command with no arguments, received: \\"\\""`,
50+
`"rollpkg requires a \\"build\\" or \\"watch\\" command, received: \\"\\""`,
51+
);
52+
});
53+
54+
test('fails with "watch" command and "--addUmdBuild" options', async () => {
55+
mockFs({
56+
'/package.json': JSON.stringify(createTestPackageJson()),
57+
'/tsconfig.json': '',
58+
'/src/index.ts': '',
59+
});
60+
61+
await expect(
62+
checkInvariantsAndGetConfiguration({
63+
args: ['watch', '--addUmdBuild'],
64+
cwd: '/',
65+
}),
66+
).rejects.toThrowErrorMatchingInlineSnapshot(
67+
`"--addUmdBuild option is not valid in watch mode (only the esm build is created in watch mode)"`,
68+
);
69+
});
70+
71+
test('fails with "watch" command and "--noStats" options', async () => {
72+
mockFs({
73+
'/package.json': JSON.stringify(createTestPackageJson()),
74+
'/tsconfig.json': '',
75+
'/src/index.ts': '',
76+
});
77+
78+
await expect(
79+
checkInvariantsAndGetConfiguration({
80+
args: ['watch', '--noStats'],
81+
cwd: '/',
82+
}),
83+
).rejects.toThrowErrorMatchingInlineSnapshot(
84+
`"--noStats option is not valid in watch mode (stats are never calculated in watch mode)"`,
5185
);
5286
});
5387

src/configureRollpkg.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export const checkInvariantsAndGetConfiguration: ConfigureRollpkg = async ({
3131
}) => {
3232
invariant(
3333
args[0] === 'build' || args[0] === 'watch',
34-
`rollpkg requires a "build" or "watch" command with no arguments, received: "${args.join(
34+
`rollpkg requires a "build" or "watch" command, received: "${args.join(
3535
' ',
3636
)}"`,
3737
);
@@ -50,7 +50,16 @@ export const checkInvariantsAndGetConfiguration: ConfigureRollpkg = async ({
5050
}
5151

5252
const addUmdBuild = args.includes('--addUmdBuild');
53+
invariant(
54+
!watchMode || (watchMode && !addUmdBuild),
55+
'--addUmdBuild option is not valid in watch mode (only the esm build is created in watch mode)',
56+
);
57+
5358
const includeBundlephobiaStats = !args.includes('--noStats');
59+
invariant(
60+
!watchMode || (watchMode && includeBundlephobiaStats),
61+
'--noStats option is not valid in watch mode (stats are never calculated in watch mode)',
62+
);
5463

5564
interface PkgJson extends PackageJson {
5665
umdGlobalDependencies?: { [key: string]: string };

0 commit comments

Comments
 (0)