Skip to content

Commit

Permalink
fix(frontend/packages/icons): fix failling to install @rivet-gg/icons…
Browse files Browse the repository at this point in the history
… when fontawesome token is not provided
  • Loading branch information
NathanFlurry committed Jan 31, 2025
1 parent ec6a0e7 commit f020c2f
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 67 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
10 changes: 10 additions & 0 deletions docker/dev-full/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -249,3 +255,7 @@ volumes:
vector-server-data:
foundationdb-data:
foundationdb-storage-data:

secrets:
fontawesome_package_token:
environment: FONTAWESOME_PACKAGE_TOKEN
3 changes: 2 additions & 1 deletion docker/universal/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 \
Expand Down
117 changes: 51 additions & 66 deletions frontend/packages/icons/scripts/postinstall.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,30 @@
const { isPackageExists, getPackageInfo } = require("local-pkg");
const fs = require("node:fs");
const dedent = require("dedent");
const { spawnSync } = require("node:child_process");
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", "");
Expand All @@ -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
`;
Expand All @@ -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`;
}
}
}
Expand All @@ -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`;
Expand Down
3 changes: 3 additions & 0 deletions packages/common/hub-embed/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

println!("cargo:rerun-if-changed={}", hub_path.display());

// Relevant package tokens
println!("cargo:rerun-if-env-changed=FONTAWESOME_PACKAGE_TOKEN");

Ok(())
}

0 comments on commit f020c2f

Please sign in to comment.