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

feat(pnp): exports support #2431

Merged
merged 41 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
abbd2ed
feat(pnp): exports support
paul-soporan Jan 11, 2021
e502810
fix(pnp): construct subpath correctly
paul-soporan Jan 11, 2021
6d9c9c3
fix(pnp): normalize subpath
paul-soporan Jan 11, 2021
34c2b51
chore: add basic test (originally written by bgotink)
paul-soporan Jan 11, 2021
71e9551
test: add another test
paul-soporan Jan 12, 2021
a88ef1d
refactor: rename resolveExports to resolveExport
paul-soporan Jan 12, 2021
58a2218
chore: update resolve.exports
paul-soporan Jan 12, 2021
4a4120e
test: add more tests
paul-soporan Jan 14, 2021
bd12ce0
refactor: add note about --conditions flag
paul-soporan Feb 2, 2021
d9369cb
Merge remote-tracking branch 'yarnpkg/master' into paul/exports
paul-soporan Feb 2, 2021
4126699
test: improve tests
paul-soporan Feb 2, 2021
5d41268
test: add tests for no known conditions error
paul-soporan Feb 2, 2021
6b3987f
test: add manifest test
paul-soporan Feb 2, 2021
ee4a789
test: add test for self-referencing
paul-soporan Feb 2, 2021
2a4f4eb
chore: update babel and jest
paul-soporan Feb 2, 2021
244e6df
refactor: wording
paul-soporan Feb 2, 2021
2b06727
Revert "chore: update babel and jest"
paul-soporan Feb 2, 2021
921bef6
chore: update hook
merceyz Feb 3, 2021
21a5d96
chore: versions
paul-soporan Feb 3, 2021
1416697
refactor: add options to resolveUnqualifiedExport
paul-soporan Feb 3, 2021
5a06310
chore: update pnp hook
paul-soporan Feb 3, 2021
228ec16
Merge branch 'master' into paul/exports
paul-soporan Feb 10, 2021
b44fe2a
fix: include packages that are discarded from lookup
paul-soporan Feb 10, 2021
ce66dec
test: check that resolveUnqualifiedExport is a method on the pnpapi
paul-soporan Feb 10, 2021
39aa7eb
fix: don't throw on missing manifest
paul-soporan Feb 10, 2021
ff48c1a
Merge remote-tracking branch 'origin/master' into paul/exports
arcanis Feb 13, 2021
4054545
Tolerates paths outside of the dependency tree
arcanis Feb 13, 2021
e7c61e5
Fixes tests
arcanis Feb 13, 2021
8df6be6
Adds support for publishConfig.exports
arcanis Feb 13, 2021
140c3ef
test: fix tests on windows
paul-soporan Feb 16, 2021
d830dcf
test: add more link: tests
paul-soporan Feb 16, 2021
3636c60
fix: support exports with pnpIgnorePatterns
paul-soporan Feb 17, 2021
3686eec
Merge branch 'master' into paul/exports
paul-soporan Feb 24, 2021
2599c10
fix: handle case when path is ignored
paul-soporan Feb 24, 2021
a34c2dc
refactor: don't expose resolveUnqualifiedExport
paul-soporan Feb 24, 2021
2ffd106
chore: update hook
paul-soporan Feb 24, 2021
732bcaa
test: add test for ignored path
paul-soporan Feb 24, 2021
8eaa65d
Update packages/acceptance-tests/pkg-tests-specs/sources/pnpapi.test.ts
paul-soporan Feb 25, 2021
5a13156
Merge remote-tracking branch 'origin/master' into paul/exports
arcanis Feb 26, 2021
da269b3
Reverts accidental comment
arcanis Feb 26, 2021
42a5e41
Adds back missing deps
arcanis Feb 26, 2021
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
26 changes: 15 additions & 11 deletions .pnp.cjs

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

2 changes: 1 addition & 1 deletion packages/yarnpkg-pnp/sources/hook.js

Large diffs are not rendered by default.

27 changes: 15 additions & 12 deletions packages/yarnpkg-pnp/sources/loader/makeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,13 +200,13 @@ export function makeApi(runtimeState: RuntimeState, opts: MakeApiOptions): PnpAp
* @returns The remapped path or `null` if the package doesn't have a package.json or an "exports" field
*/
function applyNodeExportsResolution(unqualifiedPath: PortablePath, {conditions = [], require = true}: ResolveUnqualifiedExportOptions = {}) {
// Not all required files are part of the dependency tree (for example
// some may be covered by a pnpIgnorePatterns rule). It's not too clear
// how to detect the package root in those case, so leaving that for the
// next iteration.
const locator = findPackageLocator(ppath.join(unqualifiedPath, `internal.js` as Filename), {includeDiscardFromLookup: true});
if (locator === null) {
throw makeError(
ErrorCode.API_ERROR,
`The resolveUnqualifiedExport function must be called with a valid unqualifiedPath`,
);
}
if (locator === null)
return unqualifiedPath;

const {packageLocation} = getPackageInformationSafe(locator);

Expand Down Expand Up @@ -553,12 +553,10 @@ export function makeApi(runtimeState: RuntimeState, opts: MakeApiOptions): PnpAp

function resolveToUnqualified(request: PortablePath, issuer: PortablePath | null, {considerBuiltins = true}: ResolveToUnqualifiedOptions = {}): PortablePath | null {
// The 'pnpapi' request is reserved and will always return the path to the PnP file, from everywhere

if (request === `pnpapi`)
return npath.toPortablePath(opts.pnpapiResolution);

// Bailout if the request is a native module

if (considerBuiltins && builtinModules.has(request))
return null;

Expand Down Expand Up @@ -598,7 +596,6 @@ export function makeApi(runtimeState: RuntimeState, opts: MakeApiOptions): PnpAp
// If the request is a relative or absolute path, we just return it normalized

const dependencyNameMatch = request.match(pathRegExp);

if (!dependencyNameMatch) {
if (ppath.isAbsolute(request)) {
unqualifiedPath = ppath.normalize(request);
Expand Down Expand Up @@ -817,7 +814,12 @@ export function makeApi(runtimeState: RuntimeState, opts: MakeApiOptions): PnpAp
if (isStrictRegExp.test(request))
return unqualifiedPath;

return applyNodeExportsResolution(unqualifiedPath, opts) ?? unqualifiedPath;
const unqualifiedExportPath = applyNodeExportsResolution(unqualifiedPath, opts);
if (unqualifiedExportPath) {
return ppath.normalize(unqualifiedExportPath);
} else {
return unqualifiedPath;
}
}

/**
Expand Down Expand Up @@ -851,11 +853,12 @@ export function makeApi(runtimeState: RuntimeState, opts: MakeApiOptions): PnpAp

function resolveRequest(request: PortablePath, issuer: PortablePath | null, {considerBuiltins, extensions, conditions, require}: ResolveRequestOptions = {}): PortablePath | null {
const unqualifiedPath = resolveToUnqualified(request, issuer, {considerBuiltins});

if (unqualifiedPath === null)
return null;

const remappedPath = resolveUnqualifiedExport(request, unqualifiedPath, {conditions, require});
const remappedPath = !considerBuiltins || !builtinModules.has(request)
paul-soporan marked this conversation as resolved.
Show resolved Hide resolved
? resolveUnqualifiedExport(request, unqualifiedPath, {conditions, require})
: unqualifiedPath;

try {
return resolveUnqualified(remappedPath, {extensions});
Expand Down