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

chore: migrate more codebase to ESM #5267

Merged
merged 27 commits into from
Nov 29, 2022
Merged

chore: migrate more codebase to ESM #5267

merged 27 commits into from
Nov 29, 2022

Conversation

danez
Copy link
Contributor

@danez danez commented Nov 24, 2022

Summary

Migrates some parts of the codebase to ESM.

To move further I have to first introduce vitest for the unit tests to be able to properly mock modules, which rewiremock fails with esm now.


For us to review and ship your PR efficiently, please perform the following steps:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

A picture of a cute animal (not mandatory, but encouraged)

@danez danez self-assigned this Nov 24, 2022
@danez danez changed the title Esm3 chore: migrate codebase to ESM Nov 24, 2022
@github-actions
Copy link

github-actions bot commented Nov 24, 2022

📊 Benchmark results

Comparing with 2b5d96c

Package size: 247 MB

⬇️ 0.00% decrease vs. 2b5d96c

^  257 MB                                                                                                 
│   ┌──┐   249 MB  249 MB  249 MB  249 MB  249 MB  249 MB  249 MB  247 MB  247 MB  247 MB  247 MB  247 MB 
│ ──┼──┼────┌──┐────┌──┐────┌──┐────┌──┐────┌──┐────┌──┐────┌──┐────┌──┐────┌──┐────┌──┐────┌──┐────┌──┐──
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
│   |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |  |    |▒▒|  
└───┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴────┴──┴──>
    T-12    T-11    T-10    T-9     T-8     T-7     T-6     T-5     T-4     T-3     T-2     T-1      T    
Legend

@github-actions github-actions bot added the type: chore work needed to keep the product and development running smoothly label Nov 24, 2022
@danez danez marked this pull request as ready for review November 25, 2022 14:44
@danez danez requested review from a team and lukasholzer November 25, 2022 14:44
@danez danez changed the title chore: migrate codebase to ESM chore: migrate more codebase to ESM Nov 28, 2022

// 12 hours
const UPDATE_CHECK_INTERVAL = 432e5
const pkg = JSON.parse(readFileSync(fileURLToPath(new URL('../package.json', import.meta.url))), 'utf-8')
const pkg = await getPackageJson()
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 was extracted into a separate file, so we do not have to do this all over again multiple times.

import getGlobalConfig from '../utils/get-global-config.cjs'
import { openBrowser } from '../utils/open-browser.cjs'
import StateConfig from '../utils/state-config.mjs'
import { identify, track } from '../utils/telemetry/index.mjs'
Copy link
Contributor Author

@danez danez Nov 28, 2022

Choose a reason for hiding this comment

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

I started unusing /utils/index.cjs, and instead import utils from individual files :

  1. It is easier to migrate
  2. It makes node not require everything at once, which might come in handy once the commands are not all loaded always, and only the command in use.

So the goal would be to remove utils/index.cjs at some point, but if anyone feels opposed to that it can also be reinstated at the end of the migration.

])
t.deepEqual(watchDirs, [path.join(builder.directory, 'functions'), path.join(builder.directory, 'utils')])
})
})
Copy link
Contributor Author

Choose a reason for hiding this comment

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

getFunctionsAndWatchDirs was unused, so removed.

const functionsWithProps = functions.filter(({ runtime }) => runtime === JS).map((func) => addFunctionProps(func))

return { functions: functionsWithProps, watchDirs }
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

getFunctionsAndWatchDirs was unused so removed

packageJson = JSON.parse(await readFile(packageJsonPath))
}

return packageJson
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 now also caches the root package.json of the cli as I do not think it will change during runtime.

@danez danez added the automerge Add to Kodiak auto merge queue label Nov 29, 2022
@kodiakhq kodiakhq bot merged commit c99f57f into main Nov 29, 2022
@kodiakhq kodiakhq bot deleted the esm3 branch November 29, 2022 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
automerge Add to Kodiak auto merge queue type: chore work needed to keep the product and development running smoothly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants