Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions packages/react-scripts/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"env": {
"jest": true
}
}
2 changes: 1 addition & 1 deletion packages/react-scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ npm start
- **`css.html` & `js.html`**: New files in the `build/` output folder. These are html partials that include `<script />` and `<link />` references to the various static assets output by webpack. Useful if automatic chunking is turned on and you don't want to worry about order.
- A bunch of configuration options via `"backpack-react-scripts"` field in `package.json`:
- `crossOriginLoading`: Modify the default behaviour, see [docs](https://webpack.js.org/configuration/output/#output-crossoriginloading).
- `babelIncludePrefixes`: An array of module name prefixes to opt into babel compilation. Includes `["@skyscanner/bpk-", "bpk-", "saddlebag-"]` by default.
- `babelIncludePrefixes`: An array of module name prefixes to opt into babel compilation, including local import module, e.g. `"../common"`. Includes `["@skyscanner/bpk-", "bpk-", "saddlebag-"]` by default.
- `enableAutomaticChunking`: Boolean, opt in to automatic chunking of vendor, common and app code.
- `vendorsChunkRegex`: String, Regex for picking what goes into the `vendors` chunk. See `cacheGroups` in webpack docs. Dependent on `enableAutomaticChunking` being enabled
- `amdExcludes`: Array of module names to exclude from AMD parsing. Incldues `["lodash"]` by default.
Expand Down
2 changes: 1 addition & 1 deletion packages/react-scripts/backpack-addons/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Our react scripts fork includes a number of custom configuration items in order

| Feature | Description | Default Value |
|:---|:--|:---|
| **babelIncludePrefixes** | Array of module name prefixes to opt into babel compilation. <br> Default includes **@skyscanner/bpk-, bpk- and saddlebag-** packages by default to be compiled | **[@skyscanner/bpk-, bpk- and saddlebag-]** |
| **babelIncludePrefixes** | Array of module name prefixes to opt into babel compilation, including local import module, e.g. `"../common"`. <br> Default includes **@skyscanner/bpk-, bpk- and saddlebag-** packages by default to be compiled | **[@skyscanner/bpk-, bpk- and saddlebag-]** |
| **sriEnabled** | Determines if Subresource Intergrity is used during build to add an integrity hash for files. <br> The SRI is a security feature to enable browsers to verify the files they fetch are unmodified. <br> If enabled crossOriginLoading value is overriden with anonymous to allow output to have integrity value <br> See [webpack subresource integrity docs](https://github.com/waysact/webpack-subresource-integrity/blob/master/README.md) | **false** (this is currently the default in the future security may want to make it true by default but pending them still trying things about) |
| **crossOriginLoading** | Option to enable cross origin loading of chunks to modify the default webpack behaviour of being false. <br> Docs: https://webpack.js.org/configuration/output/#outputcrossoriginloading | **false** |
| **ignoreCssWarnings** | Provides the ablity to supress CSS ordering warnings when its safe and ordering is not of a concern on the output <br> See [mini css extract plugin docs](https://github.com/webpack-contrib/mini-css-extract-plugin#remove-order-warnings) | **false** - by default we should care about order as it can sometimes have an output impact |
Expand Down
12 changes: 9 additions & 3 deletions packages/react-scripts/backpack-addons/babelIncludePrefixes.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
"use strict";

const paths = require("../config/paths");
const path = require('path');
const appPackageJson = require(paths.appPackageJson);
const bpkReactScriptsConfig = appPackageJson["backpack-react-scripts"] || {};
const customModuleRegexes = bpkReactScriptsConfig.babelIncludePrefixes
? bpkReactScriptsConfig.babelIncludePrefixes.map(
(prefix) => new RegExp(`node_modules[\\/]${prefix}`)
)
? bpkReactScriptsConfig.babelIncludePrefixes.map(prefix => {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are we able to add unit tests for this at all?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a good idea, added.
but seems BRS is lacking unit tests and there is no process in the pipeline to run the unit test automatically(I couldn’t find it if I don’t miss something), in this case, seems adding unit tests for this change doesn’t make much sense. Seems the test facility in BRS is not fully equipped, what do you think 🤔️

if (prefix && /^(\.|\/)/.test(prefix)) {
// if the prefixes starts with '.' or '/', e.g. '../common' './common' '/common'
// That means it is a relative path which doesn't need to be in the node_modules folder
return path.resolve(paths.appPath, prefix);
}
return new RegExp(`node_modules[\\/]${prefix}`);
})
: [];

// Backpack / saddlebag node module regexes
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
'use strict';
const getBabelIncludePrefixes = require('../backpack-addons/babelIncludePrefixes');

jest.mock('../config/paths', () => ({
appSrc: '/Users/xxx/backpack-react-scripts/client/src',
appPackageJson: './test/mockPackage.json',
appPath: '/Users/xxx/backpack-react-scripts/client',
}));

describe('babelIncludePrefixes', () => {
test('should handler babelIncludePrefixes correctly', () => {
const babelIncludePrefixes = getBabelIncludePrefixes();

expect(babelIncludePrefixes).toEqual([
'/Users/xxx/backpack-react-scripts/client/src',
/node_modules[\\/]bpk-/,
/node_modules[\\/]saddlebag-/,
/node_modules[\\/]@skyscanner[\\/]bpk-/,
/node_modules[\\/]@skyscanner[\\/]backpack-web/,
new RegExp('node_modules[\\/]@skyscanner'),
'/Users/xxx/backpack-react-scripts/client/common',
'/Users/xxx/backpack-react-scripts/common',
'/server',
]);
});
});
7 changes: 7 additions & 0 deletions packages/react-scripts/backpack-addons/test/mockPackage.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "test",
"version": "1.0.0",
"backpack-react-scripts": {
"babelIncludePrefixes": ["@skyscanner", "./common", "../common", "/server"]
}
}