Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
0607cb6
bump
elringus Jan 6, 2024
d80b0e6
etc
elringus Jan 6, 2024
df9a344
iteration
elringus Jan 6, 2024
1059829
iteration
elringus Jan 7, 2024
98e47ca
iteration
elringus Jan 7, 2024
f61c62f
iteration
elringus Jan 7, 2024
8bf4e01
remove source gen
elringus Jan 7, 2024
0e00e5d
etc
elringus Jan 7, 2024
327bb7a
iteration
elringus Jan 7, 2024
6447a75
fix docs last update
elringus Jan 9, 2024
a3e55bc
iteration
elringus Jan 9, 2024
d4d2016
etc
elringus Jan 9, 2024
daa6f95
iteration
elringus Jan 10, 2024
e383cdf
iteration
elringus Jan 10, 2024
0bd9480
iteration
elringus Jan 11, 2024
0883d35
iteration
elringus Jan 11, 2024
02e8969
iteration
elringus Jan 12, 2024
ed21203
iteration
elringus Jan 12, 2024
26fdf63
iteration
elringus Jan 13, 2024
8674e8b
etc
elringus Jan 13, 2024
81ee7a2
etc
elringus Jan 13, 2024
a1a0921
iteration
elringus Jan 13, 2024
9bb118f
etc
elringus Jan 13, 2024
6d72138
iteration
elringus Jan 14, 2024
95348c2
iteration
elringus Jan 14, 2024
66a0555
iteration
elringus Jan 14, 2024
938187d
iteration
elringus Jan 14, 2024
401c093
iteration
elringus Jan 15, 2024
edbfbbf
etc
elringus Jan 15, 2024
a66c1cc
etc
elringus Jan 15, 2024
9bb73ea
etc
elringus Jan 15, 2024
7d294ce
iteration
elringus Jan 15, 2024
367b048
iteration
elringus Jan 16, 2024
d3cb36c
iteration
elringus Jan 16, 2024
0208c4f
iteration
elringus Jan 16, 2024
32fa4b4
iteration
elringus Jan 16, 2024
3358f38
etc
elringus Jan 16, 2024
dc1961c
iteration
elringus Jan 16, 2024
e934367
etc
elringus Jan 16, 2024
632c098
etc
elringus Jan 16, 2024
88b8d60
iteration
elringus Jan 17, 2024
05bae60
return of the generator
elringus Jan 18, 2024
5c20435
iteration
elringus Jan 18, 2024
2fabfa0
etc
elringus Jan 18, 2024
23a5cf7
etc
elringus Jan 18, 2024
ee0343b
iteration
elringus Jan 18, 2024
e83d4fd
iteration
elringus Jan 18, 2024
2069b0c
etc
elringus Jan 18, 2024
89fd742
iteration
elringus Jan 18, 2024
fe82b57
iteration
elringus Jan 18, 2024
96a6f4c
etc
elringus Jan 18, 2024
55f0972
iteration
elringus Jan 19, 2024
057880c
iteration
elringus Jan 19, 2024
1d91f0d
pack
elringus Jan 19, 2024
ba7c12e
iteration
elringus Jan 19, 2024
759d0ae
iteration
elringus Jan 19, 2024
14063c4
iteration
elringus Jan 19, 2024
d43efb3
iteration
elringus Jan 20, 2024
f2dd7ec
iteration
elringus Jan 20, 2024
d50c90d
sharping
elringus Jan 20, 2024
09c5d77
iteration
elringus Jan 20, 2024
5a76fab
iteration
elringus Jan 20, 2024
192acec
etc
elringus Jan 20, 2024
87a80d8
etc
elringus Jan 20, 2024
c6c2af1
sharping
elringus Jan 20, 2024
5b7fa52
iteration
elringus Jan 20, 2024
f6d4490
sigh
elringus Jan 21, 2024
4d841bd
iteration
elringus Jan 22, 2024
40a48d7
fix gen
elringus Jan 22, 2024
c0af39c
fix dup
elringus Jan 22, 2024
1c74176
etc
elringus Jan 22, 2024
98ec42a
testing
elringus Jan 23, 2024
77b692d
fix inspect
elringus Jan 23, 2024
ad0c4b4
fix inspection
elringus Jan 23, 2024
0e15293
bump ver
elringus Jan 23, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 2 .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ jobs:
name: github-pages
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-node@v3
- name: build
run: |
Expand Down
8 changes: 4 additions & 4 deletions 8 samples/minimal/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ <h1 id="msg">Loading...</h1>
<script type="module">

// Named exports are auto-generated on C# build.
import bootsharp, { Global } from './cs/bin/bootsharp/bootsharp.mjs';
import bootsharp, { Program } from './cs/bin/bootsharp/index.mjs';

// Binding 'Program.GetFrontendName' endpoint invoked in C#.
Global.getFrontendName = () => "Browser";
Program.getFrontendName = () => "Browser";

// Subscribing to 'Program.OnMainInvoked' C# event.
Global.onMainInvoked.subscribe(console.log);
Program.onMainInvoked.subscribe(console.log);

// Initializing dotnet runtime and invoking entry point.
await bootsharp.boot();

// Invoking 'Program.GetBackendName' C# method.
document.getElementById("msg").innerHTML = `Hello ${Global.getBackendName()}!`;
document.getElementById("msg").innerHTML = `Hello ${Program.getBackendName()}!`;

</script>
8 changes: 4 additions & 4 deletions 8 samples/minimal/main.mjs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// Named exports are auto-generated on C# build.
import bootsharp, { Global } from "./cs/bin/bootsharp/bootsharp.mjs";
import bootsharp, { Program } from "./cs/bin/bootsharp/index.mjs";

// Binding 'Program.GetFrontendName' endpoint invoked in C#.
Global.getFrontendName = () =>
Program.getFrontendName = () =>
typeof Bun === "object" ? `Bun ${Bun.version}` :
typeof Deno === "object" ? `Deno ${Deno.version.deno}` :
typeof process === "object" ? `Node ${process.version}` :
"Unknown JavaScript Runtime";

// Subscribing to 'Program.OnMainInvoked' C# event.
Global.onMainInvoked.subscribe(console.log);
Program.onMainInvoked.subscribe(console.log);

// Initializing dotnet runtime and invoking entry point.
await bootsharp.boot();

// Invoking 'Program.GetBackendName' C# method.
console.log(`Hello ${Global.getBackendName()}!`);
console.log(`Hello ${Program.getBackendName()}!`);
3 changes: 2 additions & 1 deletion 3 samples/react/backend/Backend.WASM/Backend.WASM.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<RuntimeIdentifier>browser-wasm</RuntimeIdentifier>
<ImplicitUsings>enable</ImplicitUsings>
<!-- Specify custom name for the generated JavaScript module. -->
<BootsharpName>backend</BootsharpName>
<!-- Publish module's package.json file under solution folder for accessibility. -->
<!-- Publish module's package.json file under solution folder. -->
<BootsharpPackageDirectory>$(SolutionDir)</BootsharpPackageDirectory>
<!-- Don't embed the C# solution binaries to the JavaScript module. -->
<BootsharpEmbedBinaries>false</BootsharpEmbedBinaries>
Expand Down
12 changes: 5 additions & 7 deletions 12 samples/react/backend/Backend.WASM/Program.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using Backend;
using Backend.Prime;
using Bootsharp;
using Bootsharp.Inject;
using Microsoft.Extensions.DependencyInjection;
Expand All @@ -10,15 +8,15 @@
// and can be shared with other build targets (console, MAUI, etc).

// Generate C# -> JavaScript interop handlers for specified contracts.
[assembly: JSExport(typeof(IComputer))]
[assembly: JSExport(typeof(Backend.IComputer))]
// Generate JavaScript -> C# interop handlers for specified contracts.
[assembly: JSImport(typeof(IPrimeUI))]
// Group all generated JavaScript artifacts under 'Computer' namespace.
[assembly: JSNamespace("^.*$", "Computer")]
[assembly: JSImport(typeof(Backend.Prime.IPrimeUI))]
// Group all generated JavaScript APIs under "Computer" namespace.
[assembly: JSPreferences(Space = [".+", "Computer"])]

// Perform dependency injection.
new ServiceCollection()
.AddSingleton<IComputer, Prime>() // use prime computer
.AddSingleton<Backend.IComputer, Backend.Prime.Prime>() // use prime computer
.AddBootsharp() // inject generated interop handlers
.BuildServiceProvider()
.RunBootsharp(); // initialize interop services
5 changes: 3 additions & 2 deletions 5 samples/react/backend/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "backend",
"main": "Backend.WASM/bin/backend/backend.mjs",
"types": "Backend.WASM/bin/backend/types/backend.d.ts"
"type": "module",
"main": "Backend.WASM/bin/backend/index.mjs",
"types": "Backend.WASM/bin/backend/types/index.d.ts"
}
12 changes: 6 additions & 6 deletions 12 samples/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
},
"devDependencies": {
"typescript": "^5.3.3",
"@types/react": "^18.2.46",
"@types/react": "^18.2.48",
"@types/react-dom": "^18.2.18",
"vite": "^5.0.10",
"vite": "^5.0.12",
"@vitejs/plugin-react-swc": "^3.5.0",
"vitest": "^1.1.1",
"@vitest/coverage-v8": "^1.1.1",
"happy-dom": "^12.10.3",
"vitest": "^1.2.1",
"@vitest/coverage-v8": "^1.2.1",
"happy-dom": "^13.2.0",
"@testing-library/react": "^14.1.2",
"@testing-library/user-event": "^14.5.2",
"eslint": "^8.56.0",
"eslint-plugin-react": "^7.33.2",
"eslint-plugin-react-hooks": "^4.6.0",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/eslint-plugin": "^6.19.0",
"npm-check-updates": "^16.14.12"
},
"scripts": {
Expand Down
4 changes: 2 additions & 2 deletions 4 samples/trimming/main.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import bootsharp, { Global } from "./cs/bin/bootsharp/bootsharp.mjs";
import bootsharp, { Program } from "./cs/bin/bootsharp/index.mjs";
import zlib from "node:zlib";
import util from "node:util";
import fs from "node:fs/promises";
Expand All @@ -12,7 +12,7 @@ await Promise.all([
...resources.assemblies.map(fetchBro)
]);

Global.log = console.log;
Program.log = console.log;
await bootsharp.boot({ root: "./bin", resources });

async function measure(dir) {
Expand Down
6 changes: 3 additions & 3 deletions 6 samples/vscode/src/extension.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as vscode from "vscode";
import bootsharp, { Global } from "../../Minimal/cs/bin/bootsharp/bootsharp.mjs";
import bootsharp, { Program } from "../../Minimal/cs/bin/bootsharp/index.mjs";

export async function activate(context) {
Global.getFrontendName = () => "VS Code";
Program.getFrontendName = () => "VS Code";
try { await bootsharp.boot(); }
catch (e) { vscode.window.showErrorMessage(e.message); }
const command = vscode.commands.registerCommand("bootsharp.hello", greet);
Expand All @@ -14,6 +14,6 @@ export function deactivate() {
}

function greet() {
const message = `Welcome, ${Global.getBackendName()}! Enjoy your VS Code extension space.`;
const message = `Welcome, ${Program.getBackendName()}! Enjoy your VS Code extension space.`;
vscode.window.showInformationMessage(message);
}
25 changes: 0 additions & 25 deletions 25 src/cs/Bootsharp.Common.Test/BindingTest.cs

This file was deleted.

5 changes: 1 addition & 4 deletions 5 src/cs/Bootsharp.Common.Test/Bootsharp.Common.Test.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.8.0"/>
<PackageReference Include="xunit" Version="2.6.4"/>
<PackageReference Include="xunit" Version="2.6.6"/>
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.6">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
Expand All @@ -29,9 +29,6 @@

<ItemGroup>
<ProjectReference Include="../Bootsharp.Common/Bootsharp.Common.csproj"/>
<ProjectReference Include="../Bootsharp.Generate/Bootsharp.Generate.csproj"
PrivateAssets="all" ReferenceOutputAssembly="false"
OutputItemType="Analyzer" SetTargetFramework="TargetFramework=netstandard2.0"/>
</ItemGroup>

</Project>
28 changes: 28 additions & 0 deletions 28 src/cs/Bootsharp.Common.Test/InterfacesTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Bootsharp.Common.Test;

public class InterfacesTest
{
[Fact]
public void Records ()
{
// TODO: Remove once coverlet properly handles record coverage.
_ = new ExportInterface(default, default) with { Interface = typeof(int) };
_ = new ImportInterface(default) with { Instance = "" };
}

[Fact]
public void RegistersExports ()
{
var export = new ExportInterface(typeof(IBackend), default);
Interfaces.Register(typeof(Backend), export);
Assert.Equal(typeof(IBackend), Interfaces.Exports[typeof(Backend)].Interface);
}

[Fact]
public void RegistersImports ()
{
var import = new ImportInterface(new Frontend());
Interfaces.Register(typeof(IFrontend), import);
Assert.IsType<Frontend>(Interfaces.Imports[typeof(IFrontend)].Instance);
}
}
35 changes: 0 additions & 35 deletions 35 src/cs/Bootsharp.Common.Test/NamespaceTest.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
using static Bootsharp.Function;
using static Bootsharp.Proxies;

namespace Bootsharp.Common.Test;

public class FunctionTest
public class ProxiesTest
{
[Fact]
public void WhenEndpointNotFoundErrorIsThrown ()
{
Assert.Contains("Endpoint 'foo' is not found.",
Assert.Contains("Proxy 'foo' is not found.",
Assert.Throws<Error>(() => Get<Action>("foo")).Message);
}

[Fact]
public void WhenFunctionTypeIsWrongErrorIsThrown ()
{
Set("bar", null);
Assert.Contains("Endpoint 'bar' is not 'System.Action'.",
Assert.Contains("Proxy 'bar' is not 'System.Action'.",
Assert.Throws<Error>(() => Get<Action>("bar")).Message);
}

Expand Down
55 changes: 3 additions & 52 deletions 55 src/cs/Bootsharp.Common.Test/TypesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,8 @@
using Bootsharp;
using Bootsharp.Common.Test;

[assembly: JSExport(
typeof(IBackend),
NamePattern = "ExportNamePattern",
NameReplacement = "ExportNameReplacement",
InvokePattern = "ExportInvokePattern",
InvokeReplacement = "ExportInvokeReplacement"
)]

[assembly: JSImport(
typeof(IFrontend),
NamePattern = "ImportNamePattern",
NameReplacement = "ImportNameReplacement",
InvokePattern = "ImportInvokePattern",
InvokeReplacement = "ImportInvokeReplacement",
EventPattern = "ImportEventPattern",
EventReplacement = "ImportEventReplacement"
)]
[assembly: JSExport(typeof(IBackend))]
[assembly: JSImport(typeof(IFrontend))]

namespace Bootsharp.Common.Test;

Expand All @@ -31,11 +16,6 @@ public class TypesTest
public void Records ()
{
// TODO: Remove when coverlet bug is resolved: https://github.com/coverlet-coverage/coverlet/issues/1561
_ = new SolutionMeta { Assemblies = [], Methods = [], Types = [] } with { Assemblies = default };
_ = new AssemblyMeta { Name = "", Bytes = [] } with { Name = "foo" };
_ = new MethodMeta { Name = "", JSName = "", Arguments = default, Assembly = "", Type = default, Space = "", JSSpace = "", ReturnValue = default } with { Assembly = "foo" };
_ = new ArgumentMeta { Name = "", JSName = "", Value = default } with { Name = "foo" };
_ = new ValueMeta { Type = default, Nullable = true, TypeSyntax = "", Void = true, Serialized = true, Async = true, JSTypeSyntax = "" } with { TypeSyntax = "foo" };
_ = new MockItem("") with { Id = "foo" };
_ = new MockItemWithEnum(default) with { Enum = MockEnum.Bar };
_ = new MockRecord(default) with { Items = new[] { new MockItem("") } };
Expand All @@ -46,52 +26,23 @@ public void TypesAreAssigned ()
{
Assert.Equal([typeof(IBackend)], new JSExportAttribute(typeof(IBackend)).Types);
Assert.Equal([typeof(IFrontend)], new JSImportAttribute(typeof(IFrontend)).Types);
}

[Fact]
public void NameAndInvokeParametersAreNullByDefault ()
{
var attribute = new JSExportAttribute(typeof(IBackend));
Assert.Null(attribute.NamePattern);
Assert.Null(attribute.NameReplacement);
Assert.Null(attribute.InvokePattern);
Assert.Null(attribute.InvokeReplacement);
}

[Fact]
public void EventParametersAreNullByDefault () // (defaults are in generator)
{
var attribute = new JSImportAttribute(typeof(IBackend));
Assert.Null(attribute.EventPattern);
Assert.Null(attribute.EventReplacement);
Assert.Equal("Space", (new JSPreferencesAttribute { Space = ["Space"] }).Space[0]);
}

[Fact]
public void ExportParametersEqualArguments ()
{
Assert.Equal([typeof(IBackend)],
(export.ConstructorArguments[0].Value as IReadOnlyCollection<CustomAttributeTypedArgument>).Select(a => a.Value));
Assert.Equal("ExportNamePattern", GetNamedValue(export.NamedArguments, nameof(JSTypeAttribute.NamePattern)));
Assert.Equal("ExportNameReplacement", GetNamedValue(export.NamedArguments, nameof(JSTypeAttribute.NameReplacement)));
Assert.Equal("ExportInvokePattern", GetNamedValue(export.NamedArguments, nameof(JSTypeAttribute.InvokePattern)));
Assert.Equal("ExportInvokeReplacement", GetNamedValue(export.NamedArguments, nameof(JSTypeAttribute.InvokeReplacement)));
}

[Fact]
public void ImportParametersEqualArguments ()
{
Assert.Equal([typeof(IFrontend)],
(import.ConstructorArguments[0].Value as IReadOnlyCollection<CustomAttributeTypedArgument>).Select(a => a.Value));
Assert.Equal("ImportNamePattern", GetNamedValue(import.NamedArguments, nameof(JSTypeAttribute.NamePattern)));
Assert.Equal("ImportNameReplacement", GetNamedValue(import.NamedArguments, nameof(JSTypeAttribute.NameReplacement)));
Assert.Equal("ImportInvokePattern", GetNamedValue(import.NamedArguments, nameof(JSTypeAttribute.InvokePattern)));
Assert.Equal("ImportInvokeReplacement", GetNamedValue(import.NamedArguments, nameof(JSTypeAttribute.InvokeReplacement)));
Assert.Equal("ImportEventPattern", GetNamedValue(import.NamedArguments, nameof(JSImportAttribute.EventPattern)));
Assert.Equal("ImportEventReplacement", GetNamedValue(import.NamedArguments, nameof(JSImportAttribute.EventReplacement)));
}

private static object GetNamedValue (IList<CustomAttributeNamedArgument> args, string key) =>
args.First(a => a.MemberName == key).TypedValue.Value;
private static CustomAttributeData GetMockExportAttribute () =>
typeof(TypesTest).Assembly.CustomAttributes
.First(a => a.AttributeType == typeof(JSExportAttribute));
Expand Down
2 changes: 1 addition & 1 deletion 2 src/cs/Bootsharp.Common/Attributes/JSEventAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/// <example>
/// <code>
/// [JSEvent]
/// public static partial string OnSomethingHappened (string payload);
/// public static partial void OnSomethingHappened (string payload);
/// Namespace.onSomethingHappened.subscribe(payload => ...);
/// </code>
/// </example>
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.