From 2f5efe9a75b9ecfd139c51f15480b09a723328b6 Mon Sep 17 00:00:00 2001 From: Nicholas Bollweg Date: Tue, 12 Dec 2023 16:32:56 -0600 Subject: [PATCH] add patch_package_jsons --- docs/_static/jupyak-v0.schema.json | 46 ++++++++++++++++++++++++ docs/_static/jupyak-v0.schema.toml | 44 +++++++++++++++++++++++ docs/_static/jupyak-v0.schema.yaml | 34 ++++++++++++++++++ jupyak_config.toml | 3 ++ src/jupyak/tasks/_js.ipynb | 34 +++++++++++++++++- src/jupyak/tasks/_yak.ipynb | 57 +++++++++++++++++++++++++++--- 6 files changed, 213 insertions(+), 5 deletions(-) diff --git a/docs/_static/jupyak-v0.schema.json b/docs/_static/jupyak-v0.schema.json index a837d29..96265cd 100644 --- a/docs/_static/jupyak-v0.schema.json +++ b/docs/_static/jupyak-v0.schema.json @@ -1207,6 +1207,14 @@ "type": "string" } }, + "patch_package_jsons": { + "type": "object", + "title": "patch_package_jsons", + "description": "patches to package.json to help resolvability", + "additionalProperties": { + "$ref": "#/$defs/PackageJsonPatches" + } + }, "tasks": { "type": "object", "title": "tasks", @@ -1260,6 +1268,44 @@ } } }, + "PackageJsonPatches": { + "title": "PackageJsonPatches", + "description": "a subset of package.json", + "properties": { + "dependencies": { + "type": "object", + "title": "dependencies", + "description": "dependencies to add before linking", + "additionalProperties": { + "type": "string" + } + }, + "dev_dependencies": { + "type": "object", + "title": "dev_dependencies", + "description": "development dependencies to add before linking", + "additionalProperties": { + "type": "string" + } + }, + "resolutions": { + "type": "object", + "title": "resolutions", + "description": "resolutions to add before linking", + "additionalProperties": { + "type": "string" + } + }, + "scripts": { + "type": "object", + "title": "scripts", + "description": "scripts to overload to avoid bad effects", + "additionalProperties": { + "type": "string" + } + } + } + }, "PythonOptions": { "title": "PythonOptions", "description": "Python-related provisioning, building, and linking.", diff --git a/docs/_static/jupyak-v0.schema.toml b/docs/_static/jupyak-v0.schema.toml index 165cd7d..49da093 100644 --- a/docs/_static/jupyak-v0.schema.toml +++ b/docs/_static/jupyak-v0.schema.toml @@ -1182,6 +1182,14 @@ description = "regular expressions for the npm `@org/pkg` names that should _not ["$defs".JSOptions.properties.link_exclude_patterns.items] type = "string" +["$defs".JSOptions.properties.patch_package_jsons] +type = "object" +title = "patch_package_jsons" +description = "patches to package.json to help resolvability" + +["$defs".JSOptions.properties.patch_package_jsons.additionalProperties] +"$ref" = "#/$defs/PackageJsonPatches" + ["$defs".JSOptions.properties.tasks] type = "object" title = "tasks" @@ -1225,6 +1233,42 @@ type = "string" title = "gist" description = "a gist ID on GitHub to use as JupyterLite contents and config" +["$defs".PackageJsonPatches] +title = "PackageJsonPatches" +description = "a subset of package.json" + +["$defs".PackageJsonPatches.properties.dependencies] +type = "object" +title = "dependencies" +description = "dependencies to add before linking" + +["$defs".PackageJsonPatches.properties.dependencies.additionalProperties] +type = "string" + +["$defs".PackageJsonPatches.properties.dev_dependencies] +type = "object" +title = "dev_dependencies" +description = "development dependencies to add before linking" + +["$defs".PackageJsonPatches.properties.dev_dependencies.additionalProperties] +type = "string" + +["$defs".PackageJsonPatches.properties.resolutions] +type = "object" +title = "resolutions" +description = "resolutions to add before linking" + +["$defs".PackageJsonPatches.properties.resolutions.additionalProperties] +type = "string" + +["$defs".PackageJsonPatches.properties.scripts] +type = "object" +title = "scripts" +description = "scripts to overload to avoid bad effects" + +["$defs".PackageJsonPatches.properties.scripts.additionalProperties] +type = "string" + ["$defs".PythonOptions] title = "PythonOptions" description = "Python-related provisioning, building, and linking." diff --git a/docs/_static/jupyak-v0.schema.yaml b/docs/_static/jupyak-v0.schema.yaml index 3ab05bf..4a3fdf3 100644 --- a/docs/_static/jupyak-v0.schema.yaml +++ b/docs/_static/jupyak-v0.schema.yaml @@ -905,6 +905,12 @@ $defs: into this repo items: type: string + patch_package_jsons: + type: object + title: patch_package_jsons + description: patches to package.json to help resolvability + additionalProperties: + $ref: '#/$defs/PackageJsonPatches' tasks: type: object title: tasks @@ -939,6 +945,34 @@ $defs: type: string title: gist description: a gist ID on GitHub to use as JupyterLite contents and config + PackageJsonPatches: + title: PackageJsonPatches + description: a subset of package.json + properties: + dependencies: + type: object + title: dependencies + description: dependencies to add before linking + additionalProperties: + type: string + dev_dependencies: + type: object + title: dev_dependencies + description: development dependencies to add before linking + additionalProperties: + type: string + resolutions: + type: object + title: resolutions + description: resolutions to add before linking + additionalProperties: + type: string + scripts: + type: object + title: scripts + description: scripts to overload to avoid bad effects + additionalProperties: + type: string PythonOptions: title: PythonOptions description: Python-related provisioning, building, and linking. diff --git a/jupyak_config.toml b/jupyak_config.toml index a37a96d..f178ab6 100644 --- a/jupyak_config.toml +++ b/jupyak_config.toml @@ -20,3 +20,6 @@ link_exclude_patterns = [ "^@jupyterlab/(debugger(-extension)?|extensionmanager(-extension)?|hub-extension|nbconvert-css|pluginmanager-extension|terminal(-extension)?|template)$", "^@jupyter-notebook/(documentsearch-extension|lab-extension|terminal-extension)$", ] + +[repos.jupyterlite.js.patch_package_jsons."app/lab"] +dependencies = { "@jupyterlab/celltags-extension" = "*" } diff --git a/src/jupyak/tasks/_js.ipynb b/src/jupyak/tasks/_js.ipynb index e3a1fbd..4f27598 100644 --- a/src/jupyak/tasks/_js.ipynb +++ b/src/jupyak/tasks/_js.ipynb @@ -171,10 +171,14 @@ "\n", " install_deps += [yak.not_a_package_json]\n", "\n", + " path_patches = {\n", + " work_path / path / W.PACKAGE_JSON: patch_package_json\n", + " for path, patch_package_json in js.patch_package_jsons.items()\n", + " }\n", + "\n", " link_deps = [yak.work_path / DEP_YML_PATTERN.format(dep) for dep in js.dependencies]\n", " install_deps += link_deps\n", " pre_install_actions = [\n", - " A.git([\"reset\", \"--hard\", \"HEAD\"], in_repo),\n", " (\n", " _fix_js_resolutions,\n", " [\n", @@ -183,12 +187,14 @@ " yak.not_a_package_json,\n", " js.all_install_exclude_resolutions,\n", " js.link_exclude_patterns,\n", + " path_patches,\n", " ],\n", " ),\n", " ]\n", "\n", " yield dict(\n", " name=f\"{repo.name}:yarn:install\",\n", + " uptodate=[doit.tools.config_changed({\"config\": js.to_dict()})],\n", " doc=f\"> install npm dependencies of {repo.name}\",\n", " actions=[*pre_install_actions, A.run([*yak.env.run_args, \"yarn\"], in_repo)],\n", " file_dep=install_deps,\n", @@ -250,6 +256,25 @@ " )" ] }, + { + "cell_type": "code", + "execution_count": null, + "id": "a07c3dcf-c8eb-4372-850f-d1e23c681930", + "metadata": {}, + "outputs": [], + "source": [ + "def _patch_one_package_json(pkg_data: dict, patch_package_json: Y.PackageJsonPatches):\n", + " sections = {\n", + " \"dependencies\": patch_package_json.dependencies,\n", + " \"scripts\": patch_package_json.scripts,\n", + " \"devDependencies\": patch_package_json.dev_dependencies,\n", + " }\n", + " for section, values in sections.items():\n", + " if not values:\n", + " continue\n", + " pkg_data[section].update(values)" + ] + }, { "cell_type": "code", "execution_count": null, @@ -263,6 +288,7 @@ " not_a_package_json: Path,\n", " install_exclude_resolutions: list[str],\n", " link_exclude_patterns: list[str],\n", + " path_patches: dict[Path, Y.PackageJsonPatches],\n", "):\n", " print(f\" ... fixing resolutions for {package_json.parent.name}\")\n", " pkg_data = json.loads(package_json.read_text(encoding=\"utf-8\"))\n", @@ -271,6 +297,11 @@ " f\"\"\"link:{os.path.relpath(not_a_package_json.parent, package_json.parent)}\"\"\"\n", " )\n", "\n", + " patches = path_patches.get(package_json)\n", + " if patches:\n", + " print(f\"\"\" ... patching {package_json.parent.name}#/{section}\"\"\")\n", + " _patch_one_package_json(pkg_data, patches)\n", + "\n", " for tgz_list in tgz_lists:\n", " resolutions = yaml.safe_load(tgz_list.read_text(encoding=\"utf-8\"))\n", " dest = package_json.parent.name\n", @@ -303,6 +334,7 @@ " not_a_package_json,\n", " install_exclude_resolutions,\n", " link_exclude_patterns,\n", + " path_patches,\n", " )" ] }, diff --git a/src/jupyak/tasks/_yak.ipynb b/src/jupyak/tasks/_yak.ipynb index b91a33b..791cc9e 100644 --- a/src/jupyak/tasks/_yak.ipynb +++ b/src/jupyak/tasks/_yak.ipynb @@ -644,6 +644,44 @@ " return as_dict" ] }, + { + "cell_type": "markdown", + "id": "c65b12e4-0b2b-4325-84ec-fc73c1569de8", + "metadata": {}, + "source": [ + "a subset of package.json" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3eb7d2c2-4b53-4420-9497-68dbcf277d8d", + "metadata": {}, + "outputs": [], + "source": [ + "class PackageJsonPatches(HasSchema):\n", + " dependencies = T.Dict(\n", + " key_trait=T.Unicode(),\n", + " value_trait=T.Unicode(),\n", + " help=\"dependencies to add before linking\",\n", + " )\n", + " dev_dependencies = T.Dict(\n", + " key_trait=T.Unicode(),\n", + " value_trait=T.Unicode(),\n", + " help=\"development dependencies to add before linking\",\n", + " )\n", + " resolutions = T.Dict(\n", + " key_trait=T.Unicode(),\n", + " value_trait=T.Unicode(),\n", + " help=\"resolutions to add before linking\",\n", + " )\n", + " scripts = T.Dict(\n", + " key_trait=T.Unicode(),\n", + " value_trait=T.Unicode(),\n", + " help=\"scripts to overload to avoid bad effects\",\n", + " )" + ] + }, { "cell_type": "markdown", "id": "e5a4859f-7fb6-4641-8945-51a4c4be01b2", @@ -682,14 +720,25 @@ " T.Unicode(),\n", " help=\"regular expressions for the npm `@org/pkg` names that should _not_ be installed, ever, in this repo\",\n", " )\n", + " patch_package_jsons = T.Dict(\n", + " key_trait=T.Unicode(),\n", + " value_trait=InstanceDict(PackageJsonPatches),\n", + " help=\"patches to package.json to help resolvability\",\n", + " )\n", "\n", " def to_dict(self):\n", " as_dict = super().to_dict()\n", - " all_tasks = as_dict.get(\"tasks\", {})\n", - " if all_tasks:\n", + " tasks = as_dict.get(\"tasks\", {})\n", + " if tasks:\n", " as_dict[\"tasks\"] = {\n", - " cwd: [task.to_dict() for task in path_tasks]\n", - " for cwd, path_tasks in all_tasks.items()\n", + " path: [path_task.to_dict() for path_task in path_tasks]\n", + " for path, path_tasks in tasks.items()\n", + " }\n", + " patch_package_jsons = as_dict.get(\"patch_package_jsons\", {})\n", + " if patch_package_jsons:\n", + " as_dict[\"patch_package_jsons\"] = {\n", + " path: pkg_json.to_dict()\n", + " for path, pkg_json in patch_package_jsons.items()\n", " }\n", " return as_dict\n", "\n",