Skip to content

Commit

Permalink
Merge branch 'v2' into gkong/reduce-cache
Browse files Browse the repository at this point in the history
  • Loading branch information
gorakong authored Nov 14, 2023
2 parents 1943236 + c72c336 commit 65d93a9
Show file tree
Hide file tree
Showing 12 changed files with 84 additions and 34 deletions.
64 changes: 38 additions & 26 deletions packages/core/core/src/BundleGraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,32 +295,44 @@ export default class BundleGraph {
symbols.set(from, existing);
} else {
invariant(isReexportAll);
let local = `${node.value.id}$rewrite$${asset}$${from}`;
symbols.set(from, {
isWeak: true,
local,
loc: reexportAllLoc,
});
// It might already exist with multiple export-alls causing ambiguous resolution
if (
node.value.sourceAssetId != null &&
assetGraph.hasContentKey(node.value.sourceAssetId)
) {
let sourceAssetId = nullthrows(
assetGraphNodeIdToBundleGraphNodeId.get(
assetGraph.getNodeIdByContentKey(
nullthrows(node.value.sourceAssetId),
if (as === from) {
// Keep the export-all for non-renamed reexports, this still correctly models
// ambiguous resolution with multiple export-alls.
symbols.set('*', {
isWeak: true,
local: '*',
loc: reexportAllLoc,
});
} else {
let local = `${node.value.id}$rewrite$${asset}$${from}`;
symbols.set(from, {
isWeak: true,
local,
loc: reexportAllLoc,
});
if (node.value.sourceAssetId != null) {
let sourceAssetId = nullthrows(
assetGraphNodeIdToBundleGraphNodeId.get(
assetGraph.getNodeIdByContentKey(
node.value.sourceAssetId,
),
),
),
);
let sourceAsset = nullthrows(graph.getNode(sourceAssetId));
invariant(sourceAsset.type === 'asset');
let sourceAssetSymbols = sourceAsset.value.symbols;
if (sourceAssetSymbols && !sourceAssetSymbols.has(as)) {
sourceAssetSymbols.set(as, {
loc: reexportAllLoc,
local: local,
});
);
let sourceAsset = nullthrows(
graph.getNode(sourceAssetId),
);
invariant(sourceAsset.type === 'asset');
let sourceAssetSymbols = sourceAsset.value.symbols;
if (sourceAssetSymbols) {
// The `as == from` case above should handle multiple export-alls causing
// ambiguous resolution. So the current symbol is unambiguous and shouldn't
// already exist on the importer.
invariant(!sourceAssetSymbols.has(as));
sourceAssetSymbols.set(as, {
loc: reexportAllLoc,
local: local,
});
}
}
}
}
Expand All @@ -342,7 +354,7 @@ export default class BundleGraph {
},
usedSymbolsUp,
// This is only a temporary helper needed during symbol propagation and is never
// read afterwards.
// read afterwards (and also not exposed through the public API).
usedSymbolsDown: new Set(),
}),
};
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
if (Date.now() > 0) {
output = require("./index.js").default;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { b,c } from "./lib";

export default b + " " + c;
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module.exports = {};
// export const a = 89;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const b = 123;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { c2 as c } from "./lib-c2.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const c2 = 999;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from "./lib-a";
export * from "./lib-b";
export * from "./lib-c";
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"sideEffects": [
"entry.js",
"index.js",
"lib-a.js",
"lib-b.js",
"lib-c2.js",
"lib.js"
]
}
17 changes: 16 additions & 1 deletion packages/core/integration-tests/test/scope-hoisting.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ describe('scope hoisting', function () {
assert.equal(output, 2);
});

it('supports import * as from a library that has export *', async function () {
it('supports dependency rewriting for import * as from a library that has export *', async function () {
let b = await bundle(
path.join(
__dirname,
Expand Down Expand Up @@ -403,6 +403,21 @@ describe('scope hoisting', function () {
assert.match(contents, /output="foo bar"/);
});

it('supports re-exporting all with ambiguous CJS and non-renaming and renaming dependency retargeting', async function () {
let b = await bundle(
path.join(
__dirname,
'/integration/scope-hoisting/es6/re-export-all-ambiguous/entry.js',
),
{
mode: 'production',
},
);

let output = await run(b);
assert.strictEqual(output, '123 999');
});

it('supports re-exporting all exports from an external module', async function () {
let b = await bundle(
path.join(
Expand Down
6 changes: 3 additions & 3 deletions packages/reporters/lsp-reporter/src/LspReporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ async function watchLspActive(): Promise<FSWatcher> {
});
}

async function doWatchStart() {
async function doWatchStart(options) {
await fs.promises.mkdir(BASEDIR, {recursive: true});

// For each existing file, check if the pid matches a running process.
Expand Down Expand Up @@ -141,7 +141,7 @@ async function doWatchStart() {
await fs.promises.writeFile(
META_FILE,
JSON.stringify({
projectRoot: process.cwd(),
projectRoot: options.projectRoot,
pid: process.pid,
argv: process.argv,
}),
Expand All @@ -158,7 +158,7 @@ export default (new Reporter({

if (watchStarted && lspStarted) {
if (!watchStartPromise) {
watchStartPromise = doWatchStart();
watchStartPromise = doWatchStart(options);
}
await watchStartPromise;
}
Expand Down
7 changes: 3 additions & 4 deletions packages/utils/parcel-lsp/src/LspServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ function findClient(document: DocumentUri): Client | undefined {
return bestClient;
}

function parseMetafile(filepath: string) {
function loadMetafile(filepath: string) {
const file = fs.readFileSync(filepath, 'utf-8');
return JSON.parse(file);
}
Expand Down Expand Up @@ -295,7 +295,7 @@ fs.writeFileSync(path.join(BASEDIR, LSP_SENTINEL_FILENAME), '');
for (let filename of fs.readdirSync(BASEDIR)) {
if (!filename.endsWith('.json')) continue;
let filepath = path.join(BASEDIR, filename);
const contents = parseMetafile(filepath);
const contents = loadMetafile(filepath);
const {projectRoot} = contents;

if (WORKSPACE_ROOT === projectRoot) {
Expand All @@ -312,8 +312,7 @@ watcher.subscribe(BASEDIR, async (err, events) => {

for (let event of events) {
if (event.type === 'create' && event.path.endsWith('.json')) {
const file = fs.readFileSync(event.path, 'utf-8');
const contents = parseMetafile(file);
const contents = loadMetafile(event.path);
const {projectRoot} = contents;

if (WORKSPACE_ROOT === projectRoot) {
Expand Down

0 comments on commit 65d93a9

Please sign in to comment.