| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-27 18:08:44 +02:00
										 |  |  | module Language | 
					
						
							|  |  |  |   module Node | 
					
						
							|  |  |  |     def self.npm_cache_config | 
					
						
							| 
									
										
										
										
											2017-06-26 21:47:47 +02:00
										 |  |  |       "cache=#{HOMEBREW_CACHE}/npm_cache" | 
					
						
							| 
									
										
										
										
											2016-04-27 18:08:44 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-31 04:57:28 +01:00
										 |  |  |     def self.pack_for_installation | 
					
						
							|  |  |  |       # Homebrew assumes the buildpath/testpath will always be disposable | 
					
						
							|  |  |  |       # and from npm 5.0.0 the logic changed so that when a directory is | 
					
						
							|  |  |  |       # fed to `npm install` only symlinks are created linking back to that | 
					
						
							|  |  |  |       # directory, consequently breaking that assumption. We require a tarball | 
					
						
							|  |  |  |       # because npm install creates a "real" installation when fed a tarball. | 
					
						
							| 
									
										
										
										
											2017-07-07 15:11:41 +01:00
										 |  |  |       output = Utils.popen_read("npm pack --ignore-scripts") | 
					
						
							| 
									
										
										
										
											2019-02-19 13:11:32 +00:00
										 |  |  |       raise "npm failed to pack #{Dir.pwd}" if !$CHILD_STATUS.exitstatus.zero? || output.lines.empty? | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-26 21:33:12 +02:00
										 |  |  |       output.lines.last.chomp | 
					
						
							| 
									
										
										
										
											2017-05-31 04:57:28 +01:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-27 18:08:44 +02:00
										 |  |  |     def self.setup_npm_environment | 
					
						
							| 
									
										
										
										
											2017-06-26 21:47:47 +02:00
										 |  |  |       # guard that this is only run once | 
					
						
							|  |  |  |       return if @env_set | 
					
						
							| 
									
										
										
										
											2018-09-17 02:45:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-06-26 21:47:47 +02:00
										 |  |  |       @env_set = true | 
					
						
							| 
									
										
										
										
											2016-04-27 18:08:44 +02:00
										 |  |  |       # explicitly use our npm and node-gyp executables instead of the user | 
					
						
							|  |  |  |       # managed ones in HOMEBREW_PREFIX/lib/node_modules which might be broken | 
					
						
							| 
									
										
										
										
											2017-06-19 01:26:52 +05:30
										 |  |  |       begin | 
					
						
							|  |  |  |         ENV.prepend_path "PATH", Formula["node"].opt_libexec/"bin" | 
					
						
							|  |  |  |       rescue FormulaUnavailableError | 
					
						
							|  |  |  |         nil | 
					
						
							|  |  |  |       end | 
					
						
							| 
									
										
										
										
											2016-04-27 18:08:44 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def self.std_npm_install_args(libexec) | 
					
						
							|  |  |  |       setup_npm_environment | 
					
						
							|  |  |  |       # tell npm to not install .brew_home by adding it to the .npmignore file | 
					
						
							|  |  |  |       # (or creating a new one if no .npmignore file already exists) | 
					
						
							| 
									
										
										
										
											2016-09-10 10:38:35 +01:00
										 |  |  |       open(".npmignore", "a") { |f| f.write("\n.brew_home\n") } | 
					
						
							| 
									
										
										
										
											2017-05-31 04:57:28 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |       pack = pack_for_installation | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-27 18:08:44 +02:00
										 |  |  |       # npm install args for global style module format installed into libexec | 
					
						
							| 
									
										
										
										
											2017-05-31 04:57:28 +01:00
										 |  |  |       %W[
 | 
					
						
							| 
									
										
										
										
											2017-06-26 20:28:18 +02:00
										 |  |  |         -ddd | 
					
						
							| 
									
										
										
										
											2017-05-31 04:57:28 +01:00
										 |  |  |         --global | 
					
						
							| 
									
										
										
										
											2017-06-26 20:35:48 +02:00
										 |  |  |         --build-from-source | 
					
						
							| 
									
										
										
										
											2017-06-26 21:47:47 +02:00
										 |  |  |         --#{npm_cache_config} | 
					
						
							| 
									
										
										
										
											2017-05-31 04:57:28 +01:00
										 |  |  |         --prefix=#{libexec} | 
					
						
							|  |  |  |         #{Dir.pwd}/#{pack} | 
					
						
							|  |  |  |       ] | 
					
						
							| 
									
										
										
										
											2016-04-27 18:08:44 +02:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def self.local_npm_install_args | 
					
						
							|  |  |  |       setup_npm_environment | 
					
						
							|  |  |  |       # npm install args for local style module format | 
					
						
							| 
									
										
										
										
											2017-06-26 21:47:47 +02:00
										 |  |  |       %W[
 | 
					
						
							| 
									
										
										
										
											2017-06-26 20:35:48 +02:00
										 |  |  |         -ddd | 
					
						
							|  |  |  |         --build-from-source | 
					
						
							| 
									
										
										
										
											2017-06-26 21:47:47 +02:00
										 |  |  |         --#{npm_cache_config} | 
					
						
							| 
									
										
										
										
											2017-06-26 20:35:48 +02:00
										 |  |  |       ] | 
					
						
							| 
									
										
										
										
											2016-04-27 18:08:44 +02:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |