Skip to content

Commit 412e143

Browse files
authored
Remove nunjucks from JS renderer (#825)
1 parent b3d11f9 commit 412e143

File tree

200 files changed

+2949
-3732
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

200 files changed

+2949
-3732
lines changed

.changeset/all-actors-jog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@codama/renderers-js': minor
3+
---
4+
5+
Remove nunjucks templating library and enable browser support

.changeset/thin-cloths-smile.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@codama/renderers-core': patch
3+
---
4+
5+
Add `createFragmentTemplate` helper

packages/renderers-core/src/fragment.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,19 @@ export function mapFragmentContent<TFragment extends BaseFragment>(
1010
export function setFragmentContent<TFragment extends BaseFragment>(fragment: TFragment, content: string): TFragment {
1111
return Object.freeze({ ...fragment, content });
1212
}
13+
14+
export function createFragmentTemplate<TFragment extends BaseFragment>(
15+
template: TemplateStringsArray,
16+
items: unknown[],
17+
isFragment: (value: unknown) => value is TFragment,
18+
mergeFragments: (fragments: TFragment[], mergeContent: (contents: string[]) => string) => TFragment,
19+
): TFragment {
20+
const fragments = items.filter(isFragment);
21+
const zippedItems = items.map((item, i) => {
22+
const itemPrefix = template[i];
23+
if (typeof item === 'undefined') return itemPrefix;
24+
if (isFragment(item)) return itemPrefix + item.content;
25+
return itemPrefix + String(item);
26+
});
27+
return mergeFragments(fragments, () => zippedItems.join('') + template[template.length - 1]);
28+
}

packages/renderers-js/e2e/anchor/src/generated/accounts/guardV1.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* This code was AUTOGENERATED using the codama library.
2+
* This code was AUTOGENERATED using the Codama library.
33
* Please DO NOT EDIT THIS FILE, instead use visitors
4-
* to add features, then rerun codama to update it.
4+
* to add features, then rerun Codama to update it.
55
*
66
* @see https://github.com/codama-idl/codama
77
*/

packages/renderers-js/e2e/anchor/src/generated/accounts/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* This code was AUTOGENERATED using the codama library.
2+
* This code was AUTOGENERATED using the Codama library.
33
* Please DO NOT EDIT THIS FILE, instead use visitors
4-
* to add features, then rerun codama to update it.
4+
* to add features, then rerun Codama to update it.
55
*
66
* @see https://github.com/codama-idl/codama
77
*/

packages/renderers-js/e2e/anchor/src/generated/errors/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* This code was AUTOGENERATED using the codama library.
2+
* This code was AUTOGENERATED using the Codama library.
33
* Please DO NOT EDIT THIS FILE, instead use visitors
4-
* to add features, then rerun codama to update it.
4+
* to add features, then rerun Codama to update it.
55
*
66
* @see https://github.com/codama-idl/codama
77
*/

packages/renderers-js/e2e/anchor/src/generated/errors/wenTransferGuard.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* This code was AUTOGENERATED using the codama library.
2+
* This code was AUTOGENERATED using the Codama library.
33
* Please DO NOT EDIT THIS FILE, instead use visitors
4-
* to add features, then rerun codama to update it.
4+
* to add features, then rerun Codama to update it.
55
*
66
* @see https://github.com/codama-idl/codama
77
*/

packages/renderers-js/e2e/anchor/src/generated/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* This code was AUTOGENERATED using the codama library.
2+
* This code was AUTOGENERATED using the Codama library.
33
* Please DO NOT EDIT THIS FILE, instead use visitors
4-
* to add features, then rerun codama to update it.
4+
* to add features, then rerun Codama to update it.
55
*
66
* @see https://github.com/codama-idl/codama
77
*/

packages/renderers-js/e2e/anchor/src/generated/instructions/createGuard.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* This code was AUTOGENERATED using the codama library.
2+
* This code was AUTOGENERATED using the Codama library.
33
* Please DO NOT EDIT THIS FILE, instead use visitors
4-
* to add features, then rerun codama to update it.
4+
* to add features, then rerun Codama to update it.
55
*
66
* @see https://github.com/codama-idl/codama
77
*/
@@ -324,7 +324,7 @@ export async function getCreateGuardInstructionAsync<
324324
}
325325

326326
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
327-
const instruction = {
327+
return Object.freeze({
328328
accounts: [
329329
getAccountMeta(accounts.guard),
330330
getAccountMeta(accounts.mint),
@@ -335,10 +335,10 @@ export async function getCreateGuardInstructionAsync<
335335
getAccountMeta(accounts.tokenProgram),
336336
getAccountMeta(accounts.systemProgram),
337337
],
338-
programAddress,
339338
data: getCreateGuardInstructionDataEncoder().encode(
340339
args as CreateGuardInstructionDataArgs
341340
),
341+
programAddress,
342342
} as CreateGuardInstruction<
343343
TProgramAddress,
344344
TAccountGuard,
@@ -349,9 +349,7 @@ export async function getCreateGuardInstructionAsync<
349349
TAccountAssociatedTokenProgram,
350350
TAccountTokenProgram,
351351
TAccountSystemProgram
352-
>;
353-
354-
return instruction;
352+
>);
355353
}
356354

357355
export type CreateGuardInput<
@@ -457,7 +455,7 @@ export function getCreateGuardInstruction<
457455
}
458456

459457
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
460-
const instruction = {
458+
return Object.freeze({
461459
accounts: [
462460
getAccountMeta(accounts.guard),
463461
getAccountMeta(accounts.mint),
@@ -468,10 +466,10 @@ export function getCreateGuardInstruction<
468466
getAccountMeta(accounts.tokenProgram),
469467
getAccountMeta(accounts.systemProgram),
470468
],
471-
programAddress,
472469
data: getCreateGuardInstructionDataEncoder().encode(
473470
args as CreateGuardInstructionDataArgs
474471
),
472+
programAddress,
475473
} as CreateGuardInstruction<
476474
TProgramAddress,
477475
TAccountGuard,
@@ -482,9 +480,7 @@ export function getCreateGuardInstruction<
482480
TAccountAssociatedTokenProgram,
483481
TAccountTokenProgram,
484482
TAccountSystemProgram
485-
>;
486-
487-
return instruction;
483+
>);
488484
}
489485

490486
export type ParsedCreateGuardInstruction<

packages/renderers-js/e2e/anchor/src/generated/instructions/execute.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**
2-
* This code was AUTOGENERATED using the codama library.
2+
* This code was AUTOGENERATED using the Codama library.
33
* Please DO NOT EDIT THIS FILE, instead use visitors
4-
* to add features, then rerun codama to update it.
4+
* to add features, then rerun Codama to update it.
55
*
66
* @see https://github.com/codama-idl/codama
77
*/
@@ -223,7 +223,7 @@ export async function getExecuteInstructionAsync<
223223
}
224224

225225
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
226-
const instruction = {
226+
return Object.freeze({
227227
accounts: [
228228
getAccountMeta(accounts.sourceAccount),
229229
getAccountMeta(accounts.mint),
@@ -233,10 +233,10 @@ export async function getExecuteInstructionAsync<
233233
getAccountMeta(accounts.guard),
234234
getAccountMeta(accounts.instructionSysvarAccount),
235235
],
236-
programAddress,
237236
data: getExecuteInstructionDataEncoder().encode(
238237
args as ExecuteInstructionDataArgs
239238
),
239+
programAddress,
240240
} as ExecuteInstruction<
241241
TProgramAddress,
242242
TAccountSourceAccount,
@@ -246,9 +246,7 @@ export async function getExecuteInstructionAsync<
246246
TAccountExtraMetasAccount,
247247
TAccountGuard,
248248
TAccountInstructionSysvarAccount
249-
>;
250-
251-
return instruction;
249+
>);
252250
}
253251

254252
export type ExecuteInput<
@@ -338,7 +336,7 @@ export function getExecuteInstruction<
338336
}
339337

340338
const getAccountMeta = getAccountMetaFactory(programAddress, 'programId');
341-
const instruction = {
339+
return Object.freeze({
342340
accounts: [
343341
getAccountMeta(accounts.sourceAccount),
344342
getAccountMeta(accounts.mint),
@@ -348,10 +346,10 @@ export function getExecuteInstruction<
348346
getAccountMeta(accounts.guard),
349347
getAccountMeta(accounts.instructionSysvarAccount),
350348
],
351-
programAddress,
352349
data: getExecuteInstructionDataEncoder().encode(
353350
args as ExecuteInstructionDataArgs
354351
),
352+
programAddress,
355353
} as ExecuteInstruction<
356354
TProgramAddress,
357355
TAccountSourceAccount,
@@ -361,9 +359,7 @@ export function getExecuteInstruction<
361359
TAccountExtraMetasAccount,
362360
TAccountGuard,
363361
TAccountInstructionSysvarAccount
364-
>;
365-
366-
return instruction;
362+
>);
367363
}
368364

369365
export type ParsedExecuteInstruction<

0 commit comments

Comments
 (0)