-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
writeProfile in prebuild.js strips regex #36
Comments
Hi @lancegosby, Did you find a workaround to this issue ? Thanks |
I did this a while ago so not sure if I changed anything else. function writeProfile() {
function replacer(key, value) {
// wrap RegExp so we can find later
if (value instanceof RegExp) {
return ("__REGEXP " + value.toString() + " REGEXP__");
}
else
return value;
}
// use replacer function to wrap any RegEx so we can find it
var tmpProfileStr = "profile = " + JSON.stringify(profile, replacer, 2) + ";";
// convert back to RegEx before writing to file
var profileStr = tmpProfileStr.replace(/"__REGEXP (.*) REGEXP__"/g, function(match, p1) {
// unescape backslashes since this was stringified
return p1.replace(/\\\\/g,"\\");
});
fs.writeFileSync(wProfileFile, profileStr, "utf-8");
} |
Many thanks @lancegosby !
|
Good stuff @lancegosby ! Would it be less confusing to swap out RegExp.toJSON over this text replace? |
@gbochenek I'm not sure exactly what you mean. I remember trying a few different things at the time I was working through this. Not sure why I stuck with this, but it works for us. If you can improve on it, or make it less confusing, I would interested to see it. |
I definitely think its a good solution.
For incorporating this as a pull request, I'm wondering if something like
the solution here:
https://stackoverflow.com/questions/12075927/serialization-of-regexp/22571090#22571090
would save other devs from having to use some serialization constant
(___REGEXP) in the JSON, but I could also see pitfalls there.
What are your thoughts?
…On Thu, Apr 19, 2018 at 1:49 PM Lance Gosby ***@***.***> wrote:
@gbochenek <https://github.com/gbochenek> I'm not sure exactly what you
mean. I remember trying a few different things at the time I was working
through this. Not sure why I stuck with this, but it works for us. If you
can improve on it, or make it less confusing, I would interested to see it.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#36 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AB1zZpyaT9g40yuxlD7OJQDf1CSNJ0HIks5tqM4RgaJpZM4PBvh_>
.
|
You don't need to put "__REGEXP" in your I think the problem with The replacer function wraps the RegExp string so we can undo those unwanted side effects. Unfortunately, I don't have time to create a pull request at the moment. |
Makes sense now. I need to read more carefully next time! If anyone has time, I would be happy to accept a pull request for this solution. |
@lancegosby Do you know if this work around is still needed with newer version of WAB? |
when writing the app.profile.js file, the prebuild.js script uses
JSON.stringify()
. Unfortunately this strips out any regex from the profile and replaces it with an empty object.In my _app.profile.js file, I am trying to fix the build errors thrown by moment by excluding some files from the package using the trees property. For example:
The text was updated successfully, but these errors were encountered: