Skip to content

Commit

Permalink
feat: 🎸 watch included pug files
Browse files Browse the repository at this point in the history
  • Loading branch information
kaisermann committed Feb 2, 2020
1 parent 5a0200a commit a8855fb
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 21 deletions.
38 changes: 19 additions & 19 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,36 +49,36 @@
}
},
"devDependencies": {
"@types/jest": "^24.0.19",
"@types/node": "^12.7.8",
"@types/stylus": "^0.48.31",
"autoprefixer": "^9.4.7",
"@types/jest": "^25.1.1",
"@types/node": "^13.7.0",
"@types/stylus": "^0.48.32",
"autoprefixer": "^9.7.4",
"babel-minify": "^0.5.1",
"coffeescript": "^2.3.2",
"conventional-changelog-cli": "^2.0.25",
"eslint": "^5.13.0",
"eslint-config-kaisermann": "0.0.3",
"jest": "^24.9.0",
"less": "^3.9.0",
"node-sass": "^4.12.0",
"postcss": "^7.0.14",
"coffeescript": "^2.5.1",
"conventional-changelog-cli": "^2.0.31",
"eslint": "^6.8.0",
"eslint-config-kaisermann": "0.1.0",
"jest": "^25.1.0",
"less": "^3.10.3",
"node-sass": "^4.13.1",
"postcss": "^7.0.26",
"postcss-easy-import": "^3.0.0",
"postcss-load-config": "^2.1.0",
"prettier": "^1.16.4",
"pug": "^2.0.3",
"stylus": "^0.54.5",
"prettier": "^1.19.1",
"pug": "^2.0.4",
"stylus": "^0.54.7",
"sugarss": "^2.0.0",
"svelte": "^3.0.0",
"ts-jest": "^24.1.0",
"typescript": "^3.4.5"
"ts-jest": "^25.1.0",
"typescript": "^3.7.5"
},
"peerDependencies": {
"svelte": "^1.44.0 || ^2.0.0 || ^3.0.0"
"svelte": "^3.18.1"
},
"dependencies": {
"@types/pug": "^2.0.4",
"@types/sass": "^1.16.0",
"detect-indent": "^6.0.0",
"strip-indent": "^2.0.0"
"strip-indent": "^3.0.0"
}
}
13 changes: 11 additions & 2 deletions src/transformers/pug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,17 @@ const transformer: Transformer<Options.Pug> = async ({
};

const { type: identationType } = detectIndent(content);
const code = pug.render(`${GET_MIXINS(identationType)}\n${content}`, options);
return { code };
const code = `${GET_MIXINS(identationType)}\n${content}`;
const compiled = pug.compile(code, {
compileDebug: false,
filename,
...options,
// @types/pug compile() returned value doesn't have `dependencies` prop
}) as pug.compileTemplate & { dependencies?: string[] };
return {
code: compiled(),
dependencies: compiled.dependencies ?? null,
};
};

export default transformer;
11 changes: 11 additions & 0 deletions test/transformers/pug.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { resolve } from 'path';

import getAutoPreprocess from '../../src';
import { preprocess } from '../utils';

Expand All @@ -21,4 +23,13 @@ main
const preprocessed = await preprocess(template, opts);
expect(preprocessed.code).toBe('<main><header><h1></h1></header></main>');
});

it('should return included files as dependencies', async () => {
const template = `<template lang="pug">include ./fixtures/template.pug</template>`;
const opts = getAutoPreprocess();
const preprocessed = await preprocess(template, opts);
expect(preprocessed.dependencies).toContain(
resolve(__dirname, '..', 'fixtures', 'template.pug'),
);
});
});
11 changes: 11 additions & 0 deletions test/transformers/scss.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { resolve } from 'path';

import getAutoPreprocess from '../../src';
import { preprocess } from '../utils';

Expand All @@ -12,4 +14,13 @@ describe('transformer - scss', () => {
const preprocessed = await preprocess(template, opts);
expect(preprocessed.toString()).toContain('red');
});

it('should return @imported files as dependencies', async () => {
const template = `<style lang="scss">@import "fixtures/style.scss";</style>`;
const opts = getAutoPreprocess();
const preprocessed = await preprocess(template, opts);
expect(preprocessed.dependencies).toContain(
resolve(__dirname, '..', 'fixtures', 'style.scss'),
);
});
});

0 comments on commit a8855fb

Please sign in to comment.