From 54800f5835a30aa33a3fac1e6a9bb8d99719492d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Kry=C5=A1p=C3=ADn?= Date: Thu, 24 Oct 2024 15:19:29 +0200 Subject: [PATCH] Fix(exporter-tokens): Pass all tokens to the `computeTokensByApplyingThemes` so references work --- exporters/tokens/generated/exporter.cjs | 2 +- exporters/tokens/src/generators/fileGenerator.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/exporters/tokens/generated/exporter.cjs b/exporters/tokens/generated/exporter.cjs index 14f984d8cf..3c3ec19d50 100644 --- a/exporters/tokens/generated/exporter.cjs +++ b/exporters/tokens/generated/exporter.cjs @@ -67,4 +67,4 @@ ${a?`}; `}`;return ue(f,a)},ko=async(n,a,u,i,m)=>{const y=[],f=L(n,a,u,J),r=L(n,a,u,J,!0),t=w(f),o=w(r,!0);y.push(...f.map(c=>({path:`./${R}/${N}`,fileName:`_${c.fileName}.scss`,content:c.content})),...r.map(c=>({path:`./${x}/${N}/`,fileName:`${c.fileName}.ts`,content:c.content}))),y.push({path:`./${R}/${N}/`,fileName:"index.scss",content:t}),y.push({path:`./${x}/${N}/`,fileName:"index.ts",content:o}),y.push({path:`./${R}/`,fileName:"@global.scss",content:`@forward '${N}'; `}),y.push({path:`./${x}/`,fileName:"index.ts",content:`export * from './${N}'; export * from './${D}'; -`});const e=await Promise.all(i.map(async c=>({themedTokens:m.tokens.computeTokensByApplyingThemes([],n,[c]),theme:c})));for(const{themedTokens:c,theme:p}of e){const l=L(c,a,u,ee),d=L(c,a,u,ee,!0),g=w(l),S=w(d,!0);y.push(...l.map(b=>({path:`./${R}/${D}/${p.name}/`,fileName:`_${b.fileName}.scss`,content:b.content})),...d.map(b=>({path:`./${x}/${D}/${p.name}/`,fileName:`${b.fileName}.ts`,content:b.content}))),y.push({path:`./${R}/${D}/${p.name}/`,fileName:"index.scss",content:g}),y.push({path:`./${x}/${D}/${p.name}/`,fileName:"index.ts",content:S})}const s=te(i),T=te(i,!0);return y.push({path:`./${R}/`,fileName:"@themes.scss",content:s}),y.push({path:`./${x}/${D}`,fileName:"index.ts",content:T}),y},Co=n=>{let a=[];const u=JSON.stringify(n,(i,m)=>{if(typeof m=="object"&&m!==null){if(a!=null&&a.includes(m))return"CIRCULAR_REFERENCE";a==null||a.push(m)}return m},2);return a=null,u},ve=Pulsar.exportConfig();Pulsar.export(async(n,a)=>{const u={designSystemId:a.dsId,versionId:a.versionId};let i=await n.tokens.getTokens(u),m=await n.tokens.getTokenGroups(u);a.brandId&&(i=i.filter(e=>e.brandId===a.brandId),m=m.filter(e=>e.brandId===a.brandId));const y=new Map(i.map(e=>[e.id,e])),f=await n.tokens.getTokenThemes(u),r=(e,s,T)=>P.FileHelper.createTextFile({relativePath:e,fileName:s,content:T});let t=[];return t=(await ko(i,y,m,f,n)).map(e=>r(e.path,e.fileName,e.content)),ve.generateOriginalDataFiles&&t.push(r("./original-data/","_original-tokens.json",Co(i)),r("./original-data/","_original-groups.json",JSON.stringify(m,null,2))),t});exports.exportConfiguration=ve; +`});const e=await Promise.all(i.map(async c=>({themedTokens:m.tokens.computeTokensByApplyingThemes(n,n,[c]),theme:c})));for(const{themedTokens:c,theme:p}of e){const l=L(c,a,u,ee),d=L(c,a,u,ee,!0),g=w(l),S=w(d,!0);y.push(...l.map(b=>({path:`./${R}/${D}/${p.name}/`,fileName:`_${b.fileName}.scss`,content:b.content})),...d.map(b=>({path:`./${x}/${D}/${p.name}/`,fileName:`${b.fileName}.ts`,content:b.content}))),y.push({path:`./${R}/${D}/${p.name}/`,fileName:"index.scss",content:g}),y.push({path:`./${x}/${D}/${p.name}/`,fileName:"index.ts",content:S})}const s=te(i),T=te(i,!0);return y.push({path:`./${R}/`,fileName:"@themes.scss",content:s}),y.push({path:`./${x}/${D}`,fileName:"index.ts",content:T}),y},Co=n=>{let a=[];const u=JSON.stringify(n,(i,m)=>{if(typeof m=="object"&&m!==null){if(a!=null&&a.includes(m))return"CIRCULAR_REFERENCE";a==null||a.push(m)}return m},2);return a=null,u},ve=Pulsar.exportConfig();Pulsar.export(async(n,a)=>{const u={designSystemId:a.dsId,versionId:a.versionId};let i=await n.tokens.getTokens(u),m=await n.tokens.getTokenGroups(u);a.brandId&&(i=i.filter(e=>e.brandId===a.brandId),m=m.filter(e=>e.brandId===a.brandId));const y=new Map(i.map(e=>[e.id,e])),f=await n.tokens.getTokenThemes(u),r=(e,s,T)=>P.FileHelper.createTextFile({relativePath:e,fileName:s,content:T});let t=[];return t=(await ko(i,y,m,f,n)).map(e=>r(e.path,e.fileName,e.content)),ve.generateOriginalDataFiles&&t.push(r("./original-data/","_original-tokens.json",Co(i)),r("./original-data/","_original-groups.json",JSON.stringify(m,null,2))),t});exports.exportConfiguration=ve; diff --git a/exporters/tokens/src/generators/fileGenerator.ts b/exporters/tokens/src/generators/fileGenerator.ts index 28014c80ca..fe869cf484 100644 --- a/exporters/tokens/src/generators/fileGenerator.ts +++ b/exporters/tokens/src/generators/fileGenerator.ts @@ -122,7 +122,7 @@ export const generateOutputFilesByThemes = async ( // Compute themed tokens for all themes in parallel const allThemes = await Promise.all( themes.map(async (theme) => { - const themedTokens = sdk.tokens.computeTokensByApplyingThemes([], tokens, [theme]); + const themedTokens = sdk.tokens.computeTokensByApplyingThemes(tokens, tokens, [theme]); return { themedTokens, theme }; }),