瀏覽代碼

Allow ability to specify NODE_PATH

George S. Baugh 4 年之前
父節點
當前提交
4a0a7c5e37
共有 3 個文件被更改,包括 22 次插入4 次删除
  1. 2 0
      Changes
  2. 11 3
      bin/playwright_server
  3. 9 1
      lib/Playwright.pm

+ 2 - 0
Changes

@@ -2,6 +2,8 @@ Revision history for Playwright
 
 0.010 2021-07-27 TEODESIAN
     - Fix issue with yargs fix breaking invocation in Playwright.pm
+    - Fix issue with child selectors being broken
+    - Add ability to specify library path
 
 0.009 2021-07-26 TEODESIAN
     - Remove dependency on yargs in bin/playwright_server

+ 11 - 3
bin/playwright_server

@@ -9,9 +9,17 @@ const path = require('path');
 
 // Don't explode, but be helpful when we have unsatisfied deps
 try {
-    require('uuid');
-    require('playwright');
-    require('express');
+    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);

+ 9 - 1
lib/Playwright.pm

@@ -69,6 +69,14 @@ All the classes mentioned there will correspond to a subclass of the Playwright
 
 See example.pl for a more thoroughly fleshed-out display on how to use this module.
 
+=head3 Getting Started
+
+When using the playwright module for the first time, you may be told to install dependencies.
+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.
+To fix this, you will need to update your NODE_PATH environment variable to point to the correct location.
+
 =head3 Questions?
 
 Feel free to join the Playwright slack server, as there is a dedicated #playwright-perl channel which I, the module author, await your requests in.
@@ -226,7 +234,7 @@ sub _check_node {
         my $curdir = pushd(File::Basename::dirname($server_bin));
 
         # 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\n") if $global_install;
+        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;
 
         my $err  = capture_stderr { qx{npm i} };
         # XXX apparently doing it 'once more with feeling' fixes issues on windows, lol