Skip to content

Commit

Permalink
NuGet and npm packaging (microsoft#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasongin authored Mar 7, 2023
1 parent aef261c commit d1b4644
Show file tree
Hide file tree
Showing 47 changed files with 790 additions and 327 deletions.
19 changes: 13 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0 # Deep clone is required for versioning on git commit height

- name: Setup .NET ${{ matrix.dotnet-version }}
uses: actions/setup-dotnet@v3
Expand All @@ -40,21 +42,26 @@ jobs:
node-version: ${{ matrix.node-version }}

- name: Build
run: dotnet build --configuration Release

- name: pack
run: dotnet pack --no-build --configuration Release
run: dotnet pack --configuration Release

# Uncomment to enable an SSH session for debugging
# - name: Setup tmate session
# uses: mxschmitt/action-tmate@v3
# with:
# limit-access-to-actor: true

- name: Upload build artifacts
uses: actions/upload-artifact@v3
with:
name: ${{ runner.os }}-dotnet${{ matrix.dotnet-version }}-packages
path: |
out/pkg/*.nupkg
out/pkg/*.tgz
- name: Test
env:
NODE_API_DOTNET_TRACE: 1
run: dotnet test --no-build --configuration Release --logger trx --results-directory "test-${{ matrix.dotnet-version }}-node${{ matrix.node-version }}"
TRACE_NODE_API_HOST: 1
run: dotnet test --configuration Release --logger trx --results-directory "test-${{ matrix.dotnet-version }}-node${{ matrix.node-version }}"

- name: Upload test logs
uses: actions/upload-artifact@v3
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/out/
bin/
obj/

*.suo
*.user

.vs/

node_modules/
examples/**/package-lock.json

/src/**/*.xml

*.log
*.binlog
7 changes: 6 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
{
// Don't show the "Required assets are missing..." dialog on startup. We'll manage tasks.json / launch.json manually.
"csharp.suppressBuildAssetsNotification": true
"csharp.suppressBuildAssetsNotification": true,

// We try to limit the length of code lines to 100 columns.
"editor.rulers": [
100,
]
}
43 changes: 20 additions & 23 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
<Project>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<SelfContained Condition="'$(RuntimeIdentifier)' != ''">true</SelfContained>
<Configuration Condition="'$(Configuration)'==''">Debug</Configuration>
<BaseOutputPath>$(MSBuildThisFileDirectory)out/</BaseOutputPath>
<OutputPath>$(BaseOutputPath)bin/$(Configuration)/$(MSBuildProjectName)/</OutputPath>
<PackageOutputPath>$(BaseOutputPath)pkg/</PackageOutputPath>
<SymbolsOutputPath>$(BaseOutputPath)sym/</SymbolsOutputPath>
<BaseIntermediateOutputPath>$(BaseOutputPath)obj/$(Configuration)/$(MSBuildProjectName)/</BaseIntermediateOutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
<IsPackable>false</IsPackable>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<Configuration Condition="'$(Configuration)'==''">Debug</Configuration>
<BaseOutputPath>$(MSBuildThisFileDirectory)out/</BaseOutputPath>
<OutputPath>$(BaseOutputPath)bin/$(Configuration)/$(MSBuildProjectName)/</OutputPath>
<PackageOutputPath>$(BaseOutputPath)pkg/</PackageOutputPath>
<SymbolsOutputPath>$(BaseOutputPath)sym/</SymbolsOutputPath>
<BaseIntermediateOutputPath>$(BaseOutputPath)obj/$(Configuration)/$(MSBuildProjectName)/</BaseIntermediateOutputPath>
<IntermediateOutputPath>$(BaseIntermediateOutputPath)</IntermediateOutputPath>
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
<IsPackable>false</IsPackable>

<ItemGroup>
<CompilerVisibleProperty Include="BaseIntermediateOutputPath" /><!-- Used by NodeApi source generator. -->
<CompilerVisibleProperty Include="TargetPath" /><!-- Used by NodeApi TS source generator. -->
</ItemGroup>
<!-- Display each test case and passed/failed status when using `dotnet test`. -->
<VSTestLogger Condition="'$(VSTestLogger)' == ''">console%3Bverbosity=normal</VSTestLogger>
</PropertyGroup>

<ItemGroup>
<!--
<PackageReference Include="Nerdbank.GitVersioning" PrivateAssets="All" />
-->
</ItemGroup>
<ItemGroup>
<PackageReference Include="Nerdbank.GitVersioning" PrivateAssets="none" />
</ItemGroup>

<Import Project="./rid.props" />
</Project>
9 changes: 9 additions & 0 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>
<!-- Clean the local cache when building a package so local projects always get the new content. -->
<Target Name="CleanLocalPackageCache"
AfterTargets="Pack"
Condition=" '$(PackageId)' != '' AND '$(PackageOutputPath)' != '' "
>
<RemoveDir Directories="$(PackageOutputPath)$(PackageId)" />
</Target>
</Project>
30 changes: 23 additions & 7 deletions README-DEV.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
dotnet build
```

While developing the source generator, set `DOTNET_CLI_USE_MSBUILD_SERVER=0` to prevent MSBuild from re-using a previously-loaded (possibly outdated) version of the source generator assembly. (See [Shut down or disable MSBuild Server](https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-server?view=vs-2022#shut-down-or-disable-msbuild-server).)
While developing the source generator, set `DOTNET_CLI_USE_MSBUILD_SERVER=0` to prevent MSBuild
from re-using a previously-loaded (possibly outdated) version of the source generator assembly.
(See [Shut down or disable MSBuild Server](https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-server?view=vs-2022#shut-down-or-disable-msbuild-server).)

## Build Packages
```bash
dotnet pack
```
This produces both nuget and npm packages (for the current platform only) in the `out/pkg`
directory.

## Test
```bash
Expand All @@ -14,18 +23,25 @@ dotnet test

Or to run a subset of test cases that match a filter:
```bash
dotnet test --filter "DisplayName~hello"
dotnet test --filter "DisplayName~aot"
```

The list of test cases is automatically derived from the set of `.js` files under the `Test/TestCases` directory. Within each subdirectory there, all `.cs` files are compiled into one assembly, then all `.js` test files execute against the assembly.
The list of test cases is automatically derived from the set of `.js` files under the
`Test/TestCases` directory. Within each subdirectory there, all `.cs` files are compiled into one
assembly, then all `.js` test files execute against the assembly.

Most test cases run twice, once for "hosted" CLR mode and once for AOT ahead-of-time compiled mode with no CLR.
Most test cases run twice, once for "hosted" CLR mode and once for AOT ahead-of-time compiled mode
with no CLR.

## Debugging
With a debug build, the following environment variables trigger just-in-time debugging of the respective components:
With a debug build, the following environment variables trigger just-in-time debugging of the
respective components:
- `DEBUG_NODE_API_GENERATOR` - Debug the C# source-generator when it runs during the build.
- `DEBUG_NODE_API_RUNTIME` - Debug the .NET runtime host when it is loaded by JavaScript. (Does not apply to AOT-compiled modules.)
- `DEBUG_NODE_API_RUNTIME` - Debug the .NET runtime host when it is loaded by JavaScript. (Does
not apply to AOT-compiled modules.)

## Roadmap
Also `TRACE_NODE_API_HOST` causes tracing information to be printed about the the process of
loading the .NET host.

## Roadmap
[node-api-dotnet tasks](https://github.com/users/jasongin/projects/1/views/1)
Loading

0 comments on commit d1b4644

Please sign in to comment.