Skip to content

Commit

Permalink
Read package.json to determine installed icon packs (#175)
Browse files Browse the repository at this point in the history
* fix: read package.json to determine installed icon packs

* chore: add changeset

* chore(lint): Prettier fix

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
  • Loading branch information
natemoo-re and github-actions[bot] authored Dec 28, 2023
1 parent 3819bd1 commit c8c3df3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .changeset/six-parents-know.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro-icon": patch
---

Fixes an issue that caused installed `@iconify-json/*` packages to not be detected in production environments
3 changes: 1 addition & 2 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@
"dependencies": {
"@iconify/tools": "^3.0.1",
"@iconify/types": "^2.0.0",
"@iconify/utils": "^2.1.5",
"@skarab/detect-package-manager": "^1.0.0"
"@iconify/utils": "^2.1.5"
},
"devDependencies": {
"@types/node": "^18.18.0",
Expand Down
30 changes: 6 additions & 24 deletions packages/core/src/loaders/loadIconifyCollections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ import type {
import type { AutoInstall } from "../../typings/iconify";

import { readFile } from "node:fs/promises";
import { detectAgent } from "@skarab/detect-package-manager";
import { getIcons } from "@iconify/utils";
import { loadCollectionFromFS } from "@iconify/utils/lib/loader/fs";
import { fileURLToPath } from "node:url";
import { promisify } from "node:util";
import { exec } from "node:child_process";

Expand Down Expand Up @@ -89,29 +87,13 @@ export async function loadCollection(

async function detectInstalledCollections(root: URL) {
try {
const agent = await detectAgent(fileURLToPath(root));
let packages: string[] = [];
if (!agent) {
const text = await readFile(new URL("./package.json", root), {
encoding: "utf8",
});
const { dependencies = {}, devDependencies = {} } = JSON.parse(text);
packages.push(...Object.keys(dependencies));
packages.push(...Object.keys(devDependencies));
} else {
const { stdout: text } = await execa(`${agent.name} list --json`);
const data = JSON.parse(text);
if (Array.isArray(data)) {
for (const { dependencies = {}, devDependencies = {} } of data) {
packages.push(...Object.keys(dependencies));
packages.push(...Object.keys(devDependencies));
}
} else {
const { dependencies = {}, devDependencies = {} } = data;
packages.push(...Object.keys(dependencies));
packages.push(...Object.keys(devDependencies));
}
}
const text = await readFile(new URL("./package.json", root), {
encoding: "utf8",
});
const { dependencies = {}, devDependencies = {} } = JSON.parse(text);
packages.push(...Object.keys(dependencies));
packages.push(...Object.keys(devDependencies));
const collections = packages
.filter((name) => name.startsWith("@iconify-json/"))
.map((name) => name.replace("@iconify-json/", ""));
Expand Down
11 changes: 0 additions & 11 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 comments on commit c8c3df3

@vercel
Copy link

@vercel vercel bot commented on c8c3df3 Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

api-astroicon – ./packages/service

api-astroicon-nmoo.vercel.app
api.astroicon.dev
api-astroicon-git-main-nmoo.vercel.app

@vercel
Copy link

@vercel vercel bot commented on c8c3df3 Dec 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.