11'use strict' ;
22
3- const CoreObject = require ( 'core-object' ) ;
43const fs = require ( 'fs-extra' ) ;
54const path = require ( 'path' ) ;
65const debug = require ( 'debug' ) ( 'ember-try:dependency-manager-adapter:pnpm' ) ;
@@ -11,21 +10,24 @@ const semverGte = require('semver/functions/gte');
1110const PACKAGE_JSON = 'package.json' ;
1211const PNPM_LOCKFILE = 'pnpm-lock.yaml' ;
1312
14- module . exports = CoreObject . extend ( {
13+ module . exports = class {
1514 // This still needs to be `npm` because we're still reading the dependencies
1615 // from the `npm` key of the ember-try config.
17- configKey : 'npm' ,
16+ configKey = 'npm' ;
17+
18+ constructor ( options ) {
19+ this . buildManagerOptions = options . buildManagerOptions ;
20+ this . cwd = options . cwd ;
21+ this . managerOptions = options . managerOptions ;
22+ this . run = options . run || require ( '../utils/run' ) ;
1823
19- init ( ) {
20- this . _super . apply ( this , arguments ) ;
2124 this . backup = new Backup ( { cwd : this . cwd } ) ;
22- this . run = this . run || require ( '../utils/run' ) ;
23- } ,
25+ }
2426
2527 async setup ( ) {
2628 await this . _throwOnResolutionMode ( ) ;
2729 await this . backup . addFiles ( [ PACKAGE_JSON , PNPM_LOCKFILE ] ) ;
28- } ,
30+ }
2931
3032 async changeToDependencySet ( depSet ) {
3133 await this . applyDependencySet ( depSet ) ;
@@ -44,7 +46,7 @@ module.exports = CoreObject.extend({
4446 debug ( 'Switched to dependencies: \n' , currentDeps ) ;
4547
4648 return currentDeps ;
47- } ,
49+ }
4850
4951 async cleanup ( ) {
5052 try {
@@ -54,7 +56,7 @@ module.exports = CoreObject.extend({
5456 } catch ( e ) {
5557 console . log ( 'Error cleaning up scenario:' , e ) ; // eslint-disable-line no-console
5658 }
57- } ,
59+ }
5860
5961 _findCurrentVersionOf ( packageName ) {
6062 let filename = path . join ( this . cwd , 'node_modules' , packageName , PACKAGE_JSON ) ;
@@ -63,7 +65,7 @@ module.exports = CoreObject.extend({
6365 } else {
6466 return null ;
6567 }
66- } ,
68+ }
6769
6870 /**
6971 * pnpm versions 8.0.0 through 8.6.* have the `resolution-mode` setting inverted to
@@ -82,12 +84,12 @@ module.exports = CoreObject.extend({
8284 'You are using an old version of pnpm that uses wrong resolution mode that violates ember-try expectations. Please either upgrade pnpm or set `resolution-mode` to `highest` in `.npmrc`.' ,
8385 ) ;
8486 }
85- } ,
87+ }
8688
8789 async _getPnpmVersion ( ) {
8890 let result = await this . run ( 'pnpm' , [ '--version' ] , { cwd : this . cwd , stdio : 'pipe' } ) ;
8991 return result . stdout . split ( '\n' ) [ 0 ] ;
90- } ,
92+ }
9193
9294 async _getResolutionMode ( ) {
9395 let result = await this . run ( 'pnpm' , [ 'config' , 'get' , 'resolution-mode' ] , {
@@ -96,7 +98,7 @@ module.exports = CoreObject.extend({
9698 } ) ;
9799
98100 return result . stdout . split ( '\n' ) [ 0 ] ;
99- } ,
101+ }
100102
101103 _isResolutionModeWrong ( versionStr , resolutionMode ) {
102104 // The `resolution-mode` is not set explicitly, and the current pnpm version makes it default
@@ -106,7 +108,7 @@ module.exports = CoreObject.extend({
106108 }
107109
108110 return false ;
109- } ,
111+ }
110112
111113 async _install ( depSet ) {
112114 let mgrOptions = this . managerOptions || [ ] ;
@@ -134,7 +136,7 @@ module.exports = CoreObject.extend({
134136 debug ( 'Run pnpm install with options %s' , mgrOptions ) ;
135137
136138 await this . run ( 'pnpm' , [ ] . concat ( [ 'install' ] , mgrOptions ) , { cwd : this . cwd } ) ;
137- } ,
139+ }
138140
139141 async applyDependencySet ( depSet ) {
140142 debug ( 'Changing to dependency set: %s' , JSON . stringify ( depSet ) ) ;
@@ -155,7 +157,7 @@ module.exports = CoreObject.extend({
155157 // diff compared to the original locked dependency set.
156158
157159 await this . backup . restoreFile ( PNPM_LOCKFILE ) ;
158- } ,
160+ }
159161
160162 _packageJSONForDependencySet ( packageJSON , depSet ) {
161163 this . _overridePackageJSONDependencies ( packageJSON , depSet , 'dependencies' ) ;
@@ -167,7 +169,7 @@ module.exports = CoreObject.extend({
167169 this . _overridePackageJSONDependencies ( packageJSON , depSet , 'overrides' ) ;
168170
169171 return packageJSON ;
170- } ,
172+ }
171173
172174 _overridePackageJSONDependencies ( packageJSON , depSet , kindOfDependency ) {
173175 if ( ! depSet [ kindOfDependency ] ) {
@@ -188,5 +190,5 @@ module.exports = CoreObject.extend({
188190 packageJSON [ kindOfDependency ] [ packageName ] = version ;
189191 }
190192 }
191- } ,
192- } ) ;
193+ }
194+ } ;
0 commit comments