Skip to content

Commit

Permalink
Request yarn to be available for launch (#143)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
arjun024 and thitch97 authored Sep 24, 2021
1 parent 77a3c86 commit 2580fb5
Show file tree
Hide file tree
Showing 12 changed files with 467 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
/.bin
/.build
/bin
/build
1 change: 1 addition & 0 deletions constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package yarnstart
const (
Node = "node"
NodeModules = "node_modules"
Yarn = "yarn"
)
6 changes: 6 additions & 0 deletions detect.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ func Detect(projectPathParser PathParser) packit.DetectFunc {
"launch": true,
},
},
{
Name: Yarn,
Metadata: map[string]interface{}{
"launch": true,
},
},
{
Name: NodeModules,
Metadata: map[string]interface{}{
Expand Down
6 changes: 6 additions & 0 deletions detect_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ func testDetect(t *testing.T, context spec.G, it spec.S) {
"launch": true,
},
},
{
Name: "yarn",
Metadata: map[string]interface{}{
"launch": true,
},
},
{
Name: "node_modules",
Metadata: map[string]interface{}{
Expand Down
1 change: 1 addition & 0 deletions integration/init_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,5 +85,6 @@ func TestIntegration(t *testing.T) {
suite("Default", testDefault)
suite("GracefulShutdown", testGracefulShutdown)
suite("ProjectPath", testProjectPath)
suite("Workspaces", testWorkspaces)
suite.Run(t)
}
10 changes: 10 additions & 0 deletions integration/testdata/workspaces_app/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"main": "packages/sample-app/index.js",
"scripts": {
"start": "yarn workspace @sample/sample-app start"
},
"private": true,
"workspaces": [
"packages/*"
]
}
13 changes: 13 additions & 0 deletions integration/testdata/workspaces_app/packages/sample-app/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const express = require('express');
const app = express();
const config = require('@sample/sample-config');

app.get('/', (req, res) => {
res.send({
config: config(),
});
});

const port = process.env.PORT || 8080;

app.listen(port, () => console.log(`Sample app listening on port ${ port }!`));
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "@sample/sample-app",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"@sample/sample-config": "^1.0.0",
"express": "^4.16.3"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const config = () => {
return {
prop1: 'Package A value 1',
prop2: 'Package A value 2',
};
};

module.exports = config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "@sample/sample-config",
"version": "1.0.0",
"main": "index.js"
}
Loading

0 comments on commit 2580fb5

Please sign in to comment.