-
Notifications
You must be signed in to change notification settings - Fork 6k
fix(config): don't exclude workspace members from deploy file patterns #33562
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
Merged
+255
−1
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
bd90aab
fix(config): don't exclude workspace members from deploy file patterns
avocet-bot 4245eab
Update libs/config/workspace/mod.rs
magurotuna 4322af7
Update libs/config/workspace/mod.rs
magurotuna ea3e9ab
address review: remove verbose comment, fix formatting
avocet-bot 0f3a09c
Merge branch 'main' into fix/deploy-config-workspace-files
magurotuna 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 hidden or 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 |
|---|---|---|
|
|
@@ -2423,7 +2423,11 @@ impl WorkspaceDirectory { | |
| }; | ||
| self.exclude_includes_with_member_for_base_for_root(&mut config.files); | ||
| combine_files_config_with_cli_args(&mut config.files, cli_args); | ||
| self.append_workspace_members_to_exclude(&mut config.files); | ||
| // NOTE: Unlike lint/fmt/test/bench/publish configs, deploy should NOT | ||
| // exclude workspace member directories. When deploying from a workspace | ||
| // root, all member files need to be included in the upload manifest. | ||
| // Previously this called append_workspace_members_to_exclude here, which | ||
| // caused `deno deploy` to upload zero files for workspace monorepos | ||
| Ok(Some(config)) | ||
| } | ||
|
|
||
|
|
@@ -6558,4 +6562,269 @@ pub mod test { | |
| .trim_end_matches('/'), | ||
| ) | ||
| } | ||
|
|
||
| // --- Deploy config tests --- | ||
|
|
||
| #[test] | ||
| fn test_deploy_config_in_root_does_not_exclude_members() { | ||
| // Regression test: when deploy config is in the workspace root and the | ||
| // user runs `deno deploy` from the root, workspace member directories | ||
| // should NOT be excluded from the file patterns. | ||
| let sys = InMemorySys::default(); | ||
| let root_config = root_dir().join("deno.json"); | ||
| sys.fs_insert_json( | ||
| root_config.clone(), | ||
| json!({ | ||
| "workspace": ["./packages/backend", "./packages/types"], | ||
| "deploy": { | ||
| "org": "myorg", | ||
| "app": "myapp" | ||
| } | ||
| }), | ||
| ); | ||
| sys.fs_insert_json( | ||
| root_dir().join("packages/backend/deno.json"), | ||
| json!({ | ||
| "version": "0.1.0", | ||
| "exclude": ["coverage/"] | ||
| }), | ||
| ); | ||
| sys.fs_insert( | ||
| root_dir().join("packages/backend/main.ts"), | ||
| "Deno.serve(() => new Response('hello'));", | ||
| ); | ||
| sys.fs_insert_json( | ||
| root_dir().join("packages/types/deno.json"), | ||
| json!({ | ||
| "name": "@myapp/types", | ||
| "exports": "./mod.ts" | ||
| }), | ||
| ); | ||
| sys.fs_insert( | ||
| root_dir().join("packages/types/mod.ts"), | ||
| "export type Foo = string;", | ||
| ); | ||
|
|
||
| // Discover from workspace root | ||
| let workspace_dir = workspace_at_start_dir(&sys, &root_dir()); | ||
| let deploy_config = workspace_dir | ||
| .to_deploy_config(FilePatterns::new_with_base(workspace_dir.dir_path())) | ||
| .unwrap(); | ||
|
|
||
| assert!(deploy_config.is_some(), "deploy config should be resolved"); | ||
| let deploy_config = deploy_config.unwrap(); | ||
| assert_eq!(deploy_config.org, "myorg"); | ||
| assert_eq!(deploy_config.app, Some("myapp".to_string())); | ||
|
|
||
| // The critical check: workspace member paths must NOT be excluded | ||
| let backend_dir = root_dir().join("packages/backend"); | ||
| let types_dir = root_dir().join("packages/types"); | ||
| assert!( | ||
| deploy_config | ||
| .files | ||
| .matches_path(&backend_dir, PathKind::Directory), | ||
| "packages/backend should not be excluded from deploy files" | ||
| ); | ||
| assert!( | ||
| deploy_config | ||
| .files | ||
| .matches_path(&types_dir, PathKind::Directory), | ||
| "packages/types should not be excluded from deploy files" | ||
| ); | ||
| assert!( | ||
| deploy_config | ||
| .files | ||
|
Contributor
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. This (and the analogous blocks at ~6688, ~6764, ~6790, ~6798) is the formatting CI is rejecting. dprint wants the |
||
| .matches_path( | ||
| &root_dir().join("packages/backend/main.ts"), | ||
| PathKind::File, | ||
| ), | ||
| "packages/backend/main.ts should be included in deploy files" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_deploy_config_in_both_root_and_member() { | ||
| // When both root and member have deploy configs, running from the | ||
| // member directory should resolve the deploy config and not exclude | ||
| // member files. | ||
| let sys = InMemorySys::default(); | ||
| sys.fs_insert_json( | ||
| root_dir().join("deno.json"), | ||
| json!({ | ||
| "workspace": ["./member"], | ||
| "deploy": { | ||
| "org": "rootorg" | ||
| } | ||
| }), | ||
| ); | ||
| sys.fs_insert_json( | ||
| root_dir().join("member/deno.json"), | ||
| json!({ | ||
| "deploy": { | ||
| "org": "myorg", | ||
| "app": "myapp" | ||
| } | ||
| }), | ||
| ); | ||
| sys.fs_insert( | ||
| root_dir().join("member/main.ts"), | ||
| "Deno.serve(() => new Response('hello'));", | ||
| ); | ||
|
|
||
| let workspace_dir = | ||
| workspace_at_start_dir(&sys, &root_dir().join("member")); | ||
| let deploy_config = workspace_dir | ||
| .to_deploy_config(FilePatterns::new_with_base(workspace_dir.dir_path())) | ||
| .unwrap(); | ||
|
|
||
| assert!(deploy_config.is_some(), "deploy config should be resolved"); | ||
| let deploy_config = deploy_config.unwrap(); | ||
| // Member's org takes precedence over root's | ||
| assert_eq!(deploy_config.org, "myorg"); | ||
|
|
||
| // Member's own files must match | ||
| assert!( | ||
| deploy_config.files.matches_path( | ||
| &root_dir().join("member/main.ts"), | ||
| PathKind::File, | ||
| ), | ||
| "member/main.ts should be included" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_deploy_config_root_only_no_member_deploy() { | ||
| // deploy:{org,app} in root, NO deploy in any member. | ||
| // When running from root, to_deploy_config should return Some. | ||
| let sys = InMemorySys::default(); | ||
| sys.fs_insert_json( | ||
| root_dir().join("deno.json"), | ||
| json!({ | ||
| "workspace": [ | ||
| "./packages/backend", | ||
| "./packages/types", | ||
| "./packages/schema" | ||
| ], | ||
| "deploy": { | ||
| "org": "sfdevtools", | ||
| "app": "prod" | ||
| } | ||
| }), | ||
| ); | ||
| sys.fs_insert_json( | ||
| root_dir().join("packages/backend/deno.json"), | ||
| json!({ "version": "0.1.0" }), | ||
| ); | ||
| sys.fs_insert( | ||
| root_dir().join("packages/backend/main.ts"), | ||
| "Deno.serve(() => new Response('hello'));", | ||
| ); | ||
| sys.fs_insert_json( | ||
| root_dir().join("packages/types/deno.json"), | ||
| json!({ "name": "@myapp/types", "exports": "./mod.ts" }), | ||
| ); | ||
| sys.fs_insert( | ||
| root_dir().join("packages/types/mod.ts"), | ||
| "export type Foo = string;", | ||
| ); | ||
| sys.fs_insert_json( | ||
| root_dir().join("packages/schema/deno.json"), | ||
| json!({ "name": "@myapp/schema", "exports": "./mod.ts" }), | ||
| ); | ||
| sys.fs_insert( | ||
| root_dir().join("packages/schema/mod.ts"), | ||
| "export const VERSION = 1;", | ||
| ); | ||
|
|
||
| let workspace_dir = workspace_at_start_dir(&sys, &root_dir()); | ||
| let deploy_config = workspace_dir | ||
| .to_deploy_config(FilePatterns::new_with_base(workspace_dir.dir_path())) | ||
| .unwrap(); | ||
|
|
||
| assert!( | ||
| deploy_config.is_some(), | ||
| "deploy config should be resolved when only root has deploy field" | ||
| ); | ||
| let deploy_config = deploy_config.unwrap(); | ||
| assert_eq!(deploy_config.org, "sfdevtools"); | ||
|
|
||
| // All workspace member directories must be accessible | ||
| for member in &["packages/backend", "packages/types", "packages/schema"] { | ||
| let member_dir = root_dir().join(member); | ||
| assert!( | ||
| deploy_config | ||
| .files | ||
| .matches_path(&member_dir, PathKind::Directory), | ||
| "{member} should not be excluded from deploy files" | ||
| ); | ||
| } | ||
| // Entrypoint must be accessible | ||
| assert!( | ||
| deploy_config | ||
| .files | ||
| .matches_path( | ||
| &root_dir().join("packages/backend/main.ts"), | ||
| PathKind::File, | ||
| ), | ||
| "packages/backend/main.ts must be included" | ||
| ); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_deploy_config_with_exclude() { | ||
| // Deploy config with explicit exclude should respect it but not | ||
| // additionally exclude workspace members. | ||
| let sys = InMemorySys::default(); | ||
| sys.fs_insert_json( | ||
| root_dir().join("deno.json"), | ||
| json!({ | ||
| "workspace": ["./packages/backend", "./packages/types"], | ||
| "exclude": ["docs/"], | ||
| "deploy": { | ||
| "org": "myorg", | ||
| "app": "myapp" | ||
| } | ||
| }), | ||
| ); | ||
| sys.fs_insert_json( | ||
| root_dir().join("packages/backend/deno.json"), | ||
| json!({}), | ||
| ); | ||
| sys.fs_insert( | ||
| root_dir().join("packages/backend/main.ts"), | ||
| "Deno.serve(() => new Response('hello'));", | ||
| ); | ||
| sys.fs_insert_json( | ||
| root_dir().join("packages/types/deno.json"), | ||
| json!({}), | ||
| ); | ||
| sys.fs_insert( | ||
| root_dir().join("packages/types/mod.ts"), | ||
| "export type Foo = string;", | ||
| ); | ||
|
|
||
| let workspace_dir = workspace_at_start_dir(&sys, &root_dir()); | ||
| let deploy_config = workspace_dir | ||
| .to_deploy_config(FilePatterns::new_with_base(workspace_dir.dir_path())) | ||
| .unwrap(); | ||
|
|
||
| assert!(deploy_config.is_some()); | ||
| let deploy_config = deploy_config.unwrap(); | ||
|
|
||
| // Workspace members should NOT be excluded | ||
| assert!( | ||
| deploy_config.files.matches_path( | ||
| &root_dir().join("packages/backend/main.ts"), | ||
| PathKind::File, | ||
| ), | ||
| "workspace member files should not be excluded" | ||
| ); | ||
| // docs/ should be excluded (from top-level exclude) | ||
| assert!( | ||
| !deploy_config | ||
| .files | ||
| .matches_path(&root_dir().join("docs/readme.md"), PathKind::File), | ||
| "docs/ should be excluded" | ||
| ); | ||
| } | ||
| } | ||
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.
Worth covering: when
deno deployis run from the workspace root and a workspace member has its owndeploy: { ... }block, what's the expected behavior?to_deploy_config_innertakesmember_configfromself.deno_json.member.to_deploy_config(). From root, that's the root deno.json itself, somember_config.filesis the root's file patterns (which after this fix include all members).deploy: { app: "frontend" }) gets its files swept into the root's deploy upload anyway.Is that the intended behavior, or should a member that opts into its own deploy config be excluded from a root-level deploy (so it can be deployed separately)? The existing test
test_deploy_config_in_both_root_and_memberonly runs from the member directory, so it doesn't exercise this path. The pre-PR behavior happened to exclude all members unconditionally (broken in the simple case, but accidentally also handled this case). Now the simple case works; this edge case may need its own handling.Not a blocker — could be a follow-up if you confirm it's intended that root-level
deno deployalways sweeps everything in.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.
Good callout. Yes, this is intentional — it matches pre-0.0.93 behavior where TypeScript
walk()uploaded everything under workspace root.The member-with-its-own-deploy-config case is real but: (1) root-level deploy doesn't know about member-specific deploy targets, (2) uploading extra files is wasteful but not incorrect since the server uses entrypoint + working directory, (3) users can scope with
include.Handling this properly (exclude members that declare their own deploy config from root-level deploys) is a good follow-up but shouldn't block this regression fix.