Skip to content

Commit 18f8633

Browse files
committed
Merge branch '0.21'
2 parents c8c5934 + 58aef7b commit 18f8633

File tree

10 files changed

+152
-82
lines changed

10 files changed

+152
-82
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222
"@typescript-eslint/parser": "^6.0.0",
2323
"agadoo": "^3.0.0",
2424
"eslint": "^8.57.0",
25-
"eslint-config-turbo": "^2.0.14",
25+
"eslint-config-turbo": "^2.1.1",
2626
"eslint-plugin-simple-import-sort": "^10.0.0",
2727
"eslint-plugin-sort-keys-fix": "^1.1.2",
2828
"eslint-plugin-typescript-sort-keys": "^3.2.0",
29-
"happy-dom": "^14.12.3",
29+
"happy-dom": "^15.7.3",
3030
"prettier": "^3.3.3",
3131
"rimraf": "6.0.1",
3232
"tsup": "^8.2.4",
33-
"turbo": "^2.0.14",
33+
"turbo": "^2.1.1",
3434
"typescript": "^5.5.4",
3535
"vitest": "^2.0.5",
36-
"zx": "^8.1.4"
36+
"zx": "^8.1.5"
3737
},
3838
"engines": {
3939
"node": ">=18.0.0"

packages/nodes-from-anchor/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
"@kinobi-so/errors": "workspace:*",
5353
"@kinobi-so/nodes": "workspace:*",
5454
"@kinobi-so/visitors": "workspace:*",
55-
"@noble/hashes": "^1.4.0"
55+
"@noble/hashes": "^1.5.0"
5656
},
5757
"license": "MIT",
5858
"repository": {

packages/renderers-js/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @kinobi-so/renderers-js
22

3+
## 0.21.8
4+
5+
### Patch Changes
6+
7+
- [#200](https://github.com/kinobi-so/kinobi/pull/200) [`6639091`](https://github.com/kinobi-so/kinobi/commit/6639091714ae3b5c4330f0b1f43816fea373d55f) Thanks [@lorisleiva](https://github.com/lorisleiva)! - Fix a bug that reuses the same `ImportMap` within different code fragments
8+
39
## 0.21.7
410

511
### Patch Changes

packages/renderers-js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kinobi-so/renderers-js",
3-
"version": "0.21.7",
3+
"version": "0.21.8",
44
"description": "JavaScript renderer compatible with the Solana web3.js library",
55
"exports": {
66
"types": "./dist/types/index.d.ts",

packages/renderers-js/src/fragments/common.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ export class Fragment {
3030

3131
constructor(render: string, imports?: ImportMap, features?: Set<FragmentFeature>) {
3232
this.render = render;
33-
this.imports = imports ?? new ImportMap();
34-
this.features = features ?? new Set();
33+
this.imports = imports ? new ImportMap().mergeWith(imports) : new ImportMap();
34+
this.features = new Set([...(features ?? [])]);
3535
}
3636

3737
setRender(render: string): this {

packages/renderers-js/test/_setup.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,15 @@ export function renderMapContains(renderMap: RenderMap, key: string, expected: (
2121
return codeContains(renderMap.get(key), expected);
2222
}
2323

24+
export function renderMapDoesNotContain(
25+
renderMap: RenderMap,
26+
key: string,
27+
expected: (RegExp | string)[] | RegExp | string,
28+
) {
29+
expect(renderMap.has(key), `RenderMap is missing key "${key}".`).toBe(true);
30+
return codeDoesNotContain(renderMap.get(key), expected);
31+
}
32+
2433
export async function codeContains(actual: string, expected: (RegExp | string)[] | RegExp | string) {
2534
const expectedArray = Array.isArray(expected) ? expected : [expected];
2635
const normalizedActual = await normalizeCode(actual);
@@ -50,6 +59,15 @@ export function renderMapContainsImports(renderMap: RenderMap, key: string, expe
5059
return codeContainsImports(renderMap.get(key), expectedImports);
5160
}
5261

62+
export function renderMapDoesNotContainImports(
63+
renderMap: RenderMap,
64+
key: string,
65+
expectedImports: Record<string, string[]>,
66+
) {
67+
expect(renderMap.has(key), `RenderMap is missing key "${key}".`).toBe(true);
68+
return codeDoesNotContainImports(renderMap.get(key), expectedImports);
69+
}
70+
5371
export async function codeContainsImports(actual: string, expectedImports: Record<string, string[]>) {
5472
const normalizedActual = await inlineCode(actual);
5573
const importPairs = Object.entries(expectedImports).flatMap(([key, value]) => {
@@ -61,6 +79,17 @@ export async function codeContainsImports(actual: string, expectedImports: Recor
6179
});
6280
}
6381

82+
export async function codeDoesNotContainImports(actual: string, expectedImports: Record<string, string[]>) {
83+
const normalizedActual = await inlineCode(actual);
84+
const importPairs = Object.entries(expectedImports).flatMap(([key, value]) => {
85+
return value.map(v => [key, v] as const);
86+
});
87+
88+
importPairs.forEach(([importFrom, importValue]) => {
89+
expect(normalizedActual).not.toMatch(new RegExp(`import{[^}]*\\b${importValue}\\b[^}]*}from'${importFrom}'`));
90+
});
91+
}
92+
6493
export function codeStringAsRegex(code: string) {
6594
const stringAsRegex = escapeRegex(code)
6695
// Transform spaces between words into required whitespace.

packages/renderers-js/test/pdasPage.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
constantPdaSeedNodeFromString,
33
numberTypeNode,
4+
optionTypeNode,
45
pdaNode,
56
programNode,
67
publicKeyTypeNode,
@@ -10,7 +11,7 @@ import { visit } from '@kinobi-so/visitors-core';
1011
import { test } from 'vitest';
1112

1213
import { getRenderMapVisitor } from '../src';
13-
import { renderMapContains } from './_setup';
14+
import { renderMapContains, renderMapContainsImports, renderMapDoesNotContainImports } from './_setup';
1415

1516
test('it renders a PDA helper function and its input type', async () => {
1617
// Given the following PDA node.
@@ -82,3 +83,30 @@ test('it renders an empty array of seeds for seedless PDAs', async () => {
8283
'getProgramDerivedAddress({ programAddress, seeds: [] })',
8384
]);
8485
});
86+
87+
test('it does not import strict types for variable seeds', async () => {
88+
// Given the following PDA node.
89+
const node = programNode({
90+
name: 'myProgram',
91+
pdas: [
92+
pdaNode({
93+
name: 'foo',
94+
seeds: [variablePdaSeedNode('myAccount', optionTypeNode(publicKeyTypeNode()))],
95+
}),
96+
],
97+
publicKey: '1111',
98+
});
99+
100+
// When we render it.
101+
const renderMap = visit(node, getRenderMapVisitor());
102+
103+
// Then the `Option` string type should not be imported.
104+
await renderMapDoesNotContainImports(renderMap, 'pdas/foo.ts', {
105+
'@solana/web3.js': ['type Option'],
106+
});
107+
108+
// But the `OptionOrNullable` loose type should be imported.
109+
await renderMapContainsImports(renderMap, 'pdas/foo.ts', {
110+
'@solana/web3.js': ['type OptionOrNullable'],
111+
});
112+
});

packages/renderers/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
# @kinobi-so/renderers
22

3+
## 0.21.3
4+
5+
### Patch Changes
6+
7+
- Updated dependencies [[`6639091`](https://github.com/kinobi-so/kinobi/commit/6639091714ae3b5c4330f0b1f43816fea373d55f)]:
8+
- @kinobi-so/renderers-js@0.21.8
9+
310
## 0.21.2
411

512
### Patch Changes

packages/renderers/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@kinobi-so/renderers",
3-
"version": "0.21.2",
3+
"version": "0.21.3",
44
"description": "Exports all Kinobi renderers",
55
"exports": {
66
"types": "./dist/types/index.d.ts",

0 commit comments

Comments
 (0)