Skip to content

Commit

Permalink
feat(builtins): load min versions if available
Browse files Browse the repository at this point in the history
  • Loading branch information
martell committed Jul 17, 2018
1 parent 2e1ffc6 commit bf2843f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
18 changes: 3 additions & 15 deletions src/packagers/JSConcatPackager.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,15 @@
const Packager = require('./Packager');
const path = require('path');
const fs = require('fs');
const concat = require('../scope-hoisting/concat');
const urlJoin = require('../utils/urlJoin');
const getExisting = require('../utils/getExisting');
const walk = require('babylon-walk');
const babylon = require('babylon');
const t = require('babel-types');
const {getName, getIdentifier} = require('../scope-hoisting/utils');

const prelude = {
source: fs
.readFileSync(path.join(__dirname, '../builtins/prelude2.js'), 'utf8')
.trim(),
minified: fs
.readFileSync(path.join(__dirname, '../builtins/prelude2.min.js'), 'utf8')
.trim()
.replace(/;$/, '')
};

const helpers =
fs
.readFileSync(path.join(__dirname, '../builtins/helpers.js'), 'utf8')
.trim() + '\n';
const prelude = getExisting(path.join(__dirname, '../builtins/prelude2'));
const helpers = getExisting(path.join(__dirname, '../builtins/helpers'));

class JSConcatPackager extends Packager {
async start() {
Expand Down
12 changes: 2 additions & 10 deletions src/packagers/JSPackager.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
const fs = require('fs');
const path = require('path');
const Packager = require('./Packager');
const getExisting = require('../utils/getExisting');
const urlJoin = require('../utils/urlJoin');
const lineCounter = require('../utils/lineCounter');
const objectHash = require('../utils/objectHash');

const prelude = {
source: fs
.readFileSync(path.join(__dirname, '../builtins/prelude.js'), 'utf8')
.trim(),
minified: fs
.readFileSync(path.join(__dirname, '../builtins/prelude.min.js'), 'utf8')
.trim()
.replace(/;$/, '')
};
const prelude = getExisting(path.join(__dirname, '../builtins/prelude'));

class JSPackager extends Packager {
async start() {
Expand Down
21 changes: 21 additions & 0 deletions src/utils/getExisting.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const fs = require('fs');
/**
* Creates an object for source and a minified source
* e.g. builtins.min.js and builtins.js.
* If the first argument does not have an extension it will
* try use min.js and .js with .js as the minified fallback
*/
module.exports = function(minified, source) {
if(minified.split('.').length < 2 && source === undefined) {
source = minified + '.js';
minified = minified + 'min.js';
}
var sourceFile = fs.readFileSync(source, 'utf8').trim();
return {
source: sourceFile,
minified: fs.existsSync(minified) ? fs
.readFileSync(minified, 'utf8')
.trim()
.replace(/;$/, '') : sourceFile
}
};

0 comments on commit bf2843f

Please sign in to comment.