-
-
Notifications
You must be signed in to change notification settings - Fork 591
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: migrate rollup-plugin-yaml (#36)
* chore: migrate rollup-plugin-yaml * chore: misc metadata fixes * chore: resolve review comments:
- Loading branch information
1 parent
757948a
commit e3e20e9
Showing
25 changed files
with
1,479 additions
and
72 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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
link-workspace-packages = true | ||
link-workspace-packages = false | ||
shamefully-hoist = true | ||
shared-workspace-shrinkwrap = true |
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
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
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
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,15 @@ | ||
# @rollup/plugin-yaml Change Log | ||
|
||
## 2.0.0 | ||
*2019-10-18* | ||
|
||
* Add `transform` option [#6](https://github.com/rollup/rollup-plugin-yaml/pull/6) (by @CharlesHolbrow) | ||
* Update dependencies and build, require Node 6 [#7](https://github.com/rollup/rollup-plugin-yaml/pull/7) (by @lukastaegert) | ||
|
||
## 1.1.0 | ||
|
||
* Switch to `js-yaml` for parsing [#2](https://github.com/rollup/rollup-plugin-yaml/pull/2) | ||
|
||
## 1.0.0 | ||
|
||
* First release |
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,91 @@ | ||
[npm]: https://img.shields.io/npm/v/@rollup/plugin-yaml | ||
[npm-url]: https://www.npmjs.com/package/@rollup/plugin-yaml | ||
[size]: https://packagephobia.now.sh/badge?p=@rollup/plugin-yaml | ||
[size-url]: https://packagephobia.now.sh/result?p=@rollup/plugin-yaml | ||
|
||
[![npm][npm]][npm-url] | ||
[![size][size]][size-url] | ||
[![libera manifesto](https://img.shields.io/badge/libera-manifesto-lightgrey.svg)](https://liberamanifesto.com) | ||
|
||
# @rollup/plugin-yaml | ||
|
||
🍣 A Rollup plugin which Converts YAML files to ES6 modules. | ||
|
||
## Requirements | ||
|
||
This plugin requires an [LTS](https://github.com/nodejs/Release) Node version (v8.0.0+) and Rollup v1.20.0+. | ||
|
||
## Install | ||
|
||
Using npm: | ||
|
||
```console | ||
npm install @rollup/plugin-yaml --save-dev | ||
``` | ||
|
||
## Usage | ||
|
||
Create a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin: | ||
|
||
```js | ||
import yaml from '@rollup/plugin-yaml'; | ||
|
||
export default { | ||
input: 'src/index.js', | ||
output: { | ||
dir: 'output', | ||
format: 'cjs' | ||
}, | ||
plugins: [yaml()] | ||
}; | ||
``` | ||
|
||
Then call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the [API](https://www.rollupjs.org/guide/en/#javascript-api). | ||
|
||
With an accompanying file `src/index.js`, the local `heroes.yaml` file would now be importable as seen below: | ||
|
||
```js | ||
// src/index.js | ||
import { batman } from './heroes.yaml'; | ||
|
||
console.log(`na na na na ${batman}`); | ||
``` | ||
|
||
## Options | ||
|
||
### `exclude` | ||
|
||
Type: `String` | `Array[...String]`<br> | ||
Default: `null` | ||
|
||
A [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns, which specifies the files in the build the plugin should _ignore_. By default no files are ignored. | ||
|
||
### `include` | ||
|
||
Type: `String` | `Array(String)`<br> | ||
Default: `null` | ||
|
||
A [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted. | ||
|
||
### `transform` | ||
|
||
Type: `Function`<br> | ||
Default: `undefined` | ||
|
||
A function which can optionally mutate parsed YAML. The function should return the mutated `object`, or `undefined` which will make no changes to the parsed YAML. | ||
|
||
```js | ||
yaml({ | ||
transform(data) { | ||
if (Array.isArray(data)) { | ||
return data.filter(character => !character.batman); | ||
} | ||
} | ||
}); | ||
``` | ||
|
||
## Meta | ||
|
||
[CONTRIBUTING](/.github/CONTRIBUTING.md) | ||
|
||
[LICENSE (MIT)](/LICENSE) |
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,68 @@ | ||
{ | ||
"name": "@rollup/plugin-yaml", | ||
"version": "2.0.0", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"description": "Convert YAML files to ES6 modules", | ||
"license": "MIT", | ||
"repository": "rollup/plugins", | ||
"author": "rollup", | ||
"homepage": "https://github.com/rollup/plugins/packages/yaml/#readme", | ||
"bugs": "https://github.com/rollup/plugins/issues", | ||
"main": "dist/index.js", | ||
"scripts": { | ||
"build": "rollup -c", | ||
"ci:coverage": "nyc pnpm run test && nyc report --reporter=text-lcov > coverage.lcov", | ||
"ci:lint": "pnpm run build && pnpm run lint && pnpm run security", | ||
"ci:lint:commits": "commitlint --from=${CIRCLE_BRANCH} --to=${CIRCLE_SHA1}", | ||
"ci:test": "pnpm run test -- --verbose", | ||
"lint": "pnpm run lint:js && pnpm run lint:docs && pnpm run lint:package", | ||
"lint:docs": "prettier --single-quote --write README.md", | ||
"lint:js": "eslint --fix --cache src test", | ||
"lint:package": "prettier --write package.json --plugin=prettier-plugin-package", | ||
"prebuild": "del-cli dist", | ||
"prepare": "pnpm run build", | ||
"prepublishOnly": "pnpm run lint", | ||
"pretest": "pnpm run build", | ||
"security": "echo 'pnpm needs `npm audit` support'", | ||
"test": "ava" | ||
}, | ||
"files": [ | ||
"dist", | ||
"README.md", | ||
"LICENSE" | ||
], | ||
"keywords": [ | ||
"rollup", | ||
"plugin", | ||
"yaml" | ||
], | ||
"peerDependencies": { | ||
"rollup": "^1.20.0" | ||
}, | ||
"dependencies": { | ||
"js-yaml": "^3.13.1", | ||
"rollup-pluginutils": "^2.8.2", | ||
"tosource": "^1.0.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.7.2", | ||
"@babel/preset-env": "^7.7.1", | ||
"del-cli": "^3.0.0", | ||
"rollup": "^1.27.0", | ||
"rollup-plugin-babel": "^4.3.3", | ||
"rollup-plugin-node-resolve": "^5.2.0", | ||
"source-map-support": "^0.5.16" | ||
}, | ||
"ava": { | ||
"files": [ | ||
"!**/fixtures/**", | ||
"!**/helpers/**", | ||
"!**/recipes/**", | ||
"!**/types.ts" | ||
] | ||
}, | ||
"jsnext:main": "dist/index.es.js", | ||
"module": "dist/index.es.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import babel from 'rollup-plugin-babel'; | ||
|
||
import pkg from './package.json'; | ||
|
||
export default { | ||
input: 'src/index.js', | ||
plugins: [ | ||
babel({ | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
targets: { | ||
node: 6 | ||
} | ||
} | ||
] | ||
] | ||
}) | ||
], | ||
external: Object.keys(pkg.dependencies), | ||
output: [ | ||
{ file: pkg.main, format: 'cjs', sourcemap: true }, | ||
{ file: pkg.module, format: 'es', sourcemap: true } | ||
] | ||
}; |
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,41 @@ | ||
import YAML from 'js-yaml'; | ||
import toSource from 'tosource'; | ||
import { createFilter, makeLegalIdentifier } from 'rollup-pluginutils'; | ||
|
||
const ext = /\.ya?ml$/; | ||
|
||
export default function yamll(options = {}) { | ||
const filter = createFilter(options.include, options.exclude); | ||
|
||
return { | ||
name: 'yaml', | ||
|
||
transform(content, id) { | ||
if (!ext.test(id)) return null; | ||
if (!filter(id)) return null; | ||
|
||
let data = YAML.load(content); | ||
|
||
if (typeof options.transform === 'function') { | ||
const result = options.transform(data); | ||
// eslint-disable-next-line no-undefined | ||
if (result !== undefined) { | ||
data = result; | ||
} | ||
} | ||
|
||
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'); | ||
|
||
return { | ||
code: code + exports, | ||
map: { mappings: '' } | ||
}; | ||
} | ||
}; | ||
} |
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 @@ | ||
{ | ||
"globals": { | ||
"t": "readonly" | ||
} | ||
} |
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,2 @@ | ||
answer: | ||
42 |
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,3 @@ | ||
import config from './config.yaml'; | ||
|
||
t.is(config.answer, 42); |
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,2 @@ | ||
answer: | ||
42 |
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,2 @@ | ||
Are extensionless imports and /index resolutions a good idea?: | ||
No. |
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,7 @@ | ||
/* eslint-disable import/no-unresolved, import/extensions */ | ||
|
||
import config from './config'; | ||
import questions from './dir'; | ||
|
||
t.is(config.answer, 42); | ||
t.is(questions['Are extensionless imports and /index resolutions a good idea?'], 'No.'); |
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,2 @@ | ||
answer: | ||
42 |
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,3 @@ | ||
import { answer } from './config.yaml'; | ||
|
||
t.is(answer, 42); |
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 @@ | ||
- name: alice | ||
private: true | ||
- name: bob | ||
private: false | ||
- name: carl |
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,13 @@ | ||
/* eslint-disable no-prototype-builtins */ | ||
|
||
import array from './array.yaml'; | ||
import object from './object.yaml'; | ||
|
||
t.is(array.length, 2); | ||
t.is(array[0].name, 'bob'); | ||
t.is(array[1].name, 'carl'); | ||
|
||
t.is(Object.keys(object).length, 2); | ||
t.falsy(object.hasOwnProperty('alice')); | ||
t.truthy(object.hasOwnProperty('bob')); | ||
t.truthy(object.hasOwnProperty('carl')); |
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,3 @@ | ||
alice: { private: true } | ||
bob: { private: false } | ||
carl: {} |
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,2 @@ | ||
answer: | ||
42 |
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,3 @@ | ||
import config from './config.yml'; | ||
|
||
t.is(config.answer, 42); |
Oops, something went wrong.