Azure / Azure/static-web-apps-cli

not able to use swa cli as node dependencies in typescript project

Aperta
#691 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
command: deploy priority: low (P2) scope: deploy-client type: enhancement version: ga
Lingua principale
TypeScript
Stelle
668
Fork
156
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

Before filing this issue, please ensure you're using the latest CLI by running `swa --version` and comparing to the latest version on [npm](https://www.npmjs.com/package/@azure/static-web-apps-cli).

`1.1.1`

**Are you accessing the CLI from the default port `:4280` ?**

- [ ] No, I am using a different port number (`--port`) and accessing the CLI from that port
- [x] Yes, I am accessing the CLI from port `:4280`

> Make sure you are accessing the URL printed in the console when running `swa start`!

**ℹ️ NOTE: Make sure to enable debug logs when running any `swa` commands using `--verbose=silly`**

**Describe the bug**
I'm trying to use swa cli programmable in typescript project, but `@azure/static-web-apps-cli` package itself does not export/expose all types.

![image](https://user-images.githubusercontent.com/3431813/234918441-ed343b68-795b-4de4-9fa5-1752ec849554.png)

**To Reproduce**
Steps to reproduce the behavior:

1. Add `@azure/static-web-apps-cli` as project dependencies
2. Import config/deploy from the package, e.g.:

```typescript
import { DEFAULT_CONFIG as swaConfig } from '@azure/static-web-apps-cli/dist/config.js'
import { deploy as swaDeploy } from '@azure/static-web-apps-cli/dist/cli/commands/deploy/index.js'
```

3. Assign some properties to config, and run deploy e.g.:

```typescript
swaConfig.appLocation = 'myapp'
swaConfig.deploymentToken = 'xxxxxx...'
swaConfig.verbose = 'silly'
await swaDeploy(swaConfig)
```

4. Build the project `tsc`
5. See error:

```shell
> tsc

node_modules/@azure/static-web-apps-cli/dist/cli/commands/deploy/deploy.d.ts:1:41 - error TS2304: Cannot find name 'SWACLIConfig'.

1 export declare function deploy(options: SWACLIConfig): Promise;
~~~~~~~~~~~~

node_modules/@azure/static-web-apps-cli/dist/config.d.ts:1:38 - error TS2304: Cannot find name 'SWACLIConfig'.

1 export declare const DEFAULT_CONFIG: SWACLIConfig;
~~~~~~~~~~~~

Found 2 errors in 2 files.

Errors Files
1 node_modules/@azure/static-web-apps-cli/dist/cli/commands/deploy/deploy.d.ts:1
1 node_modules/@azure/static-web-apps-cli/dist/config.d.ts:1
```

**Expected behavior**
swa cli used in a typescript project as a dependencies package

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**

- OS: Windows
- Version: 11

**Additional context**
After exploring content of `node_modules/@azure/static-web-apps-cli/dist`, I saw not all types have been exported in distribution, lack of types defined here: https://github.com/Azure/static-web-apps-cli/blob/main/src/swa.d.ts

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Inizia confrontando src/swa.d.ts con le dichiarazioni generate in dist, in particolare config.d.ts e cli/commands/deploy/deploy.d.ts. Riproduci il problema importando DEFAULT_CONFIG e deploy in un progetto TypeScript ed eseguendo tsc. Il lavoro è completato quando SWACLIConfig è disponibile per queste dichiarazioni e il progetto di esempio viene compilato senza errori TS2304.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
cli
Tipo di issue
Bug
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Specificata chiaramente
Idoneità per principianti
48/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.