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

NodeResolver: Reload the closest package.json to an asset if it's a package entry #7909

Merged
merged 12 commits into from May 23, 2022
@@ -0,0 +1,3 @@
import {one} from 'foo/bar'

output = one;

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

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

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

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

@@ -0,0 +1,3 @@
import {one} from 'foo/bar'

output = one;

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

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

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

34 changes: 34 additions & 0 deletions packages/core/integration-tests/test/scope-hoisting.js
Expand Up @@ -2319,6 +2319,40 @@ describe('scope hoisting', function () {
assert.equal(await output, 42);
});

describe("considers an asset's closest package.json for sideEffects, not the package through which it found the asset", () => {
it('handles redirects up the tree', async () => {
let b = await bundle(
path.join(
__dirname,
'/integration/scope-hoisting/es6/side-effects-package-redirect-up/index.js',
),
);

let result = await run(b);
assert.strictEqual(result, 1);

let bar = findAsset(b, 'real-bar.js');
assert(bar);
assert.strictEqual(bar.sideEffects, false);
});

it('handles redirects down the tree', async () => {
let b = await bundle(
path.join(
__dirname,
'/integration/scope-hoisting/es6/side-effects-package-redirect-down/index.js',
),
);

let result = await run(b);
assert.strictEqual(result, 1);

let bar = findAsset(b, 'real-bar.js');
assert(bar);
assert.strictEqual(bar.sideEffects, false);
});
});

describe('correctly updates used symbols on changes', () => {
it('dependency symbols change', async function () {
let testDir = path.join(
Expand Down
10 changes: 9 additions & 1 deletion packages/utils/node-resolver-core/src/NodeResolver.js
Expand Up @@ -997,7 +997,15 @@ export default class NodeResolver {
}

if (found) {
return {path: found, pkg};
return {
path: found,
// If this package.json isn't a sibling of found, it's possible pkg is not the
// closest package.json to the resolved file. Reload it instead.
pkg:
pkg == null || pkg?.pkgdir !== path.dirname(found)
? await this.findPackage(found, ctx)
: pkg,
};
}

return null;
Expand Down

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

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

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

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

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

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

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

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

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