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

Support "module": "node16"/"nodenext" #23

Closed
jfirebaugh opened this issue Aug 14, 2024 · 4 comments
Closed

Support "module": "node16"/"nodenext" #23

jfirebaugh opened this issue Aug 14, 2024 · 4 comments

Comments

@jfirebaugh
Copy link
Contributor

Currently, tsconfig-to-swcconfig always outputs "module": { "type": "commonjs" } when the input tsconfig uses "module": "node16" or "module": "nodenext". Instead, if the nearest package.json has "type": "module", it should output "module": { "type": "es6" }.

@songkeys
Copy link
Owner

songkeys commented Sep 4, 2024

Thank you for bringing up this issue. It has been fixed and released in version v2.8.0.

@jfirebaugh
Copy link
Contributor Author

Well, now "module": "node16" and "module": "nodenext" are always considered ES6. The fix should be more like:

	const es6Modules = [
		'es2015',
		'es2020',
		'es2022',
		'esnext',
		'none',
	] as const
	if (es6Modules.includes(module as any)) {
		return 'es6'
	}

        const nodeModules = ['node16', 'nodenext'] as const
	if (nodeModules.includes(module as any) && getPackageJson(cwd)?.type === 'module') {
		return 'es6'
	}

@songkeys
Copy link
Owner

Thank you!
Would you like to send a Pull Request to address this issue?

jfirebaugh added a commit to jfirebaugh/tsconfig-to-swcconfig that referenced this issue Oct 15, 2024
With `"module": "node16"` and `"module": "nodenext"`, look at package.json to determine whether module type is es6 or commonjs. Previously, these values would unconditionally be treated as es6.

songkeys#23
@jfirebaugh
Copy link
Contributor Author

Sure, thanks for the encouragement: #24

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