Skip to content
This repository has been archived by the owner on Sep 6, 2022. It is now read-only.

Commit

Permalink
Fix file caching
Browse files Browse the repository at this point in the history
One of the main advantage of the new build plugin API introduced in
Meteor 1.2 was the possibility to define "incremental compilers" that
relies on caching to accelerate the build process.

Unfortunately 7734099 didn't implement this new caching mechanism
correctly, this commit should make it work.

The documentation for CachingCompiler is available at:

  https://github.com/meteor/meteor/tree/devel/packages/caching-compiler
  • Loading branch information
mquandalle committed Dec 25, 2015
1 parent 3b6114c commit 274d625
Showing 1 changed file with 23 additions and 11 deletions.
34 changes: 23 additions & 11 deletions packages/jade/plugin/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ class JadeCompilerPlugin extends CachingCompiler {
}

compileOneFile(file) {
const ext = file.getExtension();

try {
const handlerMode = (ext === 'jade') ? 'file' : 'template';
this[`_${handlerMode}ModeHandler`](file);
return this._getCompilerResult(file);
} catch (err) {
file.error({
message: "Jade syntax error: " + err.message
Expand All @@ -31,6 +28,24 @@ class JadeCompilerPlugin extends CachingCompiler {
return [ inputFile.getSourceHash() ];
}

addCompileResult(inputFile, compileResult) {
const fileMode = this._getMode(inputFile);
this[`_${fileMode}ModeHandler`](inputFile, compileResult);
}

compileResultSize(compileResult) {
function lengthOrZero(field) {
return field ? field.length : 0;
}
return lengthOrZero(compileResult.head) + lengthOrZero(compileResult.body) +
lengthOrZero(compileResult.templates);
}

_getMode(file) {
const ext = file.getExtension();
return (ext === 'jade') ? 'file' : 'template';
}

// XXX Handle body attributes
_bodyGen(tpl, attrs) {
const renderFunction = SpacebarsCompiler.codeGen(tpl, {
Expand Down Expand Up @@ -60,11 +75,11 @@ class JadeCompilerPlugin extends CachingCompiler {
`;
}

_getCompilerResult(file, fileMode) {
_getCompilerResult(file) {
try {
return JadeCompiler.parse(file.getContentsAsString(), {
filename: file.getPathInPackage(),
fileMode: fileMode
fileMode: this._getMode(file) === 'file'
});
} catch (err) {
return file.error({
Expand All @@ -74,9 +89,7 @@ class JadeCompilerPlugin extends CachingCompiler {
}
}

_fileModeHandler(file) {
const results = this._getCompilerResult(file, true);

_fileModeHandler(file, results) {
// Head
if (results.head !== null) {
file.addHtml({
Expand All @@ -102,8 +115,7 @@ class JadeCompilerPlugin extends CachingCompiler {
}
}

_templateModeHandler(file) {
const result = this._getCompilerResult(file, false);
_templateModeHandler(file, result) {
const templateName = path.basename(file.getPathInPackage(), '.tpl.jade');
let jsContent;

Expand Down

0 comments on commit 274d625

Please sign in to comment.