From c4402d5a9fde430a53323b34521ade0711b5949c Mon Sep 17 00:00:00 2001 From: cap-Bernardito Date: Wed, 19 Aug 2020 20:08:55 +0300 Subject: [PATCH] refactor: sourcemap processing --- .gitignore | 1 - package-lock.json | 172 ++++++++++++++++++ package.json | 3 + src/index.js | 22 ++- src/utils.js | 61 ++++++- .../sourceMap-option.test.js.snap | 159 ++++++++++++---- test/fixtures/source-map/base.less | 7 + test/fixtures/source-map/base.styl | 6 + test/fixtures/source-map/basic-less.js | 5 + test/fixtures/source-map/basic-styl.js | 5 + test/sourceMap-option.test.js | 119 ++++++++++-- 11 files changed, 501 insertions(+), 59 deletions(-) create mode 100644 test/fixtures/source-map/base.less create mode 100644 test/fixtures/source-map/base.styl create mode 100644 test/fixtures/source-map/basic-less.js create mode 100644 test/fixtures/source-map/basic-styl.js diff --git a/.gitignore b/.gitignore index 9c22fc5a4..6927f6c77 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -logs *.log npm-debug.log* .eslintcache diff --git a/package-lock.json b/package-lock.json index 2cd84b336..86c249ce6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3734,6 +3734,12 @@ "wrap-ansi": "^6.2.0" } }, + "clone": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz", + "integrity": "sha1-G39Ln1kfHo+DZwQBYANFoCiHQ18=", + "dev": true + }, "co": { "version": "4.6.0", "resolved": "https://registry.npmjs.org/co/-/co-4.6.0.tgz", @@ -4807,6 +4813,18 @@ "randomfill": "^1.0.3" } }, + "css": { + "version": "2.2.4", + "resolved": "https://registry.npmjs.org/css/-/css-2.2.4.tgz", + "integrity": "sha512-oUnjmWpy0niI3x/mPL8dVEI1l7MnG3+HHyRPHf+YFSbK+svOhXpmSOcDURUh2aOCgl2grzrOPt1nHLuCVFULLw==", + "dev": true, + "requires": { + "inherits": "^2.0.3", + "source-map": "^0.6.1", + "source-map-resolve": "^0.5.2", + "urix": "^0.1.0" + } + }, "css-blank-pseudo": { "version": "0.1.4", "resolved": "https://registry.npmjs.org/css-blank-pseudo/-/css-blank-pseudo-0.1.4.tgz", @@ -4845,6 +4863,15 @@ } } }, + "css-parse": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/css-parse/-/css-parse-2.0.0.tgz", + "integrity": "sha1-pGjuZnwW2BzPBcWMONKpfHgNv9Q=", + "dev": true, + "requires": { + "css": "^2.0.0" + } + }, "css-prefers-color-scheme": { "version": "3.1.1", "resolved": "https://registry.npmjs.org/css-prefers-color-scheme/-/css-prefers-color-scheme-3.1.1.tgz", @@ -7369,6 +7396,13 @@ "integrity": "sha512-BMpfD7PpiETpBl/A6S498BaIJ6Y/ABT93ETbby2fP00v4EbvPBXWEoaR1UBPKs3iR53pJY7EtZk5KACI57i1Uw==", "dev": true }, + "image-size": { + "version": "0.5.5", + "resolved": "https://registry.npmjs.org/image-size/-/image-size-0.5.5.tgz", + "integrity": "sha1-Cd/Uq50g4p6xw+gLiZA3jfnjy5w=", + "dev": true, + "optional": true + }, "import-cwd": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/import-cwd/-/import-cwd-2.1.0.tgz", @@ -9640,6 +9674,34 @@ "integrity": "sha512-xf88rTeHiXk+XE2Vhi6yj8Wm3gMZrygGdKjJqN8HkV+PwF/t50/LdAKHoHpPcxFAlmQszTZ1CugrK25S7qDRLA==", "dev": true }, + "less": { + "version": "3.12.2", + "resolved": "https://registry.npmjs.org/less/-/less-3.12.2.tgz", + "integrity": "sha512-+1V2PCMFkL+OIj2/HrtrvZw0BC0sYLMICJfbQjuj/K8CEnlrFX6R5cKKgzzttsZDHyxQNL1jqMREjKN3ja/E3Q==", + "dev": true, + "requires": { + "errno": "^0.1.1", + "graceful-fs": "^4.1.2", + "image-size": "~0.5.0", + "make-dir": "^2.1.0", + "mime": "^1.4.1", + "native-request": "^1.0.5", + "source-map": "~0.6.0", + "tslib": "^1.10.0" + } + }, + "less-loader": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/less-loader/-/less-loader-6.2.0.tgz", + "integrity": "sha512-Cl5h95/Pz/PWub/tCBgT1oNMFeH1WTD33piG80jn5jr12T4XbxZcjThwNXDQ7AG649WEynuIzO4b0+2Tn9Qolg==", + "dev": true, + "requires": { + "clone": "^2.1.2", + "less": "^3.11.3", + "loader-utils": "^2.0.0", + "schema-utils": "^2.7.0" + } + }, "leven": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/leven/-/leven-3.1.0.tgz", @@ -10056,6 +10118,12 @@ "integrity": "sha1-soqmKIorn8ZRA1x3EfZathkDMaY=", "dev": true }, + "lodash.clonedeep": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.clonedeep/-/lodash.clonedeep-4.5.0.tgz", + "integrity": "sha1-4j8/nE+Pvd6HJSnBBxhXoIblzO8=", + "dev": true + }, "lodash.difference": { "version": "4.5.0", "resolved": "https://registry.npmjs.org/lodash.difference/-/lodash.difference-4.5.0.tgz", @@ -10471,6 +10539,13 @@ } } }, + "mime": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-1.6.0.tgz", + "integrity": "sha512-x0Vn8spI+wuJ1O6S7gnbaQg8Pxh4NNHb7KSINmEWKiPE4RKOplvijn+NkmYmmRgP68mc70j2EbeTFRsrswaQeg==", + "dev": true, + "optional": true + }, "mime-db": { "version": "1.44.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.44.0.tgz", @@ -10796,6 +10871,13 @@ "to-regex": "^3.0.1" } }, + "native-request": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/native-request/-/native-request-1.0.7.tgz", + "integrity": "sha512-9nRjinI9bmz+S7dgNtf4A70+/vPhnd+2krGpy4SUlADuOuSa24IDkNaZ+R/QT1wQ6S8jBdi6wE7fLekFZNfUpQ==", + "dev": true, + "optional": true + }, "natural-compare": { "version": "1.4.0", "resolved": "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz", @@ -12827,6 +12909,12 @@ "semver": "^7.3.2" } }, + "sax": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/sax/-/sax-1.2.4.tgz", + "integrity": "sha512-NqVDv9TpANUjFm0N8uM5GxL36UgKi9/atZw+x7YFnQ8ckwFGKrl4xX4yWtrey3UJm5nP1kUbnYgLopqWNSRhWw==", + "dev": true + }, "saxes": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/saxes/-/saxes-5.0.1.tgz", @@ -13559,6 +13647,84 @@ "schema-utils": "^2.6.6" } }, + "stylus": { + "version": "0.54.8", + "resolved": "https://registry.npmjs.org/stylus/-/stylus-0.54.8.tgz", + "integrity": "sha512-vr54Or4BZ7pJafo2mpf0ZcwA74rpuYCZbxrHBsH8kbcXOwSfvBFwsRfpGO5OD5fhG5HDCFW737PKaawI7OqEAg==", + "dev": true, + "requires": { + "css-parse": "~2.0.0", + "debug": "~3.1.0", + "glob": "^7.1.6", + "mkdirp": "~1.0.4", + "safer-buffer": "^2.1.2", + "sax": "~1.2.4", + "semver": "^6.3.0", + "source-map": "^0.7.3" + }, + "dependencies": { + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "dev": true, + "requires": { + "ms": "2.0.0" + } + }, + "mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "dev": true + }, + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + }, + "source-map": { + "version": "0.7.3", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.7.3.tgz", + "integrity": "sha512-CkCj6giN3S+n9qrYiBTX5gystlENnRW5jZeNLHpe6aue+SrHcG5VYwujhW9s4dY31mEGsxBDrHR6oI69fTXsaQ==", + "dev": true + } + } + }, + "stylus-loader": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/stylus-loader/-/stylus-loader-3.0.2.tgz", + "integrity": "sha512-+VomPdZ6a0razP+zinir61yZgpw2NfljeSsdUF5kJuEzlo3khXhY19Fn6l8QQz1GRJGtMCo8nG5C04ePyV7SUA==", + "dev": true, + "requires": { + "loader-utils": "^1.0.2", + "lodash.clonedeep": "^4.5.0", + "when": "~3.6.x" + }, + "dependencies": { + "json5": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/json5/-/json5-1.0.1.tgz", + "integrity": "sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow==", + "dev": true, + "requires": { + "minimist": "^1.2.0" + } + }, + "loader-utils": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/loader-utils/-/loader-utils-1.4.0.tgz", + "integrity": "sha512-qH0WSMBtn/oHuwjy/NucEgbx5dbxxnxup9s4PVXJUDHZBQY+s0NWA9rJf53RBnQZxfch7euUui7hpoAPvALZdA==", + "dev": true, + "requires": { + "big.js": "^5.2.2", + "emojis-list": "^3.0.0", + "json5": "^1.0.1" + } + } + } + }, "supports-color": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-6.1.0.tgz", @@ -14558,6 +14724,12 @@ } } }, + "when": { + "version": "3.6.4", + "resolved": "https://registry.npmjs.org/when/-/when-3.6.4.tgz", + "integrity": "sha1-RztRfsFZ4rhQBUl6E5g/CVQS404=", + "dev": true + }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", diff --git a/package.json b/package.json index 860037073..f1a8e7c62 100644 --- a/package.json +++ b/package.json @@ -76,6 +76,7 @@ "file-loader": "^6.0.0", "husky": "^4.2.5", "jest": "^26.1.0", + "less-loader": "^6.2.0", "lint-staged": "^10.2.11", "memfs": "^3.2.0", "mini-css-extract-plugin": "^0.9.0", @@ -88,6 +89,8 @@ "standard-version": "^8.0.2", "strip-ansi": "^6.0.0", "style-loader": "^1.2.1", + "stylus": "^0.54.8", + "stylus-loader": "^3.0.2", "url-loader": "^4.1.0", "webpack": "^4.44.0" }, diff --git a/src/index.js b/src/index.js index b96e3c417..3cb532ee1 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,8 @@ MIT License http://www.opensource.org/licenses/mit-license.php Author Tobias Koppers @sokra */ +import path from 'path'; + import { getOptions, stringifyRequest } from 'loader-utils'; import postcss from 'postcss'; import postcssPkg from 'postcss/package.json'; @@ -26,6 +28,7 @@ import { getModulesPlugins, normalizeSourceMap, sort, + getSourceMapRelativePath, } from './utils'; export default async function loader(content, map, meta) { @@ -151,6 +154,14 @@ export default async function loader(content, map, meta) { } } + const sourceMap = map ? normalizeSourceMap(map) : null; + + if (sourceMap) { + sourceMap.sources = sourceMap.sources.map((src) => + getSourceMapRelativePath(src, path.dirname(this.resourcePath)) + ); + } + let result; try { @@ -160,7 +171,7 @@ export default async function loader(content, map, meta) { map: options.sourceMap ? { // Some loaders (example `"postcss-loader": "1.x.x"`) always generates source map, we should remove it - prev: map ? normalizeSourceMap(map) : null, + prev: sourceMap, inline: false, annotation: false, } @@ -198,7 +209,14 @@ export default async function loader(content, map, meta) { } const importCode = getImportCode(imports, options); - const moduleCode = getModuleCode(result, api, replacements, options); + const moduleCode = getModuleCode( + result, + api, + replacements, + options, + this.resourcePath, + this.rootContext + ); const exportCode = getExportCode(exports, replacements, options); callback(null, `${importCode}${moduleCode}${exportCode}`); diff --git a/src/utils.js b/src/utils.js index b0664020b..afe154ece 100644 --- a/src/utils.js +++ b/src/utils.js @@ -308,15 +308,21 @@ function normalizeSourceMap(map) { // We should normalize path because previous loaders like `sass-loader` using backslash when generate source map if (newMap.file) { - newMap.file = normalizePath(newMap.file); + delete newMap.file; } + const { sourceRoot } = newMap; + if (newMap.sourceRoot) { - newMap.sourceRoot = normalizePath(newMap.sourceRoot); + delete newMap.sourceRoot; } if (newMap.sources) { - newMap.sources = newMap.sources.map((source) => normalizePath(source)); + newMap.sources = newMap.sources.map((source) => { + return !sourceRoot + ? normalizePath(source) + : normalizePath(path.resolve(sourceRoot, source)); + }); } return newMap; @@ -370,13 +376,57 @@ function getImportCode(imports, options) { return code ? `// Imports\n${code}` : ''; } -function getModuleCode(result, api, replacements, options) { +function getSourceMapRelativePath(file, from) { + if (file.indexOf('<') === 0) return file; + if (/^\w+:\/\//.test(file)) return file; + + const result = path.relative(from, file); + + if (path.sep === '\\') { + return result.replace(/\\/g, '/'); + } + + return result; +} + +function getSourceMapContextifyPath(file, to, rootContext) { + if (file.indexOf('<') === 0) return file; + if (/^\w+:\/\//.test(file)) return file; + + if (typeof to === 'undefined') return file; + + const dirname = path.dirname(to); + + const result = path.resolve(dirname, file); + + if (path.sep === '\\') { + return result.replace(/\\/g, '/'); + } + + return `webpack:///${path.relative(rootContext, result)}`; +} + +function getModuleCode(result, api, replacements, options, to, rootContext) { if (options.modules.exportOnlyLocals === true) { return ''; } const { css, map } = result; - const sourceMapValue = options.sourceMap && map ? `,${map}` : ''; + + const sourceMap = map ? JSON.parse(map.toString()) : null; + + if (sourceMap) { + if (typeof sourceMap.file !== 'undefined') { + delete sourceMap.file; + } + + sourceMap.sources = sourceMap.sources.map((src) => + getSourceMapContextifyPath(src, to, rootContext) + ); + } + + const sourceMapValue = + options.sourceMap && sourceMap ? `,${JSON.stringify(sourceMap)}` : ''; let code = JSON.stringify(css); let beforeCode = `var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(${options.sourceMap});\n`; @@ -594,4 +644,5 @@ export { resolveRequests, isUrlRequestable, sort, + getSourceMapRelativePath, }; diff --git a/test/__snapshots__/sourceMap-option.test.js.snap b/test/__snapshots__/sourceMap-option.test.js.snap index c0cf72302..f016508c1 100644 --- a/test/__snapshots__/sourceMap-option.test.js.snap +++ b/test/__snapshots__/sourceMap-option.test.js.snap @@ -301,7 +301,7 @@ exports[`"sourceMap" option true should generate source maps #2: module 1`] = ` import ___CSS_LOADER_API_IMPORT___ from \\"../../../src/runtime/api.js\\"; var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(true); // Module -___CSS_LOADER_EXPORT___.push([module.id, \\".foo {\\\\n color: red;\\\\n}\\\\n\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"with-query.css\\"],\\"names\\":[],\\"mappings\\":\\"AAAA;EACE,UAAU;AACZ\\",\\"file\\":\\"with-query.css\\",\\"sourcesContent\\":[\\".foo {\\\\n color: red;\\\\n}\\\\n\\"]}]); +___CSS_LOADER_EXPORT___.push([module.id, \\".foo {\\\\n color: red;\\\\n}\\\\n\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"webpack:///source-map/with-query.css\\"],\\"names\\":[],\\"mappings\\":\\"AAAA;EACE,UAAU;AACZ\\",\\"sourcesContent\\":[\\".foo {\\\\n color: red;\\\\n}\\\\n\\"]}]); // Exports export default ___CSS_LOADER_EXPORT___; " @@ -317,11 +317,10 @@ Array [ ", "", Object { - "file": "with-query.css", "mappings": "AAAA;EACE,UAAU;AACZ", "names": Array [], "sources": Array [ - "with-query.css", + "webpack:///source-map/with-query.css", ], "sourcesContent": Array [ ".foo { @@ -346,7 +345,7 @@ import ___CSS_LOADER_AT_RULE_IMPORT_0___ from \\"-!../../../src/index.js??[ident var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(true); ___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___); // Module -___CSS_LOADER_EXPORT___.push([module.id, \\".class {\\\\n color: red;\\\\n}\\\\n\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"basic.css\\"],\\"names\\":[],\\"mappings\\":\\"AAEA;EACE,UAAU;AACZ\\",\\"file\\":\\"basic.css\\",\\"sourcesContent\\":[\\"@import \\\\\\"./nested/nested.css\\\\\\";\\\\n\\\\n.class {\\\\n color: red;\\\\n}\\\\n\\"]}]); +___CSS_LOADER_EXPORT___.push([module.id, \\".class {\\\\n color: red;\\\\n}\\\\n\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"webpack:///source-map/basic.css\\"],\\"names\\":[],\\"mappings\\":\\"AAEA;EACE,UAAU;AACZ\\",\\"sourcesContent\\":[\\"@import \\\\\\"./nested/nested.css\\\\\\";\\\\n\\\\n.class {\\\\n color: red;\\\\n}\\\\n\\"]}]); // Exports export default ___CSS_LOADER_EXPORT___; " @@ -362,11 +361,10 @@ Array [ ", "", Object { - "file": "nested.css", "mappings": "AAAA;EACE,WAAW;AACb", "names": Array [], "sources": Array [ - "nested.css", + "webpack:///source-map/nested/nested.css", ], "sourcesContent": Array [ ".nested { @@ -385,11 +383,10 @@ Array [ ", "", Object { - "file": "basic.css", "mappings": "AAEA;EACE,UAAU;AACZ", "names": Array [], "sources": Array [ - "basic.css", + "webpack:///source-map/basic.css", ], "sourcesContent": Array [ "@import \\"./nested/nested.css\\"; @@ -416,7 +413,7 @@ import ___CSS_LOADER_AT_RULE_IMPORT_0___ from \\"-!../../../src/index.js??[ident var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(true); ___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___); // Module -___CSS_LOADER_EXPORT___.push([module.id, \\".class {\\\\n color: red;\\\\n}\\\\n\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"basic.css\\"],\\"names\\":[],\\"mappings\\":\\"AAEA;EACE,UAAU;AACZ\\",\\"file\\":\\"basic.css\\",\\"sourcesContent\\":[\\"@import \\\\\\"./nested/nested.css\\\\\\";\\\\n\\\\n.class {\\\\n color: red;\\\\n}\\\\n\\"]}]); +___CSS_LOADER_EXPORT___.push([module.id, \\".class {\\\\n color: red;\\\\n}\\\\n\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"webpack:///source-map/basic.css\\"],\\"names\\":[],\\"mappings\\":\\"AAEA;EACE,UAAU;AACZ\\",\\"sourcesContent\\":[\\"@import \\\\\\"./nested/nested.css\\\\\\";\\\\n\\\\n.class {\\\\n color: red;\\\\n}\\\\n\\"]}]); // Exports export default ___CSS_LOADER_EXPORT___; " @@ -432,11 +429,10 @@ Array [ ", "", Object { - "file": "nested.css", "mappings": "AAAA;EACE,WAAW;AACb", "names": Array [], "sources": Array [ - "nested.css", + "webpack:///source-map/nested/nested.css", ], "sourcesContent": Array [ ".nested { @@ -455,11 +451,10 @@ Array [ ", "", Object { - "file": "basic.css", "mappings": "AAEA;EACE,UAAU;AACZ", "names": Array [], "sources": Array [ - "basic.css", + "webpack:///source-map/basic.css", ], "sourcesContent": Array [ "@import \\"./nested/nested.css\\"; @@ -486,7 +481,7 @@ import ___CSS_LOADER_AT_RULE_IMPORT_0___ from \\"-!../../../src/index.js??[ident var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(true); ___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___); // Module -___CSS_LOADER_EXPORT___.push([module.id, \\".class {\\\\n color: red;\\\\n}\\\\n\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"/fixtures/source-map/basic.css\\",\\"basic.css\\"],\\"names\\":[],\\"mappings\\":\\"AAEA;ECCE,UAAU;AACZ\\",\\"file\\":\\"basic.css\\",\\"sourcesContent\\":[\\".class {\\\\n color: red;\\\\n}\\\\n\\",\\"@import \\\\\\"./nested/nested.css\\\\\\";\\\\n\\\\n.class {\\\\n color: red;\\\\n}\\\\n\\"]}]); +___CSS_LOADER_EXPORT___.push([module.id, \\".class {\\\\n color: red;\\\\n}\\\\n\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"webpack:///source-map/basic.css\\"],\\"names\\":[],\\"mappings\\":\\"AAEA;EACE,UAAU;AACZ\\",\\"sourcesContent\\":[\\"@import \\\\\\"./nested/nested.css\\\\\\";\\\\n\\\\n.class {\\\\n color: red;\\\\n}\\\\n\\"]}]); // Exports export default ___CSS_LOADER_EXPORT___; " @@ -502,11 +497,10 @@ Array [ ", "", Object { - "file": "nested.css", "mappings": "AAAA;EACE,WAAW;AACb", "names": Array [], "sources": Array [ - "nested.css", + "webpack:///source-map/nested/nested.css", ], "sourcesContent": Array [ ".nested { @@ -525,18 +519,12 @@ Array [ ", "", Object { - "file": "basic.css", - "mappings": "AAEA;ECCE,UAAU;AACZ", + "mappings": "AAEA;EACE,UAAU;AACZ", "names": Array [], "sources": Array [ - "/fixtures/source-map/basic.css", - "basic.css", + "webpack:///source-map/basic.css", ], "sourcesContent": Array [ - ".class { - color: red; -} -", "@import \\"./nested/nested.css\\"; .class { @@ -561,7 +549,7 @@ import ___CSS_LOADER_AT_RULE_IMPORT_0___ from \\"-!../../../src/index.js??[ident var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(true); ___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___); // Module -___CSS_LOADER_EXPORT___.push([module.id, \\".class {\\\\n color: red;\\\\n}\\\\n\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"basic.css\\"],\\"names\\":[],\\"mappings\\":\\"AAEA;EACE,UAAU;AACZ\\",\\"file\\":\\"basic.css\\",\\"sourcesContent\\":[\\".class {\\\\n color: red;\\\\n}\\\\n\\"]}]); +___CSS_LOADER_EXPORT___.push([module.id, \\".class {\\\\n color: red;\\\\n}\\\\n\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"webpack:///source-map/basic.css\\"],\\"names\\":[],\\"mappings\\":\\"AAEA;EACE,UAAU;AACZ\\",\\"sourcesContent\\":[\\"@import \\\\\\"./nested/nested.css\\\\\\";\\\\n\\\\n.class {\\\\n color: red;\\\\n}\\\\n\\"]}]); // Exports export default ___CSS_LOADER_EXPORT___; " @@ -577,11 +565,10 @@ Array [ ", "", Object { - "file": "nested.css", "mappings": "AAAA;EACE,WAAW;AACb", "names": Array [], "sources": Array [ - "nested.css", + "webpack:///source-map/nested/nested.css", ], "sourcesContent": Array [ ".nested { @@ -600,14 +587,15 @@ Array [ ", "", Object { - "file": "basic.css", "mappings": "AAEA;EACE,UAAU;AACZ", "names": Array [], "sources": Array [ - "basic.css", + "webpack:///source-map/basic.css", ], "sourcesContent": Array [ - ".class { + "@import \\"./nested/nested.css\\"; + +.class { color: red; } ", @@ -620,6 +608,53 @@ Array [ exports[`"sourceMap" option true should generate source maps when source maps is valid and string from an other loader: warnings 1`] = `Array []`; +exports[`"sourceMap" option true should generate source maps when source maps is valid from an other loader (\`less-loader\`): errors 1`] = `Array []`; + +exports[`"sourceMap" option true should generate source maps when source maps is valid from an other loader (\`less-loader\`): module 1`] = ` +"// Imports +import ___CSS_LOADER_API_IMPORT___ from \\"../../../src/runtime/api.js\\"; +var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(true); +// Module +___CSS_LOADER_EXPORT___.push([module.id, \\"body {\\\\n font: 100% Helvetica, sans-serif;\\\\n color: #333;\\\\n}\\\\n\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"webpack:///source-map/base.less\\"],\\"names\\":[],\\"mappings\\":\\"AAGA;EACE,gCAAA;EACA,WAAA;AAFF\\",\\"sourcesContent\\":[\\"@font-stack: Helvetica, sans-serif;\\\\n@primary-color: #333;\\\\n\\\\nbody {\\\\n font: 100% @font-stack;\\\\n color: @primary-color;\\\\n}\\\\n\\"]}]); +// Exports +export default ___CSS_LOADER_EXPORT___; +" +`; + +exports[`"sourceMap" option true should generate source maps when source maps is valid from an other loader (\`less-loader\`): result 1`] = ` +Array [ + Array [ + "./source-map/base.less", + "body { + font: 100% Helvetica, sans-serif; + color: #333; +} +", + "", + Object { + "mappings": "AAGA;EACE,gCAAA;EACA,WAAA;AAFF", + "names": Array [], + "sources": Array [ + "webpack:///source-map/base.less", + ], + "sourcesContent": Array [ + "@font-stack: Helvetica, sans-serif; +@primary-color: #333; + +body { + font: 100% @font-stack; + color: @primary-color; +} +", + ], + "version": 3, + }, + ], +] +`; + +exports[`"sourceMap" option true should generate source maps when source maps is valid from an other loader (\`less-loader\`): warnings 1`] = `Array []`; + exports[`"sourceMap" option true should generate source maps when source maps is valid from an other loader (\`postcss-loader\`): errors 1`] = `Array []`; exports[`"sourceMap" option true should generate source maps when source maps is valid from an other loader (\`postcss-loader\`): module 1`] = ` @@ -629,7 +664,7 @@ import ___CSS_LOADER_AT_RULE_IMPORT_0___ from \\"-!../../../src/index.js??[ident var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(true); ___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___); // Module -___CSS_LOADER_EXPORT___.push([module.id, \\":root {\\\\n --fontSize: 1rem;\\\\n --mainColor: rgba(18,52,86,0.47059);\\\\n --secondaryColor: rgba(102, 51, 153, 0.9);\\\\n}\\\\n\\\\nhtml {\\\\n overflow-x: hidden;\\\\n overflow-y: auto;\\\\n overflow: hidden auto;\\\\n}\\\\n\\\\n@media (max-width: 50rem) {\\\\n body {\\\\n color: rgba(18,52,86,0.47059);\\\\n color: var(--mainColor);\\\\n font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;\\\\n font-size: 1rem;\\\\n font-size: var(--fontSize);\\\\n line-height: calc(1rem * 1.5);\\\\n line-height: calc(var(--fontSize) * 1.5);\\\\n word-wrap: break-word;\\\\n padding-left: calc(1rem / 2 + 1px);\\\\n padding-right: calc(1rem / 2 + 1px);\\\\n padding-left: calc(var(--fontSize) / 2 + 1px);\\\\n padding-right: calc(var(--fontSize) / 2 + 1px);\\\\n }\\\\n}\\\\n\\\\nh1,h2,h3,h4,h5,h6 {\\\\n margin-top: 0;\\\\n margin-bottom: 0;\\\\n}\\\\n\\\\na {\\\\n color: rgba(0, 0, 255, 0.9)\\\\n}\\\\n\\\\na:hover {\\\\n color: #639;\\\\n }\\\\n\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"basic.postcss.css\\"],\\"names\\":[],\\"mappings\\":\\"AAKA;EACE,gBAAgB;EAChB,mCAAsB;EACtB,yCAA4C;AAC9C;;AAEA;EACE,kBAAqB;EAArB,gBAAqB;EAArB,qBAAqB;AACvB;;AAEA;EACE;IACE,6BAAuB;IAAvB,uBAAuB;IACvB,iGAAsB;IACtB,eAA0B;IAA1B,0BAA0B;IAC1B,6BAAwC;IAAxC,wCAAwC;IACxC,qBAAyB;IACzB,kCAA+C;IAA/C,mCAA+C;IAA/C,6CAA+C;IAA/C,8CAA+C;EACjD;AACF;;AAEA;EACE,aAAe;EAAf,gBAAe;AACjB;;AAEA;EACE;AAKF;;AAHA;GACG,WAAoB;CACtB\\",\\"file\\":\\"basic.postcss.css\\",\\"sourcesContent\\":[\\"@import \\\\\\"./nested/nested.postcss.css\\\\\\";\\\\n\\\\n@custom-media --viewport-medium (width <= 50rem);\\\\n@custom-selector :--heading h1, h2, h3, h4, h5, h6;\\\\n\\\\n:root {\\\\n --fontSize: 1rem;\\\\n --mainColor: #12345678;\\\\n --secondaryColor: lab(32.5 38.5 -47.6 / 90%);\\\\n}\\\\n\\\\nhtml {\\\\n overflow: hidden auto;\\\\n}\\\\n\\\\n@media (--viewport-medium) {\\\\n body {\\\\n color: var(--mainColor);\\\\n font-family: system-ui;\\\\n font-size: var(--fontSize);\\\\n line-height: calc(var(--fontSize) * 1.5);\\\\n overflow-wrap: break-word;\\\\n padding-inline: calc(var(--fontSize) / 2 + 1px);\\\\n }\\\\n}\\\\n\\\\n:--heading {\\\\n margin-block: 0;\\\\n}\\\\n\\\\na {\\\\n color: rgb(0 0 100% / 90%);\\\\n\\\\n&:hover {\\\\n color: rebeccapurple;\\\\n }\\\\n}\\\\n\\"]}]); +___CSS_LOADER_EXPORT___.push([module.id, \\":root {\\\\n --fontSize: 1rem;\\\\n --mainColor: rgba(18,52,86,0.47059);\\\\n --secondaryColor: rgba(102, 51, 153, 0.9);\\\\n}\\\\n\\\\nhtml {\\\\n overflow-x: hidden;\\\\n overflow-y: auto;\\\\n overflow: hidden auto;\\\\n}\\\\n\\\\n@media (max-width: 50rem) {\\\\n body {\\\\n color: rgba(18,52,86,0.47059);\\\\n color: var(--mainColor);\\\\n font-family: system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, sans-serif;\\\\n font-size: 1rem;\\\\n font-size: var(--fontSize);\\\\n line-height: calc(1rem * 1.5);\\\\n line-height: calc(var(--fontSize) * 1.5);\\\\n word-wrap: break-word;\\\\n padding-left: calc(1rem / 2 + 1px);\\\\n padding-right: calc(1rem / 2 + 1px);\\\\n padding-left: calc(var(--fontSize) / 2 + 1px);\\\\n padding-right: calc(var(--fontSize) / 2 + 1px);\\\\n }\\\\n}\\\\n\\\\nh1,h2,h3,h4,h5,h6 {\\\\n margin-top: 0;\\\\n margin-bottom: 0;\\\\n}\\\\n\\\\na {\\\\n color: rgba(0, 0, 255, 0.9)\\\\n}\\\\n\\\\na:hover {\\\\n color: #639;\\\\n }\\\\n\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"webpack:///source-map/basic.postcss.css\\"],\\"names\\":[],\\"mappings\\":\\"AAKA;EACE,gBAAgB;EAChB,mCAAsB;EACtB,yCAA4C;AAC9C;;AAEA;EACE,kBAAqB;EAArB,gBAAqB;EAArB,qBAAqB;AACvB;;AAEA;EACE;IACE,6BAAuB;IAAvB,uBAAuB;IACvB,iGAAsB;IACtB,eAA0B;IAA1B,0BAA0B;IAC1B,6BAAwC;IAAxC,wCAAwC;IACxC,qBAAyB;IACzB,kCAA+C;IAA/C,mCAA+C;IAA/C,6CAA+C;IAA/C,8CAA+C;EACjD;AACF;;AAEA;EACE,aAAe;EAAf,gBAAe;AACjB;;AAEA;EACE;AAKF;;AAHA;GACG,WAAoB;CACtB\\",\\"sourcesContent\\":[\\"@import \\\\\\"./nested/nested.postcss.css\\\\\\";\\\\n\\\\n@custom-media --viewport-medium (width <= 50rem);\\\\n@custom-selector :--heading h1, h2, h3, h4, h5, h6;\\\\n\\\\n:root {\\\\n --fontSize: 1rem;\\\\n --mainColor: #12345678;\\\\n --secondaryColor: lab(32.5 38.5 -47.6 / 90%);\\\\n}\\\\n\\\\nhtml {\\\\n overflow: hidden auto;\\\\n}\\\\n\\\\n@media (--viewport-medium) {\\\\n body {\\\\n color: var(--mainColor);\\\\n font-family: system-ui;\\\\n font-size: var(--fontSize);\\\\n line-height: calc(var(--fontSize) * 1.5);\\\\n overflow-wrap: break-word;\\\\n padding-inline: calc(var(--fontSize) / 2 + 1px);\\\\n }\\\\n}\\\\n\\\\n:--heading {\\\\n margin-block: 0;\\\\n}\\\\n\\\\na {\\\\n color: rgb(0 0 100% / 90%);\\\\n\\\\n&:hover {\\\\n color: rebeccapurple;\\\\n }\\\\n}\\\\n\\"]}]); // Exports export default ___CSS_LOADER_EXPORT___; " @@ -645,11 +680,10 @@ Array [ ", "", Object { - "file": "nested.postcss.css", "mappings": "AAAA;EACE,WAAW;AACb", "names": Array [], "sources": Array [ - "nested.postcss.css", + "webpack:///source-map/nested/nested.postcss.css", ], "sourcesContent": Array [ ".nested { @@ -706,11 +740,10 @@ a:hover { ", "", Object { - "file": "basic.postcss.css", "mappings": "AAKA;EACE,gBAAgB;EAChB,mCAAsB;EACtB,yCAA4C;AAC9C;;AAEA;EACE,kBAAqB;EAArB,gBAAqB;EAArB,qBAAqB;AACvB;;AAEA;EACE;IACE,6BAAuB;IAAvB,uBAAuB;IACvB,iGAAsB;IACtB,eAA0B;IAA1B,0BAA0B;IAC1B,6BAAwC;IAAxC,wCAAwC;IACxC,qBAAyB;IACzB,kCAA+C;IAA/C,mCAA+C;IAA/C,6CAA+C;IAA/C,8CAA+C;EACjD;AACF;;AAEA;EACE,aAAe;EAAf,gBAAe;AACjB;;AAEA;EACE;AAKF;;AAHA;GACG,WAAoB;CACtB", "names": Array [], "sources": Array [ - "basic.postcss.css", + "webpack:///source-map/basic.postcss.css", ], "sourcesContent": Array [ "@import \\"./nested/nested.postcss.css\\"; @@ -760,6 +793,54 @@ a { exports[`"sourceMap" option true should generate source maps when source maps is valid from an other loader (\`postcss-loader\`): warnings 1`] = `Array []`; +exports[`"sourceMap" option true should generate source maps when source maps is valid from an other loader (\`stylus-loader\`): errors 1`] = `Array []`; + +exports[`"sourceMap" option true should generate source maps when source maps is valid from an other loader (\`stylus-loader\`): module 1`] = ` +"// Imports +import ___CSS_LOADER_API_IMPORT___ from \\"../../../src/runtime/api.js\\"; +var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(true); +// Module +___CSS_LOADER_EXPORT___.push([module.id, \\"body {\\\\n font: 14px/1.5 Helvetica, arial, sans-serif;\\\\n}\\\\nbody #logo {\\\\n border-radius: 5px;\\\\n}\\\\n/*# sourceMappingURL=test/fixtures/source-map/base.css.map */\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"webpack:///source-map/base.styl\\"],\\"names\\":[],\\"mappings\\":\\"AAAA;EACE,2CAAwB;AAC1B;AAAE;EACE,kBAAe;AAEnB;AACA,4DAA4D\\",\\"sourcesContent\\":[\\"body {\\\\n font: 14px/1.5 Helvetica, arial, sans-serif;\\\\n #logo {\\\\n border-radius: 5px;\\\\n }\\\\n}\\\\n\\"]}]); +// Exports +export default ___CSS_LOADER_EXPORT___; +" +`; + +exports[`"sourceMap" option true should generate source maps when source maps is valid from an other loader (\`stylus-loader\`): result 1`] = ` +Array [ + Array [ + "./source-map/base.styl", + "body { + font: 14px/1.5 Helvetica, arial, sans-serif; +} +body #logo { + border-radius: 5px; +} +/*# sourceMappingURL=test/fixtures/source-map/base.css.map */", + "", + Object { + "mappings": "AAAA;EACE,2CAAwB;AAC1B;AAAE;EACE,kBAAe;AAEnB;AACA,4DAA4D", + "names": Array [], + "sources": Array [ + "webpack:///source-map/base.styl", + ], + "sourcesContent": Array [ + "body { + font: 14px/1.5 Helvetica, arial, sans-serif; + #logo { + border-radius: 5px; + } +} +", + ], + "version": 3, + }, + ], +] +`; + +exports[`"sourceMap" option true should generate source maps when source maps is valid from an other loader (\`stylus-loader\`): warnings 1`] = `Array []`; + exports[`"sourceMap" option true should generate source maps: errors 1`] = `Array []`; exports[`"sourceMap" option true should generate source maps: module 1`] = ` @@ -769,7 +850,7 @@ import ___CSS_LOADER_AT_RULE_IMPORT_0___ from \\"-!../../../src/index.js??[ident var ___CSS_LOADER_EXPORT___ = ___CSS_LOADER_API_IMPORT___(true); ___CSS_LOADER_EXPORT___.i(___CSS_LOADER_AT_RULE_IMPORT_0___); // Module -___CSS_LOADER_EXPORT___.push([module.id, \\".class {\\\\n color: red;\\\\n}\\\\n\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"basic.css\\"],\\"names\\":[],\\"mappings\\":\\"AAEA;EACE,UAAU;AACZ\\",\\"file\\":\\"basic.css\\",\\"sourcesContent\\":[\\"@import \\\\\\"./nested/nested.css\\\\\\";\\\\n\\\\n.class {\\\\n color: red;\\\\n}\\\\n\\"]}]); +___CSS_LOADER_EXPORT___.push([module.id, \\".class {\\\\n color: red;\\\\n}\\\\n\\", \\"\\",{\\"version\\":3,\\"sources\\":[\\"webpack:///source-map/basic.css\\"],\\"names\\":[],\\"mappings\\":\\"AAEA;EACE,UAAU;AACZ\\",\\"sourcesContent\\":[\\"@import \\\\\\"./nested/nested.css\\\\\\";\\\\n\\\\n.class {\\\\n color: red;\\\\n}\\\\n\\"]}]); // Exports export default ___CSS_LOADER_EXPORT___; " @@ -785,11 +866,10 @@ Array [ ", "", Object { - "file": "nested.css", "mappings": "AAAA;EACE,WAAW;AACb", "names": Array [], "sources": Array [ - "nested.css", + "webpack:///source-map/nested/nested.css", ], "sourcesContent": Array [ ".nested { @@ -808,11 +888,10 @@ Array [ ", "", Object { - "file": "basic.css", "mappings": "AAEA;EACE,UAAU;AACZ", "names": Array [], "sources": Array [ - "basic.css", + "webpack:///source-map/basic.css", ], "sourcesContent": Array [ "@import \\"./nested/nested.css\\"; diff --git a/test/fixtures/source-map/base.less b/test/fixtures/source-map/base.less new file mode 100644 index 000000000..e8b6fd830 --- /dev/null +++ b/test/fixtures/source-map/base.less @@ -0,0 +1,7 @@ +@font-stack: Helvetica, sans-serif; +@primary-color: #333; + +body { + font: 100% @font-stack; + color: @primary-color; +} diff --git a/test/fixtures/source-map/base.styl b/test/fixtures/source-map/base.styl new file mode 100644 index 000000000..a7379c56e --- /dev/null +++ b/test/fixtures/source-map/base.styl @@ -0,0 +1,6 @@ +body { + font: 14px/1.5 Helvetica, arial, sans-serif; + #logo { + border-radius: 5px; + } +} diff --git a/test/fixtures/source-map/basic-less.js b/test/fixtures/source-map/basic-less.js new file mode 100644 index 000000000..6941e2d6c --- /dev/null +++ b/test/fixtures/source-map/basic-less.js @@ -0,0 +1,5 @@ +import css from './base.less'; + +__export__ = css; + +export default css; diff --git a/test/fixtures/source-map/basic-styl.js b/test/fixtures/source-map/basic-styl.js new file mode 100644 index 000000000..76d2785e2 --- /dev/null +++ b/test/fixtures/source-map/basic-styl.js @@ -0,0 +1,5 @@ +import css from './base.styl'; + +__export__ = css; + +export default css; diff --git a/test/sourceMap-option.test.js b/test/sourceMap-option.test.js index e047d27a3..b71bf58d6 100644 --- a/test/sourceMap-option.test.js +++ b/test/sourceMap-option.test.js @@ -147,6 +147,13 @@ describe('"sourceMap" option', () => { }); it('should generate source maps when source maps is valid and string from an other loader', async () => { + const absolutePath = path.resolve( + __dirname, + 'fixtures', + 'source-map', + 'basic.css' + ); + const compiler = getCompiler( './source-map/basic.js', {}, @@ -167,13 +174,14 @@ describe('"sourceMap" option', () => { ), options: { sourceMap: JSON.stringify({ - foo: 'bar', version: 3, - sources: ['basic.css'], + sources: [absolutePath], names: [], - mappings: 'AAAA;EACE,UAAU;AACZ', - file: 'basic.css', - sourcesContent: ['.class {\n color: red;\n}\n'], + mappings: 'AAAA,6BAA6B;;AAE7B;EACE,UAAU;AACZ', + file: absolutePath, + sourcesContent: [ + '@import "./nested/nested.css";\n\n.class {\n color: red;\n}\n', + ], }), }, }, @@ -196,6 +204,11 @@ describe('"sourceMap" option', () => { }); it('should generate source maps when source maps is valid and is set sourceRoot', async () => { + const absoluteSourceRoot = path.resolve( + __dirname, + 'fixtures', + 'source-map' + ); const compiler = getCompiler( './source-map/basic.js', {}, @@ -219,11 +232,13 @@ describe('"sourceMap" option', () => { foo: 'bar', version: 3, sources: ['basic.css'], - sourceRoot: '/fixtures/source-map', + sourceRoot: absoluteSourceRoot, names: [], - mappings: 'AAAA;EACE,UAAU;AACZ', + mappings: 'AAAA,6BAA6B;;AAE7B;EACE,UAAU;AACZ', file: 'basic.css', - sourcesContent: ['.class {\n color: red;\n}\n'], + sourcesContent: [ + '@import "./nested/nested.css";\n\n.class {\n color: red;\n}\n', + ], }), }, }, @@ -319,13 +334,95 @@ describe('"sourceMap" option', () => { // ); // const stats = await compile(compiler); // - // expect(getModuleSource('./source-map/basic.scss', stats)).toMatchSnapshot('module'); - // expect(getExecutedCode('main.bundle.js', compiler, stats)).toMatchSnapshot( - // 'result' + // expect(getModuleSource('./source-map/basic.scss', stats)).toMatchSnapshot( + // 'module' // ); + // expect( + // getExecutedCode('main.bundle.js', compiler, stats) + // ).toMatchSnapshot('result'); // expect(getWarnings(stats)).toMatchSnapshot('warnings'); // expect(getErrors(stats)).toMatchSnapshot('errors'); // }); + + it('should generate source maps when source maps is valid from an other loader (`less-loader`)', async () => { + const compiler = getCompiler( + './source-map/basic-less.js', + {}, + { + module: { + rules: [ + { + test: /\.less$/i, + use: [ + { + loader: path.resolve(__dirname, '../src'), + options: { + sourceMap: true, + }, + }, + { + loader: 'less-loader', + options: { + sourceMap: true, + }, + }, + ], + }, + ], + }, + } + ); + const stats = await compile(compiler); + + expect(getModuleSource('./source-map/base.less', stats)).toMatchSnapshot( + 'module' + ); + expect( + getExecutedCode('main.bundle.js', compiler, stats) + ).toMatchSnapshot('result'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); + + it('should generate source maps when source maps is valid from an other loader (`stylus-loader`)', async () => { + const compiler = getCompiler( + './source-map/basic-styl.js', + {}, + { + module: { + rules: [ + { + test: /\.styl$/i, + use: [ + { + loader: path.resolve(__dirname, '../src'), + options: { + sourceMap: true, + }, + }, + { + loader: 'stylus-loader', + options: { + sourceMap: true, + }, + }, + ], + }, + ], + }, + } + ); + const stats = await compile(compiler); + + expect(getModuleSource('./source-map/base.styl', stats)).toMatchSnapshot( + 'module' + ); + expect( + getExecutedCode('main.bundle.js', compiler, stats) + ).toMatchSnapshot('result'); + expect(getWarnings(stats)).toMatchSnapshot('warnings'); + expect(getErrors(stats)).toMatchSnapshot('errors'); + }); }); describe('false', () => {