Эх сурвалжийг харах

Fix #35: make startup issues the user's problem, but give advice

George S. Baugh 4 жил өмнө
parent
commit
7afbf2e9b2
6 өөрчлөгдсөн 32 нэмэгдсэн , 46 устгасан
  1. 3 0
      Changes
  2. 1 1
      README.md
  3. 4 17
      bin/playwright_server
  4. 1 1
      dist.ini
  5. 1 1
      example.pl
  6. 22 26
      lib/Playwright.pm

+ 3 - 0
Changes

@@ -1,5 +1,8 @@
 Revision history for Playwright
 
+0.011 2021-07-27 TEODESIAN
+    - Make no attempts whatsoever to install node deps for users, instead giving them advice how to self-service fix their problems.
+
 0.010 2021-07-27 TEODESIAN
     - Fix issue with yargs fix breaking invocation in Playwright.pm
     - Fix issue with child selectors being broken

+ 1 - 1
README.md

@@ -48,7 +48,7 @@ dzil listdeps --missing | sudo cpanm
 
 Actually running stuff:
 
-`perl -Ilib example.pl`
+`PATH="$(cwd)/bin:$PATH" perl -Ilib example.pl`
 
 ## Dealing with api.json
 

+ 4 - 17
bin/playwright_server

@@ -7,23 +7,10 @@ const { exit } = require('process');
 const fs = require('fs');
 const path = require('path');
 
-// Don't explode, but be helpful when we have unsatisfied deps
-try {
-    if (process.env.NODE_PATH) {
-        // Let users override in the event they have to
-        require(process.env.NODE_PATH + '/uuid');
-        require(process.env.NODE_PATH + '/playwright');
-        require(process.env.NODE_PATH + '/express');
-    } else {
-        // Assume their kit is good
-        require('uuid');
-        require('playwright');
-        require('express');
-    }
-} catch {
-    console.log("Required dependencies are not installed. Cannot continue, run `npm i` to fix.");
-    exit(1);
-}
+// Assume their kit is good
+require('uuid');
+require('playwright');
+require('express');
 
 // Get what we actually want from our deps
 const { v4 : uuidv4 } = require('uuid');

+ 1 - 1
dist.ini

@@ -1,5 +1,5 @@
 name = Playwright
-version = 0.010
+version = 0.011
 author = George S. Baugh <george@troglodyne.net>
 license = MIT
 copyright_holder = Troglodyne LLC

+ 1 - 1
example.pl

@@ -10,7 +10,7 @@ use Try::Tiny;
 my $handle = Playwright->new( debug => 1 );
 
 # Open a new chrome instance
-my $browser = $handle->launch( headless => 0, type => 'firefox' );
+my $browser = $handle->launch( headless => 1, type => 'firefox' );
 
 # Open a tab therein
 my $page = $browser->newPage({ videosPath => 'video', acceptDownloads => 1 });

+ 22 - 26
lib/Playwright.pm

@@ -71,7 +71,7 @@ See example.pl for a more thoroughly fleshed-out display on how to use this modu
 
 =head3 Getting Started
 
-When using the playwright module for the first time, you may be told to install dependencies.
+When using the playwright module for the first time, you may be told to install node.js libraries.
 It should provide you with instructions which will get you working right away.
 
 However, depending on your node installation this may not work due to dependencies for node.js not being in the expected location.
@@ -209,43 +209,39 @@ sub _check_node {
     $node_bin = File::Which::which('node');
     confess("node must exist, be in your PATH and executable") unless $node_bin && -x $node_bin;
 
-    my $global_install = '';
     my $path2here = File::Basename::dirname( Cwd::abs_path( $INC{'Playwright.pm'} ) );
 
     # Make sure it's possible to start the server
-    $server_bin = "$path2here/../bin/playwright_server";
-    if (!-f $server_bin ) {
-        $server_bin = File::Which::which('playwright_server');
-        $global_install = 1;
-    }
-    confess("Can't locate Playwright server in '$server_bin'!")
-      unless -f $server_bin;
+    $server_bin = File::Which::which('playwright_server');
+    confess("Can't locate playwright_server!
+    Please ensure it is installed in your PATH.
+    If you installed this module from CPAN, it should already be.")
+      unless $server_bin && -x $server_bin;
 
     # Attempt to start the server.  If we can't do this, we almost certainly have dependency issues.
     my ($output) = capture_merged { system($node_bin, $server_bin, '--check') };
     return if $output =~ m/OK/;
 
-    # Check for the necessary modules, this relies on package.json
-    my $npm_bin = File::Which::which('npm');
-    confess("npm must exist and be executable") unless -x $npm_bin;
+    warn $output;
 
-    # pushd/popd closure
-    {
-        my $curdir = pushd(File::Basename::dirname($server_bin));
+    confess( "playwright_server could not run successfully.
+    See the above error message for why.
+    It's likely to be unmet dependencies, or a NODE_PATH issue.
 
-        # Attempt to install deps automatically.
-        confess("Production install of node dependencies must be done manually by nonroot users. Run the following:\n\n pushd '$curdir' && sudo npm i yargs express playwright uuid; popd\n\nIf this doesn't resolve the issue, export NODE_PATH='$curdir/node_modules'.") if $global_install;
+    Install of node dependencies must be done manually.
+    Run the following:
 
-        my $err  = capture_stderr { qx{npm i} };
-        # XXX apparently doing it 'once more with feeling' fixes issues on windows, lol
-        $err     = capture_stderr { qx{npm i} };
-        my $exit = $? >> 8;
+    npm i express playwright uuid
+    sudo npx playwright install-deps
+    export NODE_PATH=\"\$(pwd)/node_modules\".
+
+    If you still experience issues, run the following:
+
+    NODE_DEBUG=module playwright_server --check
+
+    This should tell you why node can't find the deps you have installed.
+    ");
 
-        # Ignore failing for bogus reasons
-        if ( $err !~ m/package-lock/ ) {
-            confess("Error installing node dependencies:\n$err") if $exit;
-        }
-    }
 }
 
 sub _build_classes {