sku 12.1.2 → 12.3.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,66 @@
1
1
  # sku
2
2
 
3
+ ## 12.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - Allow importing external CSS from `node_modules`. ([#861](https://github.com/seek-oss/sku/pull/861))
8
+
9
+ CSS from third-party dependencies can be loaded using a side-effect import, e.g.
10
+
11
+ ```tsx
12
+ import { SomeComponent } from 'some-package';
13
+
14
+ import 'some-package/dist/styles.css';
15
+
16
+ export const MyComponent = () => {
17
+ return <SomeComponent>{/* ... */}</SomeComponent>;
18
+ };
19
+ ```
20
+
21
+ ## 12.2.0
22
+
23
+ ### Minor Changes
24
+
25
+ - Export internal Jest configuration as a [preset](https://jestjs.io/docs/configuration#preset-string) under `sku/config/jest`. This allows consumers to debug tests in their IDE by specifying the preset in their `jest.config.js`: ([#850](https://github.com/seek-oss/sku/pull/850))
26
+
27
+ ```js
28
+ /** @type {import('jest').Config} */
29
+ module.exports = {
30
+ preset: 'sku/config/jest',
31
+ };
32
+ ```
33
+
34
+ - `srcPaths` no longer affects `tsconfig.json#include`. Instead, you can use the [`dangerouslySetTSConfig`][dangerous] option to have more control over which files are included in the type checking process. ([#848](https://github.com/seek-oss/sku/pull/848))
35
+
36
+ Previously, sku managed the `include` field in `tsconfig.json`, but this was problematic for projects that wanted more fine grained control over what was included and/or excluded from compilation.
37
+
38
+ > **Note**: If you were previously using [`srcPaths`][srcpaths] for this purpose, you should remove the paths which are not source files.
39
+
40
+ [dangerous]: https://seek-oss.github.io/sku/#/./docs/configuration?id=dangerouslysettsconfig
41
+ [srcpaths]: https://seek-oss.github.io/sku/#/./docs/configuration?id=srcpaths
42
+
43
+ - Update `tsconfig.json` options to match the latest version of the TypeScript compiler. ([#844](https://github.com/seek-oss/sku/pull/844))
44
+
45
+ ### Patch Changes
46
+
47
+ - Upgrade to TypeScript 5.1 ([#844](https://github.com/seek-oss/sku/pull/844))
48
+
49
+ - Update dependency `eslint-config-seek`. ([#844](https://github.com/seek-oss/sku/pull/844))
50
+
51
+ This reverts [the autofix for a Cypress rule][rule] and [improves the performance][eslint] of linting TypeScript files.
52
+
53
+ [rule]: https://github.com/seek-oss/eslint-config-seek/releases/tag/v11.2.1
54
+ [eslint]: https://github.com/seek-oss/eslint-config-seek/releases/tag/v11.3.0
55
+
56
+ - The presence of a `sku.config.js` file previously had an effect on what was included in the `tsconfig.json#include` array. With the removal of the default `include` array, this is no longer the case and you might see a TypeScript error like this: ([#848](https://github.com/seek-oss/sku/pull/848))
57
+
58
+ ```
59
+ error TS18003: No inputs were found in config file '/path/to/project/tsconfig.json'. Specified 'include' paths were '["**/*"]' and 'exclude' paths were '[]'.
60
+ ```
61
+
62
+ If your project contains only JavaScript files and you see the above error, you should rename `sku.config.js` to `sku.config.ts` and the error will go away.
63
+
3
64
  ## 12.1.2
4
65
 
5
66
  ### Patch Changes
@@ -1,13 +1,14 @@
1
1
  const escapeRegex = require('escape-string-regexp');
2
2
  const { cwd } = require('../../lib/cwd');
3
- const { paths, rootResolution } = require('../../context');
3
+ const { paths, rootResolution, jestDecorator } = require('../../context');
4
+
4
5
  const slash = '[/\\\\]'; // Cross-platform path delimiter regex
5
6
  const compilePackagesRegex = paths.compilePackages
6
7
  .map((pkg) => `.*${escapeRegex(pkg)}`)
7
8
  .join('|');
8
9
 
9
10
  /** @type {import('jest').Config} */
10
- module.exports = {
11
+ module.exports = jestDecorator({
11
12
  testEnvironment: 'jsdom',
12
13
  setupFilesAfterEnv: paths.setupTests,
13
14
  prettierPath: require.resolve('prettier'),
@@ -41,4 +42,4 @@ module.exports = {
41
42
  require.resolve('jest-watch-typeahead/filename'),
42
43
  require.resolve('jest-watch-typeahead/testname'),
43
44
  ],
44
- };
45
+ });
@@ -26,7 +26,8 @@ module.exports = ({ config }, { isDevServer }) => {
26
26
  : [previousExclude]), // Ensure we don't clobber any existing exclusions
27
27
  ...paths.src,
28
28
  ...paths.compilePackages.map(resolvePackage),
29
- /\.vanilla\.css$/,
29
+ /\.vanilla\.css$/, // Vanilla Extract virtual modules
30
+ /\.css$/, // external CSS
30
31
  ];
31
32
  });
32
33
  }
@@ -1,19 +1,7 @@
1
1
  const { cwd } = require('../../lib/cwd');
2
- const { paths, rootResolution } = require('../../context');
3
- const path = require('path');
2
+ const { rootResolution, tsconfigDecorator } = require('../../context');
4
3
 
5
4
  module.exports = () => {
6
- const includePaths = paths.src;
7
-
8
- if (paths.appSkuConfigPath && paths.appSkuConfigPath.endsWith('.ts')) {
9
- // If the config file is in TypeScript, it needs to be included in the tsconfig
10
- includePaths.push(paths.appSkuConfigPath);
11
- } else {
12
- // If it isn't, the placeholder file needs to be included so we don't break JS only projects.
13
- // See the comments in placeholder.ts
14
- includePaths.push(path.join(__dirname, '../../lib/placeholder.ts'));
15
- }
16
-
17
5
  const config = {
18
6
  compilerOptions: {
19
7
  // This flag allows tsc to be invoked directly by VS Code (via Cmd+Shift+B),
@@ -24,25 +12,34 @@ module.exports = () => {
24
12
  // Fixes https://github.com/cypress-io/cypress/issues/1087
25
13
  skipLibCheck: true,
26
14
 
27
- esModuleInterop: true,
15
+ // When dependencies have `type: module` TypeScript doesn't know how to resolve them,
16
+ // so we need to set this to `bundler` or `node`
17
+ moduleResolution: 'bundler',
18
+ // This is required by `bundler` and for dynamic `import()`
19
+ module: 'es2022',
20
+
21
+ // resolution-related
22
+ allowImportingTsExtensions: true,
28
23
  allowSyntheticDefaultImports: true,
24
+ esModuleInterop: true,
25
+ isolatedModules: true,
29
26
  resolveJsonModule: true,
30
- noUnusedLocals: true,
27
+
28
+ // misc
31
29
  strict: true,
32
- jsx: 'preserve',
33
- lib: ['dom', 'es2019'],
34
- target: 'es5',
30
+ forceConsistentCasingInFileNames: true,
31
+ jsx: 'react-jsx',
32
+ lib: ['dom', 'es2022'],
33
+ target: 'es2022',
35
34
  },
36
- include: includePaths,
37
35
  };
38
36
 
39
37
  if (rootResolution) {
40
38
  config.compilerOptions.paths = {
41
39
  '*': ['*'],
42
40
  };
43
-
44
41
  config.compilerOptions.baseUrl = cwd();
45
42
  }
46
43
 
47
- return config;
44
+ return tsconfigDecorator(config);
48
45
  };
@@ -5,7 +5,7 @@ const { VanillaExtractPlugin } = require('@vanilla-extract/webpack-plugin');
5
5
  const {
6
6
  makeJsLoaders,
7
7
  makeCssLoaders,
8
- makeVanillaCssLoaders,
8
+ makeExternalCssLoaders,
9
9
  makeSvgLoaders,
10
10
  TYPESCRIPT,
11
11
  JAVASCRIPT,
@@ -148,18 +148,35 @@ class SkuWebpackPlugin {
148
148
  }),
149
149
  },
150
150
  {
151
- // All CSS created by vanilla-extract
152
- test: /\.vanilla.css$/i,
153
- // Don't process vanilla files from Playroom as they are handled separately.
154
- // Virtual file paths will look more realistic in the future allowing
155
- // more standard handling of include/exclude path matching.
156
- exclude: /node_modules\/playroom/,
157
- use: makeVanillaCssLoaders({
158
- isProductionBuild,
159
- MiniCssExtractPlugin,
160
- hot,
161
- browserslist,
162
- }),
151
+ test: /\.css$/i,
152
+ oneOf: [
153
+ {
154
+ // All CSS created by vanilla-extract
155
+ test: /\.vanilla\.css$/i,
156
+ // Don't process vanilla files from Playroom as they are handled separately.
157
+ // Virtual file paths will look more realistic in the future allowing
158
+ // more standard handling of include/exclude path matching.
159
+ exclude: /node_modules\/playroom/,
160
+ use: makeExternalCssLoaders({
161
+ isProductionBuild,
162
+ MiniCssExtractPlugin,
163
+ hot,
164
+ browserslist,
165
+ }),
166
+ },
167
+ {
168
+ test: /\.css$/i,
169
+ include: /node_modules/,
170
+ exclude: /node_modules\/playroom/,
171
+ use: makeExternalCssLoaders({
172
+ target,
173
+ isProductionBuild,
174
+ MiniCssExtractPlugin,
175
+ hot,
176
+ browserslist,
177
+ }),
178
+ },
179
+ ],
163
180
  },
164
181
  {
165
182
  test: IMAGE,
@@ -91,18 +91,18 @@ const makeCssLoaders = (options = {}) => {
91
91
  },
92
92
  ]
93
93
  : []),
94
-
95
94
  {
96
95
  loader: require.resolve('less-loader'),
97
96
  },
98
97
  ];
99
98
  };
100
99
 
101
- const makeVanillaCssLoaders = (options = {}) => {
102
- const { isProductionBuild, MiniCssExtractPlugin, browserslist } = options;
100
+ const makeExternalCssLoaders = (options = {}) => {
101
+ const { target, isProductionBuild, MiniCssExtractPlugin, browserslist } =
102
+ options;
103
103
 
104
104
  return [
105
- MiniCssExtractPlugin.loader,
105
+ ...(!target || target === 'browser' ? [MiniCssExtractPlugin.loader] : []),
106
106
  {
107
107
  loader: require.resolve('css-loader'),
108
108
  options: {
@@ -162,6 +162,6 @@ const makeSvgLoaders = () => [
162
162
  module.exports = {
163
163
  makeJsLoaders,
164
164
  makeCssLoaders,
165
- makeVanillaCssLoaders,
165
+ makeExternalCssLoaders,
166
166
  makeSvgLoaders,
167
167
  };
@@ -117,6 +117,9 @@ module.exports = validator.compile({
117
117
  type: 'array',
118
118
  items: 'string',
119
119
  },
120
+ storybookStoryStore: {
121
+ type: 'boolean',
122
+ },
120
123
  target: {
121
124
  type: 'string',
122
125
  },
@@ -162,6 +165,9 @@ module.exports = validator.compile({
162
165
  dangerouslySetESLintConfig: {
163
166
  type: 'function',
164
167
  },
168
+ dangerouslySetTSConfig: {
169
+ type: 'function',
170
+ },
165
171
  supportedBrowsers: {
166
172
  type: 'array',
167
173
  items: {
@@ -201,7 +207,4 @@ module.exports = validator.compile({
201
207
  externalizeNodeModules: {
202
208
  type: 'boolean',
203
209
  },
204
- storybookStoryStore: {
205
- type: 'boolean',
206
- },
207
210
  });
@@ -26,6 +26,7 @@ module.exports = {
26
26
  storybookPort: 8081,
27
27
  storybookTarget: 'dist-storybook',
28
28
  storybookAddons: [],
29
+ storybookStoryStore: true,
29
30
  initialPath: null,
30
31
  public: 'public',
31
32
  publicPath: '/',
@@ -37,6 +38,7 @@ module.exports = {
37
38
  dangerouslySetWebpackConfig: defaultDecorator,
38
39
  dangerouslySetJestConfig: defaultDecorator,
39
40
  dangerouslySetESLintConfig: defaultDecorator,
41
+ dangerouslySetTSConfig: defaultDecorator,
40
42
  supportedBrowsers,
41
43
  orderImports: false,
42
44
  cspEnabled: false,
@@ -48,5 +50,4 @@ module.exports = {
48
50
  skipPackageCompatibilityCompilation: [],
49
51
  persistentCache: true,
50
52
  externalizeNodeModules: false,
51
- storybookStoryStore: true,
52
53
  };
package/context/index.js CHANGED
@@ -188,11 +188,13 @@ module.exports = {
188
188
  storybookPort: skuConfig.storybookPort,
189
189
  storybookTarget: skuConfig.storybookTarget,
190
190
  storybookAddons: skuConfig.storybookAddons,
191
+ storybookStoryStore: skuConfig.storybookStoryStore,
191
192
  polyfills: skuConfig.polyfills,
192
193
  initialPath,
193
194
  webpackDecorator: skuConfig.dangerouslySetWebpackConfig,
194
195
  jestDecorator: skuConfig.dangerouslySetJestConfig,
195
196
  eslintDecorator: skuConfig.dangerouslySetESLintConfig,
197
+ tsconfigDecorator: skuConfig.dangerouslySetTSConfig,
196
198
  routes: normalizedRoutes,
197
199
  sites,
198
200
  environments: skuConfig.environments,
@@ -214,5 +216,4 @@ module.exports = {
214
216
  skuConfig.skipPackageCompatibilityCompilation,
215
217
  persistentCache: skuConfig.persistentCache,
216
218
  externalizeNodeModules: skuConfig.externalizeNodeModules,
217
- storybookStoryStore: skuConfig.storybookStoryStore,
218
219
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sku",
3
- "version": "12.1.2",
3
+ "version": "12.3.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": {
@@ -79,7 +79,7 @@
79
79
  "esbuild-register": "^3.3.3",
80
80
  "escape-string-regexp": "^4.0.0",
81
81
  "eslint": "^8.41.0",
82
- "eslint-config-seek": "^11.2.0",
82
+ "eslint-config-seek": "^11.3.1",
83
83
  "exception-formatter": "^2.1.2",
84
84
  "express": "^4.16.3",
85
85
  "fast-glob": "^3.2.5",
@@ -117,7 +117,7 @@
117
117
  "terser-webpack-plugin": "^5.1.4",
118
118
  "traverse": "^0.6.6",
119
119
  "tree-kill": "^1.2.1",
120
- "typescript": "~5.0.0",
120
+ "typescript": "~5.1.0",
121
121
  "validate-npm-package-name": "^5.0.0",
122
122
  "webpack": "^5.52.0",
123
123
  "webpack-bundle-analyzer": "^4.6.1",
package/scripts/test.js CHANGED
@@ -1,21 +1,23 @@
1
+ const path = require('path');
2
+ const debug = require('debug');
1
3
  const jest = require('jest');
2
4
 
3
5
  const isCI = require('../lib/isCI');
4
- const baseJestConfig = require('../config/jest/jestConfig');
5
6
  const { argv } = require('../config/args');
6
- const { jestDecorator } = require('../context');
7
-
8
7
  const { runVocabCompile } = require('../lib/runVocab');
9
8
 
9
+ const log = debug('sku:jest');
10
10
  // https://reactjs.org/blog/2022/03/08/react-18-upgrade-guide.html#configuring-your-testing-environment
11
11
  process.env.IS_REACT_ACT_ENVIRONMENT = true;
12
12
 
13
13
  (async () => {
14
14
  await runVocabCompile();
15
15
 
16
- const jestConfig = jestDecorator(baseJestConfig);
16
+ // https://jestjs.io/docs/configuration#preset-string
17
+ const jestPreset = require.resolve('../config/jest/jest-preset');
18
+ log(`Using Jest preset at ${jestPreset}`);
17
19
 
18
- argv.push('--config', JSON.stringify(jestConfig));
20
+ argv.push('--preset', path.dirname(jestPreset));
19
21
 
20
22
  if (isCI) {
21
23
  argv.push('--ci');
package/sku-types.d.ts CHANGED
@@ -102,20 +102,27 @@ export interface SkuConfig {
102
102
  cspExtraScriptSrcHosts?: string[];
103
103
 
104
104
  /**
105
- * Similar to {@link dangerouslySetWebpackConfig} but for eslint config.
105
+ * Similar to {@link dangerouslySetWebpackConfig}, but for ESLint config.
106
106
  *
107
107
  * @link https://seek-oss.github.io/sku/#/./docs/configuration?id=dangerouslyseteslintconfig
108
108
  */
109
109
  dangerouslySetESLintConfig?: (existingESLintConfig: any) => any;
110
110
 
111
111
  /**
112
- * Similar to {@link dangerouslySetWebpackConfig} but for jest config. Make sure {@link setupTests} definitely doesn’t cover your needs before using.
112
+ * Similar to {@link dangerouslySetWebpackConfig}, but for Jest config. Make sure {@link setupTests} definitely doesn’t cover your needs before using.
113
113
  * Please speak with the `sku-support` group before using.
114
114
  *
115
115
  * @link https://seek-oss.github.io/sku/#/./docs/configuration?id=dangerouslysetjestconfig
116
116
  */
117
117
  dangerouslySetJestConfig?: (existingJestConfig: any) => any;
118
118
 
119
+ /**
120
+ * Similar to {@link dangerouslySetWebpackConfig}, but for TypeScript (`tsconfig.json`).
121
+ *
122
+ * @link https://seek-oss.github.io/sku/#/./docs/configuration?id=dangerouslysettsconfig
123
+ */
124
+ dangerouslySetTSConfig?: (existingTSConfig: any) => any;
125
+
119
126
  /**
120
127
  * This function provides a way to override the webpack config after sku has created it.
121
128
  * Ideally, this setting is not needed and only used for experimenting/debugging. If you require webpack features not currently supported by sku please speak to the `sku-support` group.
@@ -242,16 +249,6 @@ export interface SkuConfig {
242
249
  */
243
250
  persistentCache?: boolean;
244
251
 
245
- /**
246
- * Allows disabling Storybook's `storyStoreV7` feature flag. This will result in all stories being
247
- * loaded upfront instead of on demand. Disabling this feature will allow stories that use the
248
- * deprecated `storiesOf` API to work, however it's highly recommended to migrate off `storiesOf`
249
- * to the Component Story Format (CSF) instead.
250
- * @default true
251
- * @link https://seek-oss.github.io/sku/#/./docs/configuration?id=storybookStoryStore
252
- */
253
- storybookStoryStore?: boolean;
254
-
255
252
  /**
256
253
  * An array of polyfills to be included into all client entry points.
257
254
  *
@@ -405,6 +402,16 @@ export interface SkuConfig {
405
402
  */
406
403
  storybookPort?: number;
407
404
 
405
+ /**
406
+ * Allows disabling Storybook's `storyStoreV7` feature flag. This will result in all stories being
407
+ * loaded upfront instead of on demand. Disabling this feature will allow stories that use the
408
+ * deprecated `storiesOf` API to work, however it's highly recommended to migrate off `storiesOf`
409
+ * to the Component Story Format (CSF) instead.
410
+ * @default true
411
+ * @link https://seek-oss.github.io/sku/#/./docs/configuration?id=storybookStoryStore
412
+ */
413
+ storybookStoryStore?: boolean;
414
+
408
415
  /**
409
416
  * The directory `sku build-storybook` will output files to.
410
417
  *
@@ -2,7 +2,7 @@ import 'braid-design-system/reset';
2
2
 
3
3
  import { BraidProvider } from 'braid-design-system';
4
4
  import apac from 'braid-design-system/themes/apac';
5
- import React, { StrictMode } from 'react';
5
+ import { StrictMode } from 'react';
6
6
 
7
7
  import { NextSteps } from './NextSteps';
8
8
 
@@ -8,7 +8,6 @@ import {
8
8
  Stack,
9
9
  List,
10
10
  } from 'braid-design-system';
11
- import React from 'react';
12
11
 
13
12
  import * as styles from './NextSteps.css';
14
13
 
@@ -1,4 +1,3 @@
1
- import React from 'react';
2
1
  import { hydrateRoot } from 'react-dom/client';
3
2
 
4
3
  import App from './App/App';
@@ -1,9 +1,8 @@
1
- import React from 'react';
2
1
  import { renderToString } from 'react-dom/server';
3
2
  import type { Render } from 'sku';
4
3
 
5
4
  import App from './App/App';
6
- import { ClientContext } from './types';
5
+ import type { ClientContext } from './types';
7
6
 
8
7
  interface RenderContext {
9
8
  appHtml: string;
@@ -1,7 +0,0 @@
1
- /**
2
- * This is a placeholder file that provides for at least one TypeScript file in the project.
3
- *
4
- * Since all projects get a tsconfig.json now, having zero TS files would cause an error.
5
- *
6
- * Support for purely JS projects will be removed in a future major version, and this file can be removed.
7
- */