Implement inputFile.readAndWatchFile.

This only works for files contained within the source root of the current
app or package.
This commit is contained in:
Ben Newman
2016-05-20 12:51:59 -04:00
parent 49a60f155b
commit c19f4ead0d

View File

@@ -8,7 +8,7 @@ var linker = require('./linker.js');
var util = require('util');
var _ = require('underscore');
var Profile = require('../tool-env/profile.js').Profile;
import {sha1} from '../fs/watch.js';
import {sha1, readAndWatchFile} from '../fs/watch.js';
import LRU from 'lru-cache';
import Fiber from 'fibers';
import {sourceMapLength} from '../utils/utils.js';
@@ -256,6 +256,19 @@ class InputFile extends buildPluginModule.InputFile {
return self._resourceSlot.inputResource.fileOptions || {};
}
readAndWatchFile(path) {
const sourceRoot = this.getSourceRoot();
const relPath = files.pathRelative(sourceRoot, path);
if (relPath.startsWith("..")) {
throw new Error(
`Attempting to read file outside ${
this.getPackageName() || "the app"}: ${path}`
);
}
const sourceBatch = this._resourceSlot.packageSourceBatch;
return readAndWatchFile(sourceBatch.unibuild.watchSet, path);
}
// Search ancestor directories for control files (e.g. package.json,
// .babelrc), and return the absolute path of the first one found, or
// null if the search failed.