Skip to content

Commit

Permalink
- Fixed lint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximiliano Ruani committed Jun 2, 2022
1 parent 9ec1e56 commit bad10e3
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 62 deletions.
13 changes: 6 additions & 7 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/watch-preprocessing/entry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Test from "./external-styles.svelte";

new Test({
target: document.body,
target: document.body,
});
4 changes: 3 additions & 1 deletion test/fixtures/watch-preprocessing/external.scss
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
p { color: red; }
p {
color: red;
}
107 changes: 54 additions & 53 deletions test/watchPreprocessingTest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

0 comments on commit bad10e3

Please sign in to comment.