Skip to content

Commit

Permalink
Move src/shared/polyfills to src/boot/polyfills
Browse files Browse the repository at this point in the history
The code in `polyfills/index.js` which determines which polyfills are
needed are compiled as part of the boot script and not used by other
parts of the application.

Because this code is compiled as part of the boot script it needs to be
compiled to parse in older browsers, even those which don't support the client
(eg. IE 10/11). Putting the `polyfills/` dir in side `src/boot` means
that it will inherit any custom Babel configuration for the `src/boot`
directory.
  • Loading branch information
robertknight committed Oct 20, 2020
1 parent 0b12d7f commit 1dea77e
Show file tree
Hide file tree
Showing 13 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,16 @@ const appBundles = [
//
// To add a new polyfill:
// - Add the relevant dependencies to the project
// - Create an entry point in `src/shared/polyfills/{set}` and a feature
// detection function in `src/shared/polyfills/index.js`
// - Create an entry point in `src/boot/polyfills/{set}` and a feature
// detection function in `src/boot/polyfills/index.js`
// - Add the polyfill set name to the required dependencies for the parts of
// the client that need it in `src/boot/boot.js`
const polyfillBundles = readdirSync('./src/shared/polyfills/')
const polyfillBundles = readdirSync('./src/boot/polyfills/')
.filter(name => name.endsWith('.js') && name !== 'index.js')
.map(name => name.replace(/\.js$/, ''))
.map(set => ({
name: `polyfills-${set}`,
entry: `./src/shared/polyfills/${set}`,
entry: `./src/boot/polyfills/${set}`,
transforms: ['babel'],
}));

Expand Down
2 changes: 1 addition & 1 deletion src/boot/boot.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { requiredPolyfillSets } from '../shared/polyfills';
import { requiredPolyfillSets } from './polyfills';

/**
* Polyfills used by both the annotator and sidebar app.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ function stubOut(obj, property, replacement = undefined) {
};
}

describe('shared/polyfills/index', () => {
describe('boot/polyfills/index', () => {
describe('requiredPolyfillSets', () => {
let undoStub;

Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/boot/test/boot-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ describe('bootstrap', function () {
};

$imports.$mock({
'../shared/polyfills': fakePolyfills,
'./polyfills': fakePolyfills,
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/karma.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ module.exports = function (config) {
// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'./shared/polyfills/*.js': ['browserify'],
'./boot/polyfills/*.js': ['browserify'],
'./sidebar/test/bootstrap.js': ['browserify'],
'**/*-test.js': ['browserify'],
'**/*-it.js': ['browserify'],
Expand Down

0 comments on commit 1dea77e

Please sign in to comment.