Skip to content

Commit bd25dee

Browse files
Add format check in GHA script (#44)
* Update formatting (`prettier --write`) * Update rest of files (prettier) * Update Makefile (add tasks for prettier) * Add format-check step in CI * Update Makefile, add comments * updates gha formatting
1 parent 3d5e287 commit bd25dee

13 files changed

+802
-512
lines changed

.github/workflows/node.js.yml

+12-12
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ name: Node.js CI
55

66
on:
77
push:
8-
branches: [ "main" ]
8+
branches: ["main"]
99
pull_request:
10-
branches: [ "main" ]
10+
branches: ["main"]
1111

1212
jobs:
1313
build:
14-
1514
runs-on: ubuntu-latest
1615

1716
strategy:
@@ -20,12 +19,13 @@ jobs:
2019
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
2120

2221
steps:
23-
- uses: actions/checkout@v3
24-
- name: Use Node.js ${{ matrix.node-version }}
25-
uses: actions/setup-node@v3
26-
with:
27-
node-version: ${{ matrix.node-version }}
28-
cache: 'npm'
29-
- run: npm ci
30-
- run: make build
31-
- run: make test
22+
- uses: actions/checkout@v3
23+
- name: Use Node.js ${{ matrix.node-version }}
24+
uses: actions/setup-node@v3
25+
with:
26+
node-version: ${{ matrix.node-version }}
27+
cache: "npm"
28+
- run: npm ci
29+
- run: make format-check
30+
- run: make build # also ensures typechecking passes
31+
- run: make test

DEVELOPMENT.md

+23-21
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,12 @@ This project uses a few tools to help with building and packaging it up: `typesc
8383
Their respective configuration files work together to produce the the library and this section contains a few highlights to
8484
help better understand how it works.
8585

86-
* Compiled and bundled up code lives in `dist/` (set in `tsconfig.json` "outDir")
87-
* We're targeting ES2022 as our output language, which is supprted by Node 18+ (see `tsconfig.json` "target")
88-
* We're building both ESM (.js) and CJS (.cjs) compatible artifacts (see `tsup.config.ts` "formats")
89-
* During build we're generating TypeScript declaration files and making them available to package consumers (see `tsup.config.ts` "dts")
90-
* Our package uses conditional exports so that the consumer will automatically get the right ESM or CJS based on how they import (see `package.json` "exports")
91-
* When we publish the package to NPM we're only including the `dist/`, `src/` and "default files", eg. `README`, `LICENCE` (see `package.json` "files")
86+
- Compiled and bundled up code lives in `dist/` (set in `tsconfig.json` "outDir")
87+
- We're targeting ES2022 as our output language, which is supprted by Node 18+ (see `tsconfig.json` "target")
88+
- We're building both ESM (.js) and CJS (.cjs) compatible artifacts (see `tsup.config.ts` "formats")
89+
- During build we're generating TypeScript declaration files and making them available to package consumers (see `tsup.config.ts` "dts")
90+
- Our package uses conditional exports so that the consumer will automatically get the right ESM or CJS based on how they import (see `package.json` "exports")
91+
- When we publish the package to NPM we're only including the `dist/`, `src/` and "default files", eg. `README`, `LICENCE` (see `package.json` "files")
9292

9393
## Versioning
9494

@@ -99,35 +99,37 @@ incorporate information about the API version and SDK version. We update version
9999
The version string looks like the following:
100100

101101
```js
102-
`${major}${version}.${minor}.${patch}`
102+
`${major}${version}.${minor}.${patch}`;
103103
```
104104

105-
* `major` is set manually and is the MAJOR version of the SDK code
106-
* `version` is a date string (`yyyymmdd`) we use as the API Version (from our OpenAPI schema)
107-
* `minor` is set manually and is the MINOR version of the SDK code
108-
* `patch` is set manually and is the PATCH version of the SDK code
105+
- `major` is set manually and is the MAJOR version of the SDK code
106+
- `version` is a date string (`yyyymmdd`) we use as the API Version (from our OpenAPI schema)
107+
- `minor` is set manually and is the MINOR version of the SDK code
108+
- `patch` is set manually and is the PATCH version of the SDK code
109109

110110
The version of the SDK should be updated in branches being merged into `main` according to the semantic versioning scheme:
111111

112-
* MAJOR version when you make incompatible API changes
113-
* MINOR version when you add functionality in a backward compatible manner
114-
* PATCH version when you make backward compatible bug fixes
112+
- MAJOR version when you make incompatible API changes
113+
- MINOR version when you add functionality in a backward compatible manner
114+
- PATCH version when you make backward compatible bug fixes
115115

116116
### Updating The Package Version
117117

118118
After making changes, you should:
119-
* Make sure to bump the `SDK_VERSION` in the `bin/update-version.ts` script
120-
* Then run `make update-version` to ensure the `package.json` and `src/version.ts` are set correctly.
119+
120+
- Make sure to bump the `SDK_VERSION` in the `bin/update-version.ts` script
121+
- Then run `make update-version` to ensure the `package.json` and `src/version.ts` are set correctly.
121122

122123
**NOTE:** The `make update-version` task will run after every `make sync-codegen` too!
123124

124125
## Releasing
125126

126127
**Prerequisites**:
127-
* Have an [npmjs.com](https://www.npmjs.com/) account and it must be a member of our organization
128-
* Have an GitHub account and it must be a member of our organization with write permissions on the repo
129-
* The changes that are currently in the branch are the one you would like to release (typically `main`)
130-
* The `version` field in the `package.json` is the one you would like to use for the release already
128+
129+
- Have an [npmjs.com](https://www.npmjs.com/) account and it must be a member of our organization
130+
- Have an GitHub account and it must be a member of our organization with write permissions on the repo
131+
- The changes that are currently in the branch are the one you would like to release (typically `main`)
132+
- The `version` field in the `package.json` is the one you would like to use for the release already
131133

132134
**Production Releases**:
133135

@@ -139,7 +141,7 @@ that we'd like to publish.
139141
2. Publish to NPM & push tag to GitHub: `make publish`
140142
3. Create new Release on GitHub (using the web UI). Add release notes, mentions, etc.
141143

142-
**Non-Production Releases**
144+
**Non-Production Releases**
143145

144146
The previous workflow assumes that the tag being published should be marked as `latest` for the NPM
145147
[distribution tag](https://docs.npmjs.com/adding-dist-tags-to-packages). If you would like to mark a release as

Makefile

+7-3
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,13 @@ sync-codegen: ensure
2626
bin/sync-codegen.ts
2727
make update-version
2828

29-
.PHONY: typecheck
30-
typecheck: ensure
31-
npx tsc -noEmit
29+
.PHONY: format-check
30+
format-check: ensure
31+
npx prettier . --check
32+
33+
.PHONY: format-fix
34+
format-fix: ensure
35+
npx prettier . --write
3236

3337
.PHONY: build
3438
build: ensure

bin/update-version.ts

-1
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ try {
2424
} catch (error) {
2525
console.error("Error reading or parsing openapi.json:", error);
2626
}
27-

examples/re-running-nodes.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ const SUBSTRATE_API_KEY = process.env["SUBSTRATE_API_KEY"];
1515
const substrate = new Substrate({ apiKey: SUBSTRATE_API_KEY });
1616

1717
const a = new GenerateText({
18-
prompt: "in very few words describe an incredible moment in sports history, be extremely concise",
18+
prompt:
19+
"in very few words describe an incredible moment in sports history, be extremely concise",
1920
});
2021

2122
a.result().then((result) => {
@@ -40,7 +41,7 @@ console.log("[3]", await f1);
4041
// when we access it's result again, we will get the same
4142
// value we had in `f1`
4243
let f2 = a.future.text.result();
43-
console.log("[4]", "await f1 === await f2 =", await f1 === await f2); // true
44+
console.log("[4]", "await f1 === await f2 =", (await f1) === (await f2)); // true
4445

4546
// now let's run the node again
4647
await substrate.run(a);
@@ -51,7 +52,7 @@ console.log("[5]", "Running node a second time!");
5152
// and it should be different than the first
5253
let f3 = a.future.text.result();
5354
console.log("[6]", await f3);
54-
console.log("[7]", "await f1 !== await f3 =", await f1 !== await f3); // true
55+
console.log("[7]", "await f1 !== await f3 =", (await f1) !== (await f3)); // true
5556

5657
// if we look back at the previous results we should see
5758
// that the first two are still the same, but the third

examples/single.ts

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ const a = new GenerateText({
1111
"in very few words describe an incredible historcal technical achievement",
1212
});
1313

14-
1514
substrate.run(a);
1615

1716
console.log(await a.future.text.result());

examples/string-concat.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ const substrate = new Substrate({
99
baseUrl: "https://api-staging.substrate.run",
1010
});
1111

12-
const a = new GenerateText({ prompt: "name a random capital city: <city name>, <country>" });
12+
const a = new GenerateText({
13+
prompt: "name a random capital city: <city name>, <country>",
14+
});
1315

1416
const concatenated = sb.concat("tell me about visiting ", a.future.text);
1517

src/Mailbox.ts

+9-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { Node } from "substrate/Node";
1111
*/
1212

1313
/** @private */
14-
class SubstrateEvent extends Event {};
14+
class SubstrateEvent extends Event {}
1515

1616
/** @private Event that reprepresents a new server response. */
1717
export class RequestCompleted extends SubstrateEvent {
@@ -47,19 +47,23 @@ export class Mailbox extends EventTarget {
4747
// When we receive an event, we'll resolve this Promise
4848
resolve(e.value.getNodeResponse(node));
4949
// Then we'll remove the event listeners to make sure there these references in the promise go away
50-
this.removeEventListener(RequestCompleted.type, handleRequestCompleted);
50+
this.removeEventListener(
51+
RequestCompleted.type,
52+
handleRequestCompleted,
53+
);
5154
// We'll move this reference over to the results list
52-
if (this.pending.length) this.resolved.push(this.pending.pop() as Promise<any>);
55+
if (this.pending.length)
56+
this.resolved.push(this.pending.pop() as Promise<any>);
5357
// Finally we'll start up a new listener
5458
waitForResponse();
55-
}
59+
},
5660
};
5761

5862
// We attach the above listener to this Mailbox
5963
this.addEventListener(RequestCompleted.type, handleRequestCompleted);
6064
});
6165
this.pending.push(p);
62-
}
66+
};
6367
waitForResponse();
6468
}
6569

0 commit comments

Comments
 (0)