UNPKG

waffle

Version:

シンプルなWEBアプリケーションフレームワークです。(ALL YOUR NODE ARE BELONG TO US)

62 lines (53 loc) 1.59 kB
/* * Copyright 2012 Katsunori Koyanagi * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ /** * @overview システムレベルのフックです。 */ "use strict"; require("./utils/patch"); var fs = require("fs"); var FSWatcher = require("./utils/FSWatcher"); var log = require("./utils/Log"); var Module = module.constructor; if (Module.__patched__) { return; } Module.__patched__ = true; var watcher = new FSWatcher(); var load0 = Module.prototype.load; var lib = __dirname; function clearCache(filename) { delete require.cache[filename]; } function add(filename) { if (filename.indexOf(lib) !== 0) { log("file loaded(%s)", filename); watcher.add(filename); } } watcher.on("change", function(filename) { log("file changed(%s)", filename); clearCache(filename); }); watcher.on("remove", function(filename) { log("file removed(%s)", filename); clearCache(filename); }); Module.prototype.load = function(filename) { var result = load0.call(this, filename); add(filename); return result; };