Skip to content

Commit

Permalink
Workaround TypeScript resolution bug (#7)
Browse files Browse the repository at this point in the history
* Workaround TypeScript resolution bug

* Add entry

* Update pages build config
  • Loading branch information
compulim authored Sep 9, 2023
1 parent 20eac5b commit adf2e33
Show file tree
Hide file tree
Showing 14 changed files with 55 additions and 51 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Fixed

- Updated `exports` field to workaround [TypeScript resolution bug](https://github.com/microsoft/TypeScript/issues/50762), by [@compulim](https://github.com/compulim), in PR [#7](https://github.com/compulim/message-port-rpc/pull/7)

## [1.0.0] - 2023-05-14

### Added
Expand Down
6 changes: 2 additions & 4 deletions packages/message-port-rpc/babel.jest.config.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
"@babel/preset-env",
{
"modules": "commonjs",
"targets": {
"ie": "11"
}
"targets": { "node": "16" }
}
]
],
"sourceMaps": "inline"
"sourceMaps": true
}
39 changes: 24 additions & 15 deletions packages/message-port-rpc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,34 @@
],
"exports": {
".": {
"import": "./lib/esmodules/index.js",
"require": "./lib/commonjs/index.js",
"types": "./lib/types/index.d.ts"
"import": {
"types": "./lib/esmodules-types/index.d.ts",
"default": "./lib/esmodules/index.js"
},
"require": {
"types": "./lib/commonjs-types/index.d.ts",
"default": "./lib/commonjs/index.js"
}
},
"./messagePortRPC": {
"import": "./lib/esmodules/messagePortRPC.js",
"require": "./lib/commonjs/messagePortRPC.js",
"types": "./lib/types/messagePortRPC.d.ts"
"import": {
"types": "./lib/esmodules-types/messagePortRPC.d.ts",
"default": "./lib/esmodules/messagePortRPC.js"
},
"require": {
"types": "./lib/commonjs-types/messagePortRPC.d.ts",
"default": "./lib/commonjs/messagePortRPC.js"
}
}
},
"main": "./lib/commonjs/index.js",
"typings": "./lib/types/index.d.ts",
"typings": "./lib/commonjs-types/index.d.ts",
"scripts": {
"build": "npm run build:babel && npm run build:typescript",
"build:babel": "npm run build:babel:commonjs && npm run build:babel:esmodules",
"build": "npm run build:babel:commonjs && npm run build:babel:esmodules && npm run build:typescript:commonjs && npm run build:typescript:esmodules",
"build:babel:commonjs": "babel src --config-file ./babel.commonjs.config.json --extensions .ts,.tsx --out-dir ./lib/commonjs/",
"build:babel:esmodules": "babel src --config-file ./babel.esmodules.config.json --extensions .ts,.tsx --out-dir ./lib/esmodules/",
"build:typescript": "tsc --project ./src/tsconfig.declaration.json",
"build:typescript:commonjs": "tsc --project ./src/tsconfig.declaration.commonjs.json",
"build:typescript:esmodules": "tsc --project ./src/tsconfig.declaration.esmodules.json",
"bump": "npm run bump:prod && npm run bump:dev && npm run bump:auditfix && npm run bump:babel",
"bump:auditfix": "npm audit fix || exit 0",
"bump:babel": "npm run bump:babel:commonjs && npm run bump:babel:esmodules",
Expand All @@ -35,13 +45,12 @@
"bump:prod": "if [ `cat package.json | jq -r '(.dependencies // {}) | length'` -ne 0 ]; then npm install --save-exact $(cat package.json | jq -r '(.pinDependencies // {}) as $p | ((.dependencies // {}) | keys) | map(. + \"@\" + ($p[.] // [\"latest\"])[0]) | .[]'); fi",
"postbump": "cat package.json | jq '. + (.dependencies = (((.dependencies // {}) + (.localPeerDependencies // {})) | to_entries | sort_by(.key) | from_entries)) | (.devDependencies = (((.devDependencies // {}) + (.localPeerDevDependencies // {})) | to_entries | sort_by(.key) | from_entries))' > package-temp.json && mv package-temp.json package.json",
"prebump": "cat package.json | jq '(((.localPeerDependencies // {}) | keys | map([\"dependencies\", .])) + ((.localPeerDevDependencies // {}) | keys | map([\"devDependencies\", .]))) as $localPeerPaths | delpaths($localPeerPaths)' > package-temp.json && mv package-temp.json package.json",
"precommit": "eslint ./src/",
"precommit": "npm run precommit:eslint && npm run precommit:typescript",
"precommit:eslint": "eslint ./src/",
"precommit:typescript": "tsc --noEmit --project ./src/tsconfig.json",
"prepack": "cp ../../CHANGELOG.md . && cp ../../LICENSE . && cp ../../README.md .",
"start": "esbuild --bundle --outfile=./public/main.js --servedir=./public --sourcemap ./scenarios/index.jsx",
"jest": "jest",
"test": "npm run test:jest && npm run test:typescript",
"test:jest": "npm run jest",
"test:typescript": "tsc --project ./src/tsconfig.test.json"
"test": "jest"
},
"repository": {
"type": "git",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"declarationDir": "../lib/commonjs-types/",
"module": "CommonJS"
},
"extends": "./tsconfig.declaration.json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"compilerOptions": {
"declarationDir": "../lib/esmodules-types/",
"module": "ESNext"
},
"extends": "./tsconfig.declaration.json"
}
1 change: 0 additions & 1 deletion packages/message-port-rpc/src/tsconfig.declaration.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"compilerOptions": {
"declaration": true,
"declarationDir": "../lib/types/",
"emitDeclarationOnly": true
},
"exclude": ["**/*.spec.*", "**/*.test.*", "__test__/**/*"],
Expand Down
7 changes: 3 additions & 4 deletions packages/message-port-rpc/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
"compilerOptions": {
"esModuleInterop": true,
"jsx": "react",
"moduleResolution": "nodenext",
"skipLibCheck": true, // "@jest/environment" has internal conflicts on their types
"strict": true,
"target": "ESNext"
"module": "NodeNext",
"moduleResolution": "NodeNext",
"strict": true
}
}
8 changes: 0 additions & 8 deletions packages/message-port-rpc/src/tsconfig.test.json

