Skip to content

Commit b5df118

Browse files
authored
fix: handle missing angular dependencis error (#91)
* fix: handle missing angular dependencis error * chore: make linter happy * chore: remove dead code and fix pretest scripts * fix: node test runner is not fond of non-ASCII chars * fix: node test runner is still unhappy * chore: bump CI v18 node version because of node test runner problems
1 parent 1983e9c commit b5df118

File tree

7 files changed

+82
-9
lines changed

7 files changed

+82
-9
lines changed

.github/workflows/test.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ jobs:
1212
strategy:
1313
matrix:
1414
os: [ubuntu-latest, macOS-latest, windows-latest]
15-
node-version: [18.13.0, '*']
15+
node-version: [18.18.2, '*']
1616
exclude:
1717
- os: macOS-latest
18-
node-version: 18.13.0
18+
node-version: 18.18.2
1919
- os: windows-latest
20-
node-version: 18.13.0
20+
node-version: 18.18.2
2121
fail-fast: false
2222

2323
steps:

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@
2222
"prepublishOnly:pull": "git pull",
2323
"prepublishOnly:install": "npm ci",
2424
"prepublishOnly:test": "npm test",
25-
"pretest:demo": "cd demo && npm ci && netlify build --cwd . --offline && cd ..",
26-
"pretest:fixtures": "cd tests/fixtures/non-angular-project && npm ci",
25+
"pretest:demo": "cd demo && npm ci && netlify build --cwd . --offline",
26+
"pretest:fixtures": "run-s pretest:fixtures:*",
27+
"pretest:fixtures:non-angular-project": "cd tests/fixtures/non-angular-project && npm ci",
28+
"pretest:fixtures:missing-angular-deps": "cd tests/fixtures/missing-angular-deps && npm ci",
2729
"pretest": "run-s pretest:*",
2830
"test": "node --test"
2931
},

src/helpers/validateAngularVersion.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,12 @@ const { satisfies } = require('semver')
77
* @returns {Promise<boolean>}
88
*/
99
const validateAngularVersion = async function (root) {
10-
// eslint-disable-next-line n/no-missing-require
11-
const packagePath = require.resolve('@angular/core/package.json', { paths: [root] })
12-
if (!packagePath) {
10+
let packagePath
11+
try {
12+
// eslint-disable-next-line n/no-missing-require
13+
packagePath = require.resolve('@angular/core/package.json', { paths: [root] })
14+
} catch {
15+
// module not found
1316
console.warn('This site does not seem to be using Angular.')
1417
return false
1518
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[build]
2+
command="npm run build"
3+
ignore="exit 1" ## always build, there might be changes in the plugin
4+
5+
[[plugins]]
6+
package="@netlify/angular-runtime"

tests/fixtures/missing-angular-deps/package-lock.json

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "missing-angular-deps",
3+
"version": "0.0.0",
4+
"scripts": {
5+
"build": "echo hello!"
6+
},
7+
"private": true,
8+
"dependencies": {
9+
"@netlify/angular-runtime": "file:../../../"
10+
},
11+
"devDependencies": {}
12+
}

tests/integration.test.mjs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,20 @@ import assert from 'node:assert'
33
import { test } from 'node:test'
44
import { fileURLToPath } from 'node:url'
55

6-
test('non angular project fails the plugin execution but does not error', async () => {
6+
test('project without angular config file fails the plugin execution but does not error', async () => {
77
const { severityCode, success } = await build({
88
repositoryRoot: fileURLToPath(new URL('./fixtures/non-angular-project', import.meta.url)),
99
})
1010

1111
assert.deepEqual(severityCode, 0)
1212
assert.deepEqual(success, true)
1313
})
14+
15+
test('project with missing angular dependencies does not error', async () => {
16+
const { severityCode, success } = await build({
17+
repositoryRoot: fileURLToPath(new URL('./fixtures/missing-angular-deps', import.meta.url)),
18+
})
19+
20+
assert.deepEqual(severityCode, 0)
21+
assert.deepEqual(success, true)
22+
})

0 commit comments

Comments
 (0)