Skip to content

Commit

Permalink
fix(svelte): support non .css extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
tivac committed Feb 3, 2022
1 parent d434f92 commit 8bf5a18
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
1 change: 1 addition & 0 deletions packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
},
"dependencies": {
"@modular-css/processor": "file:../processor",
"@rollup/pluginutils": "^4.1.2",
"escape-string-regexp": "^4.0.0",
"is-url": "^1.2.4",
"slash": "^3.0.0"
Expand Down
27 changes: 22 additions & 5 deletions packages/svelte/svelte.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const path = require("path");
const isUrl = require("is-url");
const escape = require("escape-string-regexp");
const slash = require("slash");
const utils = require("@rollup/pluginutils");

const Processor = require("@modular-css/processor");

Expand All @@ -17,20 +18,36 @@ const linkRegex = /<link\b[^<>]*?\bhref=\s*(?:"([^"]+)"|'([^']+)'|([^>\s]+))[^>]

const prefix = `[${require("./package.json").name}]`;

module.exports = (config = false) => {
const CONFIG_DEFAULTS = {
verbose : false,
values : false,

// Regexp to work around https://github.com/rollup/rollup-pluginutils/issues/39
include : /\.css$/i,
};

module.exports = (opts = {}) => {
const options = {
__proto__ : null,
...CONFIG_DEFAULTS,
...opts,
};

// Use a passed processor, or set up our own if necessary
const { processor = new Processor(config) } = config;
const { processor = new Processor(options) } = options;

const { cwd } = processor.options;

// eslint-disable-next-line no-console, no-empty-function
const log = config.verbose ? console.log.bind(console, prefix) : () => {};
const log = options.verbose ? console.log.bind(console, prefix) : () => {};

// eslint-disable-next-line no-console
const warn = console.warn.bind(console, prefix, "WARN");

const relative = (file) => slash(path.relative(cwd, file));

const filter = utils.createFilter(options.include, options.exclude);

// Check for and stringify any values in the template we couldn't convert
const missing = ({ source, file }) => {
missedRegex.lastIndex = 0;
Expand Down Expand Up @@ -130,7 +147,7 @@ module.exports = (config = false) => {
return out;
}

if(!href.endsWith(".css")) {
if(!filter(href)) {
// eslint-disable-next-line no-console
console.warn(`Possible invalid <link> href: ${href}`);
}
Expand Down Expand Up @@ -235,7 +252,7 @@ module.exports = (config = false) => {
});
}

if(config.values && valueKeys.length) {
if(options.values && valueKeys.length) {
log("updating source {cssvalue.<key>} references from", css);
log(JSON.stringify(valueKeys));

Expand Down

0 comments on commit 8bf5a18

Please sign in to comment.