Skip to content

Commit

Permalink
chore: restore removed icons to avoid a breaking release
Browse files Browse the repository at this point in the history
@carbon/icons may remove icons between minor versions. However, such an action is considered a breaking change for this library. To get around this  – and to be able to use the latest version – we can install older version of the @carbon/icons package and merge in deprecated icons.

This way, we can continuously add in new icons without breaking existing usage (which would require a major version release).
  • Loading branch information
metonym committed Feb 20, 2024
1 parent c0d65a1 commit 53dd744
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 7 deletions.
4 changes: 3 additions & 1 deletion ICON_INDEX.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Icon Index

> 2231 icons from [@carbon/icons@11.36.0](https://unpkg.com/browse/@carbon/[email protected]/)
> 2233 icons from [@carbon/icons@11.36.0](https://unpkg.com/browse/@carbon/[email protected]/)
- Accessibility
- AccessibilityAlt
Expand Down Expand Up @@ -786,6 +786,7 @@
- Forward_10
- Forward_30
- Forward_5
- FoundationModel
- Fragile
- Friendship
- FruitBowl
Expand Down Expand Up @@ -1007,6 +1008,7 @@
- IncompleteWarning
- IncreaseLevel
- Industry
- Infinity
- InfinitySymbol
- Information
- InformationDisabled
Expand Down
Binary file modified bun.lockb
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/src/build-info.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"devDependencies": {
"@carbon/icon-helpers": "latest",
"@carbon/icons": "11.36.0",
"@carbon/icons-11.31": "npm:@carbon/[email protected]",
"@types/bun": "latest",
"@types/carbon__icon-helpers": "latest",
"svelte": "latest",
Expand Down
2 changes: 1 addition & 1 deletion src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ declare module "@carbon/icons" {
}

export interface BuildIcons {
icons: ReadonlyArray<{
icons: Array<{
name: string;
friendlyName: string;
namespace: [];
Expand Down
33 changes: 30 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,40 @@
import type { BuildIcons, IconOutput, ModuleName } from "@carbon/icons";
import metadata from "@carbon/icons/metadata.json";
import metadata_11_31 from "@carbon/icons-11.31/metadata.json";
import metadata_latest from "@carbon/icons/metadata.json";
import fsp from "fs/promises";
import { devDependencies, name } from "../package.json";
import { template, templateSvg } from "./template";

const VERSION = devDependencies["@carbon/icons"];

/**
* This library is built using the `@carbon/icons` package.
* However, `@carbon/icons` may remove icons between minor versions.
* This library has a different contract; icons are not removed
* in minor versions. To ensure that icons are not removed, we
* maintain a list of deprecated icons that are merged in.
*/
const DEPRECATED_ICONS = new Set([
// From 11.31.x
"FoundationModel",
"Infinity",
]);

const metadata = { ...metadata_latest } as BuildIcons;

// Merge in deprecated icons
(metadata_11_31 as BuildIcons).icons.forEach((icon) => {
icon.output.forEach((output) => {
const iconName = output.moduleName.slice(0, -2);

if (DEPRECATED_ICONS.has(iconName)) {
metadata.icons.push(icon);
}
});
});

export const buildIcons = async () => {
console.time("Built in");
console.time("buildIcons");
const iconMap = new Map<ModuleName, IconOutput>();
const iconModuleNames = (metadata as BuildIcons).icons
.map((icon) =>
Expand Down Expand Up @@ -139,7 +166,7 @@ ${iconModuleNames
})
);

console.timeEnd("Built in");
console.timeEnd("buildIcons");

return iconModuleNames;
};
2 changes: 2 additions & 0 deletions tests/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,7 @@ exports[`imports 1`] = `
"Forward_10",
"Forward_30",
"Forward_5",
"FoundationModel",
"Fragile",
"Friendship",
"FruitBowl",
Expand Down Expand Up @@ -1007,6 +1008,7 @@ exports[`imports 1`] = `
"IncompleteWarning",
"IncreaseLevel",
"Industry",
"Infinity",
"InfinitySymbol",
"Information",
"InformationDisabled",
Expand Down
2 changes: 1 addition & 1 deletion tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { template } from "../src/template";

test("imports", async () => {
const icons = await buildIcons();
expect(icons.length).toEqual(2231);
expect(icons.length).toEqual(2233);
expect(icons).toMatchSnapshot();
});

Expand Down

0 comments on commit 53dd744

Please sign in to comment.