Skip to content

Commit

Permalink
Address top-level await error on Vite
Browse files Browse the repository at this point in the history
  • Loading branch information
dahlia committed Sep 21, 2024
1 parent b75e0e0 commit a6c56f2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"files.eol": "\n",
"files.insertFinalNewline": true,
"files.trimFinalNewlines": true,
"[javascript]": {
"editor.defaultFormatter": "denoland.vscode-deno",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
}
},
"[json]": {
"editor.defaultFormatter": "vscode.json-language-features",
"editor.formatOnSave": true
Expand Down
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ Version 0.5.2

To be released.

- Fixed a build error due to top-level `await` on [Vite]. [[#14]]

[Vite]: https://vitejs.dev/
[#14]: https://github.com/dahlia/logtape/issues/14


Version 0.5.1
-------------
Expand Down
25 changes: 13 additions & 12 deletions logtape/fs.mjs
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
let fs = null;
if (
"process" in globalThis && "versions" in globalThis.process &&
"node" in globalThis.process.versions &&
typeof globalThis.caches === "undefined" &&
typeof globalThis.addEventListener !== "function" ||
"Bun" in globalThis
("process" in globalThis && "versions" in globalThis.process &&
"node" in globalThis.process.versions &&
typeof globalThis.caches === "undefined" &&
typeof globalThis.addEventListener !== "function" ||
"Bun" in globalThis) &&
!("env" in import.meta && "SSR" in import.meta.env &&
import.meta.env.SSR === false)
) {
try {
fs = await import("node" + ":fs");
} catch (e) {
if (e instanceof TypeError) {
fs = null;
} else {
throw e;
}
fs = await import(
/* @vite-ignore */
["node", "fs"].join(":")
);
} catch {
fs = null;
}
}

Expand Down

0 comments on commit a6c56f2

Please sign in to comment.