Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/src/lib/libnodepath.js
4150 views
1
/**
2
* @license
3
* Copyright 2022 The Emscripten Authors
4
* SPDX-License-Identifier: MIT
5
*/
6
7
// This implementation ensures that Windows-style paths are being
8
// used when running on a Windows operating system - see:
9
// https://nodejs.org/api/path.html#path_windows_vs_posix
10
// It's only used/needed when linking with `-sNODERAWFS`, as that
11
// will replace all normal filesystem access with direct Node.js
12
// operations. Hence, using `nodePath` should be safe here.
13
14
addToLibrary({
15
$nodePath: "require('path')",
16
$PATH__deps: ['$nodePath'],
17
$PATH: `{
18
isAbs: nodePath.isAbsolute,
19
normalize: nodePath.normalize,
20
dirname: nodePath.dirname,
21
basename: nodePath.basename,
22
join: nodePath.join,
23
join2: nodePath.join,
24
}`,
25
// The FS-using parts are split out into a separate object, so simple path
26
// usage does not require the FS.
27
$PATH_FS__deps: ['$FS', '$nodePath'],
28
$PATH_FS__docs: '/** @type{{resolve: function(...*)}} */',
29
$PATH_FS: {
30
resolve: (...paths) => {
31
paths.unshift(FS.cwd());
32
return nodePath.posix.resolve(...paths);
33
},
34
relative: (from, to) => nodePath.posix.relative(from || FS.cwd(), to || FS.cwd()),
35
}
36
});
37
38