From 66dc59af843ab3ae0ce3bb4cc662299a38798ea8 Mon Sep 17 00:00:00 2001 From: Oscar Otero Date: Mon, 1 Jul 2024 21:17:41 +0200 Subject: [PATCH] added support for npm specifiers to postcss and lightningcss #621 --- CHANGELOG.md | 2 + core/utils/read.ts | 10 + plugins/esbuild.ts | 11 +- plugins/lightningcss.ts | 12 +- plugins/postcss.ts | 10 + tests/__snapshots__/lightningcss.test.ts.snap | 20 +- tests/__snapshots__/postcss.test.ts.snap | 586 +++++++++++++++++- tests/assets/lightningcss/text.css | 2 + tests/assets/postcss/text.css | 2 + 9 files changed, 620 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index aa2954ff..4e97ec59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Go to the `v1` branch to see the changelog of Lume 1. ## [2.2.3] - Unreleased ### Added - New option `caseSensitiveUrls` to allow to export two urls with the same name but different cases [#625]. +- Support for `npm` specifiers to postcss and lightningcss plugins [#621]. ### Changed - Nav plugin: Improved behavior for sites with pretty urls disabled. @@ -427,6 +428,7 @@ Go to the `v1` branch to see the changelog of Lume 1. [#617]: https://github.com/lumeland/lume/issues/617 [#618]: https://github.com/lumeland/lume/issues/618 [#619]: https://github.com/lumeland/lume/issues/619 +[#621]: https://github.com/lumeland/lume/issues/621 [#625]: https://github.com/lumeland/lume/issues/625 [2.2.3]: https://github.com/lumeland/lume/compare/v2.2.2...HEAD diff --git a/core/utils/read.ts b/core/utils/read.ts index ae537e59..a78b4fe6 100644 --- a/core/utils/read.ts +++ b/core/utils/read.ts @@ -84,6 +84,16 @@ export async function read( : response.text(); } +/** Read a text file like a browser */ +export async function readFile(path: string): Promise { + return await read(path, false, { + headers: { + "User-Agent": + "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/115.0", + }, + }); +} + /** * Clear the cache of remote files. */ diff --git a/plugins/esbuild.ts b/plugins/esbuild.ts index 45a2f9a8..d94d1346 100644 --- a/plugins/esbuild.ts +++ b/plugins/esbuild.ts @@ -7,7 +7,7 @@ import { import { merge } from "../core/utils/object.ts"; import { readDenoConfig } from "../core/utils/deno_config.ts"; import { log } from "../core/utils/log.ts"; -import { read } from "../core/utils/read.ts"; +import { readFile } from "../core/utils/read.ts"; import { build, BuildOptions, OutputFile, stop } from "../deps/esbuild.ts"; import { extname, fromFileUrl, posix, toFileUrl } from "../deps/path.ts"; import { prepareAsset, saveAsset } from "./source_maps.ts"; @@ -334,15 +334,6 @@ function pathWithoutExtension(path: string): string { return path.replace(/\.\w+$/, ""); } -export async function readFile(path: string): Promise { - return await read(path, false, { - headers: { - "User-Agent": - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/115.0", - }, - }); -} - function resolveImports(content: string, esm: EsmOptions): string { return content.replaceAll( /(from\s*)["']([^"']+)["']/g, diff --git a/plugins/lightningcss.ts b/plugins/lightningcss.ts index 2ac3a8cd..683427cd 100644 --- a/plugins/lightningcss.ts +++ b/plugins/lightningcss.ts @@ -1,7 +1,7 @@ import { bundleAsync, transform } from "../deps/lightningcss.ts"; import { resolveInclude } from "../core/utils/path.ts"; import { merge } from "../core/utils/object.ts"; -import { read } from "../core/utils/read.ts"; +import { readFile } from "../core/utils/read.ts"; import textLoader from "../core/loaders/text.ts"; import { Page } from "../core/file.ts"; import { prepareAsset, saveAsset } from "./source_maps.ts"; @@ -119,6 +119,9 @@ export default function (userOptions?: Options) { ...options.options, resolver: { resolve(id: string, from: string) { + if (id.startsWith("npm:")) { + return `https://esm.sh/${id.slice(4)}`; + } return resolveInclude(id, includes, posix.dirname(from)); }, async read(file: string) { @@ -127,12 +130,7 @@ export default function (userOptions?: Options) { } if (file.startsWith("http")) { - return read(file, false, { - headers: { - "User-Agent": - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/115.0", - }, - }); + return readFile(file); } return await site.getContent(file, textLoader) as string; diff --git a/plugins/postcss.ts b/plugins/postcss.ts index eb28c24b..05f0ed78 100644 --- a/plugins/postcss.ts +++ b/plugins/postcss.ts @@ -2,6 +2,7 @@ import { autoprefixer, postcss, postcssImport } from "../deps/postcss.ts"; import { merge } from "../core/utils/object.ts"; import { concurrent } from "../core/utils/concurrent.ts"; import { resolveInclude } from "../core/utils/path.ts"; +import { readFile } from "../core/utils/read.ts"; import { Page } from "../core/file.ts"; import { prepareAsset, saveAsset } from "./source_maps.ts"; import textLoader from "../core/loaders/text.ts"; @@ -114,11 +115,20 @@ function configureImport(site: Site, includes: string) { return postcssImport({ /** Resolve the import path */ resolve(id: string, basedir: string) { + if (id.startsWith("npm:")) { + return "/" + id; + } + return resolveInclude(id, includes, basedir); }, /** Load the content (using the Lume reader) */ async load(file: string) { + if (file.startsWith("/npm:")) { + const url = `https://esm.sh/${file.slice(5)}`; + return await readFile(url); + } + const content = await site.getContent(file, textLoader); if (content === undefined) { throw new Error(`File ${file} not found`); diff --git a/tests/__snapshots__/lightningcss.test.ts.snap b/tests/__snapshots__/lightningcss.test.ts.snap index 28a61633..dac01845 100644 --- a/tests/__snapshots__/lightningcss.test.ts.snap +++ b/tests/__snapshots__/lightningcss.test.ts.snap @@ -151,10 +151,12 @@ snapshot[`lightningcss plugin (only transform) 3`] = ` }, }, { - content: ".text{font-family:var(--font-family)}.text p{color:var(--color);box-shadow:0 0 .5em var(--background);-webkit-backface-visibility:hidden;backface-visibility:hidden}", + content: '@import "npm:modern-normalize@2.0.0";.text{font-family:var(--font-family)}.text p{color:var(--color);box-shadow:0 0 .5em var(--background);-webkit-backface-visibility:hidden;backface-visibility:hidden}', data: { basename: "text", - content: ".text { + content: '@import "npm:modern-normalize@2.0.0"; + +.text { font-family: var(--font-family); & p { @@ -163,7 +165,7 @@ snapshot[`lightningcss plugin (only transform) 3`] = ` backface-visibility: hidden; } } -", +', date: [], mergedKeys: [ "tags", @@ -311,7 +313,8 @@ snapshot[`lightningcss plugin (bundle mode) 2`] = `[]`; snapshot[`lightningcss plugin (bundle mode) 3`] = ` [ { - content: "::root{--color:#333;--background:#fff;--font-family:sans-serif}.text{font-family:var(--font-family)}.text p{color:var(--color);box-shadow:0 0 .5em var(--background);-webkit-backface-visibility:hidden;backface-visibility:hidden}", + content: "/*! modern-normalize v2.0.0 | MIT License | https://github.com/sindresorhus/modern-normalize */ +::root{--color:#333;--background:#fff;--font-family:sans-serif}*,:before,:after{box-sizing:border-box}html{-webkit-text-size-adjust:100%;tab-size:4;font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Noto Sans,Ubuntu,Cantarell,Helvetica Neue,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji;line-height:1.15}body{margin:0}hr{color:inherit;height:0}abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:100%;line-height:1.15}button,select{text-transform:none}button{-webkit-appearance:button}[type=button]{-webkit-appearance:button}[type=reset]{-webkit-appearance:button}[type=submit]{-webkit-appearance:button}::-moz-focus-inner{border-style:none;padding:0}:-moz-focusring{outline:1px dotted buttontext}:-moz-ui-invalid{box-shadow:none}legend{padding:0}progress{vertical-align:baseline}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}.text{font-family:var(--font-family)}.text p{color:var(--color);box-shadow:0 0 .5em var(--background);-webkit-backface-visibility:hidden;backface-visibility:hidden}", data: { basename: "index", content: '@import "variables.css"; @@ -339,10 +342,13 @@ snapshot[`lightningcss plugin (bundle mode) 3`] = ` }, }, { - content: ".text{font-family:var(--font-family)}.text p{color:var(--color);box-shadow:0 0 .5em var(--background);-webkit-backface-visibility:hidden;backface-visibility:hidden}", + content: "/*! modern-normalize v2.0.0 | MIT License | https://github.com/sindresorhus/modern-normalize */ +*,:before,:after{box-sizing:border-box}html{-webkit-text-size-adjust:100%;tab-size:4;font-family:system-ui,-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Noto Sans,Ubuntu,Cantarell,Helvetica Neue,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji;line-height:1.15}body{margin:0}hr{color:inherit;height:0}abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;font-size:1em}small{font-size:80%}sub,sup{vertical-align:baseline;font-size:75%;line-height:0;position:relative}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit}button,input,optgroup,select,textarea{margin:0;font-family:inherit;font-size:100%;line-height:1.15}button,select{text-transform:none}button{-webkit-appearance:button}[type=button]{-webkit-appearance:button}[type=reset]{-webkit-appearance:button}[type=submit]{-webkit-appearance:button}::-moz-focus-inner{border-style:none;padding:0}:-moz-focusring{outline:1px dotted buttontext}:-moz-ui-invalid{box-shadow:none}legend{padding:0}progress{vertical-align:baseline}::-webkit-inner-spin-button{height:auto}::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}.text{font-family:var(--font-family)}.text p{color:var(--color);box-shadow:0 0 .5em var(--background);-webkit-backface-visibility:hidden;backface-visibility:hidden}", data: { basename: "text", - content: ".text { + content: '@import "npm:modern-normalize@2.0.0"; + +.text { font-family: var(--font-family); & p { @@ -351,7 +357,7 @@ snapshot[`lightningcss plugin (bundle mode) 3`] = ` backface-visibility: hidden; } } -", +', date: [], mergedKeys: [ "tags", diff --git a/tests/__snapshots__/postcss.test.ts.snap b/tests/__snapshots__/postcss.test.ts.snap index 387c0612..5a17e6d1 100644 --- a/tests/__snapshots__/postcss.test.ts.snap +++ b/tests/__snapshots__/postcss.test.ts.snap @@ -135,6 +135,283 @@ snapshot[`postcss plugin 3`] = ` --font-family: sans-serif; } +/*! modern-normalize v2.0.0 | MIT License | https://github.com/sindresorhus/modern-normalize */ + +/* +Document +======== +*/ + +/** +Use a better box model (opinionated). +*/ + +*, +::before, +::after { + box-sizing: border-box; +} + +html { + /* Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3) */ + font-family: + system-ui, + 'Segoe UI', + Roboto, + Helvetica, + Arial, + sans-serif, + 'Apple Color Emoji', + 'Segoe UI Emoji'; + line-height: 1.15; /* 1. Correct the line height in all browsers. */ + -webkit-text-size-adjust: 100%; /* 2. Prevent adjustments of font size after orientation changes in iOS. */ + -moz-tab-size: 4; /* 3. Use a more readable tab size (opinionated). */ + -o-tab-size: 4; + tab-size: 4; /* 3 */ +} + +/* +Sections +======== +*/ + +body { + margin: 0; /* Remove the margin in all browsers. */ +} + +/* +Grouping content +================ +*/ + +/** +1. Add the correct height in Firefox. +2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655) +*/ + +hr { + height: 0; /* 1 */ + color: inherit; /* 2 */ +} + +/* +Text-level semantics +==================== +*/ + +/** +Add the correct text decoration in Chrome, Edge, and Safari. +*/ + +abbr[title] { + -webkit-text-decoration: underline dotted; + text-decoration: underline dotted; +} + +/** +Add the correct font weight in Edge and Safari. +*/ + +b, +strong { + font-weight: bolder; +} + +/** +1. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3) +2. Correct the odd 'em' font sizing in all browsers. +*/ + +code, +kbd, +samp, +pre { + font-family: + ui-monospace, + SFMono-Regular, + Consolas, + 'Liberation Mono', + Menlo, + monospace; /* 1 */ + font-size: 1em; /* 2 */ +} + +/** +Add the correct font size in all browsers. +*/ + +small { + font-size: 80%; +} + +/** +Prevent 'sub' and 'sup' elements from affecting the line height in all browsers. +*/ + +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sub { + bottom: -0.25em; +} + +sup { + top: -0.5em; +} + +/* +Tabular data +============ +*/ + +/** +1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297) +2. Correct table border color inheritance in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016) +*/ + +table { + text-indent: 0; /* 1 */ + border-color: inherit; /* 2 */ +} + +/* +Forms +===== +*/ + +/** +1. Change the font styles in all browsers. +2. Remove the margin in Firefox and Safari. +*/ + +button, +input, +optgroup, +select, +textarea { + font-family: inherit; /* 1 */ + font-size: 100%; /* 1 */ + line-height: 1.15; /* 1 */ + margin: 0; /* 2 */ +} + +/** +Remove the inheritance of text transform in Edge and Firefox. +*/ + +button, +select { + text-transform: none; +} + +/** +Correct the inability to style clickable types in iOS and Safari. +*/ + +button, +[type='button'], +[type='reset'], +[type='submit'] { + -webkit-appearance: button; +} + +/** +Remove the inner border and padding in Firefox. +*/ + +::-moz-focus-inner { + border-style: none; + padding: 0; +} + +/** +Restore the focus styles unset by the previous rule. +*/ + +:-moz-focusring { + outline: 1px dotted ButtonText; +} + +/** +Remove the additional ':invalid' styles in Firefox. +See: https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737 +*/ + +:-moz-ui-invalid { + box-shadow: none; +} + +/** +Remove the padding so developers are not caught out when they zero out 'fieldset' elements in all browsers. +*/ + +legend { + padding: 0; +} + +/** +Add the correct vertical alignment in Chrome and Firefox. +*/ + +progress { + vertical-align: baseline; +} + +/** +Correct the cursor style of increment and decrement buttons in Safari. +*/ + +::-webkit-inner-spin-button, +::-webkit-outer-spin-button { + height: auto; +} + +/** +1. Correct the odd appearance in Chrome and Safari. +2. Correct the outline style in Safari. +*/ + +[type='search'] { + -webkit-appearance: textfield; /* 1 */ + outline-offset: -2px; /* 2 */ +} + +/** +Remove the inner padding in Chrome and Safari on macOS. +*/ + +::-webkit-search-decoration { + -webkit-appearance: none; +} + +/** +1. Correct the inability to style clickable types in iOS and Safari. +2. Change font properties to 'inherit' in Safari. +*/ + +::-webkit-file-upload-button { + -webkit-appearance: button; /* 1 */ + font: inherit; /* 2 */ +} + +/* +Interactive +=========== +*/ + +/* +Add the correct display in Chrome and Safari. +*/ + +summary { + display: list-item; +} + .text { font-family: var(--font-family); @@ -173,7 +450,284 @@ snapshot[`postcss plugin 3`] = ` }, }, { - content: ".text { + content: "/*! modern-normalize v2.0.0 | MIT License | https://github.com/sindresorhus/modern-normalize */ + +/* +Document +======== +*/ + +/** +Use a better box model (opinionated). +*/ + +*, +::before, +::after { + box-sizing: border-box; +} + +html { + /* Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3) */ + font-family: + system-ui, + 'Segoe UI', + Roboto, + Helvetica, + Arial, + sans-serif, + 'Apple Color Emoji', + 'Segoe UI Emoji'; + line-height: 1.15; /* 1. Correct the line height in all browsers. */ + -webkit-text-size-adjust: 100%; /* 2. Prevent adjustments of font size after orientation changes in iOS. */ + -moz-tab-size: 4; /* 3. Use a more readable tab size (opinionated). */ + -o-tab-size: 4; + tab-size: 4; /* 3 */ +} + +/* +Sections +======== +*/ + +body { + margin: 0; /* Remove the margin in all browsers. */ +} + +/* +Grouping content +================ +*/ + +/** +1. Add the correct height in Firefox. +2. Correct the inheritance of border color in Firefox. (https://bugzilla.mozilla.org/show_bug.cgi?id=190655) +*/ + +hr { + height: 0; /* 1 */ + color: inherit; /* 2 */ +} + +/* +Text-level semantics +==================== +*/ + +/** +Add the correct text decoration in Chrome, Edge, and Safari. +*/ + +abbr[title] { + -webkit-text-decoration: underline dotted; + text-decoration: underline dotted; +} + +/** +Add the correct font weight in Edge and Safari. +*/ + +b, +strong { + font-weight: bolder; +} + +/** +1. Improve consistency of default fonts in all browsers. (https://github.com/sindresorhus/modern-normalize/issues/3) +2. Correct the odd 'em' font sizing in all browsers. +*/ + +code, +kbd, +samp, +pre { + font-family: + ui-monospace, + SFMono-Regular, + Consolas, + 'Liberation Mono', + Menlo, + monospace; /* 1 */ + font-size: 1em; /* 2 */ +} + +/** +Add the correct font size in all browsers. +*/ + +small { + font-size: 80%; +} + +/** +Prevent 'sub' and 'sup' elements from affecting the line height in all browsers. +*/ + +sub, +sup { + font-size: 75%; + line-height: 0; + position: relative; + vertical-align: baseline; +} + +sub { + bottom: -0.25em; +} + +sup { + top: -0.5em; +} + +/* +Tabular data +============ +*/ + +/** +1. Remove text indentation from table contents in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=999088, https://bugs.webkit.org/show_bug.cgi?id=201297) +2. Correct table border color inheritance in Chrome and Safari. (https://bugs.chromium.org/p/chromium/issues/detail?id=935729, https://bugs.webkit.org/show_bug.cgi?id=195016) +*/ + +table { + text-indent: 0; /* 1 */ + border-color: inherit; /* 2 */ +} + +/* +Forms +===== +*/ + +/** +1. Change the font styles in all browsers. +2. Remove the margin in Firefox and Safari. +*/ + +button, +input, +optgroup, +select, +textarea { + font-family: inherit; /* 1 */ + font-size: 100%; /* 1 */ + line-height: 1.15; /* 1 */ + margin: 0; /* 2 */ +} + +/** +Remove the inheritance of text transform in Edge and Firefox. +*/ + +button, +select { + text-transform: none; +} + +/** +Correct the inability to style clickable types in iOS and Safari. +*/ + +button, +[type='button'], +[type='reset'], +[type='submit'] { + -webkit-appearance: button; +} + +/** +Remove the inner border and padding in Firefox. +*/ + +::-moz-focus-inner { + border-style: none; + padding: 0; +} + +/** +Restore the focus styles unset by the previous rule. +*/ + +:-moz-focusring { + outline: 1px dotted ButtonText; +} + +/** +Remove the additional ':invalid' styles in Firefox. +See: https://github.com/mozilla/gecko-dev/blob/2f9eacd9d3d995c937b4251a5557d95d494c9be1/layout/style/res/forms.css#L728-L737 +*/ + +:-moz-ui-invalid { + box-shadow: none; +} + +/** +Remove the padding so developers are not caught out when they zero out 'fieldset' elements in all browsers. +*/ + +legend { + padding: 0; +} + +/** +Add the correct vertical alignment in Chrome and Firefox. +*/ + +progress { + vertical-align: baseline; +} + +/** +Correct the cursor style of increment and decrement buttons in Safari. +*/ + +::-webkit-inner-spin-button, +::-webkit-outer-spin-button { + height: auto; +} + +/** +1. Correct the odd appearance in Chrome and Safari. +2. Correct the outline style in Safari. +*/ + +[type='search'] { + -webkit-appearance: textfield; /* 1 */ + outline-offset: -2px; /* 2 */ +} + +/** +Remove the inner padding in Chrome and Safari on macOS. +*/ + +::-webkit-search-decoration { + -webkit-appearance: none; +} + +/** +1. Correct the inability to style clickable types in iOS and Safari. +2. Change font properties to 'inherit' in Safari. +*/ + +::-webkit-file-upload-button { + -webkit-appearance: button; /* 1 */ + font: inherit; /* 2 */ +} + +/* +Interactive +=========== +*/ + +/* +Add the correct display in Chrome and Safari. +*/ + +summary { + display: list-item; +} + +.text { font-family: var(--font-family); & p { @@ -186,7 +740,9 @@ snapshot[`postcss plugin 3`] = ` ", data: { basename: "text", - content: ".text { + content: '@import "npm:modern-normalize@2.0.0"; + +.text { font-family: var(--font-family); & p { @@ -195,7 +751,7 @@ snapshot[`postcss plugin 3`] = ` backdrop-filter: blur(2px); } } -", +', date: [], mergedKeys: [ "tags", @@ -375,7 +931,9 @@ snapshot[`postcss plugin without includes 3`] = ` }, }, { - content: ".text { + content: '@import "npm:modern-normalize@2.0.0"; + +.text { font-family: var(--font-family); & p { @@ -385,10 +943,12 @@ snapshot[`postcss plugin without includes 3`] = ` backdrop-filter: blur(2px); } } -", +', data: { basename: "text", - content: ".text { + content: '@import "npm:modern-normalize@2.0.0"; + +.text { font-family: var(--font-family); & p { @@ -397,7 +957,7 @@ snapshot[`postcss plugin without includes 3`] = ` backdrop-filter: blur(2px); } } -", +', date: [], mergedKeys: [ "tags", @@ -547,7 +1107,9 @@ snapshot[`postcss plugin with hooks 2`] = `[]`; snapshot[`postcss plugin with hooks 3`] = ` [ { - content: ".foo{color:red}::root{--color:#333;--background:#fff;--font-family:sans-serif}.text{font-family:var(--font-family);& p{-webkit-backdrop-filter:blur(2px);backdrop-filter:blur(2px);box-shadow:0 0 .5em var(--background);color:var(--color)}}", + content: ".foo{color:red}::root{--color:#333;--background:#fff;--font-family:sans-serif} + +/*! modern-normalize v2.0.0 | MIT License | https://github.com/sindresorhus/modern-normalize */*,:after,:before{box-sizing:border-box}html{font-family:system-ui,Segoe UI,Roboto,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji;line-height:1.15;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4}body{margin:0}hr{color:inherit;height:0}abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}::-moz-focus-inner{border-style:none;padding:0}:-moz-focusring{outline:1px dotted ButtonText}:-moz-ui-invalid{box-shadow:none}legend{padding:0}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}.text{font-family:var(--font-family);& p{-webkit-backdrop-filter:blur(2px);backdrop-filter:blur(2px);box-shadow:0 0 .5em var(--background);color:var(--color)}}", data: { basename: "index.min", content: '@import "variables.css"; @@ -575,10 +1137,12 @@ snapshot[`postcss plugin with hooks 3`] = ` }, }, { - content: ".text{font-family:var(--font-family);& p{-webkit-backdrop-filter:blur(2px);backdrop-filter:blur(2px);box-shadow:0 0 .5em var(--background);color:var(--color)}}", + content: "/*! modern-normalize v2.0.0 | MIT License | https://github.com/sindresorhus/modern-normalize */*,:after,:before{box-sizing:border-box}html{font-family:system-ui,Segoe UI,Roboto,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji;line-height:1.15;-webkit-text-size-adjust:100%;-moz-tab-size:4;-o-tab-size:4;tab-size:4}body{margin:0}hr{color:inherit;height:0}abbr[title]{-webkit-text-decoration:underline dotted;text-decoration:underline dotted}b,strong{font-weight:bolder}code,kbd,pre,samp{font-family:ui-monospace,SFMono-Regular,Consolas,Liberation Mono,Menlo,monospace;font-size:1em}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{border-color:inherit;text-indent:0}button,input,optgroup,select,textarea{font-family:inherit;font-size:100%;line-height:1.15;margin:0}button,select{text-transform:none}[type=button],[type=reset],[type=submit],button{-webkit-appearance:button}::-moz-focus-inner{border-style:none;padding:0}:-moz-focusring{outline:1px dotted ButtonText}:-moz-ui-invalid{box-shadow:none}legend{padding:0}progress{vertical-align:baseline}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type=search]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{-webkit-appearance:button;font:inherit}summary{display:list-item}.text{font-family:var(--font-family);& p{-webkit-backdrop-filter:blur(2px);backdrop-filter:blur(2px);box-shadow:0 0 .5em var(--background);color:var(--color)}}", data: { basename: "text", - content: ".text { + content: '@import "npm:modern-normalize@2.0.0"; + +.text { font-family: var(--font-family); & p { @@ -587,7 +1151,7 @@ snapshot[`postcss plugin with hooks 3`] = ` backdrop-filter: blur(2px); } } -", +', date: [], mergedKeys: [ "tags", diff --git a/tests/assets/lightningcss/text.css b/tests/assets/lightningcss/text.css index aa49b73d..b26faffd 100644 --- a/tests/assets/lightningcss/text.css +++ b/tests/assets/lightningcss/text.css @@ -1,3 +1,5 @@ +@import "npm:modern-normalize@2.0.0"; + .text { font-family: var(--font-family); diff --git a/tests/assets/postcss/text.css b/tests/assets/postcss/text.css index 5d49b6f8..1a9427c3 100644 --- a/tests/assets/postcss/text.css +++ b/tests/assets/postcss/text.css @@ -1,3 +1,5 @@ +@import "npm:modern-normalize@2.0.0"; + .text { font-family: var(--font-family);