diff --git a/.changeset/loud-balloons-dream.md b/.changeset/loud-balloons-dream.md new file mode 100644 index 000000000..11ea8f96c --- /dev/null +++ b/.changeset/loud-balloons-dream.md @@ -0,0 +1,5 @@ +--- +'sku': patch +--- + +Automatically detect compile packages with @seek scope diff --git a/context/defaultCompilePackages.js b/context/defaultCompilePackages.js index 4cffc428d..aee9dba1f 100644 --- a/context/defaultCompilePackages.js +++ b/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, ]; diff --git a/docs/docs/extra-features.md b/docs/docs/extra-features.md index 33e8f3600..1df2c8c87 100644 --- a/docs/docs/extra-features.md +++ b/docs/docs/extra-features.md @@ -13,7 +13,18 @@ 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 = { @@ -21,7 +32,7 @@ module.exports = { }; ``` -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