Code Monkey home page Code Monkey logo

Comments (13)

YonatanKra avatar YonatanKra commented on June 12, 2024 1

@jlmakes - do you think you could integrate this into the package?

from karma-rollup-preprocessor.

jlmakes avatar jlmakes commented on June 12, 2024

Thanks for the reproduction. I removed TypeScript from the project and everything works normally. That narrows things.

from karma-rollup-preprocessor.

kaosdev avatar kaosdev commented on June 12, 2024

Can confirm that, using babel watch works correctly. After digging a while I found that @rollup/plugin-typescript uses an internal watcher, maybe this is causing some errors?

from karma-rollup-preprocessor.

jlmakes avatar jlmakes commented on June 12, 2024

karma-rollup-preprocessor has its own watcher that manually re-runs Karma, but presently I don't deeply understand how Karma goes about generating/serving temporary files. Although, if it works without the TS plugin, it makes me think the problem lies in how @rollup/plugin-typescript names its output files, perhaps related to the file watcher or a caching strategy. 🤔

There is a bit of file name shuffling in order to get source maps working, and to account for file extension changes. If there is a fix that can be implemented in preprocessor land (as opposed to in the plug-in itself) it likely has to do with that.

There are other users that have been using TypeScript though: https://github.com/jlmakes/karma-rollup-preprocessor/blob/master/CHANGELOG.md#fixed-6 but it looks like it was done using Babel.

from karma-rollup-preprocessor.

MMMalik avatar MMMalik commented on June 12, 2024

I can confirm that there is an issue with watching files and official TS plugin @rollup/plugin-typescript. Switching to @rollup/plugin-babel helped in my case:

My plugins inside rollupPreprocessor in karma.conf.js:

plugins: [
	progress(),
	babel( {
		babelHelpers: 'bundled',
		presets: [
			'@babel/preset-env',
			'@babel/preset-typescript',
			'@babel/preset-react'
		],
		extensions: [ '.ts', '.tsx', '.js' ],
		exclude: 'node_modules/**'
	} ),
	nodeResolve( {
		preferBuiltins: false,
		extensions: [ '.ts', '.tsx', '.js' ]
	} ),
	commonJs(),
	polyfillNode()
],

With babel plugin it's just transpilation (no type checking) but I don't think it's a big deal in case of generating test bundle.

from karma-rollup-preprocessor.

xenobytezero avatar xenobytezero commented on June 12, 2024

So I have been spending a few days looking at this and it looks like it's partially related to @rollup/typescript and partially down to the structure of this preprocessor.

After diving through the @rollup/typescript code, it looks like the plugins "emitted files" cache is maintained at the plugin instance level, not per Rollup run. Since this preprocessor calls rollup.rollup() multiple times with the same config, the instance of the plugin is maintained as does the cache, hence every time the file changes the previously compiled one is emitted again.

I assume something different happens when running rollup.watch() as my main build (using an identical rollup config) works fine.

Is there a way to modify the preprocessor to use rollup.watch() and its internal watcher, while still saying to Karma "hey stuff has changed, you should do what you need to" in the same way as refreshFiles does?

I'm going to keep messing around with this on my end to see if I can make it work, but any pointers would be great.

from karma-rollup-preprocessor.

xenobytezero avatar xenobytezero commented on June 12, 2024

Follow up, after doing an ugly version of the processor that uses rollup.watch() rather than rollup.rollup() I am getting the output I expect, where the files are rebuilt and refreshing the debug page gives the updated files/test results.

It's very specific to my setup right now but it's doing what I need so I will clean it up and if people need it I can post.

from karma-rollup-preprocessor.

jlmakes avatar jlmakes commented on June 12, 2024

@xenobytezero I'd be curious to see your changes. If you have the time, please submit a PR.

from karma-rollup-preprocessor.

xenobytezero avatar xenobytezero commented on June 12, 2024

The changes are tied up in code it's a little tricky to open source right now, will see what I can do.

from karma-rollup-preprocessor.

YonatanKra avatar YonatanKra commented on June 12, 2024

@jlmakes I made it work.
I can't find the logic in the tests in order to write tests for it.
How do the tests work? All I see is a bunch of modules that import each other.
Please see this change: #74

from karma-rollup-preprocessor.

mattalexx avatar mattalexx commented on June 12, 2024

Just spend an hour solving this. My mistake for not looking further after noticing that my version matched your package.json at master.

Are you going to release soon?

from karma-rollup-preprocessor.

jlmakes avatar jlmakes commented on June 12, 2024

Thanks for your patience, the fix landed in 7.0.8 @mattalexx @YonatanKra

from karma-rollup-preprocessor.

mattalexx avatar mattalexx commented on June 12, 2024

Thanks @jlmakes

cc @Gusted

from karma-rollup-preprocessor.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.