Skip to content

Commit 3d1d588

Browse files
committed
pnpm building -- use a hack to only build some packages
1 parent 4be0bf2 commit 3d1d588

File tree

1 file changed

+33
-23
lines changed

1 file changed

+33
-23
lines changed

src/workspaces.py

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -237,29 +237,39 @@ def banner(s: str) -> None:
237237

238238
def install(args) -> None:
239239
v = packages(args)
240-
print("first install all packages")
241-
# much faster special case
242-
# see https://github.com/pnpm/pnpm/issues/6778 for why we put that confirm option in
243-
c = "cd packages && pnpm install --config.confirmModulesPurge=false"
244-
if args.prod:
245-
args.dist_only = False
246-
args.node_modules_only = True
247-
args.parallel = True
248-
clean(args)
249-
c += " --prod"
250-
cmd(c)
251-
252-
if v != all_packages():
253-
print("remove packages from excluded directories")
254-
# **remove node_modules** from all directories that are excluded.
255-
# We have to do the full install above -- there's no way around
256-
# that which works as far as I can tell. Any use of --filter that
257-
# works also ends up ignoring the lockfile.
258-
for path in all_packages():
259-
if path not in v:
260-
print("removing packages from ", path)
261-
shutil.rmtree(os.path.join(path, 'node_modules'),
262-
ignore_errors=True)
240+
241+
# The trick we use to build only a subset of the packages in a pnpm workspace
242+
# is to temporarily modify packages/pnpm-workspace.yaml to explicitly remove
243+
# the packages that we do NOT want to build. This should be supported by
244+
# pnpm via the --filter option but I can't figure that out in a way that doesn't
245+
# break the global lockfile, so this is the hack we have for now.
246+
ws = "packages/pnpm-workspace.yaml"
247+
tmp = ws + ".tmp"
248+
allp = all_packages()
249+
try:
250+
if v != allp:
251+
shutil.copy(ws, tmp)
252+
s = open(ws,'r').read() + '\n'
253+
for package in allp:
254+
if package not in v:
255+
s += ' - "!%s"\n'%package.split('/')[-1]
256+
257+
open(ws,'w').write(s)
258+
259+
print("install packages")
260+
# much faster special case
261+
# see https://github.com/pnpm/pnpm/issues/6778 for why we put that confirm option in
262+
c = "cd packages && pnpm install --config.confirmModulesPurge=false"
263+
if args.prod:
264+
args.dist_only = False
265+
args.node_modules_only = True
266+
args.parallel = True
267+
clean(args)
268+
c += " --prod"
269+
cmd(c)
270+
finally:
271+
if os.path.exists(tmp):
272+
shutil.move(tmp, ws)
263273

264274

265275
# Build all the packages that need to be built.

0 commit comments

Comments
 (0)