Skip to content

Commit

Permalink
Fixed export map
Browse files Browse the repository at this point in the history
* messing with exports again

* released v4.0.11-next.4 - testing full exports again

* released v4.0.11-next.5 - testing without main and module root level attributes

* released v4.0.11-next.5 - testing for TS

* released v4.0.11-next.6 - trying on next.6

* final commits

* released v4.0.11-next.7 - releasing next7 for testing
  • Loading branch information
kwhitley committed Jun 21, 2023
1 parent ec447b3 commit 45e8f5a
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 24 deletions.
2 changes: 1 addition & 1 deletion example/node-require.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { createServerAdapter } = require('@whatwg-node/server')
const { createServer } = require('http')
require('isomorphic-fetch')
const { Router, error, json } = require('itty-router')
const { Router, error, json } = require('../dist/index.js')

const router = Router()

Expand Down
91 changes: 89 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,97 @@
{
"name": "itty-router",
"version": "4.0.11-next.3",
"version": "4.0.11-next.7",
"description": "A tiny, zero-dependency router, designed to make beautiful APIs in any environment.",
"main": "./index.js",
"module": "./index.mjs",
"types": "./index.d.ts",
"exports": {
".": {
"import": "./index.mjs",
"require": "./index.js",
"types": "./index.d.ts"
},
"./createCors": {
"import": "./createCors.mjs",
"require": "./createCors.js",
"types": "./createCors.d.ts"
},
"./createResponse": {
"import": "./createResponse.mjs",
"require": "./createResponse.js",
"types": "./createResponse.d.ts"
},
"./error": {
"import": "./error.mjs",
"require": "./error.js",
"types": "./error.d.ts"
},
"./html": {
"import": "./html.mjs",
"require": "./html.js",
"types": "./html.d.ts"
},
"./jpeg": {
"import": "./jpeg.mjs",
"require": "./jpeg.js",
"types": "./jpeg.d.ts"
},
"./json": {
"import": "./json.mjs",
"require": "./json.js",
"types": "./json.d.ts"
},
"./png": {
"import": "./png.mjs",
"require": "./png.js",
"types": "./png.d.ts"
},
"./Router": {
"import": "./Router.mjs",
"require": "./Router.js",
"types": "./Router.d.ts"
},
"./status": {
"import": "./status.mjs",
"require": "./status.js",
"types": "./status.d.ts"
},
"./StatusError": {
"import": "./StatusError.mjs",
"require": "./StatusError.js",
"types": "./StatusError.d.ts"
},
"./text": {
"import": "./text.mjs",
"require": "./text.js",
"types": "./text.d.ts"
},
"./webp": {
"import": "./webp.mjs",
"require": "./webp.js",
"types": "./webp.d.ts"
},
"./websocket": {
"import": "./websocket.mjs",
"require": "./websocket.js",
"types": "./websocket.d.ts"
},
"./withContent": {
"import": "./withContent.mjs",
"require": "./withContent.js",
"types": "./withContent.d.ts"
},
"./withCookies": {
"import": "./withCookies.mjs",
"require": "./withCookies.js",
"types": "./withCookies.d.ts"
},
"./withParams": {
"import": "./withParams.mjs",
"require": "./withParams.js",
"types": "./withParams.d.ts"
}
},
"keywords": [
"api",
"router",
Expand Down Expand Up @@ -68,7 +155,7 @@
"gzip-size": "^7.0.0",
"http": "^0.0.1-security",
"isomorphic-fetch": "^3.0.0",
"itty-router": "^4.0.10-next.4",
"itty-router": "^4.0.11-next.6",
"jsdom": "^22.1.0",
"npm-run-all": "^4.1.5",
"prettier": "^2.8.8",
Expand Down
47 changes: 31 additions & 16 deletions rollup.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,45 @@ 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.replace('/dist', ''),
require: file.cjs.replace('/dist', ''),
types: file.types.replace('/dist', ''),
}

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 => ({
input: file.path,
output: [
{
format: 'es',
format: 'esm',
file: file.esm,
sourcemap: false,
},
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
2 changes: 1 addition & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"lib": ["esnext", "dom", "dom.iterable"],
"listEmittedFiles": false,
"listFiles": false,
"moduleResolution": "node",
"moduleResolution": "nodeNext",
"noFallthroughCasesInSwitch": true,
"pretty": true,
"resolveJsonModule": true,
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2455,10 +2455,10 @@ istanbul-reports@^3.1.4:
html-escaper "^2.0.0"
istanbul-lib-report "^3.0.0"

itty-router@^4.0.10-next.4:
version "4.0.10-next.4"
resolved "https://registry.yarnpkg.com/itty-router/-/itty-router-4.0.10-next.4.tgz#1189e706890d7ef472adcc002f03e34e1df44a5a"
integrity sha512-dr48sUf+3EFh8CM/rYs3wnpVUdKN6n1TdrvMd4KS+6ogbVdbZ2qAcvwF8Kxt26c1VYPsDcNPVT0fPpG7/Cds6Q==
itty-router@^4.0.11-next.6:
version "4.0.11-next.6"
resolved "https://registry.yarnpkg.com/itty-router/-/itty-router-4.0.11-next.6.tgz#30e697d7fe11bd7942d9a1b8e942843eb27ff688"
integrity sha512-mRWKQPNpu1IIL4K5uXYdOiVKCxaKEy7LqSpT8RqBNPSMiMZ4+QyokPwPjA93E6KYv4DDdE30UaHt/ars5VMpFQ==

jackspeak@^2.0.3:
version "2.2.1"
Expand Down

0 comments on commit 45e8f5a

Please sign in to comment.