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

feat(ext/node): embed std/node into the snapshot #17724

Merged
merged 66 commits into from Feb 14, 2023

Conversation

bartlomieju
Copy link
Member

@bartlomieju bartlomieju commented Feb 10, 2023

This commit moves "deno_std/node" in "ext/node" crate. The code is
transpiled and snapshotted during the build process.

During the first pass a minimal amount of work was done to create the snapshot,
a lot of code in "ext/node" depends on presence of "Deno" global. This code
will be gradually fixed in the follow up PRs to migrate it to import relevant
APIs from "internal:" modules.

Currently the code from snapshot is not used in any way, and all Node/npm
compatibility still uses code from "https://deno.land/std/node" (or from the
location specified by "DENO_NODE_COMPAT_URL"). This will also be
handled in a follow up PRs.

@bartlomieju
Copy link
Member Author

bartlomieju commented Feb 11, 2023

There are currently 3 blockers that we need to tackle:

tools/lint.js passes in ext/node (done)

references to Deno namespace are replaced with imports of internal modules (@bartlomieju)

replace imports of functionality outside of std/node with some embedded code:

  • ext/node/polyfills/_test_util.ts depends on std/testing/asserts.ts (@kt3k) Removed as it's a testing utility
  • ext/node/polyfills/assert.ts depends on std/testing/asserts.ts (@kt3k)
  • ext/node/polyfills/http.ts depends on std/http/http_status.ts
  • ext/node/polyfills/os.ts depends on std/fs/eol.ts
  • ext/node/polyfills/url.ts depends on std/path/_constants.ts
  • ext/node/polyfills/_fs/_fs_open.ts depends on std/fs/exists.ts
  • ext/node/polyfills/_fs/_fs_writeFile.ts depends on std/streams/write_all.ts
  • ext/node/polyfills/_fs/_fs_writeFile.ts depends on std/types.d.ts
  • ext/node/polyfills/internal/buffer.mjs depends on std/encoding/base64.ts (@crowlKats)
  • ext/node/polyfills/internal/buffer.mjs depends on std/encoding/base64url.ts (@crowlKats)
  • ext/node/polyfills/internal/crypto/hash.ts depends on std/crypto/_wasm/mod.ts (@littledivy)
  • ext/node/polyfills/internal/crypto/hash.ts depends on std/encoding/hex.ts (@littledivy)
  • ext/node/polyfills/internal/crypto/hash.ts depends on std/encoding/base64.ts (@crowlKats)
  • ext/node/polyfills/internal/crypto/hash.ts depends on std/encoding/base64url.ts (@crowlKats)
  • ext/node/polyfills/internal_binding/_utils.ts depends on std/encoding/base64.ts (@crowlKats)
  • ext/node/polyfills/internal_binding/_utils.ts depends on std/encoding/base64url.ts (@crowlKats)
  • ext/node/polyfills/internal_binding/connection_wrap.ts depends on std/types.d.ts
  • ext/node/polyfills/internal_binding/node_options.ts depends on std/flags/mod.ts
  • ext/node/polyfills/internal_binding/stream_wrap.ts depends on std/streams/write_all.ts
  • ext/node/polyfills/internal_binding/stream_wrap.ts depends on std/types.d.ts

EDIT: We can now successfully take a snapshot of ext/node/ and can run this code during runtime. Addressing references to Deno namespace are replaced with imports of internal modules is not gonna happen in this PR, I will address it in a follow up, since this PR is big enough already.

@kt3k
Copy link
Member

kt3k commented Feb 12, 2023

I think ext/node/polyfills/_crypto/crypto_browserify/asn1.js/test/util.js is testing utility and is not needed to included in ext/node

@bartlomieju bartlomieju changed the title [WIP] feat(ext/node): embed std/node into the snapshot feat(ext/node): embed std/node into the snapshot Feb 14, 2023
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.

LGTM - after landing this we are leaving main in purgatory with all this code being unused. However I think it makes sense given the size of this patch.

@bartlomieju
Copy link
Member Author

Blocked on #17735

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

5 participants