Skip to content

Commit 2580fb5

Browse files
Arjun Sreedharanthitch97
andauthored
Request yarn to be available for launch (#143)
This change adds supports to cases where yarn is used in start commands. A common example is the use of yarn workspaces or frameworks (like lerna) built on top of yarn workspaces. A chose yarn command is run in a particular workspace using the following syntax: `yarn workspace <workspace_name> <command>` See https://classic.yarnpkg.com/en/docs/cli/workspace/ This requires the yarn tool to be available at launch time. See added integration test for an example. Also, see issue paketo-buildpacks/nodejs#456 Co-authored-by: Tim Hitchener <thitch97@users.noreply.github.com>
1 parent 77a3c86 commit 2580fb5

12 files changed

Lines changed: 467 additions & 0 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
/.bin
22
/.build
3+
/bin
4+
/build

constants.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ package yarnstart
33
const (
44
Node = "node"
55
NodeModules = "node_modules"
6+
Yarn = "yarn"
67
)

detect.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ func Detect(projectPathParser PathParser) packit.DetectFunc {
3737
"launch": true,
3838
},
3939
},
40+
{
41+
Name: Yarn,
42+
Metadata: map[string]interface{}{
43+
"launch": true,
44+
},
45+
},
4046
{
4147
Name: NodeModules,
4248
Metadata: map[string]interface{}{

detect_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
5757
"launch": true,
5858
},
5959
},
60+
{
61+
Name: "yarn",
62+
Metadata: map[string]interface{}{
63+
"launch": true,
64+
},
65+
},
6066
{
6167
Name: "node_modules",
6268
Metadata: map[string]interface{}{

integration/init_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,5 +85,6 @@ func TestIntegration(t *testing.T) {
8585
suite("Default", testDefault)
8686
suite("GracefulShutdown", testGracefulShutdown)
8787
suite("ProjectPath", testProjectPath)
88+
suite("Workspaces", testWorkspaces)
8889
suite.Run(t)
8990
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"main": "packages/sample-app/index.js",
3+
"scripts": {
4+
"start": "yarn workspace @sample/sample-app start"
5+
},
6+
"private": true,
7+
"workspaces": [
8+
"packages/*"
9+
]
10+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const express = require('express');
2+
const app = express();
3+
const config = require('@sample/sample-config');
4+
5+
app.get('/', (req, res) => {
6+
res.send({
7+
config: config(),
8+
});
9+
});
10+
11+
const port = process.env.PORT || 8080;
12+
13+
app.listen(port, () => console.log(`Sample app listening on port ${ port }!`));
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"name": "@sample/sample-app",
3+
"version": "1.0.0",
4+
"main": "index.js",
5+
"scripts": {
6+
"start": "node index.js"
7+
},
8+
"dependencies": {
9+
"@sample/sample-config": "^1.0.0",
10+
"express": "^4.16.3"
11+
}
12+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
const config = () => {
2+
return {
3+
prop1: 'Package A value 1',
4+
prop2: 'Package A value 2',
5+
};
6+
};
7+
8+
module.exports = config;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"name": "@sample/sample-config",
3+
"version": "1.0.0",
4+
"main": "index.js"
5+
}

0 commit comments

Comments
 (0)