ProjectEvergreen / greenwood

Greenwood is your workbench for the web, embracing web standards from the ground up to empower your stack from front to back.
https://www.greenwoodjs.io
MIT License
97 stars 9 forks source link

refactor project to use JSON Modules #1015

Open thescientist13 opened 1 year ago

thescientist13 commented 1 year ago

After the upgrade to #1014 for Node v18 support, we can now refactor all instances of reading a JSON file to use native JSON modules, using import assertions

// before
const packageJson = JSON.parse(fs.readFileSync('./package.json', 'utf-8'));
const greenwoodPackageJson = JSON.parse(await fs.promises.readFile(new URL('../package.json', import.meta.url), 'utf-8'))

// after
import packageConfig from './package.json' assert { type: 'json' };

So goal would be to go and replace all those instances to the new version.


This will also require us updating our ESLint version to include support for import assertions, which we might still need to wait for? https://github.com/eslint/eslint/discussions/15305

Or maybe we can get around it with a plugin?

aholtzman commented 1 year ago

@thescientist13 Switching from @typescript-eslint/parser to @babel/eslint-parser as the lint parser introduces 15 errors, plus the usual warnings.

14 are Parsing error: Unexpected reserved word 'await' 1 is Parsing error: Unexpected reserved word 'interface'

These will need to be addressed for this to proceed, just a heads up.

thescientist13 commented 1 year ago

Thanks for looking into that. Pretty much @typescript-eslint/parser is there for the couple of files we have that are TypeScript in plugin-typescript package. So wonder if there's a lighter weight way to get some basic TS combat as part of this, or maybe if it's a total blocker, we can probably make a chore ticket to track just that support. It's a just a couple files so a very small blip in the overall contents of the project.