Skip to content

Commit 3744b76

Browse files
authored
feat: default manifest source to manifest.json for Bolt Framework projects (#395)
* feat: default manifest source to local for non-Deno apps Change the default manifest source for non-Deno (Bolt) projects from ManifestSourceRemote to ManifestSourceLocal, aligning their behavior with Deno projects. * feat: fix preserving app manifest source when template sets it
1 parent 8e4c0aa commit 3744b76

4 files changed

Lines changed: 45 additions & 29 deletions

File tree

cmd/project/init.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
"strings"
2121

2222
"github.com/slackapi/slack-cli/cmd/app"
23-
"github.com/slackapi/slack-cli/internal/config"
2423
"github.com/slackapi/slack-cli/internal/pkg/create"
2524
"github.com/slackapi/slack-cli/internal/shared"
2625
"github.com/slackapi/slack-cli/internal/shared/types"
@@ -108,8 +107,7 @@ func projectInitCommandRunE(clients *shared.ClientFactory, cmd *cobra.Command, a
108107

109108
// Install the project dependencies, such as .slack/ and runtime packages
110109
// Existing projects initialized always default to config.ManifestSourceLocal.
111-
// The link command will switch it to config.ManifestSourceRemote
112-
_ = create.InstallProjectDependencies(ctx, clients, projectDirPath, config.ManifestSourceLocal)
110+
_ = create.InstallProjectDependencies(ctx, clients, projectDirPath)
113111

114112
// Add an existing app to the project
115113
err = app.LinkExistingApp(ctx, clients, &types.App{}, true)

cmd/project/init_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func Test_Project_InitCommand(t *testing.T) {
7272
require.Contains(t, output, "Added "+filepath.Join("project-name", ".slack"))
7373
require.Contains(t, output, "Added "+filepath.Join("project-name", ".slack", ".gitignore"))
7474
require.Contains(t, output, "Added "+filepath.Join("project-name", ".slack", "hooks.json"))
75-
require.Contains(t, output, `Updated config.json manifest source to "project" (local)`)
75+
require.Contains(t, output, `Updated app manifest source to "project" (local)`)
7676
// Assert prompt to add existing apps was called
7777
cm.IO.AssertCalled(
7878
t,

internal/pkg/create/create.go

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func Create(ctx context.Context, clients *shared.ClientFactory, createArgs Creat
156156

157157
// Install project dependencies to add CLI support and cache dev dependencies.
158158
// CLI created projects always default to config.ManifestSourceLocal.
159-
InstallProjectDependencies(ctx, clients, projectDirPath, config.ManifestSourceLocal)
159+
InstallProjectDependencies(ctx, clients, projectDirPath)
160160
clients.IO.PrintTrace(ctx, slacktrace.CreateDependenciesSuccess)
161161

162162
return appDirPath, nil
@@ -413,7 +413,6 @@ func InstallProjectDependencies(
413413
ctx context.Context,
414414
clients *shared.ClientFactory,
415415
projectDirPath string,
416-
manifestSource config.ManifestSource,
417416
) []string {
418417
var outputs []string
419418

@@ -516,30 +515,20 @@ func InstallProjectDependencies(
516515
}
517516
}
518517

519-
// Default manifest source to ManifestSourceLocal
520-
if !manifestSource.Exists() {
521-
manifestSource = config.ManifestSourceLocal
522-
}
523-
524-
// Set non-Deno (non-ROSI) projects to ManifestSourceRemote.
525-
// TODO: should check if Slack hosted project, but the SDKConfig has not been initialized yet.
526-
if clients.Runtime != nil {
527-
isDenoProject := strings.Contains(strings.ToLower(clients.Runtime.Name()), "deno")
528-
if !isDenoProject {
529-
manifestSource = config.ManifestSourceRemote
530-
}
518+
// Get the manifest source from the project-level config
519+
manifestSource, err := clients.Config.ProjectConfig.GetManifestSource(ctx)
520+
if err != nil {
521+
clients.IO.PrintDebug(ctx, "Error getting manifest source: %s", err)
531522
}
532523

533524
// Set "manifest.source" in .slack/config.json
534525
if err := config.SetManifestSource(ctx, clients.Fs, clients.Os, manifestSource); err != nil {
535526
clients.IO.PrintDebug(ctx, "Error setting manifest source in project-level config: %s", err)
536527
} else {
537-
configJSONFilename := config.ProjectConfigJSONFilename
538528
manifestSourceStyled := style.Highlight(manifestSource.Human())
539529

540530
outputs = append(outputs, fmt.Sprintf(
541-
"Updated %s manifest source to %s",
542-
configJSONFilename,
531+
"Updated app manifest source to %s",
543532
manifestSourceStyled,
544533
))
545534
}

internal/pkg/create/create_test.go

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,7 @@ func Test_Create_installProjectDependencies(t *testing.T) {
366366
experiments []string
367367
runtime string
368368
manifestSource config.ManifestSource
369+
expectedManifestSource config.ManifestSource
369370
existingFiles map[string]string
370371
expectedOutputs []string
371372
unexpectedOutputs []string
@@ -418,24 +419,38 @@ func Test_Create_installProjectDependencies(t *testing.T) {
418419
},
419420
"When no manifest source, default to project (local)": {
420421
expectedOutputs: []string{
421-
`Updated config.json manifest source to "project" (local)`,
422+
`Updated app manifest source to "project" (local)`,
422423
},
423424
},
424-
"When manifest source is provided, should set it": {
425-
manifestSource: config.ManifestSourceRemote,
425+
"When remote manifest source is provided, should use it": {
426+
manifestSource: config.ManifestSourceRemote,
427+
expectedManifestSource: config.ManifestSourceRemote,
428+
existingFiles: map[string]string{
429+
".slack/hooks.json": "{}",
430+
},
431+
expectedOutputs: []string{
432+
`Updated app manifest source to "app settings" (remote)`,
433+
},
434+
},
435+
"When local manifest source is provided, should use it": {
436+
manifestSource: config.ManifestSourceLocal,
437+
expectedManifestSource: config.ManifestSourceLocal,
438+
existingFiles: map[string]string{
439+
".slack/hooks.json": "{}",
440+
},
426441
expectedOutputs: []string{
427-
`Updated config.json manifest source to "app settings" (remote)`,
442+
`Updated app manifest source to "project" (local)`,
428443
},
429444
},
430445
"When Deno project, should set manifest source to project (local)": {
431446
expectedOutputs: []string{
432-
`Updated config.json manifest source to "project" (local)`,
447+
`Updated app manifest source to "project" (local)`,
433448
},
434449
},
435-
"When non-Deno project, should set manifest source to app settings (remote)": {
450+
"When non-Deno project, should set manifest source to project (local)": {
436451
runtime: "node",
437452
expectedOutputs: []string{
438-
`Updated config.json manifest source to "app settings" (remote)`,
453+
`Updated app manifest source to "project" (local)`,
439454
},
440455
},
441456
}
@@ -490,8 +505,15 @@ func Test_Create_installProjectDependencies(t *testing.T) {
490505
}
491506
}
492507

508+
// Set manifest source
509+
if tc.manifestSource != "" {
510+
if err := config.SetManifestSource(ctx, clientsMock.Fs, clientsMock.Os, tc.manifestSource); err != nil {
511+
require.FailNow(t, fmt.Sprintf("Failed to set the manifest source in the memory-based file system: %s", err))
512+
}
513+
}
514+
493515
// Run the test
494-
outputs := InstallProjectDependencies(ctx, clients, projectDirPath, tc.manifestSource)
516+
outputs := InstallProjectDependencies(ctx, clients, projectDirPath)
495517

496518
// Assertions
497519
for _, expectedOutput := range tc.expectedOutputs {
@@ -503,6 +525,13 @@ func Test_Create_installProjectDependencies(t *testing.T) {
503525
for _, expectedVerboseOutput := range tc.expectedVerboseOutputs {
504526
clientsMock.IO.AssertCalled(t, "PrintDebug", mock.Anything, expectedVerboseOutput, tc.expectedVerboseArgs)
505527
}
528+
if tc.expectedManifestSource != "" {
529+
actualManifestSource, err := clients.Config.ProjectConfig.GetManifestSource(ctx)
530+
if err != nil {
531+
require.FailNow(t, fmt.Sprintf("Failed to get the manifest source: %s", err))
532+
}
533+
assert.Equal(t, tc.expectedManifestSource, actualManifestSource)
534+
}
506535
assert.NotEmpty(t, clients.Config.ProjectID, "config.project_id")
507536
// output := clientsMock.GetCombinedOutput()
508537
// assert.Contains(t, output, tc.expectedOutputs)

0 commit comments

Comments
 (0)