snyk-nuget-plugin 4.4.0 → 4.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -34,11 +34,51 @@ var __importStar = (this && this.__importStar) || (function () {
|
|
|
34
34
|
})();
|
|
35
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
36
|
exports.generate = generate;
|
|
37
|
+
const path = __importStar(require("path"));
|
|
38
|
+
const fs = __importStar(require("fs"));
|
|
37
39
|
const generator = __importStar(require("./generator"));
|
|
38
40
|
function targetFrameworkFromSdkVersion(sdkVersion) {
|
|
39
41
|
const major = parseInt(sdkVersion.split('.')[0], 10);
|
|
40
42
|
return `net${major}.0`;
|
|
41
43
|
}
|
|
44
|
+
// Escape a filesystem path so it can be safely embedded in a double-quoted XML
|
|
45
|
+
// attribute value (Windows user paths can legitimately contain '&', etc.).
|
|
46
|
+
function xmlAttributeEscape(value) {
|
|
47
|
+
return value
|
|
48
|
+
.replace(/&/g, '&')
|
|
49
|
+
.replace(/</g, '<')
|
|
50
|
+
.replace(/>/g, '>')
|
|
51
|
+
.replace(/"/g, '"');
|
|
52
|
+
}
|
|
53
|
+
// The bundled `nupkgs` folder normally lives on disk next to this module. But when this
|
|
54
|
+
// plugin runs inside the Snyk CLI's packaged binary, `pkg` mounts everything under `dist`
|
|
55
|
+
// into a virtual snapshot filesystem, so `path.join(__dirname, 'nupkgs')` resolves to a
|
|
56
|
+
// snapshot-only path (e.g. `/snapshot/...`) that only the packaged Node process itself can
|
|
57
|
+
// read. `dotnet restore` runs as a separate OS process and can't see into that snapshot at
|
|
58
|
+
// all, so instead of pointing nuget.config there directly, we copy the offline packages
|
|
59
|
+
// into the same real, on-disk directory generator.generate() already created below for
|
|
60
|
+
// Parse.csproj/Program.cs, and point nuget.config at that.
|
|
61
|
+
function writeOfflinePackagesInto(tempDir) {
|
|
62
|
+
const nugetConfigPath = path.join(tempDir, 'nuget.config');
|
|
63
|
+
if (fs.existsSync(nugetConfigPath)) {
|
|
64
|
+
// Already populated by a previous call that hit generator.generate()'s content cache
|
|
65
|
+
// and got back this same tempDir.
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
const bundledNupkgsDir = path.join(__dirname, 'nupkgs');
|
|
69
|
+
fs.mkdirSync(path.join(tempDir, 'nupkgs'));
|
|
70
|
+
for (const fileName of fs.readdirSync(bundledNupkgsDir)) {
|
|
71
|
+
fs.writeFileSync(path.join(tempDir, 'nupkgs', fileName), fs.readFileSync(path.join(bundledNupkgsDir, fileName)));
|
|
72
|
+
}
|
|
73
|
+
fs.writeFileSync(nugetConfigPath, `<?xml version="1.0" encoding="utf-8"?>
|
|
74
|
+
<configuration>
|
|
75
|
+
<packageSources>
|
|
76
|
+
<clear />
|
|
77
|
+
<add key="snyk-nuget-plugin-offline" value="${xmlAttributeEscape(tempDir)}/nupkgs" />
|
|
78
|
+
</packageSources>
|
|
79
|
+
</configuration>
|
|
80
|
+
`);
|
|
81
|
+
}
|
|
42
82
|
function generate(sdkVersion) {
|
|
43
83
|
const targetFramework = targetFrameworkFromSdkVersion(sdkVersion);
|
|
44
84
|
const files = [
|
|
@@ -56,8 +96,7 @@ function generate(sdkVersion) {
|
|
|
56
96
|
</PropertyGroup>
|
|
57
97
|
|
|
58
98
|
<ItemGroup>
|
|
59
|
-
<PackageReference Include='
|
|
60
|
-
<PackageReference Include='NuGet.Frameworks' Version='6.7.0' />
|
|
99
|
+
<PackageReference Include='NuGet.Frameworks' Version='6.14.3' />
|
|
61
100
|
</ItemGroup>
|
|
62
101
|
</Project>
|
|
63
102
|
`,
|
|
@@ -66,8 +105,8 @@ function generate(sdkVersion) {
|
|
|
66
105
|
name: 'Program.cs',
|
|
67
106
|
contents: `
|
|
68
107
|
using System;
|
|
108
|
+
using System.Text.Json;
|
|
69
109
|
using NuGet.Frameworks;
|
|
70
|
-
using Newtonsoft.Json;
|
|
71
110
|
|
|
72
111
|
class Program
|
|
73
112
|
{
|
|
@@ -84,12 +123,12 @@ class Program
|
|
|
84
123
|
try
|
|
85
124
|
{
|
|
86
125
|
NuGetFramework framework = NuGetFramework.Parse(shortName);
|
|
87
|
-
string json =
|
|
126
|
+
string json = JsonSerializer.Serialize(new
|
|
88
127
|
{
|
|
89
128
|
framework.Framework,
|
|
90
|
-
framework.Version,
|
|
129
|
+
Version = framework.Version.ToString(),
|
|
91
130
|
framework.Platform,
|
|
92
|
-
framework.PlatformVersion,
|
|
131
|
+
PlatformVersion = framework.PlatformVersion?.ToString(),
|
|
93
132
|
framework.HasPlatform,
|
|
94
133
|
framework.HasProfile,
|
|
95
134
|
framework.Profile,
|
|
@@ -103,7 +142,7 @@ class Program
|
|
|
103
142
|
framework.IsAny,
|
|
104
143
|
framework.IsSpecificFramework,
|
|
105
144
|
ShortName = shortName
|
|
106
|
-
}
|
|
145
|
+
});
|
|
107
146
|
Console.Write(json);
|
|
108
147
|
}
|
|
109
148
|
catch (Exception ex)
|
|
@@ -116,6 +155,7 @@ class Program
|
|
|
116
155
|
},
|
|
117
156
|
];
|
|
118
157
|
const tempDir = generator.generate('csharp', files);
|
|
158
|
+
writeOfflinePackagesInto(tempDir);
|
|
119
159
|
return tempDir;
|
|
120
160
|
}
|
|
121
161
|
//# sourceMappingURL=nugetframeworks_parser.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nugetframeworks_parser.js","sourceRoot":"","sources":["../../../lib/nuget-parser/csharp/nugetframeworks_parser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"nugetframeworks_parser.js","sourceRoot":"","sources":["../../../lib/nuget-parser/csharp/nugetframeworks_parser.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,4BAgFC;AA1ID,2CAA6B;AAC7B,uCAAyB;AAEzB,uDAAyC;AAEzC,SAAS,6BAA6B,CAAC,UAAkB;IACvD,MAAM,KAAK,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,aAAa,CACd,eAAe,EACf;;;;kDAI8C,kBAAkB,CAAC,OAAO,CAAC;;;CAG5E,CACE,CAAC;AACJ,CAAC;AAED,SAAgB,QAAQ,CAAC,UAAkB;IACzC,MAAM,eAAe,GAAG,6BAA6B,CAAC,UAAU,CAAC,CAAC;IAElE,MAAM,KAAK,GAAuB;QAChC;YACE,IAAI,EAAE,cAAc;YACpB,QAAQ,EAAE;;;;uBAIO,eAAe;;;;;;;;;;;CAWrC;SACI;QACD;YACE,IAAI,EAAE,YAAY;YAClB,QAAQ,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgDf;SACI;KACF,CAAC;IAEF,MAAM,OAAO,GAAG,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;IACpD,wBAAwB,CAAC,OAAO,CAAC,CAAC;IAClC,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -11,7 +11,8 @@
|
|
|
11
11
|
"lint:eslint": "eslint '{lib,test}/**/*.ts'",
|
|
12
12
|
"lint:prettier": "prettier --check '{lib,test}/**/*.{ts,csproj,json}' --log-level 'warn'",
|
|
13
13
|
"lint:fix": "prettier --write '{lib,test}/**/*.{ts,csproj,json}' && eslint --fix '{lib,test}/**/*.ts'",
|
|
14
|
-
"build": "tsc",
|
|
14
|
+
"build": "tsc && npm run copy-nupkgs",
|
|
15
|
+
"copy-nupkgs": "node -e \"require('fs').cpSync('lib/nuget-parser/csharp/nupkgs','dist/nuget-parser/csharp/nupkgs',{recursive:true})\"",
|
|
15
16
|
"build:watch": "tsc -w",
|
|
16
17
|
"prepare": "npm run build"
|
|
17
18
|
},
|
|
@@ -65,5 +66,5 @@
|
|
|
65
66
|
"ts-jest": "^29.1.2",
|
|
66
67
|
"typescript": "^6.0.3"
|
|
67
68
|
},
|
|
68
|
-
"version": "4.
|
|
69
|
+
"version": "4.5.1"
|
|
69
70
|
}
|