-
Notifications
You must be signed in to change notification settings - Fork 264
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] feat: rewrite project to typescript #1109
Conversation
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.
A few notes on the progress of this rewrite. It's weekend so I intend to continue this PR later today (or tomorrow).
I have a question about doing a proper integration test, but that might come later.
@@ -23,19 +42,41 @@ module.exports = { | |||
], | |||
'linebreak-style': [ | |||
'error', | |||
(process.platform === 'win32' ? 'windows' : 'unix') // all windows platforms are denoted by win32 | |||
'unix' |
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.
Make the default linebreak style as LF (unix-style), as this ternary configuration really broke on every text editor / IDE I use on WIndows.
'no-console': ['error'], | ||
'no-var': ['error'], | ||
'no-empty-function': ['error'], | ||
'comma-dangle': ['error', 'never'], | ||
'prefer-const': ['error'], | ||
'quotes': ['error', 'single'], | ||
'comma-spacing': ['error', { before: false, after: true }], | ||
'semi-spacing': ['warn', { before: false, after: true }], | ||
'space-before-blocks': ['warn', 'always'], | ||
'switch-colon-spacing': ['warn', { after: true, before: false }], | ||
'keyword-spacing': ['warn', { before: true, after: true }], | ||
'template-curly-spacing': ['error', 'never'], | ||
'rest-spread-spacing': ['error', 'never'], | ||
'no-multi-spaces': ['warn', { ignoreEOLComments: false }], |
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.
There are applied for consistent code style. The most prominent one is "prefer-const" to avoid any other var
on the codebase.
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 could use prettier and use the default configuration to enforce it. And configure husky
"compile": "rollup -c", | ||
"test": "mocha test/**/*.js", | ||
"lint": "eslint --ignore-path .gitignore .", | ||
"lint-fix": "eslint --ignore-path .gitignore --fix .", | ||
"prepublishOnly": "npm run test", | ||
"functional": "mocha test/functional/*.js ", | ||
"browserify": "npm run compile", |
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.
{ | ||
file: 'dist/main/minio.cjs', | ||
format: 'cjs', | ||
exports: 'default' | ||
}, | ||
{ | ||
file: 'dist/main/minio.mjs', | ||
format: 'es' | ||
}, |
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.
Provide both ESM and CommonJS output, as the Javascript ecosystem is actually still on war between CJS vs ESM.
See:
file: 'dist/main/minio.iife.js', | ||
format: 'iife', | ||
name: 'MinIO', | ||
plugins: [terser()] |
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.
IIFE output is actually optional, as I believe this will be a broken build once used.
"declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ | ||
// "declarationMap": true, /* Create sourcemaps for d.ts files. */ | ||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ | ||
"sourceMap": true, /* Create source map files for emitted JavaScript files. */ |
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 actually not sure whether we should emit the source map or not. Probably not though, but I guess it's a good thing if people want to debug the library once there is any problem or errors.
* isEmpty({ 'a': 1 }) | ||
* // => false | ||
*/ | ||
function isEmpty(value: unknown): boolean { |
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 intending to include vendored libnraries that are used not much throughout the SDK, just for turning down the final dependency size of the SDK itself.
For example if as an SDK, you're required to install Lodash that'll take a few KBs, we can trim that down into a few bytes not with using tree shaking, but with vendoring the needed functions.
return crc ^ -1 | ||
} | ||
|
||
function crc32() { |
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.
Other than vendoring some libraries that are not used often, I wanted to vendor some libraries that not really maintained anymore and might contain vulnerabilities.
This crc32 library is simple enough that I decided just to do that. And yes, we should inlude a unit test for the specific libraries that we vendored.
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.
getObject(bucketName: string, objectName: string, callback: (err: Error | null) => void): void | ||
getObject(bucketName: string, objectName: string, getOpts: GetObjectOptions, callback: (err: Error | null) => void): void | ||
getObject(bucketName: string, objectName: string, ...rest: [(err: Error | null) => void] | [GetObjectOptions, (err: Error | null) => void]): void { |
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 be the style of pattern on how we'll implement function overloading for the sake of backward compatibility. See https://tsplay.dev/wXvnOm for Typescript playground sample.
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 will try to update types for the above links. Thank you @aldy505 .
Could you please resolve the conflicts ?
@@ -3628,134 +3676,5 @@ Client.prototype.getObjectLegalHold=promisify(Client.prototype.getObjectLegalHol | |||
Client.prototype.composeObject = promisify(Client.prototype.composeObject) | |||
Client.prototype.selectObjectContent=promisify(Client.prototype.selectObjectContent) | |||
|
|||
export class CopyConditions { |
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.
Moved CopyConditions class to a separate file
} | ||
|
||
// Build PostPolicy object that can be signed by presignedPostPolicy | ||
export class PostPolicy { |
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 moved PostPolicy to a separate file, we'll re-export them from the minio.ts file later on.
response.on('data', () => { | ||
// do nothing | ||
}) |
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 looked at the PR in detail @aldy505 . |
@aldy505 - i would be migrating to ts progressively via https://github.com/minio/minio-js/pull/1114` and ensure every step passes CI test |
@prakashsvmx okay. can you create a list of checkbox that we need to do for converting the project to typescript? I only available to code OSS stuff on weekends, but I can respond to messages or a small portion of code reviews on weekdays. |
I'll leave this PR be for future reference on the Typescript rewrite journey. Please do not close this PR as long as the project is still in Javascript (or the rewrite hasn't been completed yet). All of us should work on a separate small PRs. |
The progressive upgrade PRs have been merged. closing this in favour of them. Thank you for collaborating 👍 |
Closes #1106