Skip to content

Commit

Permalink
Update to deno 2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nktpro committed Oct 9, 2024
1 parent 9d08ab5 commit ec38350
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 108 deletions.
2 changes: 1 addition & 1 deletion cli.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ run() {
}

set_version() {
local VERSION=${1:-"dev"}
local VERSION=${1:-"0.0.0"}
local JSR_JSON
JSR_JSON=$(jq -e --arg VERSION "${VERSION}" '.version=$VERSION' ./deno.json)
echo "${JSR_JSON}" >./deno.json
Expand Down
11 changes: 6 additions & 5 deletions deno.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
"name": "@wok/jetski",
"version": "0.0.0",
"exports": {
"./types": "./src/types.ts"
"./types": "./src/types.ts",
".": "./src/app.ts"
},
"publish": {
"include": ["./src", "./deno.json", "./README.md", "./LICENSE"]
Expand Down Expand Up @@ -31,13 +32,13 @@
}
},
"imports": {
"@std/assert": "jsr:@std/assert@^1.0.5",
"@std/assert": "jsr:@std/assert@^1.0.6",
"@std/async": "jsr:@std/async@^1.0.5",
"@std/fmt": "jsr:@std/fmt@^1.0.2",
"@std/fs": "jsr:@std/fs@^1.0.3",
"@std/fs": "jsr:@std/fs@^1.0.4",
"@std/path": "jsr:@std/path@^1.0.6",
"@std/yaml": "jsr:@std/yaml@^1.0.5",
"@wok/typebox": "jsr:@wok/typebox@^0.33.13",
"@wok/utils": "jsr:@wok/utils@^3.0.0"
"@wok/typebox": "jsr:@wok/typebox@^0.33.15",
"@wok/utils": "jsr:@wok/utils@^3.2.0"
}
}
61 changes: 30 additions & 31 deletions deno.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

