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

[WIP] lib: fix dual hazard #37

Closed
wants to merge 3 commits into from
Closed

[WIP] lib: fix dual hazard #37

wants to merge 3 commits into from

Conversation

MylesBorins
Copy link
Owner

Refs: #36

@MylesBorins
Copy link
Owner Author

@Raynos PTAL this now covers all interfaces, and assigns the singletons to the global using symbols with the properties being unwritable and unenumerable

@MylesBorins MylesBorins marked this pull request as ready for review April 22, 2020 20:33
@@ -6,6 +6,7 @@ extends: 'eslint:recommended'
globals:
Atomics: readonly
SharedArrayBuffer: readonly
parser: babel-eslint
Copy link

Choose a reason for hiding this comment

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

eslint :( it understands ES modules but not Symbol ... ?

Copy link
Owner Author

Choose a reason for hiding this comment

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

doesn't understand import.meta yet. There is an active issue to fix this

Copy link

@Raynos Raynos left a comment

Choose a reason for hiding this comment

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

This will solve the dual package hazard, but I'm not sure if it's worth solving when it creates boilerplate in every file.

}
}
};
Object.defineProperty(global, util.clientSymbol, {
Copy link

Choose a reason for hiding this comment

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

Consider putting a single symbol for the library on global and then putting Client on an object.

Aka

util.get('Client') and util.register('Client', Client)

The util module can have a single symbol and store an object with fields on it. This will have less symbols and also less boilerplate per source file.

@@ -1,47 +1,61 @@
import util from '../util/index.js';

class Argument {
Copy link

Choose a reason for hiding this comment

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

The Argument class is not a singleton. This is a non-issue due to it not being exported, but this class declaration should probably be in the else statement to reduce confusion

@@ -7,7 +7,9 @@ export default {
external: [
'dgram',
'events',
'module',
Copy link

Choose a reason for hiding this comment

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

This should not be necessary as we do not rollup the tests.

Copy link
Owner Author

Choose a reason for hiding this comment

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

I had put it here when i was using module in the source, that got refactored out but i forgot to remove this, thanks.

@@ -6,6 +6,7 @@ extends: 'eslint:recommended'
globals:
Copy link

Choose a reason for hiding this comment

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

I'm curious if eslint runs on .mjs

Copy link
Owner Author

Choose a reason for hiding this comment

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

yup, just needs to be globbed in the script that runs it

@Raynos
Copy link

Raynos commented Apr 23, 2020

This PR solves the problem and ensures we only have one class for the package instead of two.

However, it would be frustrating to apply this pattern to every file.

The more I think about this, the more I feel like publishing your npm package with two entry points with two pieces of duplicate code is just a bad idea.

That being said, I have already stopped using instanceof permanently in all code due to the multiple copies of a library problem.

Writing the source code in ESM but only publishing the CJS code to NPM seems like the cleanest thing to do for now ...

@MylesBorins
Copy link
Owner Author

publishing only CJS to npm would preclude named exports, as you can only export a default from CJS. At that point there is very little benefit to authoring in ESM.

Also realizing that the pattern used in this repo only works assuming your don't introduce ESM dependencies 😅

@MylesBorins MylesBorins closed this Aug 7, 2020
@Raynos
Copy link

Raynos commented Aug 7, 2020

At that point there is very little benefit to authoring in ESM.

This is a very nice conclusion. 💔

@MylesBorins MylesBorins deleted the fix-dual-hazard branch April 23, 2021 05:51
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

2 participants