Skip to content

Commit

Permalink
feat(ol): sort ol.ext entry point to the top if present
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Schmidt committed Jul 23, 2021
1 parent cde0812 commit d486529
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
16 changes: 16 additions & 0 deletions plugins/gcc/webpack-writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,21 @@ const closureWebpackInternalProps = [
'output_wrapper'
];

/**
* Entry point for the ol.ext provide. This file fixes a compiler issue and needs to be loaded first if present.
* @type {string}
*/
const olExtEntryPoint = 'goog:ol.ext';

/**
* Sort entry points. Brings the ol.ext entry point to the top of the list, and leaves remaining entry points in their
* original order.
* @param {string} a First entry point.
* @param {string} b Second entry point.
* @return {number} The sort order.
*/
const sortEntryPoints = (a, b) => a === olExtEntryPoint ? -1 : b === olExtEntryPoint ? 1 : 0;

/**
* Write support files for webpack.
* @param {Object} basePackage The base package.
Expand All @@ -40,6 +55,7 @@ const writer = function(basePackage, dir, options) {
if (entryPoints && entryPoints.length) {
const entryPoints = Array.isArray(options.entry_point) ? options.entry_point : [options.entry_point];
const indexContent = entryPoints
.sort(sortEntryPoints)
.map((ep) => `goog.require('${ep.replace(/^goog:/, '')}');`)
.join('\n');

Expand Down
16 changes: 16 additions & 0 deletions test/plugins/gcc/webpack-writer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,20 @@ describe('gcc webpack writer', function() {
expect(content).to.equal(expectedContent);
});
});

it('should sort ol.ext as the first entry point', function() {
var jsonOptions = {
entry_point: ['goog:ns1', 'goog:ol.ext', 'goog:ns2']
};

var expectedContent = `goog.require('ol.ext');\ngoog.require('ns1');\ngoog.require('ns2');`;

return webpack.writer(pack, outputDir, jsonOptions)
.then(() => {
return fs.readFileAsync(indexFile, 'utf-8');
})
.then((content) => {
expect(content).to.equal(expectedContent);
});
});
});

0 comments on commit d486529

Please sign in to comment.