Thursday, 18 May 2017

Replace a line of code in a file with a cli npm package

It is known that there is a messed up crossfilter dependency within dcjs when using webpack (or in my case, angular-cli which uses webpack). This can be "fixed" through a webpack configuration change, but that's not an option with the CLI.

However, the dependency issue in dc can be fixed by editing this line in dcjs:

define(["d3", "crossfilter"], _dc);

with this:

define(["d3", "crossfilter2"], _dc);

I'm trying to set this up as a postinstall script in my package.json so the developers on my team don't have to change this line manually every time we reinstall node_modules (or add new team members).

I've tried replace and replace-in-file, which has led me so far to something like this:

replace-in-file "define([\"d3\", \"crossfilter\"], _dc);" "define([\"d3\", \"crossfilter2\"], _dc);" "node_modules/dc/dc.js" [--isRegex]

However, it just dumps out "no files were changed" without telling me why. I'm guessing it's either not able to find the file I'm referring to, or that it can't find the line I'm trying to change.

So how can I accomplish this?



via Alex Kibler

No comments:

Post a Comment