Skip to content

Commit 03e586b

Browse files
authored
Merge pull request #88 from schmidtk/feat-sort-ol-ext
feat(ol): sort ol.ext entry point to the top if present
2 parents cde0812 + d486529 commit 03e586b

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

plugins/gcc/webpack-writer.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,21 @@ const closureWebpackInternalProps = [
1919
'output_wrapper'
2020
];
2121

22+
/**
23+
* Entry point for the ol.ext provide. This file fixes a compiler issue and needs to be loaded first if present.
24+
* @type {string}
25+
*/
26+
const olExtEntryPoint = 'goog:ol.ext';
27+
28+
/**
29+
* Sort entry points. Brings the ol.ext entry point to the top of the list, and leaves remaining entry points in their
30+
* original order.
31+
* @param {string} a First entry point.
32+
* @param {string} b Second entry point.
33+
* @return {number} The sort order.
34+
*/
35+
const sortEntryPoints = (a, b) => a === olExtEntryPoint ? -1 : b === olExtEntryPoint ? 1 : 0;
36+
2237
/**
2338
* Write support files for webpack.
2439
* @param {Object} basePackage The base package.
@@ -40,6 +55,7 @@ const writer = function(basePackage, dir, options) {
4055
if (entryPoints && entryPoints.length) {
4156
const entryPoints = Array.isArray(options.entry_point) ? options.entry_point : [options.entry_point];
4257
const indexContent = entryPoints
58+
.sort(sortEntryPoints)
4359
.map((ep) => `goog.require('${ep.replace(/^goog:/, '')}');`)
4460
.join('\n');
4561

test/plugins/gcc/webpack-writer.test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,20 @@ describe('gcc webpack writer', function() {
114114
expect(content).to.equal(expectedContent);
115115
});
116116
});
117+
118+
it('should sort ol.ext as the first entry point', function() {
119+
var jsonOptions = {
120+
entry_point: ['goog:ns1', 'goog:ol.ext', 'goog:ns2']
121+
};
122+
123+
var expectedContent = `goog.require('ol.ext');\ngoog.require('ns1');\ngoog.require('ns2');`;
124+
125+
return webpack.writer(pack, outputDir, jsonOptions)
126+
.then(() => {
127+
return fs.readFileAsync(indexFile, 'utf-8');
128+
})
129+
.then((content) => {
130+
expect(content).to.equal(expectedContent);
131+
});
132+
});
117133
});

0 commit comments

Comments
 (0)