Skip to content

Commit 30dba72

Browse files
authored
Adds support for multiple concurrent runtimes (#630)
* Adds support for multiple concurrent runtimes * More fixes * Adds documentation * More fixes * Updates snapshots * Fixes tests for Windows
1 parent 4765a9a commit 30dba72

24 files changed

Lines changed: 1457 additions & 1279 deletions

File tree

.pnp.js

Lines changed: 994 additions & 1080 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/acceptance-tests/pkg-tests-specs/sources/commands/__snapshots__/config.test.js.snap

Lines changed: 24 additions & 24 deletions
Large diffs are not rendered by default.

packages/acceptance-tests/pkg-tests-specs/sources/pnp.test.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -600,6 +600,41 @@ describe(`Plug'n'Play`, () => {
600600
),
601601
);
602602

603+
test(
604+
`it should be able to require files from a different dependency tree`,
605+
makeTemporaryEnv({
606+
dependencies: {
607+
[`no-deps`]: `1.0.0`,
608+
},
609+
}, async ({path, run, source}) => {
610+
await run(`install`);
611+
612+
const tmp = await createTemporaryFolder();
613+
614+
await xfs.writeJsonPromise(ppath.join(tmp, `package.json`), {
615+
dependencies: {
616+
[`no-deps`]: `2.0.0`,
617+
},
618+
});
619+
620+
await xfs.writeFilePromise(ppath.join(tmp, `index.js`), `
621+
module.exports = require('no-deps');
622+
`);
623+
624+
await run(`install`, {cwd: tmp});
625+
626+
await expect(source(`require('no-deps')`)).resolves.toEqual({
627+
name: `no-deps`,
628+
version: `1.0.0`,
629+
});
630+
631+
await expect(source(`require(${JSON.stringify(tmp)})`)).resolves.toEqual({
632+
name: `no-deps`,
633+
version: `2.0.0`,
634+
});
635+
}),
636+
);
637+
603638
testIf(
604639
() => satisfies(process.versions.node, `>=8.9.0`),
605640
`it should throw when using require.resolve with unsupported options`,
@@ -641,7 +676,7 @@ describe(`Plug'n'Play`, () => {
641676
await writeFile(`${tmp}/index.js`, `require(process.argv[2])`);
642677
await writeFile(`${path}/index.js`, `require('no-deps')`);
643678

644-
await run(`node`, `${npath.fromPortablePath(tmp)}/index.js`, `${path}/index.js`);
679+
await run(`node`, `${npath.fromPortablePath(tmp)}/index.js`, `${npath.fromPortablePath(path)}/index.js`);
645680
},
646681
),
647682
);

packages/acceptance-tests/pkg-tests-specs/sources/pnpapi.test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,11 +285,12 @@ describe(`Plug'n'Play API`, () => {
285285
const virtualPath = await source(`require.resolve('peer-deps')`);
286286

287287
// Sanity check: to ensure that the test actually tests something :)
288-
expect(xfs.existsSync(virtualPath)).toEqual(false);
288+
expect(virtualPath).toMatch(`${npath.sep}$$virtual${npath.sep}`);
289289

290290
const physicalPath = await source(`require('pnpapi').resolveVirtual(require.resolve('peer-deps'))`);
291291

292292
expect(typeof physicalPath).toEqual(`string`);
293+
expect(physicalPath).not.toEqual(virtualPath);
293294
expect(xfs.existsSync(physicalPath)).toEqual(true);
294295
}),
295296
);

packages/gatsby/src/pages/configuration/manifest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ const PackageJsonDoc = () => <>
133133
<JsonObjectProperty
134134
name={`peerDependencies`}
135135
description={<>
136-
Peer dependencies are inherited dependencies - the consumer of your package will be tasked to provide them. This is typically what you want when writing plugins, for example. Be careful: listing peer dependencies will have side effects on the way your package will be executed by your consumers. Check the documentation for more information.
136+
Peer dependencies are inherited dependencies - the consumer of your package will be tasked to provide them. This is typically what you want when writing plugins, for example. Note that peer dependencies can also be listed as regular dependencies; in this case, Yarn will use the package provided by the ancestors if possible, but will fallback to the regular dependencies otherwise.
137137
</>}
138138
>
139139
<JsonScalarProperty

