From d8572823a18dd636cc08cf9709280e0d8a494fe4 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Fri, 29 Jan 2021 13:55:58 +0200 Subject: [PATCH 1/6] Refactor main browser endpoint as ES rather than CommonJS This solution was suggested by @jedwards1211 in #208 --- CONTRIBUTING.md | 2 +- browser/index.js | 3 ++- browser/{dist => }/package.json | 0 3 files changed, 3 insertions(+), 2 deletions(-) rename browser/{dist => }/package.json (100%) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 9f899fa2..911ae0ab 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,7 +24,7 @@ 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` +- **`browser/`** - Browser-optimised ES 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. - **`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. 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 From dce613c96714998c6c24abcde6f36f30eca8c406 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Fri, 29 Jan 2021 14:35:23 +0200 Subject: [PATCH 2/6] Drop browser re-exporters for yaml/types & yaml/util --- browser/types.js | 1 - browser/util.js | 1 - package.json | 8 ++++---- 3 files changed, 4 insertions(+), 6 deletions(-) delete mode 100644 browser/types.js delete mode 100644 browser/util.js 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/package.json b/package.json index 827439d7..45144f36 100644 --- a/package.json +++ b/package.json @@ -24,10 +24,10 @@ "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", From c1639b31356570a16a3ca77e57febf762e50ecde Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Fri, 29 Jan 2021 14:51:22 +0200 Subject: [PATCH 3/6] Drop IE 11 support --- CONTRIBUTING.md | 6 ++++-- README.md | 3 ++- docs/01_intro.md | 3 ++- package.json | 2 +- playground | 2 +- 5 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 911ae0ab..7b0b8d3e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -24,7 +24,7 @@ npm test # just to be sure ## Repository Directory & File Structure -- **`browser/`** - Browser-optimised ES 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` +- **`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 6.0.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. @@ -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/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 45144f36..8eb511bb 100644 --- a/package.json +++ b/package.json @@ -63,7 +63,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, diff --git a/playground b/playground index e2751a6d..0cd141e2 160000 --- a/playground +++ b/playground @@ -1 +1 @@ -Subproject commit e2751a6d13a22e7feeacc91d2e00a0735a116d93 +Subproject commit 0cd141e221b44e96548202f9a612b6c1d004a9da From 5bdbf405b1d835b9cfee84ff72b1f1e8df3864b6 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Fri, 29 Jan 2021 15:09:17 +0200 Subject: [PATCH 4/6] Add preserveModules: true & treeshake config to Rollup configs --- rollup.browser-config.js | 5 +++-- rollup.node-config.js | 10 ++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) 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..01931f7d 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' } }]] }) - ] + ], + treeshake: { moduleSideEffects: false, propertyReadSideEffects: false } } From 890adcc79f3c80369ed780847158965a647d4019 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Fri, 29 Jan 2021 17:04:40 +0200 Subject: [PATCH 5/6] Add "default" fields to package.json "exports" Those will get picked up by webpack@5 and possibly others. Dropping the array fallback also means losing compatibility with Node.js 13.0 and 13.1, which fell out of maintenance support in June 2020. --- package.json | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/package.json b/package.json index 8eb511bb..fa1abd42 100644 --- a/package.json +++ b/package.json @@ -30,20 +30,25 @@ "./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", From 42e84c8fc87a7af2302fd4bf9e88e7a33c166690 Mon Sep 17 00:00:00 2001 From: Eemeli Aro Date: Fri, 29 Jan 2021 17:13:28 +0200 Subject: [PATCH 6/6] Switch minimum Node.js target from 6.5 to 10.0 BREAKING CHANGE: Users of older Node.js versions will need to transpile this library, or update their environment to a supported Node.js version. --- CONTRIBUTING.md | 2 +- package.json | 2 +- rollup.node-config.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 7b0b8d3e..c802116f 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,7 +25,7 @@ npm test # just to be sure ## Repository Directory & File Structure - **`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 6.0.0 and later without polyfills. +- **`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. diff --git a/package.json b/package.json index fa1abd42..c5e847e7 100644 --- a/package.json +++ b/package.json @@ -94,6 +94,6 @@ "typescript": "^4.1.3" }, "engines": { - "node": ">= 6" + "node": ">= 10" } } diff --git a/rollup.node-config.js b/rollup.node-config.js index 01931f7d..f6f3f561 100644 --- a/rollup.node-config.js +++ b/rollup.node-config.js @@ -16,7 +16,7 @@ export default { 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 }