From 453248fcb54c10b9df0b552715049179cad4c560 Mon Sep 17 00:00:00 2001 From: Evilebot Tnawi Date: Tue, 4 Dec 2018 16:17:00 +0300 Subject: [PATCH] fix: support module resolution in composes (#845) --- lib/loader.js | 6 +- test/__snapshots__/import-option.test.js.snap | 1350 +++++++++++++---- .../__snapshots__/modules-option.test.js.snap | 152 ++ test/fixtures/import/css-modules.css | 33 - test/fixtures/modules/alias.css | 3 + test/fixtures/modules/composes.css | 58 + test/fixtures/modules/imported-simple.css | 3 + .../modules/node_modules/package/style.css | 3 + test/fixtures/modules/relative.css | 3 + .../{import => modules}/something.css | 0 test/fixtures/modules/test-other.css | 3 + test/fixtures/modules/top-relative.css | 3 + test/fixtures/{import => modules}/values.css | 0 test/helpers.js | 8 +- test/import-option.test.js | 6 +- test/modules-option.test.js | 17 + 16 files changed, 1329 insertions(+), 319 deletions(-) delete mode 100644 test/fixtures/import/css-modules.css create mode 100644 test/fixtures/modules/alias.css create mode 100644 test/fixtures/modules/composes.css create mode 100644 test/fixtures/modules/imported-simple.css create mode 100644 test/fixtures/modules/node_modules/package/style.css create mode 100644 test/fixtures/modules/relative.css rename test/fixtures/{import => modules}/something.css (100%) create mode 100644 test/fixtures/modules/test-other.css create mode 100644 test/fixtures/modules/top-relative.css rename test/fixtures/{import => modules}/values.css (100%) diff --git a/lib/loader.js b/lib/loader.js index cec68723..d2af5e05 100644 --- a/lib/loader.js +++ b/lib/loader.js @@ -145,7 +145,9 @@ module.exports = function loader(content, map, meta) { const message = messages.find( // eslint-disable-next-line no-shadow (message) => - message.type === 'icss-import' && message.item.index === idx + message.type === 'icss-import' && + message.item && + message.item.index === idx ); if (!message) { @@ -153,7 +155,7 @@ module.exports = function loader(content, map, meta) { } const { item } = message; - const importUrl = importUrlPrefix + item.url; + const importUrl = importUrlPrefix + urlToRequest(item.url); if (exportOnlyLocals) { return `" + require(${stringifyRequest( diff --git a/test/__snapshots__/import-option.test.js.snap b/test/__snapshots__/import-option.test.js.snap index aabcb7fd..65335c6f 100644 --- a/test/__snapshots__/import-option.test.js.snap +++ b/test/__snapshots__/import-option.test.js.snap @@ -1,285 +1,5 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`import option false and modules \`false\`: errors 1`] = `Array []`; - -exports[`import option false and modules \`false\`: module (evaluated) 1`] = ` -Array [ - Array [ - 1, - "@import url(test-other.css) (min-width: 100px); - -@value def from './values.css'; -@value other from './values.css'; -@value other from './values.css'; -@value something from './something.css'; -@value foo: blue; -@value bar: block; - -.ghi { - color: def; -} - -.class { - color: foo; -} - -.other { - display: bar; -} - -.other-other { - width: something; -} - -.green { - color: other; -} - -.foo { - prop: def; - duplicate: other; -} -", - "", - ], -] -`; - -exports[`import option false and modules \`false\`: module 1`] = ` -"exports = module.exports = require(\\"../../../lib/runtime/api.js\\")(false); -// imports - - -// module -exports.push([module.id, \\"@import url(test-other.css) (min-width: 100px);\\\\n\\\\n@value def from './values.css';\\\\n@value other from './values.css';\\\\n@value other from './values.css';\\\\n@value something from './something.css';\\\\n@value foo: blue;\\\\n@value bar: block;\\\\n\\\\n.ghi {\\\\n color: def;\\\\n}\\\\n\\\\n.class {\\\\n color: foo;\\\\n}\\\\n\\\\n.other {\\\\n display: bar;\\\\n}\\\\n\\\\n.other-other {\\\\n width: something;\\\\n}\\\\n\\\\n.green {\\\\n color: other;\\\\n}\\\\n\\\\n.foo {\\\\n prop: def;\\\\n duplicate: other;\\\\n}\\\\n\\", \\"\\"]); - -// exports -" -`; - -exports[`import option false and modules \`false\`: warnings 1`] = `Array []`; - -exports[`import option false and modules \`global\`: errors 1`] = `Array []`; - -exports[`import option false and modules \`global\`: module (evaluated) 1`] = ` -Array [ - Array [ - 2, - " -", - "", - ], - Array [ - 3, - " -", - "", - ], - Array [ - 1, - "@import url(test-other.css) (min-width: 100px); - -.ghi { - color: red; -} - -.class { - color: blue; -} - -.other { - display: block; -} - -.other-other { - width: 2112moon; -} - -.green { - color: green; -} - -.foo { - prop: red; - duplicate: green; -} -", - "", - ], -] -`; - -exports[`import option false and modules \`global\`: module 1`] = ` -"exports = module.exports = require(\\"../../../lib/runtime/api.js\\")(false); -// imports -exports.i(require(\\"-!../../../index.js??ref--4-0!./values.css\\"), \\"\\"); -exports.i(require(\\"-!../../../index.js??ref--4-0!./something.css\\"), \\"\\"); - -// module -exports.push([module.id, \\"@import url(test-other.css) (min-width: 100px);\\\\n\\\\n.ghi {\\\\n color: \\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"def\\"] + \\";\\\\n}\\\\n\\\\n.class {\\\\n color: blue;\\\\n}\\\\n\\\\n.other {\\\\n display: block;\\\\n}\\\\n\\\\n.other-other {\\\\n width: \\" + require(\\"-!../../../index.js??ref--4-0!./something.css\\").locals[\\"something\\"] + \\";\\\\n}\\\\n\\\\n.green {\\\\n color: \\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"other\\"] + \\";\\\\n}\\\\n\\\\n.foo {\\\\n prop: \\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"def\\"] + \\";\\\\n duplicate: \\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"other\\"] + \\";\\\\n}\\\\n\\", \\"\\"]); - -// exports -exports.locals = { - \\"def\\": \\"\\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"def\\"] + \\"\\", - \\"other\\": \\"\\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"other\\"] + \\"\\", - \\"something\\": \\"\\" + require(\\"-!../../../index.js??ref--4-0!./something.css\\").locals[\\"something\\"] + \\"\\", - \\"foo\\": \\"blue\\", - \\"bar\\": \\"block\\" -};" -`; - -exports[`import option false and modules \`global\`: warnings 1`] = `Array []`; - -exports[`import option false and modules \`local\`: errors 1`] = `Array []`; - -exports[`import option false and modules \`local\`: module (evaluated) 1`] = ` -Array [ - Array [ - 2, - " -", - "", - ], - Array [ - 3, - " -", - "", - ], - Array [ - 1, - "@import url(test-other.css) (min-width: 100px); - -._3r49KZIIAltPknAjdNVZ-7 { - color: red; -} - -._4o0o5eKzoeDOSI0_cR8mr { - color: blue; -} - -._2wLXKM9pRjt1oRYvf0Wo3Q { - display: block; -} - -._1RBgqC8j3f4iU6k-ocmIG7 { - width: 2112moon; -} - -._1lCIckG6C8tRZjGNDsAPWr { - color: green; -} - -._1YL4f0i_603GTMRC_pnsP5 { - prop: red; - duplicate: green; -} -", - "", - ], -] -`; - -exports[`import option false and modules \`local\`: module 1`] = ` -"exports = module.exports = require(\\"../../../lib/runtime/api.js\\")(false); -// imports -exports.i(require(\\"-!../../../index.js??ref--4-0!./values.css\\"), \\"\\"); -exports.i(require(\\"-!../../../index.js??ref--4-0!./something.css\\"), \\"\\"); - -// module -exports.push([module.id, \\"@import url(test-other.css) (min-width: 100px);\\\\n\\\\n._3r49KZIIAltPknAjdNVZ-7 {\\\\n color: \\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"def\\"] + \\";\\\\n}\\\\n\\\\n._4o0o5eKzoeDOSI0_cR8mr {\\\\n color: blue;\\\\n}\\\\n\\\\n._2wLXKM9pRjt1oRYvf0Wo3Q {\\\\n display: block;\\\\n}\\\\n\\\\n._1RBgqC8j3f4iU6k-ocmIG7 {\\\\n width: \\" + require(\\"-!../../../index.js??ref--4-0!./something.css\\").locals[\\"something\\"] + \\";\\\\n}\\\\n\\\\n._1lCIckG6C8tRZjGNDsAPWr {\\\\n color: \\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"other\\"] + \\";\\\\n}\\\\n\\\\n._1YL4f0i_603GTMRC_pnsP5 {\\\\n prop: \\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"def\\"] + \\";\\\\n duplicate: \\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"other\\"] + \\";\\\\n}\\\\n\\", \\"\\"]); - -// exports -exports.locals = { - \\"def\\": \\"\\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"def\\"] + \\"\\", - \\"other\\": \\"_2wLXKM9pRjt1oRYvf0Wo3Q\\", - \\"something\\": \\"\\" + require(\\"-!../../../index.js??ref--4-0!./something.css\\").locals[\\"something\\"] + \\"\\", - \\"foo\\": \\"_1YL4f0i_603GTMRC_pnsP5\\", - \\"bar\\": \\"block\\", - \\"ghi\\": \\"_3r49KZIIAltPknAjdNVZ-7\\", - \\"class\\": \\"_4o0o5eKzoeDOSI0_cR8mr\\", - \\"other-other\\": \\"_1RBgqC8j3f4iU6k-ocmIG7\\", - \\"green\\": \\"_1lCIckG6C8tRZjGNDsAPWr\\" -};" -`; - -exports[`import option false and modules \`local\`: warnings 1`] = `Array []`; - -exports[`import option false and modules \`true\`: errors 1`] = `Array []`; - -exports[`import option false and modules \`true\`: module (evaluated) 1`] = ` -Array [ - Array [ - 2, - " -", - "", - ], - Array [ - 3, - " -", - "", - ], - Array [ - 1, - "@import url(test-other.css) (min-width: 100px); - -._3r49KZIIAltPknAjdNVZ-7 { - color: red; -} - -._4o0o5eKzoeDOSI0_cR8mr { - color: blue; -} - -._2wLXKM9pRjt1oRYvf0Wo3Q { - display: block; -} - -._1RBgqC8j3f4iU6k-ocmIG7 { - width: 2112moon; -} - -._1lCIckG6C8tRZjGNDsAPWr { - color: green; -} - -._1YL4f0i_603GTMRC_pnsP5 { - prop: red; - duplicate: green; -} -", - "", - ], -] -`; - -exports[`import option false and modules \`true\`: module 1`] = ` -"exports = module.exports = require(\\"../../../lib/runtime/api.js\\")(false); -// imports -exports.i(require(\\"-!../../../index.js??ref--4-0!./values.css\\"), \\"\\"); -exports.i(require(\\"-!../../../index.js??ref--4-0!./something.css\\"), \\"\\"); - -// module -exports.push([module.id, \\"@import url(test-other.css) (min-width: 100px);\\\\n\\\\n._3r49KZIIAltPknAjdNVZ-7 {\\\\n color: \\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"def\\"] + \\";\\\\n}\\\\n\\\\n._4o0o5eKzoeDOSI0_cR8mr {\\\\n color: blue;\\\\n}\\\\n\\\\n._2wLXKM9pRjt1oRYvf0Wo3Q {\\\\n display: block;\\\\n}\\\\n\\\\n._1RBgqC8j3f4iU6k-ocmIG7 {\\\\n width: \\" + require(\\"-!../../../index.js??ref--4-0!./something.css\\").locals[\\"something\\"] + \\";\\\\n}\\\\n\\\\n._1lCIckG6C8tRZjGNDsAPWr {\\\\n color: \\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"other\\"] + \\";\\\\n}\\\\n\\\\n._1YL4f0i_603GTMRC_pnsP5 {\\\\n prop: \\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"def\\"] + \\";\\\\n duplicate: \\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"other\\"] + \\";\\\\n}\\\\n\\", \\"\\"]); - -// exports -exports.locals = { - \\"def\\": \\"\\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"def\\"] + \\"\\", - \\"other\\": \\"_2wLXKM9pRjt1oRYvf0Wo3Q\\", - \\"something\\": \\"\\" + require(\\"-!../../../index.js??ref--4-0!./something.css\\").locals[\\"something\\"] + \\"\\", - \\"foo\\": \\"_1YL4f0i_603GTMRC_pnsP5\\", - \\"bar\\": \\"block\\", - \\"ghi\\": \\"_3r49KZIIAltPknAjdNVZ-7\\", - \\"class\\": \\"_4o0o5eKzoeDOSI0_cR8mr\\", - \\"other-other\\": \\"_1RBgqC8j3f4iU6k-ocmIG7\\", - \\"green\\": \\"_1lCIckG6C8tRZjGNDsAPWr\\" -};" -`; - -exports[`import option false and modules \`true\`: warnings 1`] = `Array []`; - exports[`import option false: errors 1`] = `Array []`; exports[`import option false: module (evaluated) 1`] = ` @@ -368,6 +88,1076 @@ exports.push([module.id, \\"@import url(test.css);\\\\n@import url('test.css');\ exports[`import option false: warnings 1`] = `Array []`; +exports[`import option true and modules \`false\`: errors 1`] = `Array []`; + +exports[`import option true and modules \`false\`: module (evaluated) 1`] = ` +Array [ + Array [ + 2, + ".test { + a: a; +} +", + "", + ], + Array [ + 3, + ".test { + a: a; +} +", + "screen and print", + ], + Array [ + 5, + "a { + b: b; +} +", + "((min-width: 100px)) and (screen and print)", + ], + Array [ + 4, + ".test { + c: c; +} +", + "screen and print", + ], + Array [ + 1, + "@import url(http://example.com/style.css);", + "", + ], + Array [ + 1, + "@import url(http://example.com/style.css#hash);", + "", + ], + Array [ + 1, + "@import url(http://example.com/style.css?#hash);", + "", + ], + Array [ + 1, + "@import url(http://example.com/style.css?foo=bar#hash);", + "", + ], + Array [ + 1, + "@import url(http://example.com/other-style.css);", + "screen and print", + ], + Array [ + 1, + "@import url(//example.com/style.css);", + "", + ], + Array [ + 6, + ".test { + d: d +} +", + "", + ], + Array [ + 7, + ".query { + e: e; +} +", + "", + ], + Array [ + 8, + ".other-query { + f: f; +} +", + "", + ], + Array [ + 9, + ".other-query { + f: f; +} +", + "screen and print", + ], + Array [ + 1, + "@import url(https://fonts.googleapis.com/css?family=Roboto);", + "", + ], + Array [ + 1, + "@import url(https://fonts.googleapis.com/css?family=Noto+Sans+TC);", + "", + ], + Array [ + 1, + "@import url(https://fonts.googleapis.com/css?family=Noto+Sans+TC|Roboto);", + "", + ], + Array [ + 10, + ".relative { + color: red; +} +", + "", + ], + Array [ + 11, + ".top-relative { + color: black; +} +", + "", + ], + Array [ + 12, + ".tilde { + color: yellow; +} +", + "", + ], + Array [ + 13, + ".alias { + color: red; +} +", + "", + ], + Array [ + 1, + "@import url(); +@import url(''); +@import url(\\"\\"); +@import ''; +@import \\"\\"; +@import \\" \\"; +@import \\" +\\"; +@import url(); +@import url(''); +@import url(\\"\\"); +@import ; +@import foo-bar; +@import-normalize; +@import url('http://') :root {} + +.class { + a: b c d; +} + +.foo { + @import 'path.css'; +} +", + "", + ], +] +`; + +exports[`import option true and modules \`false\`: module 1`] = ` +"exports = module.exports = require(\\"../../../lib/runtime/api.js\\")(false); +// imports +exports.i(require(\\"-!../../../index.js??ref--4-0!./test.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./test.css\\"), \\"screen and print\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./test-media.css\\"), \\"screen and print\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./test-other.css\\"), \\"(min-width: 100px)\\"); +exports.push([module.id, \\"@import url(http://example.com/style.css);\\", \\"\\"]); +exports.push([module.id, \\"@import url(http://example.com/style.css#hash);\\", \\"\\"]); +exports.push([module.id, \\"@import url(http://example.com/style.css?#hash);\\", \\"\\"]); +exports.push([module.id, \\"@import url(http://example.com/style.css?foo=bar#hash);\\", \\"\\"]); +exports.push([module.id, \\"@import url(http://example.com/other-style.css);\\", \\"screen and print\\"]); +exports.push([module.id, \\"@import url(//example.com/style.css);\\", \\"\\"]); +exports.i(require(\\"-!../../../index.js??ref--4-0!package/test.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./query.css?foo=1&bar=1\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./other-query.css?foo=1&bar=1#hash\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./other-query.css?foo=1&bar=1#hash\\"), \\"screen and print\\"); +exports.push([module.id, \\"@import url(https://fonts.googleapis.com/css?family=Roboto);\\", \\"\\"]); +exports.push([module.id, \\"@import url(https://fonts.googleapis.com/css?family=Noto+Sans+TC);\\", \\"\\"]); +exports.push([module.id, \\"@import url(https://fonts.googleapis.com/css?family=Noto+Sans+TC|Roboto);\\", \\"\\"]); +exports.i(require(\\"-!../../../index.js??ref--4-0!./relative.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!../import/top-relative.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!package/tilde.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!aliasesImport/alias.css\\"), \\"\\"); + +// module +exports.push([module.id, \\"@import url();\\\\n@import url('');\\\\n@import url(\\\\\\"\\\\\\");\\\\n@import '';\\\\n@import \\\\\\"\\\\\\";\\\\n@import \\\\\\" \\\\\\";\\\\n@import \\\\\\"\\\\n\\\\\\";\\\\n@import url();\\\\n@import url('');\\\\n@import url(\\\\\\"\\\\\\");\\\\n@import ;\\\\n@import foo-bar;\\\\n@import-normalize;\\\\n@import url('http://') :root {}\\\\n\\\\n.class {\\\\n a: b c d;\\\\n}\\\\n\\\\n.foo {\\\\n @import 'path.css';\\\\n}\\\\n\\", \\"\\"]); + +// exports +" +`; + +exports[`import option true and modules \`false\`: warnings 1`] = ` +Array [ + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(12:1) Unable to find uri in '@import url()'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(13:1) Unable to find uri in '@import url('')'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(14:1) Unable to find uri in '@import url(\\"\\")'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(17:1) Unable to find uri in '@import '''", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(18:1) Unable to find uri in '@import \\"\\"'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(19:1) Unable to find uri in '@import \\" \\"'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(20:1) Unable to find uri in '@import \\" +\\"'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(22:1) Unable to find uri in '@import url()'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(23:1) Unable to find uri in '@import url('')'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(24:1) Unable to find uri in '@import url(\\"\\")'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(40:1) Unable to find uri in '@import '", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(41:1) Unable to find uri in '@import foo-bar'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(43:1) It looks like you didn't end your @import statement correctly. Child nodes are attached to it.", +] +`; + +exports[`import option true and modules \`global\`: errors 1`] = `Array []`; + +exports[`import option true and modules \`global\`: module (evaluated) 1`] = ` +Array [ + Array [ + 2, + ".test { + a: a; +} +", + "", + ], + Array [ + 3, + ".test { + a: a; +} +", + "screen and print", + ], + Array [ + 5, + "a { + b: b; +} +", + "((min-width: 100px)) and (screen and print)", + ], + Array [ + 4, + ".test { + c: c; +} +", + "screen and print", + ], + Array [ + 1, + "@import url(http://example.com/style.css);", + "", + ], + Array [ + 1, + "@import url(http://example.com/style.css#hash);", + "", + ], + Array [ + 1, + "@import url(http://example.com/style.css?#hash);", + "", + ], + Array [ + 1, + "@import url(http://example.com/style.css?foo=bar#hash);", + "", + ], + Array [ + 1, + "@import url(http://example.com/other-style.css);", + "screen and print", + ], + Array [ + 1, + "@import url(//example.com/style.css);", + "", + ], + Array [ + 6, + ".test { + d: d +} +", + "", + ], + Array [ + 7, + ".query { + e: e; +} +", + "", + ], + Array [ + 8, + ".other-query { + f: f; +} +", + "", + ], + Array [ + 9, + ".other-query { + f: f; +} +", + "screen and print", + ], + Array [ + 1, + "@import url(https://fonts.googleapis.com/css?family=Roboto);", + "", + ], + Array [ + 1, + "@import url(https://fonts.googleapis.com/css?family=Noto+Sans+TC);", + "", + ], + Array [ + 1, + "@import url(https://fonts.googleapis.com/css?family=Noto+Sans+TC|Roboto);", + "", + ], + Array [ + 10, + ".relative { + color: red; +} +", + "", + ], + Array [ + 11, + ".top-relative { + color: black; +} +", + "", + ], + Array [ + 12, + ".tilde { + color: yellow; +} +", + "", + ], + Array [ + 13, + ".alias { + color: red; +} +", + "", + ], + Array [ + 1, + "@import url(); +@import url(''); +@import url(\\"\\"); +@import ''; +@import \\"\\"; +@import \\" \\"; +@import \\" +\\"; +@import url(); +@import url(''); +@import url(\\"\\"); +@import ; +@import foo-bar; +@import-normalize; +@import url('http://') :root {} + +.class { + a: b c d; +} + +.foo { + @import 'path.css'; +} +", + "", + ], +] +`; + +exports[`import option true and modules \`global\`: module 1`] = ` +"exports = module.exports = require(\\"../../../lib/runtime/api.js\\")(false); +// imports +exports.i(require(\\"-!../../../index.js??ref--4-0!./test.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./test.css\\"), \\"screen and print\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./test-media.css\\"), \\"screen and print\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./test-other.css\\"), \\"(min-width: 100px)\\"); +exports.push([module.id, \\"@import url(http://example.com/style.css);\\", \\"\\"]); +exports.push([module.id, \\"@import url(http://example.com/style.css#hash);\\", \\"\\"]); +exports.push([module.id, \\"@import url(http://example.com/style.css?#hash);\\", \\"\\"]); +exports.push([module.id, \\"@import url(http://example.com/style.css?foo=bar#hash);\\", \\"\\"]); +exports.push([module.id, \\"@import url(http://example.com/other-style.css);\\", \\"screen and print\\"]); +exports.push([module.id, \\"@import url(//example.com/style.css);\\", \\"\\"]); +exports.i(require(\\"-!../../../index.js??ref--4-0!package/test.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./query.css?foo=1&bar=1\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./other-query.css?foo=1&bar=1#hash\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./other-query.css?foo=1&bar=1#hash\\"), \\"screen and print\\"); +exports.push([module.id, \\"@import url(https://fonts.googleapis.com/css?family=Roboto);\\", \\"\\"]); +exports.push([module.id, \\"@import url(https://fonts.googleapis.com/css?family=Noto+Sans+TC);\\", \\"\\"]); +exports.push([module.id, \\"@import url(https://fonts.googleapis.com/css?family=Noto+Sans+TC|Roboto);\\", \\"\\"]); +exports.i(require(\\"-!../../../index.js??ref--4-0!./relative.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!../import/top-relative.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!package/tilde.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!aliasesImport/alias.css\\"), \\"\\"); + +// module +exports.push([module.id, \\"@import url();\\\\n@import url('');\\\\n@import url(\\\\\\"\\\\\\");\\\\n@import '';\\\\n@import \\\\\\"\\\\\\";\\\\n@import \\\\\\" \\\\\\";\\\\n@import \\\\\\"\\\\n\\\\\\";\\\\n@import url();\\\\n@import url('');\\\\n@import url(\\\\\\"\\\\\\");\\\\n@import ;\\\\n@import foo-bar;\\\\n@import-normalize;\\\\n@import url('http://') :root {}\\\\n\\\\n.class {\\\\n a: b c d;\\\\n}\\\\n\\\\n.foo {\\\\n @import 'path.css';\\\\n}\\\\n\\", \\"\\"]); + +// exports +" +`; + +exports[`import option true and modules \`global\`: warnings 1`] = ` +Array [ + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(12:1) Unable to find uri in '@import url()'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(13:1) Unable to find uri in '@import url('')'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(14:1) Unable to find uri in '@import url(\\"\\")'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(17:1) Unable to find uri in '@import '''", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(18:1) Unable to find uri in '@import \\"\\"'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(19:1) Unable to find uri in '@import \\" \\"'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(20:1) Unable to find uri in '@import \\" +\\"'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(22:1) Unable to find uri in '@import url()'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(23:1) Unable to find uri in '@import url('')'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(24:1) Unable to find uri in '@import url(\\"\\")'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(40:1) Unable to find uri in '@import '", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(41:1) Unable to find uri in '@import foo-bar'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(43:1) It looks like you didn't end your @import statement correctly. Child nodes are attached to it.", +] +`; + +exports[`import option true and modules \`local\`: errors 1`] = `Array []`; + +exports[`import option true and modules \`local\`: module (evaluated) 1`] = ` +Array [ + Array [ + 2, + "._3fDHa2l1HOcl9VXVfSKtB7 { + a: a; +} +", + "", + ], + Array [ + 3, + "._3fDHa2l1HOcl9VXVfSKtB7 { + a: a; +} +", + "screen and print", + ], + Array [ + 5, + "a { + b: b; +} +", + "((min-width: 100px)) and (screen and print)", + ], + Array [ + 4, + ".f63QYE3dlpdhZuYg8R4pd { + c: c; +} +", + "screen and print", + ], + Array [ + 1, + "@import url(http://example.com/style.css);", + "", + ], + Array [ + 1, + "@import url(http://example.com/style.css#hash);", + "", + ], + Array [ + 1, + "@import url(http://example.com/style.css?#hash);", + "", + ], + Array [ + 1, + "@import url(http://example.com/style.css?foo=bar#hash);", + "", + ], + Array [ + 1, + "@import url(http://example.com/other-style.css);", + "screen and print", + ], + Array [ + 1, + "@import url(//example.com/style.css);", + "", + ], + Array [ + 6, + "._1lN7KGFmbEaXH8rJdLC9cT { + d: d +} +", + "", + ], + Array [ + 7, + "._2FiPFdRUJ6bc--oLN32vUX { + e: e; +} +", + "", + ], + Array [ + 8, + "._2nQ7ONr22lmMu683ljj0MN { + f: f; +} +", + "", + ], + Array [ + 9, + "._2nQ7ONr22lmMu683ljj0MN { + f: f; +} +", + "screen and print", + ], + Array [ + 1, + "@import url(https://fonts.googleapis.com/css?family=Roboto);", + "", + ], + Array [ + 1, + "@import url(https://fonts.googleapis.com/css?family=Noto+Sans+TC);", + "", + ], + Array [ + 1, + "@import url(https://fonts.googleapis.com/css?family=Noto+Sans+TC|Roboto);", + "", + ], + Array [ + 10, + "._37G_Iu-0wcPjXN9ZhzZjlT { + color: red; +} +", + "", + ], + Array [ + 11, + "._4a-iWS8tumU5J8-oW8LlR { + color: black; +} +", + "", + ], + Array [ + 12, + "._2VXavzz3TUKPrbI3S1tkrW { + color: yellow; +} +", + "", + ], + Array [ + 13, + "._2E2zpPgFs4vJaVymauWk3p { + color: red; +} +", + "", + ], + Array [ + 1, + "@import url(); +@import url(''); +@import url(\\"\\"); +@import ''; +@import \\"\\"; +@import \\" \\"; +@import \\" +\\"; +@import url(); +@import url(''); +@import url(\\"\\"); +@import ; +@import foo-bar; +@import-normalize; +@import url('http://') :root {} + +.hnxX78DgkaA2kCp_BPbLd { + a: b c d; +} + +._1Lug_45kZL-M7XuNeM4SCw { + @import 'path.css'; +} +", + "", + ], +] +`; + +exports[`import option true and modules \`local\`: module 1`] = ` +"exports = module.exports = require(\\"../../../lib/runtime/api.js\\")(false); +// imports +exports.i(require(\\"-!../../../index.js??ref--4-0!./test.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./test.css\\"), \\"screen and print\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./test-media.css\\"), \\"screen and print\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./test-other.css\\"), \\"(min-width: 100px)\\"); +exports.push([module.id, \\"@import url(http://example.com/style.css);\\", \\"\\"]); +exports.push([module.id, \\"@import url(http://example.com/style.css#hash);\\", \\"\\"]); +exports.push([module.id, \\"@import url(http://example.com/style.css?#hash);\\", \\"\\"]); +exports.push([module.id, \\"@import url(http://example.com/style.css?foo=bar#hash);\\", \\"\\"]); +exports.push([module.id, \\"@import url(http://example.com/other-style.css);\\", \\"screen and print\\"]); +exports.push([module.id, \\"@import url(//example.com/style.css);\\", \\"\\"]); +exports.i(require(\\"-!../../../index.js??ref--4-0!package/test.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./query.css?foo=1&bar=1\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./other-query.css?foo=1&bar=1#hash\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./other-query.css?foo=1&bar=1#hash\\"), \\"screen and print\\"); +exports.push([module.id, \\"@import url(https://fonts.googleapis.com/css?family=Roboto);\\", \\"\\"]); +exports.push([module.id, \\"@import url(https://fonts.googleapis.com/css?family=Noto+Sans+TC);\\", \\"\\"]); +exports.push([module.id, \\"@import url(https://fonts.googleapis.com/css?family=Noto+Sans+TC|Roboto);\\", \\"\\"]); +exports.i(require(\\"-!../../../index.js??ref--4-0!./relative.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!../import/top-relative.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!package/tilde.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!aliasesImport/alias.css\\"), \\"\\"); + +// module +exports.push([module.id, \\"@import url();\\\\n@import url('');\\\\n@import url(\\\\\\"\\\\\\");\\\\n@import '';\\\\n@import \\\\\\"\\\\\\";\\\\n@import \\\\\\" \\\\\\";\\\\n@import \\\\\\"\\\\n\\\\\\";\\\\n@import url();\\\\n@import url('');\\\\n@import url(\\\\\\"\\\\\\");\\\\n@import ;\\\\n@import foo-bar;\\\\n@import-normalize;\\\\n@import url('http://') :root {}\\\\n\\\\n.hnxX78DgkaA2kCp_BPbLd {\\\\n a: b c d;\\\\n}\\\\n\\\\n._1Lug_45kZL-M7XuNeM4SCw {\\\\n @import 'path.css';\\\\n}\\\\n\\", \\"\\"]); + +// exports +exports.locals = { + \\"class\\": \\"hnxX78DgkaA2kCp_BPbLd\\", + \\"foo\\": \\"_1Lug_45kZL-M7XuNeM4SCw\\" +};" +`; + +exports[`import option true and modules \`local\`: warnings 1`] = ` +Array [ + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(12:1) Unable to find uri in '@import url()'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(13:1) Unable to find uri in '@import url('')'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(14:1) Unable to find uri in '@import url(\\"\\")'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(17:1) Unable to find uri in '@import '''", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(18:1) Unable to find uri in '@import \\"\\"'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(19:1) Unable to find uri in '@import \\" \\"'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(20:1) Unable to find uri in '@import \\" +\\"'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(22:1) Unable to find uri in '@import url()'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(23:1) Unable to find uri in '@import url('')'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(24:1) Unable to find uri in '@import url(\\"\\")'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(40:1) Unable to find uri in '@import '", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(41:1) Unable to find uri in '@import foo-bar'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(43:1) It looks like you didn't end your @import statement correctly. Child nodes are attached to it.", +] +`; + +exports[`import option true and modules \`true\`: errors 1`] = `Array []`; + +exports[`import option true and modules \`true\`: module (evaluated) 1`] = ` +Array [ + Array [ + 2, + "._3fDHa2l1HOcl9VXVfSKtB7 { + a: a; +} +", + "", + ], + Array [ + 3, + "._3fDHa2l1HOcl9VXVfSKtB7 { + a: a; +} +", + "screen and print", + ], + Array [ + 5, + "a { + b: b; +} +", + "((min-width: 100px)) and (screen and print)", + ], + Array [ + 4, + ".f63QYE3dlpdhZuYg8R4pd { + c: c; +} +", + "screen and print", + ], + Array [ + 1, + "@import url(http://example.com/style.css);", + "", + ], + Array [ + 1, + "@import url(http://example.com/style.css#hash);", + "", + ], + Array [ + 1, + "@import url(http://example.com/style.css?#hash);", + "", + ], + Array [ + 1, + "@import url(http://example.com/style.css?foo=bar#hash);", + "", + ], + Array [ + 1, + "@import url(http://example.com/other-style.css);", + "screen and print", + ], + Array [ + 1, + "@import url(//example.com/style.css);", + "", + ], + Array [ + 6, + "._1lN7KGFmbEaXH8rJdLC9cT { + d: d +} +", + "", + ], + Array [ + 7, + "._2FiPFdRUJ6bc--oLN32vUX { + e: e; +} +", + "", + ], + Array [ + 8, + "._2nQ7ONr22lmMu683ljj0MN { + f: f; +} +", + "", + ], + Array [ + 9, + "._2nQ7ONr22lmMu683ljj0MN { + f: f; +} +", + "screen and print", + ], + Array [ + 1, + "@import url(https://fonts.googleapis.com/css?family=Roboto);", + "", + ], + Array [ + 1, + "@import url(https://fonts.googleapis.com/css?family=Noto+Sans+TC);", + "", + ], + Array [ + 1, + "@import url(https://fonts.googleapis.com/css?family=Noto+Sans+TC|Roboto);", + "", + ], + Array [ + 10, + "._37G_Iu-0wcPjXN9ZhzZjlT { + color: red; +} +", + "", + ], + Array [ + 11, + "._4a-iWS8tumU5J8-oW8LlR { + color: black; +} +", + "", + ], + Array [ + 12, + "._2VXavzz3TUKPrbI3S1tkrW { + color: yellow; +} +", + "", + ], + Array [ + 13, + "._2E2zpPgFs4vJaVymauWk3p { + color: red; +} +", + "", + ], + Array [ + 1, + "@import url(); +@import url(''); +@import url(\\"\\"); +@import ''; +@import \\"\\"; +@import \\" \\"; +@import \\" +\\"; +@import url(); +@import url(''); +@import url(\\"\\"); +@import ; +@import foo-bar; +@import-normalize; +@import url('http://') :root {} + +.hnxX78DgkaA2kCp_BPbLd { + a: b c d; +} + +._1Lug_45kZL-M7XuNeM4SCw { + @import 'path.css'; +} +", + "", + ], +] +`; + +exports[`import option true and modules \`true\`: module 1`] = ` +"exports = module.exports = require(\\"../../../lib/runtime/api.js\\")(false); +// imports +exports.i(require(\\"-!../../../index.js??ref--4-0!./test.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./test.css\\"), \\"screen and print\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./test-media.css\\"), \\"screen and print\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./test-other.css\\"), \\"(min-width: 100px)\\"); +exports.push([module.id, \\"@import url(http://example.com/style.css);\\", \\"\\"]); +exports.push([module.id, \\"@import url(http://example.com/style.css#hash);\\", \\"\\"]); +exports.push([module.id, \\"@import url(http://example.com/style.css?#hash);\\", \\"\\"]); +exports.push([module.id, \\"@import url(http://example.com/style.css?foo=bar#hash);\\", \\"\\"]); +exports.push([module.id, \\"@import url(http://example.com/other-style.css);\\", \\"screen and print\\"]); +exports.push([module.id, \\"@import url(//example.com/style.css);\\", \\"\\"]); +exports.i(require(\\"-!../../../index.js??ref--4-0!package/test.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./query.css?foo=1&bar=1\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./other-query.css?foo=1&bar=1#hash\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./other-query.css?foo=1&bar=1#hash\\"), \\"screen and print\\"); +exports.push([module.id, \\"@import url(https://fonts.googleapis.com/css?family=Roboto);\\", \\"\\"]); +exports.push([module.id, \\"@import url(https://fonts.googleapis.com/css?family=Noto+Sans+TC);\\", \\"\\"]); +exports.push([module.id, \\"@import url(https://fonts.googleapis.com/css?family=Noto+Sans+TC|Roboto);\\", \\"\\"]); +exports.i(require(\\"-!../../../index.js??ref--4-0!./relative.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!../import/top-relative.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!package/tilde.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!aliasesImport/alias.css\\"), \\"\\"); + +// module +exports.push([module.id, \\"@import url();\\\\n@import url('');\\\\n@import url(\\\\\\"\\\\\\");\\\\n@import '';\\\\n@import \\\\\\"\\\\\\";\\\\n@import \\\\\\" \\\\\\";\\\\n@import \\\\\\"\\\\n\\\\\\";\\\\n@import url();\\\\n@import url('');\\\\n@import url(\\\\\\"\\\\\\");\\\\n@import ;\\\\n@import foo-bar;\\\\n@import-normalize;\\\\n@import url('http://') :root {}\\\\n\\\\n.hnxX78DgkaA2kCp_BPbLd {\\\\n a: b c d;\\\\n}\\\\n\\\\n._1Lug_45kZL-M7XuNeM4SCw {\\\\n @import 'path.css';\\\\n}\\\\n\\", \\"\\"]); + +// exports +exports.locals = { + \\"class\\": \\"hnxX78DgkaA2kCp_BPbLd\\", + \\"foo\\": \\"_1Lug_45kZL-M7XuNeM4SCw\\" +};" +`; + +exports[`import option true and modules \`true\`: warnings 1`] = ` +Array [ + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(12:1) Unable to find uri in '@import url()'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(13:1) Unable to find uri in '@import url('')'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(14:1) Unable to find uri in '@import url(\\"\\")'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(17:1) Unable to find uri in '@import '''", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(18:1) Unable to find uri in '@import \\"\\"'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(19:1) Unable to find uri in '@import \\" \\"'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(20:1) Unable to find uri in '@import \\" +\\"'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(22:1) Unable to find uri in '@import url()'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(23:1) Unable to find uri in '@import url('')'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(24:1) Unable to find uri in '@import url(\\"\\")'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(40:1) Unable to find uri in '@import '", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(41:1) Unable to find uri in '@import foo-bar'", + "ModuleWarning: Module Warning (from \`replaced original path\`): +Warning + +(43:1) It looks like you didn't end your @import statement correctly. Child nodes are attached to it.", +] +`; + exports[`import option true: errors 1`] = `Array []`; exports[`import option true: module (evaluated) 1`] = ` diff --git a/test/__snapshots__/modules-option.test.js.snap b/test/__snapshots__/modules-option.test.js.snap index a7d8c62c..01786178 100644 --- a/test/__snapshots__/modules-option.test.js.snap +++ b/test/__snapshots__/modules-option.test.js.snap @@ -5043,3 +5043,155 @@ Object { `; exports[`modules case \`values-9\`: (export \`only locals\`) (\`modules\` value is \`true)\`: warnings 1`] = `Array []`; + +exports[`modules composes should supports resolving: errors 1`] = `Array []`; + +exports[`modules composes should supports resolving: module (evaluated) 1`] = ` +Array [ + Array [ + 2, + "._2Nehoi0wFTN-8p0fEfvUYd { + d: d; +} +", + "(min-width: 100px)", + ], + Array [ + 3, + " +", + "", + ], + Array [ + 4, + " +", + "", + ], + Array [ + 5, + "._22ETk3ZhhvjVe-4dAULcsF { + display: block; +} +", + "", + ], + Array [ + 6, + ".dSGVakTZ8YY-XNW64tg9F { + display: inline; +} +", + "", + ], + Array [ + 7, + "._1SUuyapRQ82dAPS8r7zmpY { + display: flex; +} +", + "", + ], + Array [ + 8, + "._2n5szs-7uGKzfFTp9NTK64 { + display: inline-block; +} +", + "", + ], + Array [ + 9, + "._37nzOIvIANGnEtP1lWjZDN { + display: table; +} +", + "", + ], + Array [ + 1, + "._14uFt0lIVKKAlKTTT29IIQ { + color: red; +} + +._3XDgIzfUIQkaUInpEdo7fN { + color: blue; +} + +._1wABXM_RabWHj--wsPrhvM { + display: block; +} + +._1DFEYnAfn9LZyk4fErI86e { + width: 2112moon; +} + +.Ywv5coVC2RU-pIFhN9O4w { + color: green; +} + +._1tAbIwITRWAdZZE6wKNk9O { + prop: red; + duplicate: green; +} + +.Q3SQ3BwtBwUFLlg6adzOI { + color: red; +} + +._1n5XhXj4SFnYrwziC3un0d { + color: yellow; +} + +._3dnFnGkAVAiMA6etF-naHc { + color: gray; +} + +._1xUePnlnafMQ1cExy3PUWT { + color: gray; +} + +._26Jdfenl9Xn8HXwb2jipvt { + color: gainsboro; +} +", + "", + ], +] +`; + +exports[`modules composes should supports resolving: module 1`] = ` +"exports = module.exports = require(\\"../../../lib/runtime/api.js\\")(false); +// imports +exports.i(require(\\"-!../../../index.js??ref--4-0!./test-other.css\\"), \\"(min-width: 100px)\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./values.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./something.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./imported-simple.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!./relative.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!../modules/top-relative.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!package/style.css\\"), \\"\\"); +exports.i(require(\\"-!../../../index.js??ref--4-0!aliasesComposes/alias.css\\"), \\"\\"); + +// module +exports.push([module.id, \\"._14uFt0lIVKKAlKTTT29IIQ {\\\\n color: \\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"def\\"] + \\";\\\\n}\\\\n\\\\n._3XDgIzfUIQkaUInpEdo7fN {\\\\n color: blue;\\\\n}\\\\n\\\\n._1wABXM_RabWHj--wsPrhvM {\\\\n display: block;\\\\n}\\\\n\\\\n._1DFEYnAfn9LZyk4fErI86e {\\\\n width: \\" + require(\\"-!../../../index.js??ref--4-0!./something.css\\").locals[\\"something\\"] + \\";\\\\n}\\\\n\\\\n.Ywv5coVC2RU-pIFhN9O4w {\\\\n color: \\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"other\\"] + \\";\\\\n}\\\\n\\\\n._1tAbIwITRWAdZZE6wKNk9O {\\\\n prop: \\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"def\\"] + \\";\\\\n duplicate: \\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"other\\"] + \\";\\\\n}\\\\n\\\\n.Q3SQ3BwtBwUFLlg6adzOI {\\\\n color: red;\\\\n}\\\\n\\\\n._1n5XhXj4SFnYrwziC3un0d {\\\\n color: yellow;\\\\n}\\\\n\\\\n._3dnFnGkAVAiMA6etF-naHc {\\\\n color: gray;\\\\n}\\\\n\\\\n._1xUePnlnafMQ1cExy3PUWT {\\\\n color: gray;\\\\n}\\\\n\\\\n._26Jdfenl9Xn8HXwb2jipvt {\\\\n color: gainsboro;\\\\n}\\\\n\\", \\"\\"]); + +// exports +exports.locals = { + \\"def\\": \\"\\" + require(\\"-!../../../index.js??ref--4-0!./values.css\\").locals[\\"def\\"] + \\"\\", + \\"other\\": \\"_1wABXM_RabWHj--wsPrhvM\\", + \\"something\\": \\"\\" + require(\\"-!../../../index.js??ref--4-0!./something.css\\").locals[\\"something\\"] + \\"\\", + \\"foo\\": \\"_1tAbIwITRWAdZZE6wKNk9O\\", + \\"bar\\": \\"block\\", + \\"ghi\\": \\"_14uFt0lIVKKAlKTTT29IIQ\\", + \\"class\\": \\"_3XDgIzfUIQkaUInpEdo7fN\\", + \\"other-other\\": \\"_1DFEYnAfn9LZyk4fErI86e\\", + \\"green\\": \\"Ywv5coVC2RU-pIFhN9O4w\\", + \\"simple\\": \\"Q3SQ3BwtBwUFLlg6adzOI \\" + require(\\"-!../../../index.js??ref--4-0!./imported-simple.css\\").locals[\\"imported-simple\\"] + \\"\\", + \\"relative\\": \\"_1n5XhXj4SFnYrwziC3un0d \\" + require(\\"-!../../../index.js??ref--4-0!./relative.css\\").locals[\\"imported-relative\\"] + \\"\\", + \\"top-relative\\": \\"_3dnFnGkAVAiMA6etF-naHc \\" + require(\\"-!../../../index.js??ref--4-0!../modules/top-relative.css\\").locals[\\"imported-relative\\"] + \\"\\", + \\"module\\": \\"_1xUePnlnafMQ1cExy3PUWT \\" + require(\\"-!../../../index.js??ref--4-0!package/style.css\\").locals[\\"imported-module\\"] + \\"\\", + \\"alias\\": \\"_26Jdfenl9Xn8HXwb2jipvt \\" + require(\\"-!../../../index.js??ref--4-0!aliasesComposes/alias.css\\").locals[\\"imported-alias\\"] + \\"\\" +};" +`; + +exports[`modules composes should supports resolving: warnings 1`] = `Array []`; diff --git a/test/fixtures/import/css-modules.css b/test/fixtures/import/css-modules.css deleted file mode 100644 index ec7ee2d2..00000000 --- a/test/fixtures/import/css-modules.css +++ /dev/null @@ -1,33 +0,0 @@ -@import url(test-other.css) (min-width: 100px); - -@value def from './values.css'; -@value other from './values.css'; -@value other from './values.css'; -@value something from './something.css'; -@value foo: blue; -@value bar: block; - -.ghi { - color: def; -} - -.class { - color: foo; -} - -.other { - display: bar; -} - -.other-other { - width: something; -} - -.green { - color: other; -} - -.foo { - prop: def; - duplicate: other; -} diff --git a/test/fixtures/modules/alias.css b/test/fixtures/modules/alias.css new file mode 100644 index 00000000..a09f6378 --- /dev/null +++ b/test/fixtures/modules/alias.css @@ -0,0 +1,3 @@ +.imported-alias { + display: table; +} diff --git a/test/fixtures/modules/composes.css b/test/fixtures/modules/composes.css new file mode 100644 index 00000000..abf1a32a --- /dev/null +++ b/test/fixtures/modules/composes.css @@ -0,0 +1,58 @@ +@import url(test-other.css) (min-width: 100px); + +@value def from './values.css'; +@value other from './values.css'; +@value other from './values.css'; +@value something from './something.css'; +@value foo: blue; +@value bar: block; + +.ghi { + color: def; +} + +.class { + color: foo; +} + +.other { + display: bar; +} + +.other-other { + width: something; +} + +.green { + color: other; +} + +.foo { + prop: def; + duplicate: other; +} + +.simple { + color: red; + composes: imported-simple from 'imported-simple.css'; +} + +.relative { + color: yellow; + composes: imported-relative from './relative.css'; +} + +.top-relative { + color: gray; + composes: imported-relative from '../modules/top-relative.css'; +} + +.module { + color: gray; + composes: imported-module from '~package/style.css'; +} + +.alias { + color: gainsboro; + composes: imported-alias from '~aliasesComposes/alias.css'; +} diff --git a/test/fixtures/modules/imported-simple.css b/test/fixtures/modules/imported-simple.css new file mode 100644 index 00000000..888c92a5 --- /dev/null +++ b/test/fixtures/modules/imported-simple.css @@ -0,0 +1,3 @@ +.imported-simple { + display: block; +} diff --git a/test/fixtures/modules/node_modules/package/style.css b/test/fixtures/modules/node_modules/package/style.css new file mode 100644 index 00000000..1ff0fa9a --- /dev/null +++ b/test/fixtures/modules/node_modules/package/style.css @@ -0,0 +1,3 @@ +.imported-module { + display: inline-block; +} diff --git a/test/fixtures/modules/relative.css b/test/fixtures/modules/relative.css new file mode 100644 index 00000000..4cd3d00b --- /dev/null +++ b/test/fixtures/modules/relative.css @@ -0,0 +1,3 @@ +.imported-relative { + display: inline; +} diff --git a/test/fixtures/import/something.css b/test/fixtures/modules/something.css similarity index 100% rename from test/fixtures/import/something.css rename to test/fixtures/modules/something.css diff --git a/test/fixtures/modules/test-other.css b/test/fixtures/modules/test-other.css new file mode 100644 index 00000000..fc97be2e --- /dev/null +++ b/test/fixtures/modules/test-other.css @@ -0,0 +1,3 @@ +.test { + d: d; +} diff --git a/test/fixtures/modules/top-relative.css b/test/fixtures/modules/top-relative.css new file mode 100644 index 00000000..1c7eb2e9 --- /dev/null +++ b/test/fixtures/modules/top-relative.css @@ -0,0 +1,3 @@ +.top-relative { + display: flex; +} diff --git a/test/fixtures/import/values.css b/test/fixtures/modules/values.css similarity index 100% rename from test/fixtures/import/values.css rename to test/fixtures/modules/values.css diff --git a/test/helpers.js b/test/helpers.js index 354176e7..b7b6c375 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -39,6 +39,8 @@ function evaluated(output, modules, moduleId = 1) { 'import/node_modules', 'url', 'url/node_modules', + 'modules/', + 'modules/node_modules', 'modules/tests-cases/urls', 'modules/tests-cases/comments', 'modules/tests-cases/values-3', @@ -55,7 +57,10 @@ function evaluated(output, modules, moduleId = 1) { path.resolve( __dirname, `./fixtures/${importedPath}`, - module.replace('aliasesImg/', '').replace('aliasesImport/', '') + module + .replace('aliasesImg/', '') + .replace('aliasesImport/', '') + .replace('aliasesComposes/', '') ) ); @@ -174,6 +179,7 @@ function compile(fixture, config = {}, options = {}) { alias: { aliasesImg: path.resolve(__dirname, 'fixtures/url'), aliasesImport: path.resolve(__dirname, 'fixtures/import'), + aliasesComposes: path.resolve(__dirname, 'fixtures/modules'), }, }, }; diff --git a/test/import-option.test.js b/test/import-option.test.js index 9341d8df..215f9cda 100644 --- a/test/import-option.test.js +++ b/test/import-option.test.js @@ -33,11 +33,11 @@ describe('import option', () => { }); [true, 'local', 'global', false].forEach((modulesValue) => { - it(`false and modules \`${modulesValue}\``, async () => { + it(`true and modules \`${modulesValue}\``, async () => { const config = { - loader: { options: { import: false, modules: modulesValue } }, + loader: { options: { import: true, modules: modulesValue } }, }; - const testId = './import/css-modules.css'; + const testId = './import/import.css'; const stats = await webpack(testId, config); const { modules } = stats.toJson(); const module = modules.find((m) => m.id === testId); diff --git a/test/modules-option.test.js b/test/modules-option.test.js index 0c6ba929..da7348e1 100644 --- a/test/modules-option.test.js +++ b/test/modules-option.test.js @@ -36,4 +36,21 @@ describe('modules', () => { }); }); }); + + it(`composes should supports resolving`, async () => { + const config = { + loader: { options: { import: true, modules: true } }, + }; + const testId = './modules/composes.css'; + const stats = await webpack(testId, config); + const { modules } = stats.toJson(); + const module = modules.find((m) => m.id === testId); + + expect(module.source).toMatchSnapshot('module'); + expect(evaluated(module.source, modules)).toMatchSnapshot( + 'module (evaluated)' + ); + expect(stats.compilation.warnings).toMatchSnapshot('warnings'); + expect(stats.compilation.errors).toMatchSnapshot('errors'); + }); });