Skip to content

Commit 914a581

Browse files
committed
feat: detect old version of plugin
1 parent 0e445a4 commit 914a581

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

demo/package-lock.json

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/**
2+
* Ensures there's no old version of the same plugin installed.
3+
* @param {string} root
4+
* @param {function} failBuild
5+
* @returns {void}
6+
*/
7+
const ensureNoCompetingPlugin = function (root, failBuild) {
8+
let packagePath
9+
try {
10+
// eslint-disable-next-line n/no-missing-require
11+
packagePath = require.resolve('@netlify/plugin-angular-universal', { paths: [root] })
12+
} catch {}
13+
14+
if (packagePath) {
15+
return failBuild(
16+
"Detected @netlify/plugin-angular-universal, the old version of Netlify's Angular runtime. Please uninstall it, the new version was set up automatically for you.",
17+
)
18+
}
19+
}
20+
21+
module.exports = ensureNoCompetingPlugin

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const ensureNoCompetingPlugin = require('./helpers/ensureNoCompetingPlugin')
12
const getAngularJson = require('./helpers/getAngularJson')
23
const getAngularRoot = require('./helpers/getAngularRoot')
34
const setUpEdgeFunction = require('./helpers/setUpEdgeFunction')
@@ -6,14 +7,16 @@ const validateAngularVersion = require('./helpers/validateAngularVersion')
67
let isValidAngularProject = true
78

89
module.exports = {
9-
async onPreBuild({ netlifyConfig }) {
10+
async onPreBuild({ netlifyConfig, utils }) {
1011
const siteRoot = getAngularRoot({ netlifyConfig })
1112
isValidAngularProject = await validateAngularVersion(siteRoot)
1213
if (!isValidAngularProject) {
1314
console.warn('Skipping build plugin.')
1415
return
1516
}
1617

18+
ensureNoCompetingPlugin(siteRoot, utils.build.failBuild)
19+
1720
netlifyConfig.build.command ??= 'npm run build'
1821
},
1922
async onBuild({ utils, netlifyConfig, constants }) {

0 commit comments

Comments
 (0)