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

fix: add "package.json" and types to exports for all packages #484

Merged
merged 2 commits into from Aug 7, 2022

Conversation

saibotsivad
Copy link
Contributor

From #467 this adds the "./package.json": "./package.json" to all packages/*/package.json files.

For posterity, here's the script I used:

// add-package-json.mjs
import { readdir, readFile, writeFile } from 'node:fs/promises'
import { join } from 'node:path'
const ROOT = 'packages'
const dirs = await readdir(ROOT)
for (const dir of dirs) {
	const filepath = join(ROOT, dir, 'package.json')
	const pkg = JSON.parse(await readFile(filepath))
	pkg.exports['./package.json'] = './package.json'
	writeFile(filepath, JSON.stringify(pkg, undefined, 2), 'utf8')
}

The results are pretty straightforward.

@saibotsivad
Copy link
Contributor Author

Oh hey, I just noticed the discussion in 429 about adding types to the export.

I've added an additional commit to add the types property to all packages, this will close #483 as well.

For posterity, that script looks like this (very similar to the above):

// add-types.mjs
import { readdir, readFile, writeFile } from 'node:fs/promises'
import { join } from 'node:path'
const ROOT = 'packages'
const dirs = await readdir(ROOT)
for (const dir of dirs) {
	// test that there is a types file in all packages, will throw if not found
	await readFile(join(ROOT, dir, 'index.d.ts'), 'utf8')
	const filepath = join(ROOT, dir, 'package.json')
	const pkg = JSON.parse(await readFile(filepath))
	pkg.exports['.'].types = './index.d.ts'
	writeFile(filepath, JSON.stringify(pkg, undefined, 2), 'utf8')
}

@saibotsivad saibotsivad changed the title fix: add package.json to exports fix: add "package.json" and types to exports for all packages Aug 7, 2022
@angus-c
Copy link
Owner

angus-c commented Aug 7, 2022

This is great—much appreciated!!

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

Successfully merging this pull request may close these issues.

None yet

2 participants