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

[Feature] Support assert { type: 'json' } #60

Closed
HarelM opened this issue Jan 21, 2024 · 2 comments
Closed

[Feature] Support assert { type: 'json' } #60

HarelM opened this issue Jan 21, 2024 · 2 comments

Comments

@HarelM
Copy link

HarelM commented Jan 21, 2024

Plugin does not support assert { type: 'json' }?

Expected Behavior

Build should pass

Current Behavior

Build fails with the following error:

[!] (plugin istanbul) SyntaxError: /Users/harelmazor/dev/maplibre-gl-js/src/index.ts: Support for the experimental syntax 'importAttributes' isn't currently enabled (1:43):

> 1 | import packageJSON from '../package.json' assert { type: 'json' };

Possible Solution

I'm not sure, is there a rollup plugin that removes this assetion?

Steps to Reproduce

Add the plugin to a project that has this statement in the code.
I'm using typescript, so it might be related, IDK.

Context (Environment)

I'm trying to add coverage to my e2e tests, this proves a lot harder than I thought as there are different kind of styles to code coverage.

Detailed Description

Support this type of code, which I believe to be valid...?

Possible Implementation

IDK, I'm not a rollup expert...

@artberri
Copy link
Owner

artberri commented Oct 2, 2024

Hi @HarelM and sorry for the late reply.

This is not a bug, but a configuration issue. First of all you will probably need to use @rollup/plugin-json if you want to bundle the json file. And for the code instrumentation, you need to add the config to the instrumenter with the instrumenterConfig configuration option. Something like this should do the job:

	instrumenterConfig: {
		produceSourceMap: true,
		parserPlugins: [
			["importAttributes", { deprecatedAssertSyntax: true }],
		],
		generatorOpts: {
			importAttributesKeyword: "assert",
		},
	},

I've just added an example of using import assertions to one of the examples in this repo and it works:
https://github.com/artberri/rollup-plugin-istanbul/blob/main/examples/karma-ts/karma.conf.js

I'm sorry I couldn't answer you before, and this probably won't help you now, but just in case.

Thank you.

@HarelM
Copy link
Author

HarelM commented Oct 5, 2024

I've found a different solution without using this plugin, but thanks anyway!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants