@atlaspack/core 2.12.1-dev.3450 → 2.12.1-dev.3466
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/lib/AssetGraph.js +5 -1
- package/lib/Atlaspack.js +2 -2
- package/lib/CommittedAsset.js +11 -5
- package/lib/Dependency.js +1 -1
- package/lib/PackagerRunner.js +53 -5
- package/lib/RequestTracker.js +10 -4
- package/lib/SymbolPropagation.js +25 -36
- package/lib/UncommittedAsset.js +8 -2
- package/lib/assetUtils.js +9 -3
- package/lib/atlaspack-v3/fs.js +31 -29
- package/lib/atlaspack-v3/index.js +2 -2
- package/lib/atlaspack-v3/jsCallable.js +9 -4
- package/lib/atlaspack-v3/worker/compat/asset-symbols.js +192 -0
- package/lib/atlaspack-v3/worker/compat/bitflags.js +84 -0
- package/lib/atlaspack-v3/worker/compat/dependency.js +44 -0
- package/lib/atlaspack-v3/worker/compat/environment.js +68 -0
- package/lib/atlaspack-v3/worker/compat/index.js +104 -0
- package/lib/atlaspack-v3/worker/compat/mutable-asset.js +144 -0
- package/lib/atlaspack-v3/worker/compat/plugin-config.js +58 -0
- package/lib/atlaspack-v3/worker/compat/plugin-logger.js +29 -0
- package/lib/atlaspack-v3/worker/compat/plugin-options.js +113 -0
- package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +12 -0
- package/lib/atlaspack-v3/worker/compat/target.js +17 -0
- package/lib/atlaspack-v3/worker/worker.js +115 -127
- package/lib/index.js +0 -43
- package/lib/projectPath.js +12 -4
- package/lib/registerCoreWithSerializer.js +11 -5
- package/lib/requests/AtlaspackConfigRequest.js +8 -2
- package/lib/requests/ConfigRequest.js +9 -4
- package/lib/requests/DevDepRequest.js +9 -3
- package/lib/requests/PathRequest.js +8 -2
- package/lib/requests/WriteBundleRequest.js +15 -15
- package/lib/worker.js +8 -2
- package/package.json +24 -16
- package/src/AssetGraph.js +15 -13
- package/src/Atlaspack.js +5 -6
- package/src/AtlaspackConfig.js +11 -9
- package/src/AtlaspackConfig.schema.js +1 -1
- package/src/BundleGraph.js +83 -79
- package/src/CommittedAsset.js +5 -3
- package/src/Dependency.js +1 -1
- package/src/PackagerRunner.js +57 -9
- package/src/ReporterRunner.js +4 -4
- package/src/RequestTracker.js +19 -19
- package/src/SymbolPropagation.js +40 -52
- package/src/Transformation.js +12 -12
- package/src/UncommittedAsset.js +3 -3
- package/src/Validation.js +5 -5
- package/src/applyRuntimes.js +2 -2
- package/src/assetUtils.js +2 -2
- package/src/atlaspack-v3/AtlaspackV3.js +1 -1
- package/src/atlaspack-v3/fs.js +39 -25
- package/src/atlaspack-v3/index.js +1 -1
- package/src/atlaspack-v3/jsCallable.js +11 -10
- package/src/atlaspack-v3/worker/compat/asset-symbols.js +225 -0
- package/src/atlaspack-v3/worker/compat/bitflags.js +100 -0
- package/src/atlaspack-v3/worker/compat/dependency.js +83 -0
- package/src/atlaspack-v3/worker/compat/environment.js +92 -0
- package/src/atlaspack-v3/worker/compat/index.js +10 -0
- package/src/atlaspack-v3/worker/compat/mutable-asset.js +184 -0
- package/src/atlaspack-v3/worker/compat/plugin-config.js +94 -0
- package/src/atlaspack-v3/worker/compat/plugin-logger.js +47 -0
- package/src/atlaspack-v3/worker/compat/plugin-options.js +137 -0
- package/src/atlaspack-v3/worker/compat/plugin-tracer.js +11 -0
- package/src/atlaspack-v3/worker/compat/target.js +27 -0
- package/src/atlaspack-v3/worker/worker.js +148 -134
- package/src/dumpGraphToGraphViz.js +1 -1
- package/src/index.js +0 -10
- package/src/loadDotEnv.js +1 -1
- package/src/projectPath.js +12 -4
- package/src/public/Asset.js +1 -1
- package/src/public/Bundle.js +3 -3
- package/src/public/BundleGraph.js +20 -20
- package/src/public/Config.js +1 -1
- package/src/public/MutableBundleGraph.js +8 -8
- package/src/registerCoreWithSerializer.js +7 -4
- package/src/requests/AssetGraphRequest.js +10 -10
- package/src/requests/AssetGraphRequestRust.js +3 -3
- package/src/requests/AssetRequest.js +3 -3
- package/src/requests/AtlaspackConfigRequest.js +6 -4
- package/src/requests/BundleGraphRequest.js +6 -6
- package/src/requests/ConfigRequest.js +5 -6
- package/src/requests/DevDepRequest.js +8 -8
- package/src/requests/EntryRequest.js +2 -2
- package/src/requests/PathRequest.js +1 -1
- package/src/requests/TargetRequest.js +9 -8
- package/src/requests/ValidationRequest.js +2 -2
- package/src/requests/WriteBundleRequest.js +26 -20
- package/src/requests/WriteBundlesRequest.js +6 -6
- package/src/requests/asset-graph-diff.js +4 -4
- package/src/resolveOptions.js +3 -3
- package/src/serializerCore.browser.js +3 -2
- package/src/utils.js +2 -2
- package/src/worker.js +1 -1
- package/test/AtlaspackConfigRequest.test.js +1 -1
- package/test/BundleGraph.test.js +3 -3
- package/test/Dependency.test.js +28 -0
- package/test/PublicMutableBundleGraph.test.js +2 -2
- package/test/RequestTracker.test.js +7 -6
- package/test/SymbolPropagation.test.js +9 -9
- package/test/requests/ConfigRequest.test.js +3 -6
- package/test/utils.test.js +1 -1
- package/lib/atlaspack-v3/worker/compat.js +0 -57
- package/lib/buildCache.js +0 -18
- package/lib/serializer.js +0 -216
- package/lib/serializerCore.js +0 -16
- package/src/atlaspack-v3/worker/compat.js +0 -82
- package/src/buildCache.js +0 -15
- package/src/serializer.js +0 -255
- package/src/serializerCore.js +0 -5
- package/test/requests/WriteBundleRequest.test.js +0 -132
- package/test/serializer.test.js +0 -302
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import type {Symbol as NapiSymbol} from '@atlaspack/rust';
|
|
4
|
+
import type {
|
|
5
|
+
AssetSymbols as ClassicAssetSymbols,
|
|
6
|
+
MutableAssetSymbols as ClassicMutableAssetSymbols,
|
|
7
|
+
MutableDependencySymbols as ClassicMutableDependencySymbols,
|
|
8
|
+
Symbol,
|
|
9
|
+
SourceLocation,
|
|
10
|
+
Meta,
|
|
11
|
+
} from '@atlaspack/types';
|
|
12
|
+
|
|
13
|
+
export class MutableDependencySymbols
|
|
14
|
+
implements ClassicMutableDependencySymbols
|
|
15
|
+
{
|
|
16
|
+
#symbols: Map<Symbol, DependencyAssetSymbol>;
|
|
17
|
+
#locals: Set<Symbol>;
|
|
18
|
+
|
|
19
|
+
get isCleared(): boolean {
|
|
20
|
+
return this.#symbols.size === 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
constructor(inner: ?(NapiSymbol[]) | null) {
|
|
24
|
+
this.#symbols = new Map();
|
|
25
|
+
this.#locals = new Set();
|
|
26
|
+
for (const {exported, local, loc, isWeak} of inner || []) {
|
|
27
|
+
this.set(exported, local, loc, isWeak);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
ensure(): void {
|
|
32
|
+
throw new Error('MutableDependencySymbols.ensure()');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get(exportSymbol: Symbol): ?DependencyAssetSymbol {
|
|
36
|
+
return this.#symbols.get(exportSymbol);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
hasExportSymbol(exportSymbol: Symbol): boolean {
|
|
40
|
+
return this.#symbols.has(exportSymbol);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
hasLocalSymbol(local: Symbol): boolean {
|
|
44
|
+
return this.#locals.has(local);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
exportSymbols(): Iterable<Symbol> {
|
|
48
|
+
return this.#symbols.keys();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
set(
|
|
52
|
+
exportSymbol: Symbol,
|
|
53
|
+
local: Symbol,
|
|
54
|
+
loc: ?SourceLocation,
|
|
55
|
+
isWeak: ?boolean,
|
|
56
|
+
): void {
|
|
57
|
+
this.#locals.add(local);
|
|
58
|
+
this.#symbols.set(exportSymbol, {
|
|
59
|
+
local,
|
|
60
|
+
loc,
|
|
61
|
+
meta: {},
|
|
62
|
+
isWeak: isWeak ?? false,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
delete(exportSymbol: Symbol): void {
|
|
67
|
+
let existing = this.#symbols.get(exportSymbol);
|
|
68
|
+
if (!existing) return;
|
|
69
|
+
this.#locals.delete(existing.local);
|
|
70
|
+
this.#symbols.delete(exportSymbol);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/*:: @@iterator(): Iterator<[Symbol, DependencyAssetSymbol]> { return ({}: any); } */
|
|
74
|
+
// $FlowFixMe Flow can't do computed properties
|
|
75
|
+
[Symbol.iterator]() {
|
|
76
|
+
return this.#symbols.values();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export class AssetSymbols implements ClassicAssetSymbols {
|
|
81
|
+
#symbols: Map<Symbol, AssetSymbol>;
|
|
82
|
+
#locals: Set<Symbol>;
|
|
83
|
+
|
|
84
|
+
get isCleared(): boolean {
|
|
85
|
+
return this.#symbols.size === 0;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
constructor(inner: ?(NapiSymbol[]) | null) {
|
|
89
|
+
this.#symbols = new Map();
|
|
90
|
+
this.#locals = new Set();
|
|
91
|
+
for (const {exported, local, loc} of inner || []) {
|
|
92
|
+
this.#set(exported, local, loc);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
#set(exportSymbol: Symbol, local: Symbol, loc: ?SourceLocation): void {
|
|
97
|
+
this.#locals.add(local);
|
|
98
|
+
this.#symbols.set(exportSymbol, {
|
|
99
|
+
local,
|
|
100
|
+
loc,
|
|
101
|
+
meta: {},
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
get(exportSymbol: Symbol): ?AssetSymbol {
|
|
106
|
+
return this.#symbols.get(exportSymbol);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
hasExportSymbol(exportSymbol: Symbol): boolean {
|
|
110
|
+
return this.#symbols.has(exportSymbol);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
hasLocalSymbol(local: Symbol): boolean {
|
|
114
|
+
return this.#locals.has(local);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
exportSymbols(): Iterable<Symbol> {
|
|
118
|
+
return this.#symbols.keys();
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
intoNapi(): NapiSymbol[] {
|
|
122
|
+
return [];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/*:: @@iterator(): Iterator<[Symbol, AssetSymbol]> { return ({}: any); } */
|
|
126
|
+
// $FlowFixMe Flow can't do computed properties
|
|
127
|
+
[Symbol.iterator]() {
|
|
128
|
+
return this.#symbols.values();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export class MutableAssetSymbols implements ClassicMutableAssetSymbols {
|
|
133
|
+
#symbols: Map<Symbol, AssetSymbol>;
|
|
134
|
+
#locals: Set<Symbol>;
|
|
135
|
+
|
|
136
|
+
get isCleared(): boolean {
|
|
137
|
+
return this.#symbols.size === 0;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
constructor(inner: ?(NapiSymbol[]) | null) {
|
|
141
|
+
this.#symbols = new Map();
|
|
142
|
+
this.#locals = new Set();
|
|
143
|
+
for (const {exported, local, loc} of inner || []) {
|
|
144
|
+
this.set(exported, local, loc);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
intoNapi(): NapiSymbol[] {
|
|
149
|
+
const results: NapiSymbol[] = [];
|
|
150
|
+
for (const [exportSymbol, {local, loc}] of this.#symbols.entries()) {
|
|
151
|
+
results.push({
|
|
152
|
+
exported: exportSymbol,
|
|
153
|
+
local,
|
|
154
|
+
loc: loc
|
|
155
|
+
? {
|
|
156
|
+
filePath: loc.filePath,
|
|
157
|
+
start: {
|
|
158
|
+
line: loc.start.line,
|
|
159
|
+
column: loc.start.column,
|
|
160
|
+
},
|
|
161
|
+
end: {
|
|
162
|
+
line: loc.end.line,
|
|
163
|
+
column: loc.end.column,
|
|
164
|
+
},
|
|
165
|
+
}
|
|
166
|
+
: undefined,
|
|
167
|
+
// TODO
|
|
168
|
+
isWeak: false,
|
|
169
|
+
isEsmExport: false,
|
|
170
|
+
selfReferenced: false,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return results;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
ensure(): void {
|
|
177
|
+
throw new Error('MutableAssetSymbols.ensure()');
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
set(exportSymbol: Symbol, local: Symbol, loc: ?SourceLocation): void {
|
|
181
|
+
this.#locals.add(local);
|
|
182
|
+
this.#symbols.set(exportSymbol, {
|
|
183
|
+
local,
|
|
184
|
+
loc,
|
|
185
|
+
meta: {},
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
get(exportSymbol: Symbol): ?AssetSymbol {
|
|
190
|
+
return this.#symbols.get(exportSymbol);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
hasExportSymbol(exportSymbol: Symbol): boolean {
|
|
194
|
+
return this.#symbols.has(exportSymbol);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
hasLocalSymbol(local: Symbol): boolean {
|
|
198
|
+
return this.#locals.has(local);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
exportSymbols(): Iterable<Symbol> {
|
|
202
|
+
return this.#symbols.keys();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
delete(exportSymbol: Symbol): void {
|
|
206
|
+
let existing = this.#symbols.get(exportSymbol);
|
|
207
|
+
if (!existing) return;
|
|
208
|
+
this.#locals.delete(existing.local);
|
|
209
|
+
this.#symbols.delete(exportSymbol);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/*:: @@iterator(): Iterator<[Symbol, AssetSymbol]> { return ({}: any); } */
|
|
213
|
+
// $FlowFixMe Flow can't do computed properties
|
|
214
|
+
[Symbol.iterator]() {
|
|
215
|
+
return this.#symbols.values();
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export type AssetSymbol = {|local: Symbol, loc: ?SourceLocation, meta?: ?Meta|};
|
|
220
|
+
export type DependencyAssetSymbol = {|
|
|
221
|
+
local: Symbol,
|
|
222
|
+
loc: ?SourceLocation,
|
|
223
|
+
meta?: ?Meta,
|
|
224
|
+
isWeak: boolean,
|
|
225
|
+
|};
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import type {
|
|
4
|
+
BundleBehavior,
|
|
5
|
+
DependencyPriority,
|
|
6
|
+
SpecifierType,
|
|
7
|
+
} from '@atlaspack/types';
|
|
8
|
+
|
|
9
|
+
/// BitFlags is used to map number/string types from napi types
|
|
10
|
+
export class BitFlags<K, V> {
|
|
11
|
+
#kv: {[key: K]: V};
|
|
12
|
+
#vk: {[key: V]: K};
|
|
13
|
+
|
|
14
|
+
constructor(source: {[key: K]: V}) {
|
|
15
|
+
this.#kv = source;
|
|
16
|
+
this.#vk = Object.fromEntries(
|
|
17
|
+
// $FlowFixMe
|
|
18
|
+
Object.entries(source).map((a) => a.reverse()),
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
into(key: K): V {
|
|
23
|
+
const found = this.#kv[key];
|
|
24
|
+
if (found === undefined) {
|
|
25
|
+
// $FlowFixMe
|
|
26
|
+
throw new Error(`Invalid BundleBehavior(${key})`);
|
|
27
|
+
}
|
|
28
|
+
return found;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
intoNullable(key: ?K): ?V {
|
|
32
|
+
if (key === undefined || key === null) {
|
|
33
|
+
return undefined;
|
|
34
|
+
}
|
|
35
|
+
return this.into(key);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
intoArray(keys: K[]): V[] {
|
|
39
|
+
return keys.map((key) => this.into(key));
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
from(key: V): K {
|
|
43
|
+
const found = this.#vk[key];
|
|
44
|
+
if (found === undefined) {
|
|
45
|
+
// $FlowFixMe
|
|
46
|
+
throw new Error(`Invalid BundleBehavior(${key})`);
|
|
47
|
+
}
|
|
48
|
+
return found;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fromNullable(key: ?V): ?K {
|
|
52
|
+
if (key === undefined || key === null) {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
return this.from(key);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
fromArray(keys: V[]): K[] {
|
|
59
|
+
return keys.map((key) => this.from(key));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export const bundleBehaviorMap: BitFlags<BundleBehavior, number> = new BitFlags(
|
|
64
|
+
{
|
|
65
|
+
inline: 0,
|
|
66
|
+
isolated: 1,
|
|
67
|
+
},
|
|
68
|
+
);
|
|
69
|
+
|
|
70
|
+
export const dependencyPriorityMap: BitFlags<DependencyPriority, number> =
|
|
71
|
+
new BitFlags({
|
|
72
|
+
sync: 0,
|
|
73
|
+
parallel: 1,
|
|
74
|
+
lazy: 2,
|
|
75
|
+
conditional: 3,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
export const packageConditionsMap: BitFlags<string, number> = new BitFlags({
|
|
79
|
+
import: 0,
|
|
80
|
+
require: 1,
|
|
81
|
+
module: 2,
|
|
82
|
+
node: 3,
|
|
83
|
+
browser: 4,
|
|
84
|
+
worker: 5,
|
|
85
|
+
worklet: 6,
|
|
86
|
+
electron: 7,
|
|
87
|
+
development: 8,
|
|
88
|
+
production: 9,
|
|
89
|
+
types: 10,
|
|
90
|
+
default: 11,
|
|
91
|
+
style: 12,
|
|
92
|
+
sass: 13,
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
export const specifierTypeMap: BitFlags<SpecifierType, number> = new BitFlags({
|
|
96
|
+
esm: 0,
|
|
97
|
+
commonjs: 1,
|
|
98
|
+
url: 2,
|
|
99
|
+
custom: 3,
|
|
100
|
+
});
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import type {Dependency as NapiDependency} from '@atlaspack/rust';
|
|
4
|
+
import type {
|
|
5
|
+
Dependency as ClassicDependency,
|
|
6
|
+
DependencySpecifier,
|
|
7
|
+
SpecifierType,
|
|
8
|
+
DependencyPriority,
|
|
9
|
+
BundleBehavior,
|
|
10
|
+
SourceLocation,
|
|
11
|
+
Environment as ClassicEnvironment,
|
|
12
|
+
Meta,
|
|
13
|
+
Target as ClassicTarget,
|
|
14
|
+
FilePath,
|
|
15
|
+
SemverRange,
|
|
16
|
+
MutableDependencySymbols as ClassicMutableDependencySymbols,
|
|
17
|
+
} from '@atlaspack/types';
|
|
18
|
+
import {Target} from './target';
|
|
19
|
+
import {MutableDependencySymbols} from './asset-symbols';
|
|
20
|
+
import {
|
|
21
|
+
bundleBehaviorMap,
|
|
22
|
+
specifierTypeMap,
|
|
23
|
+
dependencyPriorityMap,
|
|
24
|
+
packageConditionsMap,
|
|
25
|
+
} from './bitflags';
|
|
26
|
+
|
|
27
|
+
export class Dependency implements ClassicDependency {
|
|
28
|
+
env: ClassicEnvironment;
|
|
29
|
+
meta: Meta;
|
|
30
|
+
target: ?ClassicTarget;
|
|
31
|
+
symbols: ClassicMutableDependencySymbols;
|
|
32
|
+
specifier: DependencySpecifier;
|
|
33
|
+
specifierType: SpecifierType;
|
|
34
|
+
priority: DependencyPriority;
|
|
35
|
+
bundleBehavior: ?BundleBehavior;
|
|
36
|
+
needsStableName: boolean;
|
|
37
|
+
isOptional: boolean;
|
|
38
|
+
isEntry: boolean;
|
|
39
|
+
loc: ?SourceLocation;
|
|
40
|
+
packageConditions: ?Array<string>;
|
|
41
|
+
sourceAssetId: ?string;
|
|
42
|
+
sourcePath: ?FilePath;
|
|
43
|
+
sourceAssetType: ?string;
|
|
44
|
+
resolveFrom: ?FilePath;
|
|
45
|
+
range: ?SemverRange;
|
|
46
|
+
pipeline: ?string;
|
|
47
|
+
|
|
48
|
+
get id(): string {
|
|
49
|
+
throw new Error('Dependency.id');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
constructor(inner: NapiDependency, env: ClassicEnvironment) {
|
|
53
|
+
this.env = env;
|
|
54
|
+
this.meta = inner.meta || {};
|
|
55
|
+
this.target = undefined;
|
|
56
|
+
if (inner.target) {
|
|
57
|
+
this.target = new Target(inner.target, this.env);
|
|
58
|
+
}
|
|
59
|
+
if (!inner.bundleBehavior) {
|
|
60
|
+
this.bundleBehavior = undefined;
|
|
61
|
+
} else {
|
|
62
|
+
this.bundleBehavior = bundleBehaviorMap.from(inner.bundleBehavior);
|
|
63
|
+
}
|
|
64
|
+
this.bundleBehavior = undefined;
|
|
65
|
+
this.symbols = new MutableDependencySymbols(inner.symbols || []);
|
|
66
|
+
this.specifier = inner.specifier;
|
|
67
|
+
this.specifierType = specifierTypeMap.from(inner.specifierType);
|
|
68
|
+
this.priority = dependencyPriorityMap.from(inner.priority);
|
|
69
|
+
this.needsStableName = inner.needsStableName;
|
|
70
|
+
this.isOptional = inner.isOptional;
|
|
71
|
+
this.isEntry = inner.isEntry;
|
|
72
|
+
this.loc = inner.loc;
|
|
73
|
+
this.packageConditions = packageConditionsMap.fromArray(
|
|
74
|
+
inner.packageConditions || [],
|
|
75
|
+
);
|
|
76
|
+
this.sourceAssetId = inner.sourceAssetId;
|
|
77
|
+
this.sourcePath = inner.sourcePath;
|
|
78
|
+
this.sourceAssetType = inner.sourceAssetType;
|
|
79
|
+
this.resolveFrom = inner.resolveFrom;
|
|
80
|
+
this.range = inner.range;
|
|
81
|
+
this.pipeline = inner.pipeline;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import type {Environment as NapiEnvironment} from '@atlaspack/rust';
|
|
4
|
+
import type {
|
|
5
|
+
Environment as ClassicEnvironment,
|
|
6
|
+
EnvironmentContext,
|
|
7
|
+
Engines,
|
|
8
|
+
PackageName,
|
|
9
|
+
OutputFormat,
|
|
10
|
+
SourceType,
|
|
11
|
+
TargetSourceMapOptions,
|
|
12
|
+
SourceLocation,
|
|
13
|
+
VersionMap,
|
|
14
|
+
EnvironmentFeature,
|
|
15
|
+
} from '@atlaspack/types';
|
|
16
|
+
|
|
17
|
+
export class Environment implements ClassicEnvironment {
|
|
18
|
+
id: string;
|
|
19
|
+
includeNodeModules:
|
|
20
|
+
| boolean
|
|
21
|
+
| Array<PackageName>
|
|
22
|
+
| {[PackageName]: boolean, ...};
|
|
23
|
+
context: EnvironmentContext;
|
|
24
|
+
engines: Engines;
|
|
25
|
+
outputFormat: OutputFormat;
|
|
26
|
+
sourceType: SourceType;
|
|
27
|
+
isLibrary: boolean;
|
|
28
|
+
shouldOptimize: boolean;
|
|
29
|
+
shouldScopeHoist: boolean;
|
|
30
|
+
sourceMap: ?TargetSourceMapOptions;
|
|
31
|
+
loc: ?SourceLocation;
|
|
32
|
+
|
|
33
|
+
constructor(inner: NapiEnvironment) {
|
|
34
|
+
// TODO
|
|
35
|
+
this.id = '';
|
|
36
|
+
this.includeNodeModules = inner.includeNodeModules;
|
|
37
|
+
// $FlowFixMe
|
|
38
|
+
this.context = inner.context;
|
|
39
|
+
this.engines = inner.engines;
|
|
40
|
+
// $FlowFixMe
|
|
41
|
+
this.outputFormat = inner.outputFormat;
|
|
42
|
+
// $FlowFixMe
|
|
43
|
+
this.sourceType = inner.sourceType;
|
|
44
|
+
this.isLibrary = inner.isLibrary;
|
|
45
|
+
this.shouldOptimize = inner.shouldOptimize;
|
|
46
|
+
this.shouldScopeHoist = inner.shouldScopeHoist;
|
|
47
|
+
this.sourceMap = inner.sourceMap;
|
|
48
|
+
this.loc = inner.loc;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// TODO
|
|
52
|
+
isBrowser(): boolean {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// TODO
|
|
57
|
+
isNode(): boolean {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
// TODO
|
|
62
|
+
isElectron(): boolean {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// TODO
|
|
67
|
+
isWorker(): boolean {
|
|
68
|
+
return false;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// TODO
|
|
72
|
+
isWorklet(): boolean {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// TODO
|
|
77
|
+
isIsolated(): boolean {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
// TODO
|
|
82
|
+
// eslint-disable-next-line no-unused-vars
|
|
83
|
+
matchesEngines(minVersions: VersionMap, defaultValue?: boolean): boolean {
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// TODO
|
|
88
|
+
// eslint-disable-next-line no-unused-vars
|
|
89
|
+
supports(feature: EnvironmentFeature, defaultValue?: boolean): boolean {
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
export * from './bitflags';
|
|
3
|
+
export * from './dependency';
|
|
4
|
+
export * from './environment';
|
|
5
|
+
export * from './target';
|
|
6
|
+
export * from './plugin-config';
|
|
7
|
+
export * from './plugin-tracer';
|
|
8
|
+
export * from './plugin-logger';
|
|
9
|
+
export * from './plugin-options';
|
|
10
|
+
export * from './mutable-asset';
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
// @flow
|
|
2
|
+
|
|
3
|
+
import type SourceMap from '@parcel/source-map';
|
|
4
|
+
import * as napi from '@atlaspack/rust';
|
|
5
|
+
import {Readable} from 'stream';
|
|
6
|
+
import type {
|
|
7
|
+
MutableAsset as IMutableAsset,
|
|
8
|
+
Stats,
|
|
9
|
+
FileSystem,
|
|
10
|
+
FilePath,
|
|
11
|
+
Environment,
|
|
12
|
+
Meta,
|
|
13
|
+
BundleBehavior,
|
|
14
|
+
ASTGenerator,
|
|
15
|
+
AST,
|
|
16
|
+
Dependency,
|
|
17
|
+
DependencyOptions,
|
|
18
|
+
FileCreateInvalidation,
|
|
19
|
+
EnvironmentOptions,
|
|
20
|
+
} from '@atlaspack/types';
|
|
21
|
+
import {bundleBehaviorMap} from './bitflags';
|
|
22
|
+
import {MutableAssetSymbols} from './asset-symbols';
|
|
23
|
+
|
|
24
|
+
export type InnerAsset = napi.Asset;
|
|
25
|
+
|
|
26
|
+
export class MutableAsset implements IMutableAsset {
|
|
27
|
+
fs: FileSystem;
|
|
28
|
+
env: Environment;
|
|
29
|
+
symbols: MutableAssetSymbols;
|
|
30
|
+
stats: Stats;
|
|
31
|
+
id: string;
|
|
32
|
+
filePath: FilePath;
|
|
33
|
+
type: string;
|
|
34
|
+
query: URLSearchParams;
|
|
35
|
+
isSource: boolean;
|
|
36
|
+
meta: Meta;
|
|
37
|
+
bundleBehavior: ?BundleBehavior;
|
|
38
|
+
isBundleSplittable: boolean;
|
|
39
|
+
sideEffects: boolean;
|
|
40
|
+
uniqueKey: ?string;
|
|
41
|
+
pipeline: ?string;
|
|
42
|
+
|
|
43
|
+
#inner: InnerAsset;
|
|
44
|
+
#ast: ?AST;
|
|
45
|
+
#contents: Buffer;
|
|
46
|
+
|
|
47
|
+
get astGenerator(): ?ASTGenerator {
|
|
48
|
+
throw new Error('get MutableAsset.astGenerator');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
set astGenerator(value: ?ASTGenerator) {
|
|
52
|
+
throw new Error('set MutableAsset.astGenerator');
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
constructor(asset: InnerAsset, fs: FileSystem, env: Environment) {
|
|
56
|
+
this.#inner = asset;
|
|
57
|
+
this.stats = asset.stats;
|
|
58
|
+
this.id = asset.id;
|
|
59
|
+
this.filePath = asset.filePath;
|
|
60
|
+
this.type;
|
|
61
|
+
this.symbols = new MutableAssetSymbols(asset.symbols);
|
|
62
|
+
this.stats = asset.stats;
|
|
63
|
+
this.id = asset.id;
|
|
64
|
+
this.filePath = asset.filePath;
|
|
65
|
+
this.type = asset.type;
|
|
66
|
+
this.query = new URLSearchParams(asset.query);
|
|
67
|
+
this.isSource = asset.isSource;
|
|
68
|
+
this.meta = asset.meta;
|
|
69
|
+
this.bundleBehavior = bundleBehaviorMap.fromNullable(asset.bundleBehavior);
|
|
70
|
+
this.isBundleSplittable = asset.isBundleSplittable;
|
|
71
|
+
this.sideEffects = asset.sideEffects;
|
|
72
|
+
this.uniqueKey = asset.uniqueKey;
|
|
73
|
+
this.pipeline = asset.pipeline;
|
|
74
|
+
this.#contents = Buffer.from(asset.code);
|
|
75
|
+
this.fs = fs;
|
|
76
|
+
this.env = env;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// eslint-disable-next-line require-await
|
|
80
|
+
async getAST(): Promise<?AST> {
|
|
81
|
+
return this.#ast;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
setAST(ast: AST): void {
|
|
85
|
+
this.#ast = ast;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
isASTDirty(): boolean {
|
|
89
|
+
throw new Error('MutableAsset.isASTDirty()');
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// eslint-disable-next-line require-await
|
|
93
|
+
async getCode(): Promise<string> {
|
|
94
|
+
return this.#contents.toString();
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
setCode(code: string): void {
|
|
98
|
+
this.#contents = Buffer.from(code);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
// eslint-disable-next-line require-await
|
|
102
|
+
async getBuffer(): Promise<Buffer> {
|
|
103
|
+
return this.#contents;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
setBuffer(buf: Buffer): void {
|
|
107
|
+
this.#contents = buf;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
getStream(): Readable {
|
|
111
|
+
return Readable.from(this.#contents);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
setStream(stream: Readable): void {
|
|
115
|
+
const data = [];
|
|
116
|
+
|
|
117
|
+
stream.on('data', (chunk) => {
|
|
118
|
+
data.push(chunk);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
stream.on('end', () => {
|
|
122
|
+
this.#contents = Buffer.concat(data);
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
stream.on('error', () => {
|
|
126
|
+
throw new Error('MutableAsset.setStream()');
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
getMap(): Promise<?SourceMap> {
|
|
131
|
+
throw new Error('MutableAsset.getMap');
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// eslint-disable-next-line no-unused-vars
|
|
135
|
+
setMap(sourceMap: ?SourceMap): void {
|
|
136
|
+
throw new Error('MutableAsset.setMap()');
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
getMapBuffer(): Promise<?Buffer> {
|
|
140
|
+
throw new Error('MutableAsset.getMapBuffer');
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
getDependencies(): $ReadOnlyArray<Dependency> {
|
|
144
|
+
throw new Error('MutableAsset.getDependencies');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// eslint-disable-next-line no-unused-vars
|
|
148
|
+
addDependency(options: DependencyOptions): string {
|
|
149
|
+
throw new Error('MutableAsset.addDependency()');
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// eslint-disable-next-line no-unused-vars
|
|
153
|
+
addURLDependency(url: string, opts: $Shape<DependencyOptions>): string {
|
|
154
|
+
throw new Error('MutableAsset.addURLDependency()');
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// eslint-disable-next-line no-unused-vars
|
|
158
|
+
setEnvironment(opts: EnvironmentOptions): void {
|
|
159
|
+
throw new Error('MutableAsset.setEnvironment()');
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
// eslint-disable-next-line no-unused-vars
|
|
163
|
+
invalidateOnFileChange(invalidation: FilePath): void {
|
|
164
|
+
throw new Error('MutableAsset.invalidateOnFileChange()');
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// eslint-disable-next-line no-unused-vars
|
|
168
|
+
invalidateOnFileCreate(invalidation: FileCreateInvalidation): void {
|
|
169
|
+
throw new Error('MutableAsset.invalidateOnFileCreate()');
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// eslint-disable-next-line no-unused-vars
|
|
173
|
+
invalidateOnEnvChange(invalidation: string): void {
|
|
174
|
+
throw new Error('MutableAsset.invalidateOnEnvChange()');
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
invalidateOnStartup(): void {
|
|
178
|
+
throw new Error('MutableAsset.invalidateOnStartup()');
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
invalidateOnBuild(): void {
|
|
182
|
+
throw new Error('MutableAsset.invalidateOnBuild()');
|
|
183
|
+
}
|
|
184
|
+
}
|