diff --git a/tools/isobuild/compiler-plugin.js b/tools/isobuild/compiler-plugin.js index 9cb974611c..4e510dbdf0 100644 --- a/tools/isobuild/compiler-plugin.js +++ b/tools/isobuild/compiler-plugin.js @@ -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.