-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(uniform): add logic to add exports with tsup
- Loading branch information
Showing
9 changed files
with
87 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './slugify/slugify'; |
File renamed without changes.
4 changes: 3 additions & 1 deletion
4
packages/uniform/src/helpers/slugify.ts → ...es/uniform/src/helpers/slugify/slugify.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/uniform/src/partials/FieldValidationError/FieldValidationError.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,51 @@ | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
/* eslint-disable import/no-extraneous-dependencies */ | ||
|
||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
import { defineConfig } from 'tsup'; | ||
|
||
function getAllFilePaths(dirPath: string): string[] { | ||
return fs.readdirSync(dirPath).reduce<string[]>((allFiles, file) => { | ||
const fullPath = path.join(dirPath, file); | ||
if (fs.statSync(fullPath).isDirectory()) { | ||
return allFiles.concat(getAllFilePaths(fullPath)); | ||
} | ||
return allFiles.concat(`./${fullPath}`); | ||
}, []); | ||
} | ||
|
||
export default defineConfig({ | ||
entry: getAllFilePaths('./src') | ||
.flat() | ||
.filter((file) => file.endsWith('index.ts')), | ||
format: ['esm', 'cjs'], | ||
splitting: true, | ||
sourcemap: true, | ||
clean: true, | ||
dts: true, | ||
entry: [ | ||
'src', | ||
'!src/**/__snapshots__/**', | ||
'!src/**/*.module.css', | ||
'!src/**/*.stories.*', | ||
'!src/**/*.test.*', | ||
], | ||
format: ['cjs', 'esm'], | ||
loader: { | ||
// for css modules | ||
// see: https://github.com/egoist/tsup/issues/536 | ||
'.css': 'local-css', | ||
outDir: 'dist', | ||
// update exports of package.json | ||
onSuccess: async () => { | ||
const packageJsonPath = './package.json'; | ||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); | ||
const distIndexFiles = getAllFilePaths('./dist').filter((file) => | ||
file.endsWith('index.js'), | ||
); | ||
|
||
packageJson.exports = distIndexFiles.reduce< | ||
Record<string, { import: string; require: string; types: string }> | ||
>((exports, file) => { | ||
const key = file.replace('dist/', '').replace('/index.js', ''); | ||
// eslint-disable-next-line no-param-reassign | ||
exports[key] = { | ||
import: file, | ||
require: file.replace('.js', '.cjs'), | ||
types: file.replace('.js', '.d.ts'), | ||
}; | ||
return exports; | ||
}, {}); | ||
|
||
fs.writeFileSync(packageJsonPath, JSON.stringify(packageJson, null, 2)); | ||
}, | ||
sourcemap: true, | ||
}); |