From 852f92838e18f311db783d78381c0833fcb819bf Mon Sep 17 00:00:00 2001 From: bodymindarts Date: Wed, 18 Oct 2023 16:04:02 +0200 Subject: [PATCH] fix: preparing next build with correct dirs --- toolchains/simple-pnpm/build_node_modules.py | 14 +++-------- toolchains/workspace-pnpm/build_next_build.py | 25 +++++++++++++------ toolchains/workspace-pnpm/macros.bzl | 4 ++- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/toolchains/simple-pnpm/build_node_modules.py b/toolchains/simple-pnpm/build_node_modules.py index 94dfed7d00..3fd1c750db 100755 --- a/toolchains/simple-pnpm/build_node_modules.py +++ b/toolchains/simple-pnpm/build_node_modules.py @@ -10,8 +10,7 @@ if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) - group = parser.add_mutually_exclusive_group(required=True) - group.add_argument( + parser.add_argument( "--root-dir", help="Path to the root", ) @@ -22,19 +21,12 @@ args = parser.parse_args() - if args.root_dir: - cwd = args.root_dir - else: - cwd = None - cmd = ["pnpm", "install", "--frozen-lockfile"] - exit_code = subprocess.call(cmd, cwd=cwd) + exit_code = subprocess.call(cmd, cwd=args.root_dir) if exit_code == 0: - src = "node_modules" - if cwd: - src = os.path.join(cwd, src) + src = os.path.join(args.root_dir, "node_modules") shutil.copytree( src, diff --git a/toolchains/workspace-pnpm/build_next_build.py b/toolchains/workspace-pnpm/build_next_build.py index 62a32f3f0e..c5abce2782 100644 --- a/toolchains/workspace-pnpm/build_next_build.py +++ b/toolchains/workspace-pnpm/build_next_build.py @@ -10,6 +10,10 @@ if __name__ == "__main__": parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + "--root-dir", + help="Path to the root", + ) parser.add_argument( "--package-dir", help="Directory of the package", @@ -25,27 +29,32 @@ os.path.relpath("node_modules/.bin/next"), "build" ] - exit_code = subprocess.call(next_cmd, cwd=args.package_dir) + + app_dir = os.path.join(args.root_dir, args.package_dir) + build_out_dir = os.path.join(app_dir, ".next") + + exit_code = subprocess.call(next_cmd, cwd=app_dir) shutil.copytree( - os.path.join(args.package_dir,".next"), + build_out_dir, os.path.join(args.out_path, ".next"), symlinks=True, dirs_exist_ok=True, ) - if os.path.exists(os.path.join(args.package_dir, "public")): + if os.path.exists(os.path.join(app_dir, "public")): shutil.copytree( - os.path.join(args.package_dir,"public"), - os.path.join(args.out_path, ".next", "standalone", "public"), + os.path.join(app_dir, "public"), + os.path.join(args.out_path, ".next", "standalone", args.package_dir, "public"), symlinks=True, dirs_exist_ok=True, ) - if os.path.exists(os.path.join(args.package_dir, ".next", "static")): + if os.path.exists(os.path.join(build_out_dir, "static")): shutil.copytree( - os.path.join(args.package_dir,".next", "static"), - os.path.join(args.out_path, ".next", "standalone", "static"), + os.path.join(build_out_dir, "static"), + os.path.join(args.out_path, ".next", "standalone", + args.package_dir,".next", "static"), symlinks=True, dirs_exist_ok=True, ) diff --git a/toolchains/workspace-pnpm/macros.bzl b/toolchains/workspace-pnpm/macros.bzl index 4a36045888..35ec3840dc 100644 --- a/toolchains/workspace-pnpm/macros.bzl +++ b/toolchains/workspace-pnpm/macros.bzl @@ -422,8 +422,10 @@ def next_build_impl(ctx: AnalysisContext) -> list[[DefaultInfo, RunInfo]]: cmd = cmd_args( ctx.attrs._python_toolchain[PythonToolchainInfo].interpreter, pnpm_toolchain.build_next_build[DefaultInfo].default_outputs, + "--root-dir", + build_context.workspace_root, "--package-dir", - cmd_args([build_context.workspace_root, ctx.label.package], delimiter = "/"), + ctx.label.package, out.as_output() )