Skip to content

Commit

Permalink
Re-introduce main and types fields in package.json (#243)
Browse files Browse the repository at this point in the history
* Re-introduce main and types fields in package.json

TypeScript with "moduleResolution": "node" won't look at at the "exports" field, so we add main and types for backward compatibility

Ref #242

* Use explicit mjs file extensions in build outputs, update jav2 for
ESM/CJS interoperability.
  • Loading branch information
keichan34 authored Oct 18, 2024
1 parent d2ee418 commit 4a626ff
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

# production
/build
/demo/main-browser-esm.js*
/demo/main-browser-esm.mjs*

# misc
.DS_Store
Expand Down
2 changes: 1 addition & 1 deletion demo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h1>住所正規化デモ</h1>
<script src="https://unpkg.com/[email protected]/umd/react.production.min.js"></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.production.min.js"></script>
<script type="module">
import { normalize } from './main-browser-esm.js';
import { normalize } from './main-browser-esm.mjs';
import htm from 'https://unpkg.com/[email protected]/dist/htm.module.js?module';
const html = htm.bind(React.createElement);

Expand Down
8 changes: 4 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
"version": "3.0.0",
"description": "",
"type": "module",
"main": "./dist/main-node-cjs.cjs",
"types": "./dist/main-node.d.ts",
"exports": {
"node": {
"import": "./dist/main-node-esm.js",
"import": "./dist/main-node-esm.mjs",
"require": "./dist/main-node-cjs.cjs",
"types": "./dist/main-node.d.ts"
},
"browser": {
"import": "./dist/main-browser-esm.js",
"import": "./dist/main-browser-esm.mjs",
"default": "./dist/main-browser-umd.js",
"types": "./dist/main-browser.d.ts"
}
Expand All @@ -22,7 +24,7 @@
"test:addresses": "node --test --import tsx ./test/addresses.test.ts",
"test:generate-test-data": "tsx test/build-test-data.ts > test/addresses.csv",
"lint": "eslint \"src/**/*.ts\" \"test/**/*.test.ts\" --fix",
"build": "npm run clean && rollup -c rollup.config.js && shx cp ./dist/main-browser-esm.js* ./demo/",
"build": "npm run clean && rollup -c rollup.config.js && shx cp ./dist/main-browser-esm.mjs* ./demo/",
"clean": "shx rm -rf dist"
},
"engines": {
Expand Down Expand Up @@ -52,7 +54,7 @@
"typescript": "^5.6.2"
},
"dependencies": {
"@geolonia/japanese-addresses-v2": "^0.0.3",
"@geolonia/japanese-addresses-v2": "0.0.5",
"@geolonia/japanese-numeral": "^1.0.2",
"lru-cache": "^11.0.1",
"papaparse": "^5.4.1",
Expand Down
6 changes: 4 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default [
{
input: 'src/main-browser.ts',
output: {
file: './dist/main-browser-esm.js',
file: './dist/main-browser-esm.mjs',
name: 'normalize',
format: 'esm',
sourcemap: true,
Expand All @@ -55,13 +55,14 @@ export default [
input: 'src/main-node.ts',
external: [
'@geolonia/japanese-numeral',
'@geolonia/japanese-addresses-v2',
'papaparse',
'undici',
'lru-cache',
'node:fs',
],
output: {
file: './dist/main-node-esm.js',
file: './dist/main-node-esm.mjs',
format: 'esm',
sourcemap: true,
},
Expand All @@ -71,6 +72,7 @@ export default [
input: 'src/main-node.ts',
external: [
'@geolonia/japanese-numeral',
'@geolonia/japanese-addresses-v2',
'papaparse',
'undici',
'lru-cache',
Expand Down

0 comments on commit 4a626ff

Please sign in to comment.