-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rollup-config-pectin): Use advanced multi-config for better ESM …
…output
- Loading branch information
Showing
3 changed files
with
55 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"presets": [ | ||
"@babel/preset-env" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
48
packages/rollup-config-pectin/test/rollup-config-pectin.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>, | ||
} | ||
` | ||
); | ||
}); | ||
}); |