Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: patch-package is not applied in dist'ed build #19239

Merged
merged 8 commits into from
Dec 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ macWorkflowFilters: &mac-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ tgriesser/fix/patch-resolutions, << pipeline.git.branch >> ]
- equal: [ renovate/cypress-request-2.x, << pipeline.git.branch >> ]
- matches:
pattern: "-release$"
Expand All @@ -47,6 +48,7 @@ windowsWorkflowFilters: &windows-workflow-filters
or:
- equal: [ master, << pipeline.git.branch >> ]
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ tgriesser/fix/patch-resolutions, << pipeline.git.branch >> ]
- matches:
pattern: "-release$"
value: << pipeline.git.branch >>
Expand Down Expand Up @@ -1586,7 +1588,7 @@ jobs:
- run:
name: Check current branch to persist artifacts
command: |
if [[ "$CIRCLE_BRANCH" != "develop" ]]; then
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "tgriesser/fix/patch-resolutions" ]]; then
echo "Not uploading artifacts or posting install comment for this branch."
circleci-agent step halt
fi
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@
"trash": "5.2.0",
"tree-kill": "1.2.2",
"ts-node": "8.5.4",
"tsconfig-paths": "3.10.1",
Copy link
Member

Choose a reason for hiding this comment

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

why did this need move from a dev-dep?

Copy link
Member Author

Choose a reason for hiding this comment

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

Trying to find where it failed - might have only been locally when I was writing the test case for the patch being applied, and it wasn't... and then I noticed that we do indeed use the package in a prod situation:

debug('registering project TS with options %o', tsOptions)
require('tsconfig-paths/register')
tsnode.register(tsOptions)
} catch (err) {
debug(`typescript doesn't exist. ts-node setup failed.`)
debug('error message: %s', err.message)

Copy link
Member

Choose a reason for hiding this comment

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

Nice catch then!

"tslib": "2.3.0",
"underscore.string": "3.3.5",
"url-parse": "1.5.2",
Expand Down Expand Up @@ -184,7 +185,6 @@
"supertest-session": "4.0.0",
"through2": "2.0.5",
"ts-loader": "7.0.4",
"tsconfig-paths": "3.10.1",
"webpack": "4.43.0",
"ws": "5.2.3",
"xvfb": "cypress-io/node-xvfb#22e3783c31d81ebe64d8c0df491ea00cdc74726a",
Expand Down
4 changes: 4 additions & 0 deletions packages/socket/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
},
"dependencies": {
"circular-json": "0.5.9",
"engine.io": "5.0.0",
"engine.io-parser": "4.0.2",
Comment on lines +17 to +18
Copy link
Member Author

Choose a reason for hiding this comment

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

Needed to add this, as it was being hoisted when devDeps are stripped & patch wasn't being applied.

"socket.io": "4.0.1",
"socket.io-client": "4.0.1"
},
Expand All @@ -30,6 +32,8 @@
],
"workspaces": {
"nohoist": [
"engine.io",
"engine.io-parser",
"socket.io",
"socket.io/socket.io-parser",
"socket.io-client",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 12 additions & 4 deletions scripts/binary/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,23 @@ export async function buildCypressApp (options: BuildCypressAppOpts) {
// Copy Packages: We want to copy the package.json, files, and output
Copy link
Member

Choose a reason for hiding this comment

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

why re-name from .patch to .dev.patch?

Copy link
Member

Choose a reason for hiding this comment

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

Do the patches in packages/socket/patches & packages/server/patches also need to be renamed to .dev.patch?

Copy link
Member Author

@tgriesser tgriesser Dec 3, 2021

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

Ahhhh okay 👍🏻

Copy link
Member Author

@tgriesser tgriesser Dec 3, 2021

Choose a reason for hiding this comment

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

Oops, had the wrong link, updated the above with the failing circle job. But here's the docs: https://github.com/ds300/patch-package#dev-only-patches

And no, the socket & server ones are prod dependencies, so they remain .patch

log('#copyAllToDist')
await packages.copyAllToDist(DIST_DIR)
fs.copySync(path.join(CY_ROOT_DIR, 'patches'), path.join(DIST_DIR, 'patches'))

const jsonRoot = fs.readJSONSync(path.join(CY_ROOT_DIR, 'package.json'))

fs.writeJsonSync(meta.distDir('package.json'), _.omit(jsonRoot, [
'scripts',
const packageJsonContents = _.omit(jsonRoot, [
'devDependencies',
'lint-staged',
'engines',
]), { spaces: 2 })
'scripts',
])

fs.writeJsonSync(meta.distDir('package.json'), {
...packageJsonContents,
scripts: {
postinstall: 'patch-package',
},
}, { spaces: 2 })

// Copy the yarn.lock file so we have a consistent install
fs.copySync(path.join(CY_ROOT_DIR, 'yarn.lock'), meta.distDir('yarn.lock'))
Expand Down Expand Up @@ -153,7 +161,7 @@ require('./packages/server')\
log(`#testVersion ${meta.distDir()}`)
await testVersion(meta.distDir(), version)

// testBuiltStaticAssets
log('#testStaticAssets')
await testStaticAssets(meta.distDir())

log('#removeCyAndBinFolders')
Expand Down
1 change: 0 additions & 1 deletion scripts/binary/util/packages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ export async function copyAllToDist (distDir: string) {
try {
// Strip out dev-dependencies & scripts for everything in /packages so we can yarn install in there
await fs.writeJson(path.join(distDir, pkg, 'package.json'), _.omit(json, [
'scripts',
'devDependencies',
'lint-staged',
'engines',
Expand Down
28 changes: 28 additions & 0 deletions scripts/binary/util/testStaticAssets.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,34 @@ const testStaticAssets = async (buildResourcePath) => {
'react.production.min.js',
],
}),
testPackageStaticAssets({
assetGlob: `${buildResourcePath}/packages/socket/node_modules/socket.io-parser/dist/binary.js`,
badStrings: [
'pack.data = _deconstructPacket(packetData, buffers);',
],
goodStrings: [
'pack.data = _deconstructPacket(packetData, buffers, [], new WeakMap());',
],
}),
testPackageStaticAssets({
assetGlob: `${buildResourcePath}/packages/socket/node_modules/engine.io-parser/lib/encodePacket.browser.js`,
badStrings: [
'return callback(data instanceof ArrayBuffer ? data : data.buffer);',
],
goodStrings: [
'This extra check is made because the "instanceof ArrayBuffer" check does not work',
'return callback((data instanceof ArrayBuffer || isArrayBuffer(data)) ? data : data.buffer);',
],
}),
testPackageStaticAssets({
assetGlob: `${buildResourcePath}/node_modules/winston/lib/winston/common.js`,
badStrings: [
`if (target.padLevels) {`,
],
goodStrings: [
`if (target.hasOwnProperty('padLevels') && target.padLevels) {`,
],
}),
])
}

Expand Down
36 changes: 18 additions & 18 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17601,6 +17601,13 @@ engine.io-client@~5.0.0:
ws "~7.4.2"
yeast "0.1.2"

engine.io-parser@4.0.2, engine.io-parser@~4.0.0, engine.io-parser@~4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/engine.io-parser/-/engine.io-parser-4.0.2.tgz#e41d0b3fb66f7bf4a3671d2038a154024edb501e"
integrity sha512-sHfEQv6nmtJrq6TKuIz5kyEKH/qSdK56H/A+7DnAuUPWosnIZAS2NHNcPLmyjtY3cGS/MqJdZbUjW97JU72iYg==
dependencies:
base64-arraybuffer "0.1.4"

engine.io-parser@~2.2.0:
version "2.2.1"
resolved "https://registry.yarnpkg.com/engine.io-parser/-/engine.io-parser-2.2.1.tgz#57ce5611d9370ee94f99641b589f94c97e4f5da7"
Expand All @@ -17612,12 +17619,18 @@ engine.io-parser@~2.2.0:
blob "0.0.5"
has-binary2 "~1.0.2"

engine.io-parser@~4.0.0, engine.io-parser@~4.0.1:
version "4.0.2"
resolved "https://registry.yarnpkg.com/engine.io-parser/-/engine.io-parser-4.0.2.tgz#e41d0b3fb66f7bf4a3671d2038a154024edb501e"
integrity sha512-sHfEQv6nmtJrq6TKuIz5kyEKH/qSdK56H/A+7DnAuUPWosnIZAS2NHNcPLmyjtY3cGS/MqJdZbUjW97JU72iYg==
engine.io@5.0.0, engine.io@~5.0.0:
version "5.0.0"
resolved "https://registry.npmjs.org/engine.io/-/engine.io-5.0.0.tgz#470dc94a8a4907fa4d2cd1fa6611426afcee61bf"
integrity sha512-BATIdDV3H1SrE9/u2BAotvsmjJg0t1P4+vGedImSs1lkFAtQdvk4Ev1y4LDiPF7BPWgXWEG+NDY+nLvW3UrMWw==
dependencies:
base64-arraybuffer "0.1.4"
accepts "~1.3.4"
base64id "2.0.0"
cookie "~0.4.1"
cors "~2.8.5"
debug "~4.3.1"
engine.io-parser "~4.0.0"
ws "~7.4.2"

engine.io@~3.5.0:
version "3.5.0"
Expand All @@ -17631,19 +17644,6 @@ engine.io@~3.5.0:
engine.io-parser "~2.2.0"
ws "~7.4.2"

engine.io@~5.0.0:
version "5.0.0"
resolved "https://registry.npmjs.org/engine.io/-/engine.io-5.0.0.tgz#470dc94a8a4907fa4d2cd1fa6611426afcee61bf"
integrity sha512-BATIdDV3H1SrE9/u2BAotvsmjJg0t1P4+vGedImSs1lkFAtQdvk4Ev1y4LDiPF7BPWgXWEG+NDY+nLvW3UrMWw==
dependencies:
accepts "~1.3.4"
base64id "2.0.0"
cookie "~0.4.1"
cors "~2.8.5"
debug "~4.3.1"
engine.io-parser "~4.0.0"
ws "~7.4.2"

enhanced-resolve@4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-4.1.0.tgz#41c7e0bfdfe74ac1ffe1e57ad6a5c6c9f3742a7f"
Expand Down