Skip to content

Commit

Permalink
Fix: v4.x exports (#172)
Browse files Browse the repository at this point in the history
* tempting fate with an export shakeup
* released v4.0.10-next.0 - testing exports
* released v4.0.10-next.1 - included types in exports
* cleaned up rollup config
* released v4.0.10-next.2 - verifying cjs import works with or without cjs/ prefix
* released v4.0.10-next.3 - moving release source to dist
  • Loading branch information
kwhitley committed Jun 14, 2023
1 parent 44e7204 commit d83653e
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 14 deletions.
85 changes: 82 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,88 @@
{
"name": "itty-router",
"version": "4.0.9",
"version": "4.0.10-next.3",
"description": "A tiny, zero-dependency router, designed to make beautiful APIs in any environment.",
"type": "module",
"main": "./index.js",
"main": "index.js",
"module": "index.js",
"types": "index.d.ts",
"exports": {
".": {
"import": "./index.js",
"require": "./cjs/index.js",
"types": "./index.d.ts"
},
"./createCors": {
"import": "./createCors.js",
"require": "./cjs/createCors.js",
"types": "./createCors.d.ts"
},
"./createResponse": {
"import": "./createResponse.js",
"require": "./cjs/createResponse.js",
"types": "./createResponse.d.ts"
},
"./error": {
"import": "./error.js",
"require": "./cjs/error.js",
"types": "./error.d.ts"
},
"./html": {
"import": "./html.js",
"require": "./cjs/html.js",
"types": "./html.d.ts"
},
"./jpeg": {
"import": "./jpeg.js",
"require": "./cjs/jpeg.js",
"types": "./jpeg.d.ts"
},
"./png": {
"import": "./png.js",
"require": "./cjs/png.js",
"types": "./png.d.ts"
},
"./Router": {
"import": "./Router.js",
"require": "./cjs/Router.js",
"types": "./Router.d.ts"
},
"./status": {
"import": "./status.js",
"require": "./cjs/status.js",
"types": "./status.d.ts"
},
"./text": {
"import": "./text.js",
"require": "./cjs/text.js",
"types": "./text.d.ts"
},
"./webp": {
"import": "./webp.js",
"require": "./cjs/webp.js",
"types": "./webp.d.ts"
},
"./websocket": {
"import": "./websocket.js",
"require": "./cjs/websocket.js",
"types": "./websocket.d.ts"
},
"./withContent": {
"import": "./withContent.js",
"require": "./cjs/withContent.js",
"types": "./withContent.d.ts"
},
"./withCookies": {
"import": "./withCookies.js",
"require": "./cjs/withCookies.js",
"types": "./withCookies.d.ts"
},
"./withParams": {
"import": "./withParams.js",
"require": "./cjs/withParams.js",
"types": "./withParams.d.ts"
}
},
"keywords": [
"api",
"router",
Expand All @@ -30,7 +109,7 @@
"prerelease": "yarn verify",
"prebuild": "rimraf dist && mkdir dist && yarn coverage && yarn format",
"build": "rollup -c",
"release": "release --tag --push --patch --src=dist",
"release": "release --tag --push --type=next --src=dist",
"runtime:bun": "bun example/bun.ts",
"runtime:node": "node example/node.js"
},
Expand Down
28 changes: 17 additions & 11 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,40 @@ import bundleSize from 'rollup-plugin-bundle-size'
import copy from 'rollup-plugin-copy'

export default async () => {
const files = await globby('./src/*.ts', {
const files = (await globby('./src/*.ts', {
ignore: ['**/*.spec.ts', 'example'],
})
})).map(path => ({
path,
shortPath: path.replace(/(\/src)|(\.ts)/g, '').replace('./index', '.'),
esm: path.replace('/src/', '/dist/').replace('.ts', '.js'),
cjs: path.replace('/src/', '/dist/cjs/').replace('.ts', '.js'),
types: path.replace('/src/', '/dist/').replace('.ts', '.d.ts'),
}))

console.log({ files })
console.log(files.map(f => f.path))

return files.map((path) => ({
input: path,
return files.map(file => ({
input: file.path,
output: [
{
format: 'esm',
file: path.replace('/src/', '/dist/').replace('.ts', '.js'),
// sourcemap: true,
file: file.esm,
sourcemap: false,
},
{
format: 'cjs',
file: path.replace('/src/', '/dist/cjs/').replace('.ts', '.js'),
// sourcemap: true,
file: file.cjs,
sourcemap: false,
},
],
plugins: [
typescript({ sourceMap: false }),
typescript({ sourceMap: true }),
terser(),
bundleSize(),
copy({
targets: [
{
src: ['CONTRIBUTING.md', 'CODE-OF-CONDUCT.md', 'LICENSE'],
src: ['LICENSE'],
dest: 'dist',
},
],
Expand Down

0 comments on commit d83653e

Please sign in to comment.