|
| 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 | +mergeInto(LibraryManager.library, { |
| 15 | + $PATH: { |
| 16 | + isAbs: (path) => nodePath['isAbsolute'](path), |
| 17 | + normalize: (path) => nodePath['normalize'](path), |
| 18 | + dirname: (path) => nodePath['dirname'](path), |
| 19 | + basename: (path) => nodePath['basename'](path), |
| 20 | + join: function () { |
| 21 | + return nodePath['join'].apply(null, arguments); |
| 22 | + }, |
| 23 | + join2: (l, r) => nodePath['join'](l, r), |
| 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'], |
| 28 | + $PATH_FS__docs: '/** @type{{resolve: function(...*)}} */', |
| 29 | + $PATH_FS: { |
| 30 | + resolve: function () { |
| 31 | + var paths = Array.prototype.slice.call(arguments, 0); |
| 32 | + paths.unshift(FS.cwd()); |
| 33 | + return nodePath['posix']['resolve'].apply(null, paths); |
| 34 | + }, |
| 35 | + relative: (from, to) => nodePath['posix']['relative'](from || FS.cwd(), to || FS.cwd()), |
| 36 | + } |
| 37 | +}); |
0 commit comments