Fix ts-morph insertImportDeclaration and use hash-based constant identifiers#4842
Merged
Fix ts-morph insertImportDeclaration and use hash-based constant identifiers#4842
Conversation
# Conflicts: # packages/cli/files/references.json
- Modified defineExtension.ts to return React component with .def, .getDefinition() properties - Maintained backward compatibility with .definition and .ReactComponent - Updated all index.ts files to use .def instead of .definition - Updated all usage files to remove .ReactComponent accessor - Updated ProjectConfigModel to support both old and new API Co-authored-by: adrians5j <5121148+adrians5j@users.noreply.github.com>
Co-authored-by: adrians5j <5121148+adrians5j@users.noreply.github.com>
Co-authored-by: adrians5j <5121148+adrians5j@users.noreply.github.com>
Co-authored-by: adrians5j <5121148+adrians5j@users.noreply.github.com>
Co-authored-by: adrians5j <5121148+adrians5j@users.noreply.github.com>
Co-authored-by: adrians5j <5121148+adrians5j@users.noreply.github.com>
…nition-return-type
…nsion.ts and AdminExtension.ts Co-authored-by: adrians5j <5121148+adrians5j@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Update code to follow rules from Slack conversation
Fix ts-morph insertImportDeclaration to use namedImports instead of defaultImport
Jan 5, 2026
|
Jest tests have been initiated (for more information, click here). ✨ |
|
Vitest tests have been initiated (for more information, click here). ✨ |
|
Cypress E2E tests have been initiated (for more information, click here). ✨ |
|
Cypress E2E tests have been initiated (for more information, click here). ✨ |
Member
|
Looks like you did not receive my sshot. Here it is: Note the retry @copilot |
Co-authored-by: adrians5j <5121148+adrians5j@users.noreply.github.com>
Contributor
Author
|
... Updated both files to use hash-based constant identifiers. Changes in commit d75de3d:
The identifiers are now constant (same path = same hash) and use the last 10 characters of the SHA-256 hash for uniqueness. |
Copilot
AI
changed the title
Fix ts-morph insertImportDeclaration to use namedImports instead of defaultImport
Fix ts-morph insertImportDeclaration and use hash-based constant identifiers
Jan 5, 2026
…d-admin-extensions
Copilot AI
added a commit
to loomery/aibenchmarking-webiny-js-backend-ai-arena
that referenced
this pull request
Mar 6, 2026
Co-authored-by: adrians5j <adrian@webiny.com> Co-authored-by: Adrian Smijulj <adrian1358@gmail.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: adrians5j <5121148+adrians5j@users.noreply.github.com>
Copilot AI
added a commit
to loomery/aibenchmarking-webiny-js-backend-ai-arena
that referenced
this pull request
Mar 6, 2026
Co-authored-by: adrians5j <adrian@webiny.com> Co-authored-by: Adrian Smijulj <adrian1358@gmail.com> Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: adrians5j <5121148+adrians5j@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

The code was incorrectly using
defaultImportfor named imports in ts-morph'sinsertImportDeclarationAPI, which would generate malformed import statements. Additionally, the identifier generation was using non-constant values (timestamps and long PascalCase paths), which should be replaced with hash-based constant identifiers.Changes
defineApiExtension.ts:
namedImports: [{ name: exportName, alias: exportNameAlias }]for aliased importsnamedImports: ["createContextPlugin"]for simple named importsCase.pascal(extensionFilePath)withApiExtension_<10-char-hash>using SHA-256 hash of file pathAdminExtension.ts:
namedImports: [{ name: "Extension", alias: componentName }]for aliased importsCase.pascal("Something" + Date.now()) + "Extension"withAdminExtension_<10-char-hash>using SHA-256 hash of file pathExample
ts-morph API fix:
Hash-based identifier generation:
The hash-based approach ensures identifiers are constant (same file path always generates the same identifier), unique (SHA-256 with 10 characters provides sufficient uniqueness), and readable (short identifiers like
ApiExtension_xyz).Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.