diff --git a/packages/svelte/svelte.js b/packages/svelte/svelte.js index 037ee13a5..4f996c6b5 100644 --- a/packages/svelte/svelte.js +++ b/packages/svelte/svelte.js @@ -17,7 +17,8 @@ module.exports = (config = false) => { // Defined here to avoid .lastIndex bugs since /g is set const linkRegex = /]*?\bhref=\s*(?:"([^"]+)"|'([^']+)'|([^>\s]+))[^>]*>/gim; - const processor = new Processor(config); + // Use a passed processor, or set up our own if necessary + const { processor = new Processor(config) } = config; // eslint-disable-next-line no-console, no-empty-function const log = config.verbose ? console.log.bind(console, "[svelte]") : () => {}; diff --git a/packages/svelte/test/__snapshots__/svelte.test.js.snap b/packages/svelte/test/__snapshots__/svelte.test.js.snap index fa09f3590..264447908 100644 --- a/packages/svelte/test/__snapshots__/svelte.test.js.snap +++ b/packages/svelte/test/__snapshots__/svelte.test.js.snap @@ -398,40 +398,60 @@ exports[`/svelte.js should ignore files without +
Source
" +`; + +exports[`/svelte.js should invalidate files before reprocessing ( +
Source
" +`; + +exports[`/svelte.js should invalidate files before reprocessing ( +
Source
+ `)); + + const filename = require.resolve(`./output/source.html`); + const { processor, preprocess } = plugin({ + namer, + }); + + let processed = await svelte.preprocess( + fs.readFileSync(filename, "utf8"), + Object.assign({}, preprocess, { filename }) + ); + + expect(processed.toString()).toMatchSnapshot(); + + let output = await processor.output(); + + expect(output.css).toMatchSnapshot(); + + // V2 of CSS + fs.writeFileSync(path.resolve(__dirname, "./output/source.html"), dedent(` + +
Source
+ `)); + + processed = await svelte.preprocess( + fs.readFileSync(filename, "utf8"), + Object.assign({}, preprocess, { filename }) + ); + + expect(processed.toString()).toMatchSnapshot(); + + output = await processor.output(); + + expect(output.css).toMatchSnapshot(); + }); }); diff --git a/packages/www/src/guide/usage-svelte.md b/packages/www/src/guide/usage-svelte.md index 80be1cd9b..478e4a029 100644 --- a/packages/www/src/guide/usage-svelte.md +++ b/packages/www/src/guide/usage-svelte.md @@ -128,9 +128,9 @@ module.exports = { If `true` whenever a missing replacement is found like `{css.doesnotexist}` an error will be thrown aborting the file processing. Defaults to `false`. -##### `clean` +##### `procesor` -If `true` will re-process any previously handled files (and remove any files that dependended on them). Might be useful, but currently also dangerous (see [#522](https://github.com/tivac/modular-css/issues/522)). Defaults to `false`. +Pass a previously-created `@modular-css/processor` instance into the preprocessor. Will **not** pass through any other options to the processor if this is set, but `strict` will still be honored by the preprocessor. ##### Shared Options