40 Commits

Author SHA1 Message Date
Carlo Cabrera
6a7416c296
language/*: fix *_SHEBANG_REGEX anchors
We should use `\A` to pick up shebangs at the start of files instead of
just anywhere in a given script.

See Homebrew/homebrew-core#227654 for an example where this can cause
problems.
2025-06-23 20:32:55 +08:00
botantony
dac4b6fd56
shebangs: fix broken shebangs like #!python
Signed-off-by: botantony <antonsm21@gmail.com>
2025-03-21 00:34:14 +01:00
Bo Anderson
6db4ed2793
Replace some include Kernel usages with requires_ancestor 2024-08-20 19:10:14 +01:00
Mike McQuaid
debdc30aa0
language/*: only check required deps in detected_*_shebang
Otherwise, we rewrite this even when we have a e.g. build or test
dependency on NodeJS.

See context in:
https://github.com/Homebrew/homebrew-core/issues/176257#issuecomment-2277602215
2024-08-09 14:08:29 +01:00
Branch Vincent
4bf8fef5aa
Reapply "formula: configure git/npm to ignore .brew_home"
This reverts commit abf8df38661c4b60f122336d3db3a1a810d3a0e8.
2024-04-23 18:35:55 -07:00
Mike McQuaid
abf8df3866
Revert "formula: configure git/npm to ignore .brew_home" 2024-04-23 16:09:57 +01:00
Branch Vincent
46a3bbe3c5
formula: configure git/npm to ignore .brew_home 2024-04-19 11:45:25 -07:00
Michael Cho
fb5306fc35
language/node: enable typed: strict
Signed-off-by: Michael Cho <michael@michaelcho.dev>
2024-03-29 20:13:52 -04:00
Issy Long
f682147598
Fix RuboCop Style/RedundantFreeze offenses 2024-01-18 22:20:01 +00:00
Douglas Eichelberger
0191af7899 resolve typecheck errors 2023-11-05 08:55:58 -08:00
Sam Ford
d1297c0974
node: add shebang rewriting
Formulae that depend on `node` sometimes contain files that use a
shebang like `#!/usr/bin/env node` and this can lead to issues when
the `node` in a user's environment isn't brewed `node`.

For example, some node modules are compiled when the formula is built
but if the user's `node` is a different major version than brew's
`node`, the differing `NODE_MODULE_VERSION` can produce an error when
certain parts of the application are used. The formula may build and
test fine and the issue may only become apparent when more of the
application is exercised.

This adds a `Language::Node::Shebang` module (borrowing from the
existing Perl and Python examples), which allows us to use
`rewrite_shebang detected_node_shebang, ...` in formulae to address
this type of issue.
2023-08-15 00:53:41 -04:00
Douglas Eichelberger
24cf6076e8 brew style --fix 2023-04-24 20:42:39 -07:00
Bo Anderson
4c4ed598df
language/node: also strip postpack 2022-06-14 08:56:04 +01:00
Bo Anderson
20ff68a425
Fix brew style. 2021-03-17 20:45:44 +00:00
Markus Reiter
5be4c9b5e0 Upgrade typed sigils. 2020-11-25 17:04:19 +01:00
Markus Reiter
da9289eff0 Add more type signatures. 2020-11-13 12:26:36 +01:00
Dustin Rodrigues
f9a15e7443
Update Library/Homebrew/language/node.rb
Co-authored-by: Mike McQuaid <mike@mikemcquaid.com>
2020-11-06 06:40:50 -05:00
Dustin Rodrigues
c062429ddd language/node: remove unneeded scripts prior to installation 2020-11-05 21:10:51 -05:00
Diogo Azevedo
35a7e336be
node: add support for npm 7
Co-Authored-By: Mike McQuaid <mike@mikemcquaid.com>
2020-10-24 15:26:36 +02:00
Markus Reiter
24ae318a3d Move type annotations into files. 2020-10-10 14:59:39 +02:00
Markus Reiter
d50faba744 Document Language::Node. 2020-08-26 03:13:58 +02:00
Dawid Dziurla
aac200a53d
node: detect root via Process.uid 2020-02-28 13:37:44 +01:00
Dawid Dziurla
79a1500f2b
node: add --unsafe-perm to std_args only if run as root 2020-02-28 13:00:43 +01:00
Dawid Dziurla
6874c79375
node: add --unsafe-perm to std_args 2020-02-28 12:47:03 +01:00
Mike McQuaid
36dbad3922
Add frozen_string_literal to all files. 2019-04-20 13:27:36 +09:00
Mike McQuaid
d64429a736
rubocop: enable Style/IfUnlessModifier. 2019-02-21 12:55:49 +00:00
Markus Reiter
e9b9ea49a1 Update to RuboCop 0.59.1. 2018-09-17 03:45:59 +02:00
Mike McQuaid
9f6762d958 language/node: general cleanup.
- Avoid using a temporary variable where not necessary
- Use fewer, better stubs in the tests to avoid warnings and better
  test the implemented functionality.
2017-07-07 15:11:41 +01:00
Christian Moritz
5e00c277ce partly revert log verbose npm pack output commit
to fix issues with shwoing npm debug output even on non-verbose install runs.
2017-06-30 00:55:34 +02:00
Christian Moritz
6baea2543a language/node: set cache config via argument
instead of writing a .npmrc file, which simplifies the code.
npm_cache_config is still preserved for backwarts compatiblility and
usage int he kibana@n formulas in core.
2017-06-29 20:29:25 +02:00
Christian Moritz
466fe9841a language/node: npm pack ignore prepublish scripts
This tells npm pack to don't run prepublish scripts at all.
I think this is the best default because:
* most modules don't have a prepublish script at all and aren't affected
  by this change
* most prepublish scripts are calling devDeps, which would fail in our
  case, because (dev)Deps aren't installed at npm pack time until #2820
  gets resolved
* we favor npm registry tarball for formula downloads, which are already
  prepublished, so we would in the best case needlessly run prepublish
  a second time and in the worst case it would fail (because a clean
  step is required before running prepublish a second time in a row)
* This change does the right thing for >99% of all the packages and
  would only affect packages with prepublish scripts downloaded from a
  non-npm registry tarball (like github tarballs) and with a prepublish
  script wich does no't require any devDep (unlike for cross platform)
2017-06-29 20:29:25 +02:00
Christian Moritz
fe39dbb78c language/node: log verbose npm pack output
This makes npm pack to log verbose debug output to the console to
simplify debugging npm pack failures.
Refs: https://github.com/Homebrew/brew/pull/2820#discussion_r123890729
Prevously Utils.popen_read swallowed all debug output.
2017-06-29 20:29:25 +02:00
Christian Moritz
495520a1f9 language/node: make packname detection more robust
This fixes some edge cases where verbose output from a prepublish script
could break our npm pack package name detection code by only using the
last line of the output printed by npm itself containing the desired
package name.
2017-06-29 20:29:25 +02:00
Christian Moritz
02113e2714 language/node: build native addons from source
By telling node-pre-gyp and prebuild to don't pull prebuild binaries and
instead build them from source. This still may not work for some custom
third party scripts for pulling prebuild binaries.
2017-06-29 20:29:25 +02:00
Christian Moritz
7d8124f339 language/node: set npm loglevel to max -ddd
to match the loglevel used in npm_debug.log (previous --verbose loglevel
would match -dd)
2017-06-29 20:29:25 +02:00
mansimarkaur
f8f239686d Added rescue FormulaUnavailableError to setup_npm_environment 2017-06-23 03:40:03 +05:30
Mike McQuaid
021cef4b2b Autocorrect Rubocop Style/SpecialGlobalVars. 2017-06-12 09:11:42 +01:00
Dominyk Tiller
b6d81359f0
language/node: adjustments for npm 5.0.x
Goes with: https://github.com/Homebrew/homebrew-core/pull/14085
2017-06-01 21:45:26 +01:00
Mike McQuaid
bde8d69d6e language/node: fix Rubocop warnings. 2016-09-10 10:39:59 +01:00
Christian Moritz
bc98fd3788 Language::Node.npm_install_args: add helper method (#37)
* add Language::Node helper module

This adds a language module for Node module based formulas.
It contains the 2 public methods `std_npm_install_args(libexec)` and
`local_npm_install_args`:

* `std_npm_install_args` is intended to be used in formulas for
  standard node modules and returns `npm install` args for a global
  style module installation to libexec.
* `local_npm_install_args` is for formulas, in which the `npm install`
  step is only one of multiple parts of the installation process and
  returns `npm install` args for a default local installation in place.

Both methods have in common, that they are

* making sure that a working copy of npm and node-gyp from node's
  libexec is prepended to the PATH (to not rely of a user managed npm)
* seting the npm cache to HOMEBREW_CACHE/npm, which fixes issues caused
  by overriding $HOME resulting in long install times + high disk usage
  (see https://github.com/Homebrew/brew/pull/37#issuecomment-208840366)

* audit: update npm install check for Language::Node

* cleanup: remove npm_cache too

* doc: add Node-for-Formula-Authors.md
2016-04-27 17:08:44 +01:00