diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9f899fa2..c802116f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,8 +24,8 @@ npm test # just to be sure ## Repository Directory & File Structure -- **`browser/`** - Browser-optimised build of the library, which should work in IE 11 & later. Used automatically by e.g. Webpack & Rollup via the `"browser"` value in `package.json`. A corresponding minimal set of the library's required polyfills is available at `playground/src/polyfill.js` -- **`dist/`** - Node-optimised build of the library, which should work in Node.js 6.0.0 and later without polyfills. +- **`browser/`** - Browser-optimised ES build of the library, which should work in modern browsers. Used automatically by e.g. Webpack & Rollup via the `"browser"` value in `package.json`. A corresponding minimal set of the library's required polyfills is available at `playground/src/polyfill.js` +- **`dist/`** - Node-optimised build of the library, which should work in Node.js 10.0 and later without polyfills. - **`docs/`** - Sources for the library's [documentation site](https://eemeli.org/yaml). - **`docs-slate/`** - Compiler for the library's [documentation site](https://eemeli.org/yaml). Maintained as a git submodule to allow merges from its upstream source, [Slate](https://github.com/slatedocs/slate). See its [`README`](./docs-slate/README.md) for installation instructions. Note that the build target is the `gh-pages` branch of _this_ repo. - **`playground/`** - Source files for a browser-based [playground](https://eemeli.org/yaml-playground/) using this library. Also contains the Selenium browser tests for the library. Maintained as a git submodule to allow for easier publication. @@ -42,6 +42,8 @@ npm test # just to be sure ## Contributing Code -First of all, make sure that all the tests pass, and that you've added test cases covering your changes. Our set of test suites is rather extensive, and is a significant help in making sure no regressions are introduced. Note that the CI environment runs tests in e.g. Node.js 6.0 and IE 11, so using new language features may require extending the minimal set of [polyfills](./playground/src/polyfill.js) +First of all, make sure that all the tests pass, and that you've added test cases covering your changes. +Our set of test suites is rather extensive, and is a significant help in making sure no regressions are introduced. +Note that the CI environment runs tests in both Node.js and browsers, so using new language features may require extending the minimal set of [polyfills](./playground/src/polyfill.js) If you're intending to contribute to the upstream repo, please make sure that your code style matches the Prettier and ESLint rules. The easiest way to do that is to configure your editor to do that for you, but `lint` and `prettier` npm scripts are also provided. diff --git a/README.md b/README.md index b3a2dedd..3fe29fb3 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,8 @@ `yaml` is a JavaScript parser and stringifier for [YAML](http://yaml.org/), a human friendly data serialization standard. It supports both parsing and stringifying data using all versions of YAML, along with all common data schemas. As a particularly distinguishing feature, `yaml` fully supports reading and writing comments and blank lines in YAML documents. -The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/). It has no external dependencies and runs on Node.js 6 and later, and in browsers from IE 11 upwards. +The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/). +It has no external dependencies and runs on Node.js as well as modern browsers. For the purposes of versioning, any changes that break any of the endpoints or APIs documented here will be considered semver-major breaking changes. Undocumented library internals may change between minor versions, and previous APIs may be deprecated (but not removed). diff --git a/browser/index.js b/browser/index.js index 2d2f3c0b..33189c12 100644 --- a/browser/index.js +++ b/browser/index.js @@ -1 +1,2 @@ -module.exports = require('./dist') +export * as default from './dist' +export * from './dist' diff --git a/browser/dist/package.json b/browser/package.json similarity index 100% rename from browser/dist/package.json rename to browser/package.json diff --git a/browser/types.js b/browser/types.js deleted file mode 100644 index 26a12542..00000000 --- a/browser/types.js +++ /dev/null @@ -1 +0,0 @@ -export * from './dist/types.js' diff --git a/browser/util.js b/browser/util.js deleted file mode 100644 index 3135a1c3..00000000 --- a/browser/util.js +++ /dev/null @@ -1 +0,0 @@ -export * from './dist/util.js' diff --git a/docs/01_intro.md b/docs/01_intro.md index 98879c34..5fb54f3d 100644 --- a/docs/01_intro.md +++ b/docs/01_intro.md @@ -15,7 +15,8 @@ yarn add yaml@next - Can accept any string as input without throwing, parsing as much YAML out of it as it can, and - Supports parsing, modifying, and writing YAML comments. -The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/). It has no external dependencies and runs on Node.js 6 and later, and in browsers from IE 11 upwards. +The library is released under the ISC open source license, and the code is [available on GitHub](https://github.com/eemeli/yaml/). +It has no external dependencies and runs on Node.js as well as modern browsers. For the purposes of versioning, any changes that break any of the endpoints or APIs documented here will be considered semver-major breaking changes. Undocumented library internals may change between minor versions, and previous APIs may be deprecated (but not removed). diff --git a/package.json b/package.json index 827439d7..c5e847e7 100644 --- a/package.json +++ b/package.json @@ -24,26 +24,31 @@ "main": "./index.js", "browser": { "./index.js": "./browser/index.js", - "./types.js": "./browser/types.js", - "./types.mjs": "./browser/types.js", - "./util.js": "./browser/util.js", - "./util.mjs": "./browser/util.js" + "./types.js": "./browser/dist/types.js", + "./types.mjs": "./browser/dist/types.js", + "./util.js": "./browser/dist/util.js", + "./util.mjs": "./browser/dist/util.js" }, "exports": { - ".": "./index.js", + ".": { + "node": "./index.js", + "default": "./browser/index.js" + }, "./package.json": "./package.json", - "./types": [ - { - "import": "./types.mjs" + "./types": { + "node": { + "import": "./types.mjs", + "require": "./types.js" }, - "./types.js" - ], - "./util": [ - { - "import": "./util.mjs" + "default": "./browser/dist/types.js" + }, + "./util": { + "node": { + "import": "./util.mjs", + "require": "./util.js" }, - "./util.js" - ] + "default": "./browser/dist/util.js" + } }, "scripts": { "build": "npm run build:node && npm run build:browser", @@ -63,7 +68,7 @@ "preversion": "npm test && npm run build", "prepublishOnly": "npm run clean && npm test && npm run build" }, - "browserslist": "> 0.5%, not dead", + "browserslist": "> 0.5%, not dead, not ie 11", "prettier": { "arrowParens": "avoid", "semi": false, @@ -89,6 +94,6 @@ "typescript": "^4.1.3" }, "engines": { - "node": ">= 6" + "node": ">= 10" } } diff --git a/playground b/playground index e2751a6d..0cd141e2 160000 --- a/playground +++ b/playground @@ -1 +1 @@ -Subproject commit e2751a6d13a22e7feeacc91d2e00a0735a116d93 +Subproject commit 0cd141e221b44e96548202f9a612b6c1d004a9da diff --git a/rollup.browser-config.js b/rollup.browser-config.js index 49ee5f85..75ac506a 100644 --- a/rollup.browser-config.js +++ b/rollup.browser-config.js @@ -6,11 +6,12 @@ export default { types: 'src/types.js', util: 'src/util.js' }, - output: { dir: 'browser/dist', format: 'esm' }, + output: { dir: 'browser/dist', format: 'esm', preserveModules: true }, plugins: [ babel({ babelHelpers: 'bundled', presets: [['@babel/env', { modules: false }]] }) - ] + ], + treeshake: { moduleSideEffects: false, propertyReadSideEffects: false } } diff --git a/rollup.node-config.js b/rollup.node-config.js index ca710f8e..f6f3f561 100644 --- a/rollup.node-config.js +++ b/rollup.node-config.js @@ -7,11 +7,17 @@ export default { types: 'src/types.js', util: 'src/util.js' }, - output: { dir: 'dist', format: 'cjs', esModule: false }, + output: { + dir: 'dist', + format: 'cjs', + esModule: false, + preserveModules: true + }, plugins: [ babel({ babelHelpers: 'bundled', - presets: [['@babel/env', { modules: false, targets: { node: '6.5' } }]] + presets: [['@babel/env', { modules: false, targets: { node: '10.0' } }]] }) - ] + ], + treeshake: { moduleSideEffects: false, propertyReadSideEffects: false } }