Skip to content

Commit c9225ef

Browse files
authored
chore: replace yarn with npm (#5128)
* chore: replace yarn with npm * fix: parameter passing to `npm run` * fix: cache node_modules folder * fix: release build script for npm * chore: cache all node_modules folders * fix: pass e2e options along * fix: broken workspaces config * fix: npm install * fix: nohoist in package-lock * fix: correct package.lock nesting * fix: cache node_modules for plugins * fix: split2 dependency * fix: more missing dependencies * fix: dependencies dependencies dependencies * fix: more dependencies * fix: and some more dependencies * fix: you guessed it... * fix: yup * chore: cleanup plugins and sdk build outputs * fix: even more missing dependencies * fix: more dependency and module stuff * fix: move sdk outputs into build directory and do not hide fact that this is not an ESM module so this only worked because we bundled everything into the same directory * refactor: you will not believe it * refactor: how many dependencies were never really declared? * refactor: touch was listed twice * fix: CJS compatible node-fetch * fix: make mocha find tests * fix: more missing dependencies * fix: prettier fix * chore: add package-lock for k8s-namespace and k8s-deployment package * fix: by now I am out of ideas * fix: sdk tsconfig * fix: pulumi test files are not in build folder * chore: move pulumi plugin into src folder * chore: move all plugin code in src directories * fix: make sure plugin tests can find their static test files * fix: script-utils ignore * fix: more plugin test path fixes * fix: package build using package-lock and workspaces for package install * fix: alpine builder image
1 parent c55a2e7 commit c9225ef

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

92 files changed

+70266
-17244
lines changed

.circleci/config.yml

Lines changed: 29 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,25 @@ commands:
9494
steps:
9595
- restore_cache:
9696
keys:
97-
- yarn-v7-<<parameters.context>>-{{ checksum "yarn.lock" }}
97+
- npm-v2-<<parameters.context>>-{{ checksum "package-lock.json" }}
9898

99-
- run: yarn
99+
- run: npm ci
100100

101101
- save_cache:
102-
key: yarn-v7-<<parameters.context>>-{{ checksum "yarn.lock" }}
102+
key: npm-v2-<<parameters.context>>-{{ checksum "package-lock.json" }}
103103
paths:
104-
- ~/.cache/yarn
104+
- node_modules
105+
- cli/node_modules
106+
- core/node_modules
107+
- e2e/node_modules
108+
- plugins/conftest/node_modules
109+
- plugins/conftest-container/node_modules
110+
- plugins/conftest-kubernetes/node_modules
111+
- plugins/jib/node_modules
112+
- plugins/maven-container/node_modules
113+
- plugins/pulumi/node_modules
114+
- plugins/terraform/node_modules
115+
- sdk/node_modules
105116

106117
configure_git:
107118
description: Configure git (needed for some tests)
@@ -233,7 +244,7 @@ commands:
233244
- *attach-workspace
234245
- restore_cache:
235246
keys:
236-
- pkg-v3-{{ checksum "yarn.lock" }}
247+
- pkg-v3-{{ checksum "package-lock.json" }}
237248
- run:
238249
name: Install Codesigning utility (needed for ARM64 on MacOS)
239250
command: |
@@ -248,15 +259,15 @@ commands:
248259
sudo apt-get install -y binfmt-support
249260
- run:
250261
name: Run dist script
251-
command: yarn run dist --version "<<parameters.version>>"
262+
command: npm run dist -- --version "<<parameters.version>>"
252263
- persist_to_workspace:
253264
root: ./
254265
paths:
255266
- dist/
256267
# Needed for the alpine docker build
257268
- tmp/pkg/
258269
- save_cache:
259-
key: pkg-v3-{{ checksum "yarn.lock" }}
270+
key: pkg-v3-{{ checksum "package-lock.json" }}
260271
paths:
261272
- tmp/pkg-fetch
262273
- run:
@@ -279,7 +290,7 @@ jobs:
279290
- run:
280291
name: build
281292
command: |
282-
yarn run build
293+
npm run build
283294
# Save the built output to be used for the docker image and for the release steps
284295
- persist_to_workspace:
285296
# Must be an absolute path, or relative path from working_directory. This is a directory on the container which is
@@ -316,10 +327,10 @@ jobs:
316327
- *attach-workspace
317328
- run:
318329
name: lint
319-
command: yarn run lint
330+
command: npm run lint
320331
- run:
321332
name: prettier
322-
command: yarn run prettier
333+
command: npm run prettier
323334

324335
check-docs:
325336
<<: *node-config
@@ -329,7 +340,7 @@ jobs:
329340
- *attach-workspace
330341
- run:
331342
name: Make sure generated docs are up-to-date
332-
command: yarn run check-docs
343+
command: npm run check-docs
333344

334345
check-package-licenses:
335346
<<: *node-config
@@ -341,7 +352,7 @@ jobs:
341352
name: Make sure dependency licenses are okay
342353
command: |
343354
mkdir tmp
344-
yarn check-package-licenses
355+
npm run check-package-licenses
345356
346357
test-framework:
347358
<<: *node-config
@@ -355,7 +366,7 @@ jobs:
355366
- run:
356367
name: Unit test framework components
357368
command: |
358-
yarn run test:framework:unit
369+
npm run test:framework:unit
359370
environment:
360371
CHOKIDAR_USEPOLLING: "1"
361372
NODE_OPTIONS: --max_old_space_size=4096
@@ -382,7 +393,7 @@ jobs:
382393
cd e2e/projects/<<parameters.project>>
383394
git checkout .
384395
cd ~/project
385-
yarn e2e-project --project=<<parameters.project>> --env=<<parameters.environment>> --showlog -b
396+
npm run e2e-project -- --project=<<parameters.project>> --env=<<parameters.environment>> --showlog -b
386397
- cleanup_remote_cluster:
387398
filter: <<parameters.project>>-testing-ci-$CIRCLE_BUILD_NUM-e2e
388399

@@ -579,7 +590,7 @@ jobs:
579590
# Run tests
580591
- run:
581592
name: Plugin tests
582-
command: yarn run test:plugins
593+
command: npm run test:plugins
583594
# Persist Maven cache
584595
- save_cache:
585596
key: m2-v1
@@ -613,7 +624,7 @@ jobs:
613624
# Notes:
614625
# - We skip tests that only work for remote environments
615626
# - We currently don't support in-cluster building on kind.
616-
yarn integ-kind
627+
npm run integ-kind
617628
- run:
618629
name: Deploy demo-project
619630
command: ./bin/garden deploy --root examples/demo-project --logger-type basic
@@ -742,7 +753,7 @@ jobs:
742753
# Note: We skip tests that only work for remote environments
743754
command: |
744755
cd core
745-
GARDEN_SKIP_TESTS="<<parameters.skipTests>>" yarn _integ
756+
GARDEN_SKIP_TESTS="<<parameters.skipTests>>" npm run _integ
746757
- run:
747758
name: Deploy demo-project
748759
command: ./bin/garden deploy --root examples/demo-project
@@ -782,7 +793,7 @@ jobs:
782793
# Note: We skip tests that only work for remote environments
783794
command: |
784795
cd core
785-
GARDEN_SKIP_TESTS="<<parameters.skipTests>>" yarn _integ
796+
GARDEN_SKIP_TESTS="<<parameters.skipTests>>" npm run _integ
786797
- run:
787798
name: Deploy demo-project
788799
command: ./bin/garden deploy --root examples/demo-project

.github/workflows/publish-release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ jobs:
2222
node-version: 18.x
2323
- name: Build package
2424
run: |
25-
yarn
26-
yarn build
25+
npm ci
26+
npm run build
2727
- name: Setup npm registry authentication
2828
working-directory: ./core
2929
run: |

.npmrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Ensure that dependencies are not hoisted up
2+
# Hoisting may cause troubles with some bundler tools
3+
install-strategy = "nested"

.yarnrc

Lines changed: 0 additions & 5 deletions
This file was deleted.

cli/package.json

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,12 @@
2929
"@garden-io/garden-jib": "*",
3030
"@garden-io/garden-pulumi": "*",
3131
"@garden-io/garden-terraform": "*",
32+
"@scg82/exit-hook": "^3.4.1",
3233
"chalk": "^4.1.2",
34+
"node-abi": "^3.45.0",
3335
"patch-package": "^6.5.1",
34-
"pkg": "5.8.1"
36+
"pkg": "5.8.1",
37+
"source-map-support": "^0.5.21"
3538
},
3639
"devDependencies": {
3740
"@types/chai": "^4.3.4",
@@ -50,8 +53,8 @@
5053
},
5154
"scripts": {
5255
"add-version-files": "node build/src/add-version-files.js",
53-
"build": "tsc --build . --verbose && yarn run add-version-files && yarn run generate-docs",
54-
"check-package-lock": "git diff-index --quiet HEAD -- yarn.lock || (echo 'yarn.lock is dirty!' && exit 1)",
56+
"build": "tsc --build . --verbose && npm run add-version-files && npm run generate-docs",
57+
"check-package-lock": "git diff-index --quiet HEAD -- package-lock.json || (echo 'package-lock.json is dirty!' && exit 1)",
5558
"clean": "shx rm -rf build dist",
5659
"fix-format": "prettier --write \"{src,test}/**/*.ts\"",
5760
"generate-docs": "node ./build/src/generate-docs.js",
@@ -66,10 +69,5 @@
6669
"node_modules/@garden-io/**/*.js",
6770
"node_modules/es-get-iterator/**/*.js"
6871
]
69-
},
70-
"workspaces": {
71-
"nohoist": [
72-
"pkg"
73-
]
7472
}
75-
}
73+
}

