Skip to content

Commit b24fc30

Browse files
committed
chore: Standardize file existence checks to pathExists
Co-authored by: Patryk Kuniczak <p.kuniczak@gmail.com>
1 parent 1fe0730 commit b24fc30

17 files changed

Lines changed: 62 additions & 62 deletions

File tree

packages/auto-icons/src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { defineWxtModule } from 'wxt/modules';
33
import { resolve, relative } from 'node:path';
44
import defu from 'defu';
55
import sharp from 'sharp';
6-
import { ensureDir, exists } from 'fs-extra';
6+
import { ensureDir, pathExists } from 'fs-extra';
77

88
export default defineWxtModule<AutoIconsOptions>({
99
name: '@wxt-dev/auto-icons',
@@ -37,7 +37,7 @@ export default defineWxtModule<AutoIconsOptions>({
3737
if (!parsedOptions.enabled)
3838
return wxt.logger.warn(`\`[auto-icons]\` ${this.name} disabled`);
3939

40-
if (!(await exists(resolvedPath))) {
40+
if (!(await pathExists(resolvedPath))) {
4141
return wxt.logger.warn(
4242
`\`[auto-icons]\` Skipping icon generation, no base icon found at ${relative(process.cwd(), resolvedPath)}`,
4343
);

packages/runner/src/options.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ async function findBrowserBinary(target: string): Promise<string | undefined> {
114114
for (const target of targets) {
115115
const potentialPaths = KNOWN_BROWSER_PATHS[target]?.[platform] ?? [];
116116
for (const path of potentialPaths) {
117-
if (await exists(path)) return path;
117+
if (await pathExists(path)) return path;
118118
}
119119
}
120120
}
@@ -207,7 +207,7 @@ function deduplicateArgs(
207207
return args;
208208
}
209209

210-
async function exists(path: string): Promise<boolean> {
210+
async function pathExists(path: string): Promise<boolean> {
211211
try {
212212
await open(path, 'r');
213213
return true;

packages/wxt/e2e/tests/analysis.test.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ describe('Analysis', () => {
3030
},
3131
});
3232

33-
expect(await project.fileExists('stats.html')).toBe(true);
34-
expect(await project.fileExists('.output/chrome-mv3/stats-0.json')).toBe(
33+
expect(await project.pathExists('stats.html')).toBe(true);
34+
expect(await project.pathExists('.output/chrome-mv3/stats-0.json')).toBe(
3535
false,
3636
);
3737
});
@@ -52,9 +52,9 @@ describe('Analysis', () => {
5252
},
5353
});
5454

55-
expect(await project.fileExists('stats.html')).toBe(true);
56-
expect(await project.fileExists('stats-0.json')).toBe(true);
57-
expect(await project.fileExists('stats-1.json')).toBe(true);
55+
expect(await project.pathExists('stats.html')).toBe(true);
56+
expect(await project.pathExists('stats-0.json')).toBe(true);
57+
expect(await project.pathExists('stats-1.json')).toBe(true);
5858
});
5959

6060
it('should support customizing the stats output directory', async () => {
@@ -73,7 +73,7 @@ describe('Analysis', () => {
7373
},
7474
});
7575

76-
expect(await project.fileExists('stats/bundle.html')).toBe(true);
76+
expect(await project.pathExists('stats/bundle.html')).toBe(true);
7777
});
7878

7979
it('should place artifacts next to the custom output file', async () => {
@@ -93,9 +93,9 @@ describe('Analysis', () => {
9393
},
9494
});
9595

96-
expect(await project.fileExists('stats/bundle.html')).toBe(true);
97-
expect(await project.fileExists('stats/bundle-0.json')).toBe(true);
98-
expect(await project.fileExists('stats/bundle-1.json')).toBe(true);
96+
expect(await project.pathExists('stats/bundle.html')).toBe(true);
97+
expect(await project.pathExists('stats/bundle-0.json')).toBe(true);
98+
expect(await project.pathExists('stats/bundle-1.json')).toBe(true);
9999
});
100100

101101
it('should open the stats in the browser when requested', async () => {

packages/wxt/e2e/tests/auto-imports.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ describe('Auto Imports', () => {
142142

143143
await project.prepare();
144144

145-
expect(await project.fileExists('.wxt/types/imports.d.ts')).toBe(false);
145+
expect(await project.pathExists('.wxt/types/imports.d.ts')).toBe(false);
146146
});
147147

148148
it('should only include imports-module.d.ts in the the project', async () => {
@@ -280,10 +280,10 @@ describe('Auto Imports', () => {
280280
},
281281
});
282282

283-
expect(await project.fileExists('.wxt/eslint-auto-imports.mjs')).toBe(
283+
expect(await project.pathExists('.wxt/eslint-auto-imports.mjs')).toBe(
284284
false,
285285
);
286-
expect(await project.fileExists('.wxt/eslintrc-auto-import.json')).toBe(
286+
expect(await project.pathExists('.wxt/eslintrc-auto-import.json')).toBe(
287287
false,
288288
);
289289
});

packages/wxt/e2e/tests/modules.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ describe('Module Helpers', () => {
7777

7878
await project.build(config);
7979

80-
expect(await project.fileExists('.output/chrome-mv3/injected.js')).toBe(
80+
expect(await project.pathExists('.output/chrome-mv3/injected.js')).toBe(
8181
true,
8282
);
8383
});
@@ -118,10 +118,10 @@ describe('Module Helpers', () => {
118118
fileName: 'module.txt',
119119
});
120120
await expect(
121-
project.fileExists('.output/chrome-mv3/module.txt'),
121+
project.pathExists('.output/chrome-mv3/module.txt'),
122122
).resolves.toBe(true);
123123
await expect(
124-
project.fileExists('.output/chrome-mv3/example/generated.txt'),
124+
project.pathExists('.output/chrome-mv3/example/generated.txt'),
125125
).resolves.toBe(true);
126126
});
127127

packages/wxt/e2e/tests/output-structure.test.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ describe('Output Directory Structure', () => {
126126

127127
await project.build({ browser: 'firefox' });
128128

129-
expect(await project.fileExists('.output/firefox-mv2/background.js')).toBe(
129+
expect(await project.pathExists('.output/firefox-mv2/background.js')).toBe(
130130
false,
131131
);
132132
});
@@ -146,7 +146,7 @@ describe('Output Directory Structure', () => {
146146

147147
await project.build({ browser: 'chrome' });
148148

149-
expect(await project.fileExists('.output/firefox-mv2/background.js')).toBe(
149+
expect(await project.pathExists('.output/firefox-mv2/background.js')).toBe(
150150
false,
151151
);
152152
});
@@ -174,7 +174,7 @@ describe('Output Directory Structure', () => {
174174

175175
await project.build();
176176

177-
expect(await project.fileExists('stats.html')).toBe(true);
177+
expect(await project.pathExists('stats.html')).toBe(true);
178178
});
179179

180180
it('should support JavaScript entrypoints', async () => {
@@ -210,14 +210,14 @@ describe('Output Directory Structure', () => {
210210
----------------------------------------
211211
{"manifest_version":3,"name":"E2E Extension","description":"Example description","version":"0.0.0","background":{"service_worker":"background.js"},"content_scripts":[{"matches":["*://*.google.com/*"],"js":["content-scripts/content.js"]},{"matches":["*://*.duckduckgo.com/*"],"js":["content-scripts/named.js"]}]}"
212212
`);
213-
expect(await project.fileExists('.output/chrome-mv3/background.js'));
213+
expect(await project.pathExists('.output/chrome-mv3/background.js'));
214214
expect(
215-
await project.fileExists('.output/chrome-mv3/content-scripts/content.js'),
215+
await project.pathExists('.output/chrome-mv3/content-scripts/content.js'),
216216
);
217217
expect(
218-
await project.fileExists('.output/chrome-mv3/content-scripts/named.js'),
218+
await project.pathExists('.output/chrome-mv3/content-scripts/named.js'),
219219
);
220-
expect(await project.fileExists('.output/chrome-mv3/unlisted.js'));
220+
expect(await project.pathExists('.output/chrome-mv3/unlisted.js'));
221221
});
222222

223223
it('should support CSS entrypoints', async () => {
@@ -300,7 +300,7 @@ describe('Output Directory Structure', () => {
300300

301301
await project.build();
302302

303-
expect(await project.fileExists('dist/chrome-mv3/manifest.json')).toBe(
303+
expect(await project.pathExists('dist/chrome-mv3/manifest.json')).toBe(
304304
true,
305305
);
306306
});

packages/wxt/e2e/tests/react.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('React', () => {
1616
project.addFile(
1717
'entrypoints/demo.content.tsx',
1818
`import ReactDOM from 'react-dom/client';
19-
19+
2020
export default defineContentScript({
2121
matches: "<all_urls>",
2222
main() {
@@ -31,7 +31,7 @@ describe('React', () => {
3131
await project.build();
3232

3333
expect(
34-
await project.fileExists('.output/chrome-mv3/content-scripts/demo.js'),
34+
await project.pathExists('.output/chrome-mv3/content-scripts/demo.js'),
3535
).toBe(true);
3636
expect(await project.serializeFile('.output/chrome-mv3/manifest.json'))
3737
.toMatchInlineSnapshot(`

packages/wxt/e2e/tests/remote-code.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe('Remote Code', () => {
2020
);
2121
expect(output).not.toContain(url);
2222
expect(
23-
await project.fileExists(`.wxt/cache/${encodeURIComponent(url)}`),
23+
await project.pathExists(`.wxt/cache/${encodeURIComponent(url)}`),
2424
).toBe(true);
2525
});
2626
});

packages/wxt/e2e/tests/user-config.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('User Config', () => {
108108
await project.build({ configFile: 'test.config.ts' });
109109

110110
expect(
111-
await project.fileExists('.custom-output/chrome-mv3/background.js'),
111+
await project.pathExists('.custom-output/chrome-mv3/background.js'),
112112
).toBe(true);
113113
});
114114

@@ -129,13 +129,13 @@ describe('User Config', () => {
129129
await project.build();
130130

131131
expect(
132-
await project.fileExists('.output/test-chrome-mv3-production-build'),
132+
await project.pathExists('.output/test-chrome-mv3-production-build'),
133133
).toBe(true);
134134

135135
await project.build({ mode: 'development' });
136136

137137
expect(
138-
await project.fileExists('.output/test-chrome-mv3-development-dev-build'),
138+
await project.pathExists('.output/test-chrome-mv3-development-dev-build'),
139139
).toBe(true);
140140
});
141141

packages/wxt/e2e/tests/zip.test.ts

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe('Zipping', () => {
2626
browser: 'firefox',
2727
zip: { downloadPackages: ['flatten'] },
2828
});
29-
expect(await project.fileExists('.output/')).toBe(true);
29+
expect(await project.pathExists('.output/')).toBe(true);
3030

3131
await extract(sourcesZip, { dir: unzipDir });
3232
// Update package json wxt path
@@ -51,7 +51,7 @@ describe('Zipping', () => {
5151
}),
5252
).resolves.not.toHaveProperty('exitCode');
5353

54-
await expect(project.fileExists(unzipDir, '.output')).resolves.toBe(true);
54+
await expect(project.pathExists(unzipDir, '.output')).resolves.toBe(true);
5555
expect(
5656
await project.serializeFile(
5757
project.resolvePath(unzipDir, 'package.json'),
@@ -95,8 +95,8 @@ describe('Zipping', () => {
9595
},
9696
});
9797

98-
expect(await project.fileExists(artifactZip)).toBe(true);
99-
expect(await project.fileExists(sourcesZip)).toBe(true);
98+
expect(await project.pathExists(artifactZip)).toBe(true);
99+
expect(await project.pathExists(sourcesZip)).toBe(true);
100100
});
101101

102102
it('should not zip hidden files into sources by default', async () => {
@@ -117,8 +117,8 @@ describe('Zipping', () => {
117117
browser: 'firefox',
118118
});
119119
await extract(sourcesZip, { dir: unzipDir });
120-
expect(await project.fileExists(unzipDir, '.env')).toBe(false);
121-
expect(await project.fileExists(unzipDir, '.hidden-dir/file')).toBe(false);
120+
expect(await project.pathExists(unzipDir, '.env')).toBe(false);
121+
expect(await project.pathExists(unzipDir, '.hidden-dir/file')).toBe(false);
122122
});
123123

124124
it('should not zip files inside hidden directories if only the directory is specified', async () => {
@@ -142,8 +142,8 @@ describe('Zipping', () => {
142142
},
143143
});
144144
await extract(sourcesZip, { dir: unzipDir });
145-
expect(await project.fileExists(unzipDir, '.hidden-dir/file')).toBe(false);
146-
expect(await project.fileExists(unzipDir, '.hidden-dir/nested/file')).toBe(
145+
expect(await project.pathExists(unzipDir, '.hidden-dir/file')).toBe(false);
146+
expect(await project.pathExists(unzipDir, '.hidden-dir/nested/file')).toBe(
147147
false,
148148
);
149149
});
@@ -171,12 +171,12 @@ describe('Zipping', () => {
171171
},
172172
});
173173
await extract(sourcesZip, { dir: unzipDir });
174-
expect(await project.fileExists(unzipDir, '.env')).toBe(true);
175-
expect(await project.fileExists(unzipDir, '.hidden-dir/file')).toBe(true);
176-
expect(await project.fileExists(unzipDir, '.hidden-dir/nested/file1')).toBe(
174+
expect(await project.pathExists(unzipDir, '.env')).toBe(true);
175+
expect(await project.pathExists(unzipDir, '.hidden-dir/file')).toBe(true);
176+
expect(await project.pathExists(unzipDir, '.hidden-dir/nested/file1')).toBe(
177177
true,
178178
);
179-
expect(await project.fileExists(unzipDir, '.hidden-dir/nested/file2')).toBe(
179+
expect(await project.pathExists(unzipDir, '.hidden-dir/nested/file2')).toBe(
180180
true,
181181
);
182182
});
@@ -210,10 +210,10 @@ describe('Zipping', () => {
210210
});
211211
await extract(sourcesZip, { dir: unzipDir });
212212
expect(
213-
await project.fileExists(unzipDir, 'entrypoints/not-firefox.content.ts'),
213+
await project.pathExists(unzipDir, 'entrypoints/not-firefox.content.ts'),
214214
).toBe(false);
215215
expect(
216-
await project.fileExists(unzipDir, 'entrypoints/all.content.ts'),
216+
await project.pathExists(unzipDir, 'entrypoints/all.content.ts'),
217217
).toBe(true);
218218
});
219219

@@ -234,7 +234,7 @@ describe('Zipping', () => {
234234
browser,
235235
});
236236

237-
expect(await project.fileExists(sourcesZip)).toBe(true);
237+
expect(await project.pathExists(sourcesZip)).toBe(true);
238238
},
239239
);
240240

@@ -258,7 +258,7 @@ describe('Zipping', () => {
258258
},
259259
});
260260

261-
expect(await project.fileExists(sourcesZip)).toBe(true);
261+
expect(await project.pathExists(sourcesZip)).toBe(true);
262262
},
263263
);
264264

@@ -282,7 +282,7 @@ describe('Zipping', () => {
282282
},
283283
});
284284

285-
expect(await project.fileExists(sourcesZip)).toBe(false);
285+
expect(await project.pathExists(sourcesZip)).toBe(false);
286286
},
287287
);
288288

@@ -305,6 +305,6 @@ describe('Zipping', () => {
305305
});
306306

307307
await extract(sourcesZip, { dir: unzipDir });
308-
expect(await project.fileExists(unzipDir, 'manifest.json')).toBe(true);
308+
expect(await project.pathExists(unzipDir, 'manifest.json')).toBe(true);
309309
});
310310
});

0 commit comments

Comments
 (0)