Skip to content

Commit

Permalink
fix: handle missing angular dependencis error (#91)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
JGAntunes authored Nov 28, 2023
1 parent 1983e9c commit b5df118
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, macOS-latest, windows-latest]
node-version: [18.13.0, '*']
node-version: [18.18.2, '*']
exclude:
- os: macOS-latest
node-version: 18.13.0
node-version: 18.18.2
- os: windows-latest
node-version: 18.13.0
node-version: 18.18.2
fail-fast: false

steps:
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
"prepublishOnly:pull": "git pull",
"prepublishOnly:install": "npm ci",
"prepublishOnly:test": "npm test",
"pretest:demo": "cd demo && npm ci && netlify build --cwd . --offline && cd ..",
"pretest:fixtures": "cd tests/fixtures/non-angular-project && npm ci",
"pretest:demo": "cd demo && npm ci && netlify build --cwd . --offline",
"pretest:fixtures": "run-s pretest:fixtures:*",
"pretest:fixtures:non-angular-project": "cd tests/fixtures/non-angular-project && npm ci",
"pretest:fixtures:missing-angular-deps": "cd tests/fixtures/missing-angular-deps && npm ci",
"pretest": "run-s pretest:*",
"test": "node --test"
},
Expand Down
9 changes: 6 additions & 3 deletions src/helpers/validateAngularVersion.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ const { satisfies } = require('semver')
* @returns {Promise<boolean>}
*/
const validateAngularVersion = async function (root) {
// eslint-disable-next-line n/no-missing-require
const packagePath = require.resolve('@angular/core/package.json', { paths: [root] })
if (!packagePath) {
let packagePath
try {
// eslint-disable-next-line n/no-missing-require
packagePath = require.resolve('@angular/core/package.json', { paths: [root] })
} catch {
// module not found
console.warn('This site does not seem to be using Angular.')
return false
}
Expand Down
6 changes: 6 additions & 0 deletions tests/fixtures/missing-angular-deps/netlify.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[build]
command="npm run build"
ignore="exit 1" ## always build, there might be changes in the plugin

[[plugins]]
package="@netlify/angular-runtime"
41 changes: 41 additions & 0 deletions tests/fixtures/missing-angular-deps/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions tests/fixtures/missing-angular-deps/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "missing-angular-deps",
"version": "0.0.0",
"scripts": {
"build": "echo hello!"
},
"private": true,
"dependencies": {
"@netlify/angular-runtime": "file:../../../"
},
"devDependencies": {}
}
11 changes: 10 additions & 1 deletion tests/integration.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,20 @@ import assert from 'node:assert'
import { test } from 'node:test'
import { fileURLToPath } from 'node:url'

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

assert.deepEqual(severityCode, 0)
assert.deepEqual(success, true)
})

test('project with missing angular dependencies does not error', async () => {
const { severityCode, success } = await build({
repositoryRoot: fileURLToPath(new URL('./fixtures/missing-angular-deps', import.meta.url)),
})

assert.deepEqual(severityCode, 0)
assert.deepEqual(success, true)
})

0 comments on commit b5df118

Please sign in to comment.