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zKuB,WAAW,CAyKtB,IAAI,EAAE,GAAG,CAAC,IAAI,SAzKH,WAAW,CAyKI,IAAI,EAAE,GAAG,CAAC,EACpD;AACC,SAAM;EACN;;;AAGD,KAAM,WAAW,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;AACrC,KAAM,WAAW,GAAG,WAAW,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,EAAE,WAAW,CAAC,GAAG,IAAI,CAAA;AAC5E,KAAM,IAAI,GAAG,WAAW,IAAI,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,GAAG,EAAE,CAAA;;;AAGhE,KAAM,KAAK,GAAG,OAAO,CAAC,WAAW,CAAC,CAAA;;;AAGlC,KAAI,KAAK,EACT;AACC,SAAO,KAAK,GAAG,IAAI,CAAA;EACnB;CACD","file":"common.js","sourcesContent":["import path from 'path'\r\n\r\nimport { is_object, exists, starts_with } from './helpers'\r\n\r\n// returns a stub for webpack-assets.json if it doesn't exist yet\r\n// (because node.js and webpack are being run in parallel in development mode)\r\nexport function default_webpack_assets()\r\n{\r\n\tconst webpack_assets = \r\n\t{\r\n\t\tjavascript: {},\r\n\t\tstyles: {},\r\n\t\tassets: {}\r\n\t}\r\n\r\n\treturn webpack_assets\r\n}\r\n\r\n// adds missing fields, etc\r\nexport function normalize_options(options)\r\n{\r\n\t// parameters check\r\n\tfor (let key of Object.keys(options))\r\n\t{\r\n\t\tswitch (key)\r\n\t\t{\r\n\t\t\tcase 'assets':\r\n\t\t\t\tif (!is_object(options[key]))\r\n\t\t\t\t{\r\n\t\t\t\t\tthrow new Error(`\"${key}\" configuration parameter must be ` + `an object`)\r\n\t\t\t\t}\r\n\t\t\t\tbreak\r\n\r\n\t\t\tcase 'debug':\r\n\t\t\t\tif (typeof options[key] !== 'boolean')\r\n\t\t\t\t{\r\n\t\t\t\t\tthrow new Error(`\"${key}\" configuration parameter must be ` + `a boolean`)\r\n\t\t\t\t}\r\n\t\t\t\tbreak\r\n\r\n\t\t\tcase 'webpack_assets_file_path':\r\n\t\t\t\tif (typeof options[key] !== 'string')\r\n\t\t\t\t{\r\n\t\t\t\t\tthrow new Error(`\"${key}\" configuration parameter must be ` + `a string`)\r\n\t\t\t\t}\r\n\t\t\t\tbreak\r\n\r\n\t\t\tcase 'alias':\r\n\t\t\t\tif (!is_object(options[key]))\r\n\t\t\t\t{\r\n\t\t\t\t\tthrow new Error(`\"${key}\" configuration parameter must be ` + `an object`)\r\n\t\t\t\t}\r\n\t\t\t\tbreak\r\n\r\n\t\t\tdefault:\r\n\t\t\t\tthrow new Error(`Unknown configuration parameter \"${key}\"`)\r\n\t\t}\r\n\t}\r\n\r\n\t// if no assets specified (for whatever reason), make it an empty array\r\n\tif (!options.assets)\r\n\t{\r\n\t\t// options.assets = {}\r\n\t\tthrow new Error('You must specify \"assets\" parameter in webpack-isomorphic-tools configuration')\r\n\t}\r\n\r\n\t// webpack-assets.json path, relative to the project base path\r\n\toptions.webpack_assets_file_path = options.webpack_assets_file_path || 'webpack-assets.json'\t\r\n\r\n\t// if Webpack aliases are supplied, validate them\r\n\tif (options.alias)\r\n\t{\r\n\t\tfor (let key of Object.keys(options.alias))\r\n\t\t{\r\n\t\t\tif (typeof options.alias[key] !== 'string')\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(`Invalid alias for \"${key}\": \"${options.alias[key]}\"`)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\r\n\t// generate names (if required) for each user defined asset type, normalize extensions\r\n\tfor (let asset_type of Object.keys(options.assets))\r\n\t{\r\n\t\tconst description = options.assets[asset_type]\r\n\r\n\t\t// normalize extensions\r\n\t\tif (description.extension)\r\n\t\t{\r\n\t\t\t// sanity check\r\n\t\t\tif (Array.isArray(description.extension))\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(`Use \"extensions\" key instead of \"extension\" for specifying an array of file extensions for assets of type \"${asset_type}\"`)\r\n\t\t\t}\r\n\r\n\t\t\t// sanity check\r\n\t\t\tif (typeof description.extension !== 'string')\r\n\t\t\t{\r\n\t\t\t\tthrow new Error(`\"extension\" value must be a string for assets of type \"${asset_type}\"`)\r\n\t\t\t}\r\n\r\n\t\t\t// normalize\r\n\t\t\tdescription.extensions = [description.extension]\r\n\t\t\tdelete description.extension\r\n\t\t}\r\n\r\n\t\t// sanity check\r\n\t\tif (!description.extensions)\r\n\t\t{\r\n\t\t\tthrow new Error(`You must specify file extensions for assets of type \"${asset_type}\"`)\r\n\t\t}\r\n\r\n\t\t// parameters check\r\n\t\tfor (let key of Object.keys(description))\r\n\t\t{\r\n\t\t\tswitch (key)\r\n\t\t\t{\r\n\t\t\t\tcase 'extensions':\r\n\t\t\t\t\tbreak\r\n\r\n\t\t\t\tcase 'exclude':\r\n\t\t\t\t\tif (!Array.isArray(description[key]))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tthrow new Error(`\"${key}\" must be an array for asset type \"${asset_type}\"`)\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (let exclusion of description[key])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (typeof exclusion !== 'string' \r\n\t\t\t\t\t\t\t&& !(exclusion instanceof RegExp)\r\n\t\t\t\t\t\t\t&& typeof exclusion !== 'function')\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tthrow new Error(`Unsupported object type for exclusion \"${exclusion}\" for asset type \"${asset_type}\"`)\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tbreak\r\n\r\n\t\t\t\tcase 'include':\r\n\t\t\t\t\tif (!Array.isArray(description[key]))\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tthrow new Error(`\"${key}\" must be an array for asset type \"${asset_type}\"`)\r\n\t\t\t\t\t}\r\n\t\t\t\t\tfor (let inclusion of description[key])\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tif (typeof inclusion !== 'string' \r\n\t\t\t\t\t\t\t&& !(inclusion instanceof RegExp)\r\n\t\t\t\t\t\t\t&& typeof inclusion !== 'function')\r\n\t\t\t\t\t\t{\r\n\t\t\t\t\t\t\tthrow new Error(`Unsupported object type for inclusion \"${inclusion}\" for asset type \"${asset_type}\"`)\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t}\r\n\t\t\t\t\tbreak\r\n\r\n\t\t\t\tcase 'filter':\r\n\t\t\t\tcase 'parser':\r\n\t\t\t\tcase 'path':\r\n\t\t\t\t\tif (typeof description[key] !== 'function')\r\n\t\t\t\t\t{\r\n\t\t\t\t\t\tthrow new Error(`\"${key}\" must be a function for asset type \"${asset_type}\"`)\r\n\t\t\t\t\t}\r\n\t\t\t\t\tbreak\r\n\r\n\t\t\t\tdefault:\r\n\t\t\t\t\tthrow new Error(`Unknown property \"${key}\" for asset type \"${asset_type}\"`)\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\nexport function alias(path, aliases)\r\n{\r\n\t// if it's a path to a file - don't interfere\r\n\tif (starts_with(path, '.') || starts_with(path, '/'))\r\n\t{\r\n\t\treturn\r\n\t}\r\n\r\n\t// extract module name from the path\r\n\tconst slash_index = path.indexOf('/')\r\n\tconst module_name = slash_index >= 0 ? path.substring(0, slash_index) : path\r\n\tconst rest = slash_index >= 0 ? path.substring(slash_index) : ''\r\n\r\n\t// find an alias\r\n\tconst alias = aliases[module_name]\r\n\r\n\t// if an alias is found, require() the correct path\r\n\tif (alias)\r\n\t{\r\n\t\treturn alias + rest\r\n\t}\r\n}"]}
\No newline at end of file