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: Allow Blocks to infer Addons from disk #128

Open
2 tasks done
JoshuaKGoldberg opened this issue Jan 14, 2025 · 0 comments
Open
2 tasks done

🚀 Feature: Allow Blocks to infer Addons from disk #128

JoshuaKGoldberg opened this issue Jan 14, 2025 · 0 comments
Assignees
Labels
status: blocked Waiting for something else to be resolved type: feature New enhancement or request
Milestone

Comments

@JoshuaKGoldberg
Copy link
Owner

JoshuaKGoldberg commented Jan 14, 2025

Bug Report Checklist

Overview

As of #88 -> #95, config files can specify Addons. Which is great! I should theoretically be able to make a create.config.js in any of my repos that use create-typescript-app and run npx create typescript-app without clobbering over changes specified as Addons.

For example, to add some rules to an eslint.config.js the way CTA does:

// eslint.config.js
// ...
rules: {
	// These on-by-default rules work well for this repo if configured
	"@typescript-eslint/prefer-nullish-coalescing": [
		"error",
		{ ignorePrimitives: true },
	],
	"@typescript-eslint/restrict-template-expressions": [
		"error",
		{ allowBoolean: true, allowNullish: true, allowNumber: true },
	],
// ...

...a create.config.js can specify those in the ESLint Block:

// create.config.js
import { createConfig } from "create";
import { presetEverything } from "create-typescript-app";

export default createConfig(presetEverything, {
	addons: [
		blockESLint({
			rules: [
				{
					comment:
						"These on-by-default rules work well for this repo if configured",
					entries: {
						"@typescript-eslint/prefer-nullish-coalescing": [
							"error",
							{ ignorePrimitives: true },
						],
						"@typescript-eslint/restrict-template-expressions": [
							"error",
							{ allowBoolean: true, allowNullish: true, allowNumber: true },
						],
					},
				},
			],
		}),
	],
});

But, manually specifying Addons in a create.config.js is clunky. It means you have those changes specified in two places at once. I don't think most end-users would be happy with a system requiring that. I certainly wouldn't be.

I think the only way to get this right would be to make Addons _automatically inferable from files on disk. As in, that create.config.js should be able to not manually specify any Addons:

import { createConfig } from "create";
import { presetEverything } from "create-typescript-app";

export default createConfig(presetEverything);

...and instead read the existing eslint.config.js to parse the addons from the text in the file:

{
	"comment": "These on-by-default rules work well for this repo if configured",
	"entries": {
		"@typescript-eslint/prefer-nullish-coalescing": [
			"error",
			{ "ignorePrimitives": true }
		],
		"@typescript-eslint/restrict-template-expressions": [
			"error",
			{ "allowBoolean": true, "allowNullish": true, "allowNumber": true }
		]
	}
}

I'm very confident this is the right direction to take the engine, but I don't yet know how to do it. I don't know if Handlebars or Mustache can theoretically support such a reverse-mapping. There might be an existing third-party project but I wouldn't be surprised if not. If they can't theoretically support this, I might have to make some kind of more direct, less-featured custom templating engine. 😬

Additional Info

Marking as Blocked until at least the Blocks Launch milestone is done. This is pretty tricky and should probably come after the templating engine is made more pluggable per #76.

💝

@JoshuaKGoldberg JoshuaKGoldberg added type: feature New enhancement or request status: blocked Waiting for something else to be resolved labels Jan 14, 2025
@JoshuaKGoldberg JoshuaKGoldberg added this to the Broad Launch milestone Jan 14, 2025
@JoshuaKGoldberg JoshuaKGoldberg self-assigned this Jan 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: blocked Waiting for something else to be resolved type: feature New enhancement or request
Projects
None yet
Development

No branches or pull requests

1 participant