Implement plugin cache invalidation with ESLint-style metadata#17808
Implement plugin cache invalidation with ESLint-style metadata#17808nvrakesh06 wants to merge 4 commits intoprettier:mainfrom
Conversation
Implements opt-in plugin metadata support for cache invalidation. Plugins can export prettierPluginMeta with name/version to enable proper cache invalidation when plugin versions change. Fully backward compatible - plugins without metadata behave identically. Fixes prettier#17260
Extends the plugin cache invalidation to include a package.json fallback when plugins don't export explicit prettierPluginMeta. This hybrid approach provides: 1. Explicit metadata (fastest, most reliable) 2. Package.json fallback (automatic for npm plugins) 3. Legacy behavior (unchanged for compatibility) Most existing npm-published plugins will now get automatic cache invalidation without any changes required. - Adds package.json reading with directory traversal - Includes caching to avoid repeated I/O - Comprehensive test coverage for all fallback scenarios - Updated documentation for hybrid approach
✅ Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
- Add dependency injection to plugin-signature module for testability - Replace Jest mocking with manual mocks using dependency injection - Export packageJsonCache for test cleanup - Clear cache between tests to prevent test interference - All 15 unit tests now pass successfully
commit: |
4aa3052 to
1ad22ef
Compare
- Change plugin metadata from prettierPluginMeta to meta object (ESLint-style) - Remove package.json fallback system - plugins must implement .meta - Preserve original plugin order instead of sorting for deterministic behavior - Extract plugins from options internally instead of passing separately - Update all tests and documentation to reflect simplified approach - Remove complex fallback logic and caching mechanisms Addresses PR comments: 1. Use ESLint-style explanation for plugin metadata 2. Plugins should implement .meta instead of relying on package.json fallback 3. Order matters - don't sort plugins 4. Shouldn't plugins already exist in options? (fisker)
1ad22ef to
75e2fb1
Compare
|
@fisker Updated based on your comments. Please review when you get a chance. |
|
@fisker Just following up on this PR for review. Thanks |
|
|
||
| return { | ||
| ...supportInfoToContextOptions(supportInfo), | ||
| loadedPlugins, |
There was a problem hiding this comment.
This should not be done here, we can add a function to do the hash calculation and wrap with withPlugins(), then the function will receive loaded plugins.
There was a problem hiding this comment.
Ah, you already have createPluginSignature, export the wrapped version in index.js should work.
| // Create compact signature: "name@version,name@version" | ||
| return pluginMetadata | ||
| .map(({ name, version }) => `${name}@${version}`) | ||
| .join(","); |
There was a problem hiding this comment.
Can't we simply replace the whole function with
function createPluginSignature(plugins) {
return plugins.map(plugin => `${plugin.meta?.name}@${plugin.meta?.version}`);
}?
| export const meta = { | ||
| name: "prettier-plugin-example", | ||
| version: "1.2.3", | ||
| namespace: "example" |
There was a problem hiding this comment.
The namespace should be removed, since we are not going to use. Eslint add this so user can use namespace/foo-rule to reference the rule.
| "--plugin", | ||
| "./test-plugin.js", | ||
| "test.js", | ||
| ]); |
There was a problem hiding this comment.
I think we can print differnt result to simplify the tests.
Something like this
export default {
meta: {
name: "test-plugin",
version: "1.0.0"
},
languages: [
{
name: "test-lang",
parsers: ["test-parser"],
extensions: [".js"]
}
],
parsers: {
"test-parser": {
parse: (text) => ({ /* whatever */ }),
astFormat: "test-ast"
}
},
printers: {
"test-ast": {
print: (path) => '1.0.0'
}
}
}|
Hello, @nvrakesh06 I want make a change here, instead of |
Description
This PR implements plugin cache invalidation for Prettier to fix issue #17260. The implementation uses a simplified ESLint-style approach where plugins export a
metaobject with name and version information for proper cache invalidation.Implementation
ESLint-Style Plugin Metadata
metaobject withname,version, and optionallynamespacepropertiesPlugin Metadata Format
Simplified Cache Implementation
options.pluginsinternallyFiles Modified
docs/cli.md- Updated CLI documentation with simplified cache approachdocs/plugins.md- Updated plugin documentation with ESLint-style metadata approachsrc/main/plugins/plugin-signature.js- Simplified plugin signature logicsrc/cli/format.js- Clean cache function callssrc/cli/format-results-cache.js- Extract plugins from options internallytests/integration/__tests__/cache-plugin-invalidation.js- Integration teststests/unit/format-results-cache.test.js- Cache unit teststests/unit/plugin-signature.test.js- Plugin signature unit testsBenefits
Checklist
Fixes: Cache invalidation on plugin upgrade with optional metadata #17260