Skip to content
This repository has been archived by the owner on Jan 25, 2024. It is now read-only.

Commit

Permalink
feat(sassoptions): initial directory mount
Browse files Browse the repository at this point in the history
  • Loading branch information
kwonoj committed Jul 11, 2018
1 parent 5d51d02 commit 0a3c62a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/ambient.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
declare module '*/lib/libsass';
declare module 'nanoid';
14 changes: 12 additions & 2 deletions src/interop/context.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { mountDirectory, unmount } from 'emscripten-wasm-loader';
import * as nanoid from 'nanoid';
import { SassAsmModule } from '../SassAsmModule';
import { log } from '../util/logger';
import { SassOptions, SassOptionsInterface } from './sassOptions';
import { wrapSassContext } from './wrapSassContext';
import { wrapSassOptions } from './wrapSassOptions';
Expand All @@ -10,13 +13,20 @@ import { wrapSassOptions } from './wrapSassOptions';
* @param asmModule
*/
const buildContext = (asmModule: SassAsmModule) => {
const { cwrap } = asmModule;
const { cwrap, FS } = asmModule;
const cwrapCtx = wrapSassContext(cwrap);
const cwrapOptions = wrapSassOptions(cwrap);

const nodePathId = `/${nanoid(45)}`;
FS.mkdir(nodePathId);
log(`buildContext: root mounting point created`, { nodePathId });

const mountPath = mountDirectory(FS, nodePathId);
const unmountPath = unmount(FS, nodePathId);

return {
options: {
create: () => new SassOptions(cwrapCtx, cwrapOptions) as SassOptionsInterface
create: () => new SassOptions(cwrapCtx, cwrapOptions, mountPath, unmountPath) as SassOptionsInterface
}
};
};
Expand Down
17 changes: 13 additions & 4 deletions src/interop/sassOptions.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { mountDirectory, unmount } from 'emscripten-wasm-loader';
import { log } from '../util/logger';
import { wrapSassContext } from './wrapSassContext';
import { wrapSassOptions } from './wrapSassOptions';
Expand Down Expand Up @@ -67,6 +68,10 @@ class SassOptions implements SassOptionsInterface {
* Raw pointer to `struct Sass_Options*`
*/
private readonly sassOptionsPtr: number;
/**
* List of virtual mounted path.
*/
private readonly mountedPath: Array<string> = [];
/**
* Construct new instance of SassOptions.
*
Expand All @@ -78,7 +83,9 @@ class SassOptions implements SassOptionsInterface {
*/
constructor(
private readonly cwrapCtx: ReturnType<typeof wrapSassContext>,
private readonly cwrapOptions: ReturnType<typeof wrapSassOptions>
private readonly cwrapOptions: ReturnType<typeof wrapSassOptions>,
private readonly mount: ReturnType<typeof mountDirectory>,
private readonly unmountPath: ReturnType<typeof unmount>
) {
this.sassOptionsPtr = cwrapCtx.make_options();
log(`SassOptions: created new instance`, { sassOptionsPtr: this.sassOptionsPtr });
Expand Down Expand Up @@ -122,8 +129,9 @@ class SassOptions implements SassOptionsInterface {
this.cwrapOptions.option_set_omit_source_map_url(this.sassOptionsPtr, isOmitted);
}

public addIncludePath(_includePath: string): void {
//TODO: allocate string, mount path
public addIncludePath(includePath: string): void {
this.mount(includePath);
//TODO: allocate string
//this.cwrapOptions.option_push_include_path(this.sassOptionsPtr);
}

Expand All @@ -132,8 +140,9 @@ class SassOptions implements SassOptionsInterface {
}

public dispose(): void {
//TODO: unmount path
this.cwrapCtx.delete_options(this.sassOptionsPtr);
this.mountedPath.forEach(p => this.unmountPath(p));

log(`SassOptions: disposed instance`);
}
}
Expand Down

0 comments on commit 0a3c62a

Please sign in to comment.