Skip to content
Merged
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
42 changes: 12 additions & 30 deletions Herebyfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1942,10 +1942,6 @@ const builtPublishedPlatformPackages = path.resolve("./built/published-platform-
const builtSignTmp = path.resolve("./built/sign-tmp");
const publishedTypeScriptAliasPackageName = "@typescript/bundled-typescript";
const releasePackageEnv = { COREPACK_ENABLE_STRICT: "0" };
const getReleasePackageRegistry = memoize(async () => {
const { stdout } = await runOutput("npm", ["config", "get", "registry"], { env: releasePackageEnv });
return stdout.trim();
});

const getVscodeTypeScriptExtensionPackageJson = memoize(() => JSON.parse(fs.readFileSync(path.join(extensionDir, "package.json"), "utf8")));

Expand Down Expand Up @@ -3230,38 +3226,24 @@ async function getPublishedPlatformPackageDirWorker(npmPackageName) {
if (lockEntry.version !== version) {
throw new Error(`package-lock.json has ${npmPackageName}@${lockEntry.version}, but ${publishedTypeScriptAliasPackageName} depends on ${version}.`);
}
if (!lockEntry.resolved || typeof lockEntry.resolved !== "string") {
throw new Error(`package-lock.json entry for ${npmPackageName}@${version} does not contain a tarball URL.`);
}
if (!lockEntry.integrity || typeof lockEntry.integrity !== "string") {
throw new Error(`package-lock.json entry for ${npmPackageName}@${version} does not contain an integrity hash.`);
}

const resolved = new URL(lockEntry.resolved);
if (resolved.origin === "https://registry.npmjs.org") {
const registry = new URL(await getReleasePackageRegistry());
resolved.protocol = registry.protocol;
resolved.host = registry.host;
resolved.pathname = path.posix.join(registry.pathname, resolved.pathname);
}

console.log(`Fetching locked ${npmPackageName}@${version} tarball from ${resolved}.`);
const response = await fetch(resolved);
if (!response.ok) {
throw new Error(`Failed to fetch ${npmPackageName}@${version}: ${response.status} ${response.statusText}.`);
}
const tarball = Buffer.from(await response.arrayBuffer());
const integrityMatch = /^sha512-(.+)$/.exec(lockEntry.integrity);
if (!integrityMatch) {
throw new Error(`Unsupported integrity hash for ${npmPackageName}@${version}: ${lockEntry.integrity}.`);
}
const expectedIntegrity = Buffer.from(integrityMatch[1], "base64");
const actualIntegrity = crypto.createHash("sha512").update(tarball).digest();
if (expectedIntegrity.length !== actualIntegrity.length || !crypto.timingSafeEqual(expectedIntegrity, actualIntegrity)) {
const { stdout } = await runOutput("npm", [
"pack",
`${npmPackageName}@${version}`,
"--ignore-scripts",
"--json",
"--pack-destination",
tarballDestination,
], { env: releasePackageEnv });
/** @type {{ filename: string; integrity: string }[]} */
const [packed] = JSON.parse(stdout);
if (packed.integrity !== lockEntry.integrity) {
throw new Error(`Integrity check failed for ${npmPackageName}@${version}.`);
}
const tarballPath = path.join(tarballDestination, path.basename(resolved.pathname));
await fs.promises.writeFile(tarballPath, tarball);
const tarballPath = path.join(tarballDestination, packed.filename);
await tar.x({ file: tarballPath, cwd: dest, strip: 1 });

if (!fs.existsSync(lib)) {
Expand Down
7 changes: 6 additions & 1 deletion tools/pipelines/steps/setup-node-npm-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ steps:

- bash: |
cat > .npmrc << 'EOF'
registry=https://packagefeedproxy.microsoft.io/npm/
registry=https://pkgs.dev.azure.com/devdiv/devdiv/_packaging/devdiv_PublicPackages/npm/registry/
EOF
displayName: 'Set up .npmrc'

- task: npmAuthenticate@0
inputs:
workingFile: .npmrc
displayName: 'Authenticate npm'

- pwsh: |
$ErrorActionPreference = 'Stop'
$PSNativeCommandUseErrorActionPreference = $true
Expand Down
8 changes: 7 additions & 1 deletion tools/pipelines/steps/setup-vsce.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@ steps:

- bash: |
cat > .npmrc << 'EOF'
registry=https://packagefeedproxy.microsoft.io/npm/
registry=https://pkgs.dev.azure.com/devdiv/devdiv/_packaging/devdiv_PublicPackages/npm/registry/
EOF
npm init -y
condition: ${{ parameters.condition }}
displayName: 'Set up npm'

- task: npmAuthenticate@0
condition: ${{ parameters.condition }}
inputs:
workingFile: .npmrc
displayName: 'Authenticate npm'

- bash: npm install --no-save @vscode/vsce@4.1.0
condition: ${{ parameters.condition }}
displayName: 'Install vsce'
Loading