Skip to content

Commit

Permalink
fix: storefront-watch install dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
shyim committed Feb 11, 2024
1 parent 3f28b23 commit 7265d23
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 13 deletions.
6 changes: 6 additions & 0 deletions cmd/project/project_storefront_watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ var projectStorefrontWatchCmd = &cobra.Command{
return err
}

if _, err := os.Stat(extension.PlatformPath(projectRoot, "Storefront", "Resources/app/storefront/node_modules/webpack-dev-server")); os.IsNotExist(err) {
if err := extension.InstallNPMDependencies(extension.PlatformPath(projectRoot, "Storefront", "Resources/app/storefront"), extension.NpmPackage{Dependencies: map[string]string{"not-empty": "not-empty"}}); err != nil {
return err
}
}

return runTransparentCommand(commandWithRoot(exec.CommandContext(cmd.Context(), "npm", "run-script", "hot-proxy"), extension.PlatformPath(projectRoot, "Storefront", "Resources/app/storefront")))
},
}
Expand Down
20 changes: 10 additions & 10 deletions extension/asset_platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ func BuildAssetsForExtensions(ctx context.Context, sources []asset.Source, asset
additionalNpmParameters = []string{"--production"}
}

if err := installDependencies(administrationRoot, npmPackage, additionalNpmParameters...); err != nil {
if err := InstallNPMDependencies(administrationRoot, npmPackage, additionalNpmParameters...); err != nil {
return err
}
}
Expand Down Expand Up @@ -193,7 +193,7 @@ func BuildAssetsForExtensions(ctx context.Context, sources []asset.Source, asset
additionalNpmParameters = append(additionalNpmParameters, "--production")
}

if err := installDependencies(storefrontRoot, npmPackage, additionalNpmParameters...); err != nil {
if err := InstallNPMDependencies(storefrontRoot, npmPackage, additionalNpmParameters...); err != nil {
return err
}
}
Expand Down Expand Up @@ -281,7 +281,7 @@ func InstallNodeModulesOfConfigs(ctx context.Context, cfgs ExtensionAssetConfig,

logging.FromContext(ctx).Infof("Installing npm dependencies in %s %s\n", npmPath, additionalText)

if err := installDependencies(npmPath, npmPackage, additionalNpmParameters...); err != nil {
if err := InstallNPMDependencies(npmPath, npmPackage, additionalNpmParameters...); err != nil {
return nil, err
}

Expand Down Expand Up @@ -316,7 +316,7 @@ func npmRunBuild(path string, buildCmd string, buildEnvVariables []string) error
return nil
}

func getInstallCommand(root string, isProductionMode bool, npmPackage npmPackage) *exec.Cmd {
func getInstallCommand(root string, isProductionMode bool, npmPackage NpmPackage) *exec.Cmd {
if _, err := os.Stat(path.Join(root, "pnpm-lock.yaml")); err == nil {
return exec.Command("pnpm", "install")
}
Expand All @@ -340,7 +340,7 @@ func getInstallCommand(root string, isProductionMode bool, npmPackage npmPackage
return exec.Command("npm", "install", "--no-audit", "--no-fund", "--prefer-offline")
}

func installDependencies(path string, packageJsonData npmPackage, additionalParams ...string) error {
func InstallNPMDependencies(path string, packageJsonData NpmPackage, additionalParams ...string) error {
isProductionMode := false

for _, param := range additionalParams {
Expand Down Expand Up @@ -368,15 +368,15 @@ func installDependencies(path string, packageJsonData npmPackage, additionalPara
return nil
}

func getNpmPackage(root string) (npmPackage, error) {
func getNpmPackage(root string) (NpmPackage, error) {
packageJsonFile, err := os.ReadFile(path.Join(root, "package.json"))
if err != nil {
return npmPackage{}, err
return NpmPackage{}, err
}

var packageJsonData npmPackage
var packageJsonData NpmPackage
if err := json.Unmarshal(packageJsonFile, &packageJsonData); err != nil {
return npmPackage{}, err
return NpmPackage{}, err
}
return packageJsonData, nil
}
Expand Down Expand Up @@ -667,7 +667,7 @@ type ExtensionAssetConfigStorefront struct {
StyleFiles []string `json:"styleFiles"`
}

func doesPackageJsonContainsPackageInDev(packageJsonData npmPackage, packageName string) bool {
func doesPackageJsonContainsPackageInDev(packageJsonData NpmPackage, packageName string) bool {
if _, ok := packageJsonData.DevDependencies[packageName]; ok {
return true
}
Expand Down
4 changes: 2 additions & 2 deletions extension/bun_helper.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package extension

type npmPackage struct {
type NpmPackage struct {
Dependencies map[string]string `json:"dependencies"`
DevDependencies map[string]string `json:"devDependencies"`
}

// When a package is defined in both dependencies and devDependencies, bun will crash.
func canRunBunOnPackage(npmPackage npmPackage) bool {
func canRunBunOnPackage(npmPackage NpmPackage) bool {
for name := range npmPackage.Dependencies {
if _, ok := npmPackage.DevDependencies[name]; ok {
return false
Expand Down
3 changes: 2 additions & 1 deletion extension/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func PlatformPath(projectRoot, component, path string) string {
return filepath.Join(projectRoot, "vendor", "shopware", strings.ToLower(component), path)
}

// IsContributeProject checks if the project is a contribution project aka shopware/shopware
// IsContributeProject checks if the project is a contribution project aka shopware/shopware.
func IsContributeProject(projectRoot string) bool {
if _, err := os.Stat(filepath.Join(projectRoot, "src", "Core", "composer.json")); err == nil {
return true
Expand All @@ -27,6 +27,7 @@ func IsContributeProject(projectRoot string) bool {
return false
}

// LoadSymfonyEnvFile loads the Symfony .env file from the project root.
func LoadSymfonyEnvFile(projectRoot string) error {
currentEnv := os.Getenv("APP_ENV")
if currentEnv == "" {
Expand Down

0 comments on commit 7265d23

Please sign in to comment.