@@ -42,8 +42,7 @@ def build_dist(package, dist_dir):
42
42
43
43
if "workspaces" in data :
44
44
all_data = dict ()
45
- packages = data ["workspaces" ].get ("packages" , [])
46
- for pattern in packages :
45
+ for pattern in _get_workspace_packages (data ):
47
46
for path in glob (osp .join (basedir , pattern ), recursive = True ):
48
47
path = Path (path )
49
48
package_json = path / "package.json"
@@ -91,16 +90,18 @@ def extract_dist(dist_dir, target):
91
90
tar .extractall (target )
92
91
tar .close ()
93
92
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
+
94
98
shutil .move (str (target / "package" ), str (pkg_dir ))
95
99
96
100
return names
97
101
98
102
99
- def check_dist (dist_dir , test_cmd = None ):
103
+ def check_dist (dist_dir ):
100
104
"""Check npm dist file(s) in a dist dir"""
101
- if not test_cmd :
102
- test_cmd = "node index.js"
103
-
104
105
tmp_dir = Path (TemporaryDirectory ().name )
105
106
os .makedirs (tmp_dir )
106
107
@@ -114,11 +115,6 @@ def check_dist(dist_dir, test_cmd=None):
114
115
115
116
util .run (f"npm install { install_str } " , cwd = tmp_dir )
116
117
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
-
122
118
shutil .rmtree (str (tmp_dir ), ignore_errors = True )
123
119
124
120
@@ -152,15 +148,7 @@ def get_package_versions(version):
152
148
message += f'\n npm version: { data ["name" ]} : { data ["version" ]} '
153
149
if "workspaces" in data :
154
150
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 ):
164
152
for path in glob (pattern , recursive = True ):
165
153
text = Path (path ).joinpath ("package.json" ).read_text ()
166
154
data = json .loads (text )
@@ -178,8 +166,7 @@ def tag_workspace_packages():
178
166
if not "workspaces" in data :
179
167
return
180
168
181
- packages = data ["workspaces" ].get ("packages" , [])
182
- for pattern in packages :
169
+ for pattern in _get_workspace_packages (data ):
183
170
for path in glob (pattern , recursive = True ):
184
171
sub_package_json = Path (path ) / "package.json"
185
172
sub_data = json .loads (sub_package_json .read_text (encoding = "utf-8" ))
@@ -188,3 +175,14 @@ def tag_workspace_packages():
188
175
util .log (f"Skipping existing tag { tag_name } " )
189
176
else :
190
177
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