Skip to content

Commit 20e8617

Browse files
authored
Upgrade schema-utils, and handle single quotes in large JSON files (#29)
* chore: upgraded schema-utils and addressed breaking change * fix: updated test to detect errors, added single quote case to file-big.json fixture * fix: updated to handle single quotes within large json files
1 parent cac0814 commit 20e8617

File tree

5 files changed

+27
-13
lines changed

5 files changed

+27
-13
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
},
3838
"dependencies": {
3939
"loader-utils": "^2.0.0",
40-
"schema-utils": "^2.7.1"
40+
"schema-utils": "^3.0.0"
4141
},
4242
"devDependencies": {
4343
"codecov": "^3.7.2",

src/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const { getOptions } = require('loader-utils')
2-
const validateOptions = require('schema-utils')
2+
const { validate } = require('schema-utils')
33

44
const schema = require('./options.json')
55

@@ -15,7 +15,7 @@ function shouldInline(limit, size) {
1515
module.exports = function (source) {
1616
const options = Object.assign({}, DEFAULT_OPTIONS, getOptions(this))
1717

18-
validateOptions(schema, options, 'JSON Perf Loader')
18+
validate(schema, options, 'JSON Perf Loader')
1919

2020
let value
2121

@@ -33,7 +33,7 @@ module.exports = function (source) {
3333
return `module.exports = ${value}`
3434
}
3535

36-
return `module.exports = JSON.parse('${JSON.stringify(value)}')`
36+
return `module.exports = JSON.parse(\`${JSON.stringify(value)}\`)`
3737
}
3838

3939
exports.raw = true

test/fixtures/file-big.json

+3
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,9 @@
13271327
},
13281328
{
13291329
"foooooooooooooooooooooooo": "barararararararararararararararararararararararararararararar"
1330+
},
1331+
{
1332+
"with-single-quotes": "this 'should' also work"
13301333
}
13311334
]
13321335

test/loader-big.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ describe('Loader', () => {
1313
const stats = await webpack('fixture-big.js', config)
1414
const [{ source }] = stats.toJson().modules
1515

16-
expect(source).toMatch('JSON.parse')
16+
// this will fail when there is an error e.g: `throw new Error...`
17+
expect(source.startsWith('module.exports = JSON.parse')).toEqual(true)
1718
})
1819
})

yarn.lock

+18-8
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@
541541
dependencies:
542542
"@types/istanbul-lib-report" "*"
543543

544-
"@types/json-schema@^7.0.5":
544+
"@types/json-schema@^7.0.6":
545545
version "7.0.6"
546546
resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.6.tgz#f4c7ec43e81b319a9815115031709f26987891f0"
547547
integrity sha512-3c+yGKvVP5Y9TYBEibGNR+kLtijnj7mYrXRg+WpFb2X9xm04g/DXYkfg4hmzJQosc9snFNUPkbYIhu+KAm6jJw==
@@ -796,7 +796,7 @@ ajv-keywords@^3.1.0, ajv-keywords@^3.4.1, ajv-keywords@^3.5.2:
796796
resolved "https://registry.yarnpkg.com/ajv-keywords/-/ajv-keywords-3.5.2.tgz#31f29da5ab6e00d1c2d329acf7b5929614d5014d"
797797
integrity sha512-5p6WTN0DdTGVQk6VjcEju19IgaHudalcfabD7yhDGeA6bcQnmL+CpveLJq/3hvfwd1aof6L386Ougkx6RfyMIQ==
798798

799-
ajv@^6.1.0, ajv@^6.10.2, ajv@^6.12.3, ajv@^6.12.4:
799+
ajv@^6.1.0, ajv@^6.10.2, ajv@^6.12.3:
800800
version "6.12.4"
801801
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.4.tgz#0614facc4522127fa713445c6bfd3ebd376e2234"
802802
integrity sha512-eienB2c9qVQs2KWexhkrdMLVDoIQCz5KSeLxwg9Lzk4DOfBtIK9PQwwufcsn1jjGuf9WZmqPMbGxOzfcuphJCQ==
@@ -806,6 +806,16 @@ ajv@^6.1.0, ajv@^6.10.2, ajv@^6.12.3, ajv@^6.12.4:
806806
json-schema-traverse "^0.4.1"
807807
uri-js "^4.2.2"
808808

809+
ajv@^6.12.5:
810+
version "6.12.6"
811+
resolved "https://registry.yarnpkg.com/ajv/-/ajv-6.12.6.tgz#baf5a62e802b07d977034586f8c3baf5adf26df4"
812+
integrity sha512-j3fVLgvTo527anyYyJOGTYJbG+vnnQYvE0m5mmkc1TK+nxAppkCLMIL0aZ4dblVCNoGShhm+kzE4ZUykBoMg4g==
813+
dependencies:
814+
fast-deep-equal "^3.1.1"
815+
fast-json-stable-stringify "^2.0.0"
816+
json-schema-traverse "^0.4.1"
817+
uri-js "^4.2.2"
818+
809819
ansi-colors@^4.1.1:
810820
version "4.1.1"
811821
resolved "https://registry.yarnpkg.com/ansi-colors/-/ansi-colors-4.1.1.tgz#cbb9ae256bf750af1eab344f229aa27fe94ba348"
@@ -4414,13 +4424,13 @@ schema-utils@^1.0.0:
44144424
ajv-errors "^1.0.0"
44154425
ajv-keywords "^3.1.0"
44164426

4417-
schema-utils@^2.7.1:
4418-
version "2.7.1"
4419-
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-2.7.1.tgz#1ca4f32d1b24c590c203b8e7a50bf0ea4cd394d7"
4420-
integrity sha512-SHiNtMOUGWBQJwzISiVYKu82GiV4QYGePp3odlY1tuKO7gPtphAT5R/py0fA6xtbgLL/RvtJZnU9b8s0F1q0Xg==
4427+
schema-utils@^3.0.0:
4428+
version "3.0.0"
4429+
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-3.0.0.tgz#67502f6aa2b66a2d4032b4279a2944978a0913ef"
4430+
integrity sha512-6D82/xSzO094ajanoOSbe4YvXWMfn2A//8Y1+MUqFAJul5Bs+yn36xbK9OtNDcRVSBJ9jjeoXftM6CfztsjOAA==
44214431
dependencies:
4422-
"@types/json-schema" "^7.0.5"
4423-
ajv "^6.12.4"
4432+
"@types/json-schema" "^7.0.6"
4433+
ajv "^6.12.5"
44244434
ajv-keywords "^3.5.2"
44254435

44264436
semver-compare@^1.0.0:

0 commit comments

Comments
 (0)