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

test malloc #6

Open
wants to merge 8 commits into
base: jpg
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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: 1 addition & 1 deletion .github/workflows/core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:

steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Use Deno
uses: denoland/setup-deno@v1
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ on:
jobs:
build:
runs-on: ubuntu-latest
if: 1 == 2 # Disable this job
permissions:
id-token: write # Needed for auth with Deno Deploy
contents: read # Needed to clone the repository
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
os: [ubuntu-latest]

steps:
- name: Checkout repo
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Use Deno
uses: denoland/setup-deno@v1
Expand All @@ -20,7 +20,7 @@ jobs:
run: deno task build

- name: Lint
run: deno lint
run: deno check mod.ts --all --reload

- name: Test
run: deno task test
2 changes: 0 additions & 2 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
src/
tests
logo
docs
.vscode
.github
build.ts

11 changes: 10 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
{
"deno.enable": true,
"deno.lint": true
"deno.lint": true,
"deno.disablePaths": [
"./dist",
"./node_modules",
"./docs",
"./logo",
"./.github/",
"./workers/",
"./.vscode"
]
}
177 changes: 34 additions & 143 deletions build.ts
Original file line number Diff line number Diff line change
@@ -1,169 +1,60 @@
import * as dnt from "https://deno.land/x/[email protected]/mod.ts";
import * as esbuild from "https://deno.land/x/[email protected]/mod.js";
import * as dnt from "https://deno.land/x/[email protected]/mod.ts";
import { copySync } from "https://deno.land/[email protected]/fs/copy.ts";
import { ensureDirSync } from "https://deno.land/[email protected]/fs/ensure_dir.ts";
// import { build } from "https://deno.land/x/[email protected]/mod.js";
import packageInfo from "./package.json" assert { type: "json" };

await dnt.emptyDir("./dist");

//** NPM ES Module for Node.js and Browser */

await dnt.build({
entryPoints: ["./mod.ts"],
outDir: "./dist",
test: false,
esModule: true,
declaration: "inline",
skipNpmInstall: true,
compilerOptions: {
target: "Latest",
skipLibCheck: true,
},
scriptModule: false,
typeCheck: false,
shims: {},
skipSourceOutput: true,
shims: {
webSocket: true,
undici: false,
crypto: true,
},
package: {
...packageInfo,
engines: {
node: ">=14",
},
dependencies: {
"node-fetch": "^3.2.3",
"@peculiar/webcrypto": "^1.4.0",
"ws": "^8.10.0",
},
main: "./esm/mod.js",
type: "module",
...packageInfo
},
});

Deno.copyFileSync("LICENSE", "dist/LICENSE");
Deno.copyFileSync("README.md", "dist/README.md");

// Copy WebAssembly
// Copy WASM Pack files

Deno.copyFileSync(
"src/core/libs/cardano_multiplatform_lib/cardano_multiplatform_lib_bg.wasm",
"dist/esm/src/core/libs/cardano_multiplatform_lib/cardano_multiplatform_lib_bg.wasm",
);
Deno.copyFileSync(
"src/core/libs/cardano_message_signing/cardano_message_signing_bg.wasm",
"dist/esm/src/core/libs/cardano_message_signing/cardano_message_signing_bg.wasm",
);
for (const pkg of ["cardano_message_signing", "cardano_multiplatform_lib"]) {
const files = Deno.readDirSync(`src/core/libs/${pkg}/pkg`);

//** Web ES Module */

const importPathPlugin = {
name: "core-import-path",
setup(build: any) {
build.onResolve({
filter:
/^\.\/libs\/cardano_multiplatform_lib\/cardano_multiplatform_lib.generated.js$/,
}, (args: any) => {
return {
path:
"../esm/src/core/libs/cardano_multiplatform_lib/cardano_multiplatform_lib.generated.js",
external: true,
};
});
build.onResolve({
filter:
/^\.\/libs\/cardano_message_signing\/cardano_message_signing.generated.js$/,
}, (args: any) => {
return {
path:
"../esm/src/core/libs/cardano_message_signing/cardano_message_signing.generated.js",
external: true,
};
});
},
};

await esbuild.build({
bundle: true,
format: "esm",
entryPoints: ["./dist/esm/mod.js"],
outfile: "./dist/web/mod.js",
minify: true,
plugins: [
importPathPlugin,
],
});
esbuild.stop();

/** Add necessary global import statements to NPM ES Module. */
const coreFile = `const isNode = globalThis?.process?.versions?.node;
if (isNode) {
if (typeof btoa === 'undefined') {globalThis.btoa = function (str) {return Buffer.from(str, 'binary').toString('base64');}; globalThis.atob = function (b64Encoded) {return Buffer.from(b64Encoded, 'base64').toString('binary');};}
const fetch = /* #__PURE__ */ await import(/* webpackIgnore: true */ "node-fetch");
const { Crypto } = /* #__PURE__ */ await import(/* webpackIgnore: true */ "@peculiar/webcrypto");
const { WebSocket } = /* #__PURE__ */ await import(/* webpackIgnore: true */ "ws");
const fs = /* #__PURE__ */ await import(/* webpackIgnore: true */ "fs");
if (!globalThis.WebSocket) globalThis.WebSocket = WebSocket;
if (!globalThis.crypto) globalThis.crypto = new Crypto();
if (!globalThis.fetch) globalThis.fetch = fetch.default;
if (!globalThis.Headers) globalThis.Headers = fetch.Headers;
if (!globalThis.Request) globalThis.Request = fetch.Request;
if (!globalThis.Response) globalThis.Response = fetch.Response;
if (!globalThis.fs) globalThis.fs = fs;
}

const C = await (async () => {
try {
if (isNode) {
return await import(
/* webpackIgnore: true */ "./libs/cardano_multiplatform_lib/nodejs/cardano_multiplatform_lib.generated.js"
);
}
return await import(
"./libs/cardano_multiplatform_lib/cardano_multiplatform_lib.generated.js"
);
} catch (_e) {
// This only ever happens during SSR rendering
return null;
}
})();
const M = await (async () => {
try {
if (isNode) {
return await import(
/* webpackIgnore: true */ "./libs/cardano_message_signing/nodejs/cardano_message_signing.generated.js"
for (const file of files) {
if (file.isFile && !file.name.endsWith(".js")) {
copySync(
`src/core/libs/${pkg}/pkg/${file.name}`,
`dist/esm/src/core/libs/${pkg}/pkg/${file.name}`,
{ overwrite: true }
);
}
return await import(
"./libs/cardano_message_signing/cardano_message_signing.generated.js"
);
} catch (_e) {
// This only ever happens during SSR rendering
return null;
}
})();
if (!isNode) {
async function unsafeInstantiate(module) {
try {
await module.instantiate();
} catch (_e) {
// This only ever happens during SSR rendering
}
}
await Promise.all([
unsafeInstantiate(C),
unsafeInstantiate(M),
]);
}
export { C, M };
`;
Deno.writeTextFileSync("dist/esm/src/core/core.js", coreFile);

Deno.mkdirSync("dist/esm/src/core/libs/cardano_message_signing/nodejs");
Deno.mkdirSync("dist/esm/src/core/libs/cardano_multiplatform_lib/nodejs");
const packageJson = JSON.parse(Deno.readTextFileSync(`src/core/libs/${pkg}/pkg/package.json`));
packageJson.type = "commonjs";

Deno.copyFileSync(
"src/core/libs/cardano_message_signing/nodejs/cardano_message_signing.generated.js",
"dist/esm/src/core/libs/cardano_message_signing/nodejs/cardano_message_signing.generated.js",
);
Deno.writeTextFile(
`dist/esm/src/core/libs/${pkg}/pkg/package.json`,
JSON.stringify(packageJson, null, 2),
);
}

Deno.copyFileSync(
"src/core/libs/cardano_multiplatform_lib/nodejs/cardano_multiplatform_lib.generated.js",
"dist/esm/src/core/libs/cardano_multiplatform_lib/nodejs/cardano_multiplatform_lib.generated.js",
);

Deno.writeTextFile(
"dist/esm/src/core/libs/cardano_message_signing/nodejs/package.json",
JSON.stringify({ type: "commonjs" }),
);
Deno.writeTextFile(
"dist/esm/src/core/libs/cardano_multiplatform_lib/nodejs/package.json",
JSON.stringify({ type: "commonjs" }),
);
4 changes: 2 additions & 2 deletions deno.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"tasks": {
"build": "deno run --allow-env --allow-write --allow-read --allow-net --allow-run build.ts",
"build:core": "cd src/core/libs/cardano_multiplatform_lib && deno run -A https://raw.githubusercontent.com/spacebudz/wasmbuild/a0fec73985b0f0a9120b5077e292963d513795d4/main.ts --out ./; cd ../cardano_message_signing && deno run -A https://raw.githubusercontent.com/spacebudz/wasmbuild/a0fec73985b0f0a9120b5077e292963d513795d4/main.ts --out ./",
"build": "NODE_ENV=production deno run --allow-env --allow-write --allow-read --allow-net --allow-run build.ts",
"build:core": "npm run pack -- src/core/libs/cardano_multiplatform_lib; npm run pack -- src/core/libs/cardano_message_signing",
"publish": "deno task build && deno task test && npm publish dist",
"test": "deno test --allow-env --allow-read --allow-net tests",
"test:core": "cd src/core/libs/cardano_multiplatform_lib && cargo test; cd ../cardano_message_signing && cargo test"
Expand Down
Loading