-
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.
- Loading branch information
Showing
4 changed files
with
69 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
|
||
const __filename = fileURLToPath(import.meta.url); | ||
const __dirname = path.dirname(__filename); | ||
|
||
const packageJsonPath = path.resolve(__dirname, './package.json'); | ||
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf-8')); | ||
|
||
const distDir = path.resolve(__dirname, '../dist'); | ||
|
||
const exports = { | ||
'./package.json': './package.json', | ||
'.': { | ||
import: './dist/index.js', | ||
default: './dist/index.cjs', | ||
}, | ||
}; | ||
|
||
function addExports(dir, basePath = '.') { | ||
fs.readdirSync(dir).forEach((file) => { | ||
const filePath = path.join(dir, file); | ||
const stat = fs.statSync(filePath); | ||
|
||
if (stat.isDirectory()) { | ||
addExports(filePath, `${basePath}/${file}`); | ||
} else { | ||
const match = file.match(/^(.*)\.(js|cjs)$/); | ||
if (match) { | ||
const componentName = match[1]; | ||
exports[`${basePath}/${componentName}`] = { | ||
import: `./dist/${componentName}.js`, | ||
default: `./dist/${componentName}.cjs`, | ||
}; | ||
} | ||
} | ||
}); | ||
} | ||
|
||
addExports(distDir); | ||
|
||
packageJson.exports = exports; | ||
fs.writeFileSync( | ||
packageJsonPath, | ||
JSON.stringify(packageJson, null, 2), | ||
'utf-8', | ||
); | ||
|
||
console.log('Campo `exports` actualizado en package.json'); |
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,13 +1,15 @@ | ||
import { defineConfig } from 'tsup'; | ||
import { resolve } from 'node:path'; | ||
|
||
export default defineConfig({ | ||
entryPoints: [ | ||
resolve(__dirname, 'lib/index.ts'), | ||
resolve(__dirname, 'lib/styles.ts'), | ||
entry: [ | ||
'!lib/**/*.test.(tsx|ts)', | ||
'!lib/**/*.stories.(tsx|ts)', | ||
'./lib/**/*.(tsx|ts)', | ||
], | ||
format: ['cjs', 'esm'], | ||
dts: true, | ||
outDir: 'dist', | ||
clean: true, | ||
bundle: false, | ||
splitting: true, | ||
}); |