Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .chronus/changes/playground-upload-overwrite-2026-10-21.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
changeKind: internal
packages:
- "@typespec/bundle-uploader"
---

Allow Playground package uploads to replace existing versions with `--overwrite`, and expose the option in the core publish pipeline.
14 changes: 11 additions & 3 deletions eng/emitters/scripts/upload-bundled-emitter.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
// @ts-check
import { parseArgs } from "node:util";
import { resolve } from "path";
import { bundleAndUploadStandalonePackage } from "../../../packages/bundle-uploader/dist/src/index.js";
import { repoRoot } from "../../common/scripts/helpers.ts";

const packageRelativePath = process.argv[2];
const { values, positionals } = parseArgs({
options: {
overwrite: { type: "boolean", default: false },
},
allowPositionals: true,
});

const packageRelativePath = positionals[0];
Comment on lines +9 to +14
if (!packageRelativePath) {
// eslint-disable-next-line no-console
console.error("Usage: node upload-bundled-emitter.ts <package-path>");
console.error("Usage: node upload-bundled-emitter.ts <package-path> [--overwrite]");
// eslint-disable-next-line no-console
console.error(" e.g. node upload-bundled-emitter.ts packages/http-client-csharp");
process.exit(1);
Expand All @@ -15,4 +23,4 @@ if (!packageRelativePath) {
// remove leading slash if exists, then resolve to absolute path
const packagePath = resolve(repoRoot, packageRelativePath.replace(/^\//, ""));

await bundleAndUploadStandalonePackage({ packagePath });
await bundleAndUploadStandalonePackage({ packagePath, overwrite: values.overwrite });
7 changes: 6 additions & 1 deletion eng/tsp-core/pipelines/jobs/build-packages.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
parameters:
- name: overwritePlaygroundPackages
type: boolean
default: false

jobs:
- job: build
displayName: Build Packages
Expand Down Expand Up @@ -44,7 +49,7 @@ jobs:
azureSubscription: "Azure SDK Engineering System"
scriptType: bash
scriptLocation: inlineScript
inlineScript: node ./eng/tsp-core/scripts/upload-bundler-packages.ts
inlineScript: node ./eng/tsp-core/scripts/upload-bundler-packages.ts ${{ iif(parameters.overwritePlaygroundPackages, '--overwrite', '') }}

- task: AzureCLI@2
displayName: Upload scenario manifest
Expand Down
8 changes: 8 additions & 0 deletions eng/tsp-core/pipelines/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ trigger:

pr: none

parameters:
- name: overwritePlaygroundPackages
displayName: Overwrite existing Playground package versions
type: boolean
default: false

extends:
template: /eng/common/pipelines/templates/1es-redirect.yml
parameters:
Expand All @@ -29,6 +35,8 @@ extends:

jobs:
- template: /eng/tsp-core/pipelines/jobs/build-packages.yml@self
parameters:
overwritePlaygroundPackages: ${{ parameters.overwritePlaygroundPackages }}
- template: /eng/tsp-core/pipelines/jobs/build-vs.yml@self
- template: /eng/tsp-core/pipelines/jobs/cli/build-tsp-cli-all.yml@self
- template: /eng/tsp-core/pipelines/jobs/e2e.yml@self
Expand Down
8 changes: 8 additions & 0 deletions eng/tsp-core/scripts/upload-bundler-packages.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
// @ts-check
import { parseArgs } from "node:util";
import {
bundleAndUploadPackages,
getPackageVersion,
} from "../../../packages/bundle-uploader/dist/src/index.js";
import { repoRoot } from "../../common/scripts/helpers.ts";

const { values } = parseArgs({
options: {
overwrite: { type: "boolean", default: false },
},
});

Comment on lines +9 to +14
await bundleAndUploadPackages({
repoRoot: repoRoot,
overwrite: values.overwrite,
indexName: "typespec",
indexVersion: await getPackageVersion(repoRoot, "@typespec/compiler"),
packages: [
Expand Down
27 changes: 27 additions & 0 deletions packages/bundle-uploader/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Playground bundle uploader

Internal tooling for publishing TypeSpec package bundles to Playground storage.
By default, uploads skip package versions and assets that already exist.

To replace an incorrectly published package version without deleting its blobs manually,
run the core upload command with `--overwrite`:

```sh
node eng/tsp-core/scripts/upload-bundler-packages.ts --overwrite
```

The publish pipeline exposes the same opt-in behavior through the
**Overwrite existing Playground package versions** parameter, which defaults to `false`.

Standalone packages can also be replaced with:

```sh
node eng/emitters/scripts/upload-bundled-emitter.ts path/to/package --overwrite
```

Overwrite mode replaces the manifest, JavaScript files, static assets, and bundled peer
dependencies for the uploaded versions. Both `bundleAndUploadPackages` and
`bundleAndUploadStandalonePackage` accept an optional `overwrite: true` setting.

The shared index also removes obsolete export mappings for successfully overwritten
packages, while preserving mappings for other packages.
19 changes: 17 additions & 2 deletions packages/bundle-uploader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export interface BundleAndUploadStandalonePackageOptions {
* Absolute path to the package directory.
*/
packagePath: string;

/** Replace existing bundles and assets for the same package version. Defaults to false. */
overwrite?: boolean;
}

/**
Expand All @@ -48,6 +51,7 @@ export interface BundleAndUploadStandalonePackageOptions {
*/
export async function bundleAndUploadStandalonePackage({
packagePath,
overwrite = false,
}: BundleAndUploadStandalonePackageOptions) {
const pkgJsonPath = resolve(packagePath, "package.json");
const pkgJson = JSON.parse(await readFile(pkgJsonPath, "utf-8"));
Expand All @@ -57,7 +61,7 @@ export async function bundleAndUploadStandalonePackage({
const manifest = bundle.manifest;
logInfo(`Bundling standalone package: ${manifest.name}@${manifest.version}`);

const uploader = new TypeSpecBundledPackageUploader(new AzureCliCredential());
const uploader = new TypeSpecBundledPackageUploader(new AzureCliCredential(), { overwrite });
await uploader.createIfNotExists();

const result = await uploader.upload(bundle);
Expand Down Expand Up @@ -153,6 +157,9 @@ async function uploadPlaygroundAssets(

export interface BundleAndUploadPackagesOptions {
repoRoot: string;

/** Replace existing bundles for the same package version. Defaults to false. */
overwrite?: boolean;
/**
* List of packages to bundle and upload.
*/
Expand Down Expand Up @@ -193,12 +200,13 @@ export async function bundleAndUploadPackages({
packages,
indexName,
indexVersion,
overwrite = false,
}: BundleAndUploadPackagesOptions) {
const allProjects = await findWorkspacePackages(repoRoot);
const projects = allProjects.filter((x) => packages.includes(x.manifest.name!));
logInfo("Current index version:", indexVersion);

const uploader = new TypeSpecBundledPackageUploader(new AzureCliCredential());
const uploader = new TypeSpecBundledPackageUploader(new AzureCliCredential(), { overwrite });
Comment thread
timotheeguerin marked this conversation as resolved.
Resolved
await uploader.createIfNotExists();

const existingIndex = await uploader.getIndex(indexName, indexVersion);
Expand All @@ -208,6 +216,13 @@ export async function bundleAndUploadPackages({
const manifest = bundle.manifest;
const result = await uploader.upload(bundle);
if (result.status === "uploaded") {
if (overwrite) {
for (const key of Object.keys(importMap)) {
if (key === manifest.name || key.startsWith(`${manifest.name}/`)) {
delete importMap[key];
}
}
}
Comment on lines +219 to +225
logSuccess(`Bundle for package ${manifest.name}@${manifest.version} uploaded.`);
} else {
logInfo(`Bundle for package ${manifest.name} already exist for version ${manifest.version}.`);
Expand Down
23 changes: 11 additions & 12 deletions packages/bundle-uploader/src/upload-browser-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ export interface PackageIndex {

export class TypeSpecBundledPackageUploader {
#container: ContainerClient;
#overwrite: boolean;

constructor(credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential) {
constructor(
credential?: StorageSharedKeyCredential | AnonymousCredential | TokenCredential,
options: { overwrite?: boolean } = {},
) {
this.#container = getCoverageContainer(storageAccountName, credential);
this.#overwrite = options.overwrite ?? false;
}

async createIfNotExists() {
Expand Down Expand Up @@ -88,13 +93,11 @@ export class TypeSpecBundledPackageUploader {
blobHTTPHeaders: {
blobContentType: contentType,
},
conditions: {
ifNoneMatch: "*",
},
conditions: this.#overwrite ? undefined : { ifNoneMatch: "*" },
});
return { status: "uploaded", url };
} catch (e: any) {
if (e.code === "BlobAlreadyExists") {
if (!this.#overwrite && e.code === "BlobAlreadyExists") {
return { status: "already-exists", url };
}
throw e;
Expand Down Expand Up @@ -159,12 +162,10 @@ export class TypeSpecBundledPackageUploader {
blobHTTPHeaders: {
blobContentType: "application/json; charset=utf-8",
},
conditions: {
ifNoneMatch: "*",
},
conditions: this.#overwrite ? undefined : { ifNoneMatch: "*" },
});
} catch (e: any) {
if (e.code === "BlobAlreadyExists") {
if (!this.#overwrite && e.code === "BlobAlreadyExists") {
return false;
}
throw e;
Expand All @@ -180,9 +181,7 @@ export class TypeSpecBundledPackageUploader {
blobHTTPHeaders: {
blobContentType: "application/javascript; charset=utf-8",
},
conditions: {
ifNoneMatch: "*",
},
conditions: this.#overwrite ? undefined : { ifNoneMatch: "*" },
});
}
}
Expand Down
Loading