Skip to content

Commit

Permalink
feat(rollup-config-pectin): Use advanced multi-config for better ESM …
Browse files Browse the repository at this point in the history
…output
  • Loading branch information
evocateur committed Nov 13, 2018
1 parent 0657621 commit 92be659
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 7 deletions.
5 changes: 5 additions & 0 deletions packages/rollup-config-pectin/.babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"presets": [
"@babel/preset-env"
]
}
9 changes: 8 additions & 1 deletion packages/rollup-config-pectin/lib/rollup-config-pectin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
'use strict';

module.exports = require('@pectin/core')('package.json');
const path = require('path');
const pectin = require('@pectin/core');

const cwd = process.cwd();
// eslint-disable-next-line zillow/import/no-dynamic-require
const pkg = require(path.resolve(cwd, 'package.json'));

module.exports = pectin.createMultiConfig(pkg, { cwd });
48 changes: 42 additions & 6 deletions packages/rollup-config-pectin/test/rollup-config-pectin.test.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,49 @@
'use strict';

const pectinCore = require('@pectin/core');
const path = require('path');

jest.mock('@pectin/core', () => jest.fn(() => 'I am tested elsewhere!'));
const REPO_ROOT = path.resolve(__dirname, '../../..');
const CONFIG_FILE = path.resolve(__dirname, '../lib/rollup-config-pectin');

expect.addSnapshotSerializer({
test(val) {
return typeof val === 'string' && val.indexOf(REPO_ROOT) > -1;
},
serialize(val, config, indentation, depth) {
const str = val.replace(REPO_ROOT, '<REPO_ROOT>');

// top-level strings don't need quotes, but nested ones do (object properties, etc)
return depth ? `"${str}"` : str;
},
});

describe('rollup-config-pectin', () => {
it('exports rollup config from cwd', () => {
// eslint-disable-next-line global-require
expect(require('../')).toBe('I am tested elsewhere!');
expect(pectinCore).lastCalledWith('package.json');
it('exports rollup config from cwd', async () => {
// config file expects to operate in CWD
process.chdir(path.resolve(__dirname, '..'));

// eslint-disable-next-line global-require, zillow/import/no-dynamic-require
const config = await require(CONFIG_FILE);

expect(config).toHaveLength(1);
expect(config[0]).toMatchInlineSnapshot(
{
plugins: expect.any(Array),
},
`
Object {
"experimentalCodeSplitting": false,
"input": "<REPO_ROOT>/packages/rollup-config-pectin/src/rollup-config-pectin.js",
"output": Array [
Object {
"exports": "auto",
"file": "<REPO_ROOT>/packages/rollup-config-pectin/lib/rollup-config-pectin.js",
"format": "cjs",
},
],
"plugins": Any<Array>,
}
`
);
});
});

0 comments on commit 92be659

Please sign in to comment.