Skip to content

Commit 16a96f8

Browse files
authored
fix: use native existsSync method (#141)
1 parent 2afbb43 commit 16a96f8

File tree

1 file changed

+5
-15
lines changed

1 file changed

+5
-15
lines changed

index.js

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const fs = require('fs');
21
const path = require('path');
2+
const { existsSync } = require('fs');
33
const relative = require('require-relative');
44
const { version } = require('svelte/package.json');
55
const { createFilter } = require('rollup-pluginutils');
@@ -59,16 +59,6 @@ function tryResolve(pkg, importer) {
5959
}
6060
}
6161

62-
function exists(file) {
63-
try {
64-
fs.statSync(file);
65-
return true;
66-
} catch (err) {
67-
if (err.code === 'ENOENT') return false;
68-
throw err;
69-
}
70-
}
71-
7262
class CssWriter {
7363
constructor(context, bundle, isDev, code, filename, map) {
7464
this.code = code;
@@ -213,7 +203,7 @@ module.exports = function svelte(options = {}) {
213203
if (pkg['svelte.root']) {
214204
// TODO remove this. it's weird and unnecessary
215205
const sub = path.resolve(dir, pkg['svelte.root'], parts.join('/'));
216-
if (exists(sub)) return sub;
206+
if (existsSync(sub)) return sub;
217207
}
218208
}
219209
},
@@ -227,9 +217,9 @@ module.exports = function svelte(options = {}) {
227217

228218
const extension = path.extname(id);
229219
if (!~extensions.indexOf(extension)) return null;
230-
220+
231221
const filename = path.relative(process.cwd(), id);
232-
222+
233223
const dependencies = [];
234224
let preprocessPromise;
235225
if (options.preprocess) {
@@ -313,7 +303,7 @@ module.exports = function svelte(options = {}) {
313303
return compiled.js;
314304
});
315305
},
316-
306+
317307
/**
318308
* If css: true then outputs a single file with all CSS bundled together
319309
*/

0 commit comments

Comments
 (0)