-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: paulober <[email protected]>
- Loading branch information
Showing
11 changed files
with
443 additions
and
305 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
const fs = require("fs"); | ||
|
||
// Setup: Place this file in `.yarn/plugins/list-plugin.js` and the following | ||
// to `.yarnrc.yml`: | ||
// | ||
// ``` | ||
// plugins: | ||
// - path: .yarn/plugins/plugin-list.js | ||
// ``` | ||
module.exports = { | ||
name: "plugin-list", | ||
factory: (require) => { | ||
const { BaseCommand } = require("@yarnpkg/cli"); | ||
const { Command, Option } = require("clipanion"); | ||
const { parseSyml } = require("@yarnpkg/parsers"); | ||
|
||
class ListCommand extends BaseCommand { | ||
static paths = [["list"]]; | ||
|
||
static usage = Command.Usage({ | ||
description: "Lists installed packages.", | ||
}); | ||
|
||
prod = Option.Boolean("--prod", false); | ||
json = Option.Boolean("--json", false); | ||
|
||
async execute() { | ||
if (!this.prod || !this.json) { | ||
throw new Error( | ||
"This command can only be used with the --prod and --json " + | ||
"args to match the behavior required by VSCE. See: " + | ||
"https://github.com/microsoft/vscode-vsce/blob/main/src/npm.ts", | ||
); | ||
} | ||
|
||
const packageJsonContents = fs.readFileSync("package.json", "utf-8"); | ||
const { dependencies = {} } = JSON.parse(packageJsonContents); | ||
|
||
const lockContents = fs.readFileSync("yarn.lock", "utf-8"); | ||
const resolved = parseSyml(lockContents); | ||
|
||
const trees = []; | ||
|
||
function addDependency(packageName, versionRange) { | ||
const packageInfo = lookup( | ||
resolved, | ||
getLockFileKey(packageName, versionRange), | ||
); | ||
if (!packageInfo) { | ||
throw new Error( | ||
`Cannot resolve "${packageName}" with version range "${versionRange}"`, | ||
); | ||
} | ||
|
||
const { version, dependencies } = packageInfo; | ||
const name = `${packageName}@${version}`; | ||
if (trees.find((tree) => tree.name === name)) { | ||
return; // Dependency already added as part of another tree. | ||
} | ||
|
||
if (dependencies) { | ||
const children = Object.entries(dependencies).map( | ||
([name, range]) => ({ name: `${name}@${range}` }), | ||
); | ||
trees.push({ name, children }); | ||
|
||
addDependencies(dependencies); | ||
} else { | ||
trees.push({ name, children: [] }); | ||
} | ||
} | ||
|
||
function addDependencies(dependencies) { | ||
for (const [packageName, versionRange] of Object.entries( | ||
dependencies, | ||
)) { | ||
addDependency(packageName, versionRange); | ||
} | ||
} | ||
|
||
addDependencies(dependencies); | ||
|
||
const output = { | ||
type: "tree", | ||
data: { type: "list", trees }, | ||
}; | ||
|
||
this.context.stdout.write(JSON.stringify(output)); | ||
} | ||
} | ||
|
||
return { | ||
commands: [ListCommand], | ||
}; | ||
}, | ||
}; | ||
|
||
function getLockFileKey(packageName, versionSpecifier) { | ||
// If the version field contains a URL, don't attempt to use the NPM registry | ||
return versionSpecifier.includes(":") | ||
? `${packageName}@${versionSpecifier}` | ||
: `${packageName}@npm:${versionSpecifier}`; | ||
} | ||
|
||
/** | ||
* @param resolved All the resolved dependencies as found in the lock file. | ||
* @param dependencyKey Key of the dependency to look up. Can be created using | ||
* `lockFileKey()`. | ||
*/ | ||
function lookup(resolved, dependencyKey) { | ||
let packageInfo; | ||
if (dependencyKey.includes("file:")) { | ||
const keys = Object.keys(resolved); | ||
|
||
for (let i = 0; i < keys.length; i++) { | ||
const key = keys[i]; | ||
|
||
if (key.includes(dependencyKey)) { | ||
packageInfo = resolved[key]; | ||
break; | ||
} | ||
} | ||
} else { | ||
packageInfo = resolved[dependencyKey]; | ||
} | ||
if (packageInfo) { | ||
return packageInfo; | ||
} | ||
|
||
// Fall back to slower iteration-based lookup for combined keys. | ||
for (const [key, packageInfo] of Object.entries(resolved)) { | ||
if (key.split(",").some((key) => key.trim() === dependencyKey)) { | ||
return packageInfo; | ||
} | ||
} | ||
} | ||
|
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 +1,8 @@ | ||
compressionLevel: mixed | ||
|
||
enableGlobalCache: false | ||
|
||
plugins: | ||
- path: .yarn/plugins/list-plugin.js | ||
|
||
yarnPath: .yarn/releases/yarn-4.1.1.cjs |
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
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,6 +1 @@ | ||
export const EXTENSION_NAME = "flipper-app-dev"; | ||
export const SDKS_FOLDER_NAME = ".flipper-sdk"; | ||
|
||
export const OFW_GITHUB_OWNER = "flipperdevices"; | ||
export const OFW_GITHUB_REPO = "flipperzero-firmware"; | ||
export const OFW_GITHUB_BRANCH = "dev"; |
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
Oops, something went wrong.