Skip to content

Commit

Permalink
released v4.0.11-next.4 - testing full exports again
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhitley committed Jun 21, 2023
1 parent b7d4ca7 commit 44b2f8f
Show file tree
Hide file tree
Showing 2 changed files with 121 additions and 21 deletions.
97 changes: 91 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,100 @@
{
"name": "itty-router",
"version": "4.0.11-next.3",
"version": "4.0.11-next.4",
"description": "A tiny, zero-dependency router, designed to make beautiful APIs in any environment.",
"main": "./index.js",
"module": "./index.mjs",
"types": "./index.d.ts",
"files": [
"dist",
"LICENSE",
"README.md"
],
"exports": {
".": {
"import": "./index.mjs",
"require": "./index.js",
"types": "./index.d.ts"
"import": "./dist/index.mjs",
"require": "./dist/index.js",
"types": "./dist/index.d.ts"
},
"./createCors": {
"import": "./dist/createCors.mjs",
"require": "./dist/createCors.js",
"types": "./dist/createCors.d.ts"
},
"./createResponse": {
"import": "./dist/createResponse.mjs",
"require": "./dist/createResponse.js",
"types": "./dist/createResponse.d.ts"
},
"./error": {
"import": "./dist/error.mjs",
"require": "./dist/error.js",
"types": "./dist/error.d.ts"
},
"./html": {
"import": "./dist/html.mjs",
"require": "./dist/html.js",
"types": "./dist/html.d.ts"
},
"./jpeg": {
"import": "./dist/jpeg.mjs",
"require": "./dist/jpeg.js",
"types": "./dist/jpeg.d.ts"
},
"./json": {
"import": "./dist/json.mjs",
"require": "./dist/json.js",
"types": "./dist/json.d.ts"
},
"./png": {
"import": "./dist/png.mjs",
"require": "./dist/png.js",
"types": "./dist/png.d.ts"
},
"./Router": {
"import": "./dist/Router.mjs",
"require": "./dist/Router.js",
"types": "./dist/Router.d.ts"
},
"./status": {
"import": "./dist/status.mjs",
"require": "./dist/status.js",
"types": "./dist/status.d.ts"
},
"./StatusError": {
"import": "./dist/StatusError.mjs",
"require": "./dist/StatusError.js",
"types": "./dist/StatusError.d.ts"
},
"./text": {
"import": "./dist/text.mjs",
"require": "./dist/text.js",
"types": "./dist/text.d.ts"
},
"./webp": {
"import": "./dist/webp.mjs",
"require": "./dist/webp.js",
"types": "./dist/webp.d.ts"
},
"./websocket": {
"import": "./dist/websocket.mjs",
"require": "./dist/websocket.js",
"types": "./dist/websocket.d.ts"
},
"./withContent": {
"import": "./dist/withContent.mjs",
"require": "./dist/withContent.js",
"types": "./dist/withContent.d.ts"
},
"./withCookies": {
"import": "./dist/withCookies.mjs",
"require": "./dist/withCookies.js",
"types": "./dist/withCookies.d.ts"
},
"./withParams": {
"import": "./dist/withParams.mjs",
"require": "./dist/withParams.js",
"types": "./dist/withParams.d.ts"
}
},
"keywords": [
Expand Down Expand Up @@ -39,8 +124,8 @@
"prerelease:next": "yarn verify",
"prebuild": "rimraf dist && mkdir dist",
"build": "rollup -c",
"release": "release --tag --push --patch --src=dist",
"release:next": "release --tag --push --type=next --src=dist",
"release": "release --tag --push --patch",
"release:next": "release --tag --push --type=next",
"runtime:bun": "bun example/bun.ts",
"runtime:node": "node example/node.js"
},
Expand Down
45 changes: 30 additions & 15 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,38 @@ import typescript from '@rollup/plugin-typescript'
import { globby } from 'globby'
import bundleSize from 'rollup-plugin-bundle-size'
import copy from 'rollup-plugin-copy'
import fs from 'fs-extra'

export default async () => {
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', '.mjs'),
cjs: path.replace('/src/', '/dist/').replace('.ts', '.js'),
types: path.replace('/src/', '/dist/').replace('.ts', '.d.ts'),
}))
// scan files to build
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', '.mjs'),
cjs: path.replace('/src/', '/dist/').replace('.ts', '.js'),
types: path.replace('/src/', '/dist/').replace('.ts', '.d.ts'),
})).sort((a, b) => a.shortPath.toLowerCase() < b.shortPath.toLowerCase() ? -1 : 1)


// read original package.json
const pkg = await fs.readJSON('./package.json')

// create updated exports list from build files
pkg.exports = files.reduce((acc, file) => {
acc[file.shortPath] = {
import: file.esm,
require: file.cjs,
types: file.types,
}

return acc
}, {})

// write updated package.json
await fs.writeJSON('./package.json', pkg, { spaces: 2 })

export default async () => {
console.log(files.map(f => f.path))

return files.map(file => ({
Expand All @@ -30,11 +50,6 @@ export default async () => {
file: file.cjs,
sourcemap: false,
},
{
format: 'cjs',
file: file.cjs.replace('dist', 'dist/cjs'),
sourcemap: false,
},
],
plugins: [
typescript({ sourceMap: true }),
Expand Down

0 comments on commit 44b2f8f

Please sign in to comment.