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

Task; extract and create npm package #6172

Draft
wants to merge 75 commits into
base: task/extension/remove-kiota-interop-tight-coupling
Choose a base branch
from

Conversation

thewahome
Copy link
Contributor

@thewahome thewahome commented Feb 19, 2025

Overview

  • Extracts the npm package code into its own folder inside the vscode folder.
  • Adds pipeline changes to generate both the package and vsix in the GitHub actions
  • Adds pipeline changes to deploy the npm package to npm

Folder Visualisation

vscode
├── microsoft-kiota/
├── npm-package/
│ ├── lib/
│ │ ├── generateClient.ts
│ │ ├── generatePlugin.ts
│ │ └── ...
│ ├── tests/
│ │ ├── generateClient.spec.ts
│ │ └── ...
│ ├── connect.ts
│ ├── install.ts
│ ├── ...
│ ├── runtime.json
│ ├── readme.md
│ └── index.ts
├── node_modules/
├── ...
├── lerna.json
└── package.json

Testing the npm package

  1. Package the Kiota npm package. It should generate a .tgz file microsoft-kiota-1.0.0.tgz.
cd vscode/npm-package
npm pack
  1. Create a new directory for your project and navigate into it:
    Initialize a new Node.js project. The default is (commonjs), but you can change it later to ES6 modules by setting "module": "ES6" in your tsconfig.json file and reinstall the kiota npm package
mkdir use-kiota
cd use-kiota
npm init -y
npm install typescript @types/node --save-dev
npm install 'path/to/microsoft-kiota-1.0.0.tgz'
npx tsc --init
code .
  1. Create a new file named index.ts at the root of the project and add the following code:
import { getKiotaVersion } from '@microsoft/kiota';
const getVersion = async () => {
  const version = await getKiotaVersion();
  console.log(version);
}
console.log("Hello, World!");
getVersion();
  1. Run the TypeScript compiler to compile your index.ts file into JavaScript and run the compiled code:
npx tsc
node index.js

The expected result is:

Hello, World!
1.23.0

@@ -610,7 +610,7 @@ extends:
displayName: "Set version suffix"
- pwsh: $(Build.SourcesDirectory)/scripts/get-version-from-csproj.ps1
displayName: "Get Kiota's version-number from .csproj"
- pwsh: $(Build.SourcesDirectory)/scripts/update-vscode-releases.ps1 -version $(artifactVersion)$(versionSuffix) -packageJsonFilePath $(Build.SourcesDirectory)/vscode/microsoft-kiota/package.json -runtimeFilePath $(Build.SourcesDirectory)/vscode/microsoft-kiota/src/kiotaInterop/runtime.json -binaryFolderPath $(Build.ArtifactStagingDirectory)/Binaries
- pwsh: $(Build.SourcesDirectory)/scripts/update-vscode-releases.ps1 -version $(artifactVersion)$(versionSuffix) -packageJsonFilePath $(Build.SourcesDirectory)/vscode/microsoft-kiota/package.json -runtimeFilePath $(Build.SourcesDirectory)/vscode/npm-package/runtime.json -binaryFolderPath $(Build.ArtifactStagingDirectory)/Binaries
displayName: "Update VSCode extension version-number"
- script: npm i -g @vscode/vsce
displayName: "Install vsce"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we'll need additional steps to publish the package as well.

@@ -0,0 +1,34 @@
import stylisticTs from '@stylistic/eslint-plugin-ts';
import typescriptEslint from "@typescript-eslint/eslint-plugin";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we also add the microsoft graph eslint configuration? (see kiota-typescript or graph TS)

"$schema": "node_modules/lerna/schemas/lerna-schema.json",
"version": "0.0.0",
"packages": [
"microsoft-kiota",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the need to match what's in the package.json name. Aslo using more explicit names would probably help people running the commands

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried this... it uses the folder name not the name of the package.

Also what would be the names we would give? Plus it would increase the number of code changes to rename the folders

@thewahome thewahome force-pushed the task/extension/extract-and-create-npm-package branch from ae83aa1 to c5f3828 Compare February 24, 2025 05:53
Copy link
Member

@garethj-msft garethj-msft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Put a few structural comments in

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FIlename snake case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't feel like the npm-package folder should live under vscode as it should have no dependencies on vscode

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would another location allow the extension to share the npm-package from elsewhere?

"typescript": "^5.7.3"
},
"workspaces": [
"microsoft-kiota",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the general pattern is to create a kind of fake minimal package at the top level to define the workspace

Copy link

Quality Gate Failed Quality Gate failed for 'kiota'

Failed conditions
2 Security Hotspots
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

…o task/extension/extract-and-create-npm-package
@thewahome thewahome marked this pull request as ready for review February 28, 2025 11:24
@thewahome thewahome requested a review from a team as a code owner February 28, 2025 11:24
@thewahome thewahome marked this pull request as draft February 28, 2025 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants