-
Notifications
You must be signed in to change notification settings - Fork 3.3k
/
library_nodepath.js
37 lines (35 loc) · 1.33 KB
/
library_nodepath.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/**
* @license
* Copyright 2022 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/
// This implementation ensures that Windows-style paths are being
// used when running on a Windows operating system - see:
// https://nodejs.org/api/path.html#path_windows_vs_posix
// It's only used/needed when linking with `-sNODERAWFS`, as that
// will replace all normal filesystem access with direct Node.js
// operations. Hence, using `nodePath` should be safe here.
mergeInto(LibraryManager.library, {
$PATH: {
isAbs: (path) => nodePath['isAbsolute'](path),
normalize: (path) => nodePath['normalize'](path),
dirname: (path) => nodePath['dirname'](path),
basename: (path) => nodePath['basename'](path),
join: function () {
return nodePath['join'].apply(null, arguments);
},
join2: (l, r) => nodePath['join'](l, r),
},
// The FS-using parts are split out into a separate object, so simple path
// usage does not require the FS.
$PATH_FS__deps: ['$FS'],
$PATH_FS__docs: '/** @type{{resolve: function(...*)}} */',
$PATH_FS: {
resolve: function () {
var paths = Array.prototype.slice.call(arguments, 0);
paths.unshift(FS.cwd());
return nodePath['posix']['resolve'].apply(null, paths);
},
relative: (from, to) => nodePath['posix']['relative'](from || FS.cwd(), to || FS.cwd()),
}
});