@@ -16,6 +16,7 @@ import {
16
16
getAbsoluteLibDirPath ,
17
17
presets ,
18
18
getPackageManager ,
19
+ getProjectJsonFile ,
19
20
} from '#utils' ;
20
21
import { Messages } from '#constants' ;
21
22
import { vulcan } from '#env' ;
@@ -24,16 +25,6 @@ const vulcanLibPath = getAbsoluteLibDirPath();
24
25
const vulcanRootPath = resolve ( vulcanLibPath , '..' ) ;
25
26
const isWindows = process . platform === 'win32' ;
26
27
27
- /**
28
- * Get the path corresponding to a specific alias defined in the package.json.
29
- * @param {string } alias - The desired alias.
30
- * @returns {string } The path corresponding to the alias.
31
- */
32
- /**
33
- * Get the path corresponding to a specific alias defined in the package.json.
34
- * @param {string } alias - The desired alias.
35
- * @returns {string } The path corresponding to the alias.
36
- */
37
28
/**
38
29
* Get the path corresponding to a specific alias defined in the package.json.
39
30
* @param {string } alias - The desired alias.
@@ -51,6 +42,7 @@ async function getAliasPath(alias) {
51
42
52
43
return aliasPath ;
53
44
}
45
+
54
46
/**
55
47
* Move requires and imports to file init
56
48
* @param {string } entryContent - The file content to be fixed.
@@ -200,6 +192,38 @@ async function folderExistsInProject(folder) {
200
192
}
201
193
}
202
194
195
+ /**
196
+ * Check if node_modules dir exists
197
+ */
198
+ async function checkNodeModulesDir ( ) {
199
+ let projectJson ;
200
+ try {
201
+ projectJson = getProjectJsonFile ( 'package.json' ) ;
202
+ } catch ( error ) {
203
+ if ( error . code === 'ENOENT' ) {
204
+ return ;
205
+ }
206
+
207
+ feedback . prebuild . error ( error ) ;
208
+ process . exit ( 1 ) ;
209
+ }
210
+
211
+ if (
212
+ projectJson &&
213
+ ( projectJson . dependencies || projectJson . devDependencies )
214
+ ) {
215
+ const pkgManager = await getPackageManager ( ) ;
216
+ const existNodeModules = await folderExistsInProject ( 'node_modules' ) ;
217
+
218
+ if ( ! existNodeModules ) {
219
+ feedback . prebuild . error (
220
+ Messages . build . error . install_dependencies_failed ( pkgManager ) ,
221
+ ) ;
222
+ process . exit ( 1 ) ;
223
+ }
224
+ }
225
+ }
226
+
203
227
/**
204
228
* Class representing a Dispatcher for build operations.
205
229
* @example
@@ -226,15 +250,8 @@ class Dispatcher {
226
250
* Run the build process.
227
251
*/
228
252
run = async ( ) => {
229
- // Check install depenedencies
230
- const pckManager = await getPackageManager ( ) ;
231
- const existNodeModules = await folderExistsInProject ( 'node_modules' ) ;
232
- if ( ! existNodeModules ) {
233
- feedback . prebuild . error (
234
- Messages . build . error . install_dependencies_failed ( pckManager ) ,
235
- ) ;
236
- process . exit ( 1 ) ;
237
- }
253
+ await checkNodeModulesDir ( ) ;
254
+
238
255
// Load Context based on preset
239
256
const { entryContent, prebuild, config } = await loadBuildContext (
240
257
this . preset ,
0 commit comments