-
Notifications
You must be signed in to change notification settings - Fork 108
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
Port to TypeScript #71
Conversation
For 2) I would propose the following: Removing js-logger/test-src/loggertests.js Line 32 in 34f8dc5
|
Wondering what's different between my local test (just opening the test index in the browser) and Travis's. 🤔 |
Thank you @tp, you are an open source hero! I am on mobile, but from looking at your diff I believe you need to modify the gulpfile to run tsc so that the tests execute against the generated JavaScript. Gulp is probably quite passé/unneeded now so feel free to migrate to npm scripts if that suits you better. Thanks again |
Tests now pass on Travis 🙃 Still need to test/add the capability to run the library on Node.js, as I think that was possible before. (I have never written such an export like But I think that should be possible. The only other remaining issue is the gulp git plugin, which crashes on |
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.
Couple of nits, otherwise awesome work.
// Inner class which performs the bulk of the work; ContextualLogger instances can be configured independently | ||
// of each other. | ||
export class ContextualLogger implements ILogger { | ||
public readonly context: IContext; |
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.
Any reason for making the context public?
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 global logger's context is used when creating a new logger in https://github.com/tp/js-logger/blob/077cea9477c2c3a225d301dc98190c67994fe413/src/JSLoggerDefaults.ts#L46:L52
src/ContextualLogger.ts
Outdated
// Changes the current logging level for the logging instance. | ||
public setLevel(newLevel: ILogLevel) { | ||
// Ensure the supplied Level object looks valid. | ||
if (newLevel && "value" in newLevel) { |
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.
Not sure we need this runtime check now that we are using types.
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.
Yep, that would be obsolete by now :) Neither null
/ undefined
nor a non-matching interface could be passed here from strict TypeScript code.
src/logger.ts
Outdated
export const Logger: JSLoggerExportType = { ...boundGlobalLoggerFunctions, ...JSLoggerDefaults }; | ||
|
||
// For those that are at home that are keeping score. | ||
// Logger.VERSION = "1.4.1"; |
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.
We should continue to export the version here (or remove this an make a breaking change in 2.0)
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.
Yeah, I think we can definitely keep the version. Just need to add it to the type.
src/datatypes.ts
Outdated
} | ||
|
||
declare var Logger: ILogger; | ||
export = Logger; | ||
export type JSLoggerExportType = IJSLoggerDefaultsType & ILogger; |
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.
Not a fan of this class name, why not just JSLogger
?
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.
👍 library name makes sense here, I agree
enabledFor(level: ILogLevel): boolean; | ||
} | ||
|
||
export interface IJSLoggerDefaultsType { |
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 think this would be a good oppertunity to make the LogLevel
's a publicly exported enum, we can do this in a subsequent refactor if you want to reduce the amount of change in this PR.
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.
Yeah, using TypeScript enums would be awesome :)
I'll see if we can utilize them in a way that would still keep them on the IJSLoggerDefaultsType
, such that the tests pass without any modifications.
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.
@jonnyreeves I think that would work. Would you be fine with a string based enum to preserve the human readability when it puts up during debugging? Put follow-up PR might be best, I hope no-one is using the internals of the log level interface.
tsconfig.json
Outdated
"strict": true, | ||
"removeComments": false, | ||
"preserveConstEnums": true, | ||
// "outFile": "./lib/logger.js", |
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.
remove this line.
I've not used yarn, but I have no strong feelings on this one - happy to do whatever works :) |
@jonnyreeves Thanks for your input! I'll clean this up and finalize the PR. |
@jonnyreeves I have implemented changes based on your comments and also added a new TypeScript test project to ensure that the library can actually be used in TypeScript as we intent it to :) |
The only remaining issue I see would be direct links to the minified library version as suggested in the README: Can we break these? Not sure what Github's policy is on those, but if it's generally accepted we should probably keep them for the foreseeable future. In that case, do we keep the 1.4.1 file there for maximum compatibility? Maybe adding a note in the header, that a new version is available etc. |
Ehhh, I'm pretty torn on this; I'm not a fan of "breaking the web", but JS dev has come a long way since 2011 when I first authored this library and blindly acquiring JavaScript snippets in this fashion is a long, long way from "best practice" in 2018. However, in the slim chance that someone is actually (ab)using this approach we shouldn't make their website/app stop working so let's do as you propose: publish 1.4.1 file in that location with a comment in the header explaining why it's there (and remove all mentions from the README) |
@jonnyreeves Re-added the minified library file to the |
Merged into https://github.com/jonnyreeves/js-logger/tree/2.0 - let's continue development in this branch. |
Hi @jonnyreeves, great that you want to do all the clean up in the branch! Good work on #75! Is there anything left to do that I could help you with? https://github.com/jonnyreeves/js-logger/milestone/1 currently shows no pending work. The only remaining thing I have thought about is running the tests on BrowserStack/some other Selenium Grid, but I don't know what the scope of that would be. Best, |
Hi @jonnyreeves,
since you'd would accept a TypeScript port, I have started one. At the moment it just compiles, but it's not final.
I try to keep the changes (for the user) as simple as possible, but it should probably be released as 2.0 if merged (at least the TypeScript using users will get some errors due to fixes – for JS users I strive for full compatibility).
For now I have 2 questions:
You advertise including the script via
https://cdn.rawgit.com/jonnyreeves/js-logger/master/src/logger.min.js
I would like to use the
src
folder exclusively for the TypeScript sources, and put the transpiled files inlib
(as is common convention). That would obviously break the above file. I hope no-one is using that in production anyway, but if you want to keep that stable we would need to re-arrange the source.Context type
In
js-logger/src/logger.d.ts
Line 21 in 34f8dc5
level
property.But in the current implementation I can find references to
filterLevel
(js-logger/src/logger.js
Line 59 in 34f8dc5
level
(js-logger/src/logger.js
Line 212 in 34f8dc5
js-logger/src/logger.js
Line 118 in 34f8dc5
Would you have any objections to just always use
filterLevel
(which seems to be the externally used one at the moment)?