From 6e68b683c7b0f3f82a8f362f51ec4dc4e733bf7d Mon Sep 17 00:00:00 2001 From: Rafferty Askara Date: Mon, 24 Aug 2026 15:00:15 -0700 Subject: [PATCH 1/2] fix: load dotenv inside figma-sync main to avoid top-level await --- packages/icons/scripts/figma-sync.ts | 51 ++++++++++++++++------------ 1 file changed, 30 insertions(+), 21 deletions(-) diff --git a/packages/icons/scripts/figma-sync.ts b/packages/icons/scripts/figma-sync.ts index 5c21e2c78..3465bf867 100644 --- a/packages/icons/scripts/figma-sync.ts +++ b/packages/icons/scripts/figma-sync.ts @@ -19,33 +19,32 @@ import process from 'node:process'; import { setTimeout as delay } from 'node:timers/promises'; import { optimize } from 'svgo'; -// Load .env file if it exists -try { - const dotenvPath = path.resolve(process.cwd(), '.env'); - if (fs.existsSync(dotenvPath)) { - // dotenv is optional and may not be installed; importing it dynamically via a non-literal - // specifier here (rather than a static ESM import) is what lets the surrounding try/catch - // degrade gracefully when it's absent, and avoids a `Cannot find module 'dotenv'` type error - // for a package that's intentionally not a declared dependency. - const dotenvSpecifier = 'dotenv'; - const dotenv = await import(dotenvSpecifier); - dotenv.default?.config?.(); +// oxlint no longer allows require(), and tsx compiles this .ts file as CommonJS +// (no "type": "module" in package.json), which cannot use top-level await. +// Dynamic import() is therefore wrapped in this async function and awaited from main(). +async function loadOptionalDotenv(): Promise { + try { + const dotenvPath = path.resolve(process.cwd(), '.env'); + if (fs.existsSync(dotenvPath)) { + // dotenv is optional and may not be installed; importing it dynamically via a non-literal + // specifier here (rather than a static ESM import) is what lets the surrounding try/catch + // degrade gracefully when it's absent, and avoids a `Cannot find module 'dotenv'` type error + // for a package that's intentionally not a declared dependency. + const dotenvSpecifier = 'dotenv'; + const dotenv = await import(dotenvSpecifier); + dotenv.default?.config?.(); + } + } catch { + /* ignore */ } -} catch { - /* ignore */ } // Figma API constants -const FIGMA_ACCESS_TOKEN = process.env.FIGMA_ACCESS_TOKEN; const FIGMA_FILE_KEY = '98HKKXL2dTle29ikJ3tzk7'; const FIGMA_NODE_ID = '1:1483'; -const DRY_RUN = process.env.DRY_RUN === '1'; -const FORCE_SYNC = process.env.FORCE_SYNC === '1'; - -if (!FIGMA_ACCESS_TOKEN || !FIGMA_FILE_KEY) { - console.error('Missing FIGMA_ACCESS_TOKEN.'); - process.exit(1); -} +let FIGMA_ACCESS_TOKEN: string | undefined; +let DRY_RUN = false; +let FORCE_SYNC = false; const ROOT = path.resolve(process.cwd()); const SPRITE_PATH = path.join(ROOT, 'src/img/sprite.svg'); @@ -386,6 +385,16 @@ async function mapPool(items: T[], limit: number, worker: (item: T, idx: n // Main: bring it all together to generate icon sprite and type files async function main(): Promise { + await loadOptionalDotenv(); + FIGMA_ACCESS_TOKEN = process.env.FIGMA_ACCESS_TOKEN; + DRY_RUN = process.env.DRY_RUN === '1'; + FORCE_SYNC = process.env.FORCE_SYNC === '1'; + + if (!FIGMA_ACCESS_TOKEN || !FIGMA_FILE_KEY) { + console.error('Missing FIGMA_ACCESS_TOKEN.'); + process.exit(1); + } + // 1) Get icon components const root = await fetchIconRoot(); const components = collectComponents(root); From 6c5433e15f26b117b4f5e911409bf3fa2e8c9f2d Mon Sep 17 00:00:00 2001 From: Rafferty Askara Date: Mon, 24 Aug 2026 15:12:49 -0700 Subject: [PATCH 2/2] chore: add changeset empty --- .changeset/some-nights-film.md | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 .changeset/some-nights-film.md diff --git a/.changeset/some-nights-film.md b/.changeset/some-nights-film.md new file mode 100644 index 000000000..a845151cc --- /dev/null +++ b/.changeset/some-nights-film.md @@ -0,0 +1,2 @@ +--- +---