Skip to content

Commit

Permalink
fix: improve binary cleanup to look at binary rather than monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanthemanuel committed Nov 8, 2022
1 parent 5e3a21c commit 6d1af54
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
6 changes: 5 additions & 1 deletion .circleci/config.yml
Expand Up @@ -27,6 +27,7 @@ mainBuildFilters: &mainBuildFilters
branches:
only:
- develop
- 'ryanm/fix/improve-binary-cleanup-to-look-at-binary-rather-than-monorepo'

# usually we don't build Mac app - it takes a long time
# but sometimes we want to really confirm we are doing the right thing
Expand All @@ -35,6 +36,7 @@ macWorkflowFilters: &darwin-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ 'ryanm/fix/improve-binary-cleanup-to-look-at-binary-rather-than-monorepo', << pipeline.git.branch >> ]
- matches:
pattern: "-release$"
value: << pipeline.git.branch >>
Expand All @@ -43,6 +45,7 @@ linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ 'ryanm/fix/improve-binary-cleanup-to-look-at-binary-rather-than-monorepo', << pipeline.git.branch >> ]
- matches:
pattern: "-release$"
value: << pipeline.git.branch >>
Expand All @@ -60,6 +63,7 @@ windowsWorkflowFilters: &windows-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ 'ryanm/fix/improve-binary-cleanup-to-look-at-binary-rather-than-monorepo', << pipeline.git.branch >> ]
- matches:
pattern: "-release$"
value: << pipeline.git.branch >>
Expand Down Expand Up @@ -126,7 +130,7 @@ commands:
- run:
name: Check current branch to persist artifacts
command: |
if [[ "$CIRCLE_BRANCH" != "develop" ]]; then
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "ryanm/fix/improve-binary-cleanup-to-look-at-binary-rather-than-monorepo" ]]; then
echo "Not uploading artifacts or posting install comment for this branch."
circleci-agent step halt
fi
Expand Down
30 changes: 16 additions & 14 deletions scripts/binary/binary-cleanup.js
Expand Up @@ -36,22 +36,22 @@ async function removeEmptyDirectories (directory) {
}
}

const getDependencyPathsToKeep = async () => {
const getDependencyPathsToKeep = async (buildAppDir) => {
let entryPoints = new Set([
// This is the entry point for the server bundle. It will not have access to the snapshot yet. It needs to be kept in the binary
require.resolve('@packages/server/index.js'),
require.resolve('@packages/server/index.js', { paths: [buildAppDir] }),
// This is a dynamic import that is used to load the snapshot require logic. It will not have access to the snapshot yet. It needs to be kept in the binary
require.resolve('@packages/server/hook-require.js'),
require.resolve('@packages/server/hook-require.js', { paths: [buildAppDir] }),
// These dependencies are started in a new process or thread and will not have access to the snapshot. They need to be kept in the binary
require.resolve('@packages/server/lib/plugins/child/require_async_child.js'),
require.resolve('@packages/server/lib/plugins/child/register_ts_node.js'),
require.resolve('@packages/rewriter/lib/threads/worker.ts'),
require.resolve('@packages/server/lib/plugins/child/require_async_child.js', { paths: [buildAppDir] }),
require.resolve('@packages/server/lib/plugins/child/register_ts_node.js', { paths: [buildAppDir] }),
require.resolve('@packages/rewriter/lib/threads/worker.ts', { paths: [buildAppDir] }),
// These dependencies use the `require.resolve(<dependency>, { paths: [<path>] })` pattern where <path> is a path within the cypress monorepo. These will not be
// pulled in by esbuild but still need to be kept in the binary.
require.resolve('webpack'),
require.resolve('webpack-dev-server', { paths: [path.join(__dirname, '..', '..', 'npm', 'webpack-dev-server')] }),
require.resolve('html-webpack-plugin-4', { paths: [path.join(__dirname, '..', '..', 'npm', 'webpack-dev-server')] }),
require.resolve('html-webpack-plugin-5', { paths: [path.join(__dirname, '..', '..', 'npm', 'webpack-dev-server')] }),
require.resolve('webpack', { paths: [buildAppDir] }),
require.resolve('webpack-dev-server', { paths: [buildAppDir] }),
require.resolve('html-webpack-plugin-4', { paths: [buildAppDir] }),
require.resolve('html-webpack-plugin-5', { paths: [buildAppDir] }),
// These dependencies are completely dynamic using the pattern `require(`./${name}`)` and will not be pulled in by esbuild but still need to be kept in the binary.
...['ibmi',
'sunos',
Expand All @@ -61,7 +61,7 @@ const getDependencyPathsToKeep = async () => {
'linux',
'openbsd',
'sunos',
'win32'].map((platform) => require.resolve(`default-gateway/${platform}`)),
'win32'].map((platform) => require.resolve(`default-gateway/${platform}`, { paths: [buildAppDir] })),
])
let esbuildResult
let newEntryPointsFound = true
Expand All @@ -77,7 +77,9 @@ const getDependencyPathsToKeep = async () => {
outdir: workingDir,
platform: 'node',
metafile: true,
absWorkingDir: buildAppDir,
external: [
'./packages/packherd-require/dist/transpile-ts',
'./packages/server/server-entry',
'fsevents',
'pnpapi',
Expand All @@ -95,9 +97,9 @@ const getDependencyPathsToKeep = async () => {
let entryPoint

if (warningSubject.startsWith('.')) {
entryPoint = path.join(__dirname, '..', '..', path.dirname(warning.location.file), warningSubject)
entryPoint = path.join(buildAppDir, path.dirname(warning.location.file), warningSubject)
} else {
entryPoint = require.resolve(warningSubject)
entryPoint = require.resolve(warningSubject, { paths: [path.join(buildAppDir, path.dirname(warning.location.file))] })
}

if (path.extname(entryPoint) !== '' && !entryPoints.has(entryPoint)) {
Expand All @@ -114,7 +116,7 @@ const getDependencyPathsToKeep = async () => {
const cleanup = async (buildAppDir) => {
// 1. Retrieve all dependencies that still need to be kept in the binary. In theory, we could use the bundles generated here as single files within the binary,
// but for now, we just track on the dependencies that get pulled in
const keptDependencies = [...await getDependencyPathsToKeep(), 'package.json', 'packages/server/server-entry.js']
const keptDependencies = [...await getDependencyPathsToKeep(buildAppDir), 'package.json', 'packages/server/server-entry.js']

// 2. Gather the dependencies that could potentially be removed from the binary due to being in the snapshot
const potentiallyRemovedDependencies = [...snapshotMetadata.healthy, ...snapshotMetadata.deferred, ...snapshotMetadata.norewrite]
Expand Down

1 comment on commit 6d1af54

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 6d1af54 Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/11.0.0/linux-arm64/ryanm/fix/improve-binary-cleanup-to-look-at-binary-rather-than-monorepo-6d1af54fd37adc04ca8d0edf99daec0d31dbe793/cypress.tgz

Please sign in to comment.