Comparing version 2.5.1 to 2.5.2
@@ -6,3 +6,3 @@ 'use strict'; | ||
var __getOwnPropNames=Object.getOwnPropertyNames;var __require=(x=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(x,{get:(a,b)=>(typeof require<"u"?require:a)[b]}):x)(function(x){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+x+'" is not supported')});var __commonJS=(cb,mod)=>function(){return mod||(0, cb[__getOwnPropNames(cb)[0]])((mod={exports:{}}).exports,mod),mod.exports};var require_src=__commonJS({"src/index.ts"(exports,module){var fs=__require("fs"),path=__require("path"),selfReloadError="Do not attempt to re-require Heatsync. If you REALLY want to, do it yourself with require.cache and deal with possibly ticking timers and event listeners, but don't complain if something breaks :(";function isObject(item){var _a;return typeof item!="object"||item===null||Array.isArray(item)?!1:((_a=item.constructor)==null?void 0:_a.name)==="Object"}var Sync=class{constructor(options){this.events=new events.EventEmitter;this._listeners=new Map;this._timers=new Map;this._references=new Map;this._watchers=new Map;this._options={},(options==null?void 0:options.watchFS)===void 0?this._options.watchFS=!0:this._options.watchFS=options.watchFS??!1,(options==null?void 0:options.persistentWatchers)===void 0?this._options.persistentWatchers=!0:this._options.persistentWatchers=options.persistentWatchers??!1;}require(id,_from){let from;if(from=_from??backtracker.getStack().first().dir,Array.isArray(id))return id.map(item=>this.require(item,from));let directory=path.isAbsolute(id)?__require.resolve(id):__require.resolve(path.join(from,id));if(directory===__filename)throw new Error(selfReloadError);let value=__require(directory);if(!isObject(value))throw new Error(`${directory} does not export an Object and as such, changes made to the file cannot be reflected as the value would be immutable. Importing through HeatSync isn't supported and may be erraneous`);let oldObject=this._references.get(directory);if(oldObject){for(let key of Object.keys(oldObject))value[key]||delete oldObject[key];Object.assign(oldObject,value);}else if(this._references.set(directory,value),this._options.watchFS){let timer=null;this._watchers.set(directory,fs.watch(directory,{persistent:this._options.persistentWatchers},()=>{timer&&(clearTimeout(timer),timer=null),timer=setTimeout(()=>{delete __require.cache[directory];try{this.require(directory);}catch(e){return this.events.emit("error",e)}this.events.emit(directory),this.events.emit("any",directory);let listeners=this._listeners.get(directory);if(listeners)for(let[target,event,func]of listeners)target.removeListener(event,func);let timers=this._timers.get(directory);if(timers)for(let[type,timer2]of timers)type==="timeout"?clearTimeout(timer2):clearInterval(timer2);},1e3).unref();}));}let ref=this._references.get(directory);return ref||value}import(_id,_from){throw new Error("The CJS version of this module does not support the import statement")}addTemporaryListener(target,event,callback,method="on"){let first=backtracker.getStack().first(),absolute=path.normalize(first.absolute);return this._listeners.get(absolute)||this._listeners.set(absolute,[]),this._listeners.get(absolute).push([target,event,callback]),setImmediate(()=>target[method](event,callback)),target}addTemporaryTimeout(callback,ms,...args){let first=backtracker.getStack().first(),absolute=path.normalize(`${first.dir}/${first.absolute}`);this._timers.get(absolute)||this._timers.set(absolute,[]);let timer=setTimeout(callback,ms,...args);return this._timers.get(absolute).push(["timeout",timer]),timer}addTemporaryInterval(callback,ms,...args){let first=backtracker.getStack().first(),absolute=path.normalize(`${first.dir}/${first.absolute}`);this._timers.get(absolute)||this._timers.set(absolute,[]);let timer=setInterval(callback,ms,...args);return this._timers.get(absolute).push(["interval",timer]),timer}resync(id,_from){let from;if(typeof id=="string"&&!id.startsWith(".")?from=__require.resolve(id):from=_from??backtracker.getStack().first().dir,Array.isArray(id))return id.map(item=>this.resync(item,from));let directory=path.isAbsolute(id)?__require.resolve(id):__require.resolve(path.join(from,id));if(directory===__filename)throw new Error(selfReloadError);return delete __require.cache[directory],this.require(directory)}};module.exports=Sync;}});var index = require_src(); | ||
var __getOwnPropNames=Object.getOwnPropertyNames;var __require=(x=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(x,{get:(a,b)=>(typeof require<"u"?require:a)[b]}):x)(function(x){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+x+'" is not supported')});var __commonJS=(cb,mod)=>function(){return mod||(0, cb[__getOwnPropNames(cb)[0]])((mod={exports:{}}).exports,mod),mod.exports};var require_src=__commonJS({"src/index.ts"(exports,module){var fs=__require("fs"),path=__require("path"),selfReloadError="Do not attempt to re-require Heatsync. If you REALLY want to, do it yourself with require.cache and deal with possibly ticking timers and event listeners, but don't complain if something breaks :(";function isObject(item){var _a;return typeof item!="object"||item===null||Array.isArray(item)?!1:((_a=item.constructor)==null?void 0:_a.name)==="Object"}var Sync=class{constructor(options){this.events=new events.EventEmitter;this._listeners=new Map;this._timers=new Map;this._references=new Map;this._watchers=new Map;this._options={},(options==null?void 0:options.watchFS)===void 0?this._options.watchFS=!0:this._options.watchFS=options.watchFS??!1,(options==null?void 0:options.persistentWatchers)===void 0?this._options.persistentWatchers=!0:this._options.persistentWatchers=options.persistentWatchers??!1;}require(id,_from){let from;if(from=_from??backtracker.getStack().first().dir,Array.isArray(id))return id.map(item=>this.require(item,from));let directory=path.isAbsolute(id)?__require.resolve(id):__require.resolve(path.join(from,id));if(directory===__filename)throw new Error(selfReloadError);let value=__require(directory);if(!isObject(value))throw new Error(`${directory} does not export an Object and as such, changes made to the file cannot be reflected as the value would be immutable. Importing through HeatSync isn't supported and may be erraneous`);let oldObject=this._references.get(directory);if(oldObject){for(let key of Object.keys(oldObject))value[key]||delete oldObject[key];Object.assign(oldObject,value);}else if(this._references.set(directory,value),this._options.watchFS){let timer=null;this._watchers.set(directory,fs.watch(directory,{persistent:this._options.persistentWatchers},()=>{timer&&(clearTimeout(timer),timer=null),timer=setTimeout(()=>{delete __require.cache[directory];try{this.require(directory);}catch(e){return this.events.emit("error",e)}this.events.emit(directory),this.events.emit("any",directory);let listeners=this._listeners.get(directory);if(listeners)for(let[target,event,func]of listeners)target.removeListener(event,func);let timers=this._timers.get(directory);if(timers)for(let[type,timer2]of timers)type==="timeout"?clearTimeout(timer2):clearInterval(timer2);},1e3).unref();}));}let ref=this._references.get(directory);return ref||value}import(_id,_from){throw new Error("The CJS version of this module does not support the import statement")}addTemporaryListener(target,event,callback,method="on"){let first=backtracker.getStack().first(),absolute=path.normalize(first.absolute);return this._listeners.get(absolute)||this._listeners.set(absolute,[]),this._listeners.get(absolute).push([target,event,callback]),setImmediate(()=>target[method](event,callback)),target}addTemporaryTimeout(callback,ms,...args){let first=backtracker.getStack().first(),absolute=path.normalize(first.absolute);this._timers.get(absolute)||this._timers.set(absolute,[]);let timer=setTimeout(callback,ms,...args);return this._timers.get(absolute).push(["timeout",timer]),timer}addTemporaryInterval(callback,ms,...args){let first=backtracker.getStack().first(),absolute=path.normalize(first.absolute);this._timers.get(absolute)||this._timers.set(absolute,[]);let timer=setInterval(callback,ms,...args);return this._timers.get(absolute).push(["interval",timer]),timer}resync(id,_from){let from;if(typeof id=="string"&&!id.startsWith(".")?from=__require.resolve(id):from=_from??backtracker.getStack().first().dir,Array.isArray(id))return id.map(item=>this.resync(item,from));let directory=path.isAbsolute(id)?__require.resolve(id):__require.resolve(path.join(from,id));if(directory===__filename)throw new Error(selfReloadError);return delete __require.cache[directory],this.require(directory)}};module.exports=Sync;}});var index = require_src(); | ||
@@ -9,0 +9,0 @@ module.exports = index; |
{ | ||
"name": "heatsync", | ||
"version": "2.5.1", | ||
"version": "2.5.2", | ||
"description": "A module to watch and reload CommonJS Modules on modification and sync results with objects", | ||
@@ -20,5 +20,5 @@ "types": "./dist/index.d.ts", | ||
"devDependencies": { | ||
"@types/node": "20.11.25", | ||
"@types/node": "20.12.7", | ||
"tsup": "^8.0.2", | ||
"typescript": "^5.4.2" | ||
"typescript": "^5.4.5" | ||
}, | ||
@@ -25,0 +25,0 @@ "files": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
32273
308