Skip to content

Commit

Permalink
Merge pull request #37 from railwayapp/jr/dont-prune-by-default
Browse files Browse the repository at this point in the history
Don't prune node_modules by default
  • Loading branch information
coffee-cup authored Feb 27, 2025
2 parents a476785 + 7622898 commit 98669ad
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@
"step": "packages:mise"
},
{
"include": [
"/app/node_modules"
],
"step": "prune"
},
{
"exclude": [
"node_modules"
],
"include": [
"."
],
Expand Down Expand Up @@ -126,23 +117,12 @@
}
},
{
"caches": [
"npm-install"
],
"commands": [
{
"cmd": "npm prune --omit=dev"
}
],
"inputs": [
{
"step": "install"
}
],
"name": "prune",
"variables": {
"NPM_CONFIG_PRODUCTION": "true"
}
"name": "prune"
},
{
"caches": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
"step": "packages:mise"
},
{
"include": [
"/app/node_modules"
],
"step": "prune"
},
{
"exclude": [
"node_modules"
],
"include": [
"."
],
Expand Down Expand Up @@ -125,24 +116,12 @@
}
},
{
"caches": [
"bun-install"
],
"commands": [
{
"cmd": "sh -c 'rm -rf node_modules \u0026\u0026 bun install --production'",
"customName": "rm -rf node_modules \u0026\u0026 bun install --production"
}
],
"inputs": [
{
"step": "install"
}
],
"name": "prune",
"variables": {
"NPM_CONFIG_PRODUCTION": "true"
}
"name": "prune"
},
{
"caches": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
"step": "packages:mise"
},
{
"include": [
"/app/node_modules"
],
"step": "prune"
},
{
"exclude": [
"node_modules"
],
"include": [
".",
"/root/.cache"
Expand Down Expand Up @@ -137,23 +128,12 @@
}
},
{
"caches": [
"pnpm-install"
],
"commands": [
{
"cmd": "pnpm prune --prod"
}
],
"inputs": [
{
"step": "install"
}
],
"name": "prune",
"variables": {
"NPM_CONFIG_PRODUCTION": "true"
}
"name": "prune"
},
{
"caches": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,6 @@
"step": "packages:mise"
},
{
"include": [
"/app/node_modules"
],
"step": "prune"
},
{
"exclude": [
"node_modules"
],
"include": [
"."
],
Expand Down Expand Up @@ -129,23 +120,12 @@
}
},
{
"caches": [
"npm-install"
],
"commands": [
{
"cmd": "npm prune --omit=dev"
}
],
"inputs": [
{
"step": "install"
}
],
"name": "prune",
"variables": {
"NPM_CONFIG_PRODUCTION": "true"
}
"name": "prune"
},
{
"caches": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
"step": "packages:mise"
},
{
"include": [
"/app/node_modules"
],
"step": "prune"
},
{
"exclude": [
"node_modules"
],
"include": [
"."
],
Expand Down Expand Up @@ -133,23 +124,12 @@
}
},
{
"caches": [
"npm-install"
],
"commands": [
{
"cmd": "npm prune --omit=dev"
}
],
"inputs": [
{
"step": "install"
}
],
"name": "prune",
"variables": {
"NPM_CONFIG_PRODUCTION": "true"
}
"name": "prune"
},
{
"caches": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
"step": "packages:mise"
},
{
"include": [
"/app/node_modules"
],
"step": "prune"
},
{
"exclude": [
"node_modules"
],
"include": [
"."
],
Expand Down Expand Up @@ -125,23 +116,12 @@
}
},
{
"caches": [
"npm-install"
],
"commands": [
{
"cmd": "npm prune --omit=dev"
}
],
"inputs": [
{
"step": "install"
}
],
"name": "prune",
"variables": {
"NPM_CONFIG_PRODUCTION": "true"
}
"name": "prune"
},
{
"caches": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@
"step": "packages:mise"
},
{
"include": [
"/app/node_modules"
],
"step": "prune"
},
{
"exclude": [
"node_modules"
],
"include": [
"."
],
Expand Down Expand Up @@ -137,23 +128,12 @@
}
},
{
"caches": [
"pnpm-install"
],
"commands": [
{
"cmd": "pnpm prune --prod"
}
],
"inputs": [
{
"step": "install"
}
],
"name": "prune",
"variables": {
"NPM_CONFIG_PRODUCTION": "true"
}
"name": "prune"
},
{
"caches": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@
"step": "packages:mise"
},
{
"include": [
"/app/node_modules"
],
"step": "prune"
},
{
"exclude": [
"node_modules"
],
"include": [
".",
"/root/.cache"
Expand Down Expand Up @@ -168,23 +159,12 @@
}
},
{
"caches": [
"npm-install"
],
"commands": [
{
"cmd": "npm prune --omit=dev"
}
],
"inputs": [
{
"step": "install"
}
],
"name": "prune",
"variables": {
"NPM_CONFIG_PRODUCTION": "true"
}
"name": "prune"
},
{
"caches": [
Expand Down
43 changes: 30 additions & 13 deletions core/providers/node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ func (p *NodeProvider) Plan(ctx *generate.GenerateContext) error {
// Prune
prune := ctx.NewCommandStep("prune")
prune.AddInput(plan.NewStepInput(install.Name()))
p.PruneNodeDeps(ctx, prune)
prune.Secrets = []string{}
if p.shouldPrune(ctx) {
p.PruneNodeDeps(ctx, prune)
}

// Build
build := ctx.NewCommandStep("build")
Expand All @@ -87,16 +90,30 @@ func (p *NodeProvider) Plan(ctx *generate.GenerateContext) error {
plan.NewStepInput(miseStep.Name(), plan.InputOptions{
Include: miseStep.GetOutputPaths(),
}),
plan.NewStepInput(prune.Name(), plan.InputOptions{
Include: []string{"/app/node_modules"}, // we only wanted the pruned node_modules
}),
plan.NewStepInput(build.Name(), plan.InputOptions{
Include: buildIncludeDirs,
Exclude: []string{"node_modules"},
}),
plan.NewLocalInput("."),
}

if p.shouldPrune(ctx) {
// If we are pruning, we want to grab the pruned node_modules
// and ignore the node_modules from the install/build steps
ctx.Deploy.Inputs = append(ctx.Deploy.Inputs,
plan.NewStepInput(prune.Name(), plan.InputOptions{
Include: []string{"/app/node_modules"},
}),
plan.NewStepInput(build.Name(), plan.InputOptions{
Include: buildIncludeDirs,
Exclude: []string{"node_modules"},
}),
)
} else {
ctx.Deploy.Inputs = append(ctx.Deploy.Inputs,
plan.NewStepInput(build.Name(), plan.InputOptions{
Include: buildIncludeDirs,
}),
)
}

ctx.Deploy.Inputs = append(ctx.Deploy.Inputs, plan.NewLocalInput("."))

return nil
}

Expand Down Expand Up @@ -135,11 +152,11 @@ func (p *NodeProvider) Build(ctx *generate.GenerateContext, build *generate.Comm
}
}

func (p *NodeProvider) PruneNodeDeps(ctx *generate.GenerateContext, prune *generate.CommandStepBuilder) {
if ctx.Env.IsConfigVariableTruthy("NO_PRUNE") {
return
}
func (p *NodeProvider) shouldPrune(ctx *generate.GenerateContext) bool {
return ctx.Env.IsConfigVariableTruthy("PRUNE_DEPS")
}

func (p *NodeProvider) PruneNodeDeps(ctx *generate.GenerateContext, prune *generate.CommandStepBuilder) {
prune.Variables["NPM_CONFIG_PRODUCTION"] = "true"
prune.Secrets = []string{}
p.packageManager.PruneDeps(ctx, prune)
Expand Down
Loading

0 comments on commit 98669ad

Please sign in to comment.