MCPcopy Create free account
hub / github.com/OverloadBlitz/cloudcent-cli / resolveNodeEntry

Function resolveNodeEntry

cmd/pulumi.go:1198–1226  ·  view source on GitHub ↗

resolveNodeEntry finds the TypeScript/JavaScript entry point for a Node.js Pulumi project. It checks package.json "main" first, then falls back to index.ts / index.js.

(dir string)

Source from the content-addressed store, hash-verified

1196// resolveNodeEntry finds the TypeScript/JavaScript entry point for a Node.js Pulumi project.
1197// It checks package.json "main" first, then falls back to index.ts / index.js.
1198func resolveNodeEntry(dir string) (string, error) {
1199 // Try to read main from package.json
1200 pkgData, err := os.ReadFile(filepath.Join(dir, "package.json"))
1201 if err == nil {
1202 var pkg struct {
1203 Main string `json:"main"`
1204 }
1205 if jsonErr := json.Unmarshal(pkgData, &pkg); jsonErr == nil && pkg.Main != "" {
1206 // If main points to a .js file, check for a sibling .ts file first
1207 // (the .ts is the source; .js would only exist after tsc).
1208 mainPath := filepath.Join(dir, pkg.Main)
1209 tsVariant := strings.TrimSuffix(mainPath, ".js") + ".ts"
1210 if _, err := os.Stat(tsVariant); err == nil {
1211 return tsVariant, nil
1212 }
1213 if _, err := os.Stat(mainPath); err == nil {
1214 return mainPath, nil
1215 }
1216 }
1217 }
1218 // Fall back to index.ts, then index.js
1219 for _, candidate := range []string{"index.ts", "index.js"} {
1220 p := filepath.Join(dir, candidate)
1221 if _, err := os.Stat(p); err == nil {
1222 return p, nil
1223 }
1224 }
1225 return "", fmt.Errorf("could not find a Node.js entry point in %s (tried package.json main, index.ts, index.js)", dir)
1226}
1227
1228// prependPath returns a copy of env with the given directory prepended to PATH.
1229func prependPath(env []string, dir string) []string {

Callers 1

runUserProgramToFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected