Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically detect compile packages with @seek scope #541

Merged
merged 4 commits into from Oct 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/loud-balloons-dream.md
@@ -0,0 +1,5 @@
---
'sku': patch
---

Automatically detect compile packages with @seek scope
31 changes: 31 additions & 0 deletions context/defaultCompilePackages.js
@@ -1,6 +1,37 @@
const path = require('path');
const chalk = require('chalk');
const glob = require('fast-glob');

const { cwd } = require('../lib/cwd');

let detectedCompilePackages = [];

try {
detectedCompilePackages = glob
.sync([`node_modules/@seek/*/package.json`], {
cwd: cwd(),
})
.map((packagePath) => {
const packageJson = require(path.join(cwd(), packagePath));

return {
isCompilePackage: Boolean(packageJson.skuCompilePackage),
packageName: packageJson.name,
};
})
.filter(({ isCompilePackage }) => isCompilePackage)
.map(({ packageName }) => packageName);
} catch (e) {
console.log(
chalk.red`Warning: Failed to detect compile packages. Contact #sku-support.`,
);
console.error(e);
}

module.exports = [
'sku',
'seek-style-guide',
'seek-asia-style-guide',
'braid-design-system',
...detectedCompilePackages,
];
15 changes: 13 additions & 2 deletions docs/docs/extra-features.md
Expand Up @@ -13,15 +13,26 @@ Source maps are enabled by default when running the `sku start` command. However

## 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 this toolkit provides. A great example of this is [seek-style-guide](https://github.com/seek-oss/seek-style-guide). Out of the box sku supports loading the seek-style-guide but if you need to treat other packages in 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. 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`.

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.

```json
{
"name": "@seek/my-package",
"skuCompilePackage": true
}
```

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

```js
module.exports = {
compilePackages: ['awesome-shared-components'],
};
```

Any `node_modules` passed into this option will be compiled through webpack as if they are part of your app.
Any `node_modules` marked as a `compilePackage` will be compiled through webpack as if they are part of your app.

## Polyfills

Expand Down