1
- import { mountDirectory , unmount } from 'emscripten-wasm-loader' ;
2
- import * as nanoid from 'nanoid' ;
3
- import { SassAsmModule } from '../SassAsmModule' ;
4
- import { log } from '../util/logger' ;
1
+ import { SassFileContext , SassFileContextInterface } from './file/sassFileContext' ;
2
+ import { buildInteropUtility } from './interopUtility' ;
5
3
import { SassOptions , SassOptionsInterface } from './options/sassOptions' ;
6
4
import { wrapSassOptions } from './options/wrapSassOptions' ;
7
5
import { wrapSassContext } from './wrapSassContext' ;
@@ -12,31 +10,19 @@ import { wrapSassContext } from './wrapSassContext';
12
10
*
13
11
* @param asmModule
14
12
*/
15
- const buildContext = ( asmModule : SassAsmModule ) => {
16
- const { cwrap, FS , stackAlloc, stringToUTF8, Pointer_stringify } = asmModule ;
17
- const cwrapCtx = wrapSassContext ( cwrap ) ;
18
- const cwrapOptions = wrapSassOptions ( cwrap ) ;
19
-
20
- const str = {
21
- alloc : ( value : string ) => {
22
- const len = ( value . length << 2 ) + 1 ;
23
- const ret = stackAlloc ( len ) ;
24
- stringToUTF8 ( value , ret , len ) ;
25
- return ret ;
26
- } ,
27
- ptrToString : Pointer_stringify
28
- } ;
29
-
30
- const nodePathId = `/${ nanoid ( 45 ) } ` ;
31
- FS . mkdir ( nodePathId ) ;
32
- log ( `buildContext: root mounting point created` , { nodePathId } ) ;
33
-
34
- const mountPath = mountDirectory ( FS , nodePathId ) ;
35
- const unmountPath = unmount ( FS , nodePathId ) ;
13
+ const buildContext = (
14
+ cwrapContext : ReturnType < typeof wrapSassContext > ,
15
+ cwrapOptions : ReturnType < typeof wrapSassOptions > ,
16
+ interop : ReturnType < typeof buildInteropUtility >
17
+ ) => {
18
+ const { str, mount, unmount } = interop ;
36
19
37
20
return {
38
21
options : {
39
- create : ( ) => new SassOptions ( cwrapCtx , cwrapOptions , mountPath , unmountPath , str ) as SassOptionsInterface
22
+ create : ( ) => new SassOptions ( cwrapContext , cwrapOptions , mount , unmount , str ) as SassOptionsInterface
23
+ } ,
24
+ file : {
25
+ create : ( ) => new SassFileContext ( ) as SassFileContextInterface
40
26
}
41
27
} ;
42
28
} ;
0 commit comments