Skip to content
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

Reduce size of icon package.json for ESM #3810

Merged
merged 9 commits into from
Dec 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
26 changes: 0 additions & 26 deletions packages/@spectrum-icons/build-tools/generateIcons.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,29 +55,3 @@ export function generateIcons(iconDir, outputDir, nameRegex, template) {
writeToFile(indexFilepath, indexFile);
});
}


/**
* Takes an icon directory and add all the built files to the exports.
* @param iconDir Root icon directory.
*/
export function addPackageExports(iconPackageDir) {
fs.readdir(iconPackageDir, (err, items) => {
let iconFiles = items.filter(item => !!item.endsWith('.mjs'));

// add all exports fields to package.json
let pkgJsonFilepath = path.join(iconPackageDir, 'package.json');
let pkgJson = JSON.parse(fs.readFileSync(pkgJsonFilepath), 'utf-8');
pkgJson.exports = {};
iconFiles.forEach(icon => {
let iconFileName = path.basename(icon).substring(0, icon.length - 4);
pkgJson.exports[`./${iconFileName}`] = {
'types': `./${iconFileName}.d.ts`,
'require': `./${iconFileName}.js`,
'import': `./${iconFileName}.mjs`
};
});
let pkg = JSON.stringify(pkgJson, null, 2);
fs.writeFileSync(pkgJsonFilepath, `${pkg}\n`);
});
}
96 changes: 5 additions & 91 deletions packages/@spectrum-icons/color/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@
"scripts": {
"build-cjs": "cross-env BUILD_ENV=production babel --root-mode upward src -d . --extensions '.ts,.tsx'",
"build-esm": "cross-env BUILD_ENV=production babel src -d . --extensions '.ts,.tsx' --out-file-extension '.mjs' --config-file '../../../babel-esm.config.json'",
"add-exports": "babel-node --presets @babel/env ./scripts/addExports.js -i '[]'",
"generate-types": "tsc --project ./tsconfig.types.json",
"build-icons": "yarn build-cjs && yarn build-esm && yarn generate-types && yarn add-exports",
"build-icons": "yarn build-cjs && yarn build-esm",
"make-icons": "babel-node --presets @babel/env ./scripts/generateIcons.js -i '[]' && yarn generate-types"
},
"dependencies": {
Expand All @@ -31,95 +30,10 @@
"access": "public"
},
"exports": {
"./CalendarCheckColor": {
"types": "./CalendarCheckColor.d.ts",
"require": "./CalendarCheckColor.js",
"import": "./CalendarCheckColor.mjs"
},
"./EmotionAdmirationColor": {
"types": "./EmotionAdmirationColor.d.ts",
"require": "./EmotionAdmirationColor.js",
"import": "./EmotionAdmirationColor.mjs"
},
"./EmotionAngerColor": {
"types": "./EmotionAngerColor.d.ts",
"require": "./EmotionAngerColor.js",
"import": "./EmotionAngerColor.mjs"
},
"./EmotionAnticipationColor": {
"types": "./EmotionAnticipationColor.d.ts",
"require": "./EmotionAnticipationColor.js",
"import": "./EmotionAnticipationColor.mjs"
},
"./EmotionDisgustColor": {
"types": "./EmotionDisgustColor.d.ts",
"require": "./EmotionDisgustColor.js",
"import": "./EmotionDisgustColor.mjs"
},
"./EmotionFearColor": {
"types": "./EmotionFearColor.d.ts",
"require": "./EmotionFearColor.js",
"import": "./EmotionFearColor.mjs"
},
"./EmotionJoyColor": {
"types": "./EmotionJoyColor.d.ts",
"require": "./EmotionJoyColor.js",
"import": "./EmotionJoyColor.mjs"
},
"./EmotionSadnessColor": {
"types": "./EmotionSadnessColor.d.ts",
"require": "./EmotionSadnessColor.js",
"import": "./EmotionSadnessColor.mjs"
},
"./EmotionSurpriseColor": {
"types": "./EmotionSurpriseColor.d.ts",
"require": "./EmotionSurpriseColor.js",
"import": "./EmotionSurpriseColor.mjs"
},
"./ImageCheckColor": {
"types": "./ImageCheckColor.d.ts",
"require": "./ImageCheckColor.js",
"import": "./ImageCheckColor.mjs"
},
"./LinkCheckColor": {
"types": "./LinkCheckColor.d.ts",
"require": "./LinkCheckColor.js",
"import": "./LinkCheckColor.mjs"
},
"./ProjectCameraColor": {
"types": "./ProjectCameraColor.d.ts",
"require": "./ProjectCameraColor.js",
"import": "./ProjectCameraColor.mjs"
},
"./ProjectColor": {
"types": "./ProjectColor.d.ts",
"require": "./ProjectColor.js",
"import": "./ProjectColor.mjs"
},
"./ProjectPlayColor": {
"types": "./ProjectPlayColor.d.ts",
"require": "./ProjectPlayColor.js",
"import": "./ProjectPlayColor.mjs"
},
"./ProjectRefreshColor": {
"types": "./ProjectRefreshColor.d.ts",
"require": "./ProjectRefreshColor.js",
"import": "./ProjectRefreshColor.mjs"
},
"./UserCircleColor": {
"types": "./UserCircleColor.d.ts",
"require": "./UserCircleColor.js",
"import": "./UserCircleColor.mjs"
},
"./UserGroupCircleColor": {
"types": "./UserGroupCircleColor.d.ts",
"require": "./UserGroupCircleColor.js",
"import": "./UserGroupCircleColor.mjs"
},
"./index": {
"types": "./index.d.ts",
"require": "./index.js",
"import": "./index.mjs"
"./*": {
"types": "./*.d.ts",
"import": "./*.mjs",
"require": "./*.js"
}
}
}
Loading