mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
Fixes #506 - Fixed how compiler options are handled by the node-require hook
This commit is contained in:
parent
d6719f3ce4
commit
0f3de25560
@ -13,12 +13,12 @@ function normalizeExtension(extension) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function compile(templatePath, markoCompiler, compilerOptions) {
|
function compile(templatePath, markoCompiler, compilerOptions) {
|
||||||
|
|
||||||
if (compilerOptions) {
|
if (compilerOptions) {
|
||||||
compilerOptions = markoCompiler.defaultOptions;
|
|
||||||
} else {
|
|
||||||
compilerOptions = Object.assign({}, markoCompiler.defaultOptions, compilerOptions);
|
compilerOptions = Object.assign({}, markoCompiler.defaultOptions, compilerOptions);
|
||||||
|
} else {
|
||||||
|
compilerOptions = markoCompiler.defaultOptions;
|
||||||
}
|
}
|
||||||
|
|
||||||
var writeToDisk = compilerOptions.writeToDisk;
|
var writeToDisk = compilerOptions.writeToDisk;
|
||||||
|
|
||||||
var templateSrc;
|
var templateSrc;
|
||||||
@ -124,10 +124,7 @@ function install(options) {
|
|||||||
|
|
||||||
extensions.forEach((extension) => {
|
extensions.forEach((extension) => {
|
||||||
extension = normalizeExtension(extension);
|
extension = normalizeExtension(extension);
|
||||||
|
requireExtensions[extension] = markoRequireExtension;
|
||||||
if (!requireExtensions[extension]) {
|
|
||||||
requireExtensions[extension] = markoRequireExtension;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,3 +1,19 @@
|
|||||||
|
var expect = require('chai').expect;
|
||||||
|
var fs = require('fs');
|
||||||
|
|
||||||
|
function compileAndCheck(path, shouldWriteToDisk) {
|
||||||
|
var resolved = require.resolve(path);
|
||||||
|
var compiledFile = resolved + '.js';
|
||||||
|
|
||||||
|
try {
|
||||||
|
fs.unlinkSync(compiledFile);
|
||||||
|
} catch(e) {}
|
||||||
|
|
||||||
|
require(resolved);
|
||||||
|
|
||||||
|
expect(fs.existsSync(compiledFile)).to.equal(shouldWriteToDisk);
|
||||||
|
}
|
||||||
|
|
||||||
exports.check = function(marko, markoCompiler, expect, done) {
|
exports.check = function(marko, markoCompiler, expect, done) {
|
||||||
markoCompiler.configure({
|
markoCompiler.configure({
|
||||||
writeToDisk: true,
|
writeToDisk: true,
|
||||||
@ -7,6 +23,8 @@ exports.check = function(marko, markoCompiler, expect, done) {
|
|||||||
expect(markoCompiler.config.writeToDisk).to.equal(true);
|
expect(markoCompiler.config.writeToDisk).to.equal(true);
|
||||||
expect(markoCompiler.config.preserveWhitespace).to.equal(true);
|
expect(markoCompiler.config.preserveWhitespace).to.equal(true);
|
||||||
|
|
||||||
|
compileAndCheck('./a.marko', true /* should write to disk */);
|
||||||
|
|
||||||
require('marko/node-require').install({
|
require('marko/node-require').install({
|
||||||
compilerOptions: {
|
compilerOptions: {
|
||||||
writeToDisk: false,
|
writeToDisk: false,
|
||||||
@ -17,8 +35,41 @@ exports.check = function(marko, markoCompiler, expect, done) {
|
|||||||
expect(markoCompiler.config.writeToDisk).to.equal(false);
|
expect(markoCompiler.config.writeToDisk).to.equal(false);
|
||||||
expect(markoCompiler.config.preserveWhitespace).to.equal(false);
|
expect(markoCompiler.config.preserveWhitespace).to.equal(false);
|
||||||
|
|
||||||
|
markoCompiler.configure({
|
||||||
|
writeToDisk: true,
|
||||||
|
preserveWhitespace: true
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(markoCompiler.config.writeToDisk).to.equal(true);
|
||||||
|
expect(markoCompiler.config.preserveWhitespace).to.equal(true);
|
||||||
|
|
||||||
|
compileAndCheck('./b.marko', false /* should write to disk */);
|
||||||
|
|
||||||
markoCompiler.configure(); // Reset to defaults
|
markoCompiler.configure(); // Reset to defaults
|
||||||
expect(markoCompiler.config.writeToDisk).to.equal(true);
|
expect(markoCompiler.config.writeToDisk).to.equal(true);
|
||||||
expect(markoCompiler.config.preserveWhitespace).to.equal(false);
|
expect(markoCompiler.config.preserveWhitespace).to.equal(false);
|
||||||
|
|
||||||
|
require('marko/node-require').install({
|
||||||
|
compilerOptions: {
|
||||||
|
writeToDisk: true,
|
||||||
|
preserveWhitespace: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
compileAndCheck('./c.marko', true /* should write to disk */);
|
||||||
|
|
||||||
|
require('marko/node-require').install({
|
||||||
|
compilerOptions: {
|
||||||
|
preserveWhitespace: false
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
markoCompiler.configure({
|
||||||
|
writeToDisk: false,
|
||||||
|
preserveWhitespace: true
|
||||||
|
});
|
||||||
|
|
||||||
|
compileAndCheck('./d.marko', false /* should write to disk */);
|
||||||
|
|
||||||
done();
|
done();
|
||||||
};
|
};
|
||||||
@ -4,6 +4,10 @@ var fs = require('fs');
|
|||||||
exports.check = function(marko, markoCompiler, expect, done) {
|
exports.check = function(marko, markoCompiler, expect, done) {
|
||||||
var compiledPath;
|
var compiledPath;
|
||||||
|
|
||||||
|
require('marko/compiler').configure({
|
||||||
|
writeToDisk: true
|
||||||
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
var templatePath = nodePath.join(__dirname, 'template.marko');
|
var templatePath = nodePath.join(__dirname, 'template.marko');
|
||||||
compiledPath = nodePath.join(__dirname, 'template.marko.js');
|
compiledPath = nodePath.join(__dirname, 'template.marko.js');
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user