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;AAED,QAAK,EAAE,CAAA;GACP;;;AAGD,UAAQ,CAAC;UAAM,gBAAG,UAAU,CAAC,OAAK,mBAAmB,CAAC;GAAA,EAAE,IAAI,CAAC,CAAA;;;AAG7D,SAAO,IAAI,CAAA;EACX;;QAjbmB,wBAAwB;;;qBAAxB,wBAAwB","file":"index.js","sourcesContent":["import path from 'path'\r\nimport fs from 'fs'\r\n\r\nimport require_hacker from 'require-hacker'\r\nimport Log from './tools/log'\r\n\r\nimport { exists, clone, convert_from_camel_case, starts_with } from './helpers'\r\nimport { default_webpack_assets, normalize_options, alias } from './common'\r\n\r\n// using ES6 template strings\r\n// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings\r\nexport default class webpack_isomorphic_tools\r\n{\r\n\t// require() hooks for assets\r\n\thooks = []\r\n\r\n\t// used to keep track of cached assets and flush their caches on .refresh() call\r\n\tcached_assets = []\r\n\r\n\tconstructor(options)\r\n\t{\r\n\t\t// take the passed in options\r\n\t\tthis.options = convert_from_camel_case(clone(options))\r\n\r\n\t\t// add missing fields, etc\r\n\t\tnormalize_options(this.options)\r\n\r\n\t\t// if Webpack aliases are supplied, enable aliasing\r\n\t\tif (this.options.alias)\r\n\t\t{\r\n\t\t\tthis.enable_aliasing()\r\n\t\t}\r\n\r\n\t\t// logging\r\n\t\tthis.log = new Log('webpack-isomorphic-tools', { debug: this.options.debug })\r\n\r\n\t\tthis.log.debug('instantiated webpack-isomorphic-tools with options', this.options)\r\n\t}\r\n\r\n\t// sets development mode flag to whatever was passed (or true if nothing was passed)\r\n\t// (development mode allows asset hot reloading when used with webpack-dev-server)\r\n\tdevelopment(flag)\r\n\t{\r\n\t\t// set development mode flag\r\n\t\tthis.options.development = exists(flag) ? flag : true\r\n\r\n\t\tif (this.options.development)\r\n\t\t{\r\n\t\t\tthis.log.debug('entering development mode')\r\n\t\t}\r\n\t\telse\r\n\t\t{\r\n\t\t\tthis.log.debug('entering production mode')\r\n\t\t}\r\n\r\n\t\t// allows method chaining\r\n\t\treturn this\r\n\t}\r\n\r\n\t// returns a mapping to read file paths for all the user specified asset types\r\n\t// along with a couple of predefined ones: javascripts and styles\r\n\tassets()\r\n\t{\r\n\t\t// when in development mode\r\n\t\tif (this.options.development)\r\n\t\t{\r\n\t\t\t// webpack and node.js start in parallel\r\n\t\t\t// so webpack-assets.json might not exist on the very first run\r\n\t\t\t// if a developer chose not to use the .server() method with a callback\r\n\t\t\t// (or if a developer chose not to wait for a Promise returned by the .server() method)\r\n\t\t\tif (!fs.existsSync(this.webpack_assets_path))\r\n\t\t\t{\r\n\t\t\t\tthis.log.error(`\"${this.webpack_assets_path}\" not found. Most likely it hasn't yet been generated by Webpack. Using an empty stub instead.`)\r\n\t\t\t\treturn default_webpack_assets()\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\treturn require(this.webpack_assets_path)\r\n\t}\r\n\r\n\t// clear the require.cache (only used in developer mode with webpack-dev-server)\r\n\trefresh()\r\n\t{\r\n\t\t// ensure this is development mode\r\n\t\tif (!this.options.development)\r\n\t\t{\r\n\t\t\tthrow new Error('.refresh() called in production mode. Did you forget to call .development() method on your webpack-isomorphic-tools server instance?')\r\n\t\t}\r\n\r\n\t\tthis.log.debug('flushing require() caches')\r\n\r\n\t\t// uncache webpack-assets.json file\r\n\t\t// this.log.debug(' flushing require() cache for webpack assets json file')\r\n\t\t// this.log.debug(` (was cached: ${typeof(require.cache[this.webpack_assets_path]) !== 'undefined'})`)\r\n\t\tdelete require.cache[this.webpack_assets_path]\r\n\r\n\t\t// uncache cached assets\r\n\t\tfor (let path of this.cached_assets)\r\n\t\t{\r\n\t\t\tthis.log.debug(` flushing require() cache for ${path}`)\r\n\t\t\tdelete require.cache[path]\r\n\t\t}\r\n\r\n\t\t// no assets are cached now\r\n\t\tthis.cached_assets = []\r\n\t}\r\n\r\n\t// Makes `webpack-isomorphic-tools` aware of Webpack aliasing feature.\r\n\t// https://webpack.github.io/docs/resolving.html#aliasing\r\n\t// The `aliases` parameter corresponds to `resolve.alias` \r\n\t// in your Webpack configuration. \r\n\t// If this method is used it must be called before the `.server()` method.\r\n\tenable_aliasing()\r\n\t{\r\n\t\t// mount require() hook\r\n\t\tthis.alias_hook = require_hacker.global_hook('aliasing', path =>\r\n\t\t{\r\n\t\t\t// alias the path\r\n\t\t\tconst aliased_path = alias(path, this.options.alias)\r\n\r\n\t\t\t// if an alias is found, require() the correct path\r\n\t\t\tif (aliased_path)\r\n\t\t\t{\r\n\t\t\t\tconst result = require(aliased_path)\r\n\t\t\t\treturn require_hacker.to_javascript_module_source(result)\r\n\t\t\t}\r\n\t\t},\r\n\t\t{ precede_node_loader: true })\r\n\r\n\t\t// allows method chaining\r\n\t\treturn this\r\n\t}\r\n\r\n\t// Initializes server-side instance of `webpack-isomorphic-tools` \r\n\t// with the base path for your project, then calls `.register()`,\r\n\t// and after that calls .wait_for_assets(callback).\r\n\t//\r\n\t// The `project_path` parameter must be identical \r\n\t// to the `context` parameter of your Webpack configuration \r\n\t// and is needed to locate `webpack-assets.json` \r\n\t// which is output by Webpack process. \r\n\t//\r\n\t// sets up \"project_path\" option\r\n\t// (this option is required on the server to locate webpack-assets.json)\r\n\tserver(project_path, callback)\r\n\t{\r\n\t\t// project base path, required to locate webpack-assets.json\r\n\t\tthis.options.project_path = project_path\r\n\r\n\t\t// resolve webpack-assets.json file path\r\n\t\tthis.webpack_assets_path = path.resolve(this.options.project_path, this.options.webpack_assets_file_path)\r\n\r\n\t\t// register require() hooks\r\n\t\tthis.register()\r\n\r\n\t\t// when ready: \r\n\r\n\t\t// if callback is given, call it back\r\n\t\tif (callback)\r\n\t\t{\r\n\t\t\t// call back when ready\r\n\t\t\treturn this.wait_for_assets(callback)\r\n\t\t}\r\n\t\t// otherwise resolve a Promise\r\n\t\telse\r\n\t\t{\r\n\t\t\t// no callback given, return a Promise\r\n\t\t\treturn new Promise((resolve, reject) => this.wait_for_assets(resolve))\r\n\t\t}\r\n\t}\r\n\r\n\t// Registers Node.js require() hooks for the assets\r\n\t//\r\n\t// This is what makes the `requre()` magic work on server. \r\n\t// These `require()` hooks must be set before you `require()` \r\n\t// any of your assets \r\n\t// (e.g. before you `require()` any React components \r\n\t// `require()`ing your assets).\r\n\t//\r\n\t// read this article if you don't know what a \"require hook\" is\r\n\t// http://bahmutov.calepin.co/hooking-into-node-loader-for-fun-and-profit.html\r\n\tregister()\r\n\t{\r\n\t\tthis.log.debug('registering require() hooks for assets')\r\n\r\n\t\t// for each user specified asset type,\r\n\t\t// register a require() hook for each file extension of this asset type\r\n\t\tfor (let asset_type of Object.keys(this.options.assets))\r\n\t\t{\r\n\t\t\tconst description = this.options.assets[asset_type]\r\n\t\t\t\r\n\t\t\tfor (let extension of description.extensions)\r\n\t\t\t{\r\n\t\t\t\tthis.register_extension(extension, description)\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// allows method chaining\r\n\t\treturn this\r\n\t}\r\n\r\n\t// registers a require hook for a particular file extension\r\n\tregister_extension(extension, description)\r\n\t{\r\n\t\tthis.log.debug(` registering a require() hook for *.${extension}`)\r\n\r\n\t\t// place the require() hook for this extension\r\n\t\tthis.hooks.push(require_hacker.hook(extension, path => this.require(path, description)))\r\n\t}\r\n\r\n\t// require()s an asset by a path\r\n\trequire(global_asset_path, description)\r\n\t{\r\n\t\tthis.log.debug(`require() called for ${global_asset_path}`)\r\n\r\n\t\t// sanity check\r\n\t\t/* istanbul ignore if */\r\n\t\tif (!this.options.project_path)\r\n\t\t{\r\n\t\t\tthrow new Error(`You forgot to call the .server() method passing it your project's base path`)\r\n\t\t}\r\n\r\n\t\t// // if the require()d file is not part of the project - skip it\r\n\t\t// // (should be faster, but who needs faster if the modules are cached by Node.js)\r\n\t\t// if (!global_asset_path.indexOf(this.options.project_path) === 0)\r\n\t\t// {\r\n\t\t// \tthis.log.debug(` skipping require call for ${asset_path} (not in project folder)`)\r\n\t\t// \treturn\r\n\t\t// }\r\n\r\n\t\t// // asset path relative to the project folder\r\n\t\t// // (should be faster, but who needs faster if the modules are cached by Node.js)\r\n\t\t// let asset_path = global_asset_path.slice(this.options.project_path.length + fs.sep.length)\r\n\r\n\t\t// asset path relative to the project folder\r\n\t\tlet asset_path = path.relative(this.options.project_path, global_asset_path)\r\n\r\n\t\t// for Windows:\r\n\t\t//\r\n\t\t// convert Node.js path to a correct Webpack path\r\n\t\tasset_path = asset_path.replace(/\\\\/g, '/')\r\n\t\t// add './' in the beginning if it's missing (for example, in case of Windows)\r\n\t\tif (asset_path.indexOf('.') !== 0)\r\n\t\t{\r\n\t\t\tasset_path = './' + asset_path\r\n\t\t}\r\n\r\n\t\t// if this filename is in the user specified exceptions list\r\n\t\t// (or is not in the user explicitly specified inclusion list)\r\n\t\t// then fall back to the normal require() behaviour\r\n\t\tif (!this.includes(asset_path, description) || this.excludes(asset_path, description))\r\n\t\t{\r\n\t\t\tthis.log.debug(` skipping require call for ${asset_path}`)\r\n\t\t\treturn\r\n\t\t}\r\n\r\n\t\t// track cached assets (only in development mode)\r\n\t\tif (this.options.development)\r\n\t\t{\r\n\t\t\t// mark this asset as cached\r\n\t\t\tthis.cached_assets.push(global_asset_path)\r\n\t\t}\r\n\r\n\t\t// webpack has a shortcut from \"node_modules\"\r\n\t\tif (asset_path.indexOf('./node_modules/') === 0)\r\n\t\t{\r\n\t\t\tasset_path = asset_path.replace('./node_modules/', './~/')\r\n\t\t}\r\n\t\t\r\n\t\t// return CommonJS module source for this asset\r\n\t\treturn require_hacker.to_javascript_module_source(this.asset_source(asset_path))\r\n\t}\r\n\r\n\t// returns asset source by path (looks it up in webpack-assets.json)\r\n\tasset_source(asset_path)\r\n\t{\r\n\t\tthis.log.debug(` requiring ${asset_path}`)\r\n\r\n\t\t// sanity check\r\n\t\t/* istanbul ignore if */\r\n\t\tif (!asset_path)\r\n\t\t{\r\n\t\t\treturn undefined\r\n\t\t}\r\n\r\n\t\t// get real file path list\r\n\t\tvar assets = this.assets().assets\r\n\t\t\r\n\t\t// find this asset in the real file path list\r\n\t\tconst asset = assets[asset_path]\r\n\t\t\r\n\t\t// if the asset was found in the list - return it\r\n\t\tif (exists(asset))\r\n\t\t{\r\n\t\t\treturn asset\r\n\t\t}\r\n\r\n\t\t// serve a not-found asset maybe\r\n\t\tthis.log.error(`asset not found: ${asset_path}`)\r\n\t\treturn undefined\r\n\t}\r\n\r\n\t// unregisters require() hooks\r\n\tundo()\r\n\t{\r\n\t\t// for each user specified asset type,\r\n\t\t// unregister a require() hook for each file extension of this asset type\r\n\t\tfor (let hook of this.hooks)\r\n\t\t{\r\n\t\t\thook.unmount()\r\n\t\t}\r\n\r\n\t\t// unmount the aliasing hook (if mounted)\r\n\t\tif (this.alias_hook)\r\n\t\t{\r\n\t\t\tthis.alias_hook.unmount()\r\n\t\t}\r\n\t}\r\n\r\n\t// Checks if the required path should be excluded from the custom require() hook\r\n\texcludes(path, options)\r\n\t{\r\n\t\t// if \"exclude\" parameter isn't specified, then exclude nothing\r\n\t\tif (!exists(options.exclude))\r\n\t\t{\r\n\t\t\treturn false\r\n\t\t}\r\n\r\n\t\t// for each exclusion case\r\n\t\tfor (let exclude of options.exclude)\r\n\t\t{\r\n\t\t\t// supports regular expressions\r\n\t\t\tif (exclude instanceof RegExp)\r\n\t\t\t{\r\n\t\t\t\tif (exclude.test(path))\r\n\t\t\t\t{\r\n\t\t\t\t\treturn true\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t// check for a compex logic match\r\n\t\t\telse if (typeof exclude === 'function')\r\n\t\t\t{\r\n\t\t\t\tif (exclude(path))\r\n\t\t\t\t{\r\n\t\t\t\t\treturn true\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t// otherwise check for a simple textual match\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (exclude === path)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn true\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// no matches found.\r\n\t\t// returns false so that it isn't undefined (for testing purpose)\r\n\t\treturn false\r\n\t}\r\n\r\n\t// Checks if the required path should be included in the custom require() hook\r\n\tincludes(path, options)\r\n\t{\r\n\t\t// if \"include\" parameter isn't specified, then include everything\r\n\t\tif (!exists(options.include))\r\n\t\t{\r\n\t\t\treturn true\r\n\t\t}\r\n\r\n\t\t// for each inclusion case\r\n\t\tfor (let include of options.include)\r\n\t\t{\r\n\t\t\t// supports regular expressions\r\n\t\t\tif (include instanceof RegExp)\r\n\t\t\t{\r\n\t\t\t\tif (include.test(path))\r\n\t\t\t\t{\r\n\t\t\t\t\treturn true\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t// check for a compex logic match\r\n\t\t\telse if (typeof include === 'function')\r\n\t\t\t{\r\n\t\t\t\tif (include(path))\r\n\t\t\t\t{\r\n\t\t\t\t\treturn true\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t\t// otherwise check for a simple textual match\r\n\t\t\telse\r\n\t\t\t{\r\n\t\t\t\tif (include === path)\r\n\t\t\t\t{\r\n\t\t\t\t\treturn true\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\r\n\t\t// no matches found.\r\n\t\t// returns false so that it isn't undefined (for testing purpose)\r\n\t\treturn false\r\n\t}\r\n\r\n\t// Waits for webpack-assets.json to be created after Webpack build process finishes\r\n\t//\r\n\t// The callback is called when `webpack-assets.json` has been found \r\n\t// (it's needed for development because `webpack-dev-server` \r\n\t// and your application server are usually run in parallel).\r\n\t//\r\n\twait_for_assets(done)\r\n\t{\r\n\t\t// condition check interval\r\n\t\tconst interval = 300 // in milliseconds\r\n\r\n\t\t// selfie\r\n\t\tconst tools = this\r\n\r\n\t\t// waits for condition to be met, then proceeds\r\n\t\tfunction wait_for(condition, proceed)\r\n\t\t{\r\n\t\t\tfunction check()\r\n\t\t\t{\r\n\t\t\t\t// if the condition is met, then proceed\r\n\t\t\t\tif (condition())\r\n\t\t\t\t{\r\n\t\t\t\t\treturn proceed()\r\n\t\t\t\t}\r\n\r\n\t\t\t\ttools.log.debug(`(${tools.webpack_assets_path} not found)`)\r\n\t\t\t\ttools.log.info('(waiting for the first Webpack build to finish)')\r\n\r\n\t\t\t\tsetTimeout(check, interval)\r\n\t\t\t}\r\n\r\n\t\t\tcheck()\r\n\t\t}\r\n\r\n\t\t// wait for webpack-assets.json to be written to disk by Webpack\r\n\t\twait_for(() => fs.existsSync(this.webpack_assets_path), done)\r\n\r\n\t\t// allows method chaining\r\n\t\treturn this\r\n\t}\r\n}"]}
\No newline at end of file