-
Notifications
You must be signed in to change notification settings - Fork 1
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: support output as commonjs/es modules/typescript #4
Conversation
lib/PlainSerializer.js
Outdated
let leadingLines | ||
switch (module) { | ||
case 'esm': | ||
leadingLines = ['export const dataset = ({ blankNode, literal, namedNode, quad }) => {'] | ||
break | ||
case 'ts': | ||
leadingLines = [ | ||
"import { DataFactory, Quad } from 'rdf-js'", | ||
'', | ||
'export const dataset = ({ blankNode, literal, namedNode, quad }: DataFactory): Quad[] => {' | ||
] | ||
break | ||
default: | ||
leadingLines = ['module.exports = ({ blankNode, literal, namedNode, quad }) => {'] | ||
break | ||
} | ||
|
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.
Maybe it makes sense to use subclasses to handle this? E.g. TS may also use a different code style.
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.
Yea, why not 👍
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.
Instead of going for subclassing I went for a strategy pattern. For now only the leadingLines
but could extract other portions in the future which shall differ between output types
super({ | ||
objectMode: true, | ||
read: () => {} | ||
}) | ||
|
||
getStream.array(input).then(quads => { | ||
this.push((new PlainSerializer()).transform(quads)) | ||
this.push((new PlainSerializer(options)).transform(quads)) |
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.
Also, I missed this class earlier. You want a test for that?
I'm adding one more change before we refactor, to control the kind of module to produce (commonjs, ESM, TypeScript)
module
option