Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 74d5dab

Browse filesBrowse files
janoshNotWoods
authored andcommitted
feat(yaml): provide file id to transform function (#615)
1 parent dbececf commit 74d5dab
Copy full SHA for 74d5dab

File tree

Expand file treeCollapse file tree

3 files changed

+8
-5
lines changed
Filter options
Expand file treeCollapse file tree

3 files changed

+8
-5
lines changed

‎packages/yaml/README.md

Copy file name to clipboardExpand all lines: packages/yaml/README.md
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ A function which can optionally mutate parsed YAML. The function should return t
9090

9191
```js
9292
yaml({
93-
transform(data) {
94-
if (Array.isArray(data)) {
93+
transform(data, filePath) {
94+
if (Array.isArray(data) && filePath === './my-file.yml') {
9595
return data.filter(character => !character.batman);
9696
}
9797
}

‎packages/yaml/src/index.js

Copy file name to clipboardExpand all lines: packages/yaml/src/index.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const defaults = {
99
};
1010
const ext = /\.ya?ml$/;
1111

12-
export default function yamll(opts = {}) {
12+
export default function yaml(opts = {}) {
1313
const options = Object.assign({}, defaults, opts);
1414
const { documentMode, safe } = options;
1515
const filter = createFilter(options.include, options.exclude);
@@ -35,7 +35,7 @@ export default function yamll(opts = {}) {
3535
let data = loadMethod(content);
3636

3737
if (typeof options.transform === 'function') {
38-
const result = options.transform(data);
38+
const result = options.transform(data, id);
3939
// eslint-disable-next-line no-undefined
4040
if (result !== undefined) {
4141
data = result;

‎packages/yaml/test/test.js

Copy file name to clipboardExpand all lines: packages/yaml/test/test.js
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,11 @@ test('resolves extensionless imports in conjunction with nodeResolve plugin', as
5959
});
6060

6161
test('applies the optional transform method to parsed YAML', async (t) => {
62-
const transform = (data) => {
62+
const transform = (data, filePath) => {
63+
// check that transformer is passed a correct file path
64+
t.true(typeof filePath === 'string' && filePath.endsWith('.yaml'), filePath);
6365
if (Array.isArray(data)) {
66+
t.true(filePath.endsWith('array.yaml'), filePath);
6467
return data.filter((datum) => !datum.private);
6568
}
6669
Object.keys(data).forEach((key) => {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.