Skip to content

Commit

Permalink
Build Dependency Tree - Yarn V1 (#172)
Browse files Browse the repository at this point in the history
* updated PackageInfo struct to support Yarn v1

* added functions and split in dependency tree build flow to support yarn version lesser than 2.0.0

* added tests for GetYarnDependencies for Yarn 1 + added extra checks in the tests

* added tests suitcase for yarn v1

* changed path for Yarn v2 test suitcase

* deleted old test suitcase for yarn v2 test

* fixed static analysis issues

* updated path for tested project example

* TestGenerateBuildInfoForYarnProject : updated path for tested project and fixed test according to new package.json for this project

* TestCollectDepsForYarnProjectWithTraverse, TestCollectDepsForYarnProjectWithErrorInTraverse, TestBuildYarnProjectWithArgs: updated path for tested project and fixed test according to new package.json for this project

* trying test suitcase without .yarn and .yarnrc.yml

* added back .yarnrc.yml and .yarn to v2 project

* fixed PR notes

* unified two GetVersion functions and fixed calls

* deleted omitempty tags from PackageInfo fields: Name, Version

* fixed all PR issues, except regexp for locators map

* fixed some names

* fix PR issue and optimized buildYarnV1DependencyMap

* deleted yarn-1.22.1.cjs NS .yarnrc.yml in v2 test suitcase

* added yarn-1.22.1.cjs NS .yarnrc.yml in v2 test suitcase

* added a bug fix for missing 'yarn install' command

* fixed uninstalled projects error handling and added test and suitcases

* added new suitcase for testing uninstalled projects for yarn2 & yarn3

* fixed wrong commit

* added new suitcase for testing uninstalled projects for yarn2 & yarn3

* .

* .

* .

* deleted .DS_Stores

* fixed uninstalled test to use existing suitcases and deleted redundant test suitcases

* fixed static analysis issues

* .

* deleting comments

* fixed tests according to wanted versions

* fixing tests

* fixing tests

* moved got action from cli to build-info-go

* resetting test.yml file to original state

* updated test suitcases to stable versions and updated tests accordingly

* trying solving failures

* trying solving failures - fetched original v2 suitcase

* fixed PR issues

* fixed PR issues

* fixed PR issues

* fixed PR issues

* handled edge case in splitNameAndVersion and added test for this function

* switch a use of pointer to non-pointer

* fixing usage in pointers

* changing name of variable
  • Loading branch information
eranturgeman authored Aug 3, 2023
1 parent 329b0b5 commit 8230595
Show file tree
Hide file tree
Showing 13 changed files with 453 additions and 80 deletions.
31 changes: 0 additions & 31 deletions build/testdata/yarn/project/yarn.lock

This file was deleted.

19 changes: 19 additions & 0 deletions build/testdata/yarn/v1/project/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "build-info-go-tests",
"packageManager": "[email protected]",
"version": "v1.0.0",
"description": "test package for yarn v1",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"react": "18.2.0",
"xml": "1.0.1"
},
"devDependencies": {
"json": "9.0.6"
}
}
32 changes: 32 additions & 0 deletions build/testdata/yarn/v1/project/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


"js-tokens@^3.0.0 || ^4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/js-tokens/-/js-tokens-4.0.0.tgz#19203fb59991df98e3a287050d4647cdeaf32499"
integrity sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==

[email protected]:
version "9.0.6"
resolved "https://registry.yarnpkg.com/json/-/json-9.0.6.tgz#7972c2a5a48a42678db2730c7c2c4ee6e4e24585"
integrity sha512-Nx+4WwMM1xadgqjjteOVEyjoIVq7fGH1hAlRDoxoq2tFzYsBYZDIKwYbyxolkTYwxsSOgAZD2ACLkeGjhFW2Jw==

loose-envify@^1.1.0:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
dependencies:
js-tokens "^3.0.0 || ^4.0.0"

[email protected]:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"
integrity sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==
dependencies:
loose-envify "^1.1.0"

[email protected]:
version "1.0.1"
resolved "https://registry.yarnpkg.com/xml/-/xml-1.0.1.tgz#78ba72020029c5bc87b8a81a3cfcd74b4a2fc1e5"
integrity sha512-huCv9IH9Tcf95zuYCsQraZtWnJvBtLVE0QHMOs8bWyZAFZNDcYjsPq1nEx8jKA9y+Beo9v+7OBPRisQTjinQMw==
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"react": "18.2.0",
"xml": "1.0.1"
},
"devDependencies": {
Expand Down
59 changes: 59 additions & 0 deletions build/testdata/yarn/v2/project/yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# This file is generated by running "yarn install" inside your project.
# Manual changes might be lost - proceed with caution!

__metadata:
version: 5
cacheKey: 8

"build-info-go-tests@workspace:.":
version: 0.0.0-use.local
resolution: "build-info-go-tests@workspace:."
dependencies:
json: 9.0.6
react: 18.2.0
xml: 1.0.1
languageName: unknown
linkType: soft

"js-tokens@npm:^3.0.0 || ^4.0.0":
version: 4.0.0
resolution: "js-tokens@npm:4.0.0"
checksum: 8a95213a5a77deb6cbe94d86340e8d9ace2b93bc367790b260101d2f36a2eaf4e4e22d9fa9cf459b38af3a32fb4190e638024cf82ec95ef708680e405ea7cc78
languageName: node
linkType: hard

"json@npm:9.0.6":
version: 9.0.6
resolution: "json@npm:9.0.6"
bin:
json: ./lib/json.js
checksum: b9f16874e5bab435ad2e68f5a110549da8e28a4795a24c46e52c97a4f4fc5087f2ceb197eed4f8413fa24a7f7008af3da26caeec7739ca86ec25c2da146af9d5
languageName: node
linkType: hard

"loose-envify@npm:^1.1.0":
version: 1.4.0
resolution: "loose-envify@npm:1.4.0"
dependencies:
js-tokens: ^3.0.0 || ^4.0.0
bin:
loose-envify: cli.js
checksum: 6517e24e0cad87ec9888f500c5b5947032cdfe6ef65e1c1936a0c48a524b81e65542c9c3edc91c97d5bddc806ee2a985dbc79be89215d613b1de5db6d1cfe6f4
languageName: node
linkType: hard

"react@npm:18.2.0":
version: 18.2.0
resolution: "react@npm:18.2.0"
dependencies:
loose-envify: ^1.1.0
checksum: 88e38092da8839b830cda6feef2e8505dec8ace60579e46aa5490fc3dc9bba0bd50336507dc166f43e3afc1c42939c09fe33b25fae889d6f402721dcd78fca1b
languageName: node
linkType: hard

"xml@npm:1.0.1":
version: 1.0.1
resolution: "xml@npm:1.0.1"
checksum: 11b5545ef3f8fec3fa29ce251f50ad7b6c97c103ed4d851306ec23366f5fa4699dd6a942262df52313a0cd1840ab26256da253c023bad3309d8ce46fe6020ca0
languageName: node
linkType: hard
10 changes: 7 additions & 3 deletions build/utils/npm.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,9 +410,13 @@ func GetNpmVersionAndExecPath(log utils.Log) (*version.Version, string, error) {
}

type PackageInfo struct {
Name string `json:"name,omitempty"`
Version string `json:"version,omitempty"`
Scope string
Name string `json:"name"`
Version string `json:"version"`
Dependencies map[string]string `json:"dependencies"`
DevDependencies map[string]string `json:"devDependencies"`
PeerDependencies map[string]string `json:"peerDependencies"`
OptionalDependencies map[string]string `json:"optionalDependencies"`
Scope string
}

func ReadPackageInfoFromPackageJson(packageJsonDirectory string, npmVersion *version.Version) (*PackageInfo, error) {
Expand Down
Loading

0 comments on commit 8230595

Please sign in to comment.