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

Node 16 support #47

Merged
merged 4 commits into from
Apr 2, 2024
Merged
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
4 changes: 3 additions & 1 deletion .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ jobs:

strategy:
matrix:
node-version: ["18.17.1"]
node-version:
- "16.18.1"
- "18.17.1"
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
122 changes: 115 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,24 @@
"license": "MIT",
"types": "./dist/index.d.ts",
"exports": {
"node": {
"types": "./dist/nodejs/index.d.ts",
"import": "./dist/nodejs/index.js",
"require": "./dist/nodejs/index.cjs"
},
"types": "./dist/index.d.ts",
"import": "./dist/index.js",
"require": "./dist/index.cjs",
"types": "./dist/index.d.ts"
"require": "./dist/index.cjs"
},
"devDependencies": {
"@types/node": "^20.11.25",
"prettier": "^3.1.1",
"ts-node": "^10.9.2",
"tsup": "^8.0.1",
"typescript": "^5.3.3",
"vite-tsconfig-paths": "^4.2.2",
"vitest": "^1.0.4"
},
"dependencies": {
"node-fetch": "^3.3.2"
}
}
3 changes: 3 additions & 0 deletions src/nodejs/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// entrypoint for nodejs build
import "substrate/nodejs/polyfill";
export * from "..";
16 changes: 16 additions & 0 deletions src/nodejs/polyfill.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* While we're generally aiming to support ES2022 and Node 18+ we're also including
* polyfill code for now for some of the Standard Web APIs that we use in this SDK.
*/
import fetch, { Headers, Request, Response } from "node-fetch";

if (!globalThis.fetch) {
// @ts-ignore
globalThis.fetch = fetch;
// @ts-ignore
globalThis.Headers = Headers;
// @ts-ignore
globalThis.Request = Request;
// @ts-ignore
globalThis.Response = Response;
}
2 changes: 2 additions & 0 deletions tests/Future.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import "substrate/nodejs/polyfill";

import { expect, describe, test } from "vitest";
import {
Future,
Expand Down
4 changes: 2 additions & 2 deletions tests/Node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ describe("Node", () => {
});

test(".toJSON", () => {
const a = new FutureString(new Trace([], ""));
const b = new FutureString(new Trace([], ""));
const a = new FutureString(new Trace([], new FooNode({})));
const b = new FutureString(new Trace([], new FooNode({})));
const c = new FutureString(new StringConcat([a, b]));
const d = new FutureString(new StringConcat([c, "d"]));
const n = new FooNode({ prompt: d });
Expand Down
24 changes: 17 additions & 7 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
/* Visit https://aka.ms/tsconfig to read more about this file */

/* Language and Environment */
"target": "es2022" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
// "lib": [], /* Specify a set of bundled library declaration files that describe the target runtime environment. */
"target": "es2020" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,

/* Modules */
"module": "es2022" /* Specify what module code is generated. */,
"moduleResolution": "bundler" /* Specify how TypeScript looks up a file from a given module specifier. */,
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
"module": "commonjs" /* Specify what module code is generated. */,
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,
"resolveJsonModule": true,
"esModuleInterop": true,

/* Emit */
"declaration": true /* Generate .d.ts files from TypeScript and JavaScript files in your project. */,
Expand Down Expand Up @@ -50,8 +50,18 @@
}
},

/* Internal-use: running example scripts */
/**
* Internal-use: running example scripts
* We're mostly developing on es2022/Node 18+, but to extend that support a bit futher
* back our main compiler options are overridden when running with ts-node to use newer
* syntax, eg. top-level await.
*/
"ts-node": {
"esm": true
"esm": true,
"compilerOptions": {
"target": "es2022",
"module": "es2022",
"moduleResolution": "bundler"
}
}
}
2 changes: 1 addition & 1 deletion tsup.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineConfig } from "tsup";

export default defineConfig({
entry: ["src/index.ts"],
entry: ["src/index.ts", "src/nodejs/index.ts"],
format: ["cjs", "esm"],
dts: true,
keepNames: true,
Expand Down
Loading