src/loader.js
// `require` function, used in vterm and by external plugins
`require` function, used in vterm and by external plugins
` require ` function used in vterm and by external plugins
load(module, { cache, requireCache } = {}) {
    const {
      cached,
      isCustom,
      setUseCache
    } = this
     NOTE: The interal cache is still enabled
    if(!requireCache) {
      const _path = window.require.resolve(module)
      delete window.require.cache[_path]
    }
     `__cache` is the value of cache before changing
     it for this particular request
    const __cache   = this.cache
     Set the cache JUST FOR THIS REQUEST
     Resetting in before resolving/rejecting
    if(typeof cache == 'boolean') setUseCache(cache)
    return new Promise((resolve, reject) => {
      try {
         Load the module with
         the native require function
        const _module = window.require(module)
         If the user enable the cache,
         Store the `_module` value inside of
         our cache, and it will be avaible
         for future use
         IMPORTANT:
         We only cache the module if
         it's not a custom one!!
        if(cache && !isCustom(module))
           Then let's cache it
          cached[module] = _module
         Reverting the cache value
         back to the original one
        setUseCache(__cache)
         If veverything went OK
         let's resolve the promise
        resolve(_module)
      } catch (err) {
         Reverting the cache value
         back to the original one
        setUseCache(__cache)
         Reject with the error
        reject(err)
      }
    })
  }
load ( module , { cache , requireCache } = { } ) { const { cached , isCustom , setUseCache } = this if ( ! requireCache ) { const _path = window . require . resolve ( module ) delete window . require . cache [ _path ] } const __cache = this . cache if ( typeof cache == 'boolean' ) setUseCache ( cache ) return new Promise ( ( resolve , reject ) => { try { const _module = window . require ( module ) if ( cache && ! isCustom ( module ) ) cached [ module ] = _module setUseCache ( __cache ) resolve ( _module ) } catch ( err ) { setUseCache ( __cache ) reject ( err ) } } ) }
`require` function, used in vterm and by external plugins
` require ` function used in vterm and by external plugins
// If the user disables the commonjs' cache // we reove that module from the cache array // // NOTE: The interal cache is still enabled // `__cache` is the value of cache before changing // it for this particular request // Set the cache JUST FOR THIS REQUEST // Resetting in before resolving/rejecting // Load the module with // the native require function // If the user enable the cache, // Store the `_module` value inside of // our cache, and it will be avaible // for future use // // IMPORTANT: // We only cache the module if // it's not a custom one!! // Then let's cache it // Reverting the cache value // back to the original one // If veverything went OK // let's resolve the promise // Reverting the cache value // back to the original one // Reject with the error