diff --git a/build.ts b/build.ts deleted file mode 100644 index 0a3bba5f..00000000 --- a/build.ts +++ /dev/null @@ -1,21 +0,0 @@ -import { build } from 'esbuild'; - -import { dependencies, peerDependencies } from './package.json'; - -const shared = { - entryPoints: ['src/index.tsx'], - bundle: true, - external: Object.keys(dependencies).concat(Object.keys(peerDependencies)), -}; - -build({ - ...shared, - format: 'cjs', - outfile: 'lib/index.js', -}); - -build({ - ...shared, - outfile: 'lib/index.esm.js', - format: 'esm', -}); diff --git a/package.json b/package.json index abdeb947..f913c61a 100644 --- a/package.json +++ b/package.json @@ -3,9 +3,9 @@ "version": "2.0.4", "description": "Thread-safe Helmet for React 16+ and friends", "sideEffects": false, - "main": "./lib/index.js", - "module": "./lib/index.esm.js", - "typings": "./lib/index.d.ts", + "main": "./lib/cjs/index.js", + "module": "./lib/esm/index.js", + "typings": "./lib/esm/index.d.ts", "repository": "http://github.com/staylor/react-helmet-async", "author": "Scott Taylor ", "license": "Apache-2.0", @@ -29,7 +29,6 @@ "@types/react": "18.2.39", "@types/shallowequal": "1.1.5", "@vitejs/plugin-react": "4.2.0", - "esbuild": "0.19.8", "eslint": "8.54.0", "eslint-config-prettier": "9.0.0", "eslint-plugin-prettier": "5.0.1", @@ -40,7 +39,6 @@ "react": "18.2.0", "react-dom": "18.2.0", "rimraf": "5.0.5", - "tsx": "4.6.1", "typescript": "5.2.2", "vite": "4.5.0", "vitest": "0.34.6" @@ -55,8 +53,9 @@ "test": "vitest run", "test-watch": "yarn test --watch", "test-update": "yarn test -u", - "compile": "yarn run clean && NODE_ENV=production tsx build.ts && yarn types", - "prepare": "yarn compile && husky install", - "types": "tsc src/index.tsx --jsx react --declaration --esModuleInterop --allowJs --emitDeclarationOnly --outDir lib" + "compile": "yarn run clean && yarn run compile:cjs && yarn run compile:esm", + "compile:cjs": "tsc -p ./tsconfig.cjs.json", + "compile:esm": "tsc -p ./tsconfig.esm.json", + "prepare": "yarn compile && husky install" } } diff --git a/tsconfig.build.json b/tsconfig.build.json new file mode 100644 index 00000000..683a3943 --- /dev/null +++ b/tsconfig.build.json @@ -0,0 +1,14 @@ +{ + "extends": "./tsconfig.json", + "exclude": [ + "__tests__", + "lib", + "node_modules" + ], + "include": ["src"], + "compilerOptions": { + "declaration": true, + "noEmit": false, + "rootDir": "src" + } +} diff --git a/tsconfig.cjs.json b/tsconfig.cjs.json new file mode 100644 index 00000000..285ea583 --- /dev/null +++ b/tsconfig.cjs.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.build.json", + "compilerOptions": { + "module": "CommonJS", + "moduleResolution": "node", + "target": "ESNext", + "outDir": "lib/cjs" + } +} diff --git a/tsconfig.esm.json b/tsconfig.esm.json new file mode 100644 index 00000000..e6b35ce9 --- /dev/null +++ b/tsconfig.esm.json @@ -0,0 +1,9 @@ +{ + "extends": "./tsconfig.build.json", + "compilerOptions": { + "module": "ES6", + "moduleResolution": "node", + "target": "ESNext", + "outDir": "lib/esm" + } +} diff --git a/yarn.lock b/yarn.lock index 0784da3e..ae966e39 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2090,35 +2090,7 @@ es-to-primitive@^1.2.1: is-date-object "^1.0.1" is-symbol "^1.0.2" -esbuild@0.19.8, esbuild@^0.19.3: - version "0.19.8" - resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.19.8.tgz#ad05b72281d84483fa6b5345bd246c27a207b8f1" - integrity sha512-l7iffQpT2OrZfH2rXIp7/FkmaeZM0vxbxN9KfiCwGYuZqzMg/JdvX26R31Zxn/Pxvsrg3Y9N6XTcnknqDyyv4w== - optionalDependencies: - "@esbuild/android-arm" "0.19.8" - "@esbuild/android-arm64" "0.19.8" - "@esbuild/android-x64" "0.19.8" - "@esbuild/darwin-arm64" "0.19.8" - "@esbuild/darwin-x64" "0.19.8" - "@esbuild/freebsd-arm64" "0.19.8" - "@esbuild/freebsd-x64" "0.19.8" - "@esbuild/linux-arm" "0.19.8" - "@esbuild/linux-arm64" "0.19.8" - "@esbuild/linux-ia32" "0.19.8" - "@esbuild/linux-loong64" "0.19.8" - "@esbuild/linux-mips64el" "0.19.8" - "@esbuild/linux-ppc64" "0.19.8" - "@esbuild/linux-riscv64" "0.19.8" - "@esbuild/linux-s390x" "0.19.8" - "@esbuild/linux-x64" "0.19.8" - "@esbuild/netbsd-x64" "0.19.8" - "@esbuild/openbsd-x64" "0.19.8" - "@esbuild/sunos-x64" "0.19.8" - "@esbuild/win32-arm64" "0.19.8" - "@esbuild/win32-ia32" "0.19.8" - "@esbuild/win32-x64" "0.19.8" - -esbuild@^0.18.10, esbuild@~0.18.20: +esbuild@^0.18.10: version "0.18.20" resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.18.20.tgz#4709f5a34801b43b799ab7d6d82f7284a9b7a7a6" integrity sha512-ceqxoedUrcayh7Y7ZX6NdbbDzGROiyVBgC4PriJThBKSVPWnnFHZAkfI1lJT8QFkOwH4qOS2SJkS4wvpGl8BpA== @@ -2146,6 +2118,34 @@ esbuild@^0.18.10, esbuild@~0.18.20: "@esbuild/win32-ia32" "0.18.20" "@esbuild/win32-x64" "0.18.20" +esbuild@^0.19.3: + version "0.19.8" + resolved "https://registry.yarnpkg.com/esbuild/-/esbuild-0.19.8.tgz#ad05b72281d84483fa6b5345bd246c27a207b8f1" + integrity sha512-l7iffQpT2OrZfH2rXIp7/FkmaeZM0vxbxN9KfiCwGYuZqzMg/JdvX26R31Zxn/Pxvsrg3Y9N6XTcnknqDyyv4w== + optionalDependencies: + "@esbuild/android-arm" "0.19.8" + "@esbuild/android-arm64" "0.19.8" + "@esbuild/android-x64" "0.19.8" + "@esbuild/darwin-arm64" "0.19.8" + "@esbuild/darwin-x64" "0.19.8" + "@esbuild/freebsd-arm64" "0.19.8" + "@esbuild/freebsd-x64" "0.19.8" + "@esbuild/linux-arm" "0.19.8" + "@esbuild/linux-arm64" "0.19.8" + "@esbuild/linux-ia32" "0.19.8" + "@esbuild/linux-loong64" "0.19.8" + "@esbuild/linux-mips64el" "0.19.8" + "@esbuild/linux-ppc64" "0.19.8" + "@esbuild/linux-riscv64" "0.19.8" + "@esbuild/linux-s390x" "0.19.8" + "@esbuild/linux-x64" "0.19.8" + "@esbuild/netbsd-x64" "0.19.8" + "@esbuild/openbsd-x64" "0.19.8" + "@esbuild/sunos-x64" "0.19.8" + "@esbuild/win32-arm64" "0.19.8" + "@esbuild/win32-ia32" "0.19.8" + "@esbuild/win32-x64" "0.19.8" + escalade@^3.1.1: version "3.1.1" resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.1.tgz#d8cfdc7000965c5a0174b4a82eaa5c0552742e40" @@ -2660,7 +2660,7 @@ get-symbol-description@^1.0.0: call-bind "^1.0.2" get-intrinsic "^1.1.1" -get-tsconfig@^4.5.0, get-tsconfig@^4.7.2: +get-tsconfig@^4.5.0: version "4.7.2" resolved "https://registry.yarnpkg.com/get-tsconfig/-/get-tsconfig-4.7.2.tgz#0dcd6fb330391d46332f4c6c1bf89a6514c2ddce" integrity sha512-wuMsz4leaj5hbGgg4IvDU0bqJagpftG5l5cXIAvo8uZrqn0NJqwtfupTN00VnkQJPcIRrxYrm1Ue24btpCha2A== @@ -4679,16 +4679,6 @@ tsutils@^3.21.0: dependencies: tslib "^1.8.1" -tsx@4.6.1: - version "4.6.1" - resolved "https://registry.yarnpkg.com/tsx/-/tsx-4.6.1.tgz#fc5456aabace99733eca23b42f223771a0ec1909" - integrity sha512-OQ4TAPHXAPUo/NZAmmIybl0o8LFOTlycQxFepLBAp6EV87U88fOKYGCQI2viGAEOVU9UW/cgQcxcOMnfEKVY3Q== - dependencies: - esbuild "~0.18.20" - get-tsconfig "^4.7.2" - optionalDependencies: - fsevents "~2.3.3" - type-check@^0.4.0, type-check@~0.4.0: version "0.4.0" resolved "https://registry.yarnpkg.com/type-check/-/type-check-0.4.0.tgz#07b8203bfa7056c0657050e3ccd2c37730bab8f1"