From b67073a4a6288be5bc61fcbe0fd308f25075c31f Mon Sep 17 00:00:00 2001 From: JGAntunes Date: Mon, 27 Nov 2023 12:09:07 +0000 Subject: [PATCH 1/6] fix: handle missing angular dependencis error --- package.json | 3 +- src/helpers/validateAngularVersion.js | 12 ++++-- .../missing-angular-deps/netlify.toml | 6 +++ .../missing-angular-deps/package-lock.json | 41 +++++++++++++++++++ .../missing-angular-deps/package.json | 12 ++++++ tests/integration.test.mjs | 11 ++++- 6 files changed, 80 insertions(+), 5 deletions(-) create mode 100644 tests/fixtures/missing-angular-deps/netlify.toml create mode 100644 tests/fixtures/missing-angular-deps/package-lock.json create mode 100644 tests/fixtures/missing-angular-deps/package.json diff --git a/package.json b/package.json index fc72d411..6b814fff 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,8 @@ "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: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" }, diff --git a/src/helpers/validateAngularVersion.js b/src/helpers/validateAngularVersion.js index 79f95ac5..52a057dc 100644 --- a/src/helpers/validateAngularVersion.js +++ b/src/helpers/validateAngularVersion.js @@ -7,9 +7,15 @@ const { satisfies } = require('semver') * @returns {Promise} */ 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 { + packagePath = require.resolve('@angular/core/package.json', { paths: [root] }) + if (!packagePath) { + console.warn('This site does not seem to be using Angular.') + return false + } + } catch (err) { + // module not found console.warn('This site does not seem to be using Angular.') return false } diff --git a/tests/fixtures/missing-angular-deps/netlify.toml b/tests/fixtures/missing-angular-deps/netlify.toml new file mode 100644 index 00000000..19ba21e3 --- /dev/null +++ b/tests/fixtures/missing-angular-deps/netlify.toml @@ -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" diff --git a/tests/fixtures/missing-angular-deps/package-lock.json b/tests/fixtures/missing-angular-deps/package-lock.json new file mode 100644 index 00000000..43970fce --- /dev/null +++ b/tests/fixtures/missing-angular-deps/package-lock.json @@ -0,0 +1,41 @@ +{ + "name": "missing-angular-deps", + "version": "0.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "missing-angular-deps", + "version": "0.0.0", + "dependencies": { + "@netlify/angular-runtime": "file:../../../" + }, + "devDependencies": {} + }, + "../../..": { + "version": "2.0.3", + "license": "MIT", + "dependencies": { + "fs-extra": "^11.1.1", + "semver": "^7.5.4" + }, + "devDependencies": { + "@netlify/build": "^29.28.2", + "@netlify/eslint-config-node": "^7.0.1", + "@types/node": "^16.3.1", + "eslint-plugin-unicorn": "^49.0.0", + "husky": "^4.3.0", + "netlify-cli": "^17.2.0", + "npm-run-all": "^4.1.5", + "prettier": "^2.1.2" + }, + "engines": { + "node": ">=18.13.0" + } + }, + "node_modules/@netlify/angular-runtime": { + "resolved": "../../..", + "link": true + } + } +} diff --git a/tests/fixtures/missing-angular-deps/package.json b/tests/fixtures/missing-angular-deps/package.json new file mode 100644 index 00000000..9336def3 --- /dev/null +++ b/tests/fixtures/missing-angular-deps/package.json @@ -0,0 +1,12 @@ +{ + "name": "missing-angular-deps", + "version": "0.0.0", + "scripts": { + "build": "echo hello!" + }, + "private": true, + "dependencies": { + "@netlify/angular-runtime": "file:../../../" + }, + "devDependencies": {} +} diff --git a/tests/integration.test.mjs b/tests/integration.test.mjs index 706cd0f1..91bfcbb1 100644 --- a/tests/integration.test.mjs +++ b/tests/integration.test.mjs @@ -3,7 +3,7 @@ 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.json 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)), }) @@ -11,3 +11,12 @@ test('non angular project fails the plugin execution but does not error', async 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) +}) From 4645070e7b6fc99b8fdcd7971f61be2d0bb135bf Mon Sep 17 00:00:00 2001 From: JGAntunes Date: Mon, 27 Nov 2023 12:11:09 +0000 Subject: [PATCH 2/6] chore: make linter happy --- src/helpers/validateAngularVersion.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/helpers/validateAngularVersion.js b/src/helpers/validateAngularVersion.js index 52a057dc..82035a75 100644 --- a/src/helpers/validateAngularVersion.js +++ b/src/helpers/validateAngularVersion.js @@ -9,12 +9,13 @@ const { satisfies } = require('semver') const validateAngularVersion = async function (root) { let packagePath try { + // eslint-disable-next-line n/no-missing-require packagePath = require.resolve('@angular/core/package.json', { paths: [root] }) if (!packagePath) { console.warn('This site does not seem to be using Angular.') return false } - } catch (err) { + } catch { // module not found console.warn('This site does not seem to be using Angular.') return false From 3662eee487de6bccbd3cf3a24b772b3b79fa12b8 Mon Sep 17 00:00:00 2001 From: JGAntunes Date: Mon, 27 Nov 2023 16:38:15 +0000 Subject: [PATCH 3/6] chore: remove dead code and fix pretest scripts --- package.json | 3 ++- src/helpers/validateAngularVersion.js | 4 ---- tests/integration.test.mjs | 2 +- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index 6b814fff..ac9b7903 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "prepublishOnly:pull": "git pull", "prepublishOnly:install": "npm ci", "prepublishOnly:test": "npm test", - "pretest:demo": "cd demo && npm ci && netlify build --cwd . --offline && cd ..", + "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:*", diff --git a/src/helpers/validateAngularVersion.js b/src/helpers/validateAngularVersion.js index 82035a75..eecb6452 100644 --- a/src/helpers/validateAngularVersion.js +++ b/src/helpers/validateAngularVersion.js @@ -11,10 +11,6 @@ const validateAngularVersion = async function (root) { try { // eslint-disable-next-line n/no-missing-require packagePath = require.resolve('@angular/core/package.json', { paths: [root] }) - if (!packagePath) { - console.warn('This site does not seem to be using Angular.') - return false - } } catch { // module not found console.warn('This site does not seem to be using Angular.') diff --git a/tests/integration.test.mjs b/tests/integration.test.mjs index 91bfcbb1..2060b875 100644 --- a/tests/integration.test.mjs +++ b/tests/integration.test.mjs @@ -3,7 +3,7 @@ import assert from 'node:assert' import { test } from 'node:test' import { fileURLToPath } from 'node:url' -test('project without angular.json fails the plugin execution but does not error', async () => { +test('project without `angular.json` 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)), }) From 6879cbe9f7e4f1d0c270d6afbefa55d7827e0242 Mon Sep 17 00:00:00 2001 From: JGAntunes Date: Mon, 27 Nov 2023 17:17:35 +0000 Subject: [PATCH 4/6] fix: node test runner is not fond of non-ASCII chars --- tests/integration.test.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration.test.mjs b/tests/integration.test.mjs index 2060b875..91bfcbb1 100644 --- a/tests/integration.test.mjs +++ b/tests/integration.test.mjs @@ -3,7 +3,7 @@ import assert from 'node:assert' import { test } from 'node:test' import { fileURLToPath } from 'node:url' -test('project without `angular.json` fails the plugin execution but does not error', async () => { +test('project without angular.json 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)), }) From bdfebd4a76ab6f30aabdb698abdc7c1707ada293 Mon Sep 17 00:00:00 2001 From: JGAntunes Date: Mon, 27 Nov 2023 17:22:24 +0000 Subject: [PATCH 5/6] fix: node test runner is still unhappy --- tests/integration.test.mjs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration.test.mjs b/tests/integration.test.mjs index 91bfcbb1..3dc8714d 100644 --- a/tests/integration.test.mjs +++ b/tests/integration.test.mjs @@ -3,7 +3,7 @@ import assert from 'node:assert' import { test } from 'node:test' import { fileURLToPath } from 'node:url' -test('project without angular.json 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)), }) From 72226d97ab062639230f17c9892947a521e1dda5 Mon Sep 17 00:00:00 2001 From: JGAntunes Date: Mon, 27 Nov 2023 17:47:21 +0000 Subject: [PATCH 6/6] chore: bump CI v18 node version because of node test runner problems --- .github/workflows/test.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d9d233b7..225d549f 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -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: