Skip to content

Commit

Permalink
feat(lib): true rsc support via new ssr exports
Browse files Browse the repository at this point in the history
  • Loading branch information
rektdeckard committed Sep 15, 2023
1 parent 0fc7222 commit 1de2faf
Show file tree
Hide file tree
Showing 4,999 changed files with 86,239 additions and 64,911 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
25 changes: 20 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@phosphor-icons/react",
"version": "2.1.2",
"version": "2.1.3",
"description": "A clean and friendly icon family for React",
"author": {
"name": "Tobias Fried",
Expand All @@ -22,19 +22,34 @@
"types": "./dist/index.d.ts"
},
"./dist/icons/*": {
"import": "./dist/icons/*.mjs",
"import": "./dist/csr/*.mjs",
"require": "./dist/index.cjs",
"types": "./dist/icons/*.d.ts"
"types": "./dist/csr/*.d.ts"
},
"./dist/csr/*": {
"import": "./dist/csr/*.mjs",
"require": "./dist/index.cjs",
"types": "./dist/csr/*.d.ts"
},
"./dist/lib/*": {
"import": "./dist/lib/*.mjs",
"require": "./dist/index.cjs",
"types": "./dist/lib/*.d.ts"
},
"./dist/ssr": {
"import": "./dist/ssr/index.mjs",
"require": "./dist/index.cjs",
"types": "./dist/ssr/*.d.ts"
},
"./dist/ssr/*": {
"import": "./dist/ssr/*.mjs",
"require": "./dist/index.cjs",
"types": "./dist/ssr/*.d.ts"
},
"./*": {
"import": "./dist/icons/*.mjs",
"import": "./dist/csr/*.mjs",
"require": "./dist/index.cjs",
"types": "./dist/icons/*.d.ts"
"types": "./dist/csr/*.d.ts"
}
},
"types": "./dist/index.d.ts",
Expand Down
86 changes: 66 additions & 20 deletions scripts/assemble.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ import path from "node:path";
import chalk from "chalk";
import { exec } from "node:child_process";

import { ASSETS_PATH, COMPONENTS_PATH, INDEX_PATH } from "./index.mjs";
import {
ASSETS_PATH,
CSR_PATH,
SSR_PATH,
DEFS_PATH,
INDEX_PATH,
} from "./index.mjs";
import { ALIASES } from "../core/bin/index.js";

const icons = {};
Expand Down Expand Up @@ -103,10 +109,15 @@ function generateComponents() {
let passes = 0;
let fails = 0;

if (fs.existsSync(COMPONENTS_PATH)) {
fs.rmSync(COMPONENTS_PATH, { recursive: true });
if (fs.existsSync(CSR_PATH)) {
fs.rmSync(CSR_PATH, { recursive: true });
}
fs.mkdirSync(COMPONENTS_PATH);
fs.mkdirSync(CSR_PATH);

if (fs.existsSync(SSR_PATH)) {
fs.rmSync(SSR_PATH, { recursive: true });
}
fs.mkdirSync(SSR_PATH);

for (let key in icons) {
const icon = icons[key];
Expand All @@ -123,33 +134,56 @@ function generateComponents() {
continue;
}

let componentString = `\
let defString = `\
/* GENERATED FILE */
import { forwardRef, ReactElement } from "react";
import { IconWeight, Icon, IconBase } from "../lib";
import { ReactElement } from "react";
import { IconWeight } from "../lib";
const weights = new Map<IconWeight, ReactElement>([
export default new Map<IconWeight, ReactElement>([
${Object.entries(icon)
.map(([weight, path]) => `["${weight}", <>${path.trim()}</>]`)
.join(",")}
]);
`;

componentString += `
let csrString = `
/* GENERATED FILE */
import { forwardRef } from "react";
import type { Icon } from "../lib/types";
import IconBase from "../lib/IconBase";
import weights from "../defs/${name}";
export const ${name}: Icon = forwardRef((props, ref) => (
<IconBase ref={ref} {...props} weights={weights} />
));
${name}.displayName = "${name}";
`;

let ssrString = `
/* GENERATED FILE */
import { forwardRef } from "react";
import type { Icon } from "../lib/types";
import SSRBase from "../lib/SSRBase";
import weights from "../defs/${name}";
export const ${name}: Icon = forwardRef((props, ref) => (
<SSRBase ref={ref} {...props} weights={weights} />
));
${name}.displayName = "${name}";
`;

try {
fs.writeFileSync(
path.join(COMPONENTS_PATH, `${name}.tsx`),
componentString,
{
flag: "w",
}
);
fs.writeFileSync(path.join(CSR_PATH, `${name}.tsx`), csrString, {
flag: "w",
});
fs.writeFileSync(path.join(SSR_PATH, `${name}.tsx`), ssrString, {
flag: "w",
});
fs.writeFileSync(path.join(DEFS_PATH, `${name}.tsx`), defString, {
flag: "w",
});
console.log(`${chalk.inverse.green(" DONE ")} ${name}`);
passes += 1;
} catch (err) {
Expand All @@ -172,22 +206,34 @@ ${name}.displayName = "${name}";
}

function generateExports() {
let indexString = `\
let csrIndex = `\
/* GENERATED FILE */
export type { Icon, IconProps, IconWeight } from "./lib";
export { IconContext, IconBase } from "./lib";
`;

let ssrIndex = `\
/* GENERATED FILE */
`;
for (let key in icons) {
const name = pascalize(key);
indexString += `\
csrIndex += `\
export { ${name}${
!!ALIASES[key] ? `, ${name} as ${pascalize(ALIASES[key])}` : ""
} } from "./icons/${name}";
} } from "./csr/${name}";
`;
ssrIndex += `\
export { ${name}${
!!ALIASES[key] ? `, ${name} as ${pascalize(ALIASES[key])}` : ""
} } from "./${name}";
`;
}
try {
fs.writeFileSync(INDEX_PATH, indexString, {
fs.writeFileSync(INDEX_PATH, csrIndex, {
flag: "w",
});
fs.writeFileSync(path.join(SSR_PATH, "index.ts"), ssrIndex, {
flag: "w",
});
console.log(chalk.green("Export success"));
Expand Down
4 changes: 3 additions & 1 deletion scripts/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

export const ASSETS_PATH = path.join(__dirname, "../core/assets");
export const COMPONENTS_PATH = path.join(__dirname, "../src/icons");
export const DEFS_PATH = path.join(__dirname, "../src/defs");
export const CSR_PATH = path.join(__dirname, "../src/csr");
export const SSR_PATH = path.join(__dirname, "../src/ssr");
export const INDEX_PATH = path.join(__dirname, "../src/index.ts");
11 changes: 11 additions & 0 deletions src/csr/AddressBook.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* GENERATED FILE */
import { forwardRef } from "react";
import type { Icon } from "../lib/types";
import IconBase from "../lib/IconBase";
import weights from "../defs/AddressBook";

export const AddressBook: Icon = forwardRef((props, ref) => (
<IconBase ref={ref} {...props} weights={weights} />
));

AddressBook.displayName = "AddressBook";
11 changes: 11 additions & 0 deletions src/csr/AirTrafficControl.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* GENERATED FILE */
import { forwardRef } from "react";
import type { Icon } from "../lib/types";
import IconBase from "../lib/IconBase";
import weights from "../defs/AirTrafficControl";

export const AirTrafficControl: Icon = forwardRef((props, ref) => (
<IconBase ref={ref} {...props} weights={weights} />
));

AirTrafficControl.displayName = "AirTrafficControl";
11 changes: 11 additions & 0 deletions src/csr/Airplane.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* GENERATED FILE */
import { forwardRef } from "react";
import type { Icon } from "../lib/types";
import IconBase from "../lib/IconBase";
import weights from "../defs/Airplane";

export const Airplane: Icon = forwardRef((props, ref) => (
<IconBase ref={ref} {...props} weights={weights} />
));

Airplane.displayName = "Airplane";
11 changes: 11 additions & 0 deletions src/csr/AirplaneInFlight.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* GENERATED FILE */
import { forwardRef } from "react";
import type { Icon } from "../lib/types";
import IconBase from "../lib/IconBase";
import weights from "../defs/AirplaneInFlight";

export const AirplaneInFlight: Icon = forwardRef((props, ref) => (
<IconBase ref={ref} {...props} weights={weights} />
));

AirplaneInFlight.displayName = "AirplaneInFlight";
11 changes: 11 additions & 0 deletions src/csr/AirplaneLanding.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* GENERATED FILE */
import { forwardRef } from "react";
import type { Icon } from "../lib/types";
import IconBase from "../lib/IconBase";
import weights from "../defs/AirplaneLanding";

export const AirplaneLanding: Icon = forwardRef((props, ref) => (
<IconBase ref={ref} {...props} weights={weights} />
));

AirplaneLanding.displayName = "AirplaneLanding";
11 changes: 11 additions & 0 deletions src/csr/AirplaneTakeoff.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* GENERATED FILE */
import { forwardRef } from "react";
import type { Icon } from "../lib/types";
import IconBase from "../lib/IconBase";
import weights from "../defs/AirplaneTakeoff";

export const AirplaneTakeoff: Icon = forwardRef((props, ref) => (
<IconBase ref={ref} {...props} weights={weights} />
));

AirplaneTakeoff.displayName = "AirplaneTakeoff";
11 changes: 11 additions & 0 deletions src/csr/AirplaneTilt.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* GENERATED FILE */
import { forwardRef } from "react";
import type { Icon } from "../lib/types";
import IconBase from "../lib/IconBase";
import weights from "../defs/AirplaneTilt";

export const AirplaneTilt: Icon = forwardRef((props, ref) => (
<IconBase ref={ref} {...props} weights={weights} />
));

AirplaneTilt.displayName = "AirplaneTilt";
11 changes: 11 additions & 0 deletions src/csr/Airplay.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* GENERATED FILE */
import { forwardRef } from "react";
import type { Icon } from "../lib/types";
import IconBase from "../lib/IconBase";
import weights from "../defs/Airplay";

export const Airplay: Icon = forwardRef((props, ref) => (
<IconBase ref={ref} {...props} weights={weights} />
));

Airplay.displayName = "Airplay";
11 changes: 11 additions & 0 deletions src/csr/Alarm.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* GENERATED FILE */
import { forwardRef } from "react";
import type { Icon } from "../lib/types";
import IconBase from "../lib/IconBase";
import weights from "../defs/Alarm";

export const Alarm: Icon = forwardRef((props, ref) => (
<IconBase ref={ref} {...props} weights={weights} />
));

Alarm.displayName = "Alarm";
11 changes: 11 additions & 0 deletions src/csr/Alien.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* GENERATED FILE */
import { forwardRef } from "react";
import type { Icon } from "../lib/types";
import IconBase from "../lib/IconBase";
import weights from "../defs/Alien";

export const Alien: Icon = forwardRef((props, ref) => (
<IconBase ref={ref} {...props} weights={weights} />
));

Alien.displayName = "Alien";
11 changes: 11 additions & 0 deletions src/csr/AlignBottom.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* GENERATED FILE */
import { forwardRef } from "react";
import type { Icon } from "../lib/types";
import IconBase from "../lib/IconBase";
import weights from "../defs/AlignBottom";

export const AlignBottom: Icon = forwardRef((props, ref) => (
<IconBase ref={ref} {...props} weights={weights} />
));

AlignBottom.displayName = "AlignBottom";
11 changes: 11 additions & 0 deletions src/csr/AlignBottomSimple.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* GENERATED FILE */
import { forwardRef } from "react";
import type { Icon } from "../lib/types";
import IconBase from "../lib/IconBase";
import weights from "../defs/AlignBottomSimple";

export const AlignBottomSimple: Icon = forwardRef((props, ref) => (
<IconBase ref={ref} {...props} weights={weights} />
));

AlignBottomSimple.displayName = "AlignBottomSimple";
11 changes: 11 additions & 0 deletions src/csr/AlignCenterHorizontal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* GENERATED FILE */
import { forwardRef } from "react";
import type { Icon } from "../lib/types";
import IconBase from "../lib/IconBase";
import weights from "../defs/AlignCenterHorizontal";

export const AlignCenterHorizontal: Icon = forwardRef((props, ref) => (
<IconBase ref={ref} {...props} weights={weights} />
));

AlignCenterHorizontal.displayName = "AlignCenterHorizontal";
11 changes: 11 additions & 0 deletions src/csr/AlignCenterHorizontalSimple.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* GENERATED FILE */
import { forwardRef } from "react";
import type { Icon } from "../lib/types";
import IconBase from "../lib/IconBase";
import weights from "../defs/AlignCenterHorizontalSimple";

export const AlignCenterHorizontalSimple: Icon = forwardRef((props, ref) => (
<IconBase ref={ref} {...props} weights={weights} />
));

AlignCenterHorizontalSimple.displayName = "AlignCenterHorizontalSimple";
11 changes: 11 additions & 0 deletions src/csr/AlignCenterVertical.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* GENERATED FILE */
import { forwardRef } from "react";
import type { Icon } from "../lib/types";
import IconBase from "../lib/IconBase";
import weights from "../defs/AlignCenterVertical";

export const AlignCenterVertical: Icon = forwardRef((props, ref) => (
<IconBase ref={ref} {...props} weights={weights} />
));

AlignCenterVertical.displayName = "AlignCenterVertical";
11 changes: 11 additions & 0 deletions src/csr/AlignCenterVerticalSimple.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/* GENERATED FILE */
import { forwardRef } from "react";
import type { Icon } from "../lib/types";
import IconBase from "../lib/IconBase";
import weights from "../defs/AlignCenterVerticalSimple";

export const AlignCenterVerticalSimple: Icon = forwardRef((props, ref) => (
<IconBase ref={ref} {...props} weights={weights} />
));

AlignCenterVerticalSimple.displayName = "AlignCenterVerticalSimple";
Loading

0 comments on commit 1de2faf

Please sign in to comment.