Merge pull request #26610 from awanlin/topic/create-app-yarn-4

Updated `create-app` to use Yarn 4
This commit is contained in:
Andre Wanlin
2024-09-11 08:18:12 -05:00
committed by GitHub
13 changed files with 1004 additions and 87 deletions
+2 -28
View File
@@ -209,45 +209,19 @@ describe('tasks', () => {
await expect(buildAppTask(appDir)).resolves.not.toThrow();
expect(mockChdir).toHaveBeenCalledTimes(1);
expect(mockChdir).toHaveBeenNthCalledWith(1, appDir);
expect(mockExec).toHaveBeenCalledTimes(3);
expect(mockExec).toHaveBeenCalledTimes(2);
expect(mockExec).toHaveBeenNthCalledWith(
1,
'yarn --version',
expect.any(Function),
);
expect(mockExec).toHaveBeenNthCalledWith(
2,
'yarn install',
expect.any(Function),
);
expect(mockExec).toHaveBeenNthCalledWith(
3,
2,
'yarn tsc',
expect.any(Function),
);
});
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 => {
@@ -15,7 +15,7 @@ coverage
# Dependencies
node_modules/
# Yarn 3 files
# Yarn files
.pnp.*
.yarn/*
!.yarn/patches
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"
},
@@ -3,7 +3,7 @@
#
# Before building this image, be sure to have run the following commands in the repo root:
#
# yarn install
# yarn install --immutable
# yarn tsc
# yarn build:backend
#
@@ -11,19 +11,23 @@
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.
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 libsqlite3-dev
apt-get install -y --no-install-recommends libsqlite3-dev && \
rm -rf /var/lib/apt/lists/*
# From here on we use the least-privileged `node` user to run the backend.
USER node
@@ -33,6 +37,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 +51,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 && rm -rf "$(yarn cache clean)"
# This will include the examples, if you don't need these simply remove this line
COPY --chown=node:node examples ./examples