Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

Use NPMRC_DATA to write .npmrc file in auto-indexing job for Typescript #53529

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ import (

func TestTypeScriptGenerator(t *testing.T) {
expectedIndexerImage, _ := libs.DefaultIndexerForLang("typescript")
npmrcStep := `if [ "$NPMRC_DATA" ]; then
echo "Writing npmrc config to $HOME/.npmrc"
echo "$NPMRC_DATA" > ~/.npmrc
else
echo "No npmrc config set, continuing"
fi`
nodeMemoryStep := `if [ -n "${VM_MEM_MB:-}" ]; then export NODE_OPTIONS="--max-old-space-size=$VM_MEM_MB"; fi`

expectedLocalSteps := []string{nodeMemoryStep, npmrcStep}

testGenerators(t,
generatorTestCase{
Expand All @@ -25,7 +34,7 @@ func TestTypeScriptGenerator(t *testing.T) {
Commands: []string{"npm install --ignore-scripts"},
},
},
LocalSteps: []string{`if [ -n "${VM_MEM_MB:-}" ]; then export NODE_OPTIONS="--max-old-space-size=$VM_MEM_MB"; fi`},
LocalSteps: expectedLocalSteps,
Root: "",
Indexer: expectedIndexerImage,
IndexerArgs: []string{"scip-typescript", "index", "--infer-tsconfig"},
Expand All @@ -49,7 +58,7 @@ func TestTypeScriptGenerator(t *testing.T) {
Commands: []string{"yarn --ignore-scripts"},
},
},
LocalSteps: []string{`if [ -n "${VM_MEM_MB:-}" ]; then export NODE_OPTIONS="--max-old-space-size=$VM_MEM_MB"; fi`},
LocalSteps: expectedLocalSteps,
Root: "",
Indexer: expectedIndexerImage,
IndexerArgs: []string{"scip-typescript", "index", "--infer-tsconfig"},
Expand All @@ -66,7 +75,7 @@ func TestTypeScriptGenerator(t *testing.T) {
expected: []config.IndexJob{
{
Steps: nil,
LocalSteps: []string{`if [ -n "${VM_MEM_MB:-}" ]; then export NODE_OPTIONS="--max-old-space-size=$VM_MEM_MB"; fi`},
LocalSteps: expectedLocalSteps,
Root: "",
Indexer: expectedIndexerImage,
IndexerArgs: []string{"scip-typescript", "index"},
Expand All @@ -85,7 +94,7 @@ func TestTypeScriptGenerator(t *testing.T) {
expected: []config.IndexJob{
{
Steps: nil,
LocalSteps: []string{`if [ -n "${VM_MEM_MB:-}" ]; then export NODE_OPTIONS="--max-old-space-size=$VM_MEM_MB"; fi`},
LocalSteps: expectedLocalSteps,
Root: "a",
Indexer: expectedIndexerImage,
IndexerArgs: []string{"scip-typescript", "index"},
Expand All @@ -94,7 +103,7 @@ func TestTypeScriptGenerator(t *testing.T) {
},
{
Steps: nil,
LocalSteps: []string{`if [ -n "${VM_MEM_MB:-}" ]; then export NODE_OPTIONS="--max-old-space-size=$VM_MEM_MB"; fi`},
LocalSteps: expectedLocalSteps,
Root: "b",
Indexer: expectedIndexerImage,
IndexerArgs: []string{"scip-typescript", "index"},
Expand All @@ -103,7 +112,7 @@ func TestTypeScriptGenerator(t *testing.T) {
},
{
Steps: nil,
LocalSteps: []string{`if [ -n "${VM_MEM_MB:-}" ]; then export NODE_OPTIONS="--max-old-space-size=$VM_MEM_MB"; fi`},
LocalSteps: expectedLocalSteps,
Root: "c",
Indexer: expectedIndexerImage,
IndexerArgs: []string{"scip-typescript", "index"},
Expand Down Expand Up @@ -133,7 +142,7 @@ func TestTypeScriptGenerator(t *testing.T) {
Commands: []string{"npm install"},
},
},
LocalSteps: []string{`if [ -n "${VM_MEM_MB:-}" ]; then export NODE_OPTIONS="--max-old-space-size=$VM_MEM_MB"; fi`},
LocalSteps: expectedLocalSteps,
Root: "",
Indexer: expectedIndexerImage,
IndexerArgs: []string{"scip-typescript", "index"},
Expand All @@ -153,7 +162,7 @@ func TestTypeScriptGenerator(t *testing.T) {
Commands: []string{"yarn"},
},
},
LocalSteps: []string{`if [ -n "${VM_MEM_MB:-}" ]; then export NODE_OPTIONS="--max-old-space-size=$VM_MEM_MB"; fi`},
LocalSteps: expectedLocalSteps,
Root: "foo/bar/baz",
Indexer: expectedIndexerImage,
IndexerArgs: []string{"scip-typescript", "index"},
Expand All @@ -178,7 +187,7 @@ func TestTypeScriptGenerator(t *testing.T) {
Commands: []string{"npm install"},
},
},
LocalSteps: []string{`if [ -n "${VM_MEM_MB:-}" ]; then export NODE_OPTIONS="--max-old-space-size=$VM_MEM_MB"; fi`},
LocalSteps: expectedLocalSteps,
Root: "foo/bar/bonk",
Indexer: expectedIndexerImage,
IndexerArgs: []string{"scip-typescript", "index"},
Expand All @@ -193,7 +202,7 @@ func TestTypeScriptGenerator(t *testing.T) {
Commands: []string{"npm install"},
},
},
LocalSteps: []string{`if [ -n "${VM_MEM_MB:-}" ]; then export NODE_OPTIONS="--max-old-space-size=$VM_MEM_MB"; fi`},
LocalSteps: expectedLocalSteps,
Root: "foo/baz",
Indexer: expectedIndexerImage,
IndexerArgs: []string{"scip-typescript", "index"},
Expand All @@ -218,7 +227,7 @@ func TestTypeScriptGenerator(t *testing.T) {
Commands: []string{"yarn"},
},
},
LocalSteps: []string{`if [ -n "${VM_MEM_MB:-}" ]; then export NODE_OPTIONS="--max-old-space-size=$VM_MEM_MB"; fi`},
LocalSteps: expectedLocalSteps,
Root: "",
Indexer: expectedIndexerImage,
IndexerArgs: []string{"scip-typescript", "index"},
Expand All @@ -243,10 +252,10 @@ func TestTypeScriptGenerator(t *testing.T) {
Commands: []string{"N_NODE_MIRROR=https://unofficial-builds.nodejs.org/download/release n --arch x64-musl auto", "npm install"},
},
},
LocalSteps: []string{
"N_NODE_MIRROR=https://unofficial-builds.nodejs.org/download/release n --arch x64-musl auto",
`if [ -n "${VM_MEM_MB:-}" ]; then export NODE_OPTIONS="--max-old-space-size=$VM_MEM_MB"; fi`,
},
LocalSteps: append(
[]string{"N_NODE_MIRROR=https://unofficial-builds.nodejs.org/download/release n --arch x64-musl auto"},
expectedLocalSteps...,
),
Root: "",
Indexer: expectedIndexerImage,
IndexerArgs: []string{"scip-typescript", "index"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,27 @@ local util = require("sg.autoindex.util")

local indexer = require("sg.autoindex.indexes").get "typescript"
local typescript_nmusl_command =
"N_NODE_MIRROR=https://unofficial-builds.nodejs.org/download/release n --arch x64-musl auto"
"N_NODE_MIRROR=https://unofficial-builds.nodejs.org/download/release n --arch x64-musl auto"

local exclude_paths = pattern.new_path_combine(shared.exclude_paths, {
pattern.new_path_segment("node_modules"),
})

local npmrc_steps = [[if [ "$NPMRC_DATA" ]; then
echo "Writing npmrc config to $HOME/.npmrc"
echo "$NPMRC_DATA" > ~/.npmrc
else
echo "No npmrc config set, continuing"
fi]]



local safe_decode = function(encoded)
local _, payload = pcall(function()
return json.decode(encoded)
end)
local _, payload = pcall(function()
return json.decode(encoded)
end)

return payload
return payload
end

local check_lerna_file = function(root, contents_by_path)
Expand Down Expand Up @@ -125,6 +134,8 @@ local infer_typescript_job = function(api, tsconfig_path, should_infer_config)
'if [ -n "${VM_MEM_MB:-}" ]; then export NODE_OPTIONS="--max-old-space-size=$VM_MEM_MB"; fi'
)

table.insert(local_steps, npmrc_steps)

varungandhi-src marked this conversation as resolved.
Show resolved Hide resolved
local args = { "scip-typescript", "index" }
if should_infer_config then
table.insert(args, "--infer-tsconfig")
Expand All @@ -137,7 +148,7 @@ local infer_typescript_job = function(api, tsconfig_path, should_infer_config)
indexer = indexer,
indexer_args = args,
outfile = "index.scip",
requested_envvars = { "NPM_TOKEN" },
requested_envvars = { "NPM_TOKEN", "NPMRC_DATA" },
}
end,
}))
Expand Down