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

fix(ext/node): add stubbed process.report #21373

Merged
merged 10 commits into from
Dec 1, 2023

Conversation

Danielduel
Copy link
Contributor

@Danielduel Danielduel commented Nov 28, 2023

Targets #21355, #21304

Issues with vite are caused by the missing node's process report object.
I've stubbed most of it for starter and replaced trivial spots with stubs.
I am not sure how to run compiled binary with built-in node polyfills, but things like --no-remote or declaring those deps in the import map and leading them to the deno's source doesn't work.

cargo build -vv produces build without a problem
cargo test hangs on build step and I need help with that (whole system hang, no output in journalctl)

tools/format.js and tools/lint.js tell me that test_util/std/path/mod.ts can't be found.

@CLAassistant
Copy link

CLAassistant commented Nov 28, 2023

CLA assistant check
All committers have signed the CLA.

@bartlomieju
Copy link
Member

tools/format.js and tools/lint.js tell me that test_util/std/path/mod.ts can't be found.

Run git submodule update --init --recursive in the root of the repository and make sure after that git status is clean.

@Danielduel
Copy link
Contributor Author

Pushed format fix, cargo test after rustup upgrade and cargo clean started to work and it looks like it fails in the same way like the main does.

Comment on lines 43 to 44
osRelease: todoUnimplemented,
osVersion: todoUnimplemented,
Copy link
Member

Choose a reason for hiding this comment

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

I think we should return empty values here instead of throwing

Comment on lines 50 to 59
javascriptStack: todoUnimplemented,
javascriptHeap: todoUnimplemented,
nativeStack: todoUnimplemented,
resourceUsage: todoUnimplemented,
uvthreadResourceUsage: todoUnimplemented,
libuv: todoUnimplemented,
workers: [],
environmentVariables: todoUnimplemented,
userLimits: todoUnimplemented,
sharedObjects: todoUnimplemented,
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

ext/node/lib.rs Outdated
@@ -350,6 +350,7 @@ deno_core::extension!(deno_node,
"_next_tick.ts",
"_process/exiting.ts",
"_process/process.ts",
"_process/report.ts",
Copy link
Member

Choose a reason for hiding this comment

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

I think the path should be internal/process/report.ts to align the file structure as close to Node.js lib directory as possible. https://github.com/nodejs/node/tree/main/lib/internal/process

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't aware of it, will do!

@Danielduel
Copy link
Contributor Author

I would like to ask for another round of reviews @bartlomieju @kt3k

@bartlomieju
Copy link
Member

@Danielduel could you try your local Deno build with this change and check if it solves the problem from the reported issue?

@Danielduel
Copy link
Contributor Author

@Danielduel could you try your local Deno build with this change and check if it solves the problem from the reported issue?

Hi @bartlomieju,
I've mentioned it before that I am not sure why it still resolves the wrong module, but now after tinkering with this stuff - I can put into words...

I've done alias deno=...pathtobuiltdeno

import { report as importReport, arch as importArch } from "node:process";
import { createRequire } from "node:module";

console.log("Imported:")
console.log(importReport, importArch);

const require = createRequire(import.meta.url);
const { report, arch } = require("node:process");
console.log("Required:");
console.log(report, arch)

Imported deps are fine - report is defined, arch is an empty string.
Report from required is undefined, but arch is "x64" for me.

@Danielduel
Copy link
Contributor Author

I have a feeling that ext/node/polyfills/01_require.js Module._load can give me some hints why it is.

@Danielduel
Copy link
Contributor Author

Okay, I see, the deconstruction on require works as a decostruction on default export, not in the same way as import syntax. Fixed.

@Danielduel
Copy link
Contributor Author

I can confirm that this change will fix vite start.
image

Copy link
Member

@bartlomieju bartlomieju left a comment

Choose a reason for hiding this comment

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

@Danielduel that's great to see!

Could you add some basic tests to cli/test/unit_node/process_test.ts that checks that this function is present and asserting some of the values? Especially the ones that are currently marked as undefined.

@Danielduel Danielduel force-pushed the stub_node_process_report branch from 31bf24d to 77b728d Compare November 30, 2023 07:46

Verified

This commit was signed with the committer’s verified signature. The key has expired.
zifeo Teo Stocco

Verified

This commit was signed with the committer’s verified signature.
crowlKats Leo Kettmeir

Verified

This commit was signed with the committer’s verified signature. The key has expired.
bartlomieju Bartek Iwańczuk
@Danielduel Danielduel force-pushed the stub_node_process_report branch from 4521174 to 230604f Compare November 30, 2023 07:49
@Danielduel
Copy link
Contributor Author

Removed reexport since node doesn't seem to provide anything else than a getter on process.report.
I will have to fix few typings in DefinitelyTyped regarding getReport.
I would like to get feedback if this is how I should write tests for getReport.
I haven't ran anything yet, pushing it as a wip to get feedback.

kt3k
kt3k previously approved these changes Nov 30, 2023
Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

LGTM!

@kt3k kt3k dismissed their stale review November 30, 2023 14:14

retract

@kt3k
Copy link
Member

kt3k commented Nov 30, 2023

Could you fix the lint errors like the below?:

 5 | function writeReport(filename: string, err: Error) {
   :                                             ^^|^^
   :                                               `-- Instead use the equivalent from the `primordials` object

primordials (safer versions of builtin classes/functions) are available like:

const primordials = globalThis.__bootstrap.primordials;
const { Error } = primordials;

@Danielduel
Copy link
Contributor Author

Danielduel commented Nov 30, 2023

I've updated everything that was calling for primodial... with a primodial.
I am not sure if those typings of typeof Error are best way to use the Error primodial.
I've figured out how to selectively run my tests with latest binary, I had few mistakes - fixed.
Built deno and retested vite - works.
Linted and formatted the codebase.

Copy link
Member

@kt3k kt3k left a comment

Choose a reason for hiding this comment

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

Thanks for updating!

LGTM. Nice work!

@kt3k kt3k merged commit 687ae87 into denoland:main Dec 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants