This repository has been archived by the owner on Jan 25, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 195
fix: fix the builds for public projects that use yarn 2 (or above) with workspaces #763
Closed
fulopkovacs
wants to merge
4
commits into
netlify:focal
from
theatre-js:fix-yarn-workspaces-for-public-repos
Closed
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
536caf3
fix: prevent the builds from failing for public projects that use yar…
fulopkovacs 722cf79
refactor: prevent the builds from failing for public projects that us…
fulopkovacs ef32a54
test: prevent the builds from failing for public projects that use ya…
fulopkovacs 3c7af68
refactor: fix the indentation of the package.json files in the test f…
fulopkovacs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
{ | ||
"name": "yarn-v1-workspaces", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "UNLICENSED", | ||
"dependencies": { | ||
"@netlify/plugins-list": "^3.6.0" | ||
}, | ||
"private": true, | ||
"workspaces": [ | ||
"workspace-a", | ||
"workspace-b" | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
tests/node/fixtures/yarn-v1-workspaces/workspace-a/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "workspace-a", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"@netlify/plugins-list": "^3.6.0" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
tests/node/fixtures/yarn-v1-workspaces/workspace-b/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "workspace-b", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"@netlify/plugins-list": "^3.6.0" | ||
} | ||
} |
785 changes: 785 additions & 0 deletions
785
tests/node/fixtures/yarn-v2-workspaces/.yarn/releases/yarn-3.2.0.cjs
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
nodeLinker: node-modules | ||
|
||
yarnPath: .yarn/releases/yarn-3.2.0.cjs | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "yarn-v2-workspaces", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "UNLICENSED", | ||
"dependencies": { | ||
"@netlify/plugins-list": "^3.6.0" | ||
}, | ||
"workspaces": [ | ||
"workspace-a", | ||
"workspace-b" | ||
] | ||
} |
7 changes: 7 additions & 0 deletions
7
tests/node/fixtures/yarn-v2-workspaces/workspace-a/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "workspace-a", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"@netlify/plugins-list": "^3.6.0" | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
tests/node/fixtures/yarn-v2-workspaces/workspace-b/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "workspace-b", | ||
"version": "1.0.0", | ||
"dependencies": { | ||
"@netlify/plugins-list": "^3.6.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#!/usr/bin/env bats | ||
|
||
load '../helpers.sh' | ||
|
||
load '../../node_modules/bats-support/load' | ||
load '../../node_modules/bats-assert/load' | ||
load '../../node_modules/bats-file/load' | ||
|
||
setup() { | ||
TMP_DIR=$(setup_tmp_dir) | ||
REPO_DIR="${TMP_DIR}/repo" | ||
DEPENDENCY_NAME="some-dependency" | ||
set_fixture_as_repo 'yarn-v1-workspaces' "$TMP_DIR" | ||
|
||
|
||
# Load functions | ||
load '../../run-build-functions.sh' | ||
|
||
local js_workspaces=$TMP_DIR/cache/js-workspaces | ||
|
||
# Create the directories that should be restored | ||
# from cache | ||
mkdir -p $js_workspaces/node_modules/$DEPENDENCY_NAME | ||
mkdir -p $js_workspaces/workspace-a/node_modules/$DEPENDENCY_NAME | ||
mkdir -p $js_workspaces/workspace-b/node_modules/$DEPENDENCY_NAME | ||
|
||
source_nvm | ||
} | ||
|
||
teardown() { | ||
rm -rf "$TMP_DIR" | ||
|
||
# Return to original dir | ||
cd - || return | ||
} | ||
|
||
@test 'project uses yarn v1' { | ||
run yarn --version | ||
assert_output '1.22.10' | ||
} | ||
|
||
@test 'restore_node_modules correctly restores workspace dependencies' { | ||
# Make sure that the directories we'll restore from the cache | ||
# do not exist yet | ||
assert_dir_not_exist $REPO_DIR/node_modules/$DEPENDENCY_NAME | ||
assert_dir_not_exist $REPO_DIR/workspace-a/node_modules/$DEPENDENCY_NAME | ||
assert_dir_not_exist $REPO_DIR/workspace-b/node_modules/$DEPENDENCY_NAME | ||
|
||
# I couldn't find a way to use multiline string assertions | ||
# in bats, that's why I can't use `assert_output` here | ||
logs=$(restore_node_modules 'yarn' | paste -s -d ',') | ||
assert_equal "$logs" "yarn workspaces detected,Started restoring workspace workspace-a node modules,Finished restoring workspace workspace-a node modules,Started restoring workspace workspace-b node modules,Finished restoring workspace workspace-b node modules,Started restoring workspace root node modules,Finished restoring workspace root node modules" | ||
|
||
# Check if the all the dependencies have been restored | ||
assert_dir_exist $REPO_DIR/node_modules/$DEPENDENCY_NAME | ||
assert_dir_exist $REPO_DIR/workspace-a/node_modules/$DEPENDENCY_NAME | ||
assert_dir_exist $REPO_DIR/workspace-b/node_modules/$DEPENDENCY_NAME | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#!/usr/bin/env bats | ||
|
||
load '../helpers.sh' | ||
|
||
load '../../node_modules/bats-support/load' | ||
load '../../node_modules/bats-assert/load' | ||
load '../../node_modules/bats-file/load' | ||
|
||
setup() { | ||
TMP_DIR=$(setup_tmp_dir) | ||
REPO_DIR="${TMP_DIR}/repo" | ||
DEPENDENCY_NAME="some-dependency" | ||
set_fixture_as_repo 'simple-node' "$TMP_DIR" | ||
|
||
|
||
# Load functions | ||
load '../../run-build-functions.sh' | ||
|
||
# Create a fake dependency that should be restored | ||
# from cache | ||
mkdir $TMP_DIR/cache/node_modules/$DEPENDENCY_NAME | ||
|
||
source_nvm | ||
} | ||
|
||
teardown() { | ||
rm -rf "$TMP_DIR" | ||
|
||
# Return to original dir | ||
cd - || return | ||
} | ||
|
||
@test 'project uses yarn 1.x' { | ||
run yarn --version | ||
assert_output '1.22.10' | ||
} | ||
|
||
@test 'restore_node_modules correctly restores dependencies' { | ||
# Make sure that that directory we'll restore from the cache | ||
# does not exist | ||
assert_dir_not_exist $REPO_DIR/node_modules/$DEPENDENCY_NAME | ||
|
||
# I couldn't find a way to use multiline string assertions | ||
# in bats, that's why I can't use `assert_output` here | ||
logs=$(restore_node_modules 'yarn' | paste -s -d ',') | ||
assert_equal "$logs" "No yarn workspaces detected,Started restoring cached node modules,Finished restoring cached node modules" | ||
|
||
assert_dir_exist $REPO_DIR/node_modules/$DEPENDENCY_NAME | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env bats | ||
|
||
load '../helpers.sh' | ||
|
||
load '../../node_modules/bats-support/load' | ||
load '../../node_modules/bats-assert/load' | ||
load '../../node_modules/bats-file/load' | ||
|
||
setup() { | ||
TMP_DIR=$(setup_tmp_dir) | ||
REPO_DIR="${TMP_DIR}/repo" | ||
DEPENDENCY_NAME="some-dependency" | ||
set_fixture_as_repo 'yarn-v2-workspaces' "$TMP_DIR" | ||
|
||
# Load functions | ||
load '../../run-build-functions.sh' | ||
|
||
local js_workspaces=$TMP_DIR/cache/js-workspaces | ||
|
||
# Create the directories that should be restored | ||
# from cache | ||
mkdir -p $js_workspaces/node_modules/$DEPENDENCY_NAME | ||
mkdir -p $js_workspaces/workspace-a/node_modules/$DEPENDENCY_NAME | ||
mkdir -p $js_workspaces/workspace-b/node_modules/$DEPENDENCY_NAME | ||
|
||
source_nvm | ||
} | ||
|
||
teardown() { | ||
rm -rf "$TMP_DIR" | ||
|
||
# Return to original dir | ||
cd - || return | ||
} | ||
|
||
@test 'project uses yarn 2+' { | ||
run yarn --version | ||
assert_output '3.2.0' | ||
} | ||
|
||
@test 'restore_node_modules correctly restores workspace dependencies' { | ||
# Make sure that the directories we'll restore from the cache | ||
# do not exist yet | ||
assert_dir_not_exist $REPO_DIR/node_modules/$DEPENDENCY_NAME | ||
assert_dir_not_exist $REPO_DIR/workspace-a/node_modules/$DEPENDENCY_NAME | ||
assert_dir_not_exist $REPO_DIR/workspace-b/node_modules/$DEPENDENCY_NAME | ||
|
||
# I couldn't find a way to use multiline string assertions | ||
# in bats, that's why I can't use `assert_output` here | ||
logs=$(restore_node_modules 'yarn' | paste -s -d ',') | ||
assert_equal "$logs" "yarn workspaces detected,Started restoring workspace workspace-a node modules,Finished restoring workspace workspace-a node modules,Started restoring workspace workspace-b node modules,Finished restoring workspace workspace-b node modules,Started restoring workspace root node modules,Finished restoring workspace root node modules" | ||
|
||
# Check if the all the dependencies have been restored | ||
assert_dir_exist $REPO_DIR/node_modules/$DEPENDENCY_NAME | ||
assert_dir_exist $REPO_DIR/workspace-a/node_modules/$DEPENDENCY_NAME | ||
assert_dir_exist $REPO_DIR/workspace-b/node_modules/$DEPENDENCY_NAME | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JGAntunes Shipping a binary for a specific version of yarn might be controversial, but