Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/library_async.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ mergeInto(LibraryManager.library, {
return Asyncify.handleSleep((wakeUp) => {
var _url = UTF8ToString(url);
var _file = UTF8ToString(file);
_file = PATH_FS.resolve(FS.cwd(), _file);
_file = PATH_FS.resolve(_file);
var destinationDirectory = PATH.dirname(_file);
FS.createPreloadedFile(
destinationDirectory,
Expand Down
6 changes: 3 additions & 3 deletions src/library_fs.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ FS.staticInit();` +
// paths
//
lookupPath: (path, opts = {}) => {
path = PATH_FS.resolve(FS.cwd(), path);
path = PATH_FS.resolve(path);

if (!path) return { path: '', node: null };

Expand All @@ -133,8 +133,8 @@ FS.staticInit();` +
throw new FS.ErrnoError({{{ cDefine('ELOOP') }}});
}

// split the path
var parts = PATH.normalizeArray(path.split('/').filter((p) => !!p), false);
// split the absolute path
var parts = path.split('/').filter((p) => !!p);

// start at the root
var current = FS.root;
Expand Down
30 changes: 30 additions & 0 deletions src/library_nodepath.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/**
* @license
* Copyright 2022 The Emscripten Authors
* SPDX-License-Identifier: MIT
*/

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe add a comment in this file explaining the motivation for it? (which IIUC from the discussion is windows?) lgtm with that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment with 37b6dd0. I also removed the "This has mostly been tested on Linux so far"-phrase from NODERAWFS settings description with 9115052, since using Node.js operations should be cross-platform (+ AFAIK, CI also test the NODERAWFS setting on OSes other than Linux).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

mergeInto(LibraryManager.library, {
$PATH: {
isAbs: (path) => nodePath['isAbsolute'](path),
normalize: (path) => nodePath['normalize'](path),
dirname: (path) => nodePath['dirname'](path),
basename: (path) => nodePath['basename'](path),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious why closure wouldn't know how to deal with nodePath without the extra quoting here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, it's currently used this way throughout the codebase. Perhaps nodePath should be placed within src/closure-externs/closure-externs.js?

join: function () {
return nodePath['join'].apply(null, arguments);
},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can this just be join: nodePath['join']? (same with above)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried that initially, but it caused the acorn-optimizer to fail.

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()),
}
});
2 changes: 2 additions & 0 deletions src/modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ global.LibraryManager = {
libraries.push('library_nodefs.js');
}
libraries.push('library_noderawfs.js');
// NODERAWFS overwrites library_path.js
libraries.push('library_nodepath.js');
}
} else if (WASMFS) {
libraries.push('library_wasmfs.js');
Expand Down
11 changes: 11 additions & 0 deletions test/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -8418,6 +8418,17 @@ def test_noderawfs_disables_embedding(self):
err = self.expect_fail(base + ['--embed-file', 'somefile'])
self.assertContained(expected, err)

def test_noderawfs_access_abspath(self):
create_file('foo', 'bar')
create_file('access.c', r'''
#include <unistd.h>
int main(int argc, char** argv) {
return access(argv[1], F_OK);
}
''')
self.run_process([EMCC, 'access.c', '-sNODERAWFS'])
self.run_js('a.out.js', args=[os.path.abspath('foo')])

@disabled('https://github.com/nodejs/node/issues/18265')
def test_node_code_caching(self):
self.run_process([EMCC, test_file('hello_world.c'),
Expand Down