Changes
4 changed files (+50/-1)
-
-
@@ -106,7 +106,20 @@ export function gleam({: fileURLToPath(gleamTomlPathOrUrl), ); const parsed = toml.parse(await readFile(gleamTomlPathOrUrl, { encoding: "utf8" })); let file: string; try { file = await readFile(gleamTomlPathOrUrl, { encoding: "utf8" }); } catch (error) { // TypeScript can't narrow types using `never`. Putting `return` after this line // triggers `Unreachable code detected.` so we have to *return never*. // <https://github.com/microsoft/TypeScript/issues/12825> // Following code contains the same workaround for this reason. return this.error( `Failed to open gleam manifest file, which is required: ${String(error)}`, ); } const parsed = toml.parse(file); if (!isGleamTOML(parsed)) { // TypeScript can't narrow types using `never`. Putting `return` after this line // triggers `Unreachable code detected.` so we have to *return never*.
-
-
-
@@ -0,0 +1,30 @@// Test suites for handling of miss of a manifest file. // // SPDX-FileCopyrightText: 2024 Shota FUJI <pockawoooh@gmail.com> // SPDX-License-Identifier: Apache-2.0 import { rollup } from "rollup"; import { describe, expect, it } from "vitest"; import { gleam } from "../../src/plugin"; describe("Missing gleam.toml", () => { it("Should abort build with wrapped error when gleam.toml is missing", async () => { try { await rollup({ input: new URL("./src/main.js", import.meta.url).pathname, plugins: [ gleam({ gleamToml: new URL("./gleam.toml", import.meta.url), }), ], }); expect.unreachable("Expected build error, but build succeeded."); } catch (error) { expect(String(error)).toMatch( "Failed to open gleam manifest file, which is required", ); } }); });
-
-
-
@@ -0,0 +1,3 @@pub fn hello_world() -> String { "Hello, World!" }
-
-
-
@@ -0,0 +1,3 @@import { hello_world } from "./main.gleam"; console.log(hello_world());
-