Skip to content

Commit

Permalink
perf: generate dts files by default (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsherret authored Mar 1, 2024
1 parent 0e4081c commit 84e8a11
Show file tree
Hide file tree
Showing 14 changed files with 203 additions and 186 deletions.
17 changes: 16 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

steps:
- name: clone repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Rust
uses: dsherret/rust-toolchain-file@v1
Expand All @@ -37,8 +37,23 @@ jobs:
if: contains(matrix.os, 'ubuntu')
run: deno fmt --check && cargo fmt -- --check

- name: Check lint
if: contains(matrix.os, 'ubuntu')
run: deno lint && cargo clippy

- name: Check Wasm up-to-date
run: deno task build --check

- name: Test
run: deno task test

- name: Get tag version
if: contains(matrix.os, 'ubuntu') && startsWith(github.ref, 'refs/tags/')
id: get_tag_version
run: echo TAG_VERSION=${GITHUB_REF/refs\/tags\//} >> "$GITHUB_OUTPUT"

- name: Publish
if: contains(matrix.os, 'ubuntu') && startsWith(github.ref, 'refs/tags/')
run: |
deno run -A ./scripts/update_deno_json_version.ts ${{steps.get_tag_version.outputs.TAG_VERSION}}
deno publish
20 changes: 0 additions & 20 deletions .github/workflows/publish.yml

This file was deleted.

2 changes: 1 addition & 1 deletion deno.jsonc → deno.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@deno/wasmbuild",
"version": "0.15.6",
"version": "0.0.0",
"exports": "./main.ts",
"exclude": [
"./tests/target",
Expand Down
12 changes: 10 additions & 2 deletions lib/args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export type LoaderKind = "sync" | "async" | "async-with-cache";

export interface CommonBuild {
outDir: string;
bindingJsFileExt: string;
bindingJsFileExt: "js" | "mjs";
profile: "debug" | "release";
project: string | undefined;
loaderKind: LoaderKind;
Expand Down Expand Up @@ -68,11 +68,19 @@ export function parseArgs(rawArgs: string[]): Command {
: "async-with-cache",
isOpt: !(flags["skip-opt"] ?? flags.debug == "debug"),
outDir: flags.out ?? "./lib",
bindingJsFileExt: flags["js-ext"] ?? `js`,
bindingJsFileExt: getBindingJsFileExt(),
cargoFlags: getCargoFlags(),
};
}

function getBindingJsFileExt() {
const ext: string = flags["js-ext"] ?? `js`;
if (ext !== "js" && ext !== "mjs") {
throw new Error("js-ext must be 'js' or 'mjs'");
}
return ext;
}

function getCargoFlags() {
const cargoFlags = [];

Expand Down
2 changes: 2 additions & 0 deletions lib/bindgen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as path from "@std/path";

export interface BindgenOutput {
js: string;
ts: string;
snippets: Map<string, string[]>;
localModules: Map<string, string>;
wasmBytes: number[];
Expand Down Expand Up @@ -52,6 +53,7 @@ async function generateForSelfBuild(filePath: string): Promise<BindgenOutput> {
);
return {
js: await Deno.readTextFile(path.join(tempPath, "wasmbuild.js")),
ts: await Deno.readTextFile(path.join(tempPath, "wasmbuild.d.ts")),
localModules: new Map(),
snippets: new Map(),
wasmBytes: Array.from(wasmBytes),
Expand Down
6 changes: 4 additions & 2 deletions lib/commands/build_command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ export async function runBuildCommand(args: BuildCommand) {
await ensureDir(args.outDir);
await writeSnippets();

console.log(` write ${colors.yellow(output.bindingJsPath)}`);
await Deno.writeTextFile(output.bindingJsPath, output.bindingJsText);
console.log(` write ${colors.yellow(output.bindingJs.path)}`);
await Deno.writeTextFile(output.bindingJs.path, output.bindingJs.text);
console.log(` write ${colors.yellow(output.bindingDts.path)}`);
await Deno.writeTextFile(output.bindingDts.path, output.bindingDts.text);

if (output.wasmFileName != null) {
const wasmDest = path.join(args.outDir, output.wasmFileName);
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/check_command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export async function runCheckCommand(args: CheckCommand) {
async function getOriginalSourceHash() {
try {
return getSourceHashFromText(
await Deno.readTextFile(output.bindingJsPath),
await Deno.readTextFile(output.bindingJs.path),
);
} catch (err) {
if (err instanceof Deno.errors.NotFound) {
Expand Down
2 changes: 1 addition & 1 deletion lib/loader_text.generated.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2018-2022 the Deno authors. MIT license.
// Copyright 2018-2024 the Deno authors. MIT license.

export const loaderText =
'export async function cacheToLocalDir(url, decompress) {\n\
Expand Down
Loading

0 comments on commit 84e8a11

Please sign in to comment.