|
4 | 4 | * SPDX-License-Identifier: MIT |
5 | 5 | */ |
6 | 6 |
|
7 | | -addToLibrary({ |
| 7 | +var LibraryFS = { |
8 | 8 | $FS__deps: ['$randomFill', '$PATH', '$PATH_FS', '$TTY', '$MEMFS', |
9 | 9 | '$FS_createPreloadedFile', |
10 | 10 | '$FS_modeStringToFlags', |
@@ -38,9 +38,7 @@ addToLibrary({ |
38 | 38 | addAtExit('FS.quit();'); |
39 | 39 | return ` |
40 | 40 | FS.createPreloadedFile = FS_createPreloadedFile; |
41 | | -FS.staticInit(); |
42 | | -// Set module methods based on EXPORTED_RUNTIME_METHODS |
43 | | -{{{ EXPORTED_RUNTIME_METHODS.filter((func) => func.startsWith('FS_')).map((func) => "Module['" + func + "'] = FS." + func.slice(3) + ";\n").reduce((str, func) => str + func, '') }}}`; |
| 41 | +FS.staticInit();`; |
44 | 42 | }, |
45 | 43 | $FS: { |
46 | 44 | root: null, |
@@ -1917,22 +1915,23 @@ FS.staticInit(); |
1917 | 1915 | #endif |
1918 | 1916 | }, |
1919 | 1917 |
|
1920 | | - $FS_createDataFile__deps: ['$FS'], |
1921 | | - $FS_createDataFile: (parent, name, fileData, canRead, canWrite, canOwn) => { |
1922 | | - FS.createDataFile(parent, name, fileData, canRead, canWrite, canOwn); |
1923 | | - }, |
1924 | | - |
1925 | | - $FS_unlink__deps: ['$FS'], |
1926 | | - $FS_unlink: (path) => FS.unlink(path), |
1927 | | - |
1928 | 1918 | $FS_mkdirTree__docs: ` |
1929 | 1919 | /** |
1930 | 1920 | * @param {number=} mode Optionally, the mode to create in. Uses mkdir's |
1931 | 1921 | * default if not set. |
1932 | 1922 | */`, |
1933 | | - $FS_mkdirTree__deps: ['$FS'], |
1934 | | - $FS_mkdirTree: (path, mode) => FS.mkdirTree(path, mode), |
1935 | | - |
1936 | | - $FS_createLazyFile__deps: ['$FS'], |
1937 | | - $FS_createLazyFile: 'FS.createLazyFile', |
1938 | | -}); |
| 1923 | + $FS_mkdirTree__deps: ['$FS'], |
| 1924 | + $FS_mkdirTree: (path, mode) => FS.mkdirTree(path, mode), |
| 1925 | +}; |
| 1926 | + |
| 1927 | +// Add library aliases for all the FS.<symbol> as FS_<symbol>. |
| 1928 | +for (let key in LibraryFS.$FS) { |
| 1929 | + const alias = `$FS_${key}`; |
| 1930 | + // Skip defining the alias if it already exists or if it's not an API function. |
| 1931 | + if (LibraryFS[alias] || key[0] !== key[0].toLowerCase()) { |
| 1932 | + continue; |
| 1933 | + } |
| 1934 | + LibraryFS[alias] = `(...args) => FS.${key}(...args)`; |
| 1935 | + LibraryFS[`${alias}__deps`] = ['$FS']; |
| 1936 | +} |
| 1937 | +addToLibrary(LibraryFS); |
0 commit comments