forked from yarnpkg/berry
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: compress compat patches and the pnp hook (yarnpkg#1400)
* feat(compat): compress patches using brotli * feat(pnp): compress the hook source using brotli * chore: versions * Tries to add patch validations to the workflow * Verifies the patches when they change * Fixes path * Adds author config * Validates the hook too * Fixes the hook * fix: normalize line endings Co-authored-by: Maël Nison <nison.mael@gmail.com>
- Loading branch information
Showing
12 changed files
with
130 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
releases: | ||
"@yarnpkg/cli": prerelease | ||
"@yarnpkg/plugin-compat": prerelease | ||
"@yarnpkg/pnp": prerelease | ||
|
||
declined: | ||
- "@yarnpkg/plugin-constraints" | ||
- "@yarnpkg/plugin-dlx" | ||
- "@yarnpkg/plugin-essentials" | ||
- "@yarnpkg/plugin-init" | ||
- "@yarnpkg/plugin-interactive-tools" | ||
- "@yarnpkg/plugin-node-modules" | ||
- "@yarnpkg/plugin-npm-cli" | ||
- "@yarnpkg/plugin-pack" | ||
- "@yarnpkg/plugin-patch" | ||
- "@yarnpkg/plugin-pnp" | ||
- "@yarnpkg/plugin-stage" | ||
- "@yarnpkg/plugin-typescript" | ||
- "@yarnpkg/plugin-version" | ||
- "@yarnpkg/plugin-workspace-tools" | ||
- "@yarnpkg/builder" | ||
- "@yarnpkg/core" | ||
- "@yarnpkg/doctor" | ||
- "@yarnpkg/pnpify" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
const {readFileSync,writeFileSync} = require(`fs`); | ||
const {brotliCompressSync} = require(`zlib`); | ||
|
||
const patchContent = readFileSync(process.argv[2]); | ||
const jsFile = process.argv[3]; | ||
|
||
writeFileSync(jsFile, `/* eslint-disable */ | ||
export const patch = require('zlib').brotliDecompressSync(Buffer.from('${ | ||
brotliCompressSync(patchContent).toString(`base64`) | ||
}', 'base64')).toString(); | ||
`); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export const patch = | ||
`diff --git a/fsevents.js b/fsevents.js\nsemver exclusivity ^1\n--- a/fsevents.js\n+++ b/fsevents.js\n@@ -36,11 +36,15 @@ module.exports.Constants = Native.Constants;\n var defer = global.setImmediate || process.nextTick;\n\n function watch(path) {\n- var fse = new FSEvents(String(path || ''), handler);\n+ var VFS = require('./vfs');\n+ var vfs = new VFS(String(path || ''));\n+\n+ var fse = new FSEvents(vfs.resolvedPath, handler);\n EventEmitter.call(fse);\n return fse;\n\n function handler(path, flags, id) {\n+ path = vfs.transpose(path);\n defer(function() {\n fse.emit('fsevent', path, flags, id);\n var info = getInfo(path, flags);\ndiff --git a/fsevents.js b/fsevents.js\nsemver exclusivity ^2.1\n--- a/fsevents.js\n+++ b/fsevents.js\n@@ -21,5 +21,7 @@ function watch(path, handler) {\n throw new TypeError(\`fsevents argument 2 must be a function and not a \${typeof handler}\`);\n }\n\n- let instance = Native.start(path, handler);\n+ let VFS = require('./vfs');\n+ let vfs = new VFS(path);\n+ let instance = Native.start(vfs.resolvedPath, vfs.wrap(handler));\n if (!instance) throw new Error(\`could not watch: \${path}\`);\ndiff --git a/vfs.js b/vfs.js\nnew file mode 100644\n--- /dev/null\n+++ b/vfs.js\n@@ -0,0 +1,41 @@\n+const path = require(\`path\`);\n+\n+const NUMBER_REGEXP = /^[0-9]+$/;\n+const VIRTUAL_REGEXP = /^(\\/(?:[^\\/]+\\/)*?\\$\\$virtual)((?:\\/([^\\/]+)(?:\\/([^\\/]+))?)?((?:\\/.*)?))$/;\n+\n+function resolveVirtual(p) {\n+ const match = p.match(VIRTUAL_REGEXP);\n+ if (!match)\n+ return p;\n+\n+ const target = path.dirname(match[1]);\n+ if (!match[3] || !match[4])\n+ return target;\n+\n+ const isnum = NUMBER_REGEXP.test(match[4]);\n+ if (!isnum)\n+ return p;\n+\n+ const depth = Number(match[4]);\n+ const backstep = \`../\`.repeat(depth);\n+ const subpath = (match[5] || \`.\`);\n+\n+ return resolveVirtual(path.join(target, backstep, subpath));\n+}\n+\n+module.exports = class FsePnp {\n+ constructor(p) {\n+ this.normalizedPath = path.resolve(p);\n+ this.resolvedPath = resolveVirtual(this.normalizedPath);\n+ }\n+\n+ transpose(p) {\n+ return this.normalizedPath + p.substr(this.resolvedPath.length);\n+ }\n+\n+ wrap(fn) {\n+ return (path, ...args) => {\n+ return fn(this.transpose(path), ...args);\n+ };\n+ }\n+};\n` | ||
; | ||
/* eslint-disable */ | ||
export const patch = require('zlib').brotliDecompressSync(Buffer.from('G8EIABwHuTnyDkxeQiomXep01zJ90cJ3iFSgGcnN+dVTE5YC1CBsZn0bRMFnq2+/bPJOWLRlcCblbWaytN6yn94lDuHQVXEMzob/mhDOafB/uXcOjPnzEX5TF8I/4H+A7n4PCzSY0xTuWjDfxxV8F1neM4x7jymltl+dnYEp13SxCOpkQxUClagaNItavHVUdwD73pT3+c52oJFtOTmagkX/GAaKFyr1bLfAnKMY+OZmY+0YsC6Sci7AJQI2zADQHhdIcc03Dz+GOC05kpj3M0kiNKsdFu1U3ornmwco/hOeYDp3IUlCIQqaE6eg8ho+SQaBwAeE4PktvsKmDJJy8fXAx0jTz4Oj2wWKVgNnuMz/CR5AZNuo2eZk0HwujkkFQBytGPu+p1RoCpRBYVcTf7REjfuVBUIa+MgTpb+ZaKgASLlmw2dFNlIsdYEsSntc1vhEJfQLSkVdBXXK67OUoZjcjVu8DPd8oSwu1vK52tVmsLNeekvJW3ss4Z1+thxuul1A0bzLBLT7MQMQxaGNFQUpvaAsmmOVo1hZFKHViytsKRvkULx6+VpOghLO9W/tHqSTQkqQkLWIKtzBlsPNUviOym6eOz3jjDM43Jfi2pXbla5apaLf+jR3njZPcG1zp9bxgi6Acg2V4n8rU8+1ANM2CXkW5tkqS6QfhnL1z8/s5G8r/f4omOaXOkzbHh9HdPhfxz9Tftr698n6L7UYF/L089Ch+9QgeDSlUXdaBAyLU3G6bkC5ygWmNqZMBYJHB6iFj4uo0iI9yR5r3KUooI0Zg1IkiYsgqxR8jMug6VgwtyIaxNxP30CqZH3zo/g16/wof1VdCLhd+YIOeBHFhA/D2eAvyld7FIAT8EiOA1Msg41mq8UNYCwZt2Pc519uZYhp9gP6kOwhcU+Ydc0CsPIqfy0ZGgbIKNYGZ+RP4ESfRzdDW6vhSsXuu2VB29YEdri/7CbQ7XCsVevHtY2mms7dVEMb6Wa/Ln6ZokATZTjZ/kMMNoWEp0AqBKG0DaCyBxlBsylqymr/6xM+mxOAAVREIXXGnW4IXuQ5oSGimw0C7BKZb3ZDLEWtkWXM5FB7jjp37QA=', 'base64')).toString(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,2 @@ | ||
export const patch = | ||
`diff --git a/lib/normalize-options.js b/lib/normalize-options.js\nindex 4b56904..53a3219 100644\nsemver exclusivity >=1.9\n--- a/lib/normalize-options.js\n+++ b/lib/normalize-options.js\n@@ -1,10 +1,108 @@\n-module.exports = function (x, opts) {\n- /**\n- * This file is purposefully a passthrough. It's expected that third-party\n- * environments will override it at runtime in order to inject special logic\n- * into \`resolve\` (by manipulating the options). One such example is the PnP\n- * code path in Yarn.\n- */\n-\n- return opts || {};\n+// Info: this file has been generated by Yarn with the approval of the\n+// \`resolve\` maintainers. Bugs caused by a code located here should be\n+// opened against the Yarn repository.\n+\n+const path = require(\`path\`);\n+\n+module.exports = function (_, opts) {\n+ opts = opts || {};\n+\n+ if (opts.forceNodeResolution || !process.versions.pnp)\n+ return opts;\n+\n+ // It would be nice if we could throw, but that would break the transparent\n+ // compatibility with packages that use \`resolve\` today (such as Gulp). Since\n+ // it's the whole point of this patch, we don't.\n+ //\n+ // if (opts.packageIterator || opts.paths)\n+ // throw new Error(\`The "packageIterator" and "paths" options cannot be used in PnP environments. Set "forceNodeResolution: true" if absolutely needed, or branch on process.versions.pnp otherwise.\`);\n+\n+ const {findPnpApi} = require(\`module\`);\n+\n+ const runPnpResolution = (request, basedir) => {\n+ // Extract the name of the package being requested (1=package name, 2=internal path)\n+ const parts = request.match(/^((?:@[^\\/]+\\/)?[^\\/]+)(\\/.*)?/);\n+ if (!parts)\n+ throw new Error(\`Assertion failed: Expected the "resolve" package to call the "paths" callback with package names only (got "\${request}")\`);\n+\n+ // Make sure that basedir ends with a slash\n+ if (basedir.charAt(basedir.length - 1) !== \`/\`)\n+ basedir = path.join(basedir, \`/\`);\n+\n+ const api = findPnpApi(basedir);\n+ if (api === null)\n+ return undefined;\n+\n+ // This is guaranteed to return the path to the "package.json" file from the given package\n+ let manifestPath;\n+ try {\n+ manifestPath = api.resolveToUnqualified(\`\${parts[1]}/package.json\`, basedir, {considerBuiltins: false});\n+ } catch (err) {\n+ return null;\n+ }\n+\n+ if (manifestPath === null)\n+ throw new Error(\`Assertion failed: The resolution thinks that "\${parts[1]}" is a Node builtin\`);\n+\n+ // Strip the package.json to get the package folder\n+ const packagePath = path.dirname(manifestPath);\n+\n+ // Attach the internal path to the resolved package directory\n+ const unqualifiedPath = typeof parts[2] !== \`undefined\`\n+ ? path.join(packagePath, parts[2])\n+ : packagePath;\n+\n+ return {packagePath, unqualifiedPath};\n+ };\n+\n+ const packageIterator = (request, basedir, getCandidates, opts) => {\n+ const resolution = runPnpResolution(request, basedir);\n+ if (typeof resolution === \`undefined\`)\n+ return getCandidates();\n+\n+ if (resolution === null)\n+ return [];\n+\n+ return [resolution.unqualifiedPath];\n+ };\n+\n+ const paths = (request, basedir, getNodeModulePaths, opts) => {\n+ const resolution = runPnpResolution(request, basedir);\n+ if (typeof resolution === \`undefined\`)\n+ return getNodeModulePaths();\n+\n+ if (resolution === null)\n+ return [];\n+\n+ // Stip the local named folder\n+ let nodeModules = path.dirname(resolution.packagePath);\n+\n+ // Strip the scope named folder if needed\n+ if (request.match(/^@[^\\/]+\\//))\n+ nodeModules = path.dirname(nodeModules);\n+\n+ return [nodeModules];\n+ };\n+\n+ // We need to keep track whether we're in \`packageIterator\` or not so that\n+ // the code is compatible with both \`resolve\` 1.9+ and \`resolve\` 1.15+\n+ let isInsideIterator = false;\n+\n+ opts.packageIterator = function (request, basedir, getCandidates, opts) {\n+ isInsideIterator = true;\n+ try {\n+ return packageIterator(request, basedir, getCandidates, opts);\n+ } finally {\n+ isInsideIterator = false;\n+ }\n+ };\n+\n+ opts.paths = function (request, basedir, getNodeModulePaths, opts) {\n+ if (isInsideIterator)\n+ return getNodeModulePaths();\n+\n+ return paths(request, basedir, getNodeModulePaths, opts);\n+ };\n+\n+ return opts;\n };\n` | ||
; | ||
/* eslint-disable */ | ||
export const patch = require('zlib').brotliDecompressSync(Buffer.from('G+4QAIzURnVBnOZ/S7W7LqcXJbsLsg1ujW3lVCvYwhYpoIGvNI1ypQXI/9z7C4lxoATjm1Wcm5MwCa101e7Ne78qBrVNrStdyFYkUu2sNrsMp9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tb7OOlsyfdayzwu/R387mZYl3QfmBlurVvpLtzpaj4MdnliH9XHMxsjR3uLiHcsVMWvT6VFcNT6G3lJFMjEyqX3rc9hiTo1oZuDp30GR4c34uYnbXEAiFgkCw6eDvWpYiEcFDrLdbOmiYFgYbZyXnhGZfbXRXcsUpNZQGXWw5s1DXUNKpoBVEA748fFf8Qg8OqixW/9EOjQIQ33PgQ4NaxAJRSBtQ+s/m6LUEb2xU725HKbwMfaxroY30FLQ6phKXKvvvEY393lpJppMIJmXrIjbNEUWnLpTIZXTEPf+/ou6ut8+m4nnnv8+G1UJXeBrNxspwvj/cZZPWPURZyWU11IHI4VBK4xHl5bg422anjXONdeWUQJSSLXxIOHOSFFwZDPrkFFPSg5P6VTpw805i+gXyxNI68D3HfihPCzV4axi/0s39lG0cB5a2q5phAgfaPIFFyL2q3wfXJ0vSr/afF0biVXPIDTfHhvN0gYSjLs0O6+Wb8klmPxC61SXCaqiC3hfGCNMy8K8kJjNxV+NOEMOxzqCEHRJmOlL006b4BrsKsp0Xct+2dirJ4N0JwmqWiIsL9rSFY4A', 'base64')).toString(); |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters