mirror of
https://github.com/marko-js/marko.git
synced 2025-12-08 19:26:05 +00:00
#3 Template writing to disk should be atomic
This commit is contained in:
parent
8f171379bb
commit
09da9c82b8
@ -21,6 +21,7 @@ function loadSource(templatePath, compiledSrc) {
|
||||
|
||||
module.exports = function load(templatePath) {
|
||||
templatePath = nodePath.resolve(cwd, templatePath);
|
||||
var targetDir = nodePath.dirname(templatePath);
|
||||
|
||||
var targetFile = templatePath + '.js';
|
||||
var compiler = markoCompiler.createCompiler(templatePath);
|
||||
@ -34,7 +35,10 @@ module.exports = function load(templatePath) {
|
||||
|
||||
// console.log('Compiled code for "' + templatePath + '":\n' + compiledSrc);
|
||||
|
||||
fs.writeFileSync(targetFile, compiledSrc, {encoding: 'utf8'});
|
||||
var filename = nodePath.basename(targetFile);
|
||||
var tempFile = nodePath.join(targetDir, '.' + process.pid + '.' + Date.now() + '.' + filename);
|
||||
fs.writeFileSync(tempFile, compiledSrc, {encoding: 'utf8'});
|
||||
fs.renameSync(tempFile, targetFile);
|
||||
|
||||
return require(targetFile);
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user