packages/gatsby/src/pages/configuration/yarnrc.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,9 +382,9 @@ const YarnrcDoc = () => <>
382382
</SymlArrayProperty>
383383
<SymlScalarProperty
384384
name={`virtualFolder`}
385-
placeholder={`./.yarn/virtual`}
385+
placeholder={`./.yarn/$$virtual`}
386386
description={<>
387-
Due to a particularity in how Yarn installs packages which list peer dependencies, some packages will be mapped to multiple virtual directories that don't actually exist on the filesystem. This settings tells Yarn where to put them.
387+
Due to a particularity in how Yarn installs packages which list peer dependencies, some packages will be mapped to multiple virtual directories that don't actually exist on the filesystem. This settings tells Yarn where to put them. Note that the folder name *must* be <code>$$virtual</code>.
388388
</>}
389389
/>
390390
<SymlScalarProperty

packages/plugin-dlx/sources/commands/dlx.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ export default class DlxCommand extends BaseCommand {
8383

8484
function createTemporaryDirectory(name?: Filename) {
8585
return new Promise<PortablePath>((resolve, reject) => {
86-
tmp.dir({unsafeCleanup: true}, (error, dirPath) => {
86+
tmp.dir({unsafeCleanup: false}, (error, dirPath) => {
8787
if (error) {
8888
reject(error);
8989
} else {

packages/plugin-pnp/sources/PnpLinker.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Installer, Linker, LinkOptions, MinimalLinkOptions, Manifest, LinkType,
22
import {FetchResult, Descriptor, Ident, Locator, Package, BuildDirective, BuildType} from '@yarnpkg/core';
33
import {miscUtils, structUtils} from '@yarnpkg/core';
44
import {CwdFS, FakeFS, PortablePath, npath, ppath, toFilename, xfs} from '@yarnpkg/fslib';
5-
import {PackageRegistry, generateInlinedScript, generateSplitScript} from '@yarnpkg/pnp';
5+
import {PackageRegistry, generateInlinedScript, generateSplitScript, PnpSettings} from '@yarnpkg/pnp';
66
import {UsageError} from 'clipanion';
77

88
import {getPnpPath} from './index';
@@ -165,7 +165,6 @@ class PnpInstaller implements Installer {
165165
const ignorePattern = this.opts.project.configuration.get(`pnpIgnorePattern`);
166166
const packageRegistry = this.packageRegistry;
167167
const shebang = this.opts.project.configuration.get(`pnpShebang`);
168-
const virtualRoots = [this.normalizeDirectoryPath(this.opts.project.configuration.get(`virtualFolder`))];
169168

170169
if (pnpFallbackMode === `dependencies-only`)
171170
for (const pkg of this.opts.project.storedPackages.values())
@@ -175,15 +174,14 @@ class PnpInstaller implements Installer {
175174
const pnpPath = getPnpPath(this.opts.project);
176175
const pnpDataPath = this.opts.project.configuration.get(`pnpDataPath`);
177176

178-
const pnpSettings = {
177+
const pnpSettings: PnpSettings = {
179178
blacklistedLocations,
180179
dependencyTreeRoots,
181180
enableTopLevelFallback,
182181
fallbackExclusionList,
183182
ignorePattern,
184183
packageRegistry,
185184
shebang,
186-
virtualRoots,
187185
};
188186

189187
if (this.opts.project.configuration.get(`pnpEnableInlining`)) {

packages/yarnpkg-builder/sources/commands/build/bundle.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export default class BuildBundleCommand extends Command {
8484
plugins: [
8585
new webpack.BannerPlugin({
8686
entryOnly: true,
87-
banner: `#!/usr/bin/env node`,
87+
banner: `#!/usr/bin/env node\n/* eslint-disable */`,
8888
raw: true,
8989
}),
9090
new webpack.DefinePlugin({

packages/yarnpkg-builder/sources/commands/build/plugin.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,14 @@ export default class BuildPluginCommand extends Command {
6565
for (const chunk of chunks) {
6666
for (const file of chunk.files) {
6767
compilation.assets[file] = new RawSource(reindent(`
68-
module.exports = {};
69-
70-
module.exports.factory = function (require) {
71-
${reindent(compilation.assets[file].source().replace(/^ +/, ``), 11)}
72-
return plugin;
68+
/* eslint-disable*/
69+
module.exports = {
70+
name: ${JSON.stringify(name)},
71+
factory: function (require) {
72+
${reindent(compilation.assets[file].source().replace(/^ +/, ``), 11)}
73+
return plugin;
74+
},
7375
};
74-
75-
module.exports.name = ${JSON.stringify(name)};
7676
`));
7777
}
7878
}

0 commit comments

Comments
 (0)