Skip to content

Commit de64a43

Browse files
Avoid FalseESM warning when importing commonjs in TypeScript using commonjs+node16 resolution
1 parent 80a821d commit de64a43

File tree

8 files changed

+134
-100
lines changed

8 files changed

+134
-100
lines changed

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"prettier-plugin-embed": "^0.4.15",
4545
"prettier-plugin-sql": "^0.18.1",
4646
"rollup": "4.14.3",
47+
"rollup-plugin-dts": "^6.2.1",
4748
"typescript": "^5.7.2",
4849
"vitest": "^3.2.4"
4950
}

packages/attachments/package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,14 @@
2222
"types": "./lib/index.d.ts",
2323
"exports": {
2424
".": {
25-
"types": "./lib/index.d.ts",
26-
"import": "./lib/index.js",
27-
"require": "./dist/index.cjs",
28-
"default": "./lib/index.js"
25+
"import": {
26+
"default": "./lib/index.js",
27+
"types": "./lib/index.d.ts"
28+
},
29+
"require": {
30+
"default": "./dist/index.cjs",
31+
"types": "./dist/index.d.cts"
32+
}
2933
}
3034
},
3135
"files": [
Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import commonjs from '@rollup/plugin-commonjs';
22
import resolve from '@rollup/plugin-node-resolve';
33
import typescript from '@rollup/plugin-typescript';
4+
import { dts } from 'rollup-plugin-dts';
45

56
/** @type {import('rollup').RollupOptions} */
67
export default (commandLineArgs) => {
@@ -9,23 +10,31 @@ export default (commandLineArgs) => {
910
// Clears rollup CLI warning https://github.com/rollup/rollup/issues/2694
1011
delete commandLineArgs.sourceMap;
1112

12-
return {
13-
input: 'src/index.ts',
14-
output: {
15-
format: 'cjs',
16-
file: 'dist/index.cjs',
17-
sourcemap: sourceMap,
18-
exports: 'named'
13+
return [
14+
{
15+
input: 'src/index.ts',
16+
output: {
17+
format: 'cjs',
18+
file: 'dist/index.cjs',
19+
sourcemap: sourceMap,
20+
exports: 'named'
21+
},
22+
plugins: [
23+
resolve(),
24+
commonjs(),
25+
typescript({
26+
tsconfig: './tsconfig.json',
27+
outDir: 'dist',
28+
sourceMap
29+
})
30+
],
31+
external: ['@powersync/common']
1932
},
20-
plugins: [
21-
resolve(),
22-
commonjs(),
23-
typescript({
24-
tsconfig: './tsconfig.json',
25-
outDir: 'dist',
26-
sourceMap
27-
})
28-
],
29-
external: ['@powersync/common']
30-
};
33+
// This is required to avoid https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseESM.md
34+
{
35+
input: './lib/index.d.ts',
36+
output: [{ file: 'dist/index.d.cts', format: 'cjs' }],
37+
plugins: [dts()]
38+
}
39+
];
3140
};

packages/drizzle-driver/package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
"types": "lib/src/index.d.ts",
99
"exports": {
1010
".": {
11-
"types": "./lib/src/index.d.ts",
12-
"import": "./lib/src/index.js",
13-
"require": "./dist/index.cjs",
14-
"default": "./lib/src/index.js"
11+
"import": {
12+
"default": "./lib/src/index.js",
13+
"types": "./lib/src/index.d.ts"
14+
},
15+
"require": {
16+
"default": "./dist/index.cjs",
17+
"types": "./dist/index.d.cts"
18+
}
1519
}
1620
},
1721
"author": "JOURNEYAPPS",
Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import commonjs from '@rollup/plugin-commonjs';
22
import resolve from '@rollup/plugin-node-resolve';
33
import typescript from '@rollup/plugin-typescript';
4+
import { dts } from 'rollup-plugin-dts';
45

56
/** @type {import('rollup').RollupOptions} */
67
export default (commandLineArgs) => {
@@ -9,28 +10,36 @@ export default (commandLineArgs) => {
910
// Clears rollup CLI warning https://github.com/rollup/rollup/issues/2694
1011
delete commandLineArgs.sourceMap;
1112

12-
return {
13-
input: 'src/index.ts',
14-
output: {
15-
format: 'cjs',
16-
file: 'dist/index.cjs',
17-
sourcemap: sourceMap,
18-
exports: 'named'
13+
return [
14+
{
15+
input: 'src/index.ts',
16+
output: {
17+
format: 'cjs',
18+
file: 'dist/index.cjs',
19+
sourcemap: sourceMap,
20+
exports: 'named'
21+
},
22+
plugins: [
23+
resolve(),
24+
commonjs(),
25+
typescript({
26+
tsconfig: './tsconfig.json',
27+
outDir: 'dist',
28+
sourceMap,
29+
/**
30+
* The Typescript plugin complains about internal Drizzle types not matching when selecting
31+
* other moduleResolution settings.
32+
*/
33+
moduleResolution: 'bundler'
34+
})
35+
],
36+
external: ['@powersync/common', /^drizzle-orm(\/.*)?$/]
1937
},
20-
plugins: [
21-
resolve(),
22-
commonjs(),
23-
typescript({
24-
tsconfig: './tsconfig.json',
25-
outDir: 'dist',
26-
sourceMap,
27-
/**
28-
* The Typescript plugin complains about internal Drizzle types not matching when selecting
29-
* other moduleResolution settings.
30-
*/
31-
moduleResolution: 'bundler'
32-
})
33-
],
34-
external: ['@powersync/common', /^drizzle-orm(\/.*)?$/]
35-
};
38+
// This is required to avoid https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseESM.md
39+
{
40+
input: './lib/src/index.d.ts',
41+
output: [{ file: 'dist/index.d.cts', format: 'cjs' }],
42+
plugins: [dts()]
43+
}
44+
];
3645
};

packages/kysely-driver/package.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88
"types": "lib/src/index.d.ts",
99
"exports": {
1010
".": {
11-
"types": "./lib/src/index.d.ts",
12-
"import": "./lib/src/index.js",
13-
"require": "./dist/index.cjs",
14-
"default": "./lib/src/index.js"
11+
"import": {
12+
"default": "./lib/src/index.js",
13+
"types": "./lib/src/index.d.ts"
14+
},
15+
"require": {
16+
"default": "./dist/index.cjs",
17+
"types": "./dist/index.d.cts"
18+
}
1519
}
1620
},
1721
"author": "JOURNEYAPPS",
Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import commonjs from '@rollup/plugin-commonjs';
22
import resolve from '@rollup/plugin-node-resolve';
33
import typescript from '@rollup/plugin-typescript';
4+
import { dts } from 'rollup-plugin-dts';
45

56
/** @type {import('rollup').RollupOptions} */
67
export default (commandLineArgs) => {
@@ -9,23 +10,31 @@ export default (commandLineArgs) => {
910
// Clears rollup CLI warning https://github.com/rollup/rollup/issues/2694
1011
delete commandLineArgs.sourceMap;
1112

12-
return {
13-
input: 'src/index.ts',
14-
output: {
15-
format: 'cjs',
16-
file: 'dist/index.cjs',
17-
sourcemap: sourceMap,
18-
exports: 'named'
13+
return [
14+
{
15+
input: 'src/index.ts',
16+
output: {
17+
format: 'cjs',
18+
file: 'dist/index.cjs',
19+
sourcemap: sourceMap,
20+
exports: 'named'
21+
},
22+
plugins: [
23+
resolve(),
24+
commonjs(),
25+
typescript({
26+
tsconfig: './tsconfig.json',
27+
outDir: 'dist',
28+
sourceMap
29+
})
30+
],
31+
external: ['@powersync/common', 'kysely']
1932
},
20-
plugins: [
21-
resolve(),
22-
commonjs(),
23-
typescript({
24-
tsconfig: './tsconfig.json',
25-
outDir: 'dist',
26-
sourceMap
27-
})
28-
],
29-
external: ['@powersync/common', 'kysely']
30-
};
33+
// This is required to avoid https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseESM.md
34+
{
35+
input: './lib/src/index.d.ts',
36+
output: [{ file: 'dist/index.d.cts', format: 'cjs' }],
37+
plugins: [dts()]
38+
}
39+
];
3140
};

pnpm-lock.yaml

Lines changed: 23 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)