-
Notifications
You must be signed in to change notification settings - Fork 18
Throw on invalid JSON with array as top-level structure #27
Comments
It should just be turning |
It maybe happening but problem is with what I get in bundle (note that it is invalid JSON and not const): var log = [
{
"date": "2017-06-03",
"type": "feat",
"desc": "Add changelog window with info on changes",
"pull": "22"
}
{
"date": "2017-05-29",
"type": "perf",
"desc": "Improve performance of grid processing",
"pull": "21"
}
]
; Got this with import statement: import log from '../changelog.json' Exploring context of problem brings up some interesting stuff though: I can import whatever I want in that JSON. For example, I can get this in bundled file: var log = Whoops, just some literals
; With this as Whoops, just some literals This is definitely a problem. Used import cleanup from 'rollup-plugin-cleanup'
import replace from 'rollup-plugin-replace'
import json from 'rollup-plugin-json'
export default {
entry: 'src/index.js',
plugins: [
json({
preferConst: true
}),
replace({
delimiters: ['__', '__'],
BUILD: process.env.TRAVIS_BUILD_NUMBER || 'X-LOCAL'
}),
cleanup()
],
format: 'iife',
dest: 'dist/index.js'
} |
Ah, okay. If the .json file doesn't contain JSON then that's a different matter. I've just released a new version, 2.3.0 — now, it will always call |
Super! Thank you! |
This plugin is really simple and good. Thank you for your efforts!
But it can be even better if it would check the validity of JSON to insert a little bit better. For example, insertion of JSON with array as top-level structure is available. But contents of JSON is just concatenated to bundled script (not squashed as will be with object as top-level element).
preferConst
isn't working as well. Neither validation of supplied structure.It would be better to, at least, warn the user that he supplied something that is not fully supported, or just throw an error.
The text was updated successfully, but these errors were encountered: