From 8d776738ab920a30c32898c7e39e5fe92a452e62 Mon Sep 17 00:00:00 2001 From: Pat Cavit Date: Mon, 28 Jan 2019 23:55:28 -0800 Subject: [PATCH 1/3] feat: svelte takes an existing processor No real need for this atm, but it's easy to add & support using destructuring so might as well! --- packages/svelte/svelte.js | 3 ++- .../test/__snapshots__/svelte.test.js.snap | 18 +++++++++++++ packages/svelte/test/svelte.test.js | 26 +++++++++++++++++++ 3 files changed, 46 insertions(+), 1 deletion(-) 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..85c50d1da 100644 --- a/packages/svelte/test/__snapshots__/svelte.test.js.snap +++ b/packages/svelte/test/__snapshots__/svelte.test.js.snap @@ -631,6 +631,24 @@ Array [ exports[`/svelte.js should throw on both +
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(); + }); }); From 9ae5067a30d766c0a757820cfe57b039e5267576 Mon Sep 17 00:00:00 2001 From: Pat Cavit Date: Tue, 29 Jan 2019 00:00:55 -0800 Subject: [PATCH 3/3] docs: new svelte arg Also removed old `clean` arg that was disabled by default and not really supported. Invalidates by default now but that only removes files **if** a new version is written over the top of them, so it should be an overall win! --- packages/www/src/guide/usage-svelte.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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