-
Notifications
You must be signed in to change notification settings - Fork 56
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
feat: Frameworks API cleanup #5737
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
ce2fe0d
refactor: rename `deploy_config` to `frameworks_api`
eduardoboucas 9fafe15
chore: rename `deploy_config` tests to `framework_api`
eduardoboucas 7068df1
feat: clean up Frameworks API directory before build
eduardoboucas 1b3892e
refactor: replace `forEach` with `map`
eduardoboucas 23d678b
chore: remove `.only`
eduardoboucas d5c4629
chore: update tests
eduardoboucas dbc40d6
chore: update snapshots
eduardoboucas f849de2
chore: fix tests
eduardoboucas 7116931
fix: give precedence to functions from Frameworks API
eduardoboucas 3ebe12e
fix: give precedence to edge functions from Frameworks API
eduardoboucas 09c9929
chore: update tests
eduardoboucas 558c13e
Merge branch 'main' into feat/frameworks-api-cleanup
eduardoboucas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,27 @@ | ||
import { rm } from 'node:fs/promises' | ||
import { resolve } from 'node:path' | ||
|
||
import { scanForBlobs, getBlobsDirs } from '../../utils/blobs.js' | ||
import { CoreStep, CoreStepCondition, CoreStepFunction } from '../types.js' | ||
import { getBlobsDirs } from '../../utils/blobs.js' | ||
import { FRAMEWORKS_API_ENDPOINT } from '../../utils/frameworks_api.js' | ||
import { CoreStep, CoreStepFunction } from '../types.js' | ||
|
||
const coreStep: CoreStepFunction = async ({ buildDir, packagePath }) => { | ||
const blobsDirs = getBlobsDirs(buildDir, packagePath) | ||
const dirs = [...getBlobsDirs(buildDir, packagePath), resolve(buildDir, packagePath || '', FRAMEWORKS_API_ENDPOINT)] | ||
|
||
try { | ||
await Promise.all(blobsDirs.map((dir) => rm(dir, { recursive: true, force: true }))) | ||
await Promise.all(dirs.map((dir) => rm(dir, { recursive: true, force: true }))) | ||
} catch { | ||
// Ignore errors if it fails, we can continue anyway. | ||
} | ||
|
||
return {} | ||
} | ||
|
||
const blobsPresent: CoreStepCondition = async ({ buildDir, packagePath }) => | ||
Boolean(await scanForBlobs(buildDir, packagePath)) | ||
|
||
export const preCleanup: CoreStep = { | ||
event: 'onPreBuild', | ||
coreStep, | ||
coreStepId: 'pre_cleanup', | ||
coreStepName: 'Pre cleanup', | ||
coreStepDescription: () => 'Cleaning up leftover files from previous builds', | ||
condition: blobsPresent, | ||
quiet: true, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,14 +107,13 @@ const METADATA_SUFFIX = '.json' | |
* path to its metadata file. | ||
*/ | ||
export const getKeysToUpload = async (blobsDir: string) => { | ||
const blobsToUpload: { key: string; contentPath: string; metadataPath: string }[] = [] | ||
const files = await new fdir() | ||
.withRelativePaths() // we want the relative path from the blobsDir | ||
.filter((fpath) => !path.basename(fpath).startsWith(METADATA_PREFIX)) | ||
.crawl(blobsDir) | ||
.withPromise() | ||
|
||
files.forEach((filePath) => { | ||
return files.map((filePath) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks ❤️ |
||
const key = filePath.split(path.sep).join('/') | ||
const contentPath = path.resolve(blobsDir, filePath) | ||
const basename = path.basename(filePath) | ||
|
@@ -124,14 +123,12 @@ export const getKeysToUpload = async (blobsDir: string) => { | |
`${METADATA_PREFIX}${basename}${METADATA_SUFFIX}`, | ||
) | ||
|
||
blobsToUpload.push({ | ||
return { | ||
key, | ||
contentPath, | ||
metadataPath, | ||
}) | ||
} | ||
}) | ||
|
||
return blobsToUpload | ||
} | ||
|
||
/** Read a file and its metadata file from the blobs directory */ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
5 changes: 0 additions & 5 deletions
5
...ild/tests/deploy_config/fixtures/from_build_command_legacy/.netlify/deploy/v1/config.json
This file was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
packages/build/tests/deploy_config/fixtures/malformed_config/.netlify/v1/config.json
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
packages/build/tests/deploy_config/fixtures/with_build_plugin/.netlify/v1/config.json
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
packages/build/tests/edge_functions/fixtures/functions_user_framework/build.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { cp } from 'node:fs/promises' | ||
import { resolve } from "node:path" | ||
|
||
await cp(resolve("frameworks_api_seed"), resolve(".netlify/v1"), { recursive: true }) |
9 changes: 9 additions & 0 deletions
9
...ctions/fixtures/functions_user_framework/frameworks_api_seed/edge-functions/function-2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { greeting } from "greeting" | ||
|
||
export default async () => new Response(greeting) | ||
|
||
export const config = { | ||
excludedPath: "/framework/skip_*", | ||
generator: "Hello", | ||
path: "/framework/*" | ||
} |
5 changes: 5 additions & 0 deletions
5
...ions/fixtures/functions_user_framework/frameworks_api_seed/edge-functions/import_map.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"imports": { | ||
"greeting": "./util/greeting.ts" | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ons/fixtures/functions_user_framework/frameworks_api_seed/edge-functions/util/greeting.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const greeting = "Hello world" |
2 changes: 2 additions & 0 deletions
2
packages/build/tests/edge_functions/fixtures/functions_user_framework/netlify.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[build] | ||
command = "node build.mjs" |
5 changes: 5 additions & 0 deletions
5
...functions_user_internal_framework/.netlify/edge-functions/frameworks-internal-conflict.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default async () => new Response("Generated in the legacy internal directory") | ||
|
||
export const config = { | ||
path: "/frameworks-internal-conflict/internal" | ||
} |
5 changes: 5 additions & 0 deletions
5
...ctions_user_internal_framework/.netlify/v1/edge-functions/frameworks-internal-conflict.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default async () => new Response("Generated by the Frameworks API") | ||
|
||
export const config = { | ||
path: "/frameworks-internal-conflict/frameworks" | ||
} |
5 changes: 5 additions & 0 deletions
5
.../functions_user_internal_framework/.netlify/v1/edge-functions/frameworks-user-conflict.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default async () => new Response("Generated by the Frameworks API") | ||
|
||
export const config = { | ||
path: "/frameworks-user-conflict/frameworks" | ||
} |
4 changes: 4 additions & 0 deletions
4
packages/build/tests/edge_functions/fixtures/functions_user_internal_framework/build.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { cp } from 'node:fs/promises' | ||
import { resolve } from "node:path" | ||
|
||
await cp(resolve("frameworks_api_seed"), resolve(".netlify/v1"), { recursive: true }) |
5 changes: 5 additions & 0 deletions
5
...ser_internal_framework/frameworks_api_seed/edge-functions/frameworks-internal-conflict.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default async () => new Response("Generated by the Frameworks API") | ||
|
||
export const config = { | ||
path: "/frameworks-internal-conflict/frameworks" | ||
} |
5 changes: 5 additions & 0 deletions
5
...ns_user_internal_framework/frameworks_api_seed/edge-functions/frameworks-user-conflict.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default async () => new Response("Generated by the Frameworks API") | ||
|
||
export const config = { | ||
path: "/frameworks-user-conflict/frameworks" | ||
} |
9 changes: 9 additions & 0 deletions
9
...xtures/functions_user_internal_framework/frameworks_api_seed/edge-functions/function-2.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { greeting } from "greeting" | ||
|
||
export default async () => new Response(greeting) | ||
|
||
export const config = { | ||
excludedPath: "/framework/skip_*", | ||
generator: "Hello", | ||
path: "/framework/*" | ||
} |
5 changes: 5 additions & 0 deletions
5
...ures/functions_user_internal_framework/frameworks_api_seed/edge-functions/import_map.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"imports": { | ||
"greeting": "./util/greeting.ts" | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...res/functions_user_internal_framework/frameworks_api_seed/edge-functions/util/greeting.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const greeting = "Hello world" |
2 changes: 2 additions & 0 deletions
2
packages/build/tests/edge_functions/fixtures/functions_user_internal_framework/netlify.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[build] | ||
command = "node build.mjs" |
5 changes: 5 additions & 0 deletions
5
...ures/functions_user_internal_framework/netlify/edge-functions/frameworks-user-conflict.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export default async () => new Response("Generated by the user") | ||
|
||
export const config = { | ||
path: "/frameworks-user-conflict/user" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+71 Bytes
(100%)
packages/build/tests/edge_functions/snapshots/tests.js.snap
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means that this core step will now run for all builds as opposed to only running if there are blobs directories. That is fine, since calling
rm()
on a directory that doesn't exist will not throw here, and we have atry/catch
around the calls anyway.