News for hackers. Stuff that matters.
Re:The Makefile I use with JavaScript projects by athenot on Wednesday February 28, 2018 @11:30AM (#16484095)
After going through a few build systems for Javascript, I realized they were all reinventing the wheel in one way or the other, and pulled out venerable Make from the closet. It turned out to be way more expressive and easy to read.

One target to build (prod), another to run with fsevents doing auto-rebuild when a file is saved (instant gratification during dev), then a few targets for cleaup & housekeeping. All said, the file is 1/4 the size of any other JS-based build systems.

Re:The Makefile I use with JavaScript projects by bobbyi_settv on Wednesday February 28, 2018 @01:56PM (#16485637)
The reason I don't like doing this is portability. Since the steps within the makefile are going to be run through a shell, it is going to behave differently on different systems.

If your makefile fixes up a file using sed and your system has gnu sed, your makefile may fail on a system with BSD sed (e.g., a mac). If you rely on bash-isms, your makefile may not work on a debian system where it will be run with dash instead of bash. And so on.

Re:The Makefile I use with JavaScript projects by deckard1 on Wednesday February 28, 2018 @05:34PM (#16487819)
I say, you JS guys doth protest a bit too much.

If you look in your package.json, you'll surely see a dozen or so "scripts" lines that run through the same shell that make does and have all the problems you just mentioned.

I'd also like to point out that Linux and almost certainly your production environment (because it's most likely *ix) will be case sensitive. Your macOS or Windows file system? Not so much. Point is, you're already up to your neck in portability issues. My macOS coworkers often forget this detail.

Re:The Makefile I use with JavaScript projects by bobbyi_settv on Wednesday February 28, 2018 @06:39PM (#16488335)
If an external package has scripts in it, those scripts have very likely been run by somebody on a mac and somebody on linux and worked in both cases. That is totally different than writing a line of script that only you have ever run and assuming that because it works on your laptop, it will run everywhere.
Re:The Makefile I use with JavaScript projects by deckard1 on Thursday March 01, 2018 @03:37AM (#16490492)
> That is totally different than writing a line of script that only you have ever run and assuming that because it works on your laptop, it will run everywhere.

huh?? No it's not. That's the whole discussion we are having now. I even specifically mentioned my macOS coworkers who develop on their Mac and are oblivious to case-sensitivity issues. Because "it worked for me."

> If an external package has scripts in it, those scripts have very likely been run by somebody on a mac and somebody on linux and worked in both cases.

Oh, I'd love for that to be true. But also not what I was referring to. Most large projects have a "scripts" section and those are no different than Makefile commands. If you're paranoid about your own Makefiles then you're going to need to be paranoid about your own package.json.

Re:The Makefile I use with JavaScript projects by athenot on Wednesday February 28, 2018 @03:38PM (#16486646)
True but I should specify that my targets do the job in 1 to 3 lines. No magic bash.

Also, I use javascript where it makes sense: I rely on Browserify to resolve the web of `require`d files.

Re:The Makefile I use with JavaScript projects by nwmcsween on Wednesday February 28, 2018 @10:39PM (#16489492)
You don't shell out complex crap in a makefile, create a configure script and pass vars
Re:The Makefile I use with JavaScript projects by wainstead on Wednesday February 28, 2018 @10:33PM (#16489463)
Doesn’t autoconf address these issues?
Re:The Makefile I use with JavaScript projects by IshKebab on Wednesday February 28, 2018 @12:10PM (#16484562)
Wow if you consider Makefiles easy to read...
Re:The Makefile I use with JavaScript projects by bpicolo on Wednesday February 28, 2018 @12:14PM (#16484601)
Simple makefiles couldn't be more simple.

    task: dependency
        list of
        commands

That's about as easy as it gets.
Re:The Makefile I use with JavaScript projects by matheusmoreira on Thursday March 01, 2018 @08:50AM (#16491932)
Real world makefiles are not simple like this. The simplest makefile I can think of is still hundreds of lines long:

https://git.musl-libc.org/cgit/musl/tree/Makefile

Re:The Makefile I use with JavaScript projects by creatornator on Thursday March 01, 2018 @05:27PM (#16496976)
Maybe this isn't "real-world" but I've made this cookiecutter template which generates projects with Makefiles less than 100 lines. It works decently well for my personal projects and for playing around. https://github.com/MatanSilver/cookiecutter-cproj
Re:The Makefile I use with JavaScript projects by bitwize on Wednesday February 28, 2018 @12:36PM (#16484831)
Until a stray space finds its way into your command list indentation...
Re:The Makefile I use with JavaScript projects by bpicolo on Wednesday February 28, 2018 @12:46PM (#16484936)
Every popular text editor handles this already. People manage make, python and other whitespace-specified languages just fine.
Re:The Makefile I use with JavaScript projects by emmelaich on Wednesday February 28, 2018 @12:57PM (#16485042)
They don't though. Vanilla Vim/Vi doesn't for instance.

Regardless of whether the editor can or not, I just don't see how insisting on tab and not space is remotely defensible.

Re:The Makefile I use with JavaScript projects by deathanatos on Wednesday February 28, 2018 @01:13PM (#16485194)
> Vanilla Vim/Vi doesn't for instance.

Vim does handle this. Here is Vim (and I've removed my .vimrc file, so this is not a setting I have set personally), on a Makefile where the third line erroneously uses spaces:

https://i.imgur.com/xMHXeL4.png

> I just don't see how insisting on tab and not space is remotely defensible.

This is like insisting that people haven't been having religious wars over this sort topic for years. You can see the Wiki[1] page on it (which starts "This is one of the eternal Holy Wars") for arguments as to why someone might prefer tabs. I personally like them because they allow the reader of the code to choose the visual layout of the indentation.

Now, while I love tabs, I work in Python all day. But good editors, like Vim, allow you to customize the indentation settings sufficiently to handle both cases like Python (spaces for indent) and Makefile (tabs) gracefully. So "Indent" and "Dedent" just do The Right Thing™ and it mostly never matters.

[1]: http://wiki.c2.com/?TabsVersusSpaces

Re:The Makefile I use with JavaScript projects by travmatt on Wednesday February 28, 2018 @01:36PM (#16485427)
If someone is really paranoid about white space issues in a file you’re editing on vim, you can can always use `:set list` to display those characters.
Re:The Makefile I use with JavaScript projects by enriquto on Wednesday February 28, 2018 @04:11PM (#16486964)
or, you can write your recipes as

    target : requisites ; recipe
with a semicolon instead of a tab.

However, tabs are beautiful, and every occasion to use them should be cherised as precious.

Re:The Makefile I use with JavaScript projects by emmelaich on Wednesday February 28, 2018 @09:38PM (#16489240)
I'm glad it works for you. It didn't work for me.
Re:The Makefile I use with JavaScript projects by bpicolo on Wednesday February 28, 2018 @01:09PM (#16485155)
https://stackoverflow.com/a/29787362

> remotely defensible

Feel free to write your own make superset that supports spaces. It's an irrelevant factor to the usability of make as a whole.

Re:The Makefile I use with JavaScript projects by emmelaich on Wednesday February 28, 2018 @09:39PM (#16489243)
It's something that almost everyone trips over.

Multiple times.

Actually writing a preprocessor for Make sounds like a pretty good idea.

Re:The Makefile I use with JavaScript projects by voltagex_ on Wednesday February 28, 2018 @11:48PM (#16489745)
ninja, cmake, premake.
Re:The Makefile I use with JavaScript projects by swsieber on Wednesday February 28, 2018 @03:18PM (#16486418)
FWIW, the more experienced a programmer is, the more likely they are to prefer spaces over tabs.

My pet theory is that the more experience you have, the more likely you are to have worked with Python, which is a lot easier to work with if you just always s/\t/ / (replace tabs with spaces).

Re:The Makefile I use with JavaScript projects by gnclmorais on Wednesday February 28, 2018 @12:13PM (#16484593)
I’ve written about Makefiles for the web before, you can’t say they can’t be readable: http://blog.gnclmorais.com/makefiles-are-for-the-web
Re:The Makefile I use with JavaScript projects by jorams on Wednesday February 28, 2018 @04:00PM (#16486857)
Something about the Makefile in your post is a bit weird though: You only declare "test" as a PHONY target, but every other target in the file is just as PHONY. And since you don't even explain that line, it could be a bit confusing.
Re:The Makefile I use with JavaScript projects by tachyoff on Wednesday February 28, 2018 @12:23PM (#16484706)
It's certainly better than the 200+ lines of JavaScript something like Webpack spits out when you statr a new project. I had to debug some of our project's build files and realized halfway through that my teammates didn't write this Webpack config monstrosity, Webpack generated it by /default/.
Re:The Makefile I use with JavaScript projects by acemarke on Wednesday February 28, 2018 @12:46PM (#16484941)
Webpack, by itself, doesn't generate configs, unless you're referring to the Webpack CLI tool.

FWIW, Webpack 4 (which just went final a few days ago) now has "zero-config" defaults out of the box. You may want to give that a shot.

Re:The Makefile I use with JavaScript projects by tachyoff on Wednesday February 28, 2018 @03:21PM (#16486442)
Eh, I tend towards “let’s not touch this if it works”. I’ve already had to upgrade from Webpack 1 to 2, and 2 to 3. If it ain’t broke, don’t fix it.
Re:The Makefile I use with JavaScript projects by acemarke on Thursday March 01, 2018 @12:43PM (#16494245)
Sure, I can sympathize. That said, I've seen a bunch of "here's my results after upgrading to Webpack 4" tweets going around, and they all indicate much faster builds and somewhat smaller bundle sizes, with very minimal config changes needed.
Re:The Makefile I use with JavaScript projects by megaman22 on Wednesday February 28, 2018 @12:31PM (#16484789)
Next to a non-toy webpack or gulp configuration, makefiles are pretty clean and simple.
Re:The Makefile I use with JavaScript projects by fiatjaf on Wednesday February 28, 2018 @02:18PM (#16485840)
Not to mention that gulp, grunt (do people still use this?) and webpack configs are written in JavaScript, so they're likely to have very hard to debug errors in them on the first 5 revisions.
Re:The Makefile I use with JavaScript projects by lpghatguy on Wednesday February 28, 2018 @02:27PM (#16485931)
The errors shouldn't be any harder to debug than the program itself after 5 revisions.