Skip to content

Commit 09463eb

Browse files
authored
fix: centralize build plugin auto-enable escape hatches (#6777)
1 parent ef6aea3 commit 09463eb

File tree

6 files changed

+62
-6
lines changed

6 files changed

+62
-6
lines changed

packages/build-info/src/frameworks/angular.test.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, expect, test } from 'vitest'
1+
import { afterEach, beforeEach, expect, test, vi } from 'vitest'
22

33
import { mockFileSystem } from '../../tests/mock-file-system.js'
44
import { NodeFS } from '../node/file-system.js'
@@ -8,6 +8,10 @@ beforeEach((ctx) => {
88
ctx.fs = new NodeFS()
99
})
1010

11+
afterEach(() => {
12+
vi.unstubAllEnvs()
13+
})
14+
1115
test('should detect Angular', async ({ fs }) => {
1216
const cwd = mockFileSystem({
1317
'package.json': JSON.stringify({ dependencies: { '@angular/cli': '17.0.0' } }),
@@ -66,3 +70,27 @@ test('should only install plugin on v17+', async ({ fs }) => {
6670
expect(detected?.[0].build.directory).toBe('dist/')
6771
expect(detected?.[0].plugins).toEqual([])
6872
})
73+
74+
test('should not install plugin when NETLIFY_ANGULAR_PLUGIN_SKIP is set', async ({ fs }) => {
75+
const cwd = mockFileSystem({
76+
'package.json': JSON.stringify({ dependencies: { '@angular/cli': '17.0.0' } }),
77+
'angular.json': JSON.stringify({
78+
projects: {
79+
demo: {
80+
architect: {
81+
build: {
82+
builder: '@angular-devkit/build-angular:application',
83+
options: {
84+
outputPath: 'dist/demo',
85+
},
86+
},
87+
},
88+
},
89+
},
90+
}),
91+
})
92+
vi.stubEnv('NETLIFY_ANGULAR_PLUGIN_SKIP', 'true')
93+
const detected = await new Project(fs, cwd).detectFrameworks()
94+
expect(detected?.[0].id).toBe('angular')
95+
expect(detected?.[0].plugins).toHaveLength(0)
96+
})

packages/build-info/src/frameworks/angular.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class Angular extends BaseFramework implements Framework {
3131
await super.detect()
3232

3333
if (this.detected) {
34-
if (this.version && gte(this.version, '17.0.0-rc')) {
34+
if (this.version && gte(this.version, '17.0.0-rc') && !process.env.NETLIFY_ANGULAR_PLUGIN_SKIP) {
3535
this.plugins.push('@netlify/angular-runtime')
3636
const angularJson = await this.project.fs.gracefullyReadFile('angular.json')
3737
if (angularJson) {

packages/build-info/src/frameworks/gatsby.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { beforeEach, expect, test } from 'vitest'
1+
import { afterEach, beforeEach, expect, test, vi } from 'vitest'
22

33
import { mockFileSystem } from '../../tests/mock-file-system.js'
44
import { NodeFS } from '../node/file-system.js'
@@ -8,6 +8,10 @@ beforeEach((ctx) => {
88
ctx.fs = new NodeFS()
99
})
1010

11+
afterEach(() => {
12+
vi.unstubAllEnvs()
13+
})
14+
1115
test('should not add the plugin if the node version is below 12.13.0', async ({ fs }) => {
1216
const cwd = mockFileSystem({
1317
'package.json': JSON.stringify({ dependencies: { gatsby: '^4.0.0' } }),
@@ -89,3 +93,15 @@ test('should detect a simple Gatsby 5 project', async ({ fs }) => {
8993
}),
9094
)
9195
})
96+
97+
test('should not add the plugin if NETLIFY_SKIP_GATSBY_BUILD_PLUGIN is set', async ({ fs }) => {
98+
const cwd = mockFileSystem({
99+
'package.json': JSON.stringify({ dependencies: { gatsby: '^4.0.0' } }),
100+
'gatsby-config.js': '',
101+
})
102+
fs.cwd = cwd
103+
vi.stubEnv('NETLIFY_SKIP_GATSBY_BUILD_PLUGIN', 'true')
104+
const detected = await new Project(fs, cwd).setNodeVersion('12.13.0').detectFrameworks()
105+
expect(detected?.[0].id).toBe('gatsby')
106+
expect(detected?.[0].plugins).toHaveLength(0)
107+
})

packages/build-info/src/frameworks/gatsby.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export class Gatsby extends BaseFramework implements Framework {
4444
}
4545

4646
const nodeVersion = await this.project.getCurrentNodeVersion()
47-
if (nodeVersion && gte(nodeVersion, '12.13.0')) {
47+
if (nodeVersion && gte(nodeVersion, '12.13.0') && !process.env.NETLIFY_SKIP_GATSBY_BUILD_PLUGIN) {
4848
this.plugins.push('@netlify/plugin-gatsby')
4949
}
5050
return this as DetectedFramework

packages/build-info/src/frameworks/next.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { join } from 'path'
22

3-
import { beforeEach, describe, expect, test } from 'vitest'
3+
import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'
44

55
import { createFixture } from '../../tests/helpers.js'
66
import { mockFileSystem } from '../../tests/mock-file-system.js'
@@ -34,6 +34,10 @@ describe('Next.js Plugin', () => {
3434
})
3535
})
3636

37+
afterEach(() => {
38+
vi.unstubAllEnvs()
39+
})
40+
3741
test('Should detect Next.js plugin for Next.js if when Node version >= 10.13.0', async ({ fs, cwd }) => {
3842
const project = new Project(fs, cwd).setNodeVersion('v10.13.0')
3943
const frameworks = await project.detectFrameworks()
@@ -47,6 +51,14 @@ describe('Next.js Plugin', () => {
4751
expect(frameworks?.[0].id).toBe('next')
4852
expect(frameworks?.[0].plugins).toHaveLength(0)
4953
})
54+
55+
test('Should not install plugin when NETLIFY_NEXT_PLUGIN_SKIP is set', async ({ fs, cwd }) => {
56+
const project = new Project(fs, cwd).setNodeVersion('v10.13.0')
57+
vi.stubEnv('NETLIFY_NEXT_PLUGIN_SKIP', 'true')
58+
const frameworks = await project.detectFrameworks()
59+
expect(frameworks?.[0].id).toBe('next')
60+
expect(frameworks?.[0].plugins).toHaveLength(0)
61+
})
5062
})
5163

5264
describe('simple Next.js project', async () => {

packages/build-info/src/frameworks/next.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export class Next extends BaseFramework implements Framework {
3232

3333
if (this.detected) {
3434
const nodeVersion = await this.project.getCurrentNodeVersion()
35-
if (nodeVersion && gte(nodeVersion, '10.13.0')) {
35+
if (nodeVersion && gte(nodeVersion, '10.13.0') && !process.env.NETLIFY_NEXT_PLUGIN_SKIP) {
3636
this.plugins.push('@netlify/plugin-nextjs')
3737
}
3838
return this as DetectedFramework

0 commit comments

Comments
 (0)