Skip to content

Commit

Permalink
Automatically detect compile packages with @Seek scope (#541)
Browse files Browse the repository at this point in the history
  • Loading branch information
mattcompiles committed Oct 18, 2020
1 parent d36d559 commit 590c889
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
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

0 comments on commit 590c889

Please sign in to comment.