Skip to content

Commit

Permalink
fix: preparing next build with correct dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
bodymindarts committed Oct 18, 2023
1 parent 265ecf5 commit 852f928
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
14 changes: 3 additions & 11 deletions toolchains/simple-pnpm/build_node_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand All @@ -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,
Expand Down
25 changes: 17 additions & 8 deletions toolchains/workspace-pnpm/build_next_build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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,
)
Expand Down
4 changes: 3 additions & 1 deletion toolchains/workspace-pnpm/macros.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)

Expand Down

0 comments on commit 852f928

Please sign in to comment.