Expose and use wrapped fs/path moduldes in Plugins

This commit is contained in:
Slava Kim
2015-07-23 12:31:55 -07:00
parent cfe29661fc
commit 173bfb7c03
7 changed files with 31 additions and 28 deletions

View File

@@ -1,5 +1,5 @@
const fs = Npm.require('fs');
const path = Npm.require('path');
const fs = Plugin.fs;
const path = Plugin.path;
const createHash = Npm.require('crypto').createHash;
const assert = Npm.require('assert');
const Future = Npm.require('fibers/future');
@@ -178,7 +178,7 @@ CachingCompilerBase = class CachingCompilerBase {
// doesn't exist.
_readFileOrNull(filename) {
try {
return fs.readFileSync(filename, 'utf8');
return fs.readFile(filename, 'utf8');
} catch (e) {
if (e && e.code === 'ENOENT')
return null;

View File

@@ -1,5 +1,4 @@
const fs = Npm.require('path');
const path = Npm.require('path');
const path = Plugin.path;
const Future = Npm.require('fibers/future');
const LRU = Npm.require('lru-cache');
const async = Npm.require('async');

View File

@@ -1,6 +1,5 @@
var util = Npm.require('util');
var Future = Npm.require('fibers/future');
var path = Npm.require('path');
var jshint = Npm.require('jshint').JSHINT;
Plugin.registerLinter({

View File

@@ -138,11 +138,6 @@ class MeteorImportLessFileManager extends less.AbstractFileManager {
resolvedFilename = path.join(currentDirectory, filename);
}
if (process.platform === 'win32') {
// convert the path back to standard path (backslashes to forward slashes)
resolvedFilename = resolvedFilename.replace(/\\/g, '/');
}
if (!this.allFiles.has(resolvedFilename)) {
cb({type: 'File', message: 'Unknown import: ' + filename});
return;

View File

@@ -1,8 +1,8 @@
const stylus = Npm.require('stylus');
const nib = Npm.require('nib');
const Future = Npm.require('fibers/future');
const fs = Npm.require('fs');
const path = Npm.require('path');
const fs = Plugin.fs;
const path = Plugin.path;
Plugin.registerCompiler({
extensions: ['styl'],
@@ -87,9 +87,8 @@ class StylusCompiler extends MultiFileCachingCompiler {
if (importPath[0] !== '{') {
// if it is not a custom syntax path, it could be a lookup in a folder
for (let i = paths.length - 1; i >= 0; i--) {
const joined = path.join(paths[i], importPath)
.replace(/\\/g, '/'); // XXX turn Windows paths back into standard path
if (fs.existsSync(joined))
const joined = path.join(paths[i], importPath);
if (fs.exists(joined))
return [joined];
}
}
@@ -103,18 +102,15 @@ class StylusCompiler extends MultiFileCachingCompiler {
return [absolutePath];
},
readFile(filePath) {
const isAbsolute = (process.platform === 'win32') ?
filePath[0].match(/^[A-Za-z]:\\/) : filePath[0] === '/';
const normalizedPath = (process.platform === 'win32') ?
filePath.replace(/\\/g, '/') : filePath;
const isAbsolute = filePath[0] === '/';
const isNib =
normalizedPath.indexOf('/node_modules/nib/lib/nib/') !== -1;
filePath.indexOf('/node_modules/nib/lib/nib/') !== -1;
const isStylusBuiltIn =
normalizedPath.indexOf('/node_modules/stylus/lib/') !== -1;
filePath.indexOf('/node_modules/stylus/lib/') !== -1;
if (isAbsolute || isNib || isStylusBuiltIn) {
// absolute path? let the default implementation handle this
return fs.readFileSync(filePath, 'utf8');
return fs.readFile(filePath, 'utf8');
}
const parsed = parseImportPath(filePath);

View File

@@ -814,7 +814,21 @@ _.extend(Isopack.prototype, {
nudge: function () {
Console.nudge(true);
}
},
convertToOSPath: files.convertToOSPath,
convertToStandardPath: files.convertToStandardPath,
path: {
join: files.pathJoin,
normalize: files.pathNormalize,
relative: files.pathRelative,
resolve: files.pathResolve,
dirname: files.pathDirname,
basename: files.pathBasename,
extname: files.pathExtname,
sep: files.pathSep
},
fs: files
};
return Plugin;
},

View File

@@ -1,5 +1,5 @@
var fs = Npm.require('fs');
var path = Npm.require('path');
var fs = Plugin.fs;
var path = Plugin.path;
Plugin.registerCompiler({
extensions: ['printme'],
@@ -25,14 +25,14 @@ PrintmeCompiler.prototype.processFilesForTarget = function (inputFiles) {
});
console.log("PrintmeCompiler invocation", ++self.runCount);
if (self.diskCache) {
fs.writeFileSync(self.diskCache, self.runCount + '\n');
fs.writeFile(self.diskCache, self.runCount + '\n');
}
};
PrintmeCompiler.prototype.setDiskCacheDirectory = function (diskCacheDir) {
var self = this;
self.diskCache = path.join(diskCacheDir, 'cache');
try {
var data = fs.readFileSync(self.diskCache, 'utf8');
var data = fs.readFile(self.diskCache, 'utf8');
} catch (e) {
if (e.code !== 'ENOENT')
throw e;