diff --git a/index.ts b/index.ts index fd7c118..40fa74d 100644 --- a/index.ts +++ b/index.ts @@ -184,14 +184,13 @@ export default function sveltePlugin(options?: esbuildSvelteOptions): Plugin { try { preprocessResult = await preprocess( - originalSource, - options.preprocess, - { - filename, - } + originalSource, + options.preprocess, + { + filename, + } ); - } - catch(e: any) { + } catch (e: any) { // if preprocess failed there are chances that an external dependency caused exception // to avoid stop watching those files, we keep the previous dependencies if available if (build.initialOptions.watch && cachedFile) { diff --git a/test/fixtures/watch-preprocessing/entry.js b/test/fixtures/watch-preprocessing/entry.js index 5b4c482..bbe8c80 100644 --- a/test/fixtures/watch-preprocessing/entry.js +++ b/test/fixtures/watch-preprocessing/entry.js @@ -1,5 +1,5 @@ import Test from "./external-styles.svelte"; new Test({ - target: document.body, + target: document.body, }); diff --git a/test/fixtures/watch-preprocessing/external.scss b/test/fixtures/watch-preprocessing/external.scss index 7cd741e..3d9a2b2 100644 --- a/test/fixtures/watch-preprocessing/external.scss +++ b/test/fixtures/watch-preprocessing/external.scss @@ -1 +1,3 @@ -p { color: red; } \ No newline at end of file +p { + color: red; +} diff --git a/test/watchPreprocessingTest.mjs b/test/watchPreprocessingTest.mjs index e4ada32..818f0ae 100644 --- a/test/watchPreprocessingTest.mjs +++ b/test/watchPreprocessingTest.mjs @@ -11,65 +11,66 @@ const __filename = fileURLToPath(import.meta.url); const __dirname = dirname(__filename); test("Watch and build while preprocess of external dependency succeed and fails", async () => { + function _createDeferred() { + let resolve = null; + let reject = null; + const promise = new Promise((_resolve, _reject) => { + resolve = _resolve; + reject = _reject; + }); + promise.forceResolve = resolve; + promise.forceReject = reject; + return promise; + } - function _createDeferred() { - let resolve = null; - let reject = null; - const promise = new Promise((_resolve, _reject) => { - resolve = _resolve; - reject = _reject; - }); - promise.forceResolve = resolve; - promise.forceReject = reject; - return promise; - } - - let count = 0; - const firstRebuild = _createDeferred(); - const secondRebuild = _createDeferred(); + let count = 0; + const firstRebuild = _createDeferred(); + const secondRebuild = _createDeferred(); - //more advanced - const results = await _build({ - entryPoints: ["./test/fixtures/watch-preprocessing/entry.js"], - outdir: "../example/dist", - format: "esm", - minify: true, - bundle: true, - splitting: true, - write: false, //Don't write anywhere - sourcemap: "inline", - plugins: [ - sveltePlugin({ - preprocess: { - style: sass(), + //more advanced + const results = await _build({ + entryPoints: ["./test/fixtures/watch-preprocessing/entry.js"], + outdir: "../example/dist", + format: "esm", + minify: true, + bundle: true, + splitting: true, + write: false, //Don't write anywhere + sourcemap: "inline", + plugins: [ + sveltePlugin({ + preprocess: { + style: sass(), + }, + }), + ], + watch: { + onRebuild(err, result) { + count++; + if (count === 1) { + firstRebuild.forceResolve(err); + } else if (count === 2) { + secondRebuild.forceResolve(result); + } + }, }, - }), - ], - watch: { - onRebuild(err, result) { - count++; - if (count === 1) { - firstRebuild.forceResolve(err); - } - else if (count === 2) { - secondRebuild.forceResolve(result); - } - }, - }, - }); + }); - // write external scss with invalid syntax - writeFileSync(`${__dirname}/fixtures/watch-preprocessing/external.scss`, 'p { color: red; }!$%^&*()@$%^@@'); - const firstRebuildResult = await firstRebuild; - assert.ok(firstRebuildResult instanceof Error, 'First build did not fail'); + // write external scss with invalid syntax + writeFileSync( + `${__dirname}/fixtures/watch-preprocessing/external.scss`, + "p { color: red; }!$%^&*()@$%^@@" + ); + const firstRebuildResult = await firstRebuild; + assert.ok(firstRebuildResult instanceof Error, "First build did not fail"); - // write external scss with valid syntax again - writeFileSync(`${__dirname}/fixtures/watch-preprocessing/external.scss`, 'p { color: red; }'); - const secondRebuildResult = await secondRebuild; - assert.ok(secondRebuildResult.errors.length === 0, "Second build fail"); + // write external scss with valid syntax again + writeFileSync(`${__dirname}/fixtures/watch-preprocessing/external.scss`, "p { color: red; }"); + const secondRebuildResult = await secondRebuild; + assert.ok(secondRebuildResult.errors.length === 0, "Second build fail"); - // stop watching - results.stop(); + // stop watching + results.stop(); }); test.run();