Skip to content

feat: Icon builder to library #8203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 58 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
eb2367f
icon library builder
snowystinger Apr 23, 2025
e3197a6
save
snowystinger Apr 23, 2025
f39c8f4
cleanup
snowystinger Apr 23, 2025
f66c302
remove dep
snowystinger Apr 23, 2025
fb79303
fix some versions
snowystinger Apr 23, 2025
d0c6805
add back private
snowystinger Apr 23, 2025
a974371
fix yarn lock
snowystinger Apr 23, 2025
eb07253
fix lint
snowystinger Apr 23, 2025
c3cda55
update deps
snowystinger Apr 23, 2025
d878af2
fix yarn constraints
snowystinger Apr 23, 2025
4405518
add missing dep
snowystinger Apr 23, 2025
059fbab
fix lint yet again
snowystinger Apr 23, 2025
b5a6263
fix executable
snowystinger Apr 23, 2025
165ec9c
fix yarn lock
snowystinger Apr 23, 2025
5498369
Add dependencies
snowystinger Apr 23, 2025
d5cd442
bump down glob
snowystinger Apr 24, 2025
c833bb5
add swc helpers
snowystinger Apr 24, 2025
2376198
try again
snowystinger Apr 24, 2025
935691d
remove non-dependency
snowystinger Apr 24, 2025
40ece33
move some more things around
snowystinger Apr 24, 2025
7a9e62f
Merge branch 'main' into icons
snowystinger Apr 24, 2025
809fc42
Add swc/helpers to
snowystinger Apr 24, 2025
ec9fdf9
remove ts as a dependency
snowystinger Apr 24, 2025
0909fb7
make test more realistic to use case
snowystinger Apr 25, 2025
676fe82
fix sub yarn project
snowystinger Apr 25, 2025
fb15755
fix install
snowystinger Apr 25, 2025
34ae776
publish namer plugin
snowystinger Apr 25, 2025
6b2aca7
fix builder
snowystinger Apr 25, 2025
ff79bfe
add swc helpers
snowystinger Apr 25, 2025
86c431f
fix test
snowystinger May 6, 2025
4d359dd
fix swc/helpers
snowystinger May 6, 2025
56e33aa
remove namer?
snowystinger May 6, 2025
5675fb8
write to root and see if removing exports field fixes duplicates
snowystinger May 6, 2025
2d0cd4c
remove default as maybe duplicate causing
snowystinger May 6, 2025
28fd7ab
debug output
snowystinger May 6, 2025
cc1608d
try updating the namer
snowystinger May 7, 2025
1def4d4
generate ts files
snowystinger May 7, 2025
e0d1c11
fix timing of async function
snowystinger May 7, 2025
0b42921
add another icon
snowystinger May 7, 2025
22fd984
Merge branch 'main' into icons
snowystinger May 7, 2025
db3b804
hopefully fix source maps for library
snowystinger May 7, 2025
cc0b9a1
attempt to get rid of esmodule helper
snowystinger May 8, 2025
0b06754
remove console logs and dead code
snowystinger May 8, 2025
fd8932b
Add real application to test icon builder
snowystinger May 8, 2025
65f81ac
use correct path
snowystinger May 8, 2025
9d4930e
Make sure app builds without icon
snowystinger May 8, 2025
946b414
Add icon back in
snowystinger May 8, 2025
c549352
we use bundler-library, so use it here too
snowystinger May 8, 2025
fecc412
try more configs to mimic our own setup
snowystinger May 8, 2025
1f59b63
add browsers list
snowystinger May 8, 2025
92ac4e5
add mode production
snowystinger May 8, 2025
f3c2a03
fix hoisting
snowystinger May 8, 2025
9377246
update dependencies
snowystinger May 8, 2025
efe0a83
fix browsers list
snowystinger May 8, 2025
ee66ef5
remove dead code
snowystinger May 8, 2025
a9bb8ea
fix version number
snowystinger May 8, 2025
605cfef
turn off verdaccio
snowystinger May 9, 2025
19f2fbd
Merge branch 'main' into icons
snowystinger May 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/comment.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ async function run() {
[RAC Tailwind Example](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/verdaccio/rac-tailwind/index.html)
[RAC Spectrum + Tailwind Example](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/verdaccio/rac-spectrum-tailwind/index.html)
[S2 Parcel Example](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/verdaccio/s2-parcel-example/index.html)
[S2 Custom Icons](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/verdaccio/icon-builder-fixture/index.html)
[S2 Webpack Example](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/verdaccio/s2-webpack-5-example/index.html)
[CRA Test App Size](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/verdaccio/publish-stats/build-stats.txt)
[NextJS App Size](https://reactspectrum.blob.core.windows.net/reactspectrum/${process.env.CIRCLE_SHA1}/verdaccio/publish-stats/next-build-stats.txt)
Expand Down
5 changes: 5 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,11 @@ jobs:
environment:
VERDACCIO_STORAGE_PATH: /tmp/verdaccio-workspace/storage

- persist_to_workspace:
root: verdaccio_dist
paths:
- '*/verdaccio/icon-builder-fixture'

v-publish-stats:
executor: rsp
steps:
Expand Down
2 changes: 1 addition & 1 deletion .parcelrc-build
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@parcel/transformer-react-refresh-wrap"
]
},
"namers": ["parcel-namer-s2", "parcel-namer-intl", "..."],
"namers": ["@react-spectrum/parcel-namer-s2", "parcel-namer-intl", "..."],
"optimizers": {
"**/spectrum-theme.cjs": ["parcel-optimizer-strict-mode"]
}
Expand Down
1 change: 1 addition & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export default [{
"packages/dev/optimize-locales-plugin/LocalesPlugin.d.ts",
"examples/**/*",
"starters/**/*",
"scripts/icon-builder-fixture/**/*",
"packages/@react-spectrum/s2/icon.d.ts",
"packages/@react-spectrum/s2/spectrum-illustrations"
],
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@
"@parcel/transformer-inline-string": "^2.14.0",
"@parcel/transformer-svg-react": "^2.14.0",
"@parcel/transformer-typescript-types": "^2.14.0",
"@react-spectrum/parcel-namer-s2": "^1.0.0",
"@react-spectrum/s2-icon-builder": "^0.2.0",
"@spectrum-css/component-builder": "workspace:^",
"@spectrum-css/vars": "^2.3.0",
Expand Down Expand Up @@ -222,6 +223,9 @@
"@babel/preset-env": "7.24.4",
"@babel/traverse": "7.24.1",
"@babel/types": "7.24.0",
"@parcel/transformer-react-refresh-wrap": "2.14.0",
"@parcel/transformer-js": "2.14.0",
"@parcel/codeframe": "2.14.0",
Copy link
Member

Choose a reason for hiding this comment

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

?

"postcss": "8.4.24",
"postcss-custom-properties": "13.2.0",
"postcss-import": "15.1.0",
Expand Down
22 changes: 22 additions & 0 deletions packages/dev/parcel-namer-s2/S2Namer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,28 @@ const path = require('path');
module.exports = new Namer({
name({bundle}) {
let mainAsset = bundle.getMainEntry();

if (!mainAsset?.filePath.includes('react-spectrum/packages')) {
Copy link
Member

Choose a reason for hiding this comment

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

This is the same logic as below? Could the if conditions be merged?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, so open question about this due to ask for non-20 sized icons
I had it originally separate though as a reminder to see if there was a better condition we could use

if (bundle.needsStableName && bundle.target.distEntry) {
return bundle.target.distEntry;
}
let ext = '.' + bundle.type;
if (bundle.type === 'js') {
ext = bundle.env.outputFormat === 'esmodule' ? '.mjs' : '.cjs';
}
let originalExt = path.extname(mainAsset.filePath);
let name = path.basename(mainAsset.filePath, originalExt).replace(/\*/g, 'intlStrings');

return name
.replace(/^S2_Icon_(.*?)(Size\d+)?_\d+(?:x\d+)?_N$/, '$1')
.replace(/^S2_(fill|lin)_(.+)_(generic\d)_(\d+)$/, (m, type, name, style) => {
name = name[0].toUpperCase() + name.slice(1).replace(/_/g, '');
return 'gradient/' + style + '/' + name;
})
.replace(/\.module$/, '_module')
+ ext;
}

if (mainAsset?.filePath.includes('@react-spectrum/s2')) {
if (bundle.needsStableName && bundle.target.distEntry) {
return bundle.target.distEntry;
Expand Down
3 changes: 1 addition & 2 deletions packages/dev/parcel-namer-s2/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
{
"name": "parcel-namer-s2",
"name": "@react-spectrum/parcel-namer-s2",
"version": "1.0.0",
"main": "S2Namer.js",
"private": true,
"engines": {
"parcel": "^2.0.0"
},
Expand Down
12 changes: 12 additions & 0 deletions packages/dev/s2-icon-builder/.parcelrc-library
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "@parcel/config-default",
"namers": ["@react-spectrum/parcel-namer-s2", "@parcel/namer-default"],
"bundler": "@parcel/bundler-library",
"transformers": {
"*.svg": ["@react-spectrum/parcel-transformer-s2-icon"],
"*.{js,mjs,jsm,jsx,es6,cjs,ts,tsx}": [
"@parcel/transformer-js",
"@parcel/transformer-react-refresh-wrap"
]
}
}
58 changes: 55 additions & 3 deletions packages/dev/s2-icon-builder/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/usr/bin/env node

let path = require('path');
let {Parcel} = require('@parcel/core');
let {parseArgs} = require('util');
let globSync = require('glob').sync;
let fs = require('fs');

const args = parseArgs({
options: {
Expand All @@ -17,11 +20,14 @@ const args = parseArgs({
output: {
type: 'string',
short: 'o'
},
isLibrary: {
type: 'boolean'
}
}
});

let bundler = new Parcel({
let options = {
entries: args.values.input,
config: require.resolve('@react-spectrum/s2-icon-builder/.parcelrc'),
shouldDisableCache: true,
Expand All @@ -38,7 +44,42 @@ let bundler = new Parcel({
engines: {
browsers: ['last 1 Chrome version']
}
});
};

if (args.values.isLibrary) {
options = {
entries: args.values.input,
config: require.resolve('@react-spectrum/s2-icon-builder/.parcelrc-library'),
shouldDisableCache: true,
mode: 'production',
defaultTargetOptions: {
shouldScopeHoist: true,
shouldOptimize: false
},
targets: {
[`${args.values.type}-module`]: {
distDir: args.values.output,
isLibrary: true,
includeNodeModules: false,
outputFormat: 'esmodule',
engines: {
browsers: ['last 2 Chrome versions, last 2 Safari versions, last 2 Firefox versions, last 2 Edge versions']
}
},
[`${args.values.type}-main`]: {
distDir: args.values.output,
isLibrary: true,
includeNodeModules: false,
outputFormat: 'commonjs',
engines: {
browsers: ['last 2 Chrome versions, last 2 Safari versions, last 2 Firefox versions, last 2 Edge versions']
}
}
}
};
}

let bundler = new Parcel(options);

async function run() {
try {
Expand All @@ -50,4 +91,15 @@ async function run() {
}
}

run();
run().then(() => {
if (args.values.isLibrary) {
for (let file of globSync(`${path.join(args.values.output, '.')}/*.mjs`)) {
fs.writeFileSync(file.replace('.mjs', '.d.ts'), `import type {IconProps} from '@react-spectrum/s2';
import type {ReactNode} from 'react';

declare function Icon(props: IconProps): ReactNode;
export default Icon;
`);
}
}
});
19 changes: 16 additions & 3 deletions packages/dev/s2-icon-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,33 @@
"dependencies": {
"@parcel/bundler-library": "^2.14.0",
"@parcel/compressor-raw": "^2.14.0",
"@parcel/config-default": "^2.14.0",
"@parcel/core": "^2.14.0",
"@parcel/namer-default": "^2.14.0",
"@parcel/packager-raw": "^2.14.0",
"@parcel/plugin": "^2.14.0",
"@parcel/reporter-cli": "^2.14.0",
"@parcel/resolver-default": "^2.14.0",
"@parcel/transformer-js": "^2.14.0",
"@parcel/transformer-raw": "^2.14.0",
"@react-spectrum/parcel-transformer-s2-icon": "^0.2.1"
"@parcel/transformer-react-refresh-wrap": "^2.14.0",
"@react-spectrum/parcel-namer-s2": "^1.0.0",
"@react-spectrum/parcel-transformer-s2-icon": "^0.2.1",
"@swc/helpers": "^0.5.0",
"glob": "^8.0.3"
},
"peerDependencies": {
"@react-spectrum/s2": ">=0.8.0",
"react": "^18.0.0 || ^19.0.0-rc.1",
"react-dom": "^18.0.0 || ^19.0.0-rc.1"
},
"files": [
"index.js",
".parcelrc"
".parcelrc",
".parcelrc-library"
],
"engines": {
"node": ">=18.0.0"
"node": ">=20.0.0"
},
"rsp": {
"type": "cli"
Expand Down
3 changes: 3 additions & 0 deletions scripts/icon-builder-fixture/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store
node_modules
package-lock.json
Loading