Skip to content

Commit 672ee12

Browse files
authored
Merge pull request #688 from nextcloud-libraries/feat/require-vue-loader
feat!: require explicit `vue-loader@legacy` for Vue 2, remove hidden install
2 parents fc35f88 + d760682 commit 672ee12

File tree

15 files changed

+8348
-207
lines changed

15 files changed

+8348
-207
lines changed

README.md

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,10 @@ module.exports = webpackConfig
3434

3535
## Note on Vue 2 support
3636

37-
This package supports both **Vue 2** and **Vue 3** by installing legacy `vue-loader` for Vue 2 in a `postinstall` script.
38-
39-
In Vue 2 it may result in different `vue-loader` version in the `package-lock.json` and `node_modules`.
40-
41-
### Troubleshooting in Vue 2 apps
42-
43-
In case of `npm error code ENOTEMPTY` - remove `node_modules` and try again:
44-
45-
```sh
46-
# In case of "npm error code ENOTEMPTY" in Vue 2
47-
rm -rf node_modules
48-
```
49-
50-
To avoid any errors and have explicitly specified `vue-loader` - install it as dependency:
37+
This package supports both **Vue 2** and **Vue 3**.
38+
While **Vue 3** is supported by default, **Vue 2** requires an explicit legacy `vue-loader` installation:
5139

5240
```sh
53-
# Install legacy vue-loader for Vue 2
5441
npm i -D vue-loader@legacy
5542
```
5643

REUSE.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ SPDX-FileCopyrightText = "2019 Nextcloud GmbH and Nextcloud contributors"
1212
SPDX-License-Identifier = "AGPL-3.0-or-later"
1313

1414
[[annotations]]
15-
path = ["test-apps/vue2/package-lock.json", "test-apps/vue2/package.json", "test-apps/vue3/package-lock.json", "test-apps/vue3/package.json"]
15+
path = ["test-apps/vue2/package-lock.json", "test-apps/vue2/package.json", "test-apps/vue2--wrong-vue-loader/package-lock.json", "test-apps/vue2--wrong-vue-loader/package.json", "test-apps/vue3/package-lock.json", "test-apps/vue3/package.json"]
1616
precedence = "aggregate"
1717
SPDX-FileCopyrightText = "2025 Nextcloud GmbH and Nextcloud contributors"
1818
SPDX-License-Identifier = "AGPL-3.0-or-later"

scripts/postinstall.js

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
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')
87
const packageJson = require('../package.json')
98

109
const isCompatible = (installed, expected) => expected.match(/\d+/)[0] === installed.match(/\d+/)[0]
@@ -13,24 +12,45 @@ const [vueLoaderForVue2, vueLoaderForVue3] = packageJson.peerDependencies['vue-l
1312

1413
try {
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
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2021 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
const babelConfig = require('@nextcloud/babel-config')
6+
7+
module.exports = babelConfig

0 commit comments

Comments
 (0)