@@ -42,8 +42,7 @@ def build_dist(package, dist_dir):
4242
4343 if "workspaces" in data :
4444 all_data = dict ()
45- packages = data ["workspaces" ].get ("packages" , [])
46- for pattern in packages :
45+ for pattern in _get_workspace_packages (data ):
4746 for path in glob (osp .join (basedir , pattern ), recursive = True ):
4847 path = Path (path )
4948 package_json = path / "package.json"
@@ -91,16 +90,18 @@ def extract_dist(dist_dir, target):
9190 tar .extractall (target )
9291 tar .close ()
9392
93+ if "main" in data :
94+ main = osp .join (target , "package" , data ["main" ])
95+ if not osp .exists (main ):
96+ raise ValueError (f"{ name } is missing 'main' file { data ['main' ]} " )
97+
9498 shutil .move (str (target / "package" ), str (pkg_dir ))
9599
96100 return names
97101
98102
99- def check_dist (dist_dir , test_cmd = None ):
103+ def check_dist (dist_dir ):
100104 """Check npm dist file(s) in a dist dir"""
101- if not test_cmd :
102- test_cmd = "node index.js"
103-
104105 tmp_dir = Path (TemporaryDirectory ().name )
105106 os .makedirs (tmp_dir )
106107
@@ -114,11 +115,6 @@ def check_dist(dist_dir, test_cmd=None):
114115
115116 util .run (f"npm install { install_str } " , cwd = tmp_dir )
116117
117- text = "\n " .join ([f'require("{ name } ")' for name in names ])
118- tmp_dir .joinpath ("index.js" ).write_text (text , encoding = "utf-8" )
119-
120- util .run (test_cmd , cwd = tmp_dir )
121-
122118 shutil .rmtree (str (tmp_dir ), ignore_errors = True )
123119
124120
@@ -152,15 +148,7 @@ def get_package_versions(version):
152148 message += f'\n npm version: { data ["name" ]} : { data ["version" ]} '
153149 if "workspaces" in data :
154150 message += "\n npm workspace versions:"
155-
156- if isinstance (data ["workspaces" ], dict ):
157- packages = []
158- for value in data ["workspaces" ].values ():
159- packages .extend (value )
160- else :
161- packages = data ["workspaces" ]
162-
163- for pattern in packages :
151+ for pattern in _get_workspace_packages (data ):
164152 for path in glob (pattern , recursive = True ):
165153 text = Path (path ).joinpath ("package.json" ).read_text ()
166154 data = json .loads (text )
@@ -178,8 +166,7 @@ def tag_workspace_packages():
178166 if not "workspaces" in data :
179167 return
180168
181- packages = data ["workspaces" ].get ("packages" , [])
182- for pattern in packages :
169+ for pattern in _get_workspace_packages (data ):
183170 for path in glob (pattern , recursive = True ):
184171 sub_package_json = Path (path ) / "package.json"
185172 sub_data = json .loads (sub_package_json .read_text (encoding = "utf-8" ))
@@ -188,3 +175,14 @@ def tag_workspace_packages():
188175 util .log (f"Skipping existing tag { tag_name } " )
189176 else :
190177 util .run (f"git tag { tag_name } " )
178+
179+
180+ def _get_workspace_packages (data ):
181+ """Get the workspace packages for a package given package data"""
182+ if isinstance (data ["workspaces" ], dict ):
183+ packages = []
184+ for value in data ["workspaces" ].values ():
185+ packages .extend (value )
186+ else :
187+ packages = data ["workspaces" ]
188+ return packages
0 commit comments