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] feat: rewrite project to typescript #1109

Closed
wants to merge 4 commits into from

Conversation

aldy505
Copy link
Contributor

@aldy505 aldy505 commented Mar 22, 2023

Closes #1106

Copy link
Contributor Author

@aldy505 aldy505 left a 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'
Copy link
Contributor Author

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.

Comment on lines +17 to +30
'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 }],
Copy link
Contributor Author

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.

Copy link
Member

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

Comment on lines +20 to +26
"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",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removing gulp, and replacing it with rollup just for the build step. For everything else, we can directly run their CLI commands (mocha, eslint).

Rollup itself isn't a shiny bundler. A shiny bundler would be esbuild, bun or turbo.

Comment on lines +7 to +15
{
file: 'dist/main/minio.cjs',
format: 'cjs',
exports: 'default'
},
{
file: 'dist/main/minio.mjs',
format: 'es'
},
Copy link
Contributor Author

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:

Comment on lines +17 to +20
file: 'dist/main/minio.iife.js',
format: 'iife',
name: 'MinIO',
plugins: [terser()]
Copy link
Contributor Author

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. */
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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() {
Copy link
Contributor Author

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.

Copy link
Contributor Author

@aldy505 aldy505 left a comment

Choose a reason for hiding this comment

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

Another progress update.

If anyone's want to help, you could:

  • Create typings for the signing.ts file (link)
  • Create typings for transformers.ts file (link)
  • Create typings for the xml-parsers.ts file (link)

As I will not touch those files until some of the core function on minio.ts file is completed.

Comment on lines +981 to +983
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 {
Copy link
Contributor Author

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.

Copy link
Member

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 {
Copy link
Contributor Author

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 {
Copy link
Contributor Author

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.

Comment on lines +580 to +582
response.on('data', () => {
// do nothing
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@prakashsvmx
Copy link
Member

I looked at the PR in detail @aldy505 .
My humble suggestion is, we can take the approach of progressive improvement than one single PR as it is more manageable and easy for migration.

@prakashsvmx
Copy link
Member

@aldy505 - i would be migrating to ts progressively via https://github.com/minio/minio-js/pull/1114` and ensure every step passes CI test

@aldy505
Copy link
Contributor Author

aldy505 commented Apr 4, 2023

@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.

@aldy505
Copy link
Contributor Author

aldy505 commented Apr 10, 2023

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.

@prakashsvmx
Copy link
Member

The progressive upgrade PRs have been merged. closing this in favour of them. Thank you for collaborating 👍

@prakashsvmx prakashsvmx closed this May 5, 2023
@aldy505 aldy505 deleted the feat/rewrite-typescript branch May 5, 2023 14:27
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.

Thoughts on converting this project to Typescript?
2 participants