82 changes: 30 additions & 52 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,14 @@
let
pkgs = import nixpkgs { inherit system; };
hotPotPkgs = hotPot.packages.${system};
hotPotLib = hotPot.lib.${system};
deno = hotPotPkgs.deno;
# denort = hotPotPkgs.denort;
vscodeSettings = pkgs.writeTextFile {
name = "vscode-settings.json";
text = builtins.toJSON {
"deno.enable" = true;
"deno.lint" = true;
"deno.unstable" = true;
"deno.path" = deno + "/bin/deno";
"deno.path" = hotPotPkgs.deno + "/bin/deno";
"deno.suggest.imports.hosts" = {
"https://deno.land" = false;
};
Expand Down Expand Up @@ -50,58 +48,39 @@
};
runtimeInputs = builtins.attrValues
{
inherit (hotPotPkgs)
deno
;
inherit (pkgs)
kubectl
;
};
jetski =
let
name = "jetski";
src = builtins.path
{
path = ./.;
name = "${name}-src";
filter = with pkgs.lib; (path: /* type */_:
hasInfix "/src" path ||
hasSuffix "/deno.lock" path ||
hasSuffix "/deno.json" path
);
};
deno-cache-dir = pkgs.callPackage hotPotLib.denoAppCache2 {
inherit deno name src;
config-file = ./deno.json;
lock-file = ./deno.lock;
};
transpiled = pkgs.callPackage hotPotLib.denoAppTranspile
{
inherit name deno-cache-dir src;
appSrcPath = "./src/app.ts";
denoRunFlags = ''"''${DENO_RUN_FLAGS[@]}"'';
preExec = ''
DENO_RUN_FLAGS=("-A")
if [ ! -f deno.lock ]; then
DENO_RUN_FLAGS+=("--no-lock")
fi
if [ -f deno.json ]; then
DENO_RUN_FLAGS+=("--config=deno.json")
elif [ -f deno.jsonc ]; then
DENO_RUN_FLAGS+=("--config=deno.jsonc")
fi
'';
allowNpmSpecifiers = true;
};
denoJson = builtins.fromJSON (builtins.readFile ./deno.json);
in
pkgs.runCommandLocal "${name}-wrapped"
{
buildInputs = [ pkgs.makeWrapper ];
}
''
makeWrapper ${transpiled}/bin/jetski $out/bin/jetski \
--set JETSKI_VERSION "${denoJson.version}" \
--prefix PATH : "${pkgs.lib.makeBinPath runtimeInputs}" \
--set-default JETSKI_ENABLE_STACKTRACE "0"
'';
denoJson = builtins.fromJSON (builtins.readFile ./deno.json);
src = builtins.path
{
path = ./.;
name = "jetski-src";
filter = with pkgs.lib; (path: /* type */_:
hasInfix "/src" path ||
hasSuffix "/deno.lock" path ||
hasSuffix "/deno.json" path
);
};
jetski-bin = pkgs.writeShellScript "jetski"
(if denoJson.version == "0.0.0" then ''
deno run -A --check ${src}/src/app.ts "$@"
'' else ''
deno run -A jsr:@wok/jetski@${denoJson.version} "$@"
'');
jetski = pkgs.runCommandLocal "jetski"
{
buildInputs = [ pkgs.makeWrapper ];
}
''
makeWrapper ${jetski-bin} $out/bin/jetski \
--prefix PATH : "${pkgs.lib.makeBinPath runtimeInputs}" \
--set-default JETSKI_ENABLE_STACKTRACE "0"
'';
in
{
devShell = pkgs.mkShellNoCC {
Expand All @@ -110,7 +89,6 @@
cat ${vscodeSettings} > ./.vscode/settings.json
'';
buildInputs = runtimeInputs ++ builtins.attrValues {
inherit deno;
inherit (hotPotPkgs)
typescript-eslint
;
Expand Down
2 changes: 1 addition & 1 deletion src/actions/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ export async function createInstance(instance: InstanceConfig, signal: AbortSign
},
});
} catch (e) {
err("Failed launching", e.toString());
err("Failed launching", e);
return ExitCode.One;
} finally {
await Deno.remove(tempDir, { recursive: true });
Expand Down
3 changes: 2 additions & 1 deletion src/actions/version.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { createCliAction, ExitCode } from "../deps.ts";
import { default as config } from "../../deno.json" with { type: "json" };

export default createCliAction(
{},
() => {
console.log({ app: Deno.env.get("JETSKI_VERSION") ?? "dev", ...Deno.version });
console.log(JSON.stringify({ app: config.version === "0.0.0" ? "dev" : config.version, ...Deno.version }, null, 2));
return Promise.resolve(ExitCode.Zero);
},
);
6 changes: 3 additions & 3 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ try {
await program.run(Deno.args);
} catch (e) {
if (e instanceof NonZeroExitError) {
console.error(bold(red("[Error]")), JSON.stringify(e, null, 2));
console.error(bold(red("[Error]")), e);
} else if (Deno.env.get("JETSKI_ENABLE_STACKTRACE") !== "0") {
console.error(bold(red("[Error]")), e.message, JSON.stringify(e, null, 2));
console.error(bold(red("[Error]")), e);
throw e;
} else {
console.error(bold(red("[Error]")), e.message);
console.error(bold(red("[Error]")), e);
}

Deno.exit(1);
Expand Down
8 changes: 5 additions & 3 deletions src/multipass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ export async function multipassInfo(
const output = (() => {
try {
return JSON.parse(maybeJson);
} catch (e) {
throw new Error(`Failed parsing 'multipass info ...' output to JSON due to: ${e.toString()}. Got: ${maybeJson}`);
} catch (cause) {
throw new Error(`Failed parsing 'multipass info ...' output to JSON. Got: ${maybeJson}`, {
cause,
});
}
})();

Expand Down Expand Up @@ -380,7 +382,7 @@ export async function multipassPostStart(instance: InstanceConfig, abortSignal:
try {
return (await multipassInfo({ name })).state;
} catch (e) {
err("Failed obtaining instance state, will retry in 1s. Reason:", e.message);
err("Failed obtaining instance state, will retry in 1s. Reason:", e);
await delay(1000, { signal: abortSignal });
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,10 @@ export async function createCloudInitConfig(

return result.value;
}
} catch (e) {
throw new Error(`Failed reading join metadata from ${instance.joinMetadataPath}. Reason: ${e.message}`, e);
} catch (cause) {
throw new Error(`Failed reading join metadata from ${instance.joinMetadataPath}`, {
cause,
});
}
})();

Expand Down

0 comments on commit ec38350

Please sign in to comment.