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

Adds better support for node-gyp #35

Merged
merged 5 commits into from
Mar 23, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions .pnp.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
2 changes: 1 addition & 1 deletion packages/berry-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"@babel/preset-typescript": "^7.1.0",
"@babel/register": "^7.0.0",
"@berry/cli": "workspace:*",
"@manaflair/concierge": "^0.12.1",
"@manaflair/concierge": "^0.12.3",
"brfs": "^2.0.1",
"buffer-loader": "^0.1.0",
"joi": "^13.6.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/berry-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"@berry/fslib": "workspace:*",
"@berry/parsers": "workspace:*",
"@berry/shell": "workspace:*",
"@manaflair/concierge": "^0.12.1",
"@manaflair/concierge": "^0.12.3",
"chalk": "^2.4.1",
"execa": "^1.0.0",
"joi": "^13.6.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/berry-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"@berry/parsers": "workspace:*",
"@berry/pnp": "workspace:*",
"@berry/shell": "workspace:*",
"@manaflair/concierge": "^0.12.1",
"@manaflair/concierge": "^0.12.3",
"chalk": "^2.4.1",
"execa": "^1.0.0",
"globby": "^8.0.1",
Expand Down
11 changes: 6 additions & 5 deletions packages/berry-core/sources/scriptUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ export async function makeScriptEnv(project: Project) {
const binFolder = scriptEnv.BERRY_BIN_FOLDER = dirSync().name;

// Register some binaries that must be made available in all subprocesses
// spawned by Berry
// spawned by Yarn

await makePathWrapper(binFolder, `run`, process.execPath, [process.argv[1], `run`]),
await makePathWrapper(binFolder, `yarn`, process.execPath, [process.argv[1]]),
await makePathWrapper(binFolder, `yarnpkg`, process.execPath, [process.argv[1]]),
await makePathWrapper(binFolder, `node`, process.execPath),
await makePathWrapper(binFolder, `run`, process.execPath, [process.argv[1], `run`]);
await makePathWrapper(binFolder, `yarn`, process.execPath, [process.argv[1]]);
await makePathWrapper(binFolder, `yarnpkg`, process.execPath, [process.argv[1]]);
await makePathWrapper(binFolder, `node`, process.execPath);
await makePathWrapper(binFolder, `node-gyp`, process.execPath, [process.argv[1], `run`, `--top-level`, `node-gyp`]);

scriptEnv.PATH = scriptEnv.PATH
? `${binFolder}${delimiter}${scriptEnv.PATH}`
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-essentials/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"@berry/fslib": "workspace:*",
"@berry/json-proxy": "workspace:*",
"@berry/parsers": "workspace:*",
"@manaflair/concierge": "^0.12.1",
"@manaflair/concierge": "^0.12.3",
"execa": "^1.0.0",
"inquirer": "^6.2.0",
"joi": "^13.6.0",
Expand Down
42 changes: 27 additions & 15 deletions packages/plugin-essentials/sources/commands/run.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import {Configuration, PluginConfiguration, Project, Workspace, Manifest, Cache} from '@berry/core';
import {LightReport, ThrowReport} from '@berry/core';
import {scriptUtils} from '@berry/core';
import {UsageError} from '@manaflair/concierge';
import {Readable, Writable} from 'stream';
import {Configuration, PluginConfiguration, Project, Workspace, Cache} from '@berry/core';
import {LightReport} from '@berry/core';
import {scriptUtils, structUtils} from '@berry/core';
import {UsageError} from '@manaflair/concierge';
import {Readable, Writable} from 'stream';

export default (concierge: any, pluginConfiguration: PluginConfiguration) => concierge

.command(`run <name> [... args]`)
.command(`run <name> [... args] [-T,--top-level]`)
.describe(`run a script defined in the package.json`)
.flags({proxyArguments: true})

Expand All @@ -22,7 +22,7 @@ export default (concierge: any, pluginConfiguration: PluginConfiguration) => con
Whatever happens, the cwd of the spawned process will be the workspace that declares the script (which makes it possible to call commands cross-workspaces using the third syntax).
`)

.action(async ({cwd, stdin, stdout, stderr, name, args}: {cwd: string, stdin: Readable, stdout: Writable, stderr: Writable, name: string, args: Array<string>}) => {
.action(async ({cwd, stdin, stdout, stderr, name, topLevel, args}: {cwd: string, stdin: Readable, stdout: Writable, stderr: Writable, name: string, topLevel: boolean, args: Array<string>}) => {
const configuration = await Configuration.find(cwd, pluginConfiguration);
const {project, workspace, locator} = await Project.find(configuration, cwd);
const cache = await Cache.find(configuration);
Expand All @@ -31,23 +31,27 @@ export default (concierge: any, pluginConfiguration: PluginConfiguration) => con
await project.resolveEverything({lockfileOnly: true, cache, report});
});

const effectiveLocator = topLevel
? project.topLevelWorkspace.anchoredLocator
: locator;

if (report.hasErrors())
return report.exitCode();

// First we check to see whether a script exist inside the current workspace
// First we check to see whether a script exist inside the current package
// for the given name

if (await scriptUtils.hasPackageScript(locator, name, {project}))
return await scriptUtils.executePackageScript(locator, name, args, {project, stdin, stdout, stderr});
if (await scriptUtils.hasPackageScript(effectiveLocator, name, {project}))
return await scriptUtils.executePackageScript(effectiveLocator, name, args, {project, stdin, stdout, stderr});

// If we can't find it, we then check whether one of the dependencies of the
// current workspace exports a binary with the requested name
// current package exports a binary with the requested name

const binaries = await scriptUtils.getPackageAccessibleBinaries(locator, {project});
const binaries = await scriptUtils.getPackageAccessibleBinaries(effectiveLocator, {project});
const binary = binaries.get(name);

if (binary)
return await scriptUtils.executePackageAccessibleBinary(locator, name, args, {cwd, project, stdin, stdout, stderr});
return await scriptUtils.executePackageAccessibleBinary(effectiveLocator, name, args, {cwd, project, stdin, stdout, stderr});

// When it fails, we try to check whether it's a global script (ie we look
// into all the workspaces to find one that exports this script). We only do
Expand All @@ -57,7 +61,7 @@ export default (concierge: any, pluginConfiguration: PluginConfiguration) => con
// We also disable this logic for packages coming from third-parties (ie
// not workspaces). Not particular reason except maybe security concerns.

if (workspace && name.includes(`:`)) {
if (!topLevel && workspace && name.includes(`:`)) {
let candidateWorkspaces = await Promise.all(project.workspaces.map(async workspace => {
return workspace.manifest.scripts.has(name) ? workspace : null;
}));
Expand All @@ -71,5 +75,13 @@ export default (concierge: any, pluginConfiguration: PluginConfiguration) => con
}
}

throw new UsageError(`Couldn't find a script named "${name}"`);
if (topLevel) {
if (name === `node-gyp`) {
throw new UsageError(`Couldn't find a script name "${name}" in the top-level (used by ${structUtils.prettyLocator(configuration, locator)}). This typically happens because some package depends on "node-gyp" to build itself, but didn't list it in their dependencies. To fix that, please run "yarn add node-gyp" into your top-level workspace. You also can open an issue on the repository of the specified package to suggest them to use an optional peer dependency.`);
} else {
throw new UsageError(`Couldn't find a script name "${name}" in the top-level (used by ${structUtils.prettyLocator(configuration, locator)}).`);
}
} else {
throw new UsageError(`Couldn't find a script named "${name}".`);
}
});
2 changes: 1 addition & 1 deletion packages/plugin-hub/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"@berry/core": "workspace:*",
"@berry/json-proxy": "workspace:*",
"@berry/ui": "workspace:*",
"@manaflair/concierge": "^0.12.1",
"@manaflair/concierge": "^0.12.3",
"dateformat": "^3.0.3",
"immer": "^1.7.2",
"joi": "^13.6.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-init/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"@berry/core": "workspace:*",
"@berry/fslib": "workspace:*",
"@berry/json-proxy": "workspace:*",
"@manaflair/concierge": "^0.12.1"
"@manaflair/concierge": "^0.12.3"
}
}
2 changes: 1 addition & 1 deletion packages/plugin-pack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"@berry/core": "workspace:*",
"@berry/fslib": "workspace:*",
"@berry/json-proxy": "workspace:*",
"@manaflair/concierge": "^0.12.1"
"@manaflair/concierge": "^0.12.3"
},
"devDependencies": {
"@berry/builder": "workspace:packages/berry-builder"
Expand Down
2 changes: 1 addition & 1 deletion packages/plugin-stage/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"@berry/builder": "workspace:*",
"@berry/core": "workspace:*",
"@berry/fslib": "workspace:*",
"@manaflair/concierge": "^0.12.1"
"@manaflair/concierge": "^0.12.3"
},
"scripts": {
"build:plugin-stage": "run @berry-build-plugin"
Expand Down
24 changes: 12 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1246,7 +1246,7 @@ __metadata:
"@babel/preset-typescript": "npm:^7.1.0"
"@babel/register": "npm:^7.0.0"
"@berry/cli": "workspace:*"
"@manaflair/concierge": "npm:^0.12.1"
"@manaflair/concierge": "npm:^0.12.3"
brfs: "npm:^2.0.1"
buffer-loader: "npm:^0.1.0"
joi: "npm:^13.6.0"
Expand Down Expand Up @@ -1284,7 +1284,7 @@ __metadata:
"@berry/plugin-typescript": "workspace:*"
"@berry/pnp": "workspace:*"
"@berry/shell": "workspace:*"
"@manaflair/concierge": "npm:^0.12.1"
"@manaflair/concierge": "npm:^0.12.3"
chalk: "npm:^2.4.1"
execa: "npm:^1.0.0"
joi: "npm:^13.6.0"
Expand All @@ -1302,7 +1302,7 @@ __metadata:
"@berry/parsers": "workspace:*"
"@berry/pnp": "workspace:*"
"@berry/shell": "workspace:*"
"@manaflair/concierge": "npm:^0.12.1"
"@manaflair/concierge": "npm:^0.12.3"
chalk: "npm:^2.4.1"
execa: "npm:^1.0.0"
globby: "npm:^8.0.1"
Expand Down Expand Up @@ -1458,7 +1458,7 @@ __metadata:
"@berry/fslib": "workspace:*"
"@berry/json-proxy": "workspace:*"
"@berry/parsers": "workspace:*"
"@manaflair/concierge": "npm:^0.12.1"
"@manaflair/concierge": "npm:^0.12.3"
execa: "npm:^1.0.0"
inquirer: "npm:^6.2.0"
joi: "npm:^13.6.0"
Expand Down Expand Up @@ -1499,7 +1499,7 @@ __metadata:
"@berry/core": "workspace:*"
"@berry/json-proxy": "workspace:*"
"@berry/ui": "workspace:*"
"@manaflair/concierge": "npm:^0.12.1"
"@manaflair/concierge": "npm:^0.12.3"
dateformat: "npm:^3.0.3"
immer: "npm:^1.7.2"
joi: "npm:^13.6.0"
Expand All @@ -1518,7 +1518,7 @@ __metadata:
"@berry/core": "workspace:*"
"@berry/fslib": "workspace:*"
"@berry/json-proxy": "workspace:*"
"@manaflair/concierge": "npm:^0.12.1"
"@manaflair/concierge": "npm:^0.12.3"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -1548,7 +1548,7 @@ __metadata:
"@berry/core": "workspace:*"
"@berry/fslib": "workspace:*"
"@berry/json-proxy": "workspace:*"
"@manaflair/concierge": "npm:^0.12.1"
"@manaflair/concierge": "npm:^0.12.3"
languageName: unknown
linkType: soft

Expand All @@ -1571,7 +1571,7 @@ __metadata:
"@berry/builder": "workspace:*"
"@berry/core": "workspace:*"
"@berry/fslib": "workspace:*"
"@manaflair/concierge": "npm:^0.12.1"
"@manaflair/concierge": "npm:^0.12.3"
languageName: unknown
linkType: soft

Expand Down Expand Up @@ -2173,13 +2173,13 @@ __metadata:
languageName: node
linkType: hard

"@manaflair/concierge@npm:^0.12.1":
version: 0.12.1
resolution: "@manaflair/concierge@npm:0.12.1"
"@manaflair/concierge@npm:^0.12.3":
version: 0.12.3
resolution: "@manaflair/concierge@npm:0.12.3"
dependencies:
chalk: "npm:^1.1.3"
lodash: "npm:^4.17.4"
checksum: 163178b7d5d77643734d365c52e9868025dd4220f737f41c92dc304c27f4a430501a13ac6f4d5aea447cbe9e16888bf87668f16da44c5afba777319778ff71a1
checksum: de63d1eda831e577a3c942df56a729440d2d21c29bd8f6a50d432a5013b0622f100e8af17edce621a7af73cb70298d3d5278e7e5dce950d19c713007bd5b746c
languageName: node
linkType: hard

Expand Down