Skip to content

Commit 60e9dc0

Browse files
committed
build: fixed sourcemaps for pnpm
1 parent 0ffff74 commit 60e9dc0

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
},
2626
"types": "dist/zea-ux.d.ts",
2727
"files": [
28-
"dist/"
28+
"dist/",
29+
"src/"
2930
],
3031
"keywords": [
3132
"Zea",

rollup.config.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,11 @@ const plugins = [
1616
dedupe: ['@zeainc'],
1717
}), // so Rollup can find `ms`
1818
commonjs(), // so Rollup can convert `ms` to an ES module
19-
typescript(), // so Rollup can convert TypeScript to JavaScript
19+
typescript({
20+
outputToFilesystem: true, // so Rollup can output types
21+
sourceMap: true,
22+
inlineSources: true,
23+
}), // so Rollup can convert TypeScript to JavaScript
2024
]
2125
const isProduction = !process.env.ROLLUP_WATCH
2226

@@ -25,6 +29,12 @@ if (isProduction) {
2529
}
2630

2731
const sourcemap = true
32+
const sourcemapPathTransform = (relativePath, sourcemapPath) => {
33+
// 👇 this corrects paths like "../../src/..." to "../src/..."
34+
// Without this, the paths in the sourcemap would be incorrect
35+
// when the package is installed in a monorepo or similar structure.
36+
return relativePath.replace(/^\.\.[\\\/]\.\.[\\\/]src[\\\/]?/, '../src/')
37+
}
2838

2939
export default [
3040
// Browser-friendly UMD build.
@@ -36,6 +46,7 @@ export default [
3646
file: pkg.browser,
3747
format: 'umd',
3848
sourcemap,
49+
sourcemapPathTransform,
3950
globals: {
4051
'@zeainc/zea-engine': 'zeaEngine',
4152
},
@@ -54,14 +65,14 @@ export default [
5465
external,
5566
plugins,
5667
output: [
57-
{ file: pkg.main, format: 'cjs', sourcemap },
58-
{ file: pkg.module, format: 'es', sourcemap },
68+
{ file: pkg.main, format: 'cjs', sourcemap, sourcemapPathTransform },
69+
{ file: pkg.module, format: 'es', sourcemap, sourcemapPathTransform },
5970
],
6071
},
6172

6273
{
6374
input: 'src/index.ts',
64-
output: [{ file: pkg.types, format: 'es' }],
75+
output: [{ file: pkg.types, format: 'es', sourcemapPathTransform }],
6576
plugins: [dts()],
6677
},
6778
]

0 commit comments

Comments
 (0)