Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: handle missing angular dependencis error #91

Merged
merged 6 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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, '*']
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bumped the CI execution to latest 18 as we were hitting some limitations with the node test runner:

Which have been fixed since then.

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)
})