@squiz/dxp-cli-next 2.11.1-develop.1 → 2.11.1-develop.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -27,4 +27,28 @@ describe('cmp dev', () => {
27
27
  const opts = program.opts();
28
28
  expect(opts.port).toStrictEqual(3000);
29
29
  });
30
+ it.each(['3000', '3001', '65535', '1024'])('correctly parses the port (%s)', (attemptedPort) => __awaiter(void 0, void 0, void 0, function* () {
31
+ const program = (0, dev_mode_1.buildDevModeCommand)()
32
+ .exitOverride()
33
+ .action(() => { });
34
+ program.parse(['node', 'dxp-cli', 'dev', '--port', attemptedPort]);
35
+ const opts = program.opts();
36
+ expect(typeof opts.port).toStrictEqual('number');
37
+ }));
38
+ it.each([
39
+ 'hello_world',
40
+ '3_000',
41
+ '65_535',
42
+ '1000',
43
+ '100',
44
+ '1_000_000',
45
+ '1000000',
46
+ 'abc_1000',
47
+ '1000arst',
48
+ ])('errors when port (%s) is not a number between 1000-65535', attemptedPort => {
49
+ const program = (0, dev_mode_1.buildDevModeCommand)()
50
+ .exitOverride()
51
+ .action(() => { });
52
+ expect(() => program.parse(['node', 'dxp-cli', 'dev', '--port', attemptedPort])).toThrowError('Port must be a number between 1024-65535');
53
+ });
30
54
  });
@@ -12,6 +12,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.buildDevModeCommand = void 0;
13
13
  const commander_1 = require("commander");
14
14
  const component_cli_lib_1 = require("@squiz/component-cli-lib");
15
+ const MIN_PORT = 1024;
16
+ const MAX_PORT = 65535;
15
17
  const buildDevModeCommand = () => new commander_1.Command()
16
18
  .name('dev')
17
19
  .description('A local component runner for developing new components')
@@ -23,7 +25,15 @@ The logs are currently \`bunyan\` formatted and should be piped into the bunyan
23
25
  .argument('<source>', 'folder containing the template files in development')
24
26
  .addOption(new commander_1.Option('-p, --port <number>', 'Define port the webserver runs on')
25
27
  .default(3000)
26
- .argParser(v => parseInt(v)))
28
+ .argParser(v => {
29
+ const parsedPort = Number(v);
30
+ if (isNaN(parsedPort) ||
31
+ MIN_PORT > parsedPort ||
32
+ parsedPort > MAX_PORT) {
33
+ throw new commander_1.InvalidArgumentError(`Port must be a number between ${MIN_PORT}-${MAX_PORT}`);
34
+ }
35
+ return parsedPort;
36
+ }))
27
37
  .action((source, options) => __awaiter(void 0, void 0, void 0, function* () {
28
38
  yield (0, component_cli_lib_1.startDevelopmentRender)(source, options);
29
39
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/dxp-cli-next",
3
- "version": "2.11.1-develop.1",
3
+ "version": "2.11.1-develop.2",
4
4
  "repository": {
5
5
  "url": "https://gitlab.squiz.net/developer-experience/dxp-cli-next"
6
6
  },