mirror of
https://github.com/hanzoai/next.js.git
synced 2026-10-30 14:46:38 +00:00
Enable prettier for turbopack While the majority of the javascript in turbopack is for tests, this code is generally hand authored so prettier will help us. There are also core parts of turbopack implemented in JavaScript/TypeScript so a formatter will help. This was done by simply fixing prettier ignore and chasing lint errors. There were a few fun issues * We had a test file called `won't-run-tla.js` and this triggered a bug in our eslint precommit hook. The simplest thing was to simply drop the `'` character so that is what i did. I spent a small amount of time trying to narrow this down't in the `lint-staged` dependency but failed, so i think the problem is probably in `eslint`, but it isn't really clear. * We had another test exercising `import.meta` but in a file called `.cjs`, which prettier rejects due its default `babel` parser. So i excluded this from prettier.
29 lines
1.1 KiB
JavaScript
29 lines
1.1 KiB
JavaScript
// import() doesn't care about whether a module is an async module or not
|
|
const UserApi = import('./UserAPI.js')
|
|
|
|
export const CreateUserAction = async (name) => {
|
|
console.log('Creating user', name)
|
|
// These are normal awaits, because they are in an async function
|
|
const { createUser } = await UserApi
|
|
await createUser(name)
|
|
}
|
|
|
|
// You can place import() where you like
|
|
// Placing it at top-level will start loading and evaluating on
|
|
// module evaluation.
|
|
// see CreateUserAction above
|
|
// Here: Connecting to the DB starts when the application starts
|
|
// Placing it inside of an (async) function will start loading
|
|
// and evaluating when the function is called for the first time
|
|
// which basically makes it lazy-loaded.
|
|
// see AlternativeCreateUserAction below
|
|
// Here: Connecting to the DB starts when AlternativeCreateUserAction
|
|
// is called
|
|
export const AlternativeCreateUserAction = async (name) => {
|
|
const { createUser } = await import('./UserAPI.js')
|
|
await createUser(name)
|
|
}
|
|
|
|
// Note: Using await import() at top-level doesn't make much sense
|
|
// except in rare cases. It will import modules sequentially.
|