MCPcopy Create free account
hub / github.com/microsoft/SandDance / install_npm

Function install_npm

python/jupyter-widget/setupbase.py:323–379  ·  view source on GitHub ↗

Return a Command for managing an npm installation. Note: The command is skipped if the `--skip-npm` flag is used. Parameters ---------- path: str, optional The base path of the node package. Defaults to the repo root. build_dir: str, optional The target build d

(path=None, build_dir=None, source_dir=None, build_cmd='build', force=False, npm=None)

Source from the content-addressed store, hash-verified

321
322
323def install_npm(path=None, build_dir=None, source_dir=None, build_cmd='build', force=False, npm=None):
324 """Return a Command for managing an npm installation.
325
326 Note: The command is skipped if the `--skip-npm` flag is used.
327
328 Parameters
329 ----------
330 path: str, optional
331 The base path of the node package. Defaults to the repo root.
332 build_dir: str, optional
333 The target build directory. If this and source_dir are given,
334 the JavaScript will only be build if necessary.
335 source_dir: str, optional
336 The source code directory.
337 build_cmd: str, optional
338 The npm command to build assets to the build_dir.
339 npm: str or list, optional.
340 The npm executable name, or a tuple of ['node', executable].
341 """
342
343 class NPM(BaseCommand):
344 description = 'install package.json dependencies using npm'
345
346 def run(self):
347 if skip_npm:
348 log.info('Skipping npm-installation')
349 return
350 node_package = path or HERE
351 node_modules = pjoin(node_package, 'node_modules')
352 is_yarn = os.path.exists(pjoin(node_package, 'yarn.lock'))
353
354 npm_cmd = npm
355
356 if npm is None:
357 if is_yarn:
358 npm_cmd = ['yarn']
359 else:
360 npm_cmd = ['npm']
361
362 if not which(npm_cmd[0]):
363 log.error("`{0}` unavailable. If you're running this command "
364 "using sudo, make sure `{0}` is available to sudo"
365 .format(npm_cmd[0]))
366 return
367
368 if force or is_stale(node_modules, pjoin(node_package, 'package.json')):
369 log.info('Installing build dependencies with npm. This may '
370 'take a while...')
371 run(npm_cmd + ['install'], cwd=node_package)
372 if build_dir and source_dir and not force:
373 should_build = is_stale(build_dir, source_dir)
374 else:
375 should_build = True
376 if should_build:
377 run(npm_cmd + ['run', build_cmd], cwd=node_package)
378
379 return NPM
380

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected