Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] main from nodejs:main #54

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
38 changes: 38 additions & 0 deletions doc/api/permissions.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,43 @@ does not exist, the wildcard will not be added, and access will be limited to
yet, make sure to explicitly include the wildcard:
`/my-path/folder-do-not-exist/*`.

#### Using the Permission Model with `npx`

If you're using [`npx`][] to execute a Node.js script, you can enable the
Permission Model by passing the `--node-options` flag. For example:

```bash
npx --node-options="--permission" package-name
```

This sets the `NODE_OPTIONS` environment variable for all Node.js processes
spawned by [`npx`][], without affecting the `npx` process itself.

**FileSystemRead Error with `npx`**

The above command will likely throw a `FileSystemRead` invalid access error
because Node.js requires file system read access to locate and execute the
package. To avoid this:

1. **Using a Globally Installed Package**
Grant read access to the global `node_modules` directory by running:

```bash
npx --node-options="--permission --allow-fs-read=$(npm prefix -g)" package-name
```

2. **Using the `npx` Cache**
If you are installing the package temporarily or relying on the `npx` cache,
grant read access to the npm cache directory:

```bash
npx --node-options="--permission --allow-fs-read=$(npm config get cache)" package-name
```

Any arguments you would normally pass to `node` (e.g., `--allow-*` flags) can
also be passed through the `--node-options` flag. This flexibility makes it
easy to configure permissions as needed when using `npx`.

#### Permission Model constraints

There are constraints you need to know before using this system:
Expand Down Expand Up @@ -166,4 +203,5 @@ There are constraints you need to know before using this system:
[`--allow-wasi`]: cli.md#--allow-wasi
[`--allow-worker`]: cli.md#--allow-worker
[`--permission`]: cli.md#--permission
[`npx`]: https://docs.npmjs.com/cli/commands/npx
[`permission.has()`]: process.md#processpermissionhasscope-reference
5 changes: 5 additions & 0 deletions doc/api/util.md
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,9 @@
<!-- YAML
added: v22.9.0
changes:
- version: REPLACEME
pr-url: https://github.com/nodejs/node/pull/56551

Check warning on line 375 in doc/api/util.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
description: Property `CallSite.scriptId` is exposed.
- version:
- v23.3.0
- v22.12.0
Expand All @@ -387,6 +390,7 @@
* `functionName` {string} Returns the name of the function associated with this call site.
* `scriptName` {string} Returns the name of the resource that contains the script for the
function for this call site.
* `scriptId` {string} Returns the unique id of the script, as in Chrome DevTools protocol [`Runtime.ScriptId`][].
* `lineNumber` {number} Returns the number, 1-based, of the line for the associate function call.
* `column` {number} Returns the 1-based column offset on the line for the associated function call.

Expand Down Expand Up @@ -3190,6 +3194,7 @@
[`Object.freeze()`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze
[`Promise`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise
[`Proxy`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
[`Runtime.ScriptId`]: https://chromedevtools.github.io/devtools-protocol/1-3/Runtime/#type-ScriptId
[`Set`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set
[`SharedArrayBuffer`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer
[`TypedArray`]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
Expand Down
1 change: 1 addition & 0 deletions src/env_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@
V(salt_length_string, "saltLength") \
V(scheme_string, "scheme") \
V(scopeid_string, "scopeid") \
V(script_id_string, "scriptId") \
V(script_name_string, "scriptName") \
V(serial_number_string, "serialNumber") \
V(serial_string, "serial") \
Expand Down
4 changes: 4 additions & 0 deletions src/node_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -275,14 +275,18 @@ static void GetCallSites(const FunctionCallbackInfo<Value>& args) {
script_name = v8::String::Empty(isolate);
}

std::string script_id = std::to_string(stack_frame->GetScriptId());

Local<Name> names[] = {
env->function_name_string(),
env->script_id_string(),
env->script_name_string(),
env->line_number_string(),
env->column_string(),
};
Local<Value> values[] = {
function_name,
OneByteString(isolate, script_id),
script_name,
Integer::NewFromUnsigned(isolate, stack_frame->GetLineNumber()),
Integer::NewFromUnsigned(isolate, stack_frame->GetColumn()),
Expand Down
7 changes: 7 additions & 0 deletions test/parallel/test-util-getcallsites.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@ const assert = require('node:assert');
);
}

// ScriptId is a string.
{
const callSites = getCallSites(1);
assert.strictEqual(callSites.length, 1);
assert.strictEqual(typeof callSites[0].scriptId, 'string');
}

// Guarantee [eval] will appear on stacktraces when using -e
{
const { status, stderr, stdout } = spawnSync(
Expand Down
Loading