Skip to content

Commit c2eb2ae

Browse files
committed
Fix issue where pods project would not be detected when config file had comments in it. Closes KatalysatorAB#1
1 parent deb996a commit c2eb2ae

File tree

3 files changed

+76
-2
lines changed

3 files changed

+76
-2
lines changed

LICENSE.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2015 <Your name here>
1+
Copyright (c) 2015 Katalysator AB
22

33
Permission is hereby granted, free of charge, to any person obtaining
44
a copy of this software and associated documentation files (the

lib/ember-pods-project.coffee

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
fs = require "fs"
2+
stripeJsonComments = require "../vendor/strip-json-comments"
23

34
module.exports =
45
class EmberPodsProject
@@ -18,7 +19,7 @@ class EmberPodsProject
1819
callback(false)
1920
else
2021
try
21-
@emberCliSettings = JSON.parse(contents)
22+
@emberCliSettings = JSON.parse(stripeJsonComments(contents.toString()))
2223
catch
2324
console.log "[ember-tabs] Invalid .ember-cli file"
2425
callback(false)

vendor/strip-json-comments.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*!
2+
strip-json-comments
3+
Strip comments from JSON. Lets you use comments in your JSON files!
4+
https://github.com/sindresorhus/strip-json-comments
5+
by Sindre Sorhus
6+
MIT License
7+
*/
8+
(function () {
9+
'use strict';
10+
11+
var singleComment = 1;
12+
var multiComment = 2;
13+
14+
function stripJsonComments(str) {
15+
var currentChar;
16+
var nextChar;
17+
var insideString = false;
18+
var insideComment = false;
19+
var ret = '';
20+
21+
for (var i = 0; i < str.length; i++) {
22+
currentChar = str[i];
23+
nextChar = str[i + 1];
24+
25+
if (!insideComment && currentChar === '"') {
26+
var escaped = str[i - 1] === '\\' && str[i - 2] !== '\\';
27+
if (!escaped) {
28+
insideString = !insideString;
29+
}
30+
}
31+
32+
if (insideString) {
33+
ret += currentChar;
34+
continue;
35+
}
36+
37+
if (!insideComment && currentChar + nextChar === '//') {
38+
insideComment = singleComment;
39+
i++;
40+
} else if (insideComment === singleComment && currentChar + nextChar === '\r\n') {
41+
insideComment = false;
42+
i++;
43+
ret += currentChar;
44+
ret += nextChar;
45+
continue;
46+
} else if (insideComment === singleComment && currentChar === '\n') {
47+
insideComment = false;
48+
} else if (!insideComment && currentChar + nextChar === '/*') {
49+
insideComment = multiComment;
50+
i++;
51+
continue;
52+
} else if (insideComment === multiComment && currentChar + nextChar === '*/') {
53+
insideComment = false;
54+
i++;
55+
continue;
56+
}
57+
58+
if (insideComment) {
59+
continue;
60+
}
61+
62+
ret += currentChar;
63+
}
64+
65+
return ret;
66+
}
67+
68+
if (typeof module !== 'undefined' && module.exports) {
69+
module.exports = stripJsonComments;
70+
} else {
71+
window.stripJsonComments = stripJsonComments;
72+
}
73+
})();

0 commit comments

Comments
 (0)