Skip to content

Commit

Permalink
fix: support deploy config API in monorepos (#5543)
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardoboucas committed Mar 11, 2024
1 parent 22c4d12 commit cc36c3b
Show file tree
Hide file tree
Showing 10 changed files with 62 additions and 1 deletion.
3 changes: 2 additions & 1 deletion packages/build/src/plugins_core/deploy_config/index.ts
Expand Up @@ -17,11 +17,12 @@ const ALLOWED_PROPERTIES = [['images', 'remote_images']]
const coreStep: CoreStepFunction = async function ({
buildDir,
netlifyConfig,
packagePath,
systemLog = () => {
// no-op
},
}) {
const configPath = resolve(buildDir, '.netlify/deploy/v1/config.json')
const configPath = resolve(buildDir, packagePath ?? '', '.netlify/deploy/v1/config.json')

let config: Partial<NetlifyConfig> = {}

Expand Down
@@ -0,0 +1,10 @@
import { mkdir, writeFile } from 'node:fs/promises'

const config = {
images: {
remote_images: ["domain1.netlify", "domain2.netlify"]
}
}

await mkdir('.netlify/deploy/v1', { recursive: true });
await writeFile('.netlify/deploy/v1/config.json', JSON.stringify(config));
@@ -0,0 +1,3 @@
[build]
command = "pnpm --filter app-1 build"
publish = "apps/app-1/dist"
@@ -0,0 +1,6 @@
{
"name": "app-1",
"scripts": {
"build": "node build.mjs"
}
}
@@ -0,0 +1,10 @@
import { mkdir, writeFile } from 'node:fs/promises'

const config = {
images: {
remote_images: ["domain3.netlify", "domain4.netlify"]
}
}

await mkdir('.netlify/deploy/v1', { recursive: true });
await writeFile('.netlify/deploy/v1/config.json', JSON.stringify(config));
@@ -0,0 +1,3 @@
[build]
command = "pnpm --filter app-2 build"
publish = "apps/app-2/dist"
@@ -0,0 +1,6 @@
{
"name": "app-2",
"scripts": {
"build": "node build.mjs"
}
}
@@ -0,0 +1,4 @@
{
"name": "monorepo",
"type": "module"
}
@@ -0,0 +1,2 @@
packages:
- 'apps/*'
16 changes: 16 additions & 0 deletions packages/build/tests/deploy_config/tests.js
Expand Up @@ -43,6 +43,22 @@ test('Loads configuration data that has been generated by the build command', as
}
})

test('In a monorepo setup, loads package-specific configuration data', async (t) => {
const fixture = await new Fixture('./fixtures/monorepo').withCopyRoot({ git: false })
const { success, netlifyConfig } = await fixture
.withFlags({
cwd: fixture.repositoryRoot,
featureFlags: { netlify_build_deploy_configuration_api: true },
packagePath: 'apps/app-1',
})
.runBuildProgrammatic()

t.true(success)
t.deepEqual(netlifyConfig.images, {
remote_images: ['domain1.netlify', 'domain2.netlify'],
})
})

test('Configuration data is exposed to build plugins in the `onBuild` event', async (t) => {
const { netlifyConfig, success } = await new Fixture('./fixtures/with_build_plugin')
.withFlags({
Expand Down

0 comments on commit cc36c3b

Please sign in to comment.