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
Conversation
a319889
to
3003e3e
Compare
@Raynos PTAL this now covers all interfaces, and assigns the singletons to the global using symbols with the properties being unwritable and unenumerable |
@@ -6,6 +6,7 @@ extends: 'eslint:recommended' | |||
globals: | |||
Atomics: readonly | |||
SharedArrayBuffer: readonly | |||
parser: babel-eslint |
There was a problem hiding this comment.
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 ... ?
There was a problem hiding this comment.
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
There was a problem hiding this 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, { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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', |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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 Writing the source code in ESM but only publishing the CJS code to NPM seems like the cleanest thing to do for now ... |
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 😅 |
This is a very nice conclusion. 💔 |
Refs: #36