@rollup/plugin-yaml
Advanced tools
Comparing version 2.1.1 to 3.0.0
# @rollup/plugin-yaml ChangeLog | ||
## v3.0.0 | ||
_2020-10-27_ | ||
### Breaking Changes | ||
- chore: update dependencies (943f528) | ||
### Features | ||
- feat: provide file id to transform function (#615) | ||
### Updates | ||
- chore: linting updates (93074ca) | ||
## v2.1.1 | ||
@@ -4,0 +20,0 @@ |
@@ -11,6 +11,6 @@ import YAML from 'js-yaml'; | ||
const ext = /\.ya?ml$/; | ||
function yamll(opts = {}) { | ||
function yaml(opts = {}) { | ||
const options = Object.assign({}, defaults, opts); | ||
const documentMode = options.documentMode, | ||
safe = options.safe; | ||
const { documentMode, safe } = options; | ||
const filter = createFilter(options.include, options.exclude); | ||
@@ -24,3 +24,5 @@ let loadMethod = null; | ||
} else { | ||
this.error(`plugin-yaml → documentMode: '${documentMode}' is not a valid value. Please choose 'single' or 'multi'`); | ||
this.error( | ||
`plugin-yaml → documentMode: '${documentMode}' is not a valid value. Please choose 'single' or 'multi'` | ||
); | ||
} | ||
@@ -34,7 +36,8 @@ | ||
if (!filter(id)) return null; | ||
let data = loadMethod(content); | ||
if (typeof options.transform === 'function') { | ||
const result = options.transform(data); // eslint-disable-next-line no-undefined | ||
const result = options.transform(data, id); | ||
// eslint-disable-next-line no-undefined | ||
if (result !== undefined) { | ||
@@ -45,17 +48,17 @@ data = result; | ||
const keys = Object.keys(data).filter(key => key === makeLegalIdentifier(key)); | ||
const keys = Object.keys(data).filter((key) => key === makeLegalIdentifier(key)); | ||
const code = `var data = ${toSource(data)};\n\n`; | ||
const exports = ['export default data;'].concat(keys.map(key => `export var ${key} = data.${key};`)).join('\n'); | ||
const exports = ['export default data;'] | ||
.concat(keys.map((key) => `export var ${key} = data.${key};`)) | ||
.join('\n'); | ||
return { | ||
code: code + exports, | ||
map: { | ||
mappings: '' | ||
} | ||
map: { mappings: '' } | ||
}; | ||
} | ||
}; | ||
} | ||
export default yamll; | ||
export default yaml; | ||
//# sourceMappingURL=index.es.js.map |
'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var YAML = _interopDefault(require('js-yaml')); | ||
var toSource = _interopDefault(require('tosource')); | ||
var YAML = require('js-yaml'); | ||
var toSource = require('tosource'); | ||
var pluginutils = require('@rollup/pluginutils'); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var YAML__default = /*#__PURE__*/_interopDefaultLegacy(YAML); | ||
var toSource__default = /*#__PURE__*/_interopDefaultLegacy(toSource); | ||
const defaults = { | ||
@@ -15,6 +18,6 @@ documentMode: 'single', | ||
const ext = /\.ya?ml$/; | ||
function yamll(opts = {}) { | ||
function yaml(opts = {}) { | ||
const options = Object.assign({}, defaults, opts); | ||
const documentMode = options.documentMode, | ||
safe = options.safe; | ||
const { documentMode, safe } = options; | ||
const filter = pluginutils.createFilter(options.include, options.exclude); | ||
@@ -24,7 +27,9 @@ let loadMethod = null; | ||
if (documentMode === 'single') { | ||
loadMethod = safe ? YAML.load : YAML.safeLoad; | ||
loadMethod = safe ? YAML__default['default'].load : YAML__default['default'].safeLoad; | ||
} else if (documentMode === 'multi') { | ||
loadMethod = safe ? YAML.loadAll : YAML.safeLoadAll; | ||
loadMethod = safe ? YAML__default['default'].loadAll : YAML__default['default'].safeLoadAll; | ||
} else { | ||
this.error(`plugin-yaml → documentMode: '${documentMode}' is not a valid value. Please choose 'single' or 'multi'`); | ||
this.error( | ||
`plugin-yaml → documentMode: '${documentMode}' is not a valid value. Please choose 'single' or 'multi'` | ||
); | ||
} | ||
@@ -38,7 +43,8 @@ | ||
if (!filter(id)) return null; | ||
let data = loadMethod(content); | ||
if (typeof options.transform === 'function') { | ||
const result = options.transform(data); // eslint-disable-next-line no-undefined | ||
const result = options.transform(data, id); | ||
// eslint-disable-next-line no-undefined | ||
if (result !== undefined) { | ||
@@ -49,17 +55,17 @@ data = result; | ||
const keys = Object.keys(data).filter(key => key === pluginutils.makeLegalIdentifier(key)); | ||
const code = `var data = ${toSource(data)};\n\n`; | ||
const exports = ['export default data;'].concat(keys.map(key => `export var ${key} = data.${key};`)).join('\n'); | ||
const keys = Object.keys(data).filter((key) => key === pluginutils.makeLegalIdentifier(key)); | ||
const code = `var data = ${toSource__default['default'](data)};\n\n`; | ||
const exports = ['export default data;'] | ||
.concat(keys.map((key) => `export var ${key} = data.${key};`)) | ||
.join('\n'); | ||
return { | ||
code: code + exports, | ||
map: { | ||
mappings: '' | ||
} | ||
map: { mappings: '' } | ||
}; | ||
} | ||
}; | ||
} | ||
module.exports = yamll; | ||
module.exports = yaml; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@rollup/plugin-yaml", | ||
"version": "2.1.1", | ||
"version": "3.0.0", | ||
"publishConfig": { | ||
@@ -14,2 +14,6 @@ "access": "public" | ||
"main": "dist/index.js", | ||
"module": "dist/index.es.js", | ||
"engines": { | ||
"node": ">=10.0.0" | ||
}, | ||
"scripts": { | ||
@@ -22,3 +26,3 @@ "build": "rollup -c", | ||
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package", | ||
"lint:docs": "prettier --single-quote --write README.md", | ||
"lint:docs": "prettier --single-quote --arrow-parens avoid --trailing-comma none --write README.md", | ||
"lint:js": "eslint --fix --cache src test --ext .js,.ts", | ||
@@ -46,16 +50,16 @@ "lint:package": "prettier --write package.json --plugin=prettier-plugin-package", | ||
"dependencies": { | ||
"@rollup/pluginutils": "^3.0.1", | ||
"js-yaml": "^3.13.1", | ||
"@rollup/pluginutils": "^3.1.0", | ||
"js-yaml": "^3.14.0", | ||
"tosource": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.9.0", | ||
"@babel/preset-env": "^7.9.0", | ||
"@rollup/plugin-node-resolve": "^7.1.1", | ||
"del-cli": "^3.0.0", | ||
"rollup": "^2.0.0", | ||
"rollup-plugin-babel": "^4.3.3", | ||
"source-map-support": "^0.5.16" | ||
"@rollup/plugin-node-resolve": "^8.4.0", | ||
"del-cli": "^3.0.1", | ||
"rollup": "^2.23.0", | ||
"source-map-support": "^0.5.19" | ||
}, | ||
"ava": { | ||
"babel": { | ||
"compileEnhancements": false | ||
}, | ||
"files": [ | ||
@@ -67,4 +71,3 @@ "!**/fixtures/**", | ||
] | ||
}, | ||
"module": "dist/index.es.js" | ||
} | ||
} |
@@ -93,4 +93,4 @@ [npm]: https://img.shields.io/npm/v/@rollup/plugin-yaml | ||
yaml({ | ||
transform(data) { | ||
if (Array.isArray(data)) { | ||
transform(data, filePath) { | ||
if (Array.isArray(data) && filePath === './my-file.yml') { | ||
return data.filter(character => !character.batman); | ||
@@ -97,0 +97,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
17843
4
104
Updated@rollup/pluginutils@^3.1.0
Updatedjs-yaml@^3.14.0