File tree Expand file tree Collapse file tree 5 files changed +24
-8
lines changed Expand file tree Collapse file tree 5 files changed +24
-8
lines changed Original file line number Diff line number Diff line change 58
58
"mz" : " 2.6.0" ,
59
59
"node-firefox-connect" : " 1.2.0" ,
60
60
"regenerator-runtime" : " 0.10.0" ,
61
+ "parse-json" : " 2.2.0" ,
61
62
"sign-addon" : " 0.2.0" ,
62
63
"source-map-support" : " 0.4.6" ,
63
64
"stream-to-promise" : " 2.2.0" ,
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import minimatch from 'minimatch';
4
4
import { createWriteStream } from 'fs' ;
5
5
import streamToPromise from 'stream-to-promise' ;
6
6
import { fs } from 'mz' ;
7
+ import parseJSON from 'parse-json' ;
7
8
8
9
import defaultSourceWatcher from '../watcher' ;
9
10
import { zipDir } from '../util/zip-dir' ;
@@ -59,14 +60,23 @@ export async function getDefaultLocalizedName(
59
60
) : Promise < string > {
60
61
61
62
let messageData : LocalizedMessageData ;
63
+ let messageContents : string | Buffer ;
62
64
let extensionName : string = manifestData . name ;
63
65
64
66
try {
65
- messageData = JSON . parse ( await fs . readFile ( messageFile ) ) ;
67
+ messageContents = await fs . readFile ( messageFile ) ;
66
68
} catch ( error ) {
67
69
throw new UsageError (
68
- `Error reading or parsing file ${ messageFile } : ${ error } ` ) ;
70
+ `Error reading messages.json file at ${ messageFile } : ${ error } ` ) ;
69
71
}
72
+
73
+ try {
74
+ messageData = parseJSON ( messageContents , messageFile ) ;
75
+ } catch ( error ) {
76
+ throw new UsageError (
77
+ `Error parsing messages.json ${ error } ` ) ;
78
+ }
79
+
70
80
extensionName = manifestData . name . replace ( / _ _ M S G _ ( [ A - Z a - z 0 - 9 @ _ ] + ?) _ _ / g,
71
81
( match , messageName ) => {
72
82
if ( ! ( messageData [ messageName ]
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import path from 'path';
4
4
import { fs } from 'mz' ;
5
5
import { InvalidManifest } from '../errors' ;
6
6
import { createLogger } from './logger' ;
7
+ import parseJSON from 'parse-json' ;
7
8
8
9
9
10
const log = createLogger ( __filename ) ;
@@ -45,7 +46,7 @@ export default async function getValidatedManifest(
45
46
let manifestData ;
46
47
47
48
try {
48
- manifestData = JSON . parse ( manifestContents ) ;
49
+ manifestData = parseJSON ( manifestContents , manifestFile ) ;
49
50
} catch ( error ) {
50
51
throw new InvalidManifest (
51
52
`Error parsing manifest.json at ${ manifestFile } : ${ error } ` ) ;
Original file line number Diff line number Diff line change @@ -102,9 +102,9 @@ describe('build', () => {
102
102
. then ( makeSureItFails ( ) )
103
103
. catch ( ( error ) => {
104
104
assert . instanceOf ( error , UsageError ) ;
105
- assert . match (
106
- error . message ,
107
- / E r r o r . * f i l e . * m e s s a g e s \. j s o n : S y n t a x E r r o r : U n e x p e c t e d s t r i n g / ) ;
105
+ assert . match ( error . message , / U n e x p e c t e d t o k e n ' " ' a t 1 : 1 5 / ) ;
106
+ assert . match ( error . message , / ^ E r r o r p a r s i n g m e s s a g e s . j s o n / ) ;
107
+ assert . include ( error . message , messageFileName ) ;
108
108
} ) ;
109
109
}
110
110
) ;
@@ -150,7 +150,10 @@ describe('build', () => {
150
150
assert . instanceOf ( error , UsageError ) ;
151
151
assert . match (
152
152
error . message ,
153
- / E r r o r .* f i l e .* m e s s a g e s \. j s o n : .* : n o s u c h f i l e o r d i r e c t o r y / ) ;
153
+ / E r r o r : E N O E N T : n o s u c h f i l e o r d i r e c t o r y , o p e n .* m e s s a g e s .j s o n / ) ;
154
+ assert . match ( error . message , / ^ E r r o r r e a d i n g m e s s a g e s .j s o n / ) ;
155
+ assert . include ( error . message ,
156
+ '/path/to/non-existent-dir/messages.json' ) ;
154
157
} ) ;
155
158
} ) ;
156
159
Original file line number Diff line number Diff line change @@ -70,7 +70,8 @@ describe('util/manifest', () => {
70
70
. then ( ( ) => getValidatedManifest ( tmpDir . path ( ) ) )
71
71
. then ( makeSureItFails ( ) )
72
72
. catch ( onlyInstancesOf ( InvalidManifest , ( error ) => {
73
- assert . match ( error . message , / E r r o r p a r s i n g m a n i f e s t \. j s o n / ) ;
73
+ assert . match ( error . message , / E r r o r p a r s i n g m a n i f e s t \. j s o n a t / ) ;
74
+ assert . include ( error . message , 'Unexpected token \' \' at 2:49' ) ;
74
75
assert . include ( error . message , manifestFile ) ;
75
76
} ) ) ;
76
77
}
You can’t perform that action at this time.
0 commit comments