@teambit/pnpm 1.0.1321 → 1.0.1323

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.
@@ -0,0 +1,687 @@
1
+ "use strict";
2
+
3
+ function _path() {
4
+ const data = _interopRequireDefault(require("path"));
5
+ _path = function () {
6
+ return data;
7
+ };
8
+ return data;
9
+ }
10
+ function _component() {
11
+ const data = require("@teambit/component");
12
+ _component = function () {
13
+ return data;
14
+ };
15
+ return data;
16
+ }
17
+ function _objects() {
18
+ const data = require("@teambit/objects");
19
+ _objects = function () {
20
+ return data;
21
+ };
22
+ return data;
23
+ }
24
+ function _lockfileDepsGraphConverter() {
25
+ const data = require("./lockfile-deps-graph-converter");
26
+ _lockfileDepsGraphConverter = function () {
27
+ return data;
28
+ };
29
+ return data;
30
+ }
31
+ function _chai() {
32
+ const data = require("chai");
33
+ _chai = function () {
34
+ return data;
35
+ };
36
+ return data;
37
+ }
38
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
39
+ before(async () => {
40
+ await (0, _lockfileDepsGraphConverter().init)();
41
+ });
42
+ describe('workspace components in a restored lockfile', () => {
43
+ const comp1Dir = 'comps/comp1';
44
+ const comp2Dir = 'comps/comp2';
45
+ const comp2 = '@my-org/my-scope.comp2';
46
+ const comp2FilePkgId = `${comp2}@file:${comp2Dir}`;
47
+ const comp2FileDepPath = `${comp2FilePkgId}(react@18.3.1)`;
48
+
49
+ /** A workspace lockfile where comp1 depends on the injected comp2, which has a peer. */
50
+ function workspaceLockfile() {
51
+ return {
52
+ lockfileVersion: '9.0',
53
+ importers: {
54
+ [comp1Dir]: {
55
+ dependencies: {
56
+ [comp2]: {
57
+ version: `file:${comp2Dir}(react@18.3.1)`,
58
+ specifier: '2.0.0'
59
+ },
60
+ react: {
61
+ version: '18.3.1',
62
+ specifier: '18.3.1'
63
+ }
64
+ }
65
+ }
66
+ },
67
+ packages: {
68
+ [comp2FilePkgId]: {
69
+ resolution: {
70
+ directory: comp2Dir,
71
+ type: 'directory'
72
+ },
73
+ peerDependencies: {
74
+ react: '*'
75
+ }
76
+ },
77
+ 'foo@1.0.0': {
78
+ resolution: {
79
+ integrity: 'sha512-foo'
80
+ }
81
+ },
82
+ 'react@18.3.1': {
83
+ resolution: {
84
+ integrity: 'sha512-react'
85
+ }
86
+ }
87
+ },
88
+ snapshots: {
89
+ [comp2FileDepPath]: {
90
+ dependencies: {
91
+ foo: '1.0.0',
92
+ react: '18.3.1'
93
+ }
94
+ },
95
+ 'foo@1.0.0': {},
96
+ 'react@18.3.1': {}
97
+ },
98
+ bit: {
99
+ depsRequiringBuild: [comp2FilePkgId]
100
+ }
101
+ };
102
+ }
103
+ function toGraph(lockfile) {
104
+ return (0, _lockfileDepsGraphConverter().convertLockfileToGraph)(lockfile, {
105
+ componentRelativeDir: comp1Dir,
106
+ componentIdByPkgName: new Map([[comp2, _component().ComponentID.fromString('my-org.my-scope/comp2@2.0.0')]])
107
+ });
108
+ }
109
+ function toLockfile(graph, comp2Version, resolve = failingResolver) {
110
+ return (0, _lockfileDepsGraphConverter().convertGraphToLockfile)(_objects().DependenciesGraph.deserialize(graph.serialize()), {
111
+ manifests: {
112
+ [_path().default.resolve(comp1Dir)]: {
113
+ dependencies: {
114
+ [comp2]: '2.0.0',
115
+ react: '18.3.1'
116
+ }
117
+ },
118
+ [_path().default.resolve(comp2Dir)]: {
119
+ name: comp2,
120
+ version: comp2Version
121
+ }
122
+ },
123
+ rootDir: process.cwd(),
124
+ resolve
125
+ });
126
+ }
127
+ function failingResolver() {
128
+ throw new Error('a workspace component must not be resolved from the registry');
129
+ }
130
+ it('should restore the file: package and snapshot of a workspace component, peer suffix included', async () => {
131
+ const graph = toGraph(workspaceLockfile());
132
+ (0, _chai().expect)(graph.packages.has(`${comp2}@2.0.0`)).to.equal(true);
133
+ const lockfile = await toLockfile(graph, '2.0.0');
134
+ (0, _chai().expect)(lockfile.importers[comp1Dir].dependencies[comp2]).to.eql({
135
+ version: `file:${comp2Dir}(react@18.3.1)`,
136
+ specifier: '2.0.0'
137
+ });
138
+ (0, _chai().expect)(lockfile.packages[comp2FilePkgId]).to.eql({
139
+ resolution: {
140
+ directory: comp2Dir,
141
+ type: 'directory'
142
+ },
143
+ peerDependencies: {
144
+ react: '*'
145
+ }
146
+ });
147
+ (0, _chai().expect)(lockfile.packages).not.to.have.property(`${comp2}@2.0.0`);
148
+ (0, _chai().expect)(lockfile.snapshots[comp2FileDepPath]).to.eql({
149
+ dependencies: {
150
+ foo: '1.0.0',
151
+ react: '18.3.1'
152
+ }
153
+ });
154
+ (0, _chai().expect)(lockfile.snapshots).not.to.have.property(`${comp2}@2.0.0(react@18.3.1)`);
155
+ (0, _chai().expect)(lockfile.packages['foo@1.0.0']).to.eql({
156
+ resolution: {
157
+ integrity: 'sha512-foo'
158
+ }
159
+ });
160
+ (0, _chai().expect)(lockfile.bit?.depsRequiringBuild).to.eql([comp2FilePkgId]);
161
+ });
162
+ it('should keep a dependency on another version of a workspace component as a registry package', async () => {
163
+ const graph = toGraph(workspaceLockfile());
164
+ const resolved = [];
165
+ const lockfile = await toLockfile(graph, '3.0.0', async ({
166
+ alias,
167
+ bareSpecifier
168
+ }) => {
169
+ resolved.push(`${alias}@${bareSpecifier}`);
170
+ return {
171
+ resolution: {
172
+ integrity: 'sha512-comp2'
173
+ }
174
+ };
175
+ });
176
+ (0, _chai().expect)(resolved).to.eql([`${comp2}@2.0.0`]);
177
+ (0, _chai().expect)(lockfile.importers[comp1Dir].dependencies[comp2]).to.eql({
178
+ version: '2.0.0(react@18.3.1)',
179
+ specifier: '2.0.0'
180
+ });
181
+ (0, _chai().expect)(lockfile.packages[`${comp2}@2.0.0`]).to.eql({
182
+ resolution: {
183
+ integrity: 'sha512-comp2'
184
+ },
185
+ peerDependencies: {
186
+ react: '*'
187
+ }
188
+ });
189
+ (0, _chai().expect)(lockfile.packages).not.to.have.property(comp2FilePkgId);
190
+ });
191
+ });
192
+ describe('importer entries of a restored lockfile', () => {
193
+ const comp1Dir = 'comps/comp1';
194
+ const apolloVariant = '@apollo/client@3.3.21(graphql@15.8.0)';
195
+ const graph = new (_objects().DependenciesGraph)({
196
+ packages: new Map([['@babel/runtime@7.20.0', {
197
+ resolution: {
198
+ integrity: 'sha512-runtime'
199
+ }
200
+ }], ['@teambit/ui.app@0.0.110', {
201
+ resolution: {
202
+ integrity: 'sha512-app'
203
+ }
204
+ }], ['@apollo/client@3.3.21', {
205
+ resolution: {
206
+ integrity: 'sha512-apollo'
207
+ },
208
+ peerDependencies: {
209
+ graphql: '*'
210
+ }
211
+ }], ['graphql@15.8.0', {
212
+ resolution: {
213
+ integrity: 'sha512-graphql'
214
+ }
215
+ }], ['graphql@16.0.0', {
216
+ resolution: {
217
+ integrity: 'sha512-graphql16'
218
+ }
219
+ }], ['lonely@1.0.0', {
220
+ resolution: {
221
+ integrity: 'sha512-lonely'
222
+ }
223
+ }]]),
224
+ edges: [{
225
+ id: _objects().DependenciesGraph.ROOT_EDGE_ID,
226
+ neighbours: [{
227
+ id: '@babel/runtime@7.20.0',
228
+ name: '@babel/runtime',
229
+ specifier: '*',
230
+ lifecycle: 'runtime'
231
+ }, {
232
+ id: `@teambit/ui.app@0.0.110(${apolloVariant})`,
233
+ name: '@teambit/ui.app',
234
+ specifier: '0.0.110',
235
+ lifecycle: 'runtime'
236
+ }]
237
+ }, {
238
+ id: `@teambit/ui.app@0.0.110(${apolloVariant})`,
239
+ attr: {
240
+ pkgId: '@teambit/ui.app@0.0.110'
241
+ },
242
+ neighbours: [{
243
+ id: apolloVariant
244
+ }]
245
+ }, {
246
+ id: apolloVariant,
247
+ attr: {
248
+ pkgId: '@apollo/client@3.3.21'
249
+ },
250
+ neighbours: [{
251
+ id: 'graphql@15.8.0'
252
+ }]
253
+ }, {
254
+ id: '@apollo/client@3.3.21(graphql@16.0.0)',
255
+ attr: {
256
+ pkgId: '@apollo/client@3.3.21'
257
+ },
258
+ neighbours: [{
259
+ id: 'graphql@16.0.0'
260
+ }]
261
+ }]
262
+ });
263
+ function restore(dependencies) {
264
+ return (0, _lockfileDepsGraphConverter().convertGraphToLockfile)(_objects().DependenciesGraph.deserialize(graph.serialize()), {
265
+ manifests: {
266
+ [_path().default.resolve(comp1Dir)]: {
267
+ dependencies
268
+ }
269
+ },
270
+ rootDir: process.cwd(),
271
+ resolve: () => {
272
+ throw new Error('nothing here needs the registry');
273
+ }
274
+ });
275
+ }
276
+ it('matches a range specifier against the version the graph resolved', async () => {
277
+ const lockfile = await restore({
278
+ '@babel/runtime': '^7.8.4'
279
+ });
280
+ (0, _chai().expect)(lockfile.importers[comp1Dir].dependencies['@babel/runtime']).to.eql({
281
+ version: '7.20.0',
282
+ specifier: '^7.8.4'
283
+ });
284
+ });
285
+ it('leaves a range specifier the resolved version does not satisfy without an entry', async () => {
286
+ const lockfile = await restore({
287
+ '@babel/runtime': '^8.0.0'
288
+ });
289
+ (0, _chai().expect)(lockfile.importers[comp1Dir].dependencies).not.to.have.property('@babel/runtime');
290
+ });
291
+ it('points a version the graph holds only deeper in the tree at the variant the direct dependencies use', async () => {
292
+ const lockfile = await restore({
293
+ '@apollo/client': '3.3.21',
294
+ '@teambit/ui.app': '0.0.110'
295
+ });
296
+ (0, _chai().expect)(lockfile.importers[comp1Dir].dependencies['@apollo/client']).to.eql({
297
+ version: '3.3.21(graphql@15.8.0)',
298
+ specifier: '3.3.21'
299
+ });
300
+ (0, _chai().expect)(lockfile.snapshots[apolloVariant]).to.eql({
301
+ dependencies: {
302
+ graphql: '15.8.0'
303
+ }
304
+ });
305
+ });
306
+ it('points a version the graph holds only as a package at that package', async () => {
307
+ const lockfile = await restore({
308
+ lonely: '1.0.0'
309
+ });
310
+ (0, _chai().expect)(lockfile.importers[comp1Dir].dependencies.lonely).to.eql({
311
+ version: '1.0.0',
312
+ specifier: '1.0.0'
313
+ });
314
+ (0, _chai().expect)(lockfile.snapshots['lonely@1.0.0']).to.eql({});
315
+ });
316
+ it('leaves a version the graph does not hold without an entry', async () => {
317
+ const lockfile = await restore({
318
+ '@apollo/client': '3.3.7'
319
+ });
320
+ (0, _chai().expect)(lockfile.importers[comp1Dir].dependencies).not.to.have.property('@apollo/client');
321
+ });
322
+ });
323
+ describe('resolving a workspace-component package from the registry on restore', () => {
324
+ const comp1Dir = 'comps/comp1';
325
+ const pkgId = '@my-org/my-scope.comp2@1.0.0';
326
+ function restore(resolve) {
327
+ const graph = new (_objects().DependenciesGraph)({
328
+ packages: new Map([[pkgId, {
329
+ component: {
330
+ scope: 'my-org.my-scope',
331
+ name: 'comp2'
332
+ }
333
+ }]]),
334
+ edges: [{
335
+ id: _objects().DependenciesGraph.ROOT_EDGE_ID,
336
+ neighbours: [{
337
+ id: pkgId,
338
+ name: '@my-org/my-scope.comp2',
339
+ specifier: '1.0.0',
340
+ lifecycle: 'runtime'
341
+ }]
342
+ }, {
343
+ id: pkgId,
344
+ neighbours: []
345
+ }]
346
+ });
347
+ return (0, _lockfileDepsGraphConverter().convertGraphToLockfile)(graph, {
348
+ manifests: {
349
+ [_path().default.resolve(comp1Dir)]: {
350
+ dependencies: {
351
+ '@my-org/my-scope.comp2': '1.0.0'
352
+ }
353
+ }
354
+ },
355
+ rootDir: process.cwd(),
356
+ resolve
357
+ });
358
+ }
359
+
360
+ // `@pnpm/napi`'s resolveDependency reports a registry package's integrity in
361
+ // the manifest's `dist`, and no `resolution` at all.
362
+ it("takes the integrity from the resolved manifest's dist when the resolver reports no resolution", async () => {
363
+ const lockfile = await restore(() => ({
364
+ manifest: {
365
+ dist: {
366
+ integrity: 'sha512-fromdist'
367
+ }
368
+ }
369
+ }));
370
+ (0, _chai().expect)(lockfile.packages[pkgId]).to.eql({
371
+ resolution: {
372
+ integrity: 'sha512-fromdist'
373
+ }
374
+ });
375
+ (0, _chai().expect)(lockfile.importers[comp1Dir].dependencies['@my-org/my-scope.comp2']).to.eql({
376
+ version: '1.0.0',
377
+ specifier: '1.0.0'
378
+ });
379
+ });
380
+ it('prefers the integrity of a resolution the resolver reports', async () => {
381
+ const lockfile = await restore(() => ({
382
+ resolution: {
383
+ integrity: 'sha512-fromresolution'
384
+ },
385
+ manifest: {
386
+ dist: {
387
+ integrity: 'sha512-fromdist'
388
+ }
389
+ }
390
+ }));
391
+ (0, _chai().expect)(lockfile.packages[pkgId]).to.eql({
392
+ resolution: {
393
+ integrity: 'sha512-fromresolution'
394
+ }
395
+ });
396
+ });
397
+ });
398
+ describe('optional flags of a restored lockfile', () => {
399
+ const comp1Dir = 'comps/comp1';
400
+ it('marks the entries only optional edges reach, and leaves one a required path reaches alone', async () => {
401
+ const graph = new (_objects().DependenciesGraph)({
402
+ packages: new Map(['ssh2@1.0.0', 'cpu-features@0.0.10', 'nan@2.29.0', 'fsevents@2.3.3'].map(id => [id, {
403
+ resolution: {
404
+ integrity: `sha512-${id}`
405
+ }
406
+ }])),
407
+ edges: [{
408
+ id: _objects().DependenciesGraph.ROOT_EDGE_ID,
409
+ neighbours: [{
410
+ id: 'ssh2@1.0.0',
411
+ name: 'ssh2',
412
+ specifier: '1.0.0',
413
+ lifecycle: 'runtime'
414
+ }, {
415
+ id: 'nan@2.29.0',
416
+ name: 'nan',
417
+ specifier: '2.29.0',
418
+ lifecycle: 'runtime'
419
+ }, {
420
+ id: 'fsevents@2.3.3',
421
+ name: 'fsevents',
422
+ specifier: '2.3.3',
423
+ lifecycle: 'runtime',
424
+ optional: true
425
+ }]
426
+ }, {
427
+ id: 'ssh2@1.0.0',
428
+ neighbours: [{
429
+ id: 'cpu-features@0.0.10',
430
+ optional: true
431
+ }]
432
+ }, {
433
+ id: 'cpu-features@0.0.10',
434
+ neighbours: [{
435
+ id: 'nan@2.29.0'
436
+ }]
437
+ }]
438
+ });
439
+ const lockfile = await (0, _lockfileDepsGraphConverter().convertGraphToLockfile)(graph, {
440
+ manifests: {
441
+ [_path().default.resolve(comp1Dir)]: {
442
+ dependencies: {
443
+ ssh2: '1.0.0',
444
+ nan: '2.29.0'
445
+ },
446
+ optionalDependencies: {
447
+ fsevents: '2.3.3'
448
+ }
449
+ }
450
+ },
451
+ rootDir: process.cwd(),
452
+ resolve: () => {
453
+ throw new Error('nothing here needs the registry');
454
+ }
455
+ });
456
+ (0, _chai().expect)(lockfile.snapshots['cpu-features@0.0.10'].optional).to.equal(true);
457
+ (0, _chai().expect)(lockfile.snapshots['fsevents@2.3.3'].optional).to.equal(true);
458
+ (0, _chai().expect)(lockfile.snapshots['ssh2@1.0.0']).not.to.have.property('optional');
459
+ // nan is reached optionally through cpu-features and directly as well.
460
+ (0, _chai().expect)(lockfile.snapshots['nan@2.29.0']).not.to.have.property('optional');
461
+ });
462
+ });
463
+ describe('workspace: specifiers in a restored lockfile', () => {
464
+ const comp1Dir = 'comps/comp1';
465
+ const comp2Dir = 'comps/comp2';
466
+ const comp2 = '@my-org/my-scope.comp2';
467
+ // A merged graph can hold the sibling at two versions as direct dependencies.
468
+ const graph = new (_objects().DependenciesGraph)({
469
+ packages: new Map([[`${comp2}@1.0.0`, {
470
+ resolution: {
471
+ integrity: 'sha512-one'
472
+ }
473
+ }], [`${comp2}@2.0.0`, {
474
+ resolution: {
475
+ integrity: 'sha512-two'
476
+ }
477
+ }]]),
478
+ edges: [{
479
+ id: _objects().DependenciesGraph.ROOT_EDGE_ID,
480
+ neighbours: [{
481
+ id: `${comp2}@1.0.0`,
482
+ name: comp2,
483
+ specifier: '1.0.0',
484
+ lifecycle: 'runtime'
485
+ }, {
486
+ id: `${comp2}@2.0.0`,
487
+ name: comp2,
488
+ specifier: '2.0.0',
489
+ lifecycle: 'runtime'
490
+ }]
491
+ }]
492
+ });
493
+ function restore(specifier, comp2Version) {
494
+ return (0, _lockfileDepsGraphConverter().convertGraphToLockfile)(_objects().DependenciesGraph.deserialize(graph.serialize()), {
495
+ manifests: {
496
+ [_path().default.resolve(comp1Dir)]: {
497
+ dependencies: {
498
+ [comp2]: specifier
499
+ }
500
+ },
501
+ [_path().default.resolve(comp2Dir)]: {
502
+ name: comp2,
503
+ version: comp2Version
504
+ }
505
+ },
506
+ rootDir: process.cwd(),
507
+ resolve: () => ({
508
+ resolution: {
509
+ integrity: 'sha512-other'
510
+ }
511
+ })
512
+ });
513
+ }
514
+ it('points at the version the workspace holds, not the first same-name neighbour', async () => {
515
+ const lockfile = await restore('workspace:^2', '2.0.0');
516
+ (0, _chai().expect)(lockfile.importers[comp1Dir].dependencies[comp2]).to.eql({
517
+ version: `file:${comp2Dir}`,
518
+ specifier: 'workspace:^2'
519
+ });
520
+ });
521
+ it('leaves the entry out when the range rejects the version the workspace holds', async () => {
522
+ const lockfile = await restore('workspace:^3', '2.0.0');
523
+ (0, _chai().expect)(lockfile.importers[comp1Dir].dependencies).not.to.have.property(comp2);
524
+ });
525
+ it('leaves the entry out when the graph lacks the version the workspace holds', async () => {
526
+ const lockfile = await restore('workspace:*', '3.0.0');
527
+ (0, _chai().expect)(lockfile.importers[comp1Dir].dependencies).not.to.have.property(comp2);
528
+ });
529
+ });
530
+ describe('several direct dependencies of the same name in a restored lockfile', () => {
531
+ const comp1Dir = 'comps/comp1';
532
+ // A merged graph keeps one root neighbour per distinct specifier of foo.
533
+ const graph = new (_objects().DependenciesGraph)({
534
+ packages: new Map([['foo@1.5.0', {
535
+ resolution: {
536
+ integrity: 'sha512-five'
537
+ }
538
+ }], ['foo@1.2.0', {
539
+ resolution: {
540
+ integrity: 'sha512-two'
541
+ }
542
+ }], ['foo@1.9.0', {
543
+ resolution: {
544
+ integrity: 'sha512-nine'
545
+ }
546
+ }]]),
547
+ edges: [{
548
+ id: _objects().DependenciesGraph.ROOT_EDGE_ID,
549
+ neighbours: [{
550
+ id: 'foo@1.5.0',
551
+ name: 'foo',
552
+ specifier: '^1.5.0',
553
+ lifecycle: 'runtime'
554
+ }, {
555
+ id: 'foo@1.2.0',
556
+ name: 'foo',
557
+ specifier: '^1.0.0',
558
+ lifecycle: 'runtime'
559
+ }, {
560
+ id: 'foo@1.9.0',
561
+ name: 'foo',
562
+ specifier: '*',
563
+ lifecycle: 'runtime'
564
+ }]
565
+ }]
566
+ });
567
+ function restore(specifier) {
568
+ return (0, _lockfileDepsGraphConverter().convertGraphToLockfile)(_objects().DependenciesGraph.deserialize(graph.serialize()), {
569
+ manifests: {
570
+ [_path().default.resolve(comp1Dir)]: {
571
+ dependencies: {
572
+ foo: specifier
573
+ }
574
+ }
575
+ },
576
+ rootDir: process.cwd(),
577
+ resolve: () => {
578
+ throw new Error('nothing here needs the registry');
579
+ }
580
+ });
581
+ }
582
+ it('takes the dependency recorded for the very specifier over one that merely satisfies it', async () => {
583
+ const lockfile = await restore('^1.0.0');
584
+ (0, _chai().expect)(lockfile.importers[comp1Dir].dependencies.foo).to.eql({
585
+ version: '1.2.0',
586
+ specifier: '^1.0.0'
587
+ });
588
+ });
589
+ it('takes the dependency recorded at the very version', async () => {
590
+ const lockfile = await restore('1.5.0');
591
+ (0, _chai().expect)(lockfile.importers[comp1Dir].dependencies.foo).to.eql({
592
+ version: '1.5.0',
593
+ specifier: '1.5.0'
594
+ });
595
+ });
596
+ it('takes the highest satisfying resolution when none was recorded for the specifier', async () => {
597
+ const lockfile = await restore('^1.1.0');
598
+ (0, _chai().expect)(lockfile.importers[comp1Dir].dependencies.foo).to.eql({
599
+ version: '1.9.0',
600
+ specifier: '^1.1.0'
601
+ });
602
+ });
603
+ });
604
+ describe('entries no importer reaches in a restored lockfile', () => {
605
+ it('are dropped before anything is resolved from the registry', async () => {
606
+ const graph = new (_objects().DependenciesGraph)({
607
+ packages: new Map([['foo@1.0.0', {
608
+ resolution: {
609
+ integrity: 'sha512-foo'
610
+ }
611
+ }],
612
+ // An attached extension's dev dependency: no resolution, and nothing reaches it.
613
+ ['@org/dev-only@1.0.0', {
614
+ component: {
615
+ scope: 'org',
616
+ name: 'dev-only'
617
+ }
618
+ }]]),
619
+ edges: [{
620
+ id: _objects().DependenciesGraph.ROOT_EDGE_ID,
621
+ neighbours: [{
622
+ id: 'foo@1.0.0',
623
+ name: 'foo',
624
+ specifier: '1.0.0',
625
+ lifecycle: 'runtime'
626
+ }]
627
+ }]
628
+ });
629
+ const lockfile = await (0, _lockfileDepsGraphConverter().convertGraphToLockfile)(graph, {
630
+ manifests: {
631
+ [_path().default.resolve('comps/comp1')]: {
632
+ dependencies: {
633
+ foo: '1.0.0'
634
+ }
635
+ }
636
+ },
637
+ rootDir: process.cwd(),
638
+ resolve: () => {
639
+ throw new Error('an unreachable entry must not be resolved');
640
+ }
641
+ });
642
+ (0, _chai().expect)(Object.keys(lockfile.packages)).to.eql(['foo@1.0.0']);
643
+ });
644
+ });
645
+ describe('optional flags under an aliased dependency', () => {
646
+ it('walks into the package an alias names', () => {
647
+ const lockfile = {
648
+ importers: {
649
+ 'comps/comp1': {
650
+ dependencies: {
651
+ foo: {
652
+ version: 'real-foo@1.0.0',
653
+ specifier: 'npm:real-foo@1.0.0'
654
+ }
655
+ },
656
+ optionalDependencies: {
657
+ bar: {
658
+ version: '1.0.0',
659
+ specifier: '1.0.0'
660
+ }
661
+ }
662
+ }
663
+ },
664
+ snapshots: {
665
+ 'real-foo@1.0.0': {
666
+ optionalDependencies: {
667
+ qar: '1.0.0'
668
+ },
669
+ dependencies: {
670
+ bar: '1.0.0'
671
+ }
672
+ },
673
+ 'bar@1.0.0': {
674
+ optional: true
675
+ },
676
+ 'qar@1.0.0': {}
677
+ }
678
+ };
679
+ (0, _lockfileDepsGraphConverter().markOptionalOnlyEntries)(lockfile);
680
+ (0, _chai().expect)(lockfile.snapshots['real-foo@1.0.0']).not.to.have.property('optional');
681
+ // Reached optionally from the importer, but required through the alias.
682
+ (0, _chai().expect)(lockfile.snapshots['bar@1.0.0']).not.to.have.property('optional');
683
+ (0, _chai().expect)(lockfile.snapshots['qar@1.0.0']).to.have.property('optional', true);
684
+ });
685
+ });
686
+
687
+ //# sourceMappingURL=lockfile-deps-graph-converter.restore.spec.js.map