@@ -15,7 +15,7 @@ import Manifest from './manifest.js';
1515 * The ecosystem identifier for JavaScript/npm packages
1616 * @type {string }
1717 */
18- export const ecosystem = 'npm' ;
18+ export const purlType = 'npm' ;
1919
2020/**
2121 * Base class for JavaScript package manager providers.
@@ -28,6 +28,8 @@ export default class Base_javascript {
2828 #manifest;
2929 /** @type {string } */
3030 #cmd;
31+ /** @type {string } */
32+ #ecosystem;
3133
3234 /**
3335 * Sets up the provider with the manifest path and options
@@ -38,17 +40,27 @@ export default class Base_javascript {
3840 _setUp ( manifestPath , opts ) {
3941 this . #cmd = getCustomPath ( this . _cmdName ( ) , opts ) ;
4042 this . #manifest = new Manifest ( manifestPath ) ;
43+ this . #ecosystem = purlType ;
4144 }
4245
4346 /**
44- * Gets the current manifest object
45- * @returns {Manifest } The manifest object
46- * @protected
47- */
47+ * Gets the current manifest object
48+ * @returns {Manifest } The manifest object
49+ * @protected
50+ */
4851 _getManifest ( ) {
4952 return this . #manifest;
5053 }
5154
55+ /**
56+ * Sets the ecosystem value
57+ * @param {string } ecosystem - The ecosystem identifier
58+ * @protected
59+ */
60+ _setEcosystem ( ecosystem ) {
61+ this . #ecosystem = ecosystem ;
62+ }
63+
5264 /**
5365 * Returns the name of the lock file for the specific implementation
5466 * @returns {string } The lock file name
@@ -117,7 +129,7 @@ export default class Base_javascript {
117129 provideStack ( manifestPath , opts = { } ) {
118130 this . _setUp ( manifestPath , opts ) ;
119131 return {
120- ecosystem,
132+ ecosystem : this . #ecosystem ,
121133 content : this . #getSBOM( opts ) ,
122134 contentType : 'application/vnd.cyclonedx+json'
123135 }
@@ -132,7 +144,7 @@ export default class Base_javascript {
132144 provideComponent ( manifestPath , opts = { } ) {
133145 this . _setUp ( manifestPath , opts ) ;
134146 return {
135- ecosystem,
147+ ecosystem : this . #ecosystem ,
136148 content : this . #getDirectDependencySbom( opts ) ,
137149 contentType : 'application/vnd.cyclonedx+json'
138150 }
@@ -163,7 +175,7 @@ export default class Base_javascript {
163175 #getSBOM( opts = { } ) {
164176 const depsObject = this . _buildDependencyTree ( true ) ;
165177
166- let mainComponent = toPurl ( ecosystem , this . #manifest. name , this . #manifest. version ) ;
178+ let mainComponent = toPurl ( purlType , this . #manifest. name , this . #manifest. version ) ;
167179
168180 let sbom = new Sbom ( ) ;
169181 sbom . addRoot ( mainComponent ) ;
@@ -185,8 +197,8 @@ export default class Base_javascript {
185197 Object . entries ( dependencies )
186198 . forEach ( entry => {
187199 const [ name , artifact ] = entry ;
188- const target = toPurl ( ecosystem , name , artifact . version ) ;
189- const rootPurl = toPurl ( ecosystem , this . #manifest. name , this . #manifest. version ) ;
200+ const target = toPurl ( purlType , name , artifact . version ) ;
201+ const rootPurl = toPurl ( purlType , this . #manifest. name , this . #manifest. version ) ;
190202 sbom . addDependency ( rootPurl , target ) ;
191203 this . #addDependenciesOf( sbom , target , artifact ) ;
192204 } ) ;
@@ -205,7 +217,7 @@ export default class Base_javascript {
205217 . forEach ( entry => {
206218 const [ name , depArtifact ] = entry ;
207219 if ( depArtifact . version !== undefined ) {
208- const target = toPurl ( ecosystem , name , depArtifact . version ) ;
220+ const target = toPurl ( purlType , name , depArtifact . version ) ;
209221 sbom . addDependency ( from , target ) ;
210222 this . #addDependenciesOf( sbom , target , depArtifact ) ;
211223 }
@@ -220,7 +232,7 @@ export default class Base_javascript {
220232 */
221233 #getDirectDependencySbom( opts = { } ) {
222234 const depTree = this . _buildDependencyTree ( false ) ;
223- let mainComponent = toPurl ( ecosystem , this . #manifest. name , this . #manifest. version ) ;
235+ let mainComponent = toPurl ( purlType , this . #manifest. name , this . #manifest. version ) ;
224236
225237 let sbom = new Sbom ( ) ;
226238 sbom . addRoot ( mainComponent ) ;
@@ -251,7 +263,7 @@ export default class Base_javascript {
251263
252264 return new Map (
253265 Object . entries ( depTree . dependencies ) . map (
254- ( [ key , value ] ) => [ key , toPurl ( ecosystem , key , value . version ) ]
266+ ( [ key , value ] ) => [ key , toPurl ( purlType , key , value . version ) ]
255267 )
256268 ) ;
257269 }
0 commit comments