Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix node 16 cjs import #2112

Merged
merged 11 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 37 additions & 32 deletions packages/typescript-client/package.json
Original file line number Diff line number Diff line change
@@ -1,34 +1,11 @@
{
"name": "@electric-sql/client",
"version": "0.9.0",
"description": "Postgres everywhere - your data, in sync, wherever you need it.",
"type": "module",
"main": "dist/cjs/index.cjs",
"module": "dist/index.legacy-esm.js",
"types": "dist/index.d.ts",
"exports": {
"./package.json": "./package.json",
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"default": "./dist/cjs/index.cjs"
}
},
"files": [
"dist",
"src"
],
"sideEffects": false,
"repository": {
"type": "git",
"url": "git+https://github.com/electric-sql/electric.git"
},
"version": "0.9.0",
"author": "ElectricSQL team and contributors.",
"license": "Apache-2",
"bugs": {
"url": "https://github.com/electric-sql/electric/issues"
},
"homepage": "https://electric-sql.com",
"dependencies": {},
"devDependencies": {
"@types/pg": "^8.11.6",
Expand All @@ -49,22 +26,50 @@
"uuid": "^10.0.0",
"vitest": "^2.0.2"
},
"type": "module",
"exports": {
"./package.json": "./package.json",
".": {
"import": {
"types": "./dist/index.d.ts",
"default": "./dist/index.mjs"
},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

diff is noisier than ideal as I ran https://www.npmjs.com/package/fixpack on the package.json

"require": {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming this was the main thing that was missing for node CJS imports (?)

"types": "./dist/cjs/index.d.cts",
"default": "./dist/cjs/index.cjs"
}
}
},
"files": [
"dist",
"src"
],
"homepage": "https://electric-sql.com",
"license": "Apache-2",
"main": "./dist/cjs/index.cjs",
"module": "./dist/index.legacy-esm.js",
"types": "./dist/index.d.ts",
"optionalDependencies": {
"@rollup/rollup-darwin-arm64": "^4.18.1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/electric-sql/electric.git"
},
"scripts": {
"build": "shx rm -rf dist && concurrently \"tsup\" \"tsc -p tsconfig.build.json\"",
"format": "eslint . --fix",
"prepack": "pnpm build",
"stylecheck": "eslint . --quiet",
"test": "pnpm exec vitest",
"typecheck": "tsc -p tsconfig.json"
},
"sideEffects": false,
"typesVersions": {
"*": {
"*": [
"./dist/index.d.ts"
]
}
},
"scripts": {
"test": "pnpm exec vitest",
"typecheck": "tsc -p tsconfig.json",
"build": "shx rm -rf dist && concurrently \"tsup\" \"tsc -p tsconfig.build.json\"",
"prepack": "pnpm build",
"stylecheck": "eslint . --quiet",
"format": "eslint . --fix"
}
}
57 changes: 32 additions & 25 deletions packages/typescript-client/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,59 +2,66 @@ import type { Options } from 'tsup'
import { defineConfig } from 'tsup'

export default defineConfig((options) => {
const entry = {
index: 'src/index.ts',
}
const commonOptions: Partial<Options> = {
entry,
entry: {
index: 'src/index.ts',
},
tsconfig: `./tsconfig.build.json`,
sourcemap: true,
...options,
}

return [
// Standard ESM, embedded `process.env.NODE_ENV` checks
// ESM build with .d.ts
{
...commonOptions,
format: ['esm'],
outExtension: () => ({ js: '.mjs' }), // Add dts: '.d.ts' when egoist/tsup#1053 lands
dts: true,
outExtension: () => ({ js: '.mjs' }),
dts: {
entry: commonOptions.entry,
resolve: true,
},
clean: true,
},
// Support Webpack 4 by pointing `"module"` to a file with a `.js` extension
// CJS build with .d.cts
{
...commonOptions,
format: ['cjs'],
outDir: './dist/cjs/',
outExtension: () => ({ js: '.cjs' }),
dts: {
entry: commonOptions.entry,
resolve: true,
compilerOptions: {
declarationDir: '../',
declaration: true,
declarationMap: true,
outDir: '../',
},
},
clean: false,
},
// Support Webpack 4 by pointing "module" to a file with a .js extension
{
...commonOptions,
format: ['esm'],
target: 'es2017',
dts: false,
outExtension: () => ({ js: '.js' }),
entry: Object.fromEntries(
Object.entries(entry).map(([key, value]) => [
`${key}.legacy-esm`,
value,
])
),
entry: { 'index.legacy-esm': 'src/index.ts' },
},
// Browser-ready ESM, production + minified
{
...commonOptions,

entry: Object.fromEntries(
Object.entries(entry).map(([key, value]) => [`${key}.browser`, value])
),

define: {
'process.env.NODE_ENV': JSON.stringify('production'),
},
format: ['esm'],
outExtension: () => ({ js: '.mjs' }),
minify: true,
},
{
...commonOptions,
format: 'cjs',
outDir: './dist/cjs/',
outExtension: () => ({ js: '.cjs' }),
entry: {
'index.browser': 'src/index.ts',
},
},
]
})
Loading