1- /**
1+ /*!
22 * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
33 * SPDX-License-Identifier: AGPL-3.0-or-later
44 */
55
6- const { execSync } = require ( 'node:child_process' )
7- const { loadModule, getVueVersion } = require ( '../utils.js' )
6+ const { getPackageVersion, getVueVersion } = require ( '../utils.js' )
87const packageJson = require ( '../package.json' )
98
109const isCompatible = ( installed , expected ) => expected . match ( / \d + / ) [ 0 ] === installed . match ( / \d + / ) [ 0 ]
@@ -13,24 +12,45 @@ const [vueLoaderForVue2, vueLoaderForVue3] = packageJson.peerDependencies['vue-l
1312
1413try {
1514 const vueVersion = getVueVersion ( )
16- console . info ( `[@nextcloud/webpack-vue-config | postinstall] Found Vue@${ vueVersion } ` )
17-
18- const vueLoaderVersion = vueVersion === 2 ? vueLoaderForVue2 : vueLoaderForVue3
19-
20- const installedVueLoader = loadModule ( 'vue-loader/package.json' ) . version
21- if ( installedVueLoader && isCompatible ( installedVueLoader , vueLoaderVersion ) ) {
22- console . info ( `[@nextcloud/webpack-vue-config | postinstall] Found compatible vue-loader@${ installedVueLoader } ` )
15+ const requiredVueLoaderVersion = vueVersion === 2 ? vueLoaderForVue2 : vueLoaderForVue3
16+ console . info ( `[@nextcloud/webpack-vue-config] Found Vue@${ vueVersion } , requires vue-loader@${ requiredVueLoaderVersion } ` )
17+
18+ const vueLoaderVersion = getPackageVersion ( 'vue-loader' )
19+ if ( ! vueLoaderVersion ) {
20+ // Likely an installation not in an npm environment (like nixpkgs)
21+ // Skip the check. In case of incompatibility, the compilation will fail later anyway
22+ console . warn ( `[@nextcloud/webpack-vue-config] vue-loader is not installed. This is unexpected, skipping compatibility check.` )
2323 process . exit ( 0 )
24- } else if ( installedVueLoader ) {
25- console . info ( `[@nextcloud/webpack-vue-config | postinstall] Found incompatible vue-loader@${ installedVueLoader } . Expected ${ vueLoaderVersion } ` )
2624 }
27-
28- console . info ( `[@nextcloud/webpack-vue-config | postinstall] Installing vue-loader@${ vueLoaderVersion } ` )
25+ console . info ( `[@nextcloud/webpack-vue-config] Found vue-loader@${ vueLoaderVersion } ` )
2926
30- execSync ( `npm install --no-save vue-loader@${ vueLoaderVersion } ` , { stdio : 'inherit' , cwd : process . env . INIT_CWD } )
27+ if ( isCompatible ( vueLoaderVersion , requiredVueLoaderVersion ) ) {
28+ console . info ( `[@nextcloud/webpack-vue-config] Installed vue-loader@${ vueLoaderVersion } is compatible with Vue@${ vueVersion } ` )
29+ process . exit ( 0 )
30+ }
3131
32- console . info ( `[@nextcloud/webpack-vue-config | postinstall] vue-loader${ vueLoaderVersion } installed` )
33- } catch ( error ) {
34- console . error ( error . message )
32+ console . error ( [
33+ '' ,
34+ '🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻🔻' ,
35+ '' ,
36+ ' @nextcloud/webpack-vue-config' ,
37+ '' ,
38+ ` You have "vue-loader@${ vueLoaderVersion } " installed incompatible with "Vue ${ vueVersion } ".` ,
39+ ` You must have "vue-loader@${ requiredVueLoaderVersion } " installed.` ,
40+ '' ,
41+ ' You can install it via:' ,
42+ '' ,
43+ ` npm install --save-dev vue-loader${ vueVersion === 2 ? '@legacy' : '' } ` ,
44+ '' ,
45+ '🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺🔺' ,
46+ '' ,
47+ ] . join ( '\n' ) )
3548 process . exit ( 1 )
49+ } catch ( e ) {
50+ // The purpose of the script is to warn in a simple way about an incompatible vue-loader version
51+ // If something goes wrong, just skip the check
52+ // (for example, nixpkgs or other unusual setups might run postinstall when dependencies are not installed as expected by npm)
53+ // In case of incompatibility, an error will be raised when using the package anyway, just less directly - with compilation errors
54+ console . warn ( '[@nextcloud/webpack-vue-config] Error during postinstall check:' , e )
55+ process . exit ( 0 )
3656}
0 commit comments