Skip to content

Commit

Permalink
Introduce BP_VERIFY_LAUNCHPOINT to enable generated files (#37)
Browse files Browse the repository at this point in the history
  • Loading branch information
c0d1ngm0nk3y authored Dec 6, 2024
1 parent 1868fa9 commit 05a709e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
14 changes: 9 additions & 5 deletions find_node_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,16 @@ func FindNodeApplication(workingDir string) (string, error) {

launchpoint := os.Getenv(LaunchPointEnvName)
if launchpoint != "" {
if _, err := os.Stat(filepath.Join(workingDir, launchpoint)); err != nil {
if errors.Is(err, os.ErrNotExist) {
return "", fmt.Errorf("expected value derived from BP_LAUNCHPOINT [%s] to be an existing file", launchpoint)
}
doVerify := os.Getenv(VerifyLaunchPointEnvName)

return "", err
if doVerify != "false" {
if _, err := os.Stat(filepath.Join(workingDir, launchpoint)); err != nil {
if errors.Is(err, os.ErrNotExist) {
return "", fmt.Errorf("expected value derived from BP_LAUNCHPOINT [%s] to be an existing file", launchpoint)
}

return "", err
}
}

return filepath.Clean(launchpoint), nil
Expand Down
16 changes: 16 additions & 0 deletions find_node_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,22 @@ func testFindNodeApplication(t *testing.T, context spec.G, it spec.S) {
Expect(err).To(MatchError(ContainSubstring("expected value derived from BP_LAUNCHPOINT [./no-such-file.js] to be an existing file")))
Expect(file).To(Equal(""))
})

it("returns the empty string and no error if BP_VERIFY_LAUNCHPOINT is true", func() {
t.Setenv("BP_LAUNCHPOINT", "./no-such-file.js")
t.Setenv("BP_VERIFY_LAUNCHPOINT", "true")
file, err := libnodejs.FindNodeApplication(workingDir)
Expect(err).To(MatchError(ContainSubstring("expected value derived from BP_LAUNCHPOINT [./no-such-file.js] to be an existing file")))
Expect(file).To(Equal(""))
})

it("returns the highest priority file if BP_VERIFY_LAUNCHPOINT is false", func() {
t.Setenv("BP_LAUNCHPOINT", "./gen/no-such-file-yet.js")
t.Setenv("BP_VERIFY_LAUNCHPOINT", "false")
file, err := libnodejs.FindNodeApplication(workingDir)
Expect(err).NotTo(HaveOccurred())
Expect(file).To(Equal(filepath.Join("gen", "no-such-file-yet.js")))
})
})
})

Expand Down
1 change: 1 addition & 0 deletions spec_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ package libnodejs

const ProjectPathEnvName = "BP_NODE_PROJECT_PATH"
const LaunchPointEnvName = "BP_LAUNCHPOINT"
const VerifyLaunchPointEnvName = "BP_VERIFY_LAUNCHPOINT"
const StartScriptNameEnvName = "BP_NPM_START_SCRIPT"

0 comments on commit 05a709e

Please sign in to comment.