@@ -71,30 +71,7 @@ export const getScript = async (pkg: Package, key: 'build' | 'test', deps: Insta
7171 `
7272 }
7373
74- let fixture_key = key == 'build' ? 'prop' : 'fixture'
75- let fixture = obj [ fixture_key ]
76- if ( fixture ) {
77- fixture_key = fixture_key . toUpperCase ( )
78- fixture = mm . apply ( validate . str ( fixture ) , tokens )
79- run = undent `
80- OLD_${ fixture_key } =$${ fixture_key }
81- ${ fixture_key } =$(mktemp)
82-
83- cat <<DEV_PKGX_EOF > $${ fixture_key }
84- ${ fixture }
85- DEV_PKGX_EOF
86-
87- ${ run }
88-
89- rm -f $${ fixture_key }
90-
91- if test -n "$${ fixture_key } "; then
92- ${ fixture_key } =$OLD_${ fixture_key }
93- else
94- unset ${ fixture_key }
95- fi
96- `
97- }
74+ run = add_fixture ( run , key , obj , tokens )
9875
9976 return run . trim ( )
10077 } else {
@@ -155,6 +132,38 @@ function expand_env(env: PlainObject, pkg: Package, tokens: { from: string, to:
155132 } ) . join ( "\n" )
156133}
157134
135+ function add_fixture ( run : string , key : string , obj : any , tokens : { from : string , to : string } [ ] ) {
136+ let fixture_key = key == 'build' ? 'prop' : 'fixture'
137+ let fixture = obj [ fixture_key ]
138+ if ( ! fixture ) return run
139+
140+ let extname = `${ fixture [ 'extname' ] || '' } `
141+ while ( extname . startsWith ( '.' ) ) extname = extname . slice ( 1 )
142+
143+ const contents = isPlainObject ( fixture ) ? fixture [ 'content' ] : fixture
144+
145+ fixture_key = fixture_key . toUpperCase ( )
146+ fixture = useMoustaches ( ) . apply ( validate . str ( contents ) , tokens )
147+ return undent `
148+ OLD_${ fixture_key } =$${ fixture_key }
149+ ${ fixture_key } =$(mktemp)${ extname ? `.${ extname } ` : '' }
150+
151+ cat <<DEV_PKGX_EOF > $${ fixture_key }
152+ ${ fixture }
153+ DEV_PKGX_EOF
154+
155+ ${ run }
156+
157+ rm -f $${ fixture_key } *
158+
159+ if test -n "$${ fixture_key } "; then
160+ ${ fixture_key } =$OLD_${ fixture_key }
161+ else
162+ unset ${ fixture_key }
163+ fi
164+ `
165+ }
166+
158167//FIXME these are copy pasta from usePantry because we build to a different prefix so need control over the moustaches
159168export function expand_env_obj ( env_ : PlainObject , pkg : Package , tokens : { from : string , to : string } [ ] ) : Record < string , string > {
160169 const env = { ...env_ }
0 commit comments