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 streams breaking on reverted EventEmitter / Make Discord.js work #2913

Merged
merged 11 commits into from
Jun 1, 2023

Conversation

paperclover
Copy link
Member

@paperclover paperclover commented May 17, 2023

Closes #2707, Closes #2077

fixes some of the things that were reverted before

  • crypto improvement with lazy init stream
  • js implementation for node events
  • cjs entrypoints

in addition to this, it makes discord.js work

  • ws changes
  • undici and builtins bug fix

note for the first one, it does cause slower runtime with

const hasher = createHash(alg);
hasher.write(data);
hasher.end();
hasher.read();

and we could totally optimize this simple use case too but i did not do that.

there were two fixes to this, and i went with (2)

image

1 = current
2 = lazy init + old event emitter from 0.6 and prior
3 = lazy init + js event emitter + pure js streams

@github-actions
Copy link
Contributor

github-actions bot commented May 23, 2023

@paperdave prettier reported errors

[warn] src/bun.js/events.exports.js
[warn] Code style issues found in the above file. Forgot to run Prettier?
error: "prettier" exited with code 1 (SIGHUP)
Checking formatting...

To one-off fix this manually, run:

bun fmt

You might need to run bun install locally and configure your text editor to auto-format on save.

#26dbce895c847005cf6d077997f9845be639ea8a

@@ -192,7 +192,7 @@ pub const ServerEntryPoint = struct {
\\var cjs = start?.default;
\\if (cjs && typeof cjs === 'function' && cjsSymbol in cjs) {{
\\ // if you module.exports = (class {{}}), don't call it
\\ entryNamespace = ("prototype" in cjs) ? cjs : cjs();
\\ entryNamespace = import.meta.primordials.isCallable(cjs) ? cjs() : cjs;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this shouldn't be in here


EventEmitter.prototype[kCapture] = false;

function once(emitter, type, { signal } = {}) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

we can't set a default argument in the function this way

people will pass null or something truthy and then get a very strange error

}
EventEmitter.once = once;

function on(emitter, type, { signal, close, highWatermark = Number.MAX_SAFE_INTEGER, lowWatermark = 1 } = {}) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

ditto

}
}

EventEmitter.prototype._events = undefined;
Copy link
Collaborator

Choose a reason for hiding this comment

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

instead of

EventEmitter.prototype

People might mess with it at runtime

Instead, lets assign it to a local variable and use that one

const EventEmitterPrototype = EventEmitter.prototype;

@paperclover paperclover marked this pull request as draft May 23, 2023 05:34
@paperclover paperclover marked this pull request as ready for review May 26, 2023 02:09
@github-actions
Copy link
Contributor

github-actions bot commented May 26, 2023

@paperdave 27 files with test failures on linux-x64-baseline:

  • test/bundler/bun-build-api.test.ts
  • test/bundler/bundler_browser.test.ts
  • test/bundler/bundler_compile.test.ts
  • test/bundler/bundler_edgecase.test.ts
  • test/bundler/bundler_jsx.test.ts
  • test/bundler/bundler_naming.test.ts
  • test/bundler/bundler_plugin.test.ts
  • test/bundler/esbuild/dce.test.ts
  • test/bundler/esbuild/default.test.ts
  • test/bundler/esbuild/extra.test.ts
  • test/bundler/esbuild/importstar.test.ts
  • test/bundler/esbuild/loader.test.ts
  • test/bundler/esbuild/packagejson.test.ts
  • test/bundler/esbuild/splitting.test.ts
  • test/bundler/esbuild/ts.test.ts
  • test/bundler/esbuild/tsconfig.test.ts
  • test/cli/run/env.test.ts
  • test/cli/run/preload-test.test.js
  • test/cli/run/run-cjs.test.ts
  • test/js/bun/plugin/plugins.test.ts
  • test/js/bun/resolve/png/test-png-import.test.js
  • test/js/bun/test/preload-test.test.js
  • test/js/bun/test/snapshot-tests/snapshots/more-snapshots/different-directory.test.ts
  • test/js/bun/test/snapshot-tests/snapshots/more.test.ts
  • test/js/bun/websocket/websocket-server.test.ts
  • test/js/node/child_process/child_process-node.test.js
  • test/transpiler/transpiler.test.js

