-
Notifications
You must be signed in to change notification settings - Fork 240
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support running npm install without package.json (#2269)
- Loading branch information
Showing
3 changed files
with
29 additions
and
7 deletions.
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
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 |
---|---|---|
|
@@ -135,7 +135,7 @@ func testNpm(t *testing.T, isLegacy bool) { | |
} | ||
|
||
func readModuleId(t *testing.T, wd string, npmVersion *version.Version) string { | ||
packageInfo, err := buildutils.ReadPackageInfoFromPackageJson(filepath.Dir(wd), npmVersion) | ||
packageInfo, err := buildutils.ReadPackageInfoFromPackageJsonIfExists(filepath.Dir(wd), npmVersion) | ||
assert.NoError(t, err) | ||
return packageInfo.BuildInfoModuleId() | ||
} | ||
|
@@ -165,6 +165,28 @@ func validateNpmLocalBuildInfo(t *testing.T, buildName, buildNumber, moduleName | |
} | ||
} | ||
|
||
func TestNpmWithoutPackageJson(t *testing.T) { | ||
initNpmTest(t) | ||
defer cleanNpmTest(t) | ||
|
||
// Create temp dir that does not contain an npm project | ||
tempDirPath, createTempDirCallback := coretests.CreateTempDirWithCallbackAndAssert(t) | ||
defer createTempDirCallback() | ||
wd, err := os.Getwd() | ||
assert.NoError(t, err, "Failed to get current dir") | ||
chdirCallback := clientTestUtils.ChangeDirWithCallback(t, wd, tempDirPath) | ||
defer chdirCallback() | ||
|
||
// Run config to allow resolution from Artifactory | ||
err = createConfigFileForTest([]string{tempDirPath}, tests.NpmRemoteRepo, "", t, utils.Npm, false) | ||
assert.NoError(t, err) | ||
|
||
// Run npm install and make sure that package.json and package-lock.json were created | ||
runJfrogCli(t, "npm", "i", "[email protected]", "--save-exact") | ||
assert.FileExists(t, filepath.Join(tempDirPath, "package.json")) | ||
assert.FileExists(t, filepath.Join(tempDirPath, "package-lock.json")) | ||
} | ||
|
||
func TestNpmConditionalUpload(t *testing.T) { | ||
initNpmTest(t) | ||
defer cleanNpmTest(t) | ||
|