Skip to content

Commit 2eac298

Browse files
authored
Reduce size of icon package.json for ESM (#3810)
Use exports field subpattern to reduce size of package.json for icons
1 parent 22cb32d commit 2eac298

File tree

7 files changed

+25
-5534
lines changed

7 files changed

+25
-5534
lines changed

packages/@spectrum-icons/build-tools/generateIcons.js

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -55,29 +55,3 @@ export function generateIcons(iconDir, outputDir, nameRegex, template) {
5555
writeToFile(indexFilepath, indexFile);
5656
});
5757
}
58-
59-
60-
/**
61-
* Takes an icon directory and add all the built files to the exports.
62-
* @param iconDir Root icon directory.
63-
*/
64-
export function addPackageExports(iconPackageDir) {
65-
fs.readdir(iconPackageDir, (err, items) => {
66-
let iconFiles = items.filter(item => !!item.endsWith('.mjs'));
67-
68-
// add all exports fields to package.json
69-
let pkgJsonFilepath = path.join(iconPackageDir, 'package.json');
70-
let pkgJson = JSON.parse(fs.readFileSync(pkgJsonFilepath), 'utf-8');
71-
pkgJson.exports = {};
72-
iconFiles.forEach(icon => {
73-
let iconFileName = path.basename(icon).substring(0, icon.length - 4);
74-
pkgJson.exports[`./${iconFileName}`] = {
75-
'types': `./${iconFileName}.d.ts`,
76-
'require': `./${iconFileName}.js`,
77-
'import': `./${iconFileName}.mjs`
78-
};
79-
});
80-
let pkg = JSON.stringify(pkgJson, null, 2);
81-
fs.writeFileSync(pkgJsonFilepath, `${pkg}\n`);
82-
});
83-
}

packages/@spectrum-icons/color/package.json

Lines changed: 5 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
"scripts": {
1111
"build-cjs": "cross-env BUILD_ENV=production babel --root-mode upward src -d . --extensions '.ts,.tsx'",
1212
"build-esm": "cross-env BUILD_ENV=production babel src -d . --extensions '.ts,.tsx' --out-file-extension '.mjs' --config-file '../../../babel-esm.config.json'",
13-
"add-exports": "babel-node --presets @babel/env ./scripts/addExports.js -i '[]'",
1413
"generate-types": "tsc --project ./tsconfig.types.json",
15-
"build-icons": "yarn build-cjs && yarn build-esm && yarn generate-types && yarn add-exports",
14+
"build-icons": "yarn build-cjs && yarn build-esm",
1615
"make-icons": "babel-node --presets @babel/env ./scripts/generateIcons.js -i '[]' && yarn generate-types"
1716
},
1817
"dependencies": {
@@ -31,95 +30,10 @@
3130
"access": "public"
3231
},
3332
"exports": {
34-
"./CalendarCheckColor": {
35-
"types": "./CalendarCheckColor.d.ts",
36-
"require": "./CalendarCheckColor.js",
37-
"import": "./CalendarCheckColor.mjs"
38-
},
39-
"./EmotionAdmirationColor": {
40-
"types": "./EmotionAdmirationColor.d.ts",
41-
"require": "./EmotionAdmirationColor.js",
42-
"import": "./EmotionAdmirationColor.mjs"
43-
},
44-
"./EmotionAngerColor": {
45-
"types": "./EmotionAngerColor.d.ts",
46-
"require": "./EmotionAngerColor.js",
47-
"import": "./EmotionAngerColor.mjs"
48-
},
49-
"./EmotionAnticipationColor": {
50-
"types": "./EmotionAnticipationColor.d.ts",
51-
"require": "./EmotionAnticipationColor.js",
52-
"import": "./EmotionAnticipationColor.mjs"
53-
},
54-
"./EmotionDisgustColor": {
55-
"types": "./EmotionDisgustColor.d.ts",
56-
"require": "./EmotionDisgustColor.js",
57-
"import": "./EmotionDisgustColor.mjs"
58-
},
59-
"./EmotionFearColor": {
60-
"types": "./EmotionFearColor.d.ts",
61-
"require": "./EmotionFearColor.js",
62-
"import": "./EmotionFearColor.mjs"
63-
},
64-
"./EmotionJoyColor": {
65-
"types": "./EmotionJoyColor.d.ts",
66-
"require": "./EmotionJoyColor.js",
67-
"import": "./EmotionJoyColor.mjs"
68-
},
69-
"./EmotionSadnessColor": {
70-
"types": "./EmotionSadnessColor.d.ts",
71-
"require": "./EmotionSadnessColor.js",
72-
"import": "./EmotionSadnessColor.mjs"
73-
},
74-
"./EmotionSurpriseColor": {
75-
"types": "./EmotionSurpriseColor.d.ts",
76-
"require": "./EmotionSurpriseColor.js",
77-
"import": "./EmotionSurpriseColor.mjs"
78-
},
79-
"./ImageCheckColor": {
80-
"types": "./ImageCheckColor.d.ts",
81-
"require": "./ImageCheckColor.js",
82-
"import": "./ImageCheckColor.mjs"
83-
},
84-
"./LinkCheckColor": {
85-
"types": "./LinkCheckColor.d.ts",
86-
"require": "./LinkCheckColor.js",
87-
"import": "./LinkCheckColor.mjs"
88-
},
89-
"./ProjectCameraColor": {
90-
"types": "./ProjectCameraColor.d.ts",
91-
"require": "./ProjectCameraColor.js",
92-
"import": "./ProjectCameraColor.mjs"
93-
},
94-
"./ProjectColor": {
95-
"types": "./ProjectColor.d.ts",
96-
"require": "./ProjectColor.js",
97-
"import": "./ProjectColor.mjs"
98-
},
99-
"./ProjectPlayColor": {
100-
"types": "./ProjectPlayColor.d.ts",
101-
"require": "./ProjectPlayColor.js",
102-
"import": "./ProjectPlayColor.mjs"
103-
},
104-
"./ProjectRefreshColor": {
105-
"types": "./ProjectRefreshColor.d.ts",
106-
"require": "./ProjectRefreshColor.js",
107-
"import": "./ProjectRefreshColor.mjs"
108-
},
109-
"./UserCircleColor": {
110-
"types": "./UserCircleColor.d.ts",
111-
"require": "./UserCircleColor.js",
112-
"import": "./UserCircleColor.mjs"
113-
},
114-
"./UserGroupCircleColor": {
115-
"types": "./UserGroupCircleColor.d.ts",
116-
"require": "./UserGroupCircleColor.js",
117-
"import": "./UserGroupCircleColor.mjs"
118-
},
119-
"./index": {
120-
"types": "./index.d.ts",
121-
"require": "./index.js",
122-
"import": "./index.mjs"
33+
"./*": {
34+
"types": "./*.d.ts",
35+
"import": "./*.mjs",
36+
"require": "./*.js"
12337
}
12438
}
12539
}

0 commit comments

Comments
 (0)