diff --git a/Herebyfile.mjs b/Herebyfile.mjs index 9c85e30d62edf..27a962cda89f4 100644 --- a/Herebyfile.mjs +++ b/Herebyfile.mjs @@ -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"))); @@ -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)) { diff --git a/tools/pipelines/steps/setup-node-npm-ci.yml b/tools/pipelines/steps/setup-node-npm-ci.yml index e8eb80074e7d1..94e37bdce4b78 100755 --- a/tools/pipelines/steps/setup-node-npm-ci.yml +++ b/tools/pipelines/steps/setup-node-npm-ci.yml @@ -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 diff --git a/tools/pipelines/steps/setup-vsce.yml b/tools/pipelines/steps/setup-vsce.yml index f147e018ac250..1160e6cf2f85c 100644 --- a/tools/pipelines/steps/setup-vsce.yml +++ b/tools/pipelines/steps/setup-vsce.yml @@ -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'