Skip to content

Commit

Permalink
feat: generate d.mts files for better type coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
skjalgepalg committed Oct 10, 2023
1 parent 767e42f commit 3e4cb00
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
8 changes: 8 additions & 0 deletions bin/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@ function clean (groupNames) {
fse.removeSync(path.join(npmPath, `${bundleName}.js`))
fse.removeSync(path.join(npmPath, `${bundleName}.mjs`))
fse.removeSync(path.join(npmPath, `${bundleName}.d.ts`))
fse.removeSync(path.join(npmPath, `${bundleName}.d.mts`))
// Remove old npm jsx content
fse.removeSync(path.join(npmJsxFolder, npmPath, `${bundleName}.js`))
fse.removeSync(path.join(npmJsxFolder, npmPath, `${bundleName}.mjs`))
fse.removeSync(path.join(npmJsxFolder, npmPath, `${bundleName}.d.ts`))
fse.removeSync(path.join(npmJsxFolder, npmPath, `${bundleName}.d.mts`))

// Ensure npm folders exist (for icons it's '' which is falsy)
if (npmPath) fse.mkdirsSync(npmPath)
Expand Down Expand Up @@ -140,11 +142,13 @@ function buildIcons (groupName) {
fse.writeFileSync(path.join(npmPath, `${bundleName}.js`), icons.cjs)
fse.writeFileSync(path.join(npmPath, `${bundleName}.mjs`), icons.esm)
fse.writeFileSync(path.join(npmPath, `${bundleName}.d.ts`), icons.dts)
fse.writeFileSync(path.join(npmPath, `${bundleName}.d.mts`), icons.dts)

// Generate jsx and mjsx with types for icons and logos
fse.writeFileSync(path.join(npmJsxFolder, npmPath, `${bundleName}.js`), icons.cjsx)
fse.writeFileSync(path.join(npmJsxFolder, npmPath, `${bundleName}.mjs`), icons.esmx)
fse.writeFileSync(path.join(npmJsxFolder, npmPath, `${bundleName}.d.ts`), icons.dtsx)
fse.writeFileSync(path.join(npmJsxFolder, npmPath, `${bundleName}.d.mts`), icons.dtsx)

// Generate js/jsx artefacts for logo/large -files
if (groupName === 'logo') {
Expand All @@ -162,20 +166,24 @@ function buildIcons (groupName) {
fse.removeSync(path.join(npmLargePath, `${largeBundleName}.js`))
fse.removeSync(path.join(npmLargePath, `${largeBundleName}.mjs`))
fse.removeSync(path.join(npmLargePath, `${largeBundleName}.d.ts`))
fse.removeSync(path.join(npmLargePath, `${largeBundleName}.d.mts`))
// Remove old npm jsx content
fse.removeSync(path.join(npmJsxFolder, npmLargePath, `${largeBundleName}.js`))
fse.removeSync(path.join(npmJsxFolder, npmLargePath, `${largeBundleName}.mjs`))
fse.removeSync(path.join(npmJsxFolder, npmLargePath, `${largeBundleName}.d.ts`))
fse.removeSync(path.join(npmJsxFolder, npmLargePath, `${largeBundleName}.d.mts`))

// Generate js and mjs with types for icons and logos
fse.writeFileSync(path.join(npmLargePath, `${largeBundleName}.js`), largeIcons.cjs)
fse.writeFileSync(path.join(npmLargePath, `${largeBundleName}.mjs`), largeIcons.esm)
fse.writeFileSync(path.join(npmLargePath, `${largeBundleName}.d.ts`), largeIcons.dts)
fse.writeFileSync(path.join(npmLargePath, `${largeBundleName}.d.mts`), largeIcons.dts)

// Generate jsx and mjsx with types for icons and logos
fse.writeFileSync(path.join(npmJsxFolder, npmLargePath, `${largeBundleName}.js`), largeIcons.cjsx)
fse.writeFileSync(path.join(npmJsxFolder, npmLargePath, `${largeBundleName}.mjs`), largeIcons.esmx)
fse.writeFileSync(path.join(npmJsxFolder, npmLargePath, `${largeBundleName}.d.ts`), largeIcons.dtsx)
fse.writeFileSync(path.join(npmJsxFolder, npmLargePath, `${largeBundleName}.d.mts`), largeIcons.dtsx)
}
} catch (error) {
console.error(`Failed to generate large js files for ${groupName} with error `, error)
Expand Down
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,19 @@
"./core-icons-iife.js",
"./core-icons.js",
"./core-icons.mjs",
"./core-icons.d.ts"
"./core-icons.d.ts",
"./core-icons.d.mts"
],
"exports": {
".": {
"require": "./core-icons.js",
"import": "./core-icons.mjs",
"types": "./core-icons.d.ts",
"import": {
"types": "./core-icons.d.mts",
"default": "./core-icons.mjs"
},
"require": {
"types": "./core-icons.d.ts",
"default": "./core-icons.js"
},
"browser": "./core-icons-iife.js"
},
"./logo": {
Expand Down

0 comments on commit 3e4cb00

Please sign in to comment.