Title: buildStart hook is not async in webpack · Issue #293 · unjs/unplugin · GitHub
Open Graph Title: buildStart hook is not async in webpack · Issue #293 · unjs/unplugin
X Title: buildStart hook is not async in webpack · Issue #293 · unjs/unplugin
Description: Environment unplugin 1.3.1 webpack 5.76.2 Node.js v16.14.2 Reproduction Have buildStart perform async operation. Have transform hook rely on ordered completion buildStart and its result. StackBlitz: https://stackblitz.com/edit/webpack-we...
Open Graph Description: Environment unplugin 1.3.1 webpack 5.76.2 Node.js v16.14.2 Reproduction Have buildStart perform async operation. Have transform hook rely on ordered completion buildStart and its result. StackBlitz...
X Description: Environment unplugin 1.3.1 webpack 5.76.2 Node.js v16.14.2 Reproduction Have buildStart perform async operation. Have transform hook rely on ordered completion buildStart and its result. StackBlitz...
Opengraph URL: https://github.com/unjs/unplugin/issues/293
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"buildStart hook is not async in webpack","articleBody":"### Environment\n\nunplugin 1.3.1\r\nwebpack 5.76.2\r\nNode.js v16.14.2\n\n### Reproduction\n\n1. Have `buildStart` perform async operation.\r\n2. Have `transform` hook rely on ordered completion `buildStart` and its result.\r\n\r\nStackBlitz: \u003chttps://stackblitz.com/edit/webpack-webpack-js-org-1qvdhq?file=package.json&view=editor> (`pnpm start` to run webpack programmatically, `pnpm test` to run tests which will also do the build programatically).\n\n### Describe the bug\n\n`buildStart` is not an async hook, and invoking `await` will immediately continue the build pipeline, which will have unexpected consequences.\r\n\r\nVitest:\r\n```\r\n-- webpack call\r\n-- webpack end\r\n\r\n-- buildStart call ← buildStart waits 1 second to resolve a promise\r\n\r\n-- transform call ← transform called before buildStart is fulfilled\r\n× transform thrown Error: transform method was called either before buildStart call was completed or after it has thrown an error\r\n-- transform end\r\n\r\n√ buildStart return ← timer fires, buildStart fulfills\r\n-- buildStart end\r\n\r\n(Test timeout)\r\n```\r\n\r\nNode.js:\r\n```\r\n-- webpack call\r\n-- webpack end\r\n\r\n-- buildStart call\r\n\r\n-- transform call\r\ntransform call without without buildStart completion, throwing!\r\n× transform thrown Error: transform method was called either before buildStart call was completed or after it has thrown an error\r\n-- transform end\r\n\r\n UNHANDLED EXPECTION \r\n Error: transform method was called either before buildStart call was completed or after it has thrown an error\r\n\r\n (Process halted with error code)\r\n```\n\n### Additional context\n\n- In Rollup/Vite realm `buildStart` is async and can be used to perform initial initialisation for `transform` hook invocations.\r\n- `transform` hook seems to be correctly async, which means you can await for `buildStart` fulfillment in it, which involves moving async logic of `buildStart` to a separate function and then also creating another plugin variable in which you will store promise returned by that separate async function call. But it's not obvious and still feels like a mistake/oversight.\n\n### Logs\n\n```sh\nN/A.\n```\n","author":{"url":"https://github.com/brawaru","@type":"Person","name":"brawaru"},"datePublished":"2023-03-20T16:34:43Z","url":"https://github.com/unjs/unplugin/issues/293"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:99989ff8-b7e2-1f26-2b18-57acad40d640 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8E9C:29A20E:2AE97BB:3A8C1C6:6B005291 |
| html-safe-nonce | acc034ccbc717cc752afeb29dcfcf83e9240a1072b2fb188d0a730923bc7529d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RTlDOjI5QTIwRToyQUU5N0JCOjNBOEMxQzY6NkIwMDUyOTEiLCJ2aXNpdG9yX2lkIjoiNTI4OTYzOTYxNTY4OTQxMzI2NSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e6f6c70121b84fe198df82c548234c2d3ead5f399609ebfec0e9ba232baa1bd6 |
| hovercard-subject-tag | issue:1632478957 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/unjs/unplugin/293/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7addbb84620a1cc93d3da2f2ee79bf8ee1337da52807c3d6b14af577780016aa/unjs/unplugin/issues/293 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7addbb84620a1cc93d3da2f2ee79bf8ee1337da52807c3d6b14af577780016aa/unjs/unplugin/issues/293 |
| og:image:alt | Environment unplugin 1.3.1 webpack 5.76.2 Node.js v16.14.2 Reproduction Have buildStart perform async operation. Have transform hook rely on ordered completion buildStart and its result. StackBlitz... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | brawaru |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| turbo-cache-control | no-preview |
| go-import | github.com/unjs/unplugin git https://github.com/unjs/unplugin.git |
| octolytics-dimension-user_id | 80154025 |
| octolytics-dimension-user_login | unjs |
| octolytics-dimension-repository_id | 385261169 |
| octolytics-dimension-repository_nwo | unjs/unplugin |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 385261169 |
| octolytics-dimension-repository_network_root_nwo | unjs/unplugin |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width