Skip to content

Commit

Permalink
Don't install husky anymore, update docs for husky v8 (#804)
Browse files Browse the repository at this point in the history
Co-authored-by: Remus Mate <rmate@seek.com.au>
  • Loading branch information
askoufis and mrm007 committed May 26, 2023
1 parent 8a31be0 commit 7de96d0
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 23 deletions.
12 changes: 12 additions & 0 deletions .changeset/nine-paws-unite.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
'sku': major
---

`sku init` no longer installs and configures husky for you

BREAKING CHANGE

`sku init` no longer adds `husky` as a dependecy nor does it configure husky for you out of the box.
For instructions on how to set up `husky` to use sku's pre-commit hook, see [the docs].

[the docs]: https://seek-oss.github.io/sku/#/./docs/extra-features?id=pre-commit-hook
47 changes: 30 additions & 17 deletions docs/docs/extra-features.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@ If you want to use a currently unsupported format feel free to submit a PR or co

## Source maps

Source maps are enabled by default when running the `sku start` command. However, if you want to generate source maps when running `sku build`, you can do so by enabling [`sourceMapsProd`](./docs/configuration#sourcemapsprod).
Source maps are enabled by default when running the `sku start` command.
However, if you want to generate source maps when running `sku build`, you can do so by enabling [`sourceMapsProd`](./docs/configuration#sourcemapsprod).

## Compile packages

Sometimes you might want to extract and share code between sku projects, but this code is likely to rely on the same tooling and language features that sku provides. A great example of this is [braid](https://github.com/seek-oss/braid-design-system). Out of the box, sku supports loading braid but if you need to treat other packages this way you can use `compilePackages`.
Sometimes you might want to extract and share code between sku projects, but this code is likely to rely on the same tooling and language features that sku provides.
sku supports loading packages as if they were part of your app via the `compilePackages` feature.

The best way to configure a package as a `compilePackage`, is to set `"skuCompilePackage": true` in the **packages** `package.json`. This method only works for `@seek` scoped packages.
The best way to configure a package as a `compilePackage` is to set `"skuCompilePackage": true` in the **package's** `package.json`.
This method only works for `@seek` scoped packages.

```json
{
Expand All @@ -24,7 +27,7 @@ The best way to configure a package as a `compilePackage`, is to set `"skuCompil
}
```

Alternatively, you can add any packages you like to the `compilePackages` option in the **consuming app** sku config file.
Alternatively, you can add any packages you like to the `compilePackages` option in the **consuming app's** sku config file.

```js
module.exports = {
Expand Down Expand Up @@ -55,23 +58,31 @@ module.exports = {

`sku` comes with bundle analysis built in via [webpack-bundle-analyzer](https://www.npmjs.com/package/webpack-bundle-analyzer). A report is generated in the `/report` directory when `sku build` is run.

## Pre-commit hooks
## Pre-commit hook

To speed up the feedback loop on linting and formatting errors, `sku` provides a `pre-commit` script that can be run to catch simple problems before CI. To make use of this, it's recommended that you install [husky](https://www.npmjs.com/package/husky) as a development dependency and configure it in `package.json` as follows:
To speed up the feedback loop on linting and formatting errors, `sku` provides a `pre-commit` script that can be run to catch simple problems before CI.
To make use of this hook, it's recommended to install [husky](https://www.npmjs.com/package/husky) as a development dependency and configure it as follows:

```js
```json
// package.json

"husky": {
"hooks": {
"pre-commit": "sku pre-commit"
{
"scripts": {
"prepare": "husky install"
}
},
}
```

```sh
yarn husky add .husky/pre-commit "yarn sku pre-commit"
```

For more details on configuring hooks, please see husky's [documentation](https://typicode.github.io/husky/#create-a-hook).

## Assertion removal

If you use [Node's `assert` library](https://nodejs.org/api/assert.html) or its [browser port](https://www.npmjs.com/package/assert), your assertions will be automatically removed in production via [`babel-plugin-unassert`](https://github.com/unassert-js/babel-plugin-unassert). This allows you to perform more expensive checks during development without worrying about the perfomance impacts on users.
If you use [Node's `assert` library](https://nodejs.org/api/assert.html) or its [browser port](https://www.npmjs.com/package/assert), your assertions will be automatically removed in production via [`babel-plugin-unassert`](https://github.com/unassert-js/babel-plugin-unassert).
This allows you to perform more expensive checks during development without worrying about the perfomance impacts on users.

For example, let's assume you wrote the following code:

Expand All @@ -96,16 +107,18 @@ export const Rating = ({ rating }) => <div>...</div>;

## DevServer Middleware

Supply a `devServerMiddleware` path in your sku config to access the internal dev Express server.
Supply a `devServerMiddleware` path in your sku config to access the internal dev [Express] server.

The file must export a function that will receive the express server.

Example:

```js
module.exports = app => {
module.exports = (app) => {
app.get('/mock-api', (req, res) => {
...
})
}
// ...
});
};
```

[express]: http://expressjs.com/
6 changes: 0 additions & 6 deletions packages/sku/scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,6 @@ const getTemplateFileDestinationFromRoot =
lint: 'sku lint',
format: 'sku format',
},
husky: {
hooks: {
'pre-commit': 'sku pre-commit',
},
},
};
const packageJsonString = JSON.stringify(packageJson, null, 2);

Expand Down Expand Up @@ -202,7 +197,6 @@ const getTemplateFileDestinationFromRoot =

const devDeps = [
'@vanilla-extract/css',
'husky',
'sku',
'@types/react',
'@types/react-dom',
Expand Down

0 comments on commit 7de96d0

Please sign in to comment.