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

Commit 4fd16e9

Browse files
committed
feat(sassoptions): expose importers
1 parent 84d897e commit 4fd16e9

File tree

5 files changed

+40
-6
lines changed

5 files changed

+40
-6
lines changed

src/interop/context.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { SassDataContext } from './data/sassDataContext';
22
import { SassFileContext, SassSourceContext } from './file/sassFileContext';
3+
import { wrapSassImporter } from './importer/wrapSassImporter';
34
import { buildInteropUtility } from './interopUtility';
45
import { SassOptions, SassOptionsInterface } from './options/sassOptions';
56
import { wrapSassOptions } from './options/wrapSassOptions';
@@ -14,13 +15,15 @@ import { wrapSassContext } from './wrapSassContext';
1415
const buildContext = (
1516
cwrapContext: ReturnType<typeof wrapSassContext>,
1617
cwrapOptions: ReturnType<typeof wrapSassOptions>,
18+
cwrapImporter: ReturnType<typeof wrapSassImporter>,
1719
interop: ReturnType<typeof buildInteropUtility>
1820
) => {
1921
const { str, mount, unmount } = interop;
2022

2123
return {
2224
options: {
23-
create: () => new SassOptions(cwrapContext, cwrapOptions, mount, unmount, str) as SassOptionsInterface
25+
create: () =>
26+
new SassOptions(cwrapContext, cwrapOptions, cwrapImporter, mount, unmount, str) as SassOptionsInterface
2427
},
2528
file: {
2629
create: (inputPath: string) => new SassFileContext(inputPath, cwrapContext, str) as SassSourceContext

src/interop/importer/wrapSassImporter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { cwrapSignature } from 'emscripten-wasm-loader';
77
*/
88
//TODO: verify return type / param type of cwrapped signature for Sass_Import_Entry
99
const wrapSassImporter = (cwrap: cwrapSignature) => ({
10-
//Sass_C_Import_Callback sass_make_importer (Sass_C_Import_Fn, void* cookie);
10+
//Sass_Importer_Entry sass_make_importer (Sass_Importer_Fn importer, double priority, void* cookie);
1111
make_importer: cwrap<(importFnPtr: number, cookie: number) => number>(`sass_make_importer`, 'number', [
1212
'number',
1313
'number'

src/interop/options/sassOptions.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import { mountDirectory, unmount } from 'emscripten-wasm-loader';
22
import { log } from '../../util/logger';
3+
import { SassImportEntryInterface } from '../importer/sassImportEntry';
4+
import { SassImportEntryList } from '../importer/sassImportEntryList';
5+
import { wrapSassImporter } from '../importer/wrapSassImporter';
36
import { StringMethodInterface } from '../interopUtility';
47
import { wrapSassContext } from '../wrapSassContext';
58
import { wrapSassOptions } from './wrapSassOptions';
@@ -53,6 +56,11 @@ interface SassOptionsInterface {
5356
*/
5457
inputPath: string;
5558

59+
/**
60+
* Property accessor to `sass_option_(get|set)_c_importers`
61+
*/
62+
importers: Array<SassImportEntryInterface>;
63+
5664
/**
5765
* Push include path for compilation.
5866
* Accessor to sass_option_push_include_path
@@ -100,6 +108,11 @@ class SassOptions implements SassOptionsInterface {
100108
* List of virtual mounted path.
101109
*/
102110
private readonly mountedPath: Array<string> = [];
111+
112+
/**
113+
* List of importers.
114+
*/
115+
private importersList: SassImportEntryList | null;
103116
/**
104117
* Construct new instance of SassOptions.
105118
*
@@ -112,6 +125,7 @@ class SassOptions implements SassOptionsInterface {
112125
constructor(
113126
private readonly cwrapCtx: ReturnType<typeof wrapSassContext>,
114127
private readonly cwrapOptions: ReturnType<typeof wrapSassOptions>,
128+
private readonly cwrapImporter: ReturnType<typeof wrapSassImporter>,
115129
private readonly mount: ReturnType<typeof mountDirectory>,
116130
private readonly unmountPath: ReturnType<typeof unmount>,
117131
private readonly strMethod: StringMethodInterface
@@ -193,6 +207,17 @@ class SassOptions implements SassOptionsInterface {
193207
this.cwrapOptions.option_set_input_path(this.sassOptionsPtr, this.strMethod.alloc(outPath));
194208
}
195209

210+
public get importers(): Array<SassImportEntryInterface> {
211+
return !!this.importersList ? this.importersList.entry : [];
212+
}
213+
214+
public set importers(values: Array<SassImportEntryInterface>) {
215+
this.importersList = new SassImportEntryList(this.cwrapImporter, values.length);
216+
this.importersList.entry = values;
217+
218+
this.cwrapOptions.option_set_c_importers(this.sassOptionsPtr, this.importersList.sassImportEntryListPtr);
219+
}
220+
196221
public addIncludePath(includePath: string): void {
197222
const mounted = this.mount(includePath);
198223
this.mountedPath.push(mounted);

src/interop/options/wrapSassOptions.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ const wrapSassOptions = (cwrap: cwrapSignature) => ({
5555
//const char* sass_option_get_source_map_root (struct Sass_Options* options);
5656
option_get_source_map_root: null,
5757
//Sass_Importer_List sass_option_get_c_headers (struct Sass_Options* options);
58-
sass_option_get_c_headers: null,
58+
option_get_c_headers: null,
5959
//Sass_Importer_List sass_option_get_c_importers (struct Sass_Options* options);
60-
sass_option_get_c_importers: null,
60+
option_get_c_importers: cwrap<(sassOptionsPtr: number) => number>(`sass_option_get_c_importers`, 'number', [
61+
'number'
62+
]),
6163
//Sass_Function_List sass_option_get_c_functions (struct Sass_Options* options);
6264
option_get_c_functions: null,
6365

@@ -144,7 +146,11 @@ const wrapSassOptions = (cwrap: cwrapSignature) => ({
144146
//void sass_option_set_c_headers (struct Sass_Options* options, Sass_Importer_List c_headers);
145147
option_set_c_headers: null,
146148
//void sass_option_set_c_importers (struct Sass_Options* options, Sass_Importer_List c_importers);
147-
option_set_c_importers: null,
149+
option_set_c_importers: cwrap<(sassOptionsPtr: number, importersList: number) => void>(
150+
`sass_option_set_c_importers`,
151+
null,
152+
['number', 'number']
153+
),
148154
//void sass_option_set_c_functions (struct Sass_Options* options, Sass_Function_List c_functions);
149155
option_set_c_functions: null,
150156

src/sassLoader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const sassLoader = (asmModule: SassAsmModule): SassFactory => {
2424

2525
return {
2626
getVersion: getVersion(asmModule),
27-
context: buildContext(cwrapCtx, cwrapOptions, interop),
27+
context: buildContext(cwrapCtx, cwrapOptions, cwrapImporter, interop),
2828
importer: buildImporter(cwrapImporter, interop),
2929
interop,
3030
raw: {

0 commit comments

Comments
 (0)