Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
Move jobs to separate file w less deps, reduce worker mem consumption.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Feb 3, 2017
1 parent b3001db commit a50c8a8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 33 deletions.
31 changes: 1 addition & 30 deletions lib/fs_utils/generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const flatten = helpers.flatten;
const promiseReduce = helpers.promiseReduce;
const formatOptimizerError = helpers.formatOptimizerError;
const processJob = require('../workers').processJob;
const OptimizeJob = require('../workers/jobs').OptimizeJob;
const hmr = require('../utils/hmr'); // isEnabled, generate
const BrunchError = require('../utils/error');

Expand Down Expand Up @@ -125,36 +126,6 @@ const concat = (files, path, definitionFn, autoRequire, config) => {
return root.toStringWithSourceMap({file: path});
};

const OptimizeJob = {
path: 'OptimizeJob',

serialize(hash) {
const optimizer = hash.optimizer.brunchPluginName;
const params = hash.params;
return {optimizer, params: {data: params.data, map: params.map, path: params.path}};
},

deserialize(ctx, hash) {
const optimizer = ctx.plugins.optimizers.find(p => p.brunchPluginName === hash.optimizer);

const deserializeSourceMap = serializedMap => {
return SourceMapGenerator.fromSourceMap(new SourceMapConsumer(serializedMap));
};

const params = hash.params;
params.map = deserializeSourceMap(params.map);

return {optimizer, params};
},

work(hash) {
const optimizer = hash.optimizer;
const file = hash.params;

return optimizer.optimize(file);
},
};

const prepareSourceMap = (optimizedMap, sourceFiles) => {
if (optimizedMap == null) return;
const map = SourceMapGenerator.fromSourceMap(new SourceMapConsumer(optimizedMap));
Expand Down
4 changes: 1 addition & 3 deletions lib/workers/job-processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ loadConfigWorker(false, options).then(_cfg => {
});
});

const OptimizeJob = require('../fs_utils/generate').OptimizeJob;

const jobs = {OptimizeJob};
const jobs = require('./jobs');

process.on('message', msg => {
const type = msg.type;
Expand Down
36 changes: 36 additions & 0 deletions lib/workers/jobs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const smap = require('source-map');
const SourceMapConsumer = smap.SourceMapConsumer;
const SourceMapGenerator = smap.SourceMapGenerator;
const SourceNode = smap.SourceNode;

const OptimizeJob = {
path: 'OptimizeJob',

serialize(hash) {
const optimizer = hash.optimizer.brunchPluginName;
const params = hash.params;
return {optimizer, params: {data: params.data, map: params.map, path: params.path}};
},

deserialize(ctx, hash) {
const optimizer = ctx.plugins.optimizers.find(p => p.brunchPluginName === hash.optimizer);

const deserializeSourceMap = serializedMap => {
return SourceMapGenerator.fromSourceMap(new SourceMapConsumer(serializedMap));
};

const params = hash.params;
params.map = deserializeSourceMap(params.map);

return {optimizer, params};
},

work(hash) {
const optimizer = hash.optimizer;
const file = hash.params;

return optimizer.optimize(file);
},
};

exports.OptimizeJob = OptimizeJob;

0 comments on commit a50c8a8

Please sign in to comment.