This file was deleted.

3 changes: 1 addition & 2 deletions packages/pages/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/node_modules/
/package-lock.json
/public/static/css/main.css
/public/static/js/main.js
/public/static/
8 changes: 4 additions & 4 deletions packages/pages/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
"version": "0.0.0-0",
"description": "",
"scripts": {
"build": "npm run build:typescript && npm run build:esbuild",
"build:esbuild": "esbuild --bundle --entry-names=[dir]/[ext]/main --minify --outdir=./public/static/ --sourcemap ./src/app/index.tsx ./src/iframe/index.tsx ./src/worker/index.ts",
"build:typescript": "tsc --project ./src/tsconfig.json",
"build": "esbuild --bundle --entry-names=[name]/[ext]/main --minify --outdir=./public/static/ --sourcemap app=./src/app/index.tsx iframe=./src/iframe/index.tsx worker=./src/worker/index.ts",
"bump": "npm run bump:prod && npm run bump:dev && npm run bump:auditfix",
"bump:auditfix": "npm audit fix || exit 0",
"bump:dev": "if [ `cat package.json | jq -r '(.devDependencies // {}) | length'` -ne 0 ]; then npm install $(cat package.json | jq -r '(.pinDependencies // {}) as $p | ((.devDependencies // {}) | keys) | map(. + \"@\" + ($p[.] // [\"latest\"])[0]) | .[]'); fi",
"bump:prod": "if [ `cat package.json | jq -r '(.dependencies // {}) | length'` -ne 0 ]; then npm install --save-exact $(cat package.json | jq -r '(.pinDependencies // {}) as $p | ((.dependencies // {}) | keys) | map(. + \"@\" + ($p[.] // [\"latest\"])[0]) | .[]'); fi",
"postbump": "cat package.json | jq '. + (.dependencies = (((.dependencies // {}) + (.localPeerDependencies // {})) | to_entries | sort_by(.key) | from_entries)) | (.devDependencies = (((.devDependencies // {}) + (.localPeerDevDependencies // {})) | to_entries | sort_by(.key) | from_entries))' > package-temp.json && mv package-temp.json package.json",
"prebump": "cat package.json | jq '(((.localPeerDependencies // {}) | keys | map([\"dependencies\", .])) + ((.localPeerDevDependencies // {}) | keys | map([\"devDependencies\", .]))) as $localPeerPaths | delpaths($localPeerPaths)' > package-temp.json && mv package-temp.json package.json",
"precommit": "npm run precommit:typescript",
"precommit:typescript": "tsc --project ./src/tsconfig.json",
"reinstall": "rm -r node_modules package-lock.json && npm install",
"start": "npm run build:esbuild -- --servedir=./public"
"start": "npm run build -- --servedir=./public"
},
"author": "William Wong (https://github.com/compulim)",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/pages/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<html lang="en">
<head>
<title>message-port-rpc demo</title>
<link href="./static/css/main.css" rel="stylesheet" type="text/css" />
<link href="./static/app/css/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<main></main>
Expand Down
1 change: 0 additions & 1 deletion packages/pages/public/static/iframe/js/main.js

This file was deleted.

8 changes: 0 additions & 8 deletions packages/pages/public/static/worker/js/main.js

This file was deleted.

5 changes: 2 additions & 3 deletions packages/pages/src/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
"esModuleInterop": true,
"jsx": "react",
"lib": ["DOM", "ESNext"],
"moduleResolution": "nodenext",
"moduleResolution": "Bundler",
"noEmit": true,
"strict": true,
"target": "ESNext"
},
"exclude": ["**/*.spec.*", "**/*.test.*"]
}
}

0 comments on commit adf2e33

Please sign in to comment.