diff --git a/.eslintrc.js b/.eslintrc.js index 095ce2a..29e7717 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,4 +1,4 @@ module.exports = { root: true, - extends: ['@webpack-contrib/eslint-config-webpack', 'prettier'], + extends: ["@webpack-contrib/eslint-config-webpack", "prettier"], }; diff --git a/.prettierrc.js b/.prettierrc.js deleted file mode 100644 index 4f14003..0000000 --- a/.prettierrc.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = { singleQuote: true }; diff --git a/README.md b/README.md index 63063db..5868eeb 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Then add the plugin to your `webpack` config. For example: **file.js** ```js -import css from 'file.css'; +import css from "file.css"; ``` **webpack.config.js** @@ -40,8 +40,8 @@ module.exports = { rules: [ { test: /\.js$/, - enforce: 'pre', - use: ['source-map-loader'], + enforce: "pre", + use: ["source-map-loader"], }, ], }, @@ -87,10 +87,10 @@ module.exports = { rules: [ { test: /\.js$/, - enforce: 'pre', + enforce: "pre", use: [ { - loader: 'source-map-loader', + loader: "source-map-loader", options: { filterSourceMappingUrl: (url, resourcePath) => { if (/broker-source-map-url\.js$/i.test(url)) { @@ -98,7 +98,7 @@ module.exports = { } if (/keep-source-mapping-url\.js$/i.test(resourcePath)) { - return 'skip'; + return "skip"; } return true; @@ -126,8 +126,8 @@ module.exports = { rules: [ { test: /\.js$/, - enforce: 'pre', - use: ['source-map-loader'], + enforce: "pre", + use: ["source-map-loader"], }, ], }, diff --git a/babel.config.js b/babel.config.js index 190c338..65000d4 100644 --- a/babel.config.js +++ b/babel.config.js @@ -7,10 +7,10 @@ module.exports = (api) => { return { presets: [ [ - '@babel/preset-env', + "@babel/preset-env", { targets: { - node: '10.13.0', + node: "10.13.0", }, }, ], diff --git a/commitlint.config.js b/commitlint.config.js index 84dcb12..69b4242 100644 --- a/commitlint.config.js +++ b/commitlint.config.js @@ -1,3 +1,3 @@ module.exports = { - extends: ['@commitlint/config-conventional'], + extends: ["@commitlint/config-conventional"], }; diff --git a/husky.config.js b/husky.config.js index 4c2ec3a..6cf9b3f 100644 --- a/husky.config.js +++ b/husky.config.js @@ -1,6 +1,6 @@ module.exports = { hooks: { - 'pre-commit': 'lint-staged', - 'commit-msg': 'commitlint -E HUSKY_GIT_PARAMS', + "pre-commit": "lint-staged", + "commit-msg": "commitlint -E HUSKY_GIT_PARAMS", }, }; diff --git a/lint-staged.config.js b/lint-staged.config.js index c417cb1..dc1bf51 100644 --- a/lint-staged.config.js +++ b/lint-staged.config.js @@ -1,4 +1,4 @@ module.exports = { - '*.js': ['prettier --write', 'eslint --fix'], - '*.{json,md,yml,css,ts}': ['prettier --write'], + "*.js": ["eslint --fix", "prettier --write"], + "*.{json,md,yml,css,ts}": ["prettier --write"], }; diff --git a/package.json b/package.json index ba3d568..34225c5 100644 --- a/package.json +++ b/package.json @@ -49,26 +49,26 @@ "whatwg-mimetype": "^2.3.0" }, "devDependencies": { - "@babel/cli": "^7.12.1", - "@babel/core": "^7.12.3", - "@babel/preset-env": "^7.12.1", + "@babel/cli": "^7.12.8", + "@babel/core": "^7.12.9", + "@babel/preset-env": "^7.12.7", "@commitlint/cli": "^11.0.0", "@commitlint/config-conventional": "^11.0.0", "@webpack-contrib/defaults": "^6.3.0", "@webpack-contrib/eslint-config-webpack": "^3.0.0", - "babel-jest": "^26.6.1", - "cross-env": "^7.0.2", + "babel-jest": "^26.6.3", + "cross-env": "^7.0.3", "del": "^6.0.0", "del-cli": "^3.0.1", - "eslint": "^7.12.0", - "eslint-config-prettier": "^6.14.0", + "eslint": "^7.14.0", + "eslint-config-prettier": "^6.15.0", "eslint-plugin-import": "^2.22.1", "husky": "^4.3.0", - "jest": "^26.6.1", - "lint-staged": "^10.4.2", + "jest": "^26.6.3", + "lint-staged": "^10.5.2", "memfs": "^3.2.0", "npm-run-all": "^4.1.5", - "prettier": "^2.1.2", + "prettier": "^2.2.1", "standard-version": "^9.0.0", "webpack": "^5.9.0" }, diff --git a/src/cjs.js b/src/cjs.js index c1c8d9a..68eb636 100644 --- a/src/cjs.js +++ b/src/cjs.js @@ -1,4 +1,4 @@ -const loader = require('./index'); +const loader = require("./index"); module.exports = loader.default; module.exports.raw = loader.raw; diff --git a/src/index.js b/src/index.js index 3f0c4c5..862234d 100644 --- a/src/index.js +++ b/src/index.js @@ -2,20 +2,20 @@ MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ -import path from 'path'; +import path from "path"; -import { getOptions } from 'loader-utils'; -import { validate } from 'schema-utils'; +import { getOptions } from "loader-utils"; +import { validate } from "schema-utils"; -import schema from './options.json'; -import { getSourceMappingURL, fetchFromURL, flattenSourceMap } from './utils'; +import schema from "./options.json"; +import { getSourceMappingURL, fetchFromURL, flattenSourceMap } from "./utils"; export default async function loader(input, inputMap) { const options = getOptions(this); validate(schema, options, { - name: 'Source Map Loader', - baseDataPath: 'options', + name: "Source Map Loader", + baseDataPath: "options", }); const { sourceMappingURL, replacementString } = getSourceMappingURL(input); @@ -32,9 +32,9 @@ export default async function loader(input, inputMap) { try { behaviourSourceMappingUrl = - typeof options.filterSourceMappingUrl !== 'undefined' + typeof options.filterSourceMappingUrl !== "undefined" ? options.filterSourceMappingUrl(sourceMappingURL, this.resourcePath) - : 'consume'; + : "consume"; } catch (error) { callback(error); @@ -43,12 +43,12 @@ export default async function loader(input, inputMap) { // eslint-disable-next-line default-case switch (behaviourSourceMappingUrl) { - case 'skip': + case "skip": callback(null, input, inputMap); return; case false: - case 'remove': - callback(null, input.replace(replacementString, ''), inputMap); + case "remove": + callback(null, input.replace(replacementString, ""), inputMap); return; } @@ -76,7 +76,7 @@ export default async function loader(input, inputMap) { let map; try { - map = JSON.parse(sourceContent.replace(/^\)\]\}'/, '')); + map = JSON.parse(sourceContent.replace(/^\)\]\}'/, "")); } catch (parseError) { this.emitWarning( new Error( @@ -104,11 +104,11 @@ export default async function loader(input, inputMap) { let sourceContent; const originalSourceContent = - map.sourcesContent && typeof map.sourcesContent[i] !== 'undefined' + map.sourcesContent && typeof map.sourcesContent[i] !== "undefined" ? map.sourcesContent[i] : // eslint-disable-next-line no-undefined undefined; - const skipReading = typeof originalSourceContent !== 'undefined'; + const skipReading = typeof originalSourceContent !== "undefined"; let errored = false; // We do not skipReading here, because we need absolute paths in sources. @@ -150,8 +150,8 @@ export default async function loader(input, inputMap) { // eslint-disable-next-line no-shadow const { sourceURL, sourceContent } = source; - newMap.sources.push(sourceURL || ''); - newMap.sourcesContent.push(sourceContent || ''); + newMap.sources.push(sourceURL || ""); + newMap.sourcesContent.push(sourceContent || ""); }); const sourcesContentIsEmpty = @@ -161,5 +161,5 @@ export default async function loader(input, inputMap) { delete newMap.sourcesContent; } - callback(null, input.replace(replacementString, ''), newMap); + callback(null, input.replace(replacementString, ""), newMap); } diff --git a/src/labels-to-names.js b/src/labels-to-names.js index c7ae894..21ac00e 100644 --- a/src/labels-to-names.js +++ b/src/labels-to-names.js @@ -1,209 +1,209 @@ const labelToNames = { - 866: 'IBM866', - 'unicode-1-1-utf-8': 'UTF-8', - 'utf-8': 'UTF-8', - utf8: 'UTF-8', - cp866: 'IBM866', - csibm866: 'IBM866', - ibm866: 'IBM866', - csisolatin2: 'ISO-8859-2', - 'iso-8859-2': 'ISO-8859-2', - 'iso-ir-101': 'ISO-8859-2', - 'iso8859-2': 'ISO-8859-2', - iso88592: 'ISO-8859-2', - 'iso_8859-2': 'ISO-8859-2', - 'iso_8859-2:1987': 'ISO-8859-2', - l2: 'ISO-8859-2', - latin2: 'ISO-8859-2', - csisolatin3: 'ISO-8859-3', - 'iso-8859-3': 'ISO-8859-3', - 'iso-ir-109': 'ISO-8859-3', - 'iso8859-3': 'ISO-8859-3', - iso88593: 'ISO-8859-3', - 'iso_8859-3': 'ISO-8859-3', - 'iso_8859-3:1988': 'ISO-8859-3', - l3: 'ISO-8859-3', - latin3: 'ISO-8859-3', - csisolatin4: 'ISO-8859-4', - 'iso-8859-4': 'ISO-8859-4', - 'iso-ir-110': 'ISO-8859-4', - 'iso8859-4': 'ISO-8859-4', - iso88594: 'ISO-8859-4', - 'iso_8859-4': 'ISO-8859-4', - 'iso_8859-4:1988': 'ISO-8859-4', - l4: 'ISO-8859-4', - latin4: 'ISO-8859-4', - csisolatincyrillic: 'ISO-8859-5', - cyrillic: 'ISO-8859-5', - 'iso-8859-5': 'ISO-8859-5', - 'iso-ir-144': 'ISO-8859-5', - 'iso8859-5': 'ISO-8859-5', - iso88595: 'ISO-8859-5', - 'iso_8859-5': 'ISO-8859-5', - 'iso_8859-5:1988': 'ISO-8859-5', - arabic: 'ISO-8859-6', - 'asmo-708': 'ISO-8859-6', - csiso88596e: 'ISO-8859-6', - csiso88596i: 'ISO-8859-6', - csisolatinarabic: 'ISO-8859-6', - 'ecma-114': 'ISO-8859-6', - 'iso-8859-6': 'ISO-8859-6', - 'iso-8859-6-e': 'ISO-8859-6', - 'iso-8859-6-i': 'ISO-8859-6', - 'iso-ir-127': 'ISO-8859-6', - 'iso8859-6': 'ISO-8859-6', - iso88596: 'ISO-8859-6', - 'iso_8859-6': 'ISO-8859-6', - 'iso_8859-6:1987': 'ISO-8859-6', - csisolatingreek: 'ISO-8859-7', - 'ecma-118': 'ISO-8859-7', - elot_928: 'ISO-8859-7', - greek: 'ISO-8859-7', - greek8: 'ISO-8859-7', - 'iso-8859-7': 'ISO-8859-7', - 'iso-ir-126': 'ISO-8859-7', - 'iso8859-7': 'ISO-8859-7', - iso88597: 'ISO-8859-7', - 'iso_8859-7': 'ISO-8859-7', - 'iso_8859-7:1987': 'ISO-8859-7', - sun_eu_greek: 'ISO-8859-7', - csiso88598e: 'ISO-8859-8', - csisolatinhebrew: 'ISO-8859-8', - hebrew: 'ISO-8859-8', - 'iso-8859-8': 'ISO-8859-8', - 'iso-8859-8-e': 'ISO-8859-8', - 'iso-ir-138': 'ISO-8859-8', - 'iso8859-8': 'ISO-8859-8', - iso88598: 'ISO-8859-8', - 'iso_8859-8': 'ISO-8859-8', - 'iso_8859-8:1988': 'ISO-8859-8', - visual: 'ISO-8859-8', - csisolatin6: 'ISO-8859-10', - 'iso-8859-10': 'ISO-8859-10', - 'iso-ir-157': 'ISO-8859-10', - 'iso8859-10': 'ISO-8859-10', - iso885910: 'ISO-8859-10', - l6: 'ISO-8859-10', - latin6: 'ISO-8859-10', - 'iso-8859-13': 'ISO-8859-13', - 'iso8859-13': 'ISO-8859-13', - iso885913: 'ISO-8859-13', - 'iso-8859-14': 'ISO-8859-14', - 'iso8859-14': 'ISO-8859-14', - iso885914: 'ISO-8859-14', - csisolatin9: 'ISO-8859-15', - 'iso-8859-15': 'ISO-8859-15', - 'iso8859-15': 'ISO-8859-15', - iso885915: 'ISO-8859-15', - 'iso_8859-15': 'ISO-8859-15', - l9: 'ISO-8859-15', - 'iso-8859-16': 'ISO-8859-16', - cskoi8r: 'KOI8-R', - koi: 'KOI8-R', - koi8: 'KOI8-R', - 'koi8-r': 'KOI8-R', - koi8_r: 'KOI8-R', - 'koi8-ru': 'KOI8-U', - 'koi8-u': 'KOI8-U', - csmacintosh: 'macintosh', - mac: 'macintosh', - macintosh: 'macintosh', - 'x-mac-roman': 'macintosh', - 'dos-874': 'windows-874', - 'iso-8859-11': 'windows-874', - 'iso8859-11': 'windows-874', - iso885911: 'windows-874', - 'tis-620': 'windows-874', - 'windows-874': 'windows-874', - cp1250: 'windows-1250', - 'windows-1250': 'windows-1250', - 'x-cp1250': 'windows-1250', - cp1251: 'windows-1251', - 'windows-1251': 'windows-1251', - 'x-cp1251': 'windows-1251', - 'ansi_x3.4-1968': 'windows-1252', - ascii: 'windows-1252', - cp1252: 'windows-1252', - cp819: 'windows-1252', - csisolatin1: 'windows-1252', - ibm819: 'windows-1252', - 'iso-8859-1': 'windows-1252', - 'iso-ir-100': 'windows-1252', - 'iso8859-1': 'windows-1252', - iso88591: 'windows-1252', - 'iso_8859-1': 'windows-1252', - 'iso_8859-1:1987': 'windows-1252', - l1: 'windows-1252', - latin1: 'windows-1252', - 'us-ascii': 'windows-1252', - 'windows-1252': 'windows-1252', - 'x-cp1252': 'windows-1252', - cp1253: 'windows-1253', - 'windows-1253': 'windows-1253', - 'x-cp1253': 'windows-1253', - cp1254: 'windows-1254', - csisolatin5: 'windows-1254', - 'iso-8859-9': 'windows-1254', - 'iso-ir-148': 'windows-1254', - 'iso8859-9': 'windows-1254', - iso88599: 'windows-1254', - 'iso_8859-9': 'windows-1254', - 'iso_8859-9:1989': 'windows-1254', - l5: 'windows-1254', - latin5: 'windows-1254', - 'windows-1254': 'windows-1254', - 'x-cp1254': 'windows-1254', - cp1255: 'windows-1255', - 'windows-1255': 'windows-1255', - 'x-cp1255': 'windows-1255', - cp1256: 'windows-1256', - 'windows-1256': 'windows-1256', - 'x-cp1256': 'windows-1256', - cp1257: 'windows-1257', - 'windows-1257': 'windows-1257', - 'x-cp1257': 'windows-1257', - cp1258: 'windows-1258', - 'windows-1258': 'windows-1258', - 'x-cp1258': 'windows-1258', - chinese: 'GBK', - csgb2312: 'GBK', - csiso58gb231280: 'GBK', - gb2312: 'GBK', - gb_2312: 'GBK', - 'gb_2312-80': 'GBK', - gbk: 'GBK', - 'iso-ir-58': 'GBK', - 'x-gbk': 'GBK', - gb18030: 'gb18030', - big5: 'Big5', - 'big5-hkscs': 'Big5', - 'cn-big5': 'Big5', - csbig5: 'Big5', - 'x-x-big5': 'Big5', - cseucpkdfmtjapanese: 'EUC-JP', - 'euc-jp': 'EUC-JP', - 'x-euc-jp': 'EUC-JP', - csshiftjis: 'Shift_JIS', - ms932: 'Shift_JIS', - ms_kanji: 'Shift_JIS', - 'shift-jis': 'Shift_JIS', - shift_jis: 'Shift_JIS', - sjis: 'Shift_JIS', - 'windows-31j': 'Shift_JIS', - 'x-sjis': 'Shift_JIS', - cseuckr: 'EUC-KR', - csksc56011987: 'EUC-KR', - 'euc-kr': 'EUC-KR', - 'iso-ir-149': 'EUC-KR', - korean: 'EUC-KR', - 'ks_c_5601-1987': 'EUC-KR', - 'ks_c_5601-1989': 'EUC-KR', - ksc5601: 'EUC-KR', - ksc_5601: 'EUC-KR', - 'windows-949': 'EUC-KR', - 'utf-16be': 'UTF-16BE', - 'utf-16': 'UTF-16LE', - 'utf-16le': 'UTF-16LE', + 866: "IBM866", + "unicode-1-1-utf-8": "UTF-8", + "utf-8": "UTF-8", + utf8: "UTF-8", + cp866: "IBM866", + csibm866: "IBM866", + ibm866: "IBM866", + csisolatin2: "ISO-8859-2", + "iso-8859-2": "ISO-8859-2", + "iso-ir-101": "ISO-8859-2", + "iso8859-2": "ISO-8859-2", + iso88592: "ISO-8859-2", + "iso_8859-2": "ISO-8859-2", + "iso_8859-2:1987": "ISO-8859-2", + l2: "ISO-8859-2", + latin2: "ISO-8859-2", + csisolatin3: "ISO-8859-3", + "iso-8859-3": "ISO-8859-3", + "iso-ir-109": "ISO-8859-3", + "iso8859-3": "ISO-8859-3", + iso88593: "ISO-8859-3", + "iso_8859-3": "ISO-8859-3", + "iso_8859-3:1988": "ISO-8859-3", + l3: "ISO-8859-3", + latin3: "ISO-8859-3", + csisolatin4: "ISO-8859-4", + "iso-8859-4": "ISO-8859-4", + "iso-ir-110": "ISO-8859-4", + "iso8859-4": "ISO-8859-4", + iso88594: "ISO-8859-4", + "iso_8859-4": "ISO-8859-4", + "iso_8859-4:1988": "ISO-8859-4", + l4: "ISO-8859-4", + latin4: "ISO-8859-4", + csisolatincyrillic: "ISO-8859-5", + cyrillic: "ISO-8859-5", + "iso-8859-5": "ISO-8859-5", + "iso-ir-144": "ISO-8859-5", + "iso8859-5": "ISO-8859-5", + iso88595: "ISO-8859-5", + "iso_8859-5": "ISO-8859-5", + "iso_8859-5:1988": "ISO-8859-5", + arabic: "ISO-8859-6", + "asmo-708": "ISO-8859-6", + csiso88596e: "ISO-8859-6", + csiso88596i: "ISO-8859-6", + csisolatinarabic: "ISO-8859-6", + "ecma-114": "ISO-8859-6", + "iso-8859-6": "ISO-8859-6", + "iso-8859-6-e": "ISO-8859-6", + "iso-8859-6-i": "ISO-8859-6", + "iso-ir-127": "ISO-8859-6", + "iso8859-6": "ISO-8859-6", + iso88596: "ISO-8859-6", + "iso_8859-6": "ISO-8859-6", + "iso_8859-6:1987": "ISO-8859-6", + csisolatingreek: "ISO-8859-7", + "ecma-118": "ISO-8859-7", + elot_928: "ISO-8859-7", + greek: "ISO-8859-7", + greek8: "ISO-8859-7", + "iso-8859-7": "ISO-8859-7", + "iso-ir-126": "ISO-8859-7", + "iso8859-7": "ISO-8859-7", + iso88597: "ISO-8859-7", + "iso_8859-7": "ISO-8859-7", + "iso_8859-7:1987": "ISO-8859-7", + sun_eu_greek: "ISO-8859-7", + csiso88598e: "ISO-8859-8", + csisolatinhebrew: "ISO-8859-8", + hebrew: "ISO-8859-8", + "iso-8859-8": "ISO-8859-8", + "iso-8859-8-e": "ISO-8859-8", + "iso-ir-138": "ISO-8859-8", + "iso8859-8": "ISO-8859-8", + iso88598: "ISO-8859-8", + "iso_8859-8": "ISO-8859-8", + "iso_8859-8:1988": "ISO-8859-8", + visual: "ISO-8859-8", + csisolatin6: "ISO-8859-10", + "iso-8859-10": "ISO-8859-10", + "iso-ir-157": "ISO-8859-10", + "iso8859-10": "ISO-8859-10", + iso885910: "ISO-8859-10", + l6: "ISO-8859-10", + latin6: "ISO-8859-10", + "iso-8859-13": "ISO-8859-13", + "iso8859-13": "ISO-8859-13", + iso885913: "ISO-8859-13", + "iso-8859-14": "ISO-8859-14", + "iso8859-14": "ISO-8859-14", + iso885914: "ISO-8859-14", + csisolatin9: "ISO-8859-15", + "iso-8859-15": "ISO-8859-15", + "iso8859-15": "ISO-8859-15", + iso885915: "ISO-8859-15", + "iso_8859-15": "ISO-8859-15", + l9: "ISO-8859-15", + "iso-8859-16": "ISO-8859-16", + cskoi8r: "KOI8-R", + koi: "KOI8-R", + koi8: "KOI8-R", + "koi8-r": "KOI8-R", + koi8_r: "KOI8-R", + "koi8-ru": "KOI8-U", + "koi8-u": "KOI8-U", + csmacintosh: "macintosh", + mac: "macintosh", + macintosh: "macintosh", + "x-mac-roman": "macintosh", + "dos-874": "windows-874", + "iso-8859-11": "windows-874", + "iso8859-11": "windows-874", + iso885911: "windows-874", + "tis-620": "windows-874", + "windows-874": "windows-874", + cp1250: "windows-1250", + "windows-1250": "windows-1250", + "x-cp1250": "windows-1250", + cp1251: "windows-1251", + "windows-1251": "windows-1251", + "x-cp1251": "windows-1251", + "ansi_x3.4-1968": "windows-1252", + ascii: "windows-1252", + cp1252: "windows-1252", + cp819: "windows-1252", + csisolatin1: "windows-1252", + ibm819: "windows-1252", + "iso-8859-1": "windows-1252", + "iso-ir-100": "windows-1252", + "iso8859-1": "windows-1252", + iso88591: "windows-1252", + "iso_8859-1": "windows-1252", + "iso_8859-1:1987": "windows-1252", + l1: "windows-1252", + latin1: "windows-1252", + "us-ascii": "windows-1252", + "windows-1252": "windows-1252", + "x-cp1252": "windows-1252", + cp1253: "windows-1253", + "windows-1253": "windows-1253", + "x-cp1253": "windows-1253", + cp1254: "windows-1254", + csisolatin5: "windows-1254", + "iso-8859-9": "windows-1254", + "iso-ir-148": "windows-1254", + "iso8859-9": "windows-1254", + iso88599: "windows-1254", + "iso_8859-9": "windows-1254", + "iso_8859-9:1989": "windows-1254", + l5: "windows-1254", + latin5: "windows-1254", + "windows-1254": "windows-1254", + "x-cp1254": "windows-1254", + cp1255: "windows-1255", + "windows-1255": "windows-1255", + "x-cp1255": "windows-1255", + cp1256: "windows-1256", + "windows-1256": "windows-1256", + "x-cp1256": "windows-1256", + cp1257: "windows-1257", + "windows-1257": "windows-1257", + "x-cp1257": "windows-1257", + cp1258: "windows-1258", + "windows-1258": "windows-1258", + "x-cp1258": "windows-1258", + chinese: "GBK", + csgb2312: "GBK", + csiso58gb231280: "GBK", + gb2312: "GBK", + gb_2312: "GBK", + "gb_2312-80": "GBK", + gbk: "GBK", + "iso-ir-58": "GBK", + "x-gbk": "GBK", + gb18030: "gb18030", + big5: "Big5", + "big5-hkscs": "Big5", + "cn-big5": "Big5", + csbig5: "Big5", + "x-x-big5": "Big5", + cseucpkdfmtjapanese: "EUC-JP", + "euc-jp": "EUC-JP", + "x-euc-jp": "EUC-JP", + csshiftjis: "Shift_JIS", + ms932: "Shift_JIS", + ms_kanji: "Shift_JIS", + "shift-jis": "Shift_JIS", + shift_jis: "Shift_JIS", + sjis: "Shift_JIS", + "windows-31j": "Shift_JIS", + "x-sjis": "Shift_JIS", + cseuckr: "EUC-KR", + csksc56011987: "EUC-KR", + "euc-kr": "EUC-KR", + "iso-ir-149": "EUC-KR", + korean: "EUC-KR", + "ks_c_5601-1987": "EUC-KR", + "ks_c_5601-1989": "EUC-KR", + ksc5601: "EUC-KR", + ksc_5601: "EUC-KR", + "windows-949": "EUC-KR", + "utf-16be": "UTF-16BE", + "utf-16": "UTF-16LE", + "utf-16le": "UTF-16LE", }; export default labelToNames; diff --git a/src/parse-data-url.js b/src/parse-data-url.js index 3cd6f51..722970b 100644 --- a/src/parse-data-url.js +++ b/src/parse-data-url.js @@ -1,5 +1,5 @@ -import MIMEType from 'whatwg-mimetype'; -import { atob } from 'abab'; +import MIMEType from "whatwg-mimetype"; +import { atob } from "abab"; function isASCIIHex(c) { return ( @@ -46,24 +46,24 @@ export default function parseDataUrl(stringInput) { return null; } - if (parsedUrl.protocol !== 'data:') { + if (parsedUrl.protocol !== "data:") { return null; } - parsedUrl.hash = ''; + parsedUrl.hash = ""; // `5` is value of `'data:'.length` const input = parsedUrl.toString().substring(5); let position = 0; - let mimeType = ''; + let mimeType = ""; - while (position < input.length && input[position] !== ',') { + while (position < input.length && input[position] !== ",") { mimeType += input[position]; position += 1; } - mimeType = mimeType.replace(/^[ \t\n\f\r]+/, '').replace(/[ \t\n\f\r]+$/, ''); + mimeType = mimeType.replace(/^[ \t\n\f\r]+/, "").replace(/[ \t\n\f\r]+$/, ""); if (position === input.length) { return null; @@ -73,25 +73,25 @@ export default function parseDataUrl(stringInput) { const encodedBody = input.substring(position); - let body = Buffer.from(percentDecodeBytes(Buffer.from(encodedBody, 'utf-8'))); + let body = Buffer.from(percentDecodeBytes(Buffer.from(encodedBody, "utf-8"))); // Can't use /i regexp flag because it isn't restricted to ASCII. const mimeTypeBase64MatchResult = /(.*); *[Bb][Aa][Ss][Ee]64$/.exec(mimeType); if (mimeTypeBase64MatchResult) { - const stringBody = body.toString('binary'); + const stringBody = body.toString("binary"); const asString = atob(stringBody); if (asString === null) { return null; } - body = Buffer.from(asString, 'binary'); + body = Buffer.from(asString, "binary"); [, mimeType] = mimeTypeBase64MatchResult; } - if (mimeType.startsWith(';')) { + if (mimeType.startsWith(";")) { mimeType = `text/plain ${mimeType}`; } @@ -100,7 +100,7 @@ export default function parseDataUrl(stringInput) { try { mimeTypeRecord = new MIMEType(mimeType); } catch (e) { - mimeTypeRecord = new MIMEType('text/plain;charset=US-ASCII'); + mimeTypeRecord = new MIMEType("text/plain;charset=US-ASCII"); } return { mimeType: mimeTypeRecord, body }; diff --git a/src/utils.js b/src/utils.js index 4f14c2a..b7caea2 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,33 +1,33 @@ -import path from 'path'; -import urlUtils from 'url'; +import path from "path"; +import urlUtils from "url"; -import sourceMap from 'source-map'; +import sourceMap from "source-map"; -import { decode } from 'iconv-lite'; -import { urlToRequest } from 'loader-utils'; +import { decode } from "iconv-lite"; +import { urlToRequest } from "loader-utils"; -import parseDataURL from './parse-data-url'; -import labelsToNames from './labels-to-names'; +import parseDataURL from "./parse-data-url"; +import labelsToNames from "./labels-to-names"; // Matches only the last occurrence of sourceMappingURL const innerRegex = /\s*[#@]\s*sourceMappingURL\s*=\s*([^\s'"]*)\s*/; /* eslint-disable prefer-template */ const sourceMappingURLRegex = RegExp( - '(?:' + - '/\\*' + - '(?:\\s*\r?\n(?://)?)?' + - '(?:' + + "(?:" + + "/\\*" + + "(?:\\s*\r?\n(?://)?)?" + + "(?:" + innerRegex.source + - ')' + - '\\s*' + - '\\*/' + - '|' + - '//(?:' + + ")" + + "\\s*" + + "\\*/" + + "|" + + "//(?:" + innerRegex.source + - ')' + - ')' + - '\\s*' + ")" + + ")" + + "\\s*" ); /* eslint-enable prefer-template */ @@ -87,7 +87,7 @@ function getSourceMappingURL(code) { } } - const sourceMappingURL = match ? match[1] || match[2] || '' : null; + const sourceMappingURL = match ? match[1] || match[2] || "" : null; return { sourceMappingURL: sourceMappingURL @@ -116,7 +116,7 @@ function fetchFromDataURL(loaderContext, sourceURL) { if (dataURL) { dataURL.encodingName = - labelToName(dataURL.mimeType.parameters.get('charset')) || 'UTF-8'; + labelToName(dataURL.mimeType.parameters.get("charset")) || "UTF-8"; return decode(dataURL.body, dataURL.encodingName); } @@ -149,7 +149,7 @@ async function fetchFromFilesystem(loaderContext, sourceURL) { async function fetchPathsFromFilesystem( loaderContext, possibleRequests, - errorsAccumulator = '' + errorsAccumulator = "" ) { let result; @@ -192,21 +192,21 @@ async function fetchFromURL( if (/^[a-z][a-z0-9+.-]*:/i.test(url) && !path.win32.isAbsolute(url)) { const { protocol } = urlUtils.parse(url); - if (protocol === 'data:') { + if (protocol === "data:") { if (skipReading) { - return { sourceURL: '' }; + return { sourceURL: "" }; } const sourceContent = fetchFromDataURL(loaderContext, url); - return { sourceURL: '', sourceContent }; + return { sourceURL: "", sourceContent }; } if (skipReading) { return { sourceURL: url }; } - if (protocol === 'file:') { + if (protocol === "file:") { const pathFromURL = urlUtils.fileURLToPath(url); const sourceURL = path.normalize(pathFromURL); const sourceContent = await fetchFromFilesystem(loaderContext, sourceURL); @@ -235,7 +235,7 @@ async function fetchFromURL( if (!skipReading) { const possibleRequests = [sourceURL]; - if (url.startsWith('/')) { + if (url.startsWith("/")) { possibleRequests.push( getAbsolutePath(context, sourceURL.slice(1), sourceRoot) ); diff --git a/test/cjs.test.js b/test/cjs.test.js index 8aba6ba..dc8321a 100644 --- a/test/cjs.test.js +++ b/test/cjs.test.js @@ -1,8 +1,8 @@ -import src from '../src'; -import cjs from '../src/cjs'; +import src from "../src"; +import cjs from "../src/cjs"; -describe('cjs', () => { - it('should exported', () => { +describe("cjs", () => { + it("should exported", () => { expect(cjs).toEqual(src); }); }); diff --git a/test/filterSourceMappingUrl.test.js b/test/filterSourceMappingUrl.test.js index 743652a..b5d117f 100644 --- a/test/filterSourceMappingUrl.test.js +++ b/test/filterSourceMappingUrl.test.js @@ -5,13 +5,13 @@ import { getErrors, normalizeMap, getWarnings, -} from './helpers'; +} from "./helpers"; -describe('filterSourceMappingUrl option', () => { - it('should work', async () => { +describe("filterSourceMappingUrl option", () => { + it("should work", async () => { expect.assertions(6); - const testId = 'external-source-map.js'; + const testId = "external-source-map.js"; const compiler = getCompiler(testId, { filterSourceMappingUrl: (sourceMappingURL, resourcePath) => { expect(sourceMappingURL).toBeDefined(); @@ -23,56 +23,56 @@ describe('filterSourceMappingUrl option', () => { const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should work with true value', async () => { - const testId = 'external-source-map.js'; + it("should work with true value", async () => { + const testId = "external-source-map.js"; const compiler = getCompiler(testId, { filterSourceMappingUrl: () => true, }); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); it('should work with "skip" value', async () => { - const testId = 'http-source-map.js'; + const testId = "http-source-map.js"; const compiler = getCompiler(testId, { - filterSourceMappingUrl: () => 'skip', + filterSourceMappingUrl: () => "skip", }); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeUndefined(); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); it('should work with "remove" value', async () => { - const testId = 'http-source-map.js'; + const testId = "http-source-map.js"; const compiler = getCompiler(testId, { - filterSourceMappingUrl: () => 'remove', + filterSourceMappingUrl: () => "remove", }); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeUndefined(); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should work with false value', async () => { - const testId = 'http-source-map.js'; + it("should work with false value", async () => { + const testId = "http-source-map.js"; const compiler = getCompiler(testId, { filterSourceMappingUrl: () => false, }); @@ -80,21 +80,21 @@ describe('filterSourceMappingUrl option', () => { const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeUndefined(); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should emit error', async () => { - const testId = 'external-source-map.js'; + it("should emit error", async () => { + const testId = "external-source-map.js"; const compiler = getCompiler(testId, { filterSourceMappingUrl: () => { - throw new Error('error'); + throw new Error("error"); }, }); const stats = await compile(compiler); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); }); diff --git a/test/helpers/execute.js b/test/helpers/execute.js index 4cb101d..78a77d5 100644 --- a/test/helpers/execute.js +++ b/test/helpers/execute.js @@ -1,14 +1,14 @@ -import Module from 'module'; -import path from 'path'; +import Module from "module"; +import path from "path"; const parentModule = module; export default (code) => { - const resource = 'test.js'; + const resource = "test.js"; const module = new Module(resource, parentModule); // eslint-disable-next-line no-underscore-dangle module.paths = Module._nodeModulePaths( - path.resolve(__dirname, '../fixtures') + path.resolve(__dirname, "../fixtures") ); module.filename = resource; diff --git a/test/helpers/getCodeFromBundle.js b/test/helpers/getCodeFromBundle.js index 8e3b445..7ebbb2b 100644 --- a/test/helpers/getCodeFromBundle.js +++ b/test/helpers/getCodeFromBundle.js @@ -1,6 +1,6 @@ -import vm from 'vm'; +import vm from "vm"; -import readAsset from './readAsset'; +import readAsset from "./readAsset"; function getCodeFromBundle(stats, compiler, asset) { let code = null; @@ -9,9 +9,9 @@ function getCodeFromBundle(stats, compiler, asset) { stats && stats.compilation && stats.compilation.assets && - stats.compilation.assets[asset || 'main.bundle.js'] + stats.compilation.assets[asset || "main.bundle.js"] ) { - code = readAsset(asset || 'main.bundle.js', compiler, stats); + code = readAsset(asset || "main.bundle.js", compiler, stats); } if (!code) { diff --git a/test/helpers/getCompiler.js b/test/helpers/getCompiler.js index 73b4b4e..bf33d66 100644 --- a/test/helpers/getCompiler.js +++ b/test/helpers/getCompiler.js @@ -1,7 +1,7 @@ -import path from 'path'; +import path from "path"; -import webpack from 'webpack'; -import { createFsFromVolume, Volume } from 'memfs'; +import webpack from "webpack"; +import { createFsFromVolume, Volume } from "memfs"; export default ( fixture, @@ -11,27 +11,27 @@ export default ( ) => { const loaders = [ { - loader: path.resolve(__dirname, '../../src'), + loader: path.resolve(__dirname, "../../src"), options: loaderOptions || {}, }, ]; if (!skipTestLoader) { loaders.unshift({ - loader: require.resolve('./testLoader'), + loader: require.resolve("./testLoader"), }); } const fullConfig = { - mode: 'development', - devtool: config.devtool || 'source-map', - context: path.resolve(__dirname, '../fixtures'), - entry: path.resolve(__dirname, '../fixtures', fixture), + mode: "development", + devtool: config.devtool || "source-map", + context: path.resolve(__dirname, "../fixtures"), + entry: path.resolve(__dirname, "../fixtures", fixture), output: { - path: path.resolve(__dirname, '../outputs'), - filename: '[name].bundle.js', - chunkFilename: '[name].chunk.js', - library: 'sourceMapLoaderExport', + path: path.resolve(__dirname, "../outputs"), + filename: "[name].bundle.js", + chunkFilename: "[name].chunk.js", + library: "sourceMapLoaderExport", // devtoolModuleFilenameTemplate: "[absolute-resource-path]" }, module: { diff --git a/test/helpers/getErrors.js b/test/helpers/getErrors.js index 71d940b..52a49bb 100644 --- a/test/helpers/getErrors.js +++ b/test/helpers/getErrors.js @@ -1,4 +1,4 @@ -import normalizeErrors from './normalizeErrors'; +import normalizeErrors from "./normalizeErrors"; export default (stats) => { return normalizeErrors(stats.compilation.errors.sort()); diff --git a/test/helpers/getWarnings.js b/test/helpers/getWarnings.js index 7c987d5..2f5c32c 100644 --- a/test/helpers/getWarnings.js +++ b/test/helpers/getWarnings.js @@ -1,4 +1,4 @@ -import normalizeErrors from './normalizeErrors'; +import normalizeErrors from "./normalizeErrors"; export default (stats, shortError) => { return normalizeErrors(stats.compilation.warnings.sort(), shortError); diff --git a/test/helpers/index.js b/test/helpers/index.js index 6d3e778..4facc51 100644 --- a/test/helpers/index.js +++ b/test/helpers/index.js @@ -1,13 +1,13 @@ -import compile from './compile'; -import execute from './execute'; -import getCodeFromBundle from './getCodeFromBundle'; -import getCompiler from './getCompiler'; -import getErrors from './getErrors'; -import normalizeMap from './normalizeMap'; -import getWarnings from './getWarnings'; -import normalizeErrors from './normalizeErrors'; -import readAsset from './readAsset'; -import readsAssets from './readAssets'; +import compile from "./compile"; +import execute from "./execute"; +import getCodeFromBundle from "./getCodeFromBundle"; +import getCompiler from "./getCompiler"; +import getErrors from "./getErrors"; +import normalizeMap from "./normalizeMap"; +import getWarnings from "./getWarnings"; +import normalizeErrors from "./normalizeErrors"; +import readAsset from "./readAsset"; +import readsAssets from "./readAssets"; export { compile, diff --git a/test/helpers/normalizeErrors.js b/test/helpers/normalizeErrors.js index da0d6b3..3c91cf3 100644 --- a/test/helpers/normalizeErrors.js +++ b/test/helpers/normalizeErrors.js @@ -1,17 +1,17 @@ function removeCWD(str) { - const isWin = process.platform === 'win32'; + const isWin = process.platform === "win32"; let cwd = process.cwd(); if (isWin) { // eslint-disable-next-line no-param-reassign - str = str.replace(/\\/g, '/'); + str = str.replace(/\\/g, "/"); // eslint-disable-next-line no-param-reassign - cwd = cwd.replace(/\\/g, '/'); + cwd = cwd.replace(/\\/g, "/"); } return str - .replace(/\(from .*?\)/, '(from `replaced original path`)') - .replace(new RegExp(cwd, 'g'), ''); + .replace(/\(from .*?\)/, "(from `replaced original path`)") + .replace(new RegExp(cwd, "g"), ""); } export default (errors, shortError) => { @@ -19,9 +19,9 @@ export default (errors, shortError) => { let errorMessage = error.toString(); if (shortError) { - errorMessage = errorMessage.split('\n').slice(0, 1).join('\n'); + errorMessage = errorMessage.split("\n").slice(0, 1).join("\n"); } - return removeCWD(errorMessage.split('\n').slice(0, 2).join('\n')); + return removeCWD(errorMessage.split("\n").slice(0, 2).join("\n")); }); }; diff --git a/test/helpers/normalizeMap.js b/test/helpers/normalizeMap.js index 69d7065..91f5358 100644 --- a/test/helpers/normalizeMap.js +++ b/test/helpers/normalizeMap.js @@ -24,7 +24,7 @@ function normalizeArr(arr) { return str; } - if (str.replace(/\\/g, '/') === normilized) { + if (str.replace(/\\/g, "/") === normilized) { return normilized; } @@ -33,14 +33,14 @@ function normalizeArr(arr) { } function removeCWD(str) { - const isWin = process.platform === 'win32'; + const isWin = process.platform === "win32"; let cwd = process.cwd(); if (isWin) { // eslint-disable-next-line no-param-reassign - str = str.replace(/\\/g, '/'); - cwd = cwd.replace(/\\/g, '/'); + str = str.replace(/\\/g, "/"); + cwd = cwd.replace(/\\/g, "/"); } - return str.replace(new RegExp(cwd, 'g'), ''); + return str.replace(new RegExp(cwd, "g"), ""); } diff --git a/test/helpers/readAsset.js b/test/helpers/readAsset.js index 8f4699f..fde3ff3 100644 --- a/test/helpers/readAsset.js +++ b/test/helpers/readAsset.js @@ -1,13 +1,13 @@ -import path from 'path'; +import path from "path"; export default (asset, compiler, stats) => { const usedFs = compiler.outputFileSystem; const outputPath = stats.compilation.outputOptions.path; - let data = ''; + let data = ""; let targetFile = asset; - const queryStringIdx = targetFile.indexOf('?'); + const queryStringIdx = targetFile.indexOf("?"); if (queryStringIdx >= 0) { targetFile = targetFile.substr(0, queryStringIdx); diff --git a/test/helpers/readAssets.js b/test/helpers/readAssets.js index a2fb783..15b9dca 100644 --- a/test/helpers/readAssets.js +++ b/test/helpers/readAssets.js @@ -1,4 +1,4 @@ -import readAsset from './readAsset'; +import readAsset from "./readAsset"; export default function readAssets(compiler, stats) { const assets = {}; diff --git a/test/loader.test.js b/test/loader.test.js index d85cb05..290dd69 100644 --- a/test/loader.test.js +++ b/test/loader.test.js @@ -1,5 +1,5 @@ -import path from 'path'; -import fs from 'fs'; +import path from "path"; +import fs from "fs"; import { compile, @@ -9,149 +9,149 @@ import { normalizeMap, getWarnings, readAsset, -} from './helpers'; +} from "./helpers"; -const isWin = process.platform === 'win32'; +const isWin = process.platform === "win32"; -describe('source-map-loader', () => { - it('should leave normal files untouched', async () => { - const testId = 'normal-file.js'; +describe("source-map-loader", () => { + it("should leave normal files untouched", async () => { + const testId = "normal-file.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeUndefined(); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should leave normal files with fake source-map untouched', async () => { - const testId = 'normal-file2.js'; + it("should leave normal files with fake source-map untouched", async () => { + const testId = "normal-file2.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeUndefined(); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should process inlined SourceMaps', async () => { - const testId = 'inline-source-map.js'; + it("should process inlined SourceMaps", async () => { + const testId = "inline-source-map.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should process percent-encoding path', async () => { - const testId = '{percent}.js'; + it("should process percent-encoding path", async () => { + const testId = "{percent}.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeDefined(); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should process external SourceMaps', async () => { - const testId = 'external-source-map.js'; + it("should process external SourceMaps", async () => { + const testId = "external-source-map.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); const deps = stats.compilation.fileDependencies; const dependencies = [ - path.resolve(__dirname, 'fixtures', 'external-source-map.map'), + path.resolve(__dirname, "fixtures", "external-source-map.map"), ]; dependencies.forEach((fixture) => { expect(deps.has(fixture)).toBe(true); }); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should process external SourceMaps (external sources)', async () => { - const testId = 'external-source-map2.js'; + it("should process external SourceMaps (external sources)", async () => { + const testId = "external-source-map2.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); const deps = stats.compilation.fileDependencies; const dependencies = [ - path.resolve(__dirname, 'fixtures', 'data', 'external-source-map2.map'), - path.resolve(__dirname, 'fixtures', 'external-source-map2.js'), - path.resolve(__dirname, 'fixtures', 'external-source-map2.txt'), + path.resolve(__dirname, "fixtures", "data", "external-source-map2.map"), + path.resolve(__dirname, "fixtures", "external-source-map2.js"), + path.resolve(__dirname, "fixtures", "external-source-map2.txt"), ]; dependencies.forEach((fixture) => { expect(deps.has(fixture)).toBe(true); }); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should reject http SourceMaps', async () => { - const testId = 'http-source-map.js'; + it("should reject http SourceMaps", async () => { + const testId = "http-source-map.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should reject not exist file: SourceMaps', async () => { - const testId = isWin ? 'file-source-map-windows.js' : 'file-source-map.js'; + it("should reject not exist file: SourceMaps", async () => { + const testId = isWin ? "file-source-map-windows.js" : "file-source-map.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); - const errorString = getWarnings(stats).join(''); + const errorString = getWarnings(stats).join(""); const warning = errorString.match(/TypeError \[ERR_INVALID_FILE/gi); - expect(...warning).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(...warning).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should support file protocol path', async () => { - const sourceRoot = path.resolve(__dirname, 'fixtures'); - const javaScriptFilename = 'file-protocol-path.js'; + it("should support file protocol path", async () => { + const sourceRoot = path.resolve(__dirname, "fixtures"); + const javaScriptFilename = "file-protocol-path.js"; const entryFileAbsolutePath = path.join(sourceRoot, javaScriptFilename); - const sourceMapPath = path.join(sourceRoot, 'file-protocol-path.js.map'); + const sourceMapPath = path.join(sourceRoot, "file-protocol-path.js.map"); // Create the sourcemap file const rawSourceMap = { version: 3, sources: [ - 'normal-file.js', + "normal-file.js", `file://${path - .resolve(__dirname, 'fixtures', 'normal-file2.js') - .replace(/\\/g, '/')}`, + .resolve(__dirname, "fixtures", "normal-file2.js") + .replace(/\\/g, "/")}`, ], - mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA', + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA", }; fs.writeFileSync(sourceMapPath, JSON.stringify(rawSourceMap)); // Create the entryPointFile file const entryFileContent = `// Some content \r\n // # sourceMappingURL=file://${sourceMapPath.replace( /\\/g, - '/' + "/" )}`; fs.writeFileSync(entryFileAbsolutePath, entryFileContent); @@ -160,149 +160,149 @@ describe('source-map-loader', () => { const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should skip file protocol path if sourcesContent is set', async () => { - const testId = 'file-broken-protocol-path.js'; + it("should skip file protocol path if sourcesContent is set", async () => { + const testId = "file-broken-protocol-path.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should skip webpack protocol path if sourcesContent is set', async () => { - const testId = 'webpack/main.js'; + it("should skip webpack protocol path if sourcesContent is set", async () => { + const testId = "webpack/main.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should use last SourceMap directive', async () => { - const testId = 'multi-source-map.js'; + it("should use last SourceMap directive", async () => { + const testId = "multi-source-map.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should skip invalid base64 SourceMap', async () => { - const testId = 'invalid-inline-source-map.js'; + it("should skip invalid base64 SourceMap", async () => { + const testId = "invalid-inline-source-map.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeUndefined(); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should warn on invalid base64 SourceMap', async () => { - const testId = 'invalid-inline-source-map2.js'; + it("should warn on invalid base64 SourceMap", async () => { + const testId = "invalid-inline-source-map2.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeUndefined(); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should warn on invalid SourceMap', async () => { - const testId = 'invalid-source-map.js'; + it("should warn on invalid SourceMap", async () => { + const testId = "invalid-source-map.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); const deps = stats.compilation.fileDependencies; const dependencies = [ - path.resolve(__dirname, 'fixtures', 'invalid-source-map.map'), + path.resolve(__dirname, "fixtures", "invalid-source-map.map"), ]; dependencies.forEach((fixture) => { expect(deps.has(fixture)).toBe(true); }); expect(codeFromBundle.map).toBeUndefined(); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should warn on missing SourceMap', async () => { - const testId = 'missing-source-map.js'; + it("should warn on missing SourceMap", async () => { + const testId = "missing-source-map.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeUndefined(); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should warn on missing source file', async () => { - const testId = 'missing-source-map2.js'; + it("should warn on missing source file", async () => { + const testId = "missing-source-map2.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); const deps = stats.compilation.fileDependencies; const dependencies = [ - path.resolve(__dirname, 'fixtures', 'missing-source-map2.map'), + path.resolve(__dirname, "fixtures", "missing-source-map2.map"), ]; dependencies.forEach((fixture) => { expect(deps.has(fixture)).toBe(true); }); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should process inlined SourceMaps with charset', async () => { - const testId = 'charset-inline-source-map.js'; + it("should process inlined SourceMaps with charset", async () => { + const testId = "charset-inline-source-map.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should support absolute sourceRoot paths in sourcemaps', async () => { - const sourceRoot = path.resolve(__dirname, 'fixtures'); - const javaScriptFilename = 'absolute-sourceRoot-source-map.js'; - const sourceFilename = 'absolute-sourceRoot-source-map.txt'; + it("should support absolute sourceRoot paths in sourcemaps", async () => { + const sourceRoot = path.resolve(__dirname, "fixtures"); + const javaScriptFilename = "absolute-sourceRoot-source-map.js"; + const sourceFilename = "absolute-sourceRoot-source-map.txt"; const rootRelativeSourcePath = path.join(sourceRoot, sourceFilename); const sourceMapPath = path.join( sourceRoot, - 'absolute-sourceRoot-source-map.map' + "absolute-sourceRoot-source-map.map" ); // Create the sourcemap file @@ -311,7 +311,7 @@ describe('source-map-loader', () => { file: javaScriptFilename, sourceRoot, sources: [sourceFilename], - mappings: 'AAAA', + mappings: "AAAA", }; fs.writeFileSync(sourceMapPath, JSON.stringify(rawSourceMap)); @@ -326,27 +326,27 @@ describe('source-map-loader', () => { expect(deps.has(fixture)).toBe(true); }); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should support relative sourceRoot paths in sourcemaps', async () => { - const sourceFilename = 'relative-sourceRoot-source-map.txt'; + it("should support relative sourceRoot paths in sourcemaps", async () => { + const sourceFilename = "relative-sourceRoot-source-map.txt"; const rootRelativeSourcePath = path.join( __dirname, - 'fixtures', - 'data', + "fixtures", + "data", sourceFilename ); const sourceMapPath = path.join( __dirname, - 'fixtures', - 'relative-sourceRoot-source-map.map' + "fixtures", + "relative-sourceRoot-source-map.map" ); - const testId = 'relative-sourceRoot-source-map.js'; + const testId = "relative-sourceRoot-source-map.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); @@ -358,84 +358,84 @@ describe('source-map-loader', () => { expect(deps.has(fixture)).toBe(true); }); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should support indexed sourcemaps', async () => { + it("should support indexed sourcemaps", async () => { const currentDirPath = path.join( __dirname, - 'fixtures', - 'indexed-sourcemap' + "fixtures", + "indexed-sourcemap" ); - const testId = path.join(currentDirPath, 'file.js'); + const testId = path.join(currentDirPath, "file.js"); const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); const deps = stats.compilation.fileDependencies; const dependencies = [ - path.join(currentDirPath, 'file.js'), - path.join(currentDirPath, 'file.js.map'), + path.join(currentDirPath, "file.js"), + path.join(currentDirPath, "file.js.map"), ]; dependencies.forEach((fixture) => { expect(deps.has(fixture)).toBe(true); }); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should support indexed sourcemaps 2', async () => { + it("should support indexed sourcemaps 2", async () => { const currentDirPath = path.join( __dirname, - 'fixtures', - 'indexed-sourcemap' + "fixtures", + "indexed-sourcemap" ); - const testId = path.join(currentDirPath, 'file2.js'); + const testId = path.join(currentDirPath, "file2.js"); const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); const deps = stats.compilation.fileDependencies; const dependencies = [ - path.join(currentDirPath, 'file2.js'), - path.join(currentDirPath, 'file2.js.map'), + path.join(currentDirPath, "file2.js"), + path.join(currentDirPath, "file2.js.map"), ]; dependencies.forEach((fixture) => { expect(deps.has(fixture)).toBe(true); }); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should transform to webpack', async () => { + it("should transform to webpack", async () => { const currentDirPath = path.join( __dirname, - 'fixtures', - 'indexed-sourcemap' + "fixtures", + "indexed-sourcemap" ); - const testId = path.join(currentDirPath, 'file.js'); + const testId = path.join(currentDirPath, "file.js"); const compiler = getCompiler(testId, {}, {}, true); const stats = await compile(compiler); - const bundle = readAsset('main.bundle.js.map', compiler, stats); + const bundle = readAsset("main.bundle.js.map", compiler, stats); const dependencies = [ - 'indexed-sourcemap/nested1.js', - 'nested2.js', - 'webpack/bootstrap', + "indexed-sourcemap/nested1.js", + "nested2.js", + "webpack/bootstrap", ]; // Todo: rewrite when we will fix issue whith unresolved paths @@ -444,37 +444,37 @@ describe('source-map-loader', () => { }); }); - it('should process protocol-relative-url-path', async () => { - const testId = 'protocol-relative-url-path.js'; + it("should process protocol-relative-url-path", async () => { + const testId = "protocol-relative-url-path.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeUndefined(); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should support mixed paths in sources without sourceRoot', async () => { - const sourceRoot = path.resolve(__dirname, 'fixtures'); - const javaScriptFilename = 'absolute-path.js'; + it("should support mixed paths in sources without sourceRoot", async () => { + const sourceRoot = path.resolve(__dirname, "fixtures"); + const javaScriptFilename = "absolute-path.js"; const entryFileAbsolutePath = path.join(sourceRoot, javaScriptFilename); const sourceMapPath = path.join( sourceRoot, - 'map-without-sourceroot.js.map' + "map-without-sourceroot.js.map" ); // Create the sourcemap file const rawSourceMap = { version: 3, sources: [ - 'normal-file.js', - path.resolve(__dirname, 'fixtures', 'normal-file2.js'), - 'http://path-to-map.com', - 'ftp://path-to-map.com', + "normal-file.js", + path.resolve(__dirname, "fixtures", "normal-file2.js"), + "http://path-to-map.com", + "ftp://path-to-map.com", ], - mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA', + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA", }; fs.writeFileSync(sourceMapPath, JSON.stringify(rawSourceMap)); @@ -487,29 +487,29 @@ describe('source-map-loader', () => { const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should support mixed paths in sources with sourceRoot', async () => { - const sourceRoot = path.resolve(__dirname, 'fixtures'); - const javaScriptFilename = 'absolute-path.js'; + it("should support mixed paths in sources with sourceRoot", async () => { + const sourceRoot = path.resolve(__dirname, "fixtures"); + const javaScriptFilename = "absolute-path.js"; const entryFileAbsolutePath = path.join(sourceRoot, javaScriptFilename); - const sourceMapPath = path.join(sourceRoot, 'map-with-sourceroot.js.map'); + const sourceMapPath = path.join(sourceRoot, "map-with-sourceroot.js.map"); // Create the sourcemap file const rawSourceMap = { version: 3, sourceRoot, sources: [ - 'normal-file.js', - path.resolve(__dirname, 'fixtures', 'normal-file2.js'), - 'http://path-to-map.com', - 'ftp://path-to-map.com', + "normal-file.js", + path.resolve(__dirname, "fixtures", "normal-file2.js"), + "http://path-to-map.com", + "ftp://path-to-map.com", ], - mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA', + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA", }; fs.writeFileSync(sourceMapPath, JSON.stringify(rawSourceMap)); @@ -522,27 +522,27 @@ describe('source-map-loader', () => { const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should support absolute paths to sourcemaps', async () => { - const sourceRoot = path.resolve(__dirname, 'fixtures'); - const javaScriptFilename = 'absolute-path.js'; + it("should support absolute paths to sourcemaps", async () => { + const sourceRoot = path.resolve(__dirname, "fixtures"); + const javaScriptFilename = "absolute-path.js"; const entryFileAbsolutePath = path.join(sourceRoot, javaScriptFilename); - const sourceMapPath = path.join(sourceRoot, 'normal-map.js.map'); + const sourceMapPath = path.join(sourceRoot, "normal-map.js.map"); // Create the sourcemap file const rawSourceMap = { version: 3, sourceRoot, sources: [ - 'normal-file.js', - path.resolve(__dirname, 'fixtures', 'normal-file2.js'), + "normal-file.js", + path.resolve(__dirname, "fixtures", "normal-file2.js"), ], - mappings: 'CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA', + mappings: "CAAC,IAAI,IAAM,SAAUA,GAClB,OAAOA", }; fs.writeFileSync(sourceMapPath, JSON.stringify(rawSourceMap)); @@ -555,84 +555,84 @@ describe('source-map-loader', () => { const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should reject not support url', async () => { - const testId = 'unSupport-file-source-map.js'; + it("should reject not support url", async () => { + const testId = "unSupport-file-source-map.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should process inlined sources', async () => { - const testId = 'inline-sources.js'; + it("should process inlined sources", async () => { + const testId = "inline-sources.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should process css sourceMap', async () => { - const testId = 'app.css'; + it("should process css sourceMap", async () => { + const testId = "app.css"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should process css sourceMap', async () => { - const testId = 'skip-sourcesContent.js'; + it("should process css sourceMap", async () => { + const testId = "skip-sourcesContent.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); expect(codeFromBundle.map).toBeDefined(); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should allow to filter warnings', async () => { - const testId = 'invalid-inline-source-map2.js'; + it("should allow to filter warnings", async () => { + const testId = "invalid-inline-source-map2.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); expect( stats.toString({ warningsFilter: /Failed to parse source map/ }) - ).not.toContain('Failed to parse source map'); + ).not.toContain("Failed to parse source map"); expect(codeFromBundle.map).toBeUndefined(); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should process server-relative-url-path', async () => { - const sourceRoot = path.resolve(__dirname, 'fixtures'); - const javaScriptFilename = 'server-relative-url-path.js'; - const sourceFilename = 'server-relative-url-path.js'; + it("should process server-relative-url-path", async () => { + const sourceRoot = path.resolve(__dirname, "fixtures"); + const javaScriptFilename = "server-relative-url-path.js"; + const sourceFilename = "server-relative-url-path.js"; const sourceMapPath = path.join( sourceRoot, - 'server-relative-url-path.js.map' + "server-relative-url-path.js.map" ); // Create the sourcemap file @@ -641,48 +641,48 @@ describe('source-map-loader', () => { file: javaScriptFilename, sourceRoot, sources: [sourceFilename], - mappings: 'AAAA', + mappings: "AAAA", }; fs.writeFileSync(sourceMapPath, JSON.stringify(rawSourceMap)); - const testId = 'server-relative-url-path.js'; + const testId = "server-relative-url-path.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should emit warning when unresolved server-relative-url-path', async () => { - const testId = 'unresolved-server-relative-url-path.js'; + it("should emit warning when unresolved server-relative-url-path", async () => { + const testId = "unresolved-server-relative-url-path.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(getWarnings(stats, true)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(getWarnings(stats, true)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should add only valid `sources` to dependencies', async () => { - const testId = 'dependencies.js'; + it("should add only valid `sources` to dependencies", async () => { + const testId = "dependencies.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); const deps = stats.compilation.fileDependencies; const dependencies = [ - path.resolve(__dirname, 'fixtures', 'dependencies.js.map'), + path.resolve(__dirname, "fixtures", "dependencies.js.map"), path.resolve( __dirname, - 'fixtures', - 'data/relative-sourceRoot-source-map.txt' + "fixtures", + "data/relative-sourceRoot-source-map.txt" ), ]; - const notInDependencies = ['', 'data:invalid;A;a', './data/not-found.txt']; + const notInDependencies = ["", "data:invalid;A;a", "./data/not-found.txt"]; dependencies.forEach((fixture) => { expect(deps.has(fixture)).toBe(true); @@ -690,28 +690,28 @@ describe('source-map-loader', () => { notInDependencies.forEach((fixture) => { expect(deps.has(fixture)).toBe(false); }); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); - it('should add only valid `sources` with `sourceContent` to dependencies', async () => { - const testId = 'dependencies2.js'; + it("should add only valid `sources` with `sourceContent` to dependencies", async () => { + const testId = "dependencies2.js"; const compiler = getCompiler(testId); const stats = await compile(compiler); const codeFromBundle = getCodeFromBundle(stats, compiler); const deps = stats.compilation.fileDependencies; const dependencies = [ - path.resolve(__dirname, 'fixtures', 'dependencies2.js.map'), + path.resolve(__dirname, "fixtures", "dependencies2.js.map"), ]; const notInDependencies = [ - './data/relative-sourceRoot-source-map.txt', - path.resolve(__dirname, './data/relative-sourceRoot-source-map.txt'), - './data/not-found.txt', - 'data:application/json;base64,c29tZSBraW5kIGNvbnRlbnQ=', - 'data:invalid;A;a', + "./data/relative-sourceRoot-source-map.txt", + path.resolve(__dirname, "./data/relative-sourceRoot-source-map.txt"), + "./data/not-found.txt", + "data:application/json;base64,c29tZSBraW5kIGNvbnRlbnQ=", + "data:invalid;A;a", ]; dependencies.forEach((fixture) => { @@ -720,9 +720,9 @@ describe('source-map-loader', () => { notInDependencies.forEach((fixture) => { expect(deps.has(fixture)).toBe(false); }); - expect(codeFromBundle.css).toMatchSnapshot('css'); - expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot('map'); - expect(getWarnings(stats)).toMatchSnapshot('warnings'); - expect(getErrors(stats)).toMatchSnapshot('errors'); + expect(codeFromBundle.css).toMatchSnapshot("css"); + expect(normalizeMap(codeFromBundle.map)).toMatchSnapshot("map"); + expect(getWarnings(stats)).toMatchSnapshot("warnings"); + expect(getErrors(stats)).toMatchSnapshot("errors"); }); }); diff --git a/test/parseDataUrl.test.js b/test/parseDataUrl.test.js index c090a72..505dc83 100644 --- a/test/parseDataUrl.test.js +++ b/test/parseDataUrl.test.js @@ -1,8 +1,8 @@ -import parseDataUrl from '../src/parse-data-url'; +import parseDataUrl from "../src/parse-data-url"; -import dataUrls from './fixtures/json/data-urls.json'; +import dataUrls from "./fixtures/json/data-urls.json"; -describe('parse-data-url', () => { +describe("parse-data-url", () => { dataUrls.forEach((entry) => { it(`should work with "${entry}" url`, async () => { const [url, expected] = entry; diff --git a/test/sourceMapperRegexp.test.js b/test/sourceMapperRegexp.test.js index 8f1d98a..3d8b2a8 100644 --- a/test/sourceMapperRegexp.test.js +++ b/test/sourceMapperRegexp.test.js @@ -1,16 +1,16 @@ -import { getSourceMappingURL } from '../src/utils'; +import { getSourceMappingURL } from "../src/utils"; -describe('source-map-loader', () => { +describe("source-map-loader", () => { const cases = [ - '/*#sourceMappingURL=absolute-sourceRoot-source-map.map*/', - '/* #sourceMappingURL=absolute-sourceRoot-source-map.map */', - '//#sourceMappingURL=absolute-sourceRoot-source-map.map', - '//@sourceMappingURL=absolute-sourceRoot-source-map.map', - ' // #sourceMappingURL=absolute-sourceRoot-source-map.map', - ' // # sourceMappingURL = absolute-sourceRoot-source-map.map ', - '// #sourceMappingURL = http://sampledomain.com/external-source-map2.map', - '// #sourceMappingURL = //sampledomain.com/external-source-map2.map', - '// @sourceMappingURL=data:application/source-map;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5saW5lLXNvdXJjZS1tYXAuanMiLCJzb3VyY2VzIjpbImlubGluZS1zb3VyY2UtbWFwLnR4dCJdLCJzb3VyY2VzQ29udGVudCI6WyJ3aXRoIFNvdXJjZU1hcCJdLCJtYXBwaW5ncyI6IkFBQUEifQ==', + "/*#sourceMappingURL=absolute-sourceRoot-source-map.map*/", + "/* #sourceMappingURL=absolute-sourceRoot-source-map.map */", + "//#sourceMappingURL=absolute-sourceRoot-source-map.map", + "//@sourceMappingURL=absolute-sourceRoot-source-map.map", + " // #sourceMappingURL=absolute-sourceRoot-source-map.map", + " // # sourceMappingURL = absolute-sourceRoot-source-map.map ", + "// #sourceMappingURL = http://sampledomain.com/external-source-map2.map", + "// #sourceMappingURL = //sampledomain.com/external-source-map2.map", + "// @sourceMappingURL=data:application/source-map;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5saW5lLXNvdXJjZS1tYXAuanMiLCJzb3VyY2VzIjpbImlubGluZS1zb3VyY2UtbWFwLnR4dCJdLCJzb3VyY2VzQ29udGVudCI6WyJ3aXRoIFNvdXJjZU1hcCJdLCJtYXBwaW5ncyI6IkFBQUEifQ==", ` with SourceMap @@ -34,7 +34,7 @@ describe('source-map-loader', () => { it(`should work with "${item}" url`, async () => { const { sourceMappingURL } = getSourceMappingURL(item); - expect(sourceMappingURL).toMatchSnapshot('result'); + expect(sourceMappingURL).toMatchSnapshot("result"); }); }); }); diff --git a/test/validate-options.test.js b/test/validate-options.test.js index cc0d213..e406f34 100644 --- a/test/validate-options.test.js +++ b/test/validate-options.test.js @@ -1,21 +1,21 @@ -import { getCompiler, compile } from './helpers'; +import { getCompiler, compile } from "./helpers"; -describe('validate options', () => { +describe("validate options", () => { const tests = { filterSourceMappingUrl: { - success: [() => false, () => 'false', () => 'remove', () => 'skip'], - failure: [1, true, false, 'test', /test/, [], {}, { foo: 'bar' }], + success: [() => false, () => "false", () => "remove", () => "skip"], + failure: [1, true, false, "test", /test/, [], {}, { foo: "bar" }], }, unknown: { success: [], - failure: [1, true, false, 'test', /test/, [], {}, { foo: 'bar' }], + failure: [1, true, false, "test", /test/, [], {}, { foo: "bar" }], }, }; function stringifyValue(value) { if ( Array.isArray(value) || - (value && typeof value === 'object' && value.constructor === Object) + (value && typeof value === "object" && value.constructor === Object) ) { return JSON.stringify(value); } @@ -25,18 +25,18 @@ describe('validate options', () => { async function createTestCase(key, value, type) { it(`should ${ - type === 'success' ? 'successfully validate' : 'throw an error on' + type === "success" ? "successfully validate" : "throw an error on" } the "${key}" option with "${stringifyValue(value)}" value`, async () => { - const compiler = getCompiler('normal-file.js', { [key]: value }); + const compiler = getCompiler("normal-file.js", { [key]: value }); let stats; try { stats = await compile(compiler); } finally { - if (type === 'success') { + if (type === "success") { expect(stats.hasErrors()).toBe(false); - } else if (type === 'failure') { + } else if (type === "failure") { const { compilation: { errors }, } = stats;