From 99f77dfe0a5723c5d2a29f7abe7747d8e7337a56 Mon Sep 17 00:00:00 2001 From: David Soulayrol Date: Mon, 28 Aug 2023 21:49:09 +0200 Subject: [PATCH] Fixed #1 (Source file is transformed). --- lib/index.js | 5 ++++- test/fixtures/source/src/foo.ms | 1 + test/index.js | 21 +++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/source/src/foo.ms diff --git a/lib/index.js b/lib/index.js index 89bba81..30013e4 100644 --- a/lib/index.js +++ b/lib/index.js @@ -167,7 +167,10 @@ function plugin (options) { return new Promise((resolve, reject) => { let dir = path.dirname(file), destination = path.basename(file, path.extname(file)) + '.' + pluginOptions.device, - data = files[file], + data = { + contents: Buffer.from(files[file].contents), + mode: files[file].mode + } input = data.contents if (dir !== '.') diff --git a/test/fixtures/source/src/foo.ms b/test/fixtures/source/src/foo.ms new file mode 100644 index 0000000..1910281 --- /dev/null +++ b/test/fixtures/source/src/foo.ms @@ -0,0 +1 @@ +foo \ No newline at end of file diff --git a/test/index.js b/test/index.js index 67b1b3d..491aabd 100644 --- a/test/index.js +++ b/test/index.js @@ -130,4 +130,25 @@ describe('metalsmith-groff', function () { 'Preprocessors are missing: ' + Object.values(preprocessors)) }) }) + + it('should keep the source file if requested to do so', function (done) { + const metalsmith = Metalsmith('test/fixtures/source'), + logger = debug('metalsmith-groff:test:source') + + metalsmith + .use(groff({ + exe: 'test/groff_mock', + source: true + })) + .use((files, metalsmith) => { + assert.equal(Object.keys(files).length, 2, 'Expected two files on output!') + assert.equal(files['foo.ms'].contents.toString('utf8'), 'foo', + 'Source file was modified!') + }) + .process((err) => { + if (err) + throw err + done() + }) + }) })