Skip to content

Commit

Permalink
Avoid overwriting customLogger (#2341)
Browse files Browse the repository at this point in the history
* Allow passing custom loggers from Vite config

* Changesets
  • Loading branch information
frandiox authored Jul 29, 2024
1 parent 5339006 commit a2d9acf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/flat-melons-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/cli-hydrogen': patch
---

Allow passing `customLogger` in `vite.config.js`.
16 changes: 7 additions & 9 deletions packages/cli/src/commands/hydrogen/dev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,22 +221,20 @@ export async function runDev({
await removeFile(joinPath(root, 'node_modules/.vite'));
}

const customLogger = vite.createLogger();
if (process.env.SHOPIFY_UNIT_TEST) {
// Make logs from Vite visible in tests
customLogger.info = (msg) => collectLog('info', msg);
customLogger.warn = (msg) => collectLog('warn', msg);
customLogger.error = (msg) => collectLog('error', msg);
}

const formatOptionsPromise = Promise.resolve().then(() =>
getCodeFormatOptions(root),
);

const viteServer = await vite.createServer({
root,
customLogger,
clearScreen: false,
customLogger: process.env.SHOPIFY_UNIT_TEST
? Object.assign(vite.createLogger(), {
info: (msg: string) => collectLog('info', msg),
warn: (msg: string) => collectLog('warn', msg),
error: (msg: string) => collectLog('error', msg),
})
: undefined,
server: {
host: host ? true : undefined,
// Allow Vite to read files from the Hydrogen packages in local development.
Expand Down

0 comments on commit a2d9acf

Please sign in to comment.