|
| 1 | +"""sanity checks for webpack vs python packaging""" |
| 2 | +import subprocess |
| 3 | +import sys |
| 4 | +from pathlib import Path |
| 5 | + |
| 6 | +ROOT = Path(__file__).parent.parent |
| 7 | + |
| 8 | +# known packages that cause problems if vendored in webpack |
| 9 | +BAD_CHUNK_PATTERNS = { |
| 10 | + ( |
| 11 | + "codemirror_codemirror", |
| 12 | + "codemirror_lib", |
| 13 | + ): """ |
| 14 | + Please ensure is CodeMirror is imported by type, e.g. |
| 15 | +
|
| 16 | + import type * as CodeMirror from 'codemirror' |
| 17 | +
|
| 18 | + see https://github.com/krassowski/jupyterlab-lsp/issues/575 |
| 19 | + """ |
| 20 | +} |
| 21 | + |
| 22 | +# canary file created by a debug build |
| 23 | +BUILD_LOG = "build_log.json" |
| 24 | + |
| 25 | +# where the packages are |
| 26 | +PY_PACKAGES = ROOT / "python_packages" |
| 27 | + |
| 28 | +# just one, for now |
| 29 | +LABEXTENSION_PATHS = [ |
| 30 | + "jupyterlab_lsp/jupyterlab_lsp/labextensions/@krassowski/jupyterlab-lsp" |
| 31 | +] |
| 32 | + |
| 33 | + |
| 34 | +def check_webpack(): |
| 35 | + """verify certain packages would not be bundled |
| 36 | +
|
| 37 | + this it to avoid distributing private copies of modules |
| 38 | + """ |
| 39 | + for path in LABEXTENSION_PATHS: |
| 40 | + build_log = PY_PACKAGES / path / BUILD_LOG |
| 41 | + print("checking for", build_log) |
| 42 | + if not build_log.exists(): |
| 43 | + print(build_log, "missing, doing verbose debug build") |
| 44 | + subprocess.check_call(["jlpm", "lerna", "run", "build:labextension:dev"]) |
| 45 | + break |
| 46 | + |
| 47 | + bad = [] |
| 48 | + good = 0 |
| 49 | + |
| 50 | + for path in LABEXTENSION_PATHS: |
| 51 | + for asset in (PY_PACKAGES / path / "static").rglob("*.js"): |
| 52 | + for patterns, msg in BAD_CHUNK_PATTERNS.items(): |
| 53 | + for pattern in patterns: |
| 54 | + if pattern in str(asset): |
| 55 | + print(">>> Found", pattern, "in", asset, "\n", msg) |
| 56 | + bad += [asset] |
| 57 | + if asset not in bad: |
| 58 | + good += 1 |
| 59 | + |
| 60 | + if not good: |
| 61 | + print("didn't find any js assets, probably broken") |
| 62 | + return 1 |
| 63 | + |
| 64 | + print(f"{good} assets looked good vs", sum(BAD_CHUNK_PATTERNS.keys(), tuple())) |
| 65 | + |
| 66 | + if bad: |
| 67 | + print(f"{bad} assets appear to be on the bad list", BAD_CHUNK_PATTERNS) |
| 68 | + |
| 69 | + return len(bad) |
| 70 | + |
| 71 | + |
| 72 | +if __name__ == "__main__": |
| 73 | + sys.exit(check_webpack()) |
0 commit comments