@@ -18,6 +18,7 @@ import { AuthInfo, Connection, fs, NamedPackageDir, SfdxProject } from '@salesfo
1818import { AsyncCreatable } from '@salesforce/kit' ;
1919import { debug , Debugger } from 'debug' ;
2020import { MetadataResolver } from '@salesforce/source-deploy-retrieve' ;
21+ import * as shelljs from 'shelljs' ;
2122import { Result , StatusResult } from './types' ;
2223import { Assertions } from './assertions' ;
2324import { ExecutionLog } from './executionLog' ;
@@ -215,7 +216,7 @@ export class Nutshell extends AsyncCreatable<Nutshell.Options> {
215216 */
216217 public async readMaxRevision ( ) : Promise < { sourceMembers : JsonMap } > {
217218 const maxRevisionPath = path . join ( this . session . project . dir , '.sfdx' , 'orgs' , this . username , 'maxRevision.json' ) ;
218- return ( fs . readJson ( maxRevisionPath ) as unknown ) as { sourceMembers : JsonMap } ;
219+ return fs . readJson ( maxRevisionPath ) as unknown as { sourceMembers : JsonMap } ;
219220 }
220221
221222 /**
@@ -297,7 +298,7 @@ export class Nutshell extends AsyncCreatable<Nutshell.Options> {
297298 const allFiles = await this . doGlob ( globs ) ;
298299
299300 for ( const file of allFiles ) {
300- await this . modifyLocalFile ( file ) ;
301+ await this . modifyLocalFile ( path . normalize ( file ) ) ;
301302 }
302303 }
303304
@@ -370,9 +371,31 @@ export class Nutshell extends AsyncCreatable<Nutshell.Options> {
370371 await this . writeMaxRevision ( maxRevision ) ;
371372 }
372373
374+ public isSourcePlugin ( ) : boolean {
375+ return this . executable . endsWith ( `${ path . sep } bin${ path . sep } run` ) ;
376+ }
377+
378+ // SDR does not output the package.xml in the same location as toolbelt
379+ // so we have to find it within the output dir, move it, and delete the
380+ // generated dir.
381+ public findAndMoveManifest ( dir : string ) : void {
382+ const manifest = shelljs . find ( dir ) . filter ( ( file ) => file . endsWith ( 'package.xml' ) ) ;
383+ if ( ! manifest ?. length ) {
384+ throw Error ( `Did not find package.xml within ${ dir } ` ) ;
385+ }
386+ shelljs . mv ( manifest [ 0 ] , path . join ( process . cwd ( ) ) ) ;
387+ shelljs . rm ( '-rf' , dir ) ;
388+ }
389+
373390 protected async init ( ) : Promise < void > {
374391 if ( ! Nutshell . Env . getString ( 'TESTKIT_HUB_USERNAME' ) && ! Nutshell . Env . getString ( 'TESTKIT_AUTH_URL' ) ) {
375- ensureString ( Nutshell . Env . getString ( 'TESTKIT_JWT_KEY' ) ) ;
392+ const jwtKey = ensureString ( Nutshell . Env . getString ( 'TESTKIT_JWT_KEY' ) ) ;
393+ if ( ! jwtKey ) {
394+ const err = Error ( 'must set on of : TESTKIT_HUB_USERNAME, TESTKIT_AUTH_RUL, or TESTKIT_JWT_KEY' ) ;
395+ err . name = 'InvalidTestEnvironment' ;
396+ throw err ;
397+ }
398+ ensureString ( jwtKey ) ;
376399 ensureString ( Nutshell . Env . getString ( 'TESTKIT_JWT_CLIENT_ID' ) ) ;
377400 ensureString ( Nutshell . Env . getString ( 'TESTKIT_HUB_INSTANCE' ) ) ;
378401 }
@@ -456,7 +479,7 @@ export class Nutshell extends AsyncCreatable<Nutshell.Options> {
456479 ? [ ]
457480 : [
458481 'sfdx config:set restDeploy=false --global' ,
459- ' sfdx force:org:create -d 1 -s -f config/ project-scratch-def.json',
482+ ` sfdx force:org:create -d 1 -s -f ${ path . join ( ' config' , ' project-scratch-def.json') } ` ,
460483 ] ;
461484 return await TestSession . create ( {
462485 project : { gitClone : this . repository } ,
@@ -479,9 +502,16 @@ export class Nutshell extends AsyncCreatable<Nutshell.Options> {
479502 }
480503
481504 private async doGlob ( globs : string [ ] ) : Promise < string [ ] > {
482- const fullGlobs = globs . map ( ( g ) =>
483- g . startsWith ( this . session . project . dir ) ? g : [ this . session . project . dir , g ] . join ( '/' )
484- ) ;
505+ const dir = this . session . project . dir . replace ( / \\ / g, '/' ) ;
506+ const fullGlobs = globs . map ( ( g ) => {
507+ g = g . replace ( / \\ / g, '/' ) ;
508+ if ( g . startsWith ( '!' ) ) {
509+ g = g . substr ( 1 ) . startsWith ( dir ) ? `!${ g } ` : [ `!${ dir } ` , g ] . join ( '/' ) ;
510+ } else {
511+ g = g . startsWith ( dir ) ? g : [ dir , g ] . join ( '/' ) ;
512+ }
513+ return g ;
514+ } ) ;
485515 return fg ( fullGlobs ) ;
486516 }
487517}
0 commit comments