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

Inject deno.arch/deno.platform from Node's process.arch/process.platform through rollup #773

Merged
merged 3 commits into from
Sep 20, 2018

Conversation

kevinkassimo
Copy link
Contributor

@kevinkassimo kevinkassimo commented Sep 19, 2018

Related to #771 .
Now deno.arch and deno.platform becomes exactly the same as Node's process.arch and process.platform. Injected compile-time in rollup.config.js.

(I am not familiar with rollup but a brief examination of its documentation seems justifying this solution, though might not be the best . Manually tested and working locally. Hard to create test for it though...)

@kitsonk

Copy link
Contributor

@kitsonk kitsonk left a comment

Choose a reason for hiding this comment

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

Cool! very much the approach I would have taken! Couple comments.

rollup.config.js Outdated
code: `export const arch = "${process.arch}";
export const platform = "${process.platform}";
`,
map: { mappings: "" }
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it is fine for now, but we might want a todo to actually have a valid map in here, as it might cause confusing stack traces. It may be worth testing it to just see how bad it is at the moment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

So I just ripped off the sourceMap generating code from rollup-plugin-inject. Hopefully it could work

js/platform.ts Outdated
@@ -0,0 +1,3 @@
// Dummy. Injected in rollup.config.js
export const arch = "";
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe something other than empty string? Like "unknown"?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, just thinking out loud, is that when these types get extracted and bundled up, because this is a const, TypeScript I suspect will create a literal type of "" for these, which isn't the best. What would be better would be to have a literal union type in here so that when it gets bundled into the types, end users have a valid type they can use, like:

export const arch: "x32'" | "x64" | "unknown" = "unknown";
export const platform: "darwin" | "linux" | "win32" | "unknown" = "unknown";

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I did notice this behavior when trying to add basic tests. I can definitely add the union type, just need to update the type if node will be supported on other new platforms (fuschia?)

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

Great - looks good.
Is the magic string necessary ? It’s just for source maps? Does third party need to be updated ?

@kevinkassimo
Copy link
Contributor Author

@ry just for source map. It comes as dependency already for some other rollup plugins in node_modules, so nothing need to be changed for third_party

Copy link
Member

@ry ry left a comment

Choose a reason for hiding this comment

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

Cool - LGTM

@ry ry merged commit fab4bdf into denoland:master Sep 20, 2018
kt3k pushed a commit to kt3k/deno that referenced this pull request Sep 20, 2018
ry added a commit to ry/deno that referenced this pull request Sep 22, 2018
- Add atob() btoa() denoland#776
- Add deno.arch deno.platform denoland#773
- Add deno.symlink() and deno.symlinkSync() denoland#742
- Add deno.mkdir() and deno.mkdirSync() denoland#746
- Add deno.makeTempDir() denoland#740
- Improvements to FileInfo interface denoland#765, denoland#761
- Add fetch.blob()
- Upgrade V8 to 7.0.276.15
- Upgrade Rust crates
@ry ry mentioned this pull request Sep 22, 2018
ry added a commit that referenced this pull request Sep 22, 2018
- Add atob() btoa() #776
- Add deno.arch deno.platform #773
- Add deno.symlink() and deno.symlinkSync() #742
- Add deno.mkdir() and deno.mkdirSync() #746
- Add deno.makeTempDir() #740
- Improvements to FileInfo interface #765, #761
- Add fetch.blob()
- Upgrade V8 to 7.0.276.15
- Upgrade Rust crates
@kevinkassimo kevinkassimo deleted the platform/rollup branch December 27, 2019 07:50
littledivy pushed a commit that referenced this pull request Feb 15, 2023
Fixes #16922.

The error messages in the `ffi` module are somewhat cryptic when passing
functions that have invalid `parameters` or `result` type strings. While
the generated serializer for the `ForeignFunction` struct correctly
outputs a correct and verbose message, the user sees a far less helpful
`data did not match any variant` message instead.

The underlying cause appears to be the fallback message in the
auto-derived deserializer for untagged enums [1] generated as a result
of `ForeignSymbol` being marked as `#[serde(untagged)]` [2]. Passing an
unexpected value for `NativeType` causes it to error out while
attempting to deserialize both enum variants -- once because it's not a
match for the `ForeignStatic` variant, and once because the
`ForeignFunction` deserializer rejects the invalid type for the
parameters/return type. This is currently open as [serde
#773](serde-rs/serde#773), and not a trivial
exercise to fix generically.

[1]
https://github.com/serde-rs/serde/blob/v0.9.7/serde_derive/src/de.rs#L730
[2] https://github.com/denoland/deno/blob/main/ext/ffi/dlfcn.rs#L102
[3] serde-rs/serde#773

Note that the auto-generated deserializer for untagged enums uses a
private API to buffer deserializer content that we don't have access to.
Instead, we can make use of the `serde_value` crate to buffer the
values. This can likely be removed once the official buffering API lands
(see [4] and [5]). In addition, this crate pulls in `serde_json` as a
cheap way to test that the deserializer works properly.

[4] serde-rs/serde#741
[5] serde-rs/serde#2348
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

3 participants