Closed viT-1 closed 4 years ago
Same issue but not my variant https://github.com/shelljs/shx/issues/165
This looks like a dupe of #165. Single quotes don't work the same on Windows. Please ping this thread if I've misunderstood.
@nfischer No, I'm searching text contains single quotes.
At a glance, your code looks like it should work in that case (although I'm not sure if dist/*.js
needs to be dist\*.js
on Windows).
Which OS did you try this on?
@nfischer Yeah, I'm trying on Windows. Tried simple change 'foo'
to 'bar'
, dist\*.js
path is correct.
I think you need to escape the /
characters in your replacement string, otherwise sed
treats them as special delimiters. This behavior is consistent with unix sed:
# Failing to escape quotes in unix sed would fail like so:
sed -i "s/'vue'/'https://cccdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.esm.browser.js'/g" dist/*.js
sed: -e expression #1, char 17: unknown option to `s'
You should escape the characters with a "\" in the commandline like so:
# Escape '/' characters so sed doesn't treat them specially anymore:
shx sed -i "s/'vue'/'https:\/\/cdn.jsdelivr.net\/npm\/vue@2.6.10\/dist\/vue.esm.browser.js'/g" dist/*.js
# The same is necessary for unix sed:
sed -i "s/'vue'/'https:\/\/cdn.jsdelivr.net\/npm\/vue@2.6.10\/dist\/vue.esm.browser.js'/g" dist/*.js
To use this in a package.json
, you need double \
so JSON passes a single \
onto shx
:
{
"scripts": {
"resolvevue": "shx sed -i \"s/'vue'/'https:\\/\\/cdn.jsdelivr.net\\/npm\\/vue@2.6.10\\/dist\\/vue.esm.browser.js'/g\" dist/*.js"
}
}
Updating labels. I don't think this is Win-specific, and it's clear this is not really a duplicate of issue #165 despite the similar error message.
Yes! This (in package.json) works:
shx sed -i \"s/'vue'/'https:\\/\\/cdn.jsdelivr.net\\/npm\\/vue@2.6.10\\/dist\\/vue.esm.browser.js'/g\" dist/*.js
@nfischer Please, add this to documentation.
can't
npm run resolvevue
package.json: