From f020c2f15d9001d64d53960db1b54f15e0547f35 Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Thu, 30 Jan 2025 14:41:50 -0800 Subject: [PATCH] fix(frontend/packages/icons): fix failling to install @rivet-gg/icons when fontawesome token is not provided --- .github/workflows/release.yaml | 12 ++ docker/dev-full/docker-compose.yml | 10 ++ docker/universal/Dockerfile | 3 +- .../packages/icons/scripts/postinstall.js | 117 ++++++++---------- packages/common/hub-embed/build.rs | 3 + 5 files changed, 78 insertions(+), 67 deletions(-) diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 601e3fcba5..6d88ac130d 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -235,6 +235,8 @@ jobs: file: docker/universal/Dockerfile target: server-full platforms: ${{ matrix.platform }} + secrets: | + fontawesome_package_token=${{ secrets.FONTAWESOME_PACKAGE_TOKEN }} secret-files: | netrc=${{ runner.temp }}/netrc @@ -247,6 +249,8 @@ jobs: file: docker/universal/Dockerfile target: server-slim platforms: ${{ matrix.platform }} + secrets: | + fontawesome_package_token=${{ secrets.FONTAWESOME_PACKAGE_TOKEN }} secret-files: | netrc=${{ runner.temp }}/netrc @@ -271,6 +275,8 @@ jobs: file: docker/universal/Dockerfile target: client-full platforms: ${{ matrix.platform }} + secrets: | + fontawesome_package_token=${{ secrets.FONTAWESOME_PACKAGE_TOKEN }} secret-files: | netrc=${{ runner.temp }}/netrc @@ -283,6 +289,8 @@ jobs: file: docker/universal/Dockerfile target: isolate-v8-runner platforms: ${{ matrix.platform }} + secrets: | + fontawesome_package_token=${{ secrets.FONTAWESOME_PACKAGE_TOKEN }} secret-files: | netrc=${{ runner.temp }}/netrc @@ -295,6 +303,8 @@ jobs: file: docker/universal/Dockerfile target: container-runner platforms: ${{ matrix.platform }} + secrets: | + fontawesome_package_token=${{ secrets.FONTAWESOME_PACKAGE_TOKEN }} secret-files: | netrc=${{ runner.temp }}/netrc @@ -307,6 +317,8 @@ jobs: file: docker/universal/Dockerfile target: monolith platforms: ${{ matrix.platform }} + secrets: | + fontawesome_package_token=${{ secrets.FONTAWESOME_PACKAGE_TOKEN }} secret-files: | netrc=${{ runner.temp }}/netrc diff --git a/docker/dev-full/docker-compose.yml b/docker/dev-full/docker-compose.yml index 964a258ff0..aa2f9c65e3 100644 --- a/docker/dev-full/docker-compose.yml +++ b/docker/dev-full/docker-compose.yml @@ -4,6 +4,8 @@ services: context: ../.. dockerfile: docker/universal/Dockerfile target: server-full + secrets: + - fontawesome_package_token platform: linux/amd64 restart: unless-stopped command: /usr/bin/rivet-server start @@ -50,6 +52,8 @@ services: context: ../.. dockerfile: docker/universal/Dockerfile target: server-full + secrets: + - fontawesome_package_token platform: linux/amd64 restart: unless-stopped command: sleep infinity @@ -106,6 +110,8 @@ services: context: ../.. dockerfile: docker/universal/Dockerfile target: client-full + secrets: + - fontawesome_package_token # TODO(RVT-4168): Compile libfdb from scratch for ARM platform: linux/amd64 restart: unless-stopped @@ -249,3 +255,7 @@ volumes: vector-server-data: foundationdb-data: foundationdb-storage-data: + +secrets: + fontawesome_package_token: + environment: FONTAWESOME_PACKAGE_TOKEN diff --git a/docker/universal/Dockerfile b/docker/universal/Dockerfile index 310e0cc547..ce54c4abf6 100644 --- a/docker/universal/Dockerfile +++ b/docker/universal/Dockerfile @@ -1,4 +1,4 @@ -# syntax=docker/dockerfile:1.2 +# syntax=docker/dockerfile:1.10.0 # MARK: Builder # TODO(RVT-4168): Compile libfdb from scratch for ARM @@ -42,6 +42,7 @@ COPY . . # included in the output because of cache mount) RUN \ --mount=type=secret,id=netrc,target=/root/.netrc,mode=0600 \ + --mount=type=secret,id=fontawesome_package_token,env=FONTAWESOME_PACKAGE_TOKEN \ --mount=type=cache,target=/usr/local/cargo/git,id=univseral-cargo-git \ --mount=type=cache,target=/usr/local/cargo/registry,id=univseral-cargo-registry \ --mount=type=cache,target=/app/target,id=univseral-target \ diff --git a/frontend/packages/icons/scripts/postinstall.js b/frontend/packages/icons/scripts/postinstall.js index 61d674ba56..3b29e89e05 100644 --- a/frontend/packages/icons/scripts/postinstall.js +++ b/frontend/packages/icons/scripts/postinstall.js @@ -1,4 +1,3 @@ -const { isPackageExists, getPackageInfo } = require("local-pkg"); const fs = require("node:fs"); const dedent = require("dedent"); const { spawnSync } = require("node:child_process"); @@ -6,31 +5,26 @@ const { join, resolve } = require("node:path"); const manifest = require("./../manifest.json"); const vite = require("vite"); -const packageExistsOptions = { - paths: [ - join(process.cwd(), "src", "node_modules"), - join(process.cwd(), "..", ".."), - ], -}; +let hasFaToken = !!process.env.FONTAWESOME_PACKAGE_TOKEN; if (process.env.FONTAWESOME_PACKAGE_TOKEN) { fs.writeFileSync( "./src/.yarnrc.yml", dedent` - nodeLinker: node-modules - - enableImmutableInstalls: false - - npmScopes: - fortawesome: - npmAlwaysAuth: true - npmRegistryServer: 'https://npm.fontawesome.com/' - npmAuthToken: \${FONTAWESOME_PACKAGE_TOKEN} - awesome.me: - npmAlwaysAuth: true - npmRegistryServer: "https://npm.fontawesome.com/" - npmAuthToken: \${FONTAWESOME_PACKAGE_TOKEN} - `, + nodeLinker: node-modules + + enableImmutableInstalls: false + + npmScopes: + fortawesome: + npmAlwaysAuth: true + npmRegistryServer: 'https://npm.fontawesome.com/' + npmAuthToken: \${FONTAWESOME_PACKAGE_TOKEN} + awesome.me: + npmAlwaysAuth: true + npmRegistryServer: "https://npm.fontawesome.com/" + npmAuthToken: \${FONTAWESOME_PACKAGE_TOKEN} + `, ); fs.writeFileSync("./src/yarn.lock", ""); @@ -54,15 +48,10 @@ if (process.env.FONTAWESOME_PACKAGE_TOKEN) { }); } -const isPro = isPackageExists( - "@fortawesome/pro-solid-svg-icons", - packageExistsOptions, -); - const banner = dedent` // This file is generated by scripts/postinstall.js // Do not modify this file directly - // ${isPro ? "This file includes pro icons" : "This file does not include pro icons, all pro icons are replaced with square icon. To use pro icons, please add FONTAWESOME_PACKAGE_TOKEN to your environment and rebuild this package."} \n + // ${hasFaToken ? "This file includes pro icons" : "This file does not include pro icons, all pro icons are replaced with square icon. To use pro icons, please add FONTAWESOME_PACKAGE_TOKEN to your environment and rebuild this package."} \n `; @@ -77,38 +66,37 @@ let indexTsSource = dedent` `; for (const [pkg, { icons }] of Object.entries(manifest)) { - const pkgExists = pkg.includes("pro") ? isPro : true; const isCustom = pkg.startsWith("@awesome.me/kit-"); + const isPro = pkg.startsWith("@fortawesome/pro-"); if (isCustom) { - if (!pkgExists) { + if (hasFaToken) { + indexTsSource += `export * from "${pkg}";\n`; + } else { const iconNames = icons.map(({ icon }) => icon); const exp = iconNames .map((icon) => `definition as ${icon}`) .join(", "); indexTsSource += `export { ${exp} } from "@fortawesome/free-solid-svg-icons/faSquare";\n`; - } else { - indexTsSource += `export * from "${pkg}";\n`; } - continue; - } - - for (const { icon, aliases } of icons) { - if (!indexTsSource.includes(`export { definition as ${icon} }`)) { - if (pkgExists) { - indexTsSource += `export { definition as ${icon} } from "${pkg}/${icon}";\n`; - } else { - indexTsSource += `export { definition as ${icon} } from "@fortawesome/free-solid-svg-icons/faSquare";\n`; + } else { + for (const { icon, aliases } of icons) { + if (!indexTsSource.includes(`export { definition as ${icon} }`)) { + if (hasFaToken || !isPro) { + indexTsSource += `export { definition as ${icon} } from "${pkg}/${icon}";\n`; + } else { + indexTsSource += `export { definition as ${icon} } from "@fortawesome/free-solid-svg-icons/faSquare";\n`; + } } - } - for (const alias of aliases) { - if ( - alias === icon || - indexTsSource.includes(`export { definition as ${icon} }`) - ) { - continue; + for (const alias of aliases) { + if ( + alias === icon || + indexTsSource.includes(`export { definition as ${icon} }`) + ) { + continue; + } + indexTsSource += `export { definition as ${alias} } from "${pkg}/${icon}";\n`; } - indexTsSource += `export { definition as ${alias} } from "${pkg}/${icon}";\n`; } } } @@ -118,39 +106,36 @@ let iconsPackTsSource = `${banner}\n import {type IconPack} from "@fortawesome/fontawesome-common-types";\n`; for (const [pkg, { icons }] of Object.entries(manifest)) { - const pkgExists = pkg.includes("pro") ? isPro : true; const isCustom = pkg.startsWith("@awesome.me/kit-"); + const isPro = pkg.startsWith("@fortawesome/pro-"); if (isCustom) { const iconNames = icons.map(({ icon }) => icon); - if (!pkgExists) { + if (hasFaToken) { + iconsPackTsSource += `import {${iconNames.join(",")}} from "${pkg}";\n`; + } else { const exp = iconNames .map((icon) => `definition as ${icon}`) .join(", "); iconsPackTsSource += `import {${exp}} from "@fortawesome/free-solid-svg-icons/faSquare";\n`; - } else { - iconsPackTsSource += `import {${iconNames.join(",")}} from "${pkg}";\n`; - } - continue; - } - - for (const { icon } of icons) { - if (iconsPackTsSource.includes(`import {definition as ${icon}}`)) { - continue; } - if (pkgExists) { - iconsPackTsSource += `import {definition as ${icon}} from "${pkg}/${icon}";\n`; - } else { - iconsPackTsSource += `import {definition as ${icon}} from "@fortawesome/free-solid-svg-icons/faSquare";\n`; + } else { + for (const { icon } of icons) { + if (iconsPackTsSource.includes(`import {definition as ${icon}}`)) { + continue; + } + if (hasFaToken || !isPro) { + iconsPackTsSource += `import {definition as ${icon}} from "${pkg}/${icon}";\n`; + } else { + iconsPackTsSource += `import {definition as ${icon}} from "@fortawesome/free-solid-svg-icons/faSquare";\n`; + } } } } iconsPackTsSource += "export default {\n"; -for (const [pkg, { icons }] of Object.entries(manifest)) { - const pkgExists = pkg.includes("pro") ? isPro : true; - +for (const [_pkg, { icons }] of Object.entries(manifest)) { for (const { icon, aliases } of icons) { if (!iconsPackTsSource.includes(`{...${icon},`)) { iconsPackTsSource += ` ${icon}: {...${icon}, prefix: "fas"},\n`; diff --git a/packages/common/hub-embed/build.rs b/packages/common/hub-embed/build.rs index a88da627af..10ba588f21 100644 --- a/packages/common/hub-embed/build.rs +++ b/packages/common/hub-embed/build.rs @@ -53,5 +53,8 @@ fn main() -> Result<(), Box> { println!("cargo:rerun-if-changed={}", hub_path.display()); + // Relevant package tokens + println!("cargo:rerun-if-env-changed=FONTAWESOME_PACKAGE_TOKEN"); + Ok(()) }