Skip to content

Commit 61778f2

Browse files
authored
Simplify file finding/reading files in JS compiler. NFC (emscripten-core#23349)
- Use import.meta.dirname - Remove duplicate copy of `find` function. - Remove `export` of find function
1 parent 0afaf41 commit 61778f2

File tree

2 files changed

+5
-25
lines changed

2 files changed

+5
-25
lines changed

src/compiler.mjs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,11 @@
77

88
// LLVM => JavaScript compiler, main entry point
99

10-
import * as fs from 'node:fs';
11-
import * as path from 'node:path';
12-
import * as url from 'node:url';
13-
1410
import {Benchmarker, applySettings, assert, loadSettingsFile, printErr, read} from './utility.mjs';
1511

16-
function find(filename) {
17-
assert(filename);
18-
const dirname = url.fileURLToPath(new URL('.', import.meta.url));
19-
const prefixes = [dirname, process.cwd()];
20-
for (let i = 0; i < prefixes.length; ++i) {
21-
const combined = path.join(prefixes[i], filename);
22-
if (fs.existsSync(combined)) {
23-
return combined;
24-
}
25-
}
26-
return filename;
27-
}
28-
2912
// Load default settings
30-
loadSettingsFile(find('settings.js'));
31-
loadSettingsFile(find('settings_internal.js'));
13+
loadSettingsFile('settings.js');
14+
loadSettingsFile('settings_internal.js');
3215

3316
const argv = process.argv.slice(2);
3417
const symbolsOnlyArg = argv.indexOf('--symbols-only');

src/utility.mjs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
// General JS utilities - things that might be useful in any JS project.
88
// Nothing specific to Emscripten appears here.
99

10-
import * as url from 'node:url';
1110
import * as path from 'node:path';
1211
import * as fs from 'node:fs';
1312
import * as vm from 'node:vm';
@@ -240,11 +239,9 @@ export function read(filename) {
240239
return fs.readFileSync(absolute).toString();
241240
}
242241

243-
export function find(filename) {
244-
const dirname = url.fileURLToPath(new URL('.', import.meta.url));
245-
const prefixes = [process.cwd(), path.join(dirname, '..', 'src')];
246-
for (let i = 0; i < prefixes.length; ++i) {
247-
const combined = path.join(prefixes[i], filename);
242+
function find(filename) {
243+
for (const prefix of [process.cwd(), import.meta.dirname]) {
244+
const combined = path.join(prefix, filename);
248245
if (fs.existsSync(combined)) {
249246
return combined;
250247
}

0 commit comments

Comments
 (0)