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

Commit f944764

Browse files
committed
feat(addpath): implement sassoptions add* path
1 parent 0a3c62a commit f944764

File tree

3 files changed

+29
-10
lines changed

3 files changed

+29
-10
lines changed

src/interop/context.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,17 @@ import { wrapSassOptions } from './wrapSassOptions';
1313
* @param asmModule
1414
*/
1515
const buildContext = (asmModule: SassAsmModule) => {
16-
const { cwrap, FS } = asmModule;
16+
const { cwrap, FS, stackAlloc, stringToUTF8 } = asmModule;
1717
const cwrapCtx = wrapSassContext(cwrap);
1818
const cwrapOptions = wrapSassOptions(cwrap);
1919

20+
const allocString = (value: string) => {
21+
const len = (value.length << 2) + 1;
22+
const ret = stackAlloc(len);
23+
stringToUTF8(value, ret, len);
24+
return ret;
25+
};
26+
2027
const nodePathId = `/${nanoid(45)}`;
2128
FS.mkdir(nodePathId);
2229
log(`buildContext: root mounting point created`, { nodePathId });
@@ -26,7 +33,7 @@ const buildContext = (asmModule: SassAsmModule) => {
2633

2734
return {
2835
options: {
29-
create: () => new SassOptions(cwrapCtx, cwrapOptions, mountPath, unmountPath) as SassOptionsInterface
36+
create: () => new SassOptions(cwrapCtx, cwrapOptions, mountPath, unmountPath, allocString) as SassOptionsInterface
3037
}
3138
};
3239
};

src/interop/sassOptions.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ class SassOptions implements SassOptionsInterface {
8585
private readonly cwrapCtx: ReturnType<typeof wrapSassContext>,
8686
private readonly cwrapOptions: ReturnType<typeof wrapSassOptions>,
8787
private readonly mount: ReturnType<typeof mountDirectory>,
88-
private readonly unmountPath: ReturnType<typeof unmount>
88+
private readonly unmountPath: ReturnType<typeof unmount>,
89+
private readonly allocString: (value: string) => number
8990
) {
9091
this.sassOptionsPtr = cwrapCtx.make_options();
9192
log(`SassOptions: created new instance`, { sassOptionsPtr: this.sassOptionsPtr });
@@ -130,13 +131,17 @@ class SassOptions implements SassOptionsInterface {
130131
}
131132

132133
public addIncludePath(includePath: string): void {
133-
this.mount(includePath);
134-
//TODO: allocate string
135-
//this.cwrapOptions.option_push_include_path(this.sassOptionsPtr);
134+
const mounted = this.mount(includePath);
135+
this.mountedPath.push(mounted);
136+
137+
this.cwrapOptions.option_push_include_path(this.sassOptionsPtr, this.allocString(mounted));
136138
}
137139

138-
public addPluginPath(_pluginPath: string): void {
139-
//this.cwrapOptions.option_push_plugin_path(this.sassOptionsPtr);
140+
public addPluginPath(pluginPath: string): void {
141+
const mounted = this.mount(pluginPath);
142+
this.mountedPath.push(mounted);
143+
144+
this.cwrapOptions.option_push_plugin_path(this.sassOptionsPtr, this.allocString(mounted));
140145
}
141146

142147
public dispose(): void {

src/interop/wrapSassOptions.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,16 @@ const wrapSassOptions = (cwrap: cwrapSignature) => ({
116116
option_set_importer: null,
117117

118118
//void sass_option_push_plugin_path (struct Sass_Options* options, const char* path);
119-
option_push_plugin_path: null,
119+
option_push_plugin_path: cwrap<(sassOptionsPtr: number, path: number) => void>(`sass_option_push_plugin_path`, null, [
120+
'number',
121+
'number'
122+
]),
120123
//void sass_option_push_include_path (struct Sass_Options* options, const char* path);
121-
option_push_include_path: null,
124+
option_push_include_path: cwrap<(sassOptionsPtr: number, path: number) => void>(
125+
`sass_option_push_include_path`,
126+
null,
127+
['number', 'number']
128+
),
122129

123130
//char* sass_find_file (const char* path, struct Sass_Options* opt);
124131
find_file: null,

0 commit comments

Comments
 (0)