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

Commit

Permalink
match against deps patterns (#1451)
Browse files Browse the repository at this point in the history
* match against deps patterns

* fix travis
  • Loading branch information
shvaikalesh authored and paulmillr committed Jul 28, 2016
1 parent defe243 commit 97f0281
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 44 deletions.
7 changes: 4 additions & 3 deletions .travis.yml
Expand Up @@ -4,8 +4,9 @@ os:
- linux
- osx
node_js:
- '4'
- '5'
- '6'
- 4
- 5
- 6
before_install:
- npm install bower@^1 -g
- npm install npm@3 -g
35 changes: 17 additions & 18 deletions lib/fs_utils/file_list.js
Expand Up @@ -9,6 +9,7 @@ const formatError = require('../helpers').formatError;
const Asset = require('./asset');
const SourceFile = require('./source_file');
const BrunchError = require('../error');
const anymatch = require('anymatch');

const normalizePath = path => sysPath.slashes(path);

Expand Down Expand Up @@ -124,7 +125,7 @@ class FileList extends EventEmitter {
const files = isStatic ? this.staticFiles : this.files;
files.forEach((dependent, fpath) => {
const deps = dependent.dependencies;
const isDep = deps && deps.includes(path) && !this.compiled.has(fpath);
const isDep = anymatch(deps, path) && !this.compiled.has(fpath);
if (!isDep) return;
paths.push(fpath);
parents.push(dependent);
Expand All @@ -139,30 +140,28 @@ class FileList extends EventEmitter {
file.removed = false;
if (this.compiling.has(path)) {
this.resetTimer();
} else {
const reset = p => {
this.compiling.delete(path);
this.resetTimer();
return p;
};
this.compiling.add(path);
file.compile()
.then(reset, reset)
.then(() => {
debug(`Compiled ${path}`);
this.compiled.add(path);
this.emit('compiled', path);
});
return;
}
const reset = () => {
this.compiling.delete(path);
this.resetTimer();
};
this.compiling.add(path);
file.compile()
.then(reset, reset)
.then(() => {
debug(`Compiled ${path}`);
this.compiled.add(path);
this.emit('compiled', path);
});
}

copy(asset) {
const path = asset.path;
const resetCopy = p => {
if (this.disposed) return p;
const resetCopy = () => {
if (this.disposed) return;
this.copying.delete(path);
this.resetTimer();
return p;
};

this.copying.add(path);
Expand Down
4 changes: 3 additions & 1 deletion lib/fs_utils/pipeline.js
Expand Up @@ -37,7 +37,9 @@ const getDependencies = (file, compiler) => {
const name = compiler.constructor.name;
debug(`Fetching dependencies ${file.path} @ ${name}`);
return callPlugin(compiler, 'getDependencies', file)
.then(deps => deps.map(sysPath.normalize))
.then(deps => {
return deps.map(sysPath.normalize).concat(deps.patterns);
})
.catch(rethrow('Dependency parsing'));
};

Expand Down
23 changes: 11 additions & 12 deletions lib/watch.js
Expand Up @@ -55,17 +55,16 @@ const checkProjectDependencies = config => {
});
};

const MAX_JOBS = 32;
const setDefaultJobsCount = options => {
const envy = process.env.BRUNCH_JOBS;
if (!options.jobs && !envy) return;
if (options.jobs === true) options.jobs = undefined;
const setDefaultJobsCount = jobs => {
const MAX_JOBS = 32;
const env = process.env.BRUNCH_JOBS;
if (!jobs && !env || jobs === true) return;
// Mitigates Intel Hyperthreading.
const str = options.jobs || envy || cpus / 2;
const parsed = parseInt(str);
const jobs = isNaN(parsed) || parsed < 1 || parsed > MAX_JOBS ? 1 : parsed;
options.jobs = jobs;
return jobs;
const str = jobs || env || cpus / 2;
const int = Math.round(str);
return isNaN(int) ||
int < 1 ||
int > MAX_JOBS ? 1 : int;
};

/* persistent - Boolean: should brunch build the app only once or watch it?
Expand All @@ -85,7 +84,7 @@ class BrunchWatcher {
this._startTime = Date.now() - speed.sinceStart;
this._isFirstRun = true;
this._onReload = options._onReload;
setDefaultJobsCount(options);
options.jobs = setDefaultJobsCount(options.jobs);

application.loadConfig(persistent, options)
.then(cfg => {
Expand Down Expand Up @@ -138,7 +137,7 @@ class BrunchWatcher {
if (!this._startTime) return;
this.compile(this._endCompilation(), this.watcherIsReady);
})
.on('bundled', this._endBundle.bind(this));
.on('bundled', () => this._endBundle());

// Emit `change` event for each file that is included with plugins.
// Wish it worked like `watcher.add includes`.
Expand Down
10 changes: 4 additions & 6 deletions lib/workers/job-processor.js
Expand Up @@ -18,15 +18,13 @@ const CompileJob = require('../fs_utils/pipeline').CompileJob;

const jobs = {OptimizeJob, CompileJob};

const processMsg = msg => {
process.on('message', msg => {
const type = msg.type;
const data = msg.data;

const job = jobs[type];
const hash = job.deserialize({plugins}, data.hash);
return job.work(hash);
};

process.on('message', msg => {
processMsg(msg).then(result => process.send({result}), error => process.send({error: error.message}));
job.work(hash).then(result => process.send({result}),
error => process.send({error: error.message})
);
});
6 changes: 3 additions & 3 deletions lib/workers/manager.js
Expand Up @@ -37,7 +37,7 @@ class WorkerManager {
let num = options.jobs;
debug(`Spinning ${num} workers`);
while (num--) this.fork();
this._checker = setInterval(() => this.sendMessage(), 1);
this._checker = setInterval(() => this.sendMessage());
}

fork() {
Expand Down Expand Up @@ -88,12 +88,12 @@ class WorkerManager {
});
}

getFreeWorkerIdx() {
get freeWorkerIdx() {
return Object.keys(this.workers).find(idx => this.pending[idx] === false);
}

sendMessage() {
const workerIdx = this.getFreeWorkerIdx();
const workerIdx = this.freeWorkerIdx;
if (!workerIdx) return;
const job = this.jobs.dequeue();
if (!job) return;
Expand Down
2 changes: 1 addition & 1 deletion test/build.js
Expand Up @@ -388,7 +388,7 @@ test.serial.cb('npm integration', t => {
// finally, modules with .js in their name are correctly processed
contains('require.alias("bignumber.js/bignumber.js", "bignumber.js");');

outputContains(t, /compiled (180|181) files into app\.js/);
outputContains(t, /compiled (\d{3}) files into app\.js/);
noError(t);

t.end();
Expand Down

0 comments on commit 97f0281

Please sign in to comment.