Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions build/jslib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ define(function (require) {
//Caching function for performance. Attached to
//require so it can be reused in requirePatch.js. _cachedRawText
//set up by requirePatch.js
require._cacheReadAsync = function (path, encoding) {
require._cacheReadAsync = function (path, encoding, moduleName, context) {
var d;

if (lang.hasProp(require._cachedRawText, path)) {
d = prim();
d.resolve(require._cachedRawText[path]);
return d.promise;
} else {
return file.readFileAsync(path, encoding).then(function (text) {
return file.readFileAsync(path, encoding, moduleName, context).then(function (text) {
require._cachedRawText[path] = text;
return text;
});
Expand Down
18 changes: 14 additions & 4 deletions build/jslib/node/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,15 +204,25 @@ define(['fs', 'path', 'prim'], function (fs, path, prim) {
/**
* Reads a *text* file.
*/
readFile: function (/*String*/path, /*String?*/encoding) {
readFile: function (/*String*/path, /*String?*/encoding, /*String?*/moduleName, /*String?*/context) {
if (encoding === 'utf-8') {
encoding = 'utf8';
}
if (!encoding) {
encoding = 'utf8';
}

var text = fs.readFileSync(path, encoding);
var text;

try {
text = fs.readFileSync(path, encoding);
} catch(e) {
if(context && context.config && context.config.onReadFileError) {
text = context.config.onReadFileError(moduleName, path);
} else {
throw e;
}
}

//Hmm, would not expect to get A BOM, but it seems to happen,
//remove it just in case.
Expand All @@ -223,10 +233,10 @@ define(['fs', 'path', 'prim'], function (fs, path, prim) {
return text;
},

readFileAsync: function (path, encoding) {
readFileAsync: function (path, encoding, moduleName, context) {
var d = prim();
try {
d.resolve(file.readFile(path, encoding));
d.resolve(file.readFile(path, encoding, moduleName, context));
} catch (e) {
d.reject(e);
}
Expand Down
2 changes: 1 addition & 1 deletion build/jslib/requirePatch.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ define([ 'env!env/file', 'pragma', 'parse', 'lang', 'logger', 'commonJs', 'prim'
} else {
//Load the file contents, process for conditionals, then
//evaluate it.
return require._cacheReadAsync(url).then(function (text) {
return require._cacheReadAsync(url, null, moduleName, context).then(function (text) {
contents = text;

if (context.config.cjsTranslate &&
Expand Down