Skip to content

Commit 63e7e99

Browse files
committed
refactor: use ddev composer create-project everywhere
1 parent e53d3c4 commit 63e7e99

25 files changed

Lines changed: 122 additions & 109 deletions
Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,20 @@ import (
2121

2222
var composerDirectoryArg = ""
2323

24-
// ComposerCreateCmd handles ddev composer create
25-
var ComposerCreateCmd = &cobra.Command{
24+
// ComposerCreateProjectCmd handles ddev composer create-project
25+
var ComposerCreateProjectCmd = &cobra.Command{
2626
DisableFlagParsing: true,
27-
Use: "create [args] [flags]",
28-
Aliases: []string{"create-project"},
27+
Use: "create-project [args] [flags]",
2928
Short: "Executes 'composer create-project' within the web container with the arguments and flags provided",
3029
Long: `Directs basic invocations of 'composer create-project' within the context of the
3130
web container. Projects will be installed to a temporary directory and moved to
3231
the Composer root directory after install.`,
33-
Example: `ddev composer create drupal/recommended-project
34-
ddev composer create drupal/recommended-project
35-
ddev composer create "typo3/cms-base-distribution:^10"
36-
ddev composer create drupal/recommended-project --no-install
37-
ddev composer create --repository=https://repo.magento.com/ magento/project-community-edition
38-
ddev composer create --prefer-dist --no-interaction --no-dev psr/log
32+
Example: `ddev composer create-project drupal/recommended-project
33+
ddev composer create-project drupal/recommended-project .
34+
ddev composer create-project typo3/cms-base-distribution . "^10"
35+
ddev composer create-project drupal/recommended-project --no-install .
36+
ddev composer create-project --repository=https://repo.magento.com/ magento/project-community-edition .
37+
ddev composer create-project --prefer-dist --no-interaction --no-dev psr/log .
3938
`,
4039
ValidArgsFunction: getComposerCompletionFunc(true),
4140
Run: func(cmd *cobra.Command, args []string) {
@@ -75,7 +74,7 @@ ddev composer create --prefer-dist --no-interaction --no-dev psr/log
7574

7675
// Add some args to avoid troubles while cloning the project.
7776
// We add the three options to "composer create-project": --no-plugins, --no-scripts, --no-install
78-
// These options make the difference between "composer create-project" and "ddev composer create".
77+
// These options make the difference between "composer create-project" and "ddev composer create-project".
7978
var createArgs []string
8079

8180
for _, arg := range args {
@@ -301,19 +300,19 @@ ddev composer create --prefer-dist --no-interaction --no-dev psr/log
301300
prepareAppForComposer(app)
302301
}
303302

304-
util.Success("\nddev composer create was successful.")
303+
util.Success("\nddev composer create-project was successful.")
305304

306305
if runtime.GOOS == "windows" {
307306
fileutil.ReplaceSimulatedLinks(app.AppRoot)
308307
}
309308
},
310309
}
311310

312-
// checkForComposerCreateAllowedPaths ensures that the project does not contain any paths that are not allowed to be present in the composer create command
311+
// checkForComposerCreateAllowedPaths ensures that the project does not contain any paths that are not allowed to be present in the composer create-project command
313312
func checkForComposerCreateAllowedPaths(app *ddevapp.DdevApp) {
314313
appRoot := app.GetAbsAppRoot(false)
315314
composerRoot := filepath.Join(app.GetComposerRoot(false, false), composerDirectoryArg)
316-
skipDirs := []string{".ddev", ".git", ".tarballs"}
315+
skipDirs := []string{".ddev", ".git", ".idea", ".tarballs", ".vscode"}
317316
composerCreateAllowedPaths, _ := app.GetComposerCreateAllowedPaths()
318317
err := filepath.Walk(composerRoot,
319318
func(walkPath string, walkInfo os.FileInfo, err error) error {
@@ -327,7 +326,7 @@ func checkForComposerCreateAllowedPaths(app *ddevapp.DdevApp) {
327326
return filepath.SkipDir
328327
}
329328
if !slices.Contains(composerCreateAllowedPaths, checkPath) {
330-
return fmt.Errorf("'%s' is not allowed to be present. composer create needs to be run on a clean/empty project with only the following paths: %v - please clean up the project before using 'ddev composer create'", filepath.Join(appRoot, checkPath), composerCreateAllowedPaths)
329+
return fmt.Errorf("'%s' is not allowed to be present. composer create-project needs to be run on a clean/empty project with only the following paths: %v - please clean up the project before using 'ddev composer create-project'", filepath.Join(appRoot, checkPath), composerCreateAllowedPaths)
331330
}
332331
return err
333332
})
@@ -497,6 +496,20 @@ func prepareAppForComposer(app *ddevapp.DdevApp) {
497496
}
498497
}
499498

499+
// ComposerCreateCmd sends people to the right thing
500+
// when they try ddev composer create
501+
var ComposerCreateCmd = &cobra.Command{
502+
Use: "create",
503+
Short: `Use "ddev composer create-project" instead`,
504+
DisableFlagParsing: true,
505+
Hidden: true,
506+
Deprecated: `use "create-project" instead`,
507+
Run: func(cmd *cobra.Command, args []string) {
508+
ComposerCreateProjectCmd.Run(cmd, args)
509+
},
510+
}
511+
500512
func init() {
513+
ComposerCmd.AddCommand(ComposerCreateProjectCmd)
501514
ComposerCmd.AddCommand(ComposerCreateCmd)
502515
}

cmd/ddev/cmd/composer-create_test.go renamed to cmd/ddev/cmd/composer-create-project_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/stretchr/testify/require"
1717
)
1818

19-
func TestComposerCreateCmd(t *testing.T) {
19+
func TestComposerCreateProjectCmd(t *testing.T) {
2020
composerVersionForThisTest := nodeps.ComposerDefault
2121
//composerVersionForThisTest := "2.8.0"
2222

@@ -31,11 +31,11 @@ func TestComposerCreateCmd(t *testing.T) {
3131
for _, docRoot := range []string{"", "doc-root"} {
3232
for _, projectType := range validAppTypes {
3333
if projectType == nodeps.AppTypeDrupal6 {
34-
t.Logf("== SKIP TestComposerCreateCmd for project of type '%s' with docroot '%s'\n", projectType, docRoot)
35-
t.Logf("== SKIP drupal6 projects uses a very old php version and composer create is very unlikely to be used")
34+
t.Logf("== SKIP TestComposerCreateProjectCmd for project of type '%s' with docroot '%s'\n", projectType, docRoot)
35+
t.Logf("== SKIP drupal6 projects uses a very old php version and composer create-project is very unlikely to be used")
3636
continue
3737
}
38-
t.Logf("== BEGIN TestComposerCreateCmd for project of type '%s' with docroot '%s'\n", projectType, docRoot)
38+
t.Logf("== BEGIN TestComposerCreateProjectCmd for project of type '%s' with docroot '%s'\n", projectType, docRoot)
3939
tmpDir := testcommon.CreateTmpDir(t.Name() + projectType)
4040
err = os.Chdir(tmpDir)
4141
require.NoError(t, err)
@@ -88,22 +88,22 @@ func TestComposerCreateCmd(t *testing.T) {
8888
// These are different conditions to test different composer flag combinations
8989
// Conditions for docRoot and projectType are not important here, they are only needed to make the test act different each time
9090
if docRoot == "" {
91-
cmd = "ddev composer create --no-plugins --no-scripts ddev/ddev-test-composer-create"
91+
cmd = "ddev composer create-project --no-plugins --no-scripts ddev/ddev-test-composer-create"
9292
if projectType == nodeps.AppTypePHP {
93-
cmd = "ddev composer create --no-install ddev/ddev-test-composer-create ."
93+
cmd = "ddev composer create-project --no-install ddev/ddev-test-composer-create ."
9494
}
9595
} else {
9696
if projectType != nodeps.AppTypePHP {
97-
cmd = "ddev composer create ddev/ddev-test-composer-create --prefer-install auto . --no-dev v1.0.0"
97+
cmd = "ddev composer create-project ddev/ddev-test-composer-create --prefer-install auto . --no-dev v1.0.0"
9898
} else {
99-
cmd = "ddev composer create -vvv ddev/ddev-test-composer-create --prefer-install=auto --fake-flag ."
99+
cmd = "ddev composer create-project -vvv ddev/ddev-test-composer-create --prefer-install=auto --fake-flag ."
100100
}
101101
}
102102

103103
t.Logf("Attempting cmd='%s' with docroot='%s' composer_root='%s' type='%s'", cmd, docRoot, docRoot, projectType)
104104
args := strings.Split(strings.TrimPrefix(cmd, "ddev "), " ")
105105

106-
// If a file exists in the composer root then composer create should fail
106+
// If a file exists in the composer root then composer create-project should fail
107107
file, err := os.Create(filepath.Join(composerDirOnHost, "touch1.txt"))
108108
require.NoError(t, err)
109109
out, err = exec.RunHostCommand(DdevBin, args...)
@@ -118,7 +118,7 @@ func TestComposerCreateCmd(t *testing.T) {
118118
require.Contains(t, out, "Created project in ")
119119
require.FileExists(t, filepath.Join(composerDirOnHost, "composer.json"))
120120

121-
if cmd == "ddev composer create --no-plugins --no-scripts ddev/ddev-test-composer-create" {
121+
if cmd == "ddev composer create-project --no-plugins --no-scripts ddev/ddev-test-composer-create" {
122122
// Check what was executed or not
123123
require.Contains(t, out, "Executing Composer command: [composer create-project --no-plugins --no-scripts --no-install ddev/ddev-test-composer-create /tmp/")
124124
require.NotContains(t, out, "Executing Composer command: [composer run-script post-root-package-install")
@@ -133,7 +133,7 @@ func TestComposerCreateCmd(t *testing.T) {
133133
require.FileExists(t, filepath.Join(composerDirOnHost, "vendor", "ddev", "ddev-test-composer-require-dev", "composer.json"))
134134
}
135135

136-
if cmd == "ddev composer create -vvv ddev/ddev-test-composer-create --prefer-install=auto --fake-flag ." {
136+
if cmd == "ddev composer create-project -vvv ddev/ddev-test-composer-create --prefer-install=auto --fake-flag ." {
137137
// Check what was executed or not
138138
require.Contains(t, out, "Executing Composer command: [composer create-project -vvv --prefer-install=auto --no-plugins --no-scripts --no-install ddev/ddev-test-composer-create /tmp/")
139139
require.Contains(t, out, "Executing Composer command: [composer run-script post-root-package-install -vvv]")
@@ -149,7 +149,7 @@ func TestComposerCreateCmd(t *testing.T) {
149149
require.FileExists(t, filepath.Join(composerDirOnHost, "vendor", "ddev", "ddev-test-composer-require-dev", "composer.json"))
150150
}
151151

152-
if cmd == "ddev composer create --no-install ddev/ddev-test-composer-create ." {
152+
if cmd == "ddev composer create-project --no-install ddev/ddev-test-composer-create ." {
153153
// Check what was executed or not
154154
require.Contains(t, out, "Executing Composer command: [composer create-project --no-install --no-plugins --no-scripts ddev/ddev-test-composer-create /tmp/")
155155
require.Contains(t, out, "Executing Composer command: [composer run-script post-root-package-install]")
@@ -162,7 +162,7 @@ func TestComposerCreateCmd(t *testing.T) {
162162
require.NoDirExists(t, filepath.Join(composerDirOnHost, "vendor"))
163163
}
164164

165-
if cmd == "ddev composer create ddev/ddev-test-composer-create --prefer-install auto . --no-dev v1.0.0" {
165+
if cmd == "ddev composer create-project ddev/ddev-test-composer-create --prefer-install auto . --no-dev v1.0.0" {
166166
// Check what was executed or not
167167
require.Contains(t, out, "Executing Composer command: [composer create-project --prefer-install auto --no-dev --no-plugins --no-scripts --no-install ddev/ddev-test-composer-create /tmp/")
168168
require.Contains(t, out, "v1.0.0")
@@ -179,7 +179,7 @@ func TestComposerCreateCmd(t *testing.T) {
179179
}
180180

181181
require.Contains(t, out, "Moving install to Composer root")
182-
require.Contains(t, out, "ddev composer create was successful")
182+
require.Contains(t, out, "ddev composer create-project was successful")
183183

184184
// Check that resulting composer.json (copied from testdata) has post-root-package-install and post-create-project-cmd scripts
185185
composerManifest, err := composer.NewManifest(filepath.Join(composerDirOnHost, "composer.json"))
@@ -217,7 +217,7 @@ func TestComposerCreateAutocomplete(t *testing.T) {
217217
require.NoError(t, err)
218218

219219
// Pressing tab after `composer completion` should result in the completion "bash"
220-
out, err := exec.RunHostCommand(DdevBin, "__complete", "composer", "create", "--")
220+
out, err := exec.RunHostCommand(DdevBin, "__complete", "composer", "create-project", "--")
221221
require.NoError(t, err)
222222
// Completions are terminated with ":4", so just grab the stuff before that
223223
completions, _, found := strings.Cut(out, ":")

cmd/ddev/cmd/composer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ the command with 'ddev'.`,
2323
Example: `ddev composer install
2424
ddev composer require <package>
2525
ddev composer outdated --minor-only
26-
ddev composer create drupal/recommended-project`,
26+
ddev composer create-project drupal/recommended-project .`,
2727
ValidArgsFunction: getComposerCompletionFunc(false),
2828
Run: func(_ *cobra.Command, args []string) {
2929
app, err := ddevapp.GetActiveApp("")

cmd/ddev/cmd/composer_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
)
1818

1919
func TestComposerCmdCreateConfigInstall(t *testing.T) {
20-
// 2022-05-24: I've spent lots of time debugging intermittent `composer create` failures when NFS
20+
// 2022-05-24: I've spent lots of time debugging intermittent `composer create-project` failures when NFS
2121
// is enabled, both on macOS and Windows. As far as I can tell, it only happens in this test, I've
2222
// never recreated manually. I do see https://github.com/composer/composer/issues/9627 which seemed
2323
// to deal with similar issues in vagrant context, and has a hack now embedded into Composer.
@@ -70,8 +70,8 @@ func TestComposerCmdCreateConfigInstall(t *testing.T) {
7070
// These two often fail on Windows with NFS, also Colima
7171
// It appears to be something about Composer itself?
7272

73-
// ddev composer create --prefer-dist --no-interaction --no-dev psr/log:1.1.0
74-
args := []string{"composer", "create", "--prefer-dist", "--no-interaction", "--no-dev", "--no-install", "psr/log:1.1.0"}
73+
// ddev composer create-project --prefer-dist --no-interaction --no-dev psr/log:1.1.0
74+
args := []string{"composer", "create-project", "--prefer-dist", "--no-interaction", "--no-dev", "--no-install", "psr/log:1.1.0"}
7575
out, err = exec.RunHostCommand(DdevBin, args...)
7676
assert.NoError(err, "failed to run %v: err=%v, output=\n=====\n%s\n=====\n", args, err, out)
7777
assert.Contains(out, "Created project in ")
@@ -90,7 +90,7 @@ func TestComposerCmdCreateConfigInstall(t *testing.T) {
9090
}
9191

9292
func TestComposerCmdCreateRequireRemoveConfigVersion(t *testing.T) {
93-
// 2022-05-24: I've spent lots of time debugging intermittent `composer create` failures when NFS
93+
// 2022-05-24: I've spent lots of time debugging intermittent `composer create-project` failures when NFS
9494
// is enabled, both on macOS and Windows. As far as I can tell, it only happens in this test, I've
9595
// never recreated manually. I do see https://github.com/composer/composer/issues/9627 which seemed
9696
// to deal with similar issues in vagrant context, and has a hack now embedded into Composer.
@@ -143,8 +143,8 @@ func TestComposerCmdCreateRequireRemoveConfigVersion(t *testing.T) {
143143
// These two often fail on Windows with NFS, also Colima
144144
// It appears to be something about Composer itself?
145145

146-
// ddev composer create --prefer-dist --no-dev --no-install psr/log:1.1.0
147-
args := []string{"composer", "create", "--prefer-dist", "--no-dev", "--no-install", "psr/log:1.1.0"}
146+
// ddev composer create-project --prefer-dist --no-dev --no-install psr/log:1.1.0 .
147+
args := []string{"composer", "create-project", "--prefer-dist", "--no-dev", "--no-install", "psr/log:1.1.0", "."}
148148
out, err = exec.RunHostCommand(DdevBin, args...)
149149
assert.NoError(err, "failed to run %v: err=%v, output=\n=====\n%s\n=====\n", args, err, out)
150150
assert.Contains(out, "Created project in ")

docs/content/developers/building-contributing.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ The pull request title must follow this convention which is based on the [Conven
333333
* `ci: enforce commit message convention, fixes #5037`
334334
* `docs: change code refs of Mac M1 to Apple Silicon`
335335
* `feat: allow multiple upload dirs, fixes #4190, fixes #4796`
336-
* `fix: create upload_dir if it doesn't exist in ddev composer create, fixes #5031`
336+
* `fix: create upload_dir if it doesn't exist in ddev composer create-project, fixes #5031`
337337
* `refactor: add new Amplitude Property DDEV-Environment`
338338
* `test: optimize caching of downloaded assets`
339339

docs/content/developers/project-types.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ To add a new project type:
2626
* `postStartAction` adds actions at the end of [`ddev start`](../users/usage/commands.md#start). You'll see several implementations of this, for things like creating needed default directories, or setting permissions on files, etc.
2727
* `importFilesAction` defines how [`ddev import-files`](../users/usage/commands.md#import-files) works for this project type.
2828
* `defaultWorkingDirMap` allows the project type to override the project’s [`working_dir`](../users/configuration/config.md#working_dir) (where [`ddev ssh`](../users/usage/commands.md#ssh) and [`ddev exec`](../users/usage/commands.md#exec) start by default). This is mostly not done anymore, as the `working_dir` is typically the project root.
29-
* `composerCreateAllowedPaths` specifies the paths that can exist in a directory when `ddev composer create` is being used.
29+
* `composerCreateAllowedPaths` specifies the paths that can exist in a directory when `ddev composer create-project` is being used.
3030
* You’ll likely need templates for settings files, use the Drupal or TYPO3 templates as examples, for example `pkg/ddevapp/drupal` and `pkg/ddevapp/typo3`. Those templates have to be loaded at runtime as well.
3131
* Implement `nginx-site-<project-type>.conf` in `webserver_config_assets`. You can use `webserver_config_assets/nginx-site-php.conf` as a pattern, or something from the upstream project.
3232
* Upload the project detection file stubs to the `testdata/TestDetectAppType` folder.

docs/content/users/install/performance.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ Mutagen is enabled by default on Mac and traditional Windows, and it can be disa
7272
* **Beware simultaneous changes to the same file in both filesystems.**<br>
7373
As we pointed out above, any project likely to change the same file on the host *and* inside the container may encounter conflicts.
7474
* **Massive changes can cause problems.**<br>
75-
Massive file changes on the host or in the container are the most likely to introduce issues. This integration has been tested extensively with major changes introduced by `ddev composer` and `ddev composer create`, but be aware of this issue. Changing Git branches, `npm install`, `yarn install`, or a script that deletes huge sections of the synced data are related behaviors that should raise caution. Again, use `ddev mutagen reset` before restarting the project if you want to be sure Mutagen starts out looking at the host machine’s files.
75+
Massive file changes on the host or in the container are the most likely to introduce issues. This integration has been tested extensively with major changes introduced by `ddev composer` and `ddev composer create-project`, but be aware of this issue. Changing Git branches, `npm install`, `yarn install`, or a script that deletes huge sections of the synced data are related behaviors that should raise caution. Again, use `ddev mutagen reset` before restarting the project if you want to be sure Mutagen starts out looking at the host machine’s files.
7676
* **Mutagen is asynchronous.**<br>
7777
A massive change in either filesystem can result in lag as all changed files are handled. You can use `ddev mutagen monitor` to get a better look at what’s happening.
7878
* **You can manually trigger a sync.**<br>

0 commit comments

Comments
 (0)