From 59f010d7b485737866b5479d9b4729cf85ccad05 Mon Sep 17 00:00:00 2001 From: Daniel Kontorovskyi Date: Mon, 26 Aug 2019 14:15:56 +0300 Subject: [PATCH] fix: support net4 as a target framework --- lib/nuget-parser/framework.ts | 11 ++++++++- test/parse-dotnet-cli.test.ts | 11 +++++++++ test/repositories-config-packages.test.ts | 1 - .../packages-config-net4/packages.config | 24 +++++++++++++++++++ 4 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 test/stubs/packages-config-net4/packages.config diff --git a/lib/nuget-parser/framework.ts b/lib/nuget-parser/framework.ts index 5cdb9b50..5a260280 100644 --- a/lib/nuget-parser/framework.ts +++ b/lib/nuget-parser/framework.ts @@ -8,6 +8,16 @@ export function toReadableFramework(targetFramework: string): TargetFramework | v: '.NETFramework', }; + // HACK: this is an edge case and it's supported by NuGet design + // https://github.com/NuGet/Home/issues/1371 + if (targetFramework === 'net4') { + return { + framework: typeMapping.net, + original: targetFramework, + version: '4', + }; + } + for (const type in typeMapping) { if (new RegExp(type + /\d.?\d(.?\d)?$/.source).test(targetFramework)) { return { @@ -20,4 +30,3 @@ export function toReadableFramework(targetFramework: string): TargetFramework | return undefined; } - \ No newline at end of file diff --git a/test/parse-dotnet-cli.test.ts b/test/parse-dotnet-cli.test.ts index 0e428193..b2c47854 100644 --- a/test/parse-dotnet-cli.test.ts +++ b/test/parse-dotnet-cli.test.ts @@ -6,6 +6,8 @@ const manifestFile = 'obj/project.assets.json'; const packagesConfigOnlyPath = './test/stubs/packages-config-only/'; const packagesConfigOnlyManifestFile = 'packages.config'; +const packageConfigWithNet4TFPath = './test/stubs/packages-config-net4/'; +const packageConfigWithNet4TFManifestFile = 'packages.config'; test('parse dotnet-cli project without frameworks field', async (t) => { try { @@ -24,3 +26,12 @@ test('parse dotnet-cli project with packages.config only', async (t) => { t.ok(res.package.dependencies.jQuery, 'jQuery should be found because specified'); t.ok(res.package.dependencies['Moment.js'], 'Moment.js should be found because specified'); }); + +test('parse dotnet-cli project with packages.config containing net4 as target framework', async (t) => { + const res = await plugin.inspect(packageConfigWithNet4TFPath, packageConfigWithNet4TFManifestFile); + t.equal(res.package.name, 'packages-config-net4', 'expected packages-config-net4 name'); + // expect the first found targetRuntime to be returned by the plugin + t.equal(res.plugin.targetRuntime, 'net4', 'expected net4 framework'); + t.ok(res.package.dependencies.jQuery, 'jQuery should be found because specified'); + t.ok(res.package.dependencies.Unity, 'Unity should be found because specified'); +}); diff --git a/test/repositories-config-packages.test.ts b/test/repositories-config-packages.test.ts index 7f4a6b2d..99fe8411 100644 --- a/test/repositories-config-packages.test.ts +++ b/test/repositories-config-packages.test.ts @@ -11,6 +11,5 @@ const expectedTree = JSON.parse(fs.readFileSync(path.resolve(projectPath, 'expec test('packages contains many deps: only jquery', async (t) => { const result = await plugin.inspect(projectPath, manifestFile, {packagesFolder}); - console.log(expectedTree); t.deepEqual(result, expectedTree, 'expects project data to be correct'); }); diff --git a/test/stubs/packages-config-net4/packages.config b/test/stubs/packages-config-net4/packages.config new file mode 100644 index 00000000..27e0a088 --- /dev/null +++ b/test/stubs/packages-config-net4/packages.config @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + + + + + + + +