Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
afinch7 committed Jun 30, 2019
1 parent 908a885 commit 8c4b70f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
50 changes: 23 additions & 27 deletions cargo/mod.ts
Expand Up @@ -41,12 +41,12 @@ export interface CargoBuildResData {
}

export interface CargoBuildResError {
message: string;
message: string;
}

export interface CargoBuildRes {
data?: CargoBuildResData;
error?: CargoBuildResError;
data?: CargoBuildResData;
error?: CargoBuildResError;
}

// TODO(afinch7) make DENO_CARGO_PLUGIN_PATH optional once we can load plugins via url
Expand All @@ -58,30 +58,26 @@ const textEncoder = new TextEncoder();
const textDecoder = new TextDecoder();

export function build(opts: CargoBuildOptions): CargoBuildResData {
const response = cargoBuildOp.dispatch(
textEncoder.encode(
JSON.stringify({
...defaultCargoBuildOptions,
...opts
})
)
);
if (response instanceof Uint8Array) {
const result: CargoBuildRes = JSON.parse(
textDecoder.decode(
response,
)
);
if (result.error) {
throw new Error(result.error.message);
} else {
if (result.data) {
return result.data;
} else {
throw new Error("Unexpected empty data field in response");
}
}
const response = cargoBuildOp.dispatch(
textEncoder.encode(
JSON.stringify({
...defaultCargoBuildOptions,
...opts
})
)
);
if (response instanceof Uint8Array) {
const result: CargoBuildRes = JSON.parse(textDecoder.decode(response));
if (result.error) {
throw new Error(result.error.message);
} else {
throw new Error(`Unexpected response type ${typeof response}`);
if (result.data) {
return result.data;
} else {
throw new Error("Unexpected empty data field in response");
}
}
} else {
throw new Error(`Unexpected response type ${typeof response}`);
}
}
5 changes: 4 additions & 1 deletion cargo/test_plugin/mod.ts
Expand Up @@ -9,6 +9,9 @@ const buildResult = build({
});
// We could also search through the artifacts list here to find something more specific if we wanted.
const plugin = openPlugin(
join(buildResult.output_root, pluginFilename(buildResult.artifacts[0].output_name))
join(
buildResult.output_root,
pluginFilename(buildResult.artifacts[0].output_name)
)
);
export const testOp = plugin.loadOp("test_op");

0 comments on commit 8c4b70f

Please sign in to comment.