Skip to content

Commit

Permalink
Update npm api builld pipeline (#14309)
Browse files Browse the repository at this point in the history
* Updates to publishing npm

* updates

* wip

* Rename type
  • Loading branch information
DonJayamanne authored Sep 12, 2023
1 parent 2f76851 commit 024313d
Show file tree
Hide file tree
Showing 14 changed files with 131 additions and 103 deletions.
3 changes: 2 additions & 1 deletion api/.npmignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.gitignore
tsconfig.json
build.js
stable.js
proposed.js
clean.js
2 changes: 1 addition & 1 deletion api/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Installation

`npm install @vscode/jupyter`
`npm install @vscode/jupyter-extension`

# Summary

Expand Down
85 changes: 0 additions & 85 deletions api/build.js

This file was deleted.

6 changes: 3 additions & 3 deletions api/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@vscode/jupyter-extension",
"description": "Contains the type definitions for the API exposed by the Jupyter Extension for VS Code",
"version": "1.0.0",
"version": "0.0.0",
"author": {
"name": "Microsoft Corporation"
},
Expand All @@ -21,8 +21,8 @@
"url": "https://github.com/Microsoft/vscode-jupyter/issues"
},
"scripts": {
"prepublishOnly": "npm run clean && npm run build",
"build": "node ./build.js",
"buildStable": "npm run clean && node ./stable.js",
"buildProposed": "npm run clean && node ./proposed.js",
"clean": "node ./clean.js"
}
}
83 changes: 83 additions & 0 deletions api/proposed.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

const { EOL } = require('os');
const fs = require('fs');
const path = require('path');

// For stable we only ship the api.d.ts file.
fs.copyFileSync(path.join(__dirname, '../src/api.d.ts'), path.join(__dirname, 'api.d.ts'));

// For proposed API, we need to merge all proposed API files into a single file.
// Anyone installing the proposed tag will get all of the proposed API
// Today we have at lest 3 extensions that manually pull down *.d.ts files via some automated scripts, shipping proposed API
// in the npm makes it easier for other consumers as well (DW, AzML, Synapse, etc).

// Ensure all imports are on top
// Ensure we have a module declaration that matches the npm package name.
// Duplicate imports is not a problem.

let proposedApi = '';
let proposedApiImports = [];
const tab = ' '; // 4 spaces used as tab size in source formatting.
const newModuleDeclaration = `declare module '@vscode/jupyter-extension' {`;
fs.readdirSync(path.join(__dirname, '../src')).forEach((file) => {
if (file.startsWith('api.proposed.') && file.endsWith('.d.ts')) {
console.error(file);
let source = fs.readFileSync(path.join(__dirname, '../src', file), 'utf8').toString();
let foundFirstExport = false;
const newSource = source
.replace(`declare module './api' {`, newModuleDeclaration)
.split(/\r?\n/g)
.filter((line) => {
if (foundFirstExport) {
return true;
}
if (line.startsWith('import ') && line.trim().endsWith(';')) {
proposedApiImports.push(line);
return false;
}
if (line.startsWith(newModuleDeclaration)) {
foundFirstExport = true;
}
return false;
})
.join(EOL);

// Remove the trailing `}`
// Do not trim leading spaces, as we need to preserve the indentation.
proposedApi += ('1' + newSource).trim().slice(0, -1).substring(1) + EOL;
}
});
// Add module namespace to the main api.d.ts file.
// Required for module augmentation to work.
const source = fs.readFileSync(path.join(__dirname, 'api.d.ts'), 'utf8').toString();
let foundFirstExport = false;
const newSource = source
.split(/\r?\n/g)
.map((line) => {
if (proposedApiImports.length && line.startsWith('import ') && line.trim().endsWith(';')) {
const newLine = [line, ...proposedApiImports].join(EOL);
proposedApiImports = [];
return newLine;
}
if (line.startsWith('export ') && !foundFirstExport) {
foundFirstExport = true;
let imports = '';
if (proposedApiImports.length) {
imports = proposedApiImports.join(EOL) + EOL + EOL;
}
return imports + [`declare module '@vscode/jupyter-extension' {`, `${tab}${line}`].join(EOL);
}
if (foundFirstExport) {
return `${tab}${line}`;
}
return line;
})
.join(EOL);

// Do not trim leading spaces, as we need to preserve the indentation.
fs.writeFileSync(
path.join(__dirname, 'api.d.ts'),
newSource.trim() + EOL + `1${proposedApi}`.trim().substring(1) + EOL + '}' + EOL
);
9 changes: 9 additions & 0 deletions api/stable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

const { EOL } = require('os');
const fs = require('fs');
const path = require('path');

// For stable we only ship the api.d.ts file.
fs.copyFileSync(path.join(__dirname, '../src/api.d.ts'), path.join(__dirname, 'api.d.ts'));
12 changes: 12 additions & 0 deletions build/azure-pipeline.npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ resources:
endpoint: Monaco

parameters:
- name: nextVersion
displayName: '🚀 Release Version (eg: none, major, minor, patch, or X.X.X)'
type: string
default: 'none'
- name: quality
displayName: Quality
type: string
Expand All @@ -29,6 +33,14 @@ extends:
parameters:
npmPackages:
- name: jupyterExtensionApi
buildSteps:
- script: npm run buildStable
workingDirectory: $(Build.SourcesDirectory)/api
condition: not(eq('${{ parameters.quality }}', 'proposed'))
- script: npm run buildProposed
workingDirectory: $(Build.SourcesDirectory)/api
condition: eq('${{ parameters.quality }}', 'proposed')
tag: ${{ parameters.quality }}
publishPackage: ${{ parameters.publishJupyterApi }}
nextVersion: ${{ parameters.nextVersion }}
workingDirectory: $(Build.SourcesDirectory)/api
6 changes: 3 additions & 3 deletions src/api.d.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { CancellationToken, ProviderResult, CancellationError } from 'vscode';
import { Event, Uri } from 'vscode';
import type { CancellationToken, ProviderResult, CancellationError } from 'vscode';
import type { Event, Uri } from 'vscode';

export interface JupyterAPI {
export interface Jupyter {
/**
* Creates a Jupyter Server Collection that can be displayed in the Notebook Kernel Picker.
*
Expand Down
2 changes: 1 addition & 1 deletion src/api.internal.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { Event, QuickPickItem, Uri } from 'vscode';
import type { Event, QuickPickItem, Uri } from 'vscode';

// These types are only used internally within the extension.
// Never to be exposed to other extensions.
Expand Down
2 changes: 1 addition & 1 deletion src/api.proposed.mappedRemoteDirectory.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { Uri } from 'vscode';
import type { Uri } from 'vscode';

declare module './api' {
export interface JupyterServer {
Expand Down
2 changes: 1 addition & 1 deletion src/api.proposed.removeJupyterServer.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { Uri } from 'vscode';
import type { Uri } from 'vscode';

declare module './api' {
export interface JupyterServerProvider {
Expand Down
4 changes: 2 additions & 2 deletions src/api.pythonIntegration.d.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { PythonApi } from './platform/api/types';
import type { PythonApi } from './platform/api/types';

declare module './api' {
/**
* These types are not required for any other extension, except for the Python extension.
* Hence the reason to keep this separate. This way we can keep the API stable for other extensions (which would be the majority case).
*/
export interface JupyterAPI {
export interface Jupyter {
registerPythonApi(pythonApi: PythonApi): void;
}
}
14 changes: 11 additions & 3 deletions src/api.unstable.d.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { CancellationToken, Disposable, Event, NotebookController, NotebookDocument, QuickPickItem, Uri } from 'vscode';
import type {
CancellationToken,
Disposable,
Event,
NotebookController,
NotebookDocument,
QuickPickItem,
Uri
} from 'vscode';
import type { Kernel } from '@jupyterlab/services/lib/kernel';
import type { Session } from '@jupyterlab/services';
import { IDataViewerDataProvider } from './webviews/extension-side/dataviewer/types';
import type { IDataViewerDataProvider } from './webviews/extension-side/dataviewer/types';

declare module './api' {
export interface JupyterAPI {
export interface Jupyter {
/**
* Promise indicating whether all parts of the extension have completed loading or not.
* @type {Promise<void>}
Expand Down
4 changes: 2 additions & 2 deletions src/standalone/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { sendTelemetryEvent } from '../../telemetry';
import { noop } from '../../platform/common/utils/misc';
import { isRemoteConnection } from '../../kernels/types';
import {
JupyterAPI,
Jupyter,
IExportedKernelService,
IJupyterUriProvider,
JupyterServerCollection,
Expand All @@ -33,7 +33,7 @@ export interface IExportedKernelServiceFactory {
* This is the public API for other extensions to interact with this extension.
*/

export interface IExtensionApi extends JupyterAPI {}
export interface IExtensionApi extends Jupyter {}

function waitForNotebookControllersCreationForServer(
serverId: { id: string; handle: string },
Expand Down

0 comments on commit 024313d

Please sign in to comment.