Skip to content

Replace form-data with native built in #1240

Description

@jimmywarting

Use native built in FormData instead of using any other dependency and use built in fetch to send it instead.

import FormData from 'form-data';

vscode-vsce/src/publish.ts

Lines 280 to 297 in 2aeafb2

const form = new FormData();
const lineBreak = '\r\n';
form.setBoundary('0f411892-ef48-488f-89d3-4f0546e84723');
form.append('vsix', packageStream, {
header: `--${form.getBoundary()}${lineBreak}Content-Disposition: attachment; name=vsix; filename=\"${packageName}\"${lineBreak}Content-Type: application/octet-stream${lineBreak}${lineBreak}`
});
form.append('sigzip', sigzipStream, {
header: `--${form.getBoundary()}${lineBreak}Content-Disposition: attachment; name=sigzip; filename=\"${sigzipName}\"${lineBreak}Content-Type: application/octet-stream${lineBreak}${lineBreak}`
});
const publishWithRetry = retry(handleWhen(err => err.message.includes('timeout')), {
maxAttempts: 3,
backoff: new IterableBackoff([5_000, 10_000, 20_000])
});
return await publishWithRetry.execute(async () => {
return await api.publishExtensionWithPublisherSignature(undefined, form, manifest.publisher, manifest.name, extensionType);
});

"form-data": "^4.0.0",

the only way to get a blob in nodejs and append it to a formdata is if you use fs.openAsBlob

import { openAsBlob } from 'node:fs';

const blob = await openAsBlob(path, { type: 'application/octet-stream' })
formData.append('vsix', blob, packageName)

fetch(...)

ever since ljharb took over form-data pkg, it only got more sub dependencies and increased size

the other alternative is to construct a own Blob/File yourself

Metadata

Metadata

Assignees

Labels

help wantedIssues identified as good community contribution opportunities

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions