@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.
Files changed (112) hide show
  1. package/lib/AssetGraph.js +5 -1
  2. package/lib/Atlaspack.js +2 -2
  3. package/lib/CommittedAsset.js +11 -5
  4. package/lib/Dependency.js +1 -1
  5. package/lib/PackagerRunner.js +53 -5
  6. package/lib/RequestTracker.js +10 -4
  7. package/lib/SymbolPropagation.js +25 -36
  8. package/lib/UncommittedAsset.js +8 -2
  9. package/lib/assetUtils.js +9 -3
  10. package/lib/atlaspack-v3/fs.js +31 -29
  11. package/lib/atlaspack-v3/index.js +2 -2
  12. package/lib/atlaspack-v3/jsCallable.js +9 -4
  13. package/lib/atlaspack-v3/worker/compat/asset-symbols.js +192 -0
  14. package/lib/atlaspack-v3/worker/compat/bitflags.js +84 -0
  15. package/lib/atlaspack-v3/worker/compat/dependency.js +44 -0
  16. package/lib/atlaspack-v3/worker/compat/environment.js +68 -0
  17. package/lib/atlaspack-v3/worker/compat/index.js +104 -0
  18. package/lib/atlaspack-v3/worker/compat/mutable-asset.js +144 -0
  19. package/lib/atlaspack-v3/worker/compat/plugin-config.js +58 -0
  20. package/lib/atlaspack-v3/worker/compat/plugin-logger.js +29 -0
  21. package/lib/atlaspack-v3/worker/compat/plugin-options.js +113 -0
  22. package/lib/atlaspack-v3/worker/compat/plugin-tracer.js +12 -0
  23. package/lib/atlaspack-v3/worker/compat/target.js +17 -0
  24. package/lib/atlaspack-v3/worker/worker.js +115 -127
  25. package/lib/index.js +0 -43
  26. package/lib/projectPath.js +12 -4
  27. package/lib/registerCoreWithSerializer.js +11 -5
  28. package/lib/requests/AtlaspackConfigRequest.js +8 -2
  29. package/lib/requests/ConfigRequest.js +9 -4
  30. package/lib/requests/DevDepRequest.js +9 -3
  31. package/lib/requests/PathRequest.js +8 -2
  32. package/lib/requests/WriteBundleRequest.js +15 -15
  33. package/lib/worker.js +8 -2
  34. package/package.json +24 -16
  35. package/src/AssetGraph.js +15 -13
  36. package/src/Atlaspack.js +5 -6
  37. package/src/AtlaspackConfig.js +11 -9
  38. package/src/AtlaspackConfig.schema.js +1 -1
  39. package/src/BundleGraph.js +83 -79
  40. package/src/CommittedAsset.js +5 -3
  41. package/src/Dependency.js +1 -1
  42. package/src/PackagerRunner.js +57 -9
  43. package/src/ReporterRunner.js +4 -4
  44. package/src/RequestTracker.js +19 -19
  45. package/src/SymbolPropagation.js +40 -52
  46. package/src/Transformation.js +12 -12
  47. package/src/UncommittedAsset.js +3 -3
  48. package/src/Validation.js +5 -5
  49. package/src/applyRuntimes.js +2 -2
  50. package/src/assetUtils.js +2 -2
  51. package/src/atlaspack-v3/AtlaspackV3.js +1 -1
  52. package/src/atlaspack-v3/fs.js +39 -25
  53. package/src/atlaspack-v3/index.js +1 -1
  54. package/src/atlaspack-v3/jsCallable.js +11 -10
  55. package/src/atlaspack-v3/worker/compat/asset-symbols.js +225 -0
  56. package/src/atlaspack-v3/worker/compat/bitflags.js +100 -0
  57. package/src/atlaspack-v3/worker/compat/dependency.js +83 -0
  58. package/src/atlaspack-v3/worker/compat/environment.js +92 -0
  59. package/src/atlaspack-v3/worker/compat/index.js +10 -0
  60. package/src/atlaspack-v3/worker/compat/mutable-asset.js +184 -0
  61. package/src/atlaspack-v3/worker/compat/plugin-config.js +94 -0
  62. package/src/atlaspack-v3/worker/compat/plugin-logger.js +47 -0
  63. package/src/atlaspack-v3/worker/compat/plugin-options.js +137 -0
  64. package/src/atlaspack-v3/worker/compat/plugin-tracer.js +11 -0
  65. package/src/atlaspack-v3/worker/compat/target.js +27 -0
  66. package/src/atlaspack-v3/worker/worker.js +148 -134
  67. package/src/dumpGraphToGraphViz.js +1 -1
  68. package/src/index.js +0 -10
  69. package/src/loadDotEnv.js +1 -1
  70. package/src/projectPath.js +12 -4
  71. package/src/public/Asset.js +1 -1
  72. package/src/public/Bundle.js +3 -3
  73. package/src/public/BundleGraph.js +20 -20
  74. package/src/public/Config.js +1 -1
  75. package/src/public/MutableBundleGraph.js +8 -8
  76. package/src/registerCoreWithSerializer.js +7 -4
  77. package/src/requests/AssetGraphRequest.js +10 -10
  78. package/src/requests/AssetGraphRequestRust.js +3 -3
  79. package/src/requests/AssetRequest.js +3 -3
  80. package/src/requests/AtlaspackConfigRequest.js +6 -4
  81. package/src/requests/BundleGraphRequest.js +6 -6
  82. package/src/requests/ConfigRequest.js +5 -6
  83. package/src/requests/DevDepRequest.js +8 -8
  84. package/src/requests/EntryRequest.js +2 -2
  85. package/src/requests/PathRequest.js +1 -1
  86. package/src/requests/TargetRequest.js +9 -8
  87. package/src/requests/ValidationRequest.js +2 -2
  88. package/src/requests/WriteBundleRequest.js +26 -20
  89. package/src/requests/WriteBundlesRequest.js +6 -6
  90. package/src/requests/asset-graph-diff.js +4 -4
  91. package/src/resolveOptions.js +3 -3
  92. package/src/serializerCore.browser.js +3 -2
  93. package/src/utils.js +2 -2
  94. package/src/worker.js +1 -1
  95. package/test/AtlaspackConfigRequest.test.js +1 -1
  96. package/test/BundleGraph.test.js +3 -3
  97. package/test/Dependency.test.js +28 -0
  98. package/test/PublicMutableBundleGraph.test.js +2 -2
  99. package/test/RequestTracker.test.js +7 -6
  100. package/test/SymbolPropagation.test.js +9 -9
  101. package/test/requests/ConfigRequest.test.js +3 -6
  102. package/test/utils.test.js +1 -1
  103. package/lib/atlaspack-v3/worker/compat.js +0 -57
  104. package/lib/buildCache.js +0 -18
  105. package/lib/serializer.js +0 -216
  106. package/lib/serializerCore.js +0 -16
  107. package/src/atlaspack-v3/worker/compat.js +0 -82
  108. package/src/buildCache.js +0 -15
  109. package/src/serializer.js +0 -255
  110. package/src/serializerCore.js +0 -5
  111. package/test/requests/WriteBundleRequest.test.js +0 -132
  112. package/test/serializer.test.js +0 -302
@@ -1,132 +0,0 @@
1
- // @flow strict-local
2
-
3
- import {replaceStream} from '../../src/requests/WriteBundleRequest';
4
- import {Writable, pipeline} from 'stream';
5
- import {replaceHashReferences} from '@atlaspack/rust';
6
- import assert from 'assert';
7
- import {blobToStream} from '@atlaspack/utils';
8
-
9
- class BufferWritable extends Writable {
10
- buffers: Buffer[];
11
-
12
- constructor() {
13
- super();
14
- this.buffers = [];
15
- }
16
-
17
- getBuffer(): Buffer {
18
- return Buffer.concat(this.buffers);
19
- }
20
-
21
- _write(chunk: string | Buffer, encoding: string, callback) {
22
- let buffer =
23
- typeof chunk === 'string'
24
- ? // $FlowFixMe
25
- Buffer.from(chunk, encoding)
26
- : chunk;
27
- this.buffers.push(buffer);
28
- callback();
29
- }
30
- }
31
-
32
- function generateSampleInput(
33
- hashReferences: Map<string, string>,
34
- inputSize: number,
35
- ): Buffe {
36
- let output = '';
37
-
38
- while (output.length < inputSize) {
39
- if (Math.random() < 0.1) {
40
- output += 'HASH_REF_1234567890123456';
41
- } else {
42
- for (let i = 0; i < 16; i++) {
43
- output += String.fromCharCode(97 + Math.floor(Math.random() * 26));
44
- }
45
- }
46
- }
47
-
48
- return Buffer.from(output);
49
- }
50
-
51
- async function javascriptReplaceHashReferences(
52
- buffer: Buffer,
53
- hashReferences: Map<string, string>,
54
- ): Promise<Buffer> {
55
- const writable = new BufferWritable();
56
- const transform = replaceStream(hashReferences);
57
-
58
- await new Promise((resolve, reject) => {
59
- pipeline(blobToStream(buffer), transform, writable, err => {
60
- if (err) reject(err);
61
- else resolve(null);
62
- });
63
- });
64
-
65
- const output = writable.getBuffer();
66
- return output;
67
- }
68
-
69
- describe('replaceStream', () => {
70
- const hashReferences = new Map([
71
- ['HASH_REF_1234567890123456', 'HASH_REF_replacedwithstri'],
72
- ]);
73
- const buffer = Buffer.from(
74
- 'Hello HASH_REF_1234567890123456 more stuff here HASH_REF_1234567890123456',
75
- );
76
- const expectedOutput =
77
- 'Hello HASH_REF_replacedwithstri more stuff here HASH_REF_replacedwithstri';
78
-
79
- it('javascript - replaces hash references in buffers', async () => {
80
- const output = await javascriptReplaceHashReferences(
81
- buffer,
82
- hashReferences,
83
- );
84
- const outputString = output.toString();
85
- assert.equal(outputString, expectedOutput);
86
- });
87
-
88
- it('rust - replaces hash references in buffers', () => {
89
- const output = replaceHashReferences(
90
- buffer,
91
- Object.fromEntries(hashReferences.entries()),
92
- );
93
-
94
- const outputString = output.toString();
95
- assert.equal(outputString, expectedOutput);
96
- });
97
-
98
- let currentInputSize = 1024 * 1024; // Start at 1MB and grow to 40MB
99
- const inputSizes = [];
100
- while (currentInputSize < 40 * 1024 * 1024) {
101
- inputSizes.push(currentInputSize);
102
- currentInputSize *= 2;
103
- }
104
-
105
- inputSizes.forEach(inputSize => {
106
- describe('input size ' + inputSize / 1024 / 1024 + 'MB', () => {
107
- const buffer = generateSampleInput(hashReferences, inputSize);
108
- const expectedOutput = buffer
109
- .toString()
110
- .replace(/HASH_REF_1234567890123456/g, 'HASH_REF_replacedwithstri');
111
-
112
- it('javascript - works on huge buffer', async () => {
113
- const output = await javascriptReplaceHashReferences(
114
- buffer,
115
- hashReferences,
116
- );
117
- const outputString = output.toString();
118
- assert.equal(outputString, expectedOutput);
119
- });
120
-
121
- it('rust - works on huge buffer', () => {
122
- const output = replaceHashReferences(
123
- buffer,
124
- Object.fromEntries(hashReferences.entries()),
125
- );
126
-
127
- const outputString = output.toString();
128
- assert.equal(outputString, expectedOutput);
129
- });
130
- });
131
- });
132
- });
@@ -1,302 +0,0 @@
1
- // @flow
2
- import {
3
- serialize,
4
- deserialize,
5
- registerSerializableClass,
6
- unregisterSerializableClass,
7
- } from '../src/serializer';
8
- import assert from 'assert';
9
- import sinon from 'sinon';
10
-
11
- describe('serializer', () => {
12
- it('should serialize a basic object', () => {
13
- let serialized = serialize({foo: 2, bar: 3});
14
- assert(Buffer.isBuffer(serialized));
15
- let deserialized = deserialize(serialized);
16
- assert.equal(typeof deserialized, 'object');
17
- assert.deepEqual(deserialized, {foo: 2, bar: 3});
18
- });
19
-
20
- it('should serialize an object with multiple references', () => {
21
- let a = {foo: 2};
22
- let b = {bar: a, baz: a};
23
- let res = deserialize(serialize(b));
24
- assert.deepEqual(res, b);
25
- assert.equal(res.bar, res.baz);
26
- });
27
-
28
- it('should serialize a cyclic object', () => {
29
- let a = {foo: 2, bar: {}};
30
- a.bar = a;
31
- let res = deserialize(serialize(a));
32
- assert.deepEqual(res, a);
33
- assert.equal(res.bar, res);
34
- assert.equal(a.bar, a);
35
- });
36
-
37
- it('should serialize a Map', () => {
38
- let a = new Map([[2, 3]]);
39
- let res = deserialize(serialize(a));
40
- assert(res instanceof Map);
41
- assert.equal(res.get(2), 3);
42
- });
43
-
44
- it('should serialize a Set', () => {
45
- let a = new Set([2, 3]);
46
- let res = deserialize(serialize(a));
47
- assert(res instanceof Set);
48
- assert(res.has(2));
49
- assert(res.has(3));
50
- });
51
-
52
- it('should serialize a class', () => {
53
- class Test {
54
- x: number;
55
- constructor(x: number) {
56
- this.x = x;
57
- }
58
- }
59
-
60
- registerSerializableClass('Test', Test);
61
-
62
- let x = new Test(2);
63
- let res = deserialize(serialize(x));
64
- assert(res instanceof Test);
65
- assert.equal(res.x, x.x);
66
-
67
- unregisterSerializableClass('Test', Test);
68
- });
69
-
70
- it('should serialize a class with a custom serialize method', () => {
71
- class Test {
72
- x: number;
73
- constructor(x: number) {
74
- this.x = x;
75
- }
76
-
77
- serialize() {
78
- return {
79
- x: this.x,
80
- serialized: true,
81
- };
82
- }
83
- }
84
-
85
- registerSerializableClass('Test', Test);
86
-
87
- let x = new Test(2);
88
- let res = deserialize(serialize(x));
89
- assert(res instanceof Test);
90
- assert.equal(res.x, x.x);
91
- assert.equal(res.serialized, true);
92
-
93
- unregisterSerializableClass('Test', Test);
94
- });
95
-
96
- it('should serialize a class with a custom deserialize method', () => {
97
- class Test {
98
- x: number;
99
- constructor(x: number) {
100
- this.x = x;
101
- }
102
-
103
- static deserialize(x: any) {
104
- return {
105
- deserialized: true,
106
- value: x,
107
- };
108
- }
109
- }
110
-
111
- registerSerializableClass('Test', Test);
112
-
113
- let x = new Test(2);
114
- let res = deserialize(serialize(x));
115
- assert(!(res instanceof Test));
116
- assert.equal(res.value.x, x.x);
117
- assert.equal(res.deserialized, true);
118
-
119
- unregisterSerializableClass('Test', Test);
120
- });
121
-
122
- it('should serialize a class recursively', () => {
123
- class Foo {
124
- x: number;
125
- constructor(x: number) {
126
- this.x = x;
127
- }
128
- }
129
-
130
- class Bar {
131
- foo: Foo;
132
- constructor(foo: Foo) {
133
- this.foo = foo;
134
- }
135
- }
136
-
137
- registerSerializableClass('Foo', Foo);
138
- registerSerializableClass('Bar', Bar);
139
-
140
- let x = new Bar(new Foo(2));
141
- let res = deserialize(serialize(x));
142
- assert(res instanceof Bar);
143
- assert(res.foo instanceof Foo);
144
- assert.equal(res.foo.x, 2);
145
-
146
- unregisterSerializableClass('Foo', Foo);
147
- unregisterSerializableClass('Bar', Bar);
148
- });
149
-
150
- it('should serialize a cyclic class', () => {
151
- class Foo {
152
- x: ?Foo;
153
- constructor(x: ?Foo) {
154
- this.x = x;
155
- }
156
- }
157
-
158
- registerSerializableClass('Foo', Foo);
159
-
160
- let x = new Foo();
161
- x.x = x;
162
-
163
- let res = deserialize(serialize(x));
164
- assert(res instanceof Foo);
165
- assert(res.x instanceof Foo);
166
- assert.equal(res.x, res);
167
-
168
- assert.equal(x.x, x);
169
-
170
- unregisterSerializableClass('Foo', Foo);
171
- });
172
-
173
- it('should copy on write', () => {
174
- class Foo {
175
- x: number;
176
- constructor(x: number) {
177
- this.x = x;
178
- }
179
- }
180
-
181
- registerSerializableClass('Foo', Foo);
182
-
183
- let x = {y: {foo: new Foo(2)}};
184
-
185
- let res = deserialize(serialize(x));
186
- assert(res.y.foo instanceof Foo);
187
- assert(x.y.foo instanceof Foo);
188
-
189
- unregisterSerializableClass('Foo', Foo);
190
- });
191
-
192
- it('should serialize a cyclic class and copy on write', () => {
193
- class Foo {
194
- x: ?Foo;
195
- constructor(x: ?Foo) {
196
- this.x = x;
197
- }
198
- }
199
-
200
- registerSerializableClass('Foo', Foo);
201
-
202
- let x = new Foo();
203
- x.x = x;
204
- let y = {x: {y: x}};
205
-
206
- let res = deserialize(serialize(y));
207
- assert(res.x.y instanceof Foo);
208
- assert(res.x.y.x instanceof Foo);
209
- assert(y.x.y instanceof Foo);
210
- assert(y.x.y.x instanceof Foo);
211
- assert.equal(res.x.y.x, res.x.y);
212
-
213
- assert.equal(x.x, x);
214
-
215
- unregisterSerializableClass('Foo', Foo);
216
- });
217
-
218
- it('should serialize a class inside a Map', () => {
219
- class Test {
220
- x: number;
221
- constructor(x: number) {
222
- this.x = x;
223
- }
224
- }
225
-
226
- registerSerializableClass('Test', Test);
227
-
228
- let x = new Map([[2, new Test(2)]]);
229
- let res = deserialize(serialize(x));
230
- assert(res instanceof Map);
231
- assert(res.get(2) instanceof Test);
232
-
233
- unregisterSerializableClass('Test', Test);
234
- });
235
-
236
- it('should serialize a class inside a Set', () => {
237
- class Test {
238
- x: number;
239
- constructor(x: number) {
240
- this.x = x;
241
- }
242
- }
243
-
244
- registerSerializableClass('Test', Test);
245
-
246
- let x = new Set([new Test(2)]);
247
- let res = deserialize(serialize(x));
248
- assert(res instanceof Set);
249
- assert(res.values().next().value instanceof Test);
250
-
251
- unregisterSerializableClass('Test', Test);
252
- });
253
-
254
- describe('raw values', () => {
255
- class Outer {
256
- inner: Inner;
257
-
258
- constructor(inner) {
259
- this.inner = inner;
260
- }
261
-
262
- serialize() {
263
- return {
264
- $$raw: true,
265
- inner: this.inner,
266
- };
267
- }
268
- }
269
-
270
- class Inner {
271
- x: number;
272
-
273
- constructor(x) {
274
- this.x = x;
275
- }
276
-
277
- static deserialize = sinon.spy();
278
- }
279
-
280
- beforeEach(() => {
281
- registerSerializableClass('Outer', Outer);
282
- registerSerializableClass('Inner', Inner);
283
- });
284
-
285
- afterEach(() => {
286
- unregisterSerializableClass('Outer', Outer);
287
- unregisterSerializableClass('Inner', Inner);
288
- });
289
-
290
- it('should not recursively serialize raw values', () => {
291
- let res = deserialize(serialize(new Outer(new Inner(42))));
292
- assert(res instanceof Outer);
293
- assert(!(res.inner instanceof Inner));
294
- assert.equal(res.inner.x, 42);
295
- });
296
-
297
- it('should not recursively deserialize raw values', () => {
298
- deserialize(serialize(new Outer(new Inner(42))));
299
- assert(Inner.deserialize.notCalled);
300
- });
301
- });
302
- });