sku 12.4.11 → 12.5.0

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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,23 @@
1
1
  # sku
2
2
 
3
+ ## 12.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Update TypeScript to 5.3 ([#938](https://github.com/seek-oss/sku/pull/938))
8
+
9
+ This release includes breaking changes. See the [TypeScript 5.3 announcement] for more information.
10
+
11
+ [TypeScript 5.3 announcement]: https://devblogs.microsoft.com/typescript/announcing-typescript-5-3/
12
+
13
+ ### Patch Changes
14
+
15
+ - Remove `empty-dir` dependency ([#935](https://github.com/seek-oss/sku/pull/935))
16
+
17
+ - Replace `command-line-args` with `minimist` for parsing CLI arguments ([#940](https://github.com/seek-oss/sku/pull/940))
18
+
19
+ - Emit incremental TypeScript build info for faster subsequent type checking ([#938](https://github.com/seek-oss/sku/pull/938))
20
+
3
21
  ## 12.4.11
4
22
 
5
23
  ### Patch Changes
@@ -4,11 +4,15 @@ const { rootResolution, tsconfigDecorator } = require('../../context');
4
4
  module.exports = () => {
5
5
  const config = {
6
6
  compilerOptions: {
7
- // This flag allows tsc to be invoked directly by VS Code (via Cmd+Shift+B),
8
- // otherwise it would emit a bunch of useless JS/JSX files in your project.
9
- // We emit compiled JavaScript into `dist` via webpack + Babel, not tsc.
7
+ // Don't compile anything, only perform type checking
10
8
  noEmit: true,
11
9
 
10
+ // Emit build information for faster subsequent type checking
11
+ incremental: true,
12
+ // Emit build information to `node_modules` to avoid bloating the project root
13
+ // and ignore files
14
+ outDir: 'node_modules',
15
+
12
16
  // Fixes https://github.com/cypress-io/cypress/issues/1087
13
17
  skipLibCheck: true,
14
18
 
@@ -1,20 +1,14 @@
1
1
  import fs from 'node:fs';
2
2
  import http from 'node:http';
3
3
  import https from 'node:https';
4
- import commandLineArgs from 'command-line-args';
5
4
  import { app, onStart } from './server';
5
+ import minimist from 'minimist';
6
6
 
7
- const { port } = commandLineArgs(
8
- [
9
- {
10
- name: 'port',
11
- alias: 'p',
12
- type: Number,
13
- defaultValue: __SKU_DEFAULT_SERVER_PORT__, // eslint-disable-line no-undef
14
- },
15
- ],
16
- { partial: true },
17
- );
7
+ const { port } = minimist(process.argv.slice(2), {
8
+ alias: { p: 'port' },
9
+ // eslint-disable-next-line no-undef
10
+ default: { port: __SKU_DEFAULT_SERVER_PORT__ },
11
+ });
18
12
 
19
13
  const startCallback = () => {
20
14
  console.log('Server started on port', port);
package/lib/configure.js CHANGED
@@ -32,27 +32,23 @@ const writeFileToCWD = async (fileName, content, { banner = true } = {}) => {
32
32
  };
33
33
 
34
34
  module.exports = async () => {
35
- // Ignore webpack bundle report output
35
+ // Ignore target directories
36
+ const webpackTargetDirectory = addSep(
37
+ paths.target.replace(addSep(cwd()), ''),
38
+ );
39
+ const storybookTargetDirectory = addSep(
40
+ paths.storybookTarget.replace(addSep(cwd()), ''),
41
+ );
42
+
36
43
  const gitIgnorePatterns = [
44
+ // Ignore webpack bundle report output
37
45
  addSep(bundleReportFolder),
38
46
  addSep(coverageFolder),
47
+ webpackTargetDirectory,
48
+ storybookTargetDirectory,
39
49
  storybookMainConfigPath,
40
50
  ];
41
- const lintIgnorePatterns = [
42
- addSep(bundleReportFolder),
43
- addSep(coverageFolder),
44
- '*.less.d.ts',
45
- storybookMainConfigPath,
46
- ];
47
-
48
- // Ignore webpack target directories
49
- const targetDirectory = addSep(paths.target.replace(addSep(cwd()), ''));
50
- const storybookTargetDirectory = addSep(
51
- paths.storybookTarget.replace(addSep(cwd()), ''),
52
- );
53
-
54
- gitIgnorePatterns.push(targetDirectory, storybookTargetDirectory);
55
- lintIgnorePatterns.push(targetDirectory, storybookTargetDirectory);
51
+ const lintIgnorePatterns = [...gitIgnorePatterns, '*.less.d.ts'];
56
52
 
57
53
  // Generate ESLint configuration
58
54
  const eslintConfigFilename = '.eslintrc';
@@ -0,0 +1,20 @@
1
+ const { statSync, readdirSync } = require('node:fs');
2
+
3
+ /**
4
+ * Returns whether the given directory is empty, throwing if the path is not a directory
5
+ * @typedef {import('fs').PathLike} PathLike
6
+ * @param {PathLike} path A path to a directory
7
+ */
8
+ const isEmptyDir = (path) => {
9
+ const isDirectory = statSync(path).isDirectory();
10
+
11
+ if (!isDirectory) {
12
+ throw new Error(`${path} is not a directory`);
13
+ }
14
+
15
+ const files = readdirSync(path);
16
+
17
+ return files.length === 0;
18
+ };
19
+
20
+ module.exports = { isEmptyDir };
package/lib/parseArgs.js CHANGED
@@ -1,58 +1,4 @@
1
- const commandLineArgs = require('command-line-args');
2
-
3
- const optionDefinitions = [
4
- {
5
- name: 'script',
6
- defaultOption: true,
7
- },
8
- {
9
- name: 'env',
10
- alias: 'e',
11
- type: String,
12
- defaultValue: 'production',
13
- },
14
- {
15
- name: 'tenant',
16
- alias: 't',
17
- type: String,
18
- defaultValue: '',
19
- },
20
- {
21
- name: 'build',
22
- alias: 'b',
23
- type: String,
24
- },
25
- {
26
- name: 'config',
27
- alias: 'c',
28
- type: String,
29
- },
30
- {
31
- name: 'debug',
32
- alias: 'D',
33
- type: Boolean,
34
- },
35
- {
36
- name: 'environment',
37
- type: String,
38
- },
39
- {
40
- name: 'packageManager',
41
- type: String,
42
- },
43
- {
44
- name: 'port',
45
- type: Number,
46
- },
47
- {
48
- name: 'site',
49
- type: String,
50
- },
51
- {
52
- name: 'stats',
53
- type: String,
54
- },
55
- ];
1
+ const minimist = require('minimist');
56
2
 
57
3
  /**
58
4
  * Supports parsing args that look like:
@@ -60,16 +6,53 @@ const optionDefinitions = [
60
6
  *
61
7
  * @param {string[]} args - should look like process.argv
62
8
  */
63
- module.exports = (args) => {
64
- const options = commandLineArgs(optionDefinitions, {
9
+ module.exports = (processArgv) => {
10
+ /**
11
+ * @type {string[]}
12
+ */
13
+ const unknown = [];
14
+
15
+ // We are tracking unknown arguments ourselves, so we ignore `minimist`'s unknown property `_`
16
+ const { _, ...options } = minimist(
65
17
  // The first 2 items in process.argv are /path/to/node and /path/to/sku.
66
- // We need the first arg we give to command-line-args to be the script name.
67
- argv: args.slice(2),
68
- stopAtFirstUnknown: false,
69
- partial: true,
70
- });
18
+ // We need the first arg we give to minimist to be the script name.
19
+ processArgv.slice(2),
20
+ {
21
+ string: [
22
+ 'env',
23
+ 'tenant',
24
+ 'build',
25
+ 'config',
26
+ 'environment',
27
+ 'packageManager',
28
+ 'site',
29
+ 'stats',
30
+ ],
31
+ default: {
32
+ env: 'production',
33
+ tenant: '',
34
+ },
35
+ alias: {
36
+ e: 'env',
37
+ t: 'tenant',
38
+ b: 'build',
39
+ c: 'config',
40
+ D: 'debug',
41
+ },
42
+ boolean: [
43
+ 'debug',
44
+ // Passed to Vocab in the `translations` script
45
+ 'delete-unused-keys',
46
+ ],
47
+ // `minimist` does not push unknown flags to `_` even if this function returns `true`, so we
48
+ // need to track them ourselves
49
+ unknown: (arg) => {
50
+ unknown.push(arg);
51
+ },
52
+ },
53
+ );
71
54
 
72
- const { script, _unknown: argv = [] } = options;
55
+ const [script, ...argv] = unknown;
73
56
 
74
57
  // Backwards compatibility for unnamed build name argument, to be deprecated
75
58
  const buildName = () => {
@@ -78,11 +61,13 @@ module.exports = (args) => {
78
61
  } else if (argv.length) {
79
62
  return argv[0];
80
63
  }
81
- return undefined; // eslint-disable-line no-undefined
64
+
65
+ return undefined;
82
66
  };
83
67
 
84
68
  return {
85
69
  ...options,
70
+ script,
86
71
  buildName: script === 'start' ? buildName() : null,
87
72
  env: script === 'start' ? 'development' : options.env,
88
73
  argv,
@@ -1,20 +1,28 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+
1
5
  const parseArgs = require('./parseArgs');
2
6
 
3
- describe('arg parsing', () => {
4
- test('sku exec', () => {
5
- const { script, argv, env } = parseArgs([
7
+ describe('parseArgs', () => {
8
+ test('sku script with short and long flag', () => {
9
+ const { script, argv, env, config } = parseArgs([
6
10
  '/path/to/node',
7
11
  '/path/to/bin/sku',
8
12
  'lint',
9
13
  '-e',
10
14
  'test',
15
+ '--config',
16
+ 'custom.sku.config.ts',
11
17
  ]);
18
+
12
19
  expect(script).toEqual('lint');
13
20
  expect(argv).toEqual([]);
14
21
  expect(env).toEqual('test');
22
+ expect(config).toEqual('custom.sku.config.ts');
15
23
  });
16
24
 
17
- test('sku exec with args', () => {
25
+ test('sku script with flag and argument', () => {
18
26
  const { script, argv, env } = parseArgs([
19
27
  '/path/to/node',
20
28
  '/path/to/bin/sku',
@@ -23,15 +31,32 @@ describe('arg parsing', () => {
23
31
  '-e',
24
32
  'test',
25
33
  ]);
34
+
26
35
  expect(script).toEqual('lint');
27
36
  expect(argv).toEqual(['src/components/**']);
28
37
  expect(env).toEqual('test');
29
38
  });
30
39
 
40
+ test('sku script with argument, known flag and unknown flag', () => {
41
+ const { script, argv, env } = parseArgs([
42
+ '/path/to/node',
43
+ '/path/to/bin/sku',
44
+ 'test',
45
+ '-e',
46
+ 'test',
47
+ 'testFilter',
48
+ '--someJestFlag',
49
+ ]);
50
+
51
+ expect(script).toEqual('test');
52
+ expect(argv).toEqual(['testFilter', '--someJestFlag']);
53
+ expect(env).toEqual('test');
54
+ });
55
+
31
56
  test('debug', () => {
32
57
  expect(
33
58
  parseArgs(['/path/to/node', '/path/to/bin/sku', 'build']).debug,
34
- ).toBeUndefined();
59
+ ).toBe(false);
35
60
 
36
61
  expect(
37
62
  parseArgs(['/path/to/node', '/path/to/bin/sku', '-D', 'build']).debug,
@@ -1,3 +1,7 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+
1
5
  const toPosixPath = require('./toPosixPath');
2
6
 
3
7
  describe('toPosixPath', () => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sku",
3
- "version": "12.4.11",
3
+ "version": "12.5.0",
4
4
  "description": "Front-end development toolkit, powered by Webpack, Babel, CSS Modules, Less and Jest",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -64,7 +64,6 @@
64
64
  "browserslist": "^4.16.1",
65
65
  "browserslist-config-seek": "^2.1.0",
66
66
  "chalk": "^4.1.0",
67
- "command-line-args": "^5.1.1",
68
67
  "cross-spawn": "^7.0.3",
69
68
  "css-loader": "^6.7.1",
70
69
  "css-modules-typescript-loader": "4.0.1",
@@ -74,7 +73,6 @@
74
73
  "dedent": "^1.5.1",
75
74
  "didyoumean2": "^6.0.1",
76
75
  "ejs": "^3.1.8",
77
- "empty-dir": "^3.0.0",
78
76
  "ensure-gitignore": "^1.1.2",
79
77
  "env-ci": "^7.0.0",
80
78
  "esbuild": "^0.19.7",
@@ -99,6 +97,7 @@
99
97
  "lint-staged": "^11.1.1",
100
98
  "memoizee": "^0.4.15",
101
99
  "mini-css-extract-plugin": "^2.6.1",
100
+ "minimist": "^1.2.8",
102
101
  "node-html-parser": "^6.1.1",
103
102
  "open": "^7.3.1",
104
103
  "path-to-regexp": "^6.2.0",
@@ -115,7 +114,7 @@
115
114
  "svgo-loader": "^4.0.0",
116
115
  "terser-webpack-plugin": "^5.1.4",
117
116
  "tree-kill": "^1.2.1",
118
- "typescript": "~5.2.0",
117
+ "typescript": "~5.3.0",
119
118
  "validate-npm-package-name": "^5.0.0",
120
119
  "webpack": "^5.52.0",
121
120
  "webpack-bundle-analyzer": "^4.6.1",
package/scripts/init.js CHANGED
@@ -10,7 +10,7 @@ const {
10
10
  const chalk = require('chalk');
11
11
  const fs = require('node:fs/promises');
12
12
  const { posix: path } = require('node:path');
13
- const emptyDir = require('empty-dir');
13
+ const { isEmptyDir } = require('../lib/isEmptyDir');
14
14
  const validatePackageName = require('validate-npm-package-name');
15
15
  const dedent = require('dedent');
16
16
  const { setCwd } = require('../lib/cwd');
@@ -125,7 +125,7 @@ const getTemplateFileDestinationFromRoot =
125
125
 
126
126
  await fs.mkdir(projectName, { recursive: true });
127
127
 
128
- if (!emptyDir.sync(root)) {
128
+ if (!isEmptyDir(root)) {
129
129
  console.log(`The directory ${chalk.green(projectName)} is not empty.`);
130
130
  process.exit(1);
131
131
  }