diff --git a/src/index.ts b/src/index.ts index 3015472..70c1f83 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,6 +3,11 @@ import * as d from './declarations'; import { loadDiagnostic } from './diagnostics'; import { createResultsId, getRenderOptions, usePlugin } from './util'; +/** + * Helper type to note which plugin methods are defined for this plugin. + */ +type WithRequired = T & { [P in K]-?: T[P] }; + /** * The entrypoint of the Stencil Sass plugin * @@ -13,7 +18,7 @@ import { createResultsId, getRenderOptions, usePlugin } from './util'; * @param opts options to configure the plugin * @return the configured plugin */ -export function sass(opts: d.PluginOptions = {}): d.Plugin { +export function sass(opts: d.PluginOptions = {}): WithRequired { return { name: 'sass', pluginType: 'css', @@ -52,7 +57,9 @@ export function sass(opts: d.PluginOptions = {}): d.Plugin { results.code = `/** sass error${err && err.message ? ': ' + err.message : ''} **/`; resolve(results); } else { - results.dependencies = Array.from(sassResult.stats.includedFiles); + results.dependencies = Array.from(sassResult.stats.includedFiles).map((dep) => + context.sys.normalizePath(dep), + ); results.code = sassResult.css.toString(); // write this css content to memory only so it can be referenced diff --git a/test/build.spec.ts b/test/build.spec.ts index d5486ad..e84b933 100644 --- a/test/build.spec.ts +++ b/test/build.spec.ts @@ -14,8 +14,10 @@ describe('test build', () => { rootDir: '/Users/my/app/', srcDir: '/Users/my/app/src/', }, - cache: null, - sys: {} as any, + cache: null as any, + sys: { + normalizePath: jest.fn((p: string) => p), + } as any, fs: { readFileSync(filePath: string) { return fs.readFileSync(filePath, 'utf8'); @@ -50,6 +52,7 @@ describe('test build', () => { path.join(__dirname, 'fixtures', 'scss', 'variables.scss') ]); expect(results.diagnostics).toEqual(undefined); + expect(context.sys.normalizePath).toBeCalledTimes(1) }); it('transform, error scss', async () => {