Updated create-app to use Yarn 4

Signed-off-by: Andre Wanlin <awanlin@spotify.com>
This commit is contained in:
Andre Wanlin
2024-09-10 19:06:50 -05:00
parent f094dfd54a
commit 4975e634f4
9 changed files with 946 additions and 45 deletions
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/create-app': patch
---
Yarn 4 is now the default for `create-app`. Updated `yarn dev` script to use `yarn workspaces foreach`. Removed unused Lerna and Concurrently dependencies.
-21
View File
@@ -227,27 +227,6 @@ describe('tasks', () => {
);
});
it('should error out on incorrect yarn version', async () => {
// requires callback implementation to support `promisify` wrapper
// https://stackoverflow.com/a/60579617/10044859
mockExec.mockImplementation((_command, callback) => {
callback(null, { stdout: '3.2.1', stderr: 'standard error' });
});
const appDir = 'projects/dir';
await expect(buildAppTask(appDir)).rejects.toThrow(
/^@backstage\/create-app requires Yarn v1, found '3\.2\.1'/,
);
expect(mockChdir).toHaveBeenCalledTimes(1);
expect(mockChdir).toHaveBeenNthCalledWith(1, appDir);
expect(mockExec).toHaveBeenCalledTimes(1);
expect(mockExec).toHaveBeenNthCalledWith(
1,
'yarn --version',
expect.any(Function),
);
});
it('should fail if project directory does not exist', async () => {
const appDir = 'projects/missingProject';
await expect(buildAppTask(appDir)).rejects.toThrow(
-11
View File
@@ -187,17 +187,6 @@ export async function checkPathExistsTask(path: string) {
export async function buildAppTask(appDir: string) {
process.chdir(appDir);
await Task.forItem('determining', 'yarn version', async () => {
const result = await exec('yarn --version');
const yarnVersion = result.stdout?.trim();
if (yarnVersion && !yarnVersion.startsWith('1.')) {
throw new Error(
`@backstage/create-app requires Yarn v1, found '${yarnVersion}'. You can migrate the project to Yarn 3 after creation using https://backstage.io/docs/tutorials/yarn-migration`,
);
}
});
const runCmd = async (cmd: string) => {
await Task.forItem('executing', cmd, async () => {
await exec(cmd).catch(error => {
File diff suppressed because one or more lines are too long
@@ -0,0 +1,3 @@
nodeLinker: node-modules
yarnPath: .yarn/releases/yarn-4.4.1.cjs
@@ -1,6 +0,0 @@
{
"packages": ["packages/*", "plugins/*"],
"npmClient": "yarn",
"version": "0.1.0",
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
@@ -6,7 +6,7 @@
"node": "18 || 20"
},
"scripts": {
"dev": "concurrently \"yarn start\" \"yarn start-backend\"",
"dev": "yarn workspaces foreach -A --include backend --include app --parallel -v -i run start",
"start": "yarn workspace app start",
"start-backend": "yarn workspace backend start",
"build:backend": "yarn workspace backend build",
@@ -35,8 +35,6 @@
"@backstage/e2e-test-utils": "^{{version '@backstage/e2e-test-utils'}}",
"@playwright/test": "^1.32.3",
"@spotify/prettier-config": "^12.0.0",
"concurrently": "^8.0.0",
"lerna": "^7.3.0",
"node-gyp": "^10.0.0",
"prettier": "^2.3.2",
"typescript": "~5.4.0"
@@ -54,5 +52,6 @@
"*.{json,md}": [
"prettier --write"
]
}
},
"packageManager": "yarn@4.4.1"
}
@@ -50,10 +50,10 @@
"devDependencies": {
"@backstage/test-utils": "^{{version '@backstage/test-utils'}}",
"@playwright/test": "^1.32.3",
"@testing-library/dom": "^9.0.0",
"@testing-library/jest-dom": "^6.0.0",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.0.0",
"@testing-library/dom": "^9.0.0",
"@types/react-dom": "*",
"cross-env": "^7.0.0"
},
@@ -11,12 +11,15 @@
FROM node:18-bookworm-slim
# Set Python interpreter for `node-gyp` to use
ENV PYTHON=/usr/bin/python3
# Install isolate-vm dependencies, these are needed by the @backstage/plugin-scaffolder-backend.
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \
--mount=type=cache,target=/var/lib/apt,sharing=locked \
apt-get update && \
apt-get install -y --no-install-recommends python3 g++ build-essential && \
yarn config set python /usr/bin/python3
rm -rf /var/lib/apt/lists/*
# Install sqlite3 dependencies. You can skip this if you don't use sqlite3 in the image,
# in which case you should also move better-sqlite3 to "devDependencies" in package.json.
@@ -33,6 +36,10 @@ USER node
# If this occurs, then ensure BuildKit is enabled (`DOCKER_BUILDKIT=1`) so the app dir is correctly created as `node`.
WORKDIR /app
# Copy files needed by Yarn
COPY --chown=node:node .yarn ./.yarn
COPY --chown=node:node .yarnrc.yml ./
# This switches many Node.js dependencies to production mode.
ENV NODE_ENV=production
@@ -43,7 +50,7 @@ COPY --chown=node:node yarn.lock package.json packages/backend/dist/skeleton.tar
RUN tar xzf skeleton.tar.gz && rm skeleton.tar.gz
RUN --mount=type=cache,target=/home/node/.cache/yarn,sharing=locked,uid=1000,gid=1000 \
yarn install --frozen-lockfile --production --network-timeout 300000
yarn workspaces focus --all --production
# This will include the examples, if you don't need these simply remove this line
COPY --chown=node:node examples ./examples