-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Expand file tree
/
Copy pathlibnodepath.js
More file actions
36 lines (34 loc) · 1.18 KB
/
libnodepath.js
File metadata and controls
36 lines (34 loc) · 1.18 KB
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
/**
* @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.
addToLibrary({
$nodePath: "{{{ makeNodeImport('node:path', false) }}}",
$PATH__deps: ['$nodePath'],
$PATH: `{
isAbs: nodePath.isAbsolute,
normalize: nodePath.normalize,
dirname: nodePath.dirname,
basename: nodePath.basename,
join: nodePath.join,
join2: nodePath.join,
}`,
// The FS-using parts are split out into a separate object, so simple path
// usage does not require the FS.
$PATH_FS__deps: ['$FS', '$nodePath'],
$PATH_FS__docs: '/** @type{{resolve: function(...*)}} */',
$PATH_FS: {
resolve: (...paths) => {
paths.unshift(FS.cwd());
return nodePath.posix.resolve(...paths);
},
relative: (from, to) => nodePath.posix.relative(from || FS.cwd(), to || FS.cwd()),
}
});