cli/src/build-pkg.ts

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ export function getTarballFilename(version: string, targetName: string): string
7171
return composePackageFilename(version, targetName, "tar.gz")
7272
}
7373

74+
export type NPMWorkspaceQueryResult = {
75+
name: string
76+
location: string
77+
dependencies: Record<string, string>
78+
}
79+
7480
async function buildBinaries(args: string[]) {
7581
const argv = minimist(args)
7682
const version = argv.version || getPackageVersion()
@@ -90,14 +96,14 @@ async function buildBinaries(args: string[]) {
9096

9197
// Copy each package to the temp dir
9298
console.log(chalk.cyan("Getting package info"))
93-
const res = (await exec("yarn", ["--json", "workspaces", "info"])).stdout
94-
const workspaces = JSON.parse(JSON.parse(res).data)
99+
const res = (await exec("npm", ["query", ".workspace"])).stdout
100+
const workspaces: NPMWorkspaceQueryResult[] = JSON.parse(res)
95101

96102
console.log(chalk.cyan("Copying packages"))
97103
await Promise.all(
98-
Object.entries(workspaces).map(async ([name, info]: [string, any]) => {
99-
const sourcePath = resolve(repoRoot, info.location)
100-
const targetPath = resolve(tmpDirPath, info.location)
104+
workspaces.map(async ({ name, location }: { name: string; location: string }) => {
105+
const sourcePath = resolve(repoRoot, location)
106+
const targetPath = resolve(tmpDirPath, location)
101107
await remove(targetPath)
102108
await mkdirp(targetPath)
103109
await exec("rsync", [
@@ -117,13 +123,19 @@ async function buildBinaries(args: string[]) {
117123
// Edit all the packages to have them directly link any internal dependencies
118124
console.log(chalk.cyan("Modifying package.json files for direct installation"))
119125
await Promise.all(
120-
Object.entries(workspaces).map(async ([name, info]: [string, any]) => {
121-
const packageRoot = resolve(tmpDirPath, info.location)
126+
workspaces.map(async ({ name, location, dependencies }) => {
127+
const packageRoot = resolve(tmpDirPath, location)
122128
const packageJsonPath = resolve(packageRoot, "package.json")
123129
const packageJson = require(packageJsonPath)
124130

125-
for (const depName of info.workspaceDependencies) {
126-
const depInfo = workspaces[depName]
131+
const workspaceDependencies = Object.keys(dependencies).filter((dependencyName) => {
132+
return workspaces.some((p) => p.name === dependencyName)
133+
})
134+
for (const depName of workspaceDependencies) {
135+
const depInfo = workspaces.find((p) => p.name === depName)
136+
if (!depInfo) {
137+
throw new Error("Could not find workspace info for " + depName)
138+
}
127139
const targetRoot = resolve(tmpDirPath, depInfo.location)
128140
const relPath = relative(packageRoot, targetRoot)
129141
packageJson.dependencies[depName] = "file:" + relPath
@@ -141,11 +153,16 @@ async function buildBinaries(args: string[]) {
141153
})
142154
)
143155

144-
// Run yarn install in the cli package
145-
console.log(chalk.cyan("Installing packages in @garden-io/cli package"))
146-
const cliPath = resolve(tmpDirPath, workspaces["@garden-io/cli"].location)
147-
await exec("yarn", ["--production"], { cwd: cliPath })
156+
// Run npm install in the cli package
157+
await copy(resolve(repoRoot, "package.json"), resolve(tmpDirPath, "package.json"))
158+
await copy(resolve(repoRoot, "package-lock.json"), resolve(tmpDirPath, "package-lock.json"))
159+
// The `.npmrc` config ensures that we're not hoisting any dependencies
160+
await copy(resolve(repoRoot, ".npmrc"), resolve(tmpDirPath, ".npmrc"))
161+
162+
console.log("Installing all packages in workspaces")
163+
await exec("npm", ["install", "--omit=dev"], { cwd: tmpDirPath, stdio: "inherit" })
148164

165+
const cliPath = resolve(tmpDirPath, workspaces.find((p) => p.name === "@garden-io/cli")!.location)
149166
// Run pkg and pack up each platform binary
150167
console.log(chalk.cyan("Packaging garden binaries"))
151168

@@ -292,7 +309,7 @@ async function pkgCommon({
292309
} else {
293310
const filename = nodeBinaryPlatform === "linuxmusl" ? `node.abi${abi}.musl.node` : `node.abi${abi}.node`
294311
const abiPath = resolve(
295-
repoRoot,
312+
GARDEN_CORE_ROOT,
296313
"node_modules",
297314
"node-pty-prebuilt-multiarch",
298315
"prebuilds",
@@ -322,7 +339,7 @@ async function pkgCommon({
322339
"--output",
323340
resolve(targetPath, binFilename),
324341
],
325-
{ env: { PKG_CACHE_PATH: pkgFetchTmpDir } }
342+
{ env: { PKG_CACHE_PATH: pkgFetchTmpDir }, stdio: "inherit" }
326343
)
327344

328345
console.log(` - ${targetName} -> static`)

0 commit comments

Comments
 (0)