diff --git a/tasks/offlinePackagingTasks.ts b/tasks/offlinePackagingTasks.ts index a032168373..5945956bbd 100644 --- a/tasks/offlinePackagingTasks.ts +++ b/tasks/offlinePackagingTasks.ts @@ -23,6 +23,21 @@ import { getRuntimeDependenciesPackages } from '../src/tools/RuntimeDependencyPa import { getAbsolutePathPackagesToInstall } from '../src/packageManager/getAbsolutePathPackagesToInstall'; import { isValidDownload } from '../src/packageManager/isValidDownload'; +export const offlinePackages = [ + { platformInfo: new PlatformInformation('win32', 'x86_64'), id: "win32-x64" }, + { platformInfo: new PlatformInformation('win32', 'x86'), id: "win32-ia32" }, + { platformInfo: new PlatformInformation('win32', 'arm64'), id: "win32-arm64" }, + { platformInfo: new PlatformInformation('linux', 'x86_64'), id: "linux-x64" }, + { platformInfo: new PlatformInformation('darwin', 'x86_64'), id: "darwin-x64" }, + { platformInfo: new PlatformInformation('darwin', 'arm64'), id: "darwin-arm64" }, +]; + +export function getPackageName(packageJSON: any, vscodePlatformId: string) { + const name = packageJSON.name; + const version = packageJSON.version; + return `${name}.${version}-${vscodePlatformId}.vsix`; +} + gulp.task('vsix:offline:package', async () => { if (process.platform === 'win32') { @@ -53,27 +68,13 @@ async function doPackageOffline() { } const packageJSON = getPackageJSON(); - const name = packageJSON.name; - const version = packageJSON.version; - const packageName = name + '.' + version; - - const packages = [ - { platformInfo: new PlatformInformation('win32', 'x86_64'), id: "win32-x64" }, - { platformInfo: new PlatformInformation('win32', 'x86'), id: "win32-ia32" }, - { platformInfo: new PlatformInformation('win32', 'arm64'), id: "win32-arm64" }, - { platformInfo: new PlatformInformation('linux', 'x86_64'), id: "linux-x64" }, - { platformInfo: new PlatformInformation('darwin', 'x86_64'), id: "darwin-x64" }, - { platformInfo: new PlatformInformation('darwin', 'arm64'), id: "darwin-arm64" }, - ]; - - for (let p of packages) { - try - { - await doOfflinePackage(p.platformInfo, p.id, packageName, packageJSON, packedVsixOutputRoot); + + for (let p of offlinePackages) { + try { + await doOfflinePackage(p.platformInfo, p.id, packageJSON, packedVsixOutputRoot); } - catch (err) - { - // NOTE: Extra `\n---` at the end is because gulp will print this message following by the + catch (err) { + // NOTE: Extra `\n---` at the end is because gulp will print this message following by the // stack trace of this line. So that seperates the two stack traces. throw Error(`Failed to create package ${p.id}. ${err.stack ?? err ?? ''}\n---`); } @@ -81,16 +82,16 @@ async function doPackageOffline() { } async function cleanAsync(deleteVsix: boolean) { - await del([ 'install.*', '.omnisharp*', '.debugger', '.razor']); + await del(['install.*', '.omnisharp*', '.debugger', '.razor']); if (deleteVsix) { await del('*.vsix'); } } -async function doOfflinePackage(platformInfo: PlatformInformation, vscodePlatformId: string, packageName: string, packageJSON: any, outputFolder: string) { +async function doOfflinePackage(platformInfo: PlatformInformation, vscodePlatformId: string, packageJSON: any, outputFolder: string) { await cleanAsync(false); - const packageFileName = `${packageName}-${vscodePlatformId}.vsix`; + const packageFileName = getPackageName(packageJSON, vscodePlatformId); await install(platformInfo, packageJSON); await createPackageAsync(packageFileName, outputFolder, vscodePlatformId); } @@ -104,14 +105,13 @@ async function install(platformInfo: PlatformInformation, packageJSON: any) { let runTimeDependencies = getRuntimeDependenciesPackages(packageJSON); let packagesToInstall = await getAbsolutePathPackagesToInstall(runTimeDependencies, platformInfo, codeExtensionPath); let provider = () => new NetworkSettings(undefined, undefined); - if (!(await downloadAndInstallPackages(packagesToInstall, provider, eventStream, isValidDownload))) - { + if (!(await downloadAndInstallPackages(packagesToInstall, provider, eventStream, isValidDownload))) { throw Error("Failed to download package."); } // The VSIX Format doesn't allow files that differ only by case. The Linux OmniSharp package had a lowercase version of these files ('.targets') targets from mono, // and an upper case ('.Targets') from Microsoft.Build.Runtime. Remove the lowercase versions. - await del([ '.omnisharp/*/omnisharp/.msbuild/Current/Bin/Workflow.targets', '.omnisharp/*/omnisharp/.msbuild/Current/Bin/Workflow.VisualBasic.targets' ]); + await del(['.omnisharp/*/omnisharp/.msbuild/Current/Bin/Workflow.targets', '.omnisharp/*/omnisharp/.msbuild/Current/Bin/Workflow.VisualBasic.targets']); } /// Packaging (VSIX) Tasks diff --git a/test/releaseTests/offlinePackage.test.ts b/test/releaseTests/offlinePackage.test.ts index 49d9ba073b..028ccf84a8 100644 --- a/test/releaseTests/offlinePackage.test.ts +++ b/test/releaseTests/offlinePackage.test.ts @@ -7,14 +7,18 @@ import * as chai from 'chai'; import * as glob from 'glob-promise'; import * as path from 'path'; import { invokeNode } from './testAssets/testAssets'; -import { PlatformInformation } from '../../src/platform'; import { TmpAsset, CreateTmpDir } from '../../src/CreateTmpAsset'; +import { getPackageName, offlinePackages } from '../../tasks/offlinePackagingTasks'; +import { getPackageJSON } from '../../tasks/packageJson'; +import { expect } from 'chai'; suite("Offline packaging of VSIX", function () { let vsixFiles: string[]; this.timeout(1000000); let tmpDir: TmpAsset; + const packageJson = getPackageJSON(); + suiteSetup(async () => { chai.should(); tmpDir = await CreateTmpDir(true); @@ -28,18 +32,19 @@ suite("Offline packaging of VSIX", function () { vsixFiles = glob.sync(path.join(tmpDir.name, '*.vsix')); }); - test("Exactly 3 vsix files should be produced", () => { - vsixFiles.length.should.be.equal(3, "the build should produce exactly 3 vsix files"); + test(`Exactly ${offlinePackages.length} vsix files should be produced`, () => { + vsixFiles.length.should.be.equal(offlinePackages.length, `the build should produce exactly ${offlinePackages.length} vsix files`); }); - [ - new PlatformInformation('win32', 'x86_64'), - new PlatformInformation('darwin', 'x86_64'), - new PlatformInformation('linux', 'x86_64') - ].forEach(element => { - test(`Given Platform: ${element.platform} and Architecture: ${element.architecture}, the vsix file is created`, () => { - vsixFiles.findIndex(elem => elem.indexOf(element.platform) != -1).should.not.be.equal(-1); - vsixFiles.findIndex(elem => elem.indexOf(element.architecture) != -1).should.not.be.equal(-1); + offlinePackages.forEach(packageInfo => { + const platformInfo = packageInfo.platformInfo; + const packageId = packageInfo.id; + + test(`Given Platform: ${platformInfo.platform} and Architecture: ${platformInfo.architecture}, the vsix file is created`, () => { + const expectedVsixName = getPackageName(packageJson, packageId); + const vsixFile = vsixFiles.find(file => file.endsWith(expectedVsixName)) + expect(vsixFile, `offline packaging did not build package ${expectedVsixName}`) + .to.not.be.null; }); }); diff --git a/tsconfig.json b/tsconfig.json index 4029049269..e7603b6472 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,7 +4,7 @@ "module": "commonjs", "outDir": "out", "lib": [ - "es6" + "ES2017" ], "sourceMap": true, "moduleResolution": "node",