View test output

#26dbce895c847005cf6d077997f9845be639ea8a

@github-actions
Copy link
Contributor

github-actions bot commented May 26, 2023

@paperdave 27 files with test failures on linux-x64:

  • test/bundler/bun-build-api.test.ts
  • test/bundler/bundler_browser.test.ts
  • test/bundler/bundler_compile.test.ts
  • test/bundler/bundler_edgecase.test.ts
  • test/bundler/bundler_jsx.test.ts
  • test/bundler/bundler_naming.test.ts
  • test/bundler/bundler_plugin.test.ts
  • test/bundler/esbuild/dce.test.ts
  • test/bundler/esbuild/default.test.ts
  • test/bundler/esbuild/extra.test.ts
  • test/bundler/esbuild/importstar.test.ts
  • test/bundler/esbuild/loader.test.ts
  • test/bundler/esbuild/packagejson.test.ts
  • test/bundler/esbuild/splitting.test.ts
  • test/bundler/esbuild/ts.test.ts
  • test/bundler/esbuild/tsconfig.test.ts
  • test/cli/run/env.test.ts
  • test/cli/run/preload-test.test.js
  • test/cli/run/run-cjs.test.ts
  • test/js/bun/plugin/plugins.test.ts
  • test/js/bun/resolve/png/test-png-import.test.js
  • test/js/bun/test/preload-test.test.js
  • test/js/bun/test/snapshot-tests/snapshots/more-snapshots/different-directory.test.ts
  • test/js/bun/test/snapshot-tests/snapshots/more.test.ts
  • test/js/bun/websocket/websocket-server.test.ts
  • test/js/node/child_process/child_process-node.test.js
  • test/transpiler/transpiler.test.js

View test output

#26dbce895c847005cf6d077997f9845be639ea8a

@github-actions
Copy link
Contributor

github-actions bot commented May 26, 2023

@paperdave 30 files with test failures on bun-darwin-x64-baseline:

  • test/bundler/bun-build-api.test.ts
  • test/bundler/bundler_browser.test.ts
  • test/bundler/bundler_compile.test.ts
  • test/bundler/bundler_edgecase.test.ts
  • test/bundler/bundler_jsx.test.ts
  • test/bundler/bundler_naming.test.ts
  • test/bundler/bundler_plugin.test.ts
  • test/bundler/esbuild/dce.test.ts
  • test/bundler/esbuild/default.test.ts
  • test/bundler/esbuild/extra.test.ts
  • test/bundler/esbuild/importstar.test.ts
  • test/bundler/esbuild/loader.test.ts
  • test/bundler/esbuild/packagejson.test.ts
  • test/bundler/esbuild/splitting.test.ts
  • test/bundler/esbuild/ts.test.ts
  • test/bundler/esbuild/tsconfig.test.ts
  • test/cli/run/env.test.ts
  • test/cli/run/preload-test.test.js
  • test/cli/run/run-cjs.test.ts
  • test/js/bun/plugin/plugins.test.ts
  • test/js/bun/resolve/png/test-png-import.test.js
  • test/js/bun/spawn/spawn-streaming-stdin.test.ts
  • test/js/bun/spawn/spawn.test.ts
  • test/js/bun/sqlite/sqlite.test.js
  • test/js/bun/test/preload-test.test.js
  • test/js/bun/test/snapshot-tests/snapshots/more-snapshots/different-directory.test.ts
  • test/js/bun/test/snapshot-tests/snapshots/more.test.ts
  • test/js/bun/util/sleepSync.test.ts
  • test/js/web/timers/setTimeout.test.js
  • test/transpiler/transpiler.test.js

View test output

#26dbce895c847005cf6d077997f9845be639ea8a

@paperclover paperclover changed the title Fix streams breaking on reverted EventEmitter. Fix streams breaking on reverted EventEmitter / Make Discord.js work May 30, 2023
@Jarred-Sumner Jarred-Sumner merged commit 2c1694f into main Jun 1, 2023
@Jarred-Sumner Jarred-Sumner deleted the dave/events2 branch June 1, 2023 21:31
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.

node:crypto createHash or node:stream, stream isn't readable Support discord.js
2 participants