Skip to content

[Bug]: can not use a local build emitter in tsp 0.67.1 #6625

Open
@dolauli

Description

@dolauli

Describe the bug

I used to be able to use a local build emitter to generate code for testing or debugging purposes.

tsp compile ./ --emit c:\Users\<username>\source\autorest.powershell\packages\typespec-powershell

However, after upgrading to TypeSpec/Compiler 0.67.1, I found that it no longer works.

I noticed two major issues

  1. It will report issues as below.
Diagnostics were reported during compilation:

../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/main.tsp:21:1 - error @azure-tools/typespec-azure-resource-manager/single-arm-provider: Only one @armProviderNamespace can be declared in a typespec spec at once.
> 21 | @armProviderNamespace
     | ^^^^^^^^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/WebhookResource.tsp:29:7 - error @azure-tools/typespec-azure-resource-manager/arm-resource-missing-arm-namespace: The @armProviderNamespace decorator must be used to define the ARM namespace of the service.  This is best applied to the file-level namespace.
> 29 | model WebhookResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/SnapshotResource.tsp:23:7 - error @azure-tools/typespec-azure-resource-manager/arm-resource-missing-arm-namespace: The @armProviderNamespace decorator must be used to define the ARM namespace of the service.  This is best applied to the file-level namespace.
> 23 | model SnapshotResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/ScopingConfigurationResource.tsp:31:7 - error @azure-tools/typespec-azure-resource-manager/arm-resource-missing-arm-namespace: The @armProviderNamespace decorator must be used to define the ARM namespace of the service.  This is best applied to the file-level namespace.
> 31 | model ScopingConfigurationResource
     |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/EvidenceResource.tsp:25:7 - error @azure-tools/typespec-azure-resource-manager/arm-resource-missing-arm-namespace: The @armProviderNamespace decorator must be used to define the ARM namespace of the service.  This is best applied to the file-level namespace.
> 25 | model EvidenceResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/ReportResource.tsp:25:7 - error @azure-tools/typespec-azure-resource-manager/arm-resource-missing-arm-namespace: The @armProviderNamespace decorator must be used to define the ARM namespace of the service.  This is best applied to the file-level namespace.
> 25 | model ReportResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/ReportResource.tsp:25:7 - error @azure-tools/typespec-azure-resource-manager/arm-resource-missing: No @armResource registration found for type ReportResource
> 25 | model ReportResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/WebhookResource.tsp:29:7 - error @azure-tools/typespec-azure-resource-manager/parent-type: Parent type ReportResource of WebhookResource is not registered as an ARM resource type.
> 29 | model WebhookResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/ReportResource.tsp:25:7 - error @azure-tools/typespec-azure-resource-manager/arm-resource-missing: No @armResource registration found for type ReportResource
> 25 | model ReportResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/WebhookResource.tsp:29:7 - error @azure-tools/typespec-azure-resource-manager/parent-type: Parent type ReportResource of WebhookResource is not registered as an ARM resource type.
> 29 | model WebhookResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/ReportResource.tsp:25:7 - error @azure-tools/typespec-azure-resource-manager/arm-resource-missing: No @armResource registration found for type ReportResource
> 25 | model ReportResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/SnapshotResource.tsp:23:7 - error @azure-tools/typespec-azure-resource-manager/parent-type: Parent type ReportResource of SnapshotResource is not registered as an ARM resource type.
> 23 | model SnapshotResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^^^
../C:/Users/xidi/source/autorest.powershell/tests-upgrade/tests-emitter/AppComplianceAutomation.Management/resources/ReportResource.tsp:25:7 - error @azure-tools/typespec-azure-resource-manager/arm-resource-missing: No @armResource registration found for type ReportResource
> 25 | model ReportResource extends Azure.ResourceManager.Foundations.ProxyResource {
     |       ^^^^^^^^^^^^^^
...
  1. The API listServices will return two duplicated services.

Image

Some investigation

The root cause of the issue appears to be the presence of two copies of TypeSpec/Compiler: one in my emitter project and another in my test project.

How to workaround the issue

I can work around the issue by packaging my emitter locally and then installing the emitter package. However, this process is very inconvenient for testing and debugging my emitter.

Reproduction

  1. Install node 20 and rush.
  2. Clone the repo https://github.com/dolauli/autorest.powershell/tree/tspupgrade
  3. Go to the root folder and execute rush update and rush rebuild
  4. Go to tests-upgrade/tests-emitter, edit package.json, remove "@azure-tools/typespec-powershell": "file:../../common/temp/artifacts/packages/azure-tools-typespec-powershell-0.0.1.tgz", and run npm install
  5. Install tsp compiler npm install -g @typespec/compiler@latest
  6. Go to tests-upgrade/tests-emitter/AppComplianceAutomation.Management and run tsp compile ./ --emit c:\Users\<username>\source\autorest.powershell\packages\typespec-powershell or node --inspect-brk 'C:\Users\<username>\source\autorest.powershell\packages\typespec-powershell\node_modules\@typespec\compiler\cmd\tsp.js' compile ./ --emit C:\Users\<username>\source\autorest.powershell\packages\typespec-powershell to debug the code
  7. You will see the issues I mention above

Following the same steps with TSP before version 0.67.1, everything worked fine. You can check out the main branch (which still uses version 0.64.0) of the repo mentioned above to give it a try.

How to workaround

  1. Add "@azure-tools/typespec-powershell": "file:../../common/temp/artifacts/packages/azure-tools-typespec-powershell-0.0.1.tgz", back to the package.json file I mentioned above
  2. Pack the emitter locally rush publish --publish --pack --include-all --tag latest
  3. Go to tests-upgrade/tests-emitter/ and run npm install
  4. Go to tests-upgrade/tests-emitter/AppComplianceAutomation.Management, and run tsp compile ./ --emit @azure-tools/typespec-powershell
  5. Everything works fine

Checklist

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions