@atlaspack/core 2.26.3-dev-compiled-hash-e5f8a1735.0 → 2.28.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +61 -0
- package/dist/Atlaspack.js +5 -1
- package/dist/BundleGraph.js +105 -0
- package/dist/CommittedAsset.js +1 -1
- package/dist/Transformation.js +3 -2
- package/dist/UncommittedAsset.js +3 -3
- package/dist/assetUtils.js +2 -1
- package/dist/atlaspack-v3/worker/compat/bitflags.js +24 -20
- package/dist/atlaspack-v3/worker/compat/dependency.js +1 -1
- package/dist/atlaspack-v3/worker/compat/mutable-asset.js +1 -1
- package/dist/atlaspack-v3/worker/worker.js +14 -7
- package/dist/public/BundleGraph.js +12 -0
- package/dist/requests/AssetGraphRequest.js +1 -1
- package/dist/requests/AssetGraphRequestRust.js +99 -36
- package/dist/requests/AtlaspackConfigRequest.js +10 -21
- package/dist/requests/BundleGraphRequest.js +5 -3
- package/dist/resolveOptions.js +1 -0
- package/dist/worker.js +1 -1
- package/lib/Atlaspack.js +5 -1
- package/lib/BundleGraph.js +107 -0
- package/lib/CommittedAsset.js +1 -1
- package/lib/Transformation.js +9 -4
- package/lib/UncommittedAsset.js +3 -3
- package/lib/assetUtils.js +8 -1
- package/lib/atlaspack-v3/worker/compat/bitflags.js +25 -20
- package/lib/atlaspack-v3/worker/compat/dependency.js +1 -1
- package/lib/atlaspack-v3/worker/compat/mutable-asset.js +1 -1
- package/lib/atlaspack-v3/worker/worker.js +13 -5
- package/lib/public/BundleGraph.js +13 -0
- package/lib/requests/AssetGraphRequest.js +1 -1
- package/lib/requests/AssetGraphRequestRust.js +96 -35
- package/lib/requests/AtlaspackConfigRequest.js +14 -24
- package/lib/requests/BundleGraphRequest.js +4 -2
- package/lib/resolveOptions.js +1 -0
- package/lib/types/BundleGraph.d.ts +2 -0
- package/lib/types/CommittedAsset.d.ts +1 -1
- package/lib/types/PackagerRunner.d.ts +1 -1
- package/lib/types/UncommittedAsset.d.ts +1 -1
- package/lib/types/atlaspack-v3/worker/compat/bitflags.d.ts +11 -12
- package/lib/types/atlaspack-v3/worker/compat/mutable-asset.d.ts +1 -1
- package/lib/types/public/Asset.d.ts +1 -1
- package/lib/types/public/BundleGraph.d.ts +2 -0
- package/lib/types/requests/AssetGraphRequestRust.d.ts +1 -1
- package/lib/types/types.d.ts +1 -0
- package/lib/worker.js +1 -1
- package/package.json +21 -22
- package/src/Atlaspack.ts +6 -2
- package/src/BundleGraph.ts +152 -0
- package/src/CommittedAsset.ts +1 -1
- package/src/PackagerRunner.ts +1 -1
- package/src/Transformation.ts +3 -2
- package/src/UncommittedAsset.ts +3 -3
- package/src/assetUtils.ts +2 -1
- package/src/atlaspack-v3/worker/compat/bitflags.ts +44 -41
- package/src/atlaspack-v3/worker/compat/dependency.ts +1 -1
- package/src/atlaspack-v3/worker/compat/mutable-asset.ts +1 -1
- package/src/atlaspack-v3/worker/worker.ts +15 -5
- package/src/public/Asset.ts +1 -1
- package/src/public/BundleGraph.ts +21 -0
- package/src/requests/AssetGraphRequest.ts +1 -1
- package/src/requests/AssetGraphRequestRust.ts +138 -40
- package/src/requests/AtlaspackConfigRequest.ts +10 -20
- package/src/requests/BundleGraphRequest.ts +9 -7
- package/src/resolveOptions.ts +1 -0
- package/src/types.ts +1 -0
- package/src/worker.ts +1 -1
- package/test/requests/AssetGraphRequestRust.test.ts +1 -0
- package/tsconfig.json +3 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/LICENSE +0 -201
package/src/BundleGraph.ts
CHANGED
|
@@ -1435,6 +1435,158 @@ export default class BundleGraph {
|
|
|
1435
1435
|
});
|
|
1436
1436
|
}
|
|
1437
1437
|
|
|
1438
|
+
// New method: Fast checks only (no caching of results)
|
|
1439
|
+
isAssetReferencedFastCheck(bundle: Bundle, asset: Asset): boolean | null {
|
|
1440
|
+
// Fast Check #1: If asset is in multiple bundles in same target, it's referenced
|
|
1441
|
+
let bundlesWithAsset = this.getBundlesWithAsset(asset).filter(
|
|
1442
|
+
(b) =>
|
|
1443
|
+
b.target.name === bundle.target.name &&
|
|
1444
|
+
b.target.distDir === bundle.target.distDir,
|
|
1445
|
+
);
|
|
1446
|
+
|
|
1447
|
+
if (bundlesWithAsset.length > 1) {
|
|
1448
|
+
return true;
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
// Fast Check #2: If asset is referenced by any async/conditional dependency, it's referenced
|
|
1452
|
+
let assetNodeId = nullthrows(this._graph.getNodeIdByContentKey(asset.id));
|
|
1453
|
+
|
|
1454
|
+
if (
|
|
1455
|
+
this._graph
|
|
1456
|
+
.getNodeIdsConnectedTo(assetNodeId, bundleGraphEdgeTypes.references)
|
|
1457
|
+
.map((id) => this._graph.getNode(id))
|
|
1458
|
+
.some(
|
|
1459
|
+
(node) =>
|
|
1460
|
+
node?.type === 'dependency' &&
|
|
1461
|
+
(node.value.priority === Priority.lazy ||
|
|
1462
|
+
node.value.priority === Priority.conditional) &&
|
|
1463
|
+
node.value.specifierType !== SpecifierType.url,
|
|
1464
|
+
)
|
|
1465
|
+
) {
|
|
1466
|
+
return true;
|
|
1467
|
+
}
|
|
1468
|
+
|
|
1469
|
+
// Fast checks failed - return null to indicate expensive computation needed
|
|
1470
|
+
return null;
|
|
1471
|
+
}
|
|
1472
|
+
|
|
1473
|
+
getReferencedAssets(bundle: Bundle): Set<Asset> {
|
|
1474
|
+
let referencedAssets = new Set<Asset>();
|
|
1475
|
+
|
|
1476
|
+
// Build a map of all assets in this bundle with their dependencies
|
|
1477
|
+
// This allows us to check all assets in a single traversal
|
|
1478
|
+
let assetDependenciesMap = new Map<Asset, Array<Dependency>>();
|
|
1479
|
+
|
|
1480
|
+
this.traverseAssets(bundle, (asset) => {
|
|
1481
|
+
// Always do fast checks (no caching)
|
|
1482
|
+
let fastCheckResult = this.isAssetReferencedFastCheck(bundle, asset);
|
|
1483
|
+
|
|
1484
|
+
if (fastCheckResult === true) {
|
|
1485
|
+
referencedAssets.add(asset);
|
|
1486
|
+
return;
|
|
1487
|
+
}
|
|
1488
|
+
|
|
1489
|
+
// Fast checks failed (fastCheckResult === null), need expensive computation
|
|
1490
|
+
// Check if it's actually referenced via traversal
|
|
1491
|
+
|
|
1492
|
+
// Store dependencies for later batch checking
|
|
1493
|
+
let dependencies = this._graph
|
|
1494
|
+
.getNodeIdsConnectedTo(
|
|
1495
|
+
nullthrows(this._graph.getNodeIdByContentKey(asset.id)),
|
|
1496
|
+
)
|
|
1497
|
+
.map((id) => nullthrows(this._graph.getNode(id)))
|
|
1498
|
+
.filter((node) => node.type === 'dependency')
|
|
1499
|
+
.map((node) => {
|
|
1500
|
+
invariant(node.type === 'dependency');
|
|
1501
|
+
return node.value;
|
|
1502
|
+
});
|
|
1503
|
+
|
|
1504
|
+
if (dependencies.length > 0) {
|
|
1505
|
+
assetDependenciesMap.set(asset, dependencies);
|
|
1506
|
+
}
|
|
1507
|
+
});
|
|
1508
|
+
|
|
1509
|
+
// If no assets need the expensive check, return early
|
|
1510
|
+
if (assetDependenciesMap.size === 0) {
|
|
1511
|
+
return referencedAssets;
|
|
1512
|
+
}
|
|
1513
|
+
|
|
1514
|
+
// Get the assets we need to check once
|
|
1515
|
+
let assetsToCheck = Array.from(assetDependenciesMap.keys());
|
|
1516
|
+
|
|
1517
|
+
// Helper function to check if all assets from assetDependenciesMap are in referencedAssets
|
|
1518
|
+
const allAssetsReferenced = (): boolean =>
|
|
1519
|
+
assetsToCheck.length <= referencedAssets.size &&
|
|
1520
|
+
assetsToCheck.every((asset) => referencedAssets.has(asset));
|
|
1521
|
+
|
|
1522
|
+
// Do ONE traversal to check all remaining assets
|
|
1523
|
+
// We can share visitedBundles across all assets because we check every asset
|
|
1524
|
+
// against every visited bundle, which matches the original per-asset behavior
|
|
1525
|
+
let siblingBundles = new Set(
|
|
1526
|
+
this.getBundleGroupsContainingBundle(bundle).flatMap((bundleGroup) =>
|
|
1527
|
+
this.getBundlesInBundleGroup(bundleGroup, {includeInline: true}),
|
|
1528
|
+
),
|
|
1529
|
+
);
|
|
1530
|
+
|
|
1531
|
+
let visitedBundles: Set<Bundle> = new Set();
|
|
1532
|
+
|
|
1533
|
+
// Single traversal from all referencers
|
|
1534
|
+
for (let referencer of siblingBundles) {
|
|
1535
|
+
this.traverseBundles((descendant, _, actions) => {
|
|
1536
|
+
if (descendant.id === bundle.id) {
|
|
1537
|
+
return;
|
|
1538
|
+
}
|
|
1539
|
+
|
|
1540
|
+
if (visitedBundles.has(descendant)) {
|
|
1541
|
+
actions.skipChildren();
|
|
1542
|
+
return;
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
visitedBundles.add(descendant);
|
|
1546
|
+
|
|
1547
|
+
if (
|
|
1548
|
+
descendant.type !== bundle.type ||
|
|
1549
|
+
fromEnvironmentId(descendant.env).context !==
|
|
1550
|
+
fromEnvironmentId(bundle.env).context
|
|
1551
|
+
) {
|
|
1552
|
+
// Don't skip children - they might be the right type!
|
|
1553
|
+
return;
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
// Check ALL assets at once in this descendant bundle
|
|
1557
|
+
for (let [asset, dependencies] of assetDependenciesMap) {
|
|
1558
|
+
// Skip if already marked as referenced
|
|
1559
|
+
if (referencedAssets.has(asset)) {
|
|
1560
|
+
continue;
|
|
1561
|
+
}
|
|
1562
|
+
|
|
1563
|
+
// Check if this descendant bundle references the asset
|
|
1564
|
+
if (
|
|
1565
|
+
!this.bundleHasAsset(descendant, asset) &&
|
|
1566
|
+
dependencies.some((dependency) =>
|
|
1567
|
+
this.bundleHasDependency(descendant, dependency),
|
|
1568
|
+
)
|
|
1569
|
+
) {
|
|
1570
|
+
referencedAssets.add(asset);
|
|
1571
|
+
}
|
|
1572
|
+
}
|
|
1573
|
+
|
|
1574
|
+
// If all assets from assetDependenciesMap are now marked as referenced, we can stop early
|
|
1575
|
+
if (allAssetsReferenced()) {
|
|
1576
|
+
actions.stop();
|
|
1577
|
+
return;
|
|
1578
|
+
}
|
|
1579
|
+
}, referencer);
|
|
1580
|
+
|
|
1581
|
+
// If all assets from assetDependenciesMap are referenced, no need to check more sibling bundles
|
|
1582
|
+
if (allAssetsReferenced()) {
|
|
1583
|
+
break;
|
|
1584
|
+
}
|
|
1585
|
+
}
|
|
1586
|
+
|
|
1587
|
+
return referencedAssets;
|
|
1588
|
+
}
|
|
1589
|
+
|
|
1438
1590
|
hasParentBundleOfType(bundle: Bundle, type: string): boolean {
|
|
1439
1591
|
let parents = this.getParentBundles(bundle);
|
|
1440
1592
|
return (
|
package/src/CommittedAsset.ts
CHANGED
|
@@ -3,7 +3,7 @@ import {Readable} from 'stream';
|
|
|
3
3
|
import {deserializeRaw} from '@atlaspack/build-cache';
|
|
4
4
|
import type {AST, Blob} from '@atlaspack/types';
|
|
5
5
|
import {bufferStream, blobToStream, streamFromPromise} from '@atlaspack/utils';
|
|
6
|
-
import SourceMap from '@
|
|
6
|
+
import SourceMap from '@atlaspack/source-map';
|
|
7
7
|
|
|
8
8
|
import {generateFromAST} from './assetUtils';
|
|
9
9
|
import type {Asset, Dependency, AtlaspackOptions} from './types';
|
package/src/PackagerRunner.ts
CHANGED
package/src/Transformation.ts
CHANGED
|
@@ -69,6 +69,7 @@ import {
|
|
|
69
69
|
import {invalidateOnFileCreateToInternal, createInvalidations} from './utils';
|
|
70
70
|
import invariant from 'assert';
|
|
71
71
|
import {tracer, PluginTracer} from '@atlaspack/profiler';
|
|
72
|
+
import SourceMap from '@atlaspack/source-map';
|
|
72
73
|
import {getFeatureFlag} from '@atlaspack/feature-flags';
|
|
73
74
|
|
|
74
75
|
type GenerateFunc = (input: UncommittedAsset) => Promise<GenerateOutput>;
|
|
@@ -460,7 +461,7 @@ export default class Transformation {
|
|
|
460
461
|
if (asset.isASTDirty && asset.generate) {
|
|
461
462
|
let output = await asset.generate();
|
|
462
463
|
asset.content = output.content;
|
|
463
|
-
asset.mapBuffer = output.map
|
|
464
|
+
asset.mapBuffer = SourceMap.safeToBuffer(output.map);
|
|
464
465
|
}
|
|
465
466
|
|
|
466
467
|
asset.clearAST();
|
|
@@ -634,7 +635,7 @@ export default class Transformation {
|
|
|
634
635
|
) {
|
|
635
636
|
let output = await asset.generate();
|
|
636
637
|
asset.content = output.content;
|
|
637
|
-
asset.mapBuffer = output.map
|
|
638
|
+
asset.mapBuffer = SourceMap.safeToBuffer(output.map);
|
|
638
639
|
}
|
|
639
640
|
|
|
640
641
|
// Load config for the transformer.
|
package/src/UncommittedAsset.ts
CHANGED
|
@@ -11,7 +11,7 @@ import type {Asset, Dependency, AtlaspackOptions, Invalidations} from './types';
|
|
|
11
11
|
|
|
12
12
|
import invariant from 'assert';
|
|
13
13
|
import {Readable} from 'stream';
|
|
14
|
-
import SourceMap from '@
|
|
14
|
+
import SourceMap from '@atlaspack/source-map';
|
|
15
15
|
import {serializeRaw} from '@atlaspack/build-cache';
|
|
16
16
|
import {
|
|
17
17
|
blobToStream,
|
|
@@ -249,7 +249,7 @@ export default class UncommittedAsset {
|
|
|
249
249
|
|
|
250
250
|
if (map) {
|
|
251
251
|
this.map = map;
|
|
252
|
-
this.mapBuffer =
|
|
252
|
+
this.mapBuffer = SourceMap.safeToBuffer(map);
|
|
253
253
|
this.setCode(code.replace(SOURCEMAP_RE, ''));
|
|
254
254
|
}
|
|
255
255
|
|
|
@@ -425,7 +425,7 @@ export default class UncommittedAsset {
|
|
|
425
425
|
content,
|
|
426
426
|
ast: result.ast,
|
|
427
427
|
isASTDirty: result.ast === this.ast ? this.isASTDirty : true,
|
|
428
|
-
mapBuffer:
|
|
428
|
+
mapBuffer: SourceMap.safeToBuffer(result.map),
|
|
429
429
|
code: this.code,
|
|
430
430
|
invalidations: this.invalidations,
|
|
431
431
|
});
|
package/src/assetUtils.ts
CHANGED
|
@@ -39,6 +39,7 @@ import {PluginTracer} from '@atlaspack/profiler';
|
|
|
39
39
|
import {identifierRegistry} from './IdentifierRegistry';
|
|
40
40
|
import type {EnvironmentRef} from './EnvironmentManager';
|
|
41
41
|
import {toEnvironmentId} from './EnvironmentManager';
|
|
42
|
+
import SourceMap from '@atlaspack/source-map';
|
|
42
43
|
|
|
43
44
|
export type AssetOptions = {
|
|
44
45
|
id?: string;
|
|
@@ -180,7 +181,7 @@ async function _generateFromAST(asset: CommittedAsset | UncommittedAsset) {
|
|
|
180
181
|
tracer: new PluginTracer({origin: pluginName, category: 'asset-generate'}),
|
|
181
182
|
});
|
|
182
183
|
|
|
183
|
-
let mapBuffer = map
|
|
184
|
+
let mapBuffer = SourceMap.safeToBuffer(map);
|
|
184
185
|
// Store the results in the cache so we can avoid generating again next time
|
|
185
186
|
await Promise.all([
|
|
186
187
|
asset.options.cache.setStream(
|
|
@@ -5,21 +5,20 @@ import type {
|
|
|
5
5
|
} from '@atlaspack/types';
|
|
6
6
|
|
|
7
7
|
/// BitFlags is used to map number/string types from napi types
|
|
8
|
-
export class BitFlags<K
|
|
8
|
+
export class BitFlags<K> {
|
|
9
9
|
// @ts-expect-error TS2344
|
|
10
|
-
#kv: Partial<Record<K,
|
|
11
|
-
|
|
12
|
-
#vk: Partial<Record<V, K>>;
|
|
10
|
+
#kv: Partial<Record<K, number>>;
|
|
11
|
+
#vk: Partial<Record<number, K>>;
|
|
13
12
|
|
|
14
13
|
// @ts-expect-error TS2344
|
|
15
|
-
constructor(source: Partial<Record<K,
|
|
14
|
+
constructor(source: Partial<Record<K, number>>) {
|
|
16
15
|
this.#kv = source;
|
|
17
16
|
this.#vk = Object.fromEntries(
|
|
18
17
|
Object.entries(source).map((a) => a.reverse()),
|
|
19
18
|
);
|
|
20
19
|
}
|
|
21
20
|
|
|
22
|
-
into(key: K):
|
|
21
|
+
into(key: K): number {
|
|
23
22
|
const found = this.#kv[key];
|
|
24
23
|
if (found === undefined) {
|
|
25
24
|
throw new Error(`Invalid BundleBehavior(${key})`);
|
|
@@ -27,18 +26,14 @@ export class BitFlags<K, V> {
|
|
|
27
26
|
return found;
|
|
28
27
|
}
|
|
29
28
|
|
|
30
|
-
intoNullable(key?: K | null):
|
|
29
|
+
intoNullable(key?: K | null): number | null | undefined {
|
|
31
30
|
if (key === undefined || key === null) {
|
|
32
31
|
return undefined;
|
|
33
32
|
}
|
|
34
33
|
return this.into(key);
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
return keys.map((key) => this.into(key));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
from(key: V): K {
|
|
36
|
+
from(key: number): K {
|
|
42
37
|
const found = this.#vk[key];
|
|
43
38
|
if (found === undefined) {
|
|
44
39
|
throw new Error(`Invalid BundleBehavior(${key})`);
|
|
@@ -46,52 +41,60 @@ export class BitFlags<K, V> {
|
|
|
46
41
|
return found;
|
|
47
42
|
}
|
|
48
43
|
|
|
49
|
-
fromNullable(key?:
|
|
44
|
+
fromNullable(key?: number | null): K | null | undefined {
|
|
50
45
|
if (key === undefined || key === null) {
|
|
51
46
|
return undefined;
|
|
52
47
|
}
|
|
53
48
|
return this.from(key);
|
|
54
49
|
}
|
|
55
50
|
|
|
56
|
-
|
|
57
|
-
|
|
51
|
+
toArray(keys: number): K[] {
|
|
52
|
+
let values = [];
|
|
53
|
+
for (let [key, value] of Object.entries(this.#kv) as [K, number][]) {
|
|
54
|
+
if ((keys & value) !== 0) {
|
|
55
|
+
values.push(key);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return values;
|
|
58
60
|
}
|
|
59
61
|
}
|
|
60
62
|
|
|
61
|
-
export const bundleBehaviorMap: BitFlags<BundleBehavior
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
},
|
|
67
|
-
);
|
|
63
|
+
export const bundleBehaviorMap: BitFlags<BundleBehavior> = new BitFlags({
|
|
64
|
+
inline: 0,
|
|
65
|
+
isolated: 1,
|
|
66
|
+
inlineIsolated: 2,
|
|
67
|
+
});
|
|
68
68
|
|
|
69
|
-
export const dependencyPriorityMap: BitFlags<DependencyPriority
|
|
70
|
-
|
|
69
|
+
export const dependencyPriorityMap: BitFlags<DependencyPriority> = new BitFlags(
|
|
70
|
+
{
|
|
71
71
|
sync: 0,
|
|
72
72
|
parallel: 1,
|
|
73
73
|
lazy: 2,
|
|
74
74
|
conditional: 3,
|
|
75
|
-
}
|
|
75
|
+
},
|
|
76
|
+
);
|
|
76
77
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
78
|
+
// Note: The bitflags must match the bitflags in the Rust code.
|
|
79
|
+
// crates/atlaspack_core/src/types/package_json.rs
|
|
80
|
+
export const packageConditionsMap: BitFlags<string> = new BitFlags({
|
|
81
|
+
import: 1 << 0,
|
|
82
|
+
require: 1 << 1,
|
|
83
|
+
module: 1 << 2,
|
|
84
|
+
node: 1 << 3,
|
|
85
|
+
browser: 1 << 4,
|
|
86
|
+
worker: 1 << 5,
|
|
87
|
+
worklet: 1 << 6,
|
|
88
|
+
electron: 1 << 7,
|
|
89
|
+
development: 1 << 8,
|
|
90
|
+
production: 1 << 9,
|
|
91
|
+
types: 1 << 10,
|
|
92
|
+
default: 1 << 11,
|
|
93
|
+
style: 1 << 12,
|
|
94
|
+
sass: 1 << 13,
|
|
92
95
|
});
|
|
93
96
|
|
|
94
|
-
export const specifierTypeMap: BitFlags<SpecifierType
|
|
97
|
+
export const specifierTypeMap: BitFlags<SpecifierType> = new BitFlags({
|
|
95
98
|
esm: 0,
|
|
96
99
|
commonjs: 1,
|
|
97
100
|
url: 2,
|
|
@@ -70,7 +70,7 @@ export class Dependency implements IDependency {
|
|
|
70
70
|
this.isOptional = inner.isOptional;
|
|
71
71
|
this.isEntry = inner.isEntry;
|
|
72
72
|
this.loc = inner.loc;
|
|
73
|
-
this.packageConditions = packageConditionsMap.
|
|
73
|
+
this.packageConditions = packageConditionsMap.toArray(
|
|
74
74
|
inner.packageConditions || [],
|
|
75
75
|
);
|
|
76
76
|
this.sourceAssetId = inner.sourceAssetId;
|
|
@@ -33,27 +33,37 @@ export class AtlaspackWorker {
|
|
|
33
33
|
#resolvers: Map<string, ResolverState<any>>;
|
|
34
34
|
#transformers: Map<string, TransformerState<any>>;
|
|
35
35
|
#fs: FileSystem;
|
|
36
|
+
#packageManager: NodePackageManager;
|
|
36
37
|
|
|
37
38
|
constructor() {
|
|
38
39
|
this.#resolvers = new Map();
|
|
39
40
|
this.#transformers = new Map();
|
|
40
41
|
this.#fs = new NodeFS();
|
|
42
|
+
this.#packageManager = new NodePackageManager(this.#fs, '/');
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
loadPlugin: JsCallable<[LoadPluginOptions], Promise<undefined>> = jsCallable(
|
|
44
46
|
async ({kind, specifier, resolveFrom, featureFlags}) => {
|
|
45
|
-
|
|
46
|
-
let
|
|
47
|
-
|
|
47
|
+
// Use packageManager.require() instead of dynamic import() to support TypeScript plugins
|
|
48
|
+
let resolvedModule = await this.#packageManager.require(
|
|
49
|
+
specifier,
|
|
50
|
+
resolveFrom,
|
|
51
|
+
{shouldAutoInstall: false},
|
|
52
|
+
);
|
|
48
53
|
|
|
49
54
|
let instance = undefined;
|
|
50
|
-
|
|
55
|
+
// Check for CommonJS export (module.exports = new Plugin(...))
|
|
56
|
+
if (resolvedModule[CONFIG]) {
|
|
57
|
+
instance = resolvedModule[CONFIG];
|
|
58
|
+
} else if (resolvedModule.default && resolvedModule.default[CONFIG]) {
|
|
59
|
+
// ESM default export
|
|
51
60
|
instance = resolvedModule.default[CONFIG];
|
|
52
61
|
} else if (
|
|
53
62
|
resolvedModule.default &&
|
|
54
63
|
resolvedModule.default.default &&
|
|
55
64
|
resolvedModule.default.default[CONFIG]
|
|
56
65
|
) {
|
|
66
|
+
// Double-wrapped default export
|
|
57
67
|
instance = resolvedModule.default.default[CONFIG];
|
|
58
68
|
} else {
|
|
59
69
|
throw new Error(
|
|
@@ -161,7 +171,7 @@ export class AtlaspackWorker {
|
|
|
161
171
|
type: 'resolved',
|
|
162
172
|
filePath: result.filePath || '',
|
|
163
173
|
canDefer: result.canDefer || false,
|
|
164
|
-
sideEffects: result.sideEffects
|
|
174
|
+
sideEffects: result.sideEffects ?? true,
|
|
165
175
|
code: result.code || undefined,
|
|
166
176
|
meta: result.meta || undefined,
|
|
167
177
|
pipeline: result.pipeline || undefined,
|
package/src/public/Asset.ts
CHANGED
|
@@ -198,6 +198,27 @@ export default class BundleGraph<TBundle extends IBundle>
|
|
|
198
198
|
);
|
|
199
199
|
}
|
|
200
200
|
|
|
201
|
+
isAssetReferencedFastCheck(bundle: IBundle, asset: IAsset): boolean | null {
|
|
202
|
+
return this.#graph.isAssetReferencedFastCheck(
|
|
203
|
+
bundleToInternalBundle(bundle),
|
|
204
|
+
assetToAssetValue(asset),
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
getReferencedAssets(bundle: IBundle): Set<IAsset> {
|
|
209
|
+
let internalReferencedAssets = this.#graph.getReferencedAssets(
|
|
210
|
+
bundleToInternalBundle(bundle),
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
// Convert internal assets to public assets
|
|
214
|
+
let publicReferencedAssets = new Set<IAsset>();
|
|
215
|
+
for (let internalAsset of internalReferencedAssets) {
|
|
216
|
+
publicReferencedAssets.add(assetFromValue(internalAsset, this.#options));
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return publicReferencedAssets;
|
|
220
|
+
}
|
|
221
|
+
|
|
201
222
|
hasParentBundleOfType(bundle: IBundle, type: string): boolean {
|
|
202
223
|
return this.#graph.hasParentBundleOfType(
|
|
203
224
|
bundleToInternalBundle(bundle),
|
|
@@ -81,7 +81,7 @@ export default function createAssetGraphRequest(
|
|
|
81
81
|
await input.api.getPreviousResult<AssetGraphRequestResult>();
|
|
82
82
|
|
|
83
83
|
let builder = new AssetGraphBuilder(input, prevResult);
|
|
84
|
-
let assetGraphRequest = await
|
|
84
|
+
let assetGraphRequest = await builder.build();
|
|
85
85
|
|
|
86
86
|
// early break for incremental bundling if production or flag is off;
|
|
87
87
|
assetGraphRequest.assetGraph.setDisableIncrementalBundling(
|