Install package.json dependencies using npm. When ``build`` is True (the default), also runs ``npm run build`` to rebuild the JupyterLab extension and FigureWidget bundles and verifies that the widget bundle exists. Pass ``build=False`` when you only need to refresh ``node_modules``
(local, build=True)
| 45 | |
| 46 | |
| 47 | def install_js_deps(local, build=True): |
| 48 | """Install package.json dependencies using npm. |
| 49 | |
| 50 | When ``build`` is True (the default), also runs ``npm run build`` to |
| 51 | rebuild the JupyterLab extension and FigureWidget bundles and verifies |
| 52 | that the widget bundle exists. Pass ``build=False`` when you only need |
| 53 | to refresh ``node_modules`` / ``package-lock.json`` (e.g. after a |
| 54 | plotly.js version bump) and don't need the bundles rebuilt. |
| 55 | """ |
| 56 | |
| 57 | npmName = "npm" |
| 58 | if platform.system() == "Windows": |
| 59 | npmName = "npm.cmd" |
| 60 | |
| 61 | try: |
| 62 | check_call([npmName, "--version"]) |
| 63 | has_npm = True |
| 64 | except Exception: |
| 65 | has_npm = False |
| 66 | |
| 67 | skip_npm = os.environ.get("SKIP_NPM", False) |
| 68 | if skip_npm: |
| 69 | LOGGER.info("Skipping npm-installation") |
| 70 | return |
| 71 | |
| 72 | if not has_npm: |
| 73 | LOGGER.error( |
| 74 | "`npm` unavailable. If you're running this command using sudo, make sure `npm` is available to sudo" |
| 75 | ) |
| 76 | |
| 77 | env = os.environ.copy() |
| 78 | env["PATH"] = NPM_PATH |
| 79 | |
| 80 | if has_npm: |
| 81 | LOGGER.info("Installing build dependencies with npm. This may take a while...") |
| 82 | check_call( |
| 83 | [npmName, "install"], |
| 84 | cwd=NODE_ROOT, |
| 85 | stdout=sys.stdout, |
| 86 | stderr=sys.stderr, |
| 87 | ) |
| 88 | if local is not None: |
| 89 | plotly_archive = os.path.join(local, "plotly.js.tgz") |
| 90 | check_call( |
| 91 | [npmName, "install", plotly_archive], |
| 92 | cwd=NODE_ROOT, |
| 93 | stdout=sys.stdout, |
| 94 | stderr=sys.stderr, |
| 95 | ) |
| 96 | if build: |
| 97 | check_call( |
| 98 | [npmName, "run", "build"], |
| 99 | cwd=NODE_ROOT, |
| 100 | stdout=sys.stdout, |
| 101 | stderr=sys.stderr, |
| 102 | ) |
| 103 | os.utime(NODE_MODULES, None) |
| 104 |
no test coverage detected