Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve module typedefs and loader generation #265

Merged
merged 3 commits into from
Apr 8, 2024

Conversation

jasongin
Copy link
Member

@jasongin jasongin commented Apr 8, 2024

Fixes: #239
Fixes: #260

This has a lot of improvements related to generating the .d.ts and .js files for the .NET node module scenario, including ES and AOT.

  • When generating typedefs for an assembly that includes [JSExport] attributes, export items directly from the module rather than augmenting the node-api-dotnet module. (The augmentation is only when dynamically loading pre-existing assemblies.)
  • Use new template JS code for module-loader scripts that has correct export behavior for modules vs dynamically-loaded assemblies.
  • In MSBuild targets, when publishing AOT, transform the generated module-loader scripts so they load the native binary directly.
  • Add ability for the TS generator to produce both .cjs and .mjs loader scripts, or just one of them (as .js).
  • Add ability for the TS generator to auto-detect the module system (CommonJS vs ES) based on the current project's package.json. This is the new default behavior, hooked up automatically in NodeApi.Generator.targets, and eliminates the need to specify the module type via an MSBuild property in the project most of the time.
  • Improve support for ES default exports in the TS generator.
  • Fix some issues in ModuleGenerator and TypeDefinitionsGenerator related to un-namespaced types. (Does not fully resolve Add full support for types/interfaces/delegates without namespaces #262.)
  • Update the matrix of JS/TS + CommonJS/ESM dynamic-invoke project test cases to use the new capabilities, and add new parallel test cases for "module" projects.
  • Switch some example projects to ES instead of CommonJS module system.
  • Bump version to 0.7.

The overall effect of these changes is that the generated typedefs and loader scripts now work correctly and automatically in many scenarios where they were broken before or required some workarounds to consume.

@jasongin jasongin merged commit 348c8fd into main Apr 8, 2024
24 checks passed
@jasongin jasongin deleted the dev/jasongin/module-ts-gen branch April 8, 2024 20:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants