From 1d3002df9bc6f6c18cff56b37a19c60a3814f179 Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Fri, 16 Oct 2020 12:53:13 +1100 Subject: [PATCH 1/4] Automatically detect compile packages with @seek scope --- .changeset/loud-balloons-dream.md | 5 +++++ context/defaultCompilePackages.js | 21 +++++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 .changeset/loud-balloons-dream.md 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..8cb302774 100644 --- a/context/defaultCompilePackages.js +++ b/context/defaultCompilePackages.js @@ -1,6 +1,27 @@ +const path = require('path'); +const glob = require('fast-glob'); + +const { cwd } = require('../lib/cwd'); + +const 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); + module.exports = [ 'sku', 'seek-style-guide', 'seek-asia-style-guide', 'braid-design-system', + ...detectedCompilePackages, ]; From 5b6e1caf8e1cd98282aba0954f39898abff6a3d2 Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Mon, 19 Oct 2020 09:47:55 +1100 Subject: [PATCH 2/4] Improved error handling --- context/defaultCompilePackages.js | 36 ++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/context/defaultCompilePackages.js b/context/defaultCompilePackages.js index 8cb302774..aee9dba1f 100644 --- a/context/defaultCompilePackages.js +++ b/context/defaultCompilePackages.js @@ -1,22 +1,32 @@ const path = require('path'); +const chalk = require('chalk'); const glob = require('fast-glob'); const { cwd } = require('../lib/cwd'); -const detectedCompilePackages = glob - .sync([`node_modules/@seek/*/package.json`], { - cwd: cwd(), - }) - .map((packagePath) => { - const packageJson = require(path.join(cwd(), packagePath)); +let detectedCompilePackages = []; - return { - isCompilePackage: Boolean(packageJson.skuCompilePackage), - packageName: packageJson.name, - }; - }) - .filter(({ isCompilePackage }) => isCompilePackage) - .map(({ packageName }) => packageName); +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', From 1b15529ad9d5d632fb8f8ad670df083b3110fa80 Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Mon, 19 Oct 2020 10:14:52 +1100 Subject: [PATCH 3/4] Update docs --- docs/docs/extra-features.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/docs/extra-features.md b/docs/docs/extra-features.md index 33e8f3600..a34290d49 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 **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 From d301aefb1ba1d5ddd6044c908f80aa9d10711eb2 Mon Sep 17 00:00:00 2001 From: Matt Jones Date: Mon, 19 Oct 2020 10:27:24 +1100 Subject: [PATCH 4/4] Typo --- docs/docs/extra-features.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/extra-features.md b/docs/docs/extra-features.md index a34290d49..1df2c8c87 100644 --- a/docs/docs/extra-features.md +++ b/docs/docs/extra-features.md @@ -24,7 +24,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 **consuming app** sku config file. +Alternatively, you can add any packages you like to the `compilePackages` option in the **consuming app** sku config file. ```js module.exports = {