Skip to content

Commit da7b577

Browse files
brettz9Brett Zamir
authored andcommitted
Details on breaking changes:
1. Adds support for genuine ESM in Node (`type` and `exports` in `package.json` and changed `main` path). 2. Changes browser paths to include "-browser" in the file name 3. Adds `browser` to `package.json` to point to browser build for browser-specific bundling. Rollup users wishing the browser bundle must ensure `@rollup/plugin-node-resolve` has `mainFields` to include `browser` as the first item in the array; Webpack users may need to set `resolve` with `aliasFields: ['browser']` and/or `mainFields: ['browser', 'module', 'main']`, ensuring that `browser` is in the front of the list 4. Has `module` point to the Node-specific build (with a new path) - Breaking change: Add `type: 'commonjs'` and `exports: {import, require}` (with `node-import-test` npm script to demo) - Breaking change: Change paths for browser (now is `dist/index-browser-umd.js` or `dist/index-browser-es.js`) (for Node, `main` and `module` point to new Node-specific dist) - Breaking enhancement: Add `browser` for browser bundling; allowing static analysis environments, doesn't have however conditional code to require `vm`); for ESM browser bundling, now must check `browser` in Rollup Node resolver plugin; see README - Linting: quote props; as per latest ash-nazg - Testing: Fix browser tests - Travis: add default `dist` field to avoid extra config reporting - Docs: Update - npm: Reorder scripts by test execution order - npm: Stable `mocha-multi-reporters` - npm: Update devDeps. and package-lock - npm: Bump to 5.0.0
1 parent aace022 commit da7b577

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4654
-4026
lines changed

.eslintrc.js

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
'use strict';
22
module.exports = {
3-
'extends': ['ash-nazg/sauron-node'],
3+
extends: ['ash-nazg/sauron-node'],
44
parserOptions: {
55
ecmaVersion: 2020,
66
sourceType: 'module'
77
},
8-
'settings': {
9-
'polyfills': [
8+
settings: {
9+
polyfills: [
1010
'Array.isArray',
1111
'console',
1212
'Date.now',
@@ -20,7 +20,7 @@ module.exports = {
2020
'XMLHttpRequest'
2121
]
2222
},
23-
'overrides': [
23+
overrides: [
2424
{
2525
files: ['.eslintrc.js', '.mocharc.js'],
2626
extends: ['plugin:node/recommended-script'],
@@ -30,12 +30,12 @@ module.exports = {
3030
}
3131
},
3232
{
33-
'files': ['src/jsonpath.js', 'test-helpers/node-env.js'],
33+
files: ['src/jsonpath-node.js', 'test-helpers/node-env.js'],
3434
// Apparent bug with `overrides` necessitating this
35-
'globals': {
36-
'require': 'readonly',
37-
'run': 'readonly',
38-
'module': 'readonly'
35+
globals: {
36+
require: 'readonly',
37+
run: 'readonly',
38+
module: 'readonly'
3939
},
4040
rules: {
4141
'node/no-unsupported-features/es-syntax': ['error', {
@@ -46,55 +46,63 @@ module.exports = {
4646
}
4747
},
4848
{
49-
'files': ['*.md'],
50-
'rules': {
49+
files: ['*.md'],
50+
rules: {
5151
'import/unambiguous': 0,
5252
'import/no-commonjs': 0,
5353
'import/no-unresolved': ['error', {
54-
'ignore': ['jsonpath-plus']
54+
ignore: ['jsonpath-plus']
5555
}],
5656
'no-undef': 0,
5757
'no-unused-vars': ['error', {
58-
'varsIgnorePattern': 'json|result'
58+
varsIgnorePattern: 'json|result'
59+
}],
60+
'import/no-extraneous-dependencies': 0,
61+
'node/no-extraneous-import': ['error', {
62+
allowModules: ['jsonpath-plus']
5963
}],
6064
'node/no-missing-require': ['error', {
61-
'allowModules': ['jsonpath-plus']
65+
allowModules: ['jsonpath-plus']
6266
}],
6367
'node/no-missing-import': ['error', {
64-
'allowModules': ['jsonpath-plus']
68+
allowModules: ['jsonpath-plus']
6569
}]
6670
}
6771
},
6872
{
69-
'files': ['test/**'],
70-
'extends': [
73+
files: ['test/**'],
74+
extends: [
7175
'plugin:chai-expect/recommended',
7276
'plugin:chai-friendly/recommended'
7377
],
74-
'globals': {
75-
'assert': 'readonly',
76-
'expect': 'readonly',
77-
'jsonpath': 'readonly'
78+
globals: {
79+
assert: 'readonly',
80+
expect: 'readonly',
81+
jsonpath: 'readonly'
7882
},
79-
'env': {'mocha': true},
80-
'rules': {
81-
'quotes': 0,
83+
env: {mocha: true},
84+
rules: {
85+
quotes: 0,
86+
'quote-props': 0,
8287
'import/unambiguous': 0,
8388
// Todo: Reenable
8489
'max-len': 0
8590
}
8691
}
8792
],
88-
'rules': {
89-
'indent': ['error', 4, {'outerIIFEBody': 0}],
93+
rules: {
94+
indent: ['error', 4, {outerIIFEBody: 0}],
9095
'promise/prefer-await-to-callbacks': 0,
91-
'quote-props': 0,
9296
'require-jsdoc': 0,
9397

9498
// Disable for now
9599
'eslint-comments/require-description': 0,
100+
// Reenable as have time and confirming no longer needing:
101+
// https://github.com/babel/babel/issues/8951#issuecomment-508045524 is no
102+
'prefer-named-capture-group': 0,
96103

97104
// Reenable when no longer having problems
98-
'unicorn/no-unsafe-regex': 0
105+
'unicorn/no-unsafe-regex': 0,
106+
'unicorn/consistent-destructuring': 0
99107
}
100108
};

.mocharc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
22
module.exports = {
33
delay: true,
4-
reporter: 'cypress-multi-reporters'
4+
reporter: 'mocha-multi-reporters'
55
};

.travis.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
language: node_js
2-
os:
3-
- linux
2+
os: linux
3+
dist: xenial
4+
45
node_js:
56
- 10
67
- 12

CHANGES.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,34 @@
11
# CHANGES for jsonpath-plus
22

3-
## ?
4-
3+
## 5.0.0 (2020-07-11)
4+
5+
- Breaking change: Add `type: 'commonjs'` and `exports: {import, require}`
6+
(with `node-import-test` npm script to demo)
7+
- Breaking change: Change paths for browser (now is
8+
`dist/index-browser-umd.js` or `dist/index-browser-es.js`)
9+
(for Node, `main` and `module` point to new Node-specific dist)
10+
- Breaking enhancement: Add `browser` for browser bundling;
11+
allowing static analysis environments, doesn't have however
12+
conditional code to require `vm`); for ESM browser bundling,
13+
now must check `browser` in Rollup Node resolver plugin;
14+
see README
515
- Build: Update per latest devDeps.
616
- Docs: Add Regex (`.match`) example on value (@jeffreypriebe)
717
- Docs: Add Regex (`.match`) example on property
818
- Docs: Fix XPath example (@humbertoc-silva)
919
- Docs: Link to XPath 2.0 tester
1020
- Docs: Update badges per latest updates
21+
- Linting: quote props
1122
- Linting: As per latest ash-nazg
23+
- Testing: Fix browser tests
1224
- Testing: Add test case for setting values in callbacks (issue #126)
1325
- Testing: Add more at-sign tests
1426
- Testing: Bump timeout
1527
- Travis: Check Node 14
28+
- Travis: add default `dist` field to avoid extra config reporting
1629
- npm: Update from deprecated `rollup-plugin-babel` to `@rollup/plugin-babel`
1730
(and make `babelHelpers` explicit)
31+
- npm: Reorder scripts by test execution order
1832
- npm: Update devDeps
1933

2034
## 4.0.0 (2020-04-09)

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ magic is necessary:
8686
browsers in dist -->
8787
<script src="node_modules/core-js-bundle/minified.js"></script>
8888

89-
<script src="node_modules/jsonpath-plus/dist/index-umd.js"></script>
89+
<script src="node_modules/jsonpath-plus/dist/index-browser-umd.js"></script>
9090

9191
<script>
9292
@@ -102,15 +102,18 @@ You may also use ES6 Module imports (for modern browsers):
102102
```html
103103
<script type="module">
104104
105-
import {JSONPath} from './node_modules/jsonpath-plus/dist/index-es.js';
105+
import {JSONPath} from './node_modules/jsonpath-plus/dist/index-browser-es.js';
106106
const result = JSONPath({path: '...', json: ...});
107107
108108
</script>
109109
```
110110

111111
### ESM (Bundlers)
112112

113-
Or if you are bundling your JavaScript (e.g., with Rollup), just use:
113+
Or if you are bundling your JavaScript (e.g., with Rollup), just use,
114+
noting that [`mainFields`](https://github.com/rollup/plugins/tree/master/packages/node-resolve#mainfields)
115+
should include `browser` for browser builds (for Node, the default, which
116+
checks `module`, should be fine):
114117

115118
```js
116119
import {JSONPath} from 'jsonpath-plus';

demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ <h2>JSONPath Demo <i id="demoNode">(To demo on Node instead, see the <a href="ht
2626
</label>
2727
</div>
2828
</form>
29-
<script src="../dist/index-umd.js"></script>
29+
<script src="../dist/index-browser-umd.js"></script>
3030
<script src="index.js"></script>
3131
</body>
3232
</html>

demo/node-import-test.mjs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import {JSONPath} from '../dist/index-node-esm.mjs';
2+
3+
/* eslint-disable quotes, quote-props */
4+
const json = {
5+
"store": {
6+
"book": [{
7+
"category": "reference",
8+
"author": "Nigel Rees",
9+
"title": "Sayings of the Century",
10+
"price": 8.95
11+
},
12+
{
13+
"category": "fiction",
14+
"author": "Evelyn Waugh",
15+
"title": "Sword of Honour",
16+
"price": 12.99
17+
},
18+
{
19+
"category": "fiction",
20+
"author": "Herman Melville",
21+
"title": "Moby Dick",
22+
"isbn": "0-553-21311-3",
23+
"price": 8.99
24+
},
25+
{
26+
"category": "fiction",
27+
"author": "J. R. R. Tolkien",
28+
"title": "The Lord of the Rings",
29+
"isbn": "0-395-19395-8",
30+
"price": 22.99
31+
}],
32+
"bicycle": {
33+
"color": "red",
34+
"price": 19.95
35+
}
36+
}
37+
};
38+
/* eslint-enable quotes, quote-props */
39+
40+
const result = JSONPath({
41+
json,
42+
path: '$.store.book[*].author'
43+
});
44+
45+
// eslint-disable-next-line no-console
46+
console.log('result', result);

0 commit comments

Comments
 (0)