Skip to content

Commit

Permalink
create @primate/go
Browse files Browse the repository at this point in the history
  • Loading branch information
terrablue committed Aug 3, 2024
1 parent 41ed6f8 commit b04fad1
Show file tree
Hide file tree
Showing 21 changed files with 77 additions and 29 deletions.
3 changes: 0 additions & 3 deletions packages/binding/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@
"files": [
"src/**/*.js",
"src/**/*.json",
"src/**/*.go",
"src/**/*.py",
"src/**/*.rb",
"src/**/*.sum",
"src/**/*.mod",
"!src/**/*.spec.js"
],
"repository": {
Expand Down
5 changes: 0 additions & 5 deletions packages/binding/src/server/go/common.js

This file was deleted.

7 changes: 0 additions & 7 deletions packages/binding/src/server/go/default.js

This file was deleted.

3 changes: 0 additions & 3 deletions packages/binding/src/server/go/runtime.js

This file was deleted.

50 changes: 50 additions & 0 deletions packages/go/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"name": "@primate/go",
"version": "0.1.0",
"description": "Primate Go module",
"homepage": "https://primatejs.com/modules/go",
"bugs": "https://github.com/primatejs/primate/issues",
"license": "MIT",
"files": [
"src/**/*.go",
"src/**/*.sum",
"src/**/*.mod",
"src/**/*.js",
"!src/**/*.spec.js"
],
"repository": {
"type": "git",
"url": "https://github.com/primatejs/primate",
"directory": "packages/go"
},
"dependencies": {
"@primate/core": "workspace:^",
"@rcompat/cli": "^0.5.0",
"@rcompat/env": "^0.3.0",
"@rcompat/fs": "^0.4.0",
"@rcompat/invariant": "^0.5.0",
"@rcompat/object": "^0.5.0",
"@rcompat/platform": "^0.3.0",
"@rcompat/stdio": "^0.4.0"
},
"type": "module",
"imports": {
"#*": {
"@primate/lt": "./src/private/*.js",
"default": "./src/private/*.js"
},
"#error/*": {
"@primate/lt": "./src/private/error/*.js",
"default": "./src/private/error/*.js"
}
},
"exports": {
"./to-request": "./src/to-request.js",
"./to-response": "./src/to-response.js",
"./env": "./src/env.js",
".": {
"runtime": "./src/runtime.js",
"default": "./src/default.js"
}
}
}
8 changes: 8 additions & 0 deletions packages/go/src/default.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import build from "#build";
import default_extension from "#extension";
import name from "#name";

export default ({ extension = default_extension } = {}) => ({
name,
build: build({ extension }),
});
1 change: 1 addition & 0 deletions packages/go/src/env.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from "./vendored/wasm_exec.js";
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import faulty_go_route from "#error/faulty-go-route";
import { name } from "@primate/binding/go/common";
import faulty_route from "#error/faulty-route";
import module from "#name";
import log from "@primate/core/log";
import dim from "@rcompat/cli/color/dim";
import { user } from "@rcompat/env";
import file from "@rcompat/fs/file";
import platform from "@rcompat/platform";
import execute from "@rcompat/stdio/execute";
import log from "@primate/core/log";

const module = `@primate/binding/${name}`;
const command = "go";
const run = (wasm, go, includes = "request.go") =>
`${command} build -o ${wasm} ${go} ${includes}`;
Expand All @@ -31,8 +30,9 @@ const make_route = route =>
}`;

const js_wrapper = (path, routes) => `
import to_request from "@primate/binding/go/to-request";
import to_response from "@primate/binding/go/to-response";
import env from "@primate/go/env";
import to_request from "@primate/go/to-request";
import to_response from "@primate/go/to-response";
${
platform === "bun" ? `
import route_path from "${path}" with { type: "file" };
Expand All @@ -43,8 +43,6 @@ ${
.arrayBuffer());
`
}
import { env } from "@primate/binding/go/common";
env();
export default {
Expand Down Expand Up @@ -97,7 +95,7 @@ const create_meta_files = async (directory, app) => {
request: "request.go",
session: "session.go",
};
const has_session = app.modules.names.includes("primate:session");
const has_session = app.modules.names.includes("@primate/session");

if (!await directory.join(meta.mod).exists()) {
const request_struct_items = [];
Expand Down Expand Up @@ -166,7 +164,7 @@ export default ({ extension }) => (app, next) => {
await execute(run(wasm, go, includes.join(" ")),
{ cwd, env: { HOME: user.HOME, ...env } });
} catch (error) {
faulty_go_route(file, error);
faulty_route(file, error);
}
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import module from "#name";
import log from "@primate/core/log";
import file from "@rcompat/fs/file";

export default (...params) => log.error({
params,
name: file(import.meta.url).base,
module: "@primate/binding",
module,
message: "the Go route {0} contains the following error\n {1}",
});
1 change: 1 addition & 0 deletions packages/go/src/private/extension.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default ".go";
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions packages/go/src/private/name.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export default "@primate/go";
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions packages/go/src/runtime.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import name from "#name";

export default () => ({ name });
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions packages/go/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../tsconfig.base.json"
}

0 comments on commit b04fad1

Please sign in to comment.