diff --git a/index.js b/index.js index c1df2d3..0c04807 100644 --- a/index.js +++ b/index.js @@ -76,7 +76,7 @@ module.exports = function(content, ...rest) { const { failed, success } = makeDoneHandlers(this.async(), content, rest); const filename = this.resourcePath; - const { mode = 'emit' } = loaderUtils.getOptions(this) || {}; + const { mode = 'emit', banner = bannerMessage } = loaderUtils.getOptions(this) || {}; if (!validModes.includes(mode)) { return failed(new Error(`Invalid mode option: ${mode}`)); } @@ -96,7 +96,7 @@ module.exports = function(content, ...rest) { } } - const cssModuleDefinition = `${bannerMessage}\n${cssModuleToInterface(cssModuleKeys)}\n${cssModuleExport}`; + const cssModuleDefinition = `${banner}\n${cssModuleToInterface(cssModuleKeys)}\n${cssModuleExport}`; if (mode === 'verify') { read((err, fileContents) => { diff --git a/test/banner-custom/.gitignore b/test/banner-custom/.gitignore new file mode 100644 index 0000000..cc5d7db --- /dev/null +++ b/test/banner-custom/.gitignore @@ -0,0 +1 @@ +index.css.d.ts diff --git a/test/banner-custom/__snapshots__/banner-custom.test.js.snap b/test/banner-custom/__snapshots__/banner-custom.test.js.snap new file mode 100644 index 0000000..65ed1f8 --- /dev/null +++ b/test/banner-custom/__snapshots__/banner-custom.test.js.snap @@ -0,0 +1,11 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`Can add custom banners 1`] = ` +"// @generated +interface CssExports { + 'foo': string; +} +export const cssExports: CssExports; +export default cssExports; +" +`; diff --git a/test/banner-custom/banner-custom.test.js b/test/banner-custom/banner-custom.test.js new file mode 100644 index 0000000..3d8ff90 --- /dev/null +++ b/test/banner-custom/banner-custom.test.js @@ -0,0 +1,15 @@ +const fs = require('fs'); +const compiler = require('../compiler.js'); + +test('Can add custom banners', async () => { + await compiler(require.resolve('./index.js'), { + banner: "// @generated", + }); + + const declaration = fs.readFileSync( + require.resolve('./index.css.d.ts'), + 'utf-8' + ); + + expect(declaration).toMatchSnapshot(); +}); diff --git a/test/banner-custom/index.css b/test/banner-custom/index.css new file mode 100644 index 0000000..40167ad --- /dev/null +++ b/test/banner-custom/index.css @@ -0,0 +1,3 @@ +.foo { + display: block; +} diff --git a/test/banner-custom/index.js b/test/banner-custom/index.js new file mode 100644 index 0000000..14a65bf --- /dev/null +++ b/test/banner-custom/index.js @@ -0,0 +1 @@ +import styles from './index.css';