Plugin failures due to tippex dependency
See original GitHub issueHi! I’m afraid the recently introduced dependency on tippex
(https://github.com/surma/rollup-plugin-off-main-thread/pull/32) has broken our app’s Rollup build in a few ways:
- tippex throws an error when running on some of our third party dependencies - for example this line of code in page.js:
[!] (plugin off-main-thread) Error: Unexpected character (820:3). If this is valid JavaScript, it's probably a bug in tippex. Please raise an issue at https://github.com/Rich-Harris/tippex/issues – thanks!
};
^
../../../common/temp/node_modules/.pnpm/page@1.11.6/node_modules/page/page.mjs
Error: Unexpected character (820:3). If this is valid JavaScript, it's probably a bug in tippex. Please raise an issue at https://github.com/Rich-Harris/tippex/issues – thanks!
};
^
at find (<truncated>/tippex@3.0.0/node_modules/tippex/src/index.js:318:10)
at Object.match (<truncated>/tippex@3.0.0/node_modules/tippex/src/index.js:366:16)
at Object.transform (<truncated>/@surma/rollup-plugin-off-main-thread@2.0.0/node_modules/@surma/rollup-plugin-off-main-thread/index.js:114:14)
at Object.timedPlugin.<computed> (<truncated>/rollup@2.36.1/node_modules/rollup/dist/shared/rollup.js:9695:45)
at <truncated>/rollup@2.36.1/node_modules/rollup/dist/shared/rollup.js:18781:25
- A similar failure occurs when tippex runs on this code in URI.js.
- Even after I manually patch the plugin’s
transform
function to ignore the above files, or comment out the problematic code in those files, tippex still fails in therenderChunk
function, in/around some LitElement copyright headers:
Error: Unexpected character (537:5). If this is valid JavaScript, it's probably a bug in tippex. Please raise an issue at https://github.com/Rich-Harris/tippex/issues – thanks!
} /**
^
at find (<truncated>/tippex@3.0.0/node_modules/tippex/src/index.js:318:10)
at Object.match (<truncated>/tippex@3.0.0/node_modules/tippex/src/index.js:366:16)
at Object.renderChunk (<truncated>/@surma/rollup-plugin-off-main-thread@2.1.0/node_modules/@surma/rollup-plugin-off-main-thread/index.js:260:14)
at <truncated>/rollup@2.36.1/node_modules/rollup/dist/shared/rollup.js:18781:25
In all cases it seems to be failing on valid JS code.
Options to fix this
We could try to fix these apparent issues in tippex. However, given the number of issues already surfacing with it, I’m concerned that similar problems are liable to surface as our codebase grows. It’s also not clear to me that tippex is actively maintained, as it has not been modified for a few years.
For now, I wondered if you would be open to a PR that reverts to simple regex matching, instead of tippex? Long term, if a more robust approach is desired, the plugin could switch over to AST, which seems common in other rollup plugins we use. It would be more expensive, but costs could be mitigated by allowing plugin users to specify include
/ exclude
filters.
CC @surma @RReverser
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top GitHub Comments
@surma Can you please merge this PR and release 2.1.1 for a temporary fix?
I’d say, this kind of use-cases (replacing specific patterns without doing whole-tree static analysis) is precisely the kind of cases where tippex shines over AST parsing. Considering how infrequent usage of
new Worker
is in real-world codebases, the savings from avoiding full AST parse can be pretty significant.I also spoke to Rich Harris privately, and he said they’d be on outlook for any issues/repros and could look into them, so extracted examples could really help.
That said, as I already mentioned above, I agree that replacing with regular regex match-replace is okay for a temporary solution, I’m just not too happy about it as it will break on any usages with comments.