-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
integration.js
1276 lines (1048 loc) · 58.8 KB
/
integration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* @flow */
import Config from '../../../src/config';
import PackageResolver from '../../../src/package-resolver.js';
import {run as add} from '../../../src/cli/commands/add.js';
import {run as cache} from '../../../src/cli/commands/cache.js';
import {run as check} from '../../../src/cli/commands/check.js';
import * as constants from '../../../src/constants.js';
import * as reporters from '../../../src/reporters/index.js';
import {Install, run as install} from '../../../src/cli/commands/install.js';
import Lockfile from '../../../src/lockfile';
import * as fs from '../../../src/util/fs.js';
import * as misc from '../../../src/util/misc.js';
import {getPackageVersion, explodeLockfile, runInstall, runLink, createLockfile, run as buildRun} from '../_helpers.js';
jasmine.DEFAULT_TIMEOUT_INTERVAL = 150000;
let request = require('request');
const path = require('path');
const stream = require('stream');
async function mockConstants(base: Config, mocks: Object, cb: (config: Config) => Promise<void>): Promise<void> {
// We cannot put this function inside _helpers, because we need to change the "request" variable
// after resetting the modules. Updating this variable is required because some tests check what
// happened during the Yarn execution, and they need to use the same instance of "request" than
// the Yarn environment.
const opts = {};
opts.binLinks = base.binLinks;
opts.cwd = base.cwd;
opts.globalFolder = base.globalFolder;
opts.linkFolder = base.linkFolder;
opts.production = base.production;
opts.cacheFolder = base._cacheRootFolder;
const automock = jest.genMockFromModule('../../../src/constants');
jest.setMock('../../../src/constants', Object.assign(automock, mocks));
jest.resetModules();
request = require('request');
jest.mock('../../../src/constants');
await cb(await require('../../../src/config.js').default.create(opts, base.reporter));
jest.unmock('../../../src/constants');
}
beforeEach(request.__resetAuthedRequests);
afterEach(request.__resetAuthedRequests);
test('install should not copy the .bin folders from the cache', () =>
runInstall({}, 'install-no-bin', async config => {
expect(await fs.exists(`${config.cwd}/node_modules/is-pnp/.bin`)).toEqual(false);
}));
test('install should not hoist packages above their peer dependencies', () =>
runInstall({}, 'install-should-not-hoist-through-peer-deps', async config => {
expect(await fs.exists(`${config.cwd}/node_modules/a/node_modules/c`)).toEqual(true);
}));
test('install should resolve peer dependencies from same subtrees', () =>
runInstall({}, 'peer-dep-same-subtree', async config => {
expect(JSON.parse(await fs.readFile(`${config.cwd}/node_modules/d/node_modules/a/package.json`)).version).toEqual(
'1.0.0',
);
expect(JSON.parse(await fs.readFile(`${config.cwd}/node_modules//a/package.json`)).version).toEqual('1.1.0');
expect(fs.exists(`${config.cwd}/node_modules/c/node_modules/a`)).resolves.toEqual(false);
}));
test('install optional subdependencies by default', () =>
runInstall({}, 'install-optional-dependencies', config => {
expect(fs.exists(`${config.cwd}/node_modules/dep-b`)).resolves.toEqual(true);
}));
test('installing with --ignore-optional should not install optional subdependencies', () =>
runInstall({ignoreOptional: true}, 'install-optional-dependencies', config => {
expect(fs.exists(`${config.cwd}/node_modules/dep-b`)).resolves.toEqual(false);
expect(fs.exists(`${config.cwd}/node_modules/dep-c`)).resolves.toEqual(true);
expect(fs.exists(`${config.cwd}/node_modules/dep-d`)).resolves.toEqual(true);
expect(fs.exists(`${config.cwd}/node_modules/dep-e`)).resolves.toEqual(true);
}));
test('running install inside a workspace should run the install from the root of the workspace', () =>
runInstall({}, 'install-workspaces', async (config, reporter): Promise<void> => {
const pkgJson = await fs.readJson(`${config.cwd}/workspace/package.json`);
pkgJson.dependencies['b'] = 'file:../b';
await fs.writeFile(`${config.cwd}/workspace/package.json`, JSON.stringify(pkgJson));
const workspaceConfig = await Config.create({cwd: `${config.cwd}/workspace`}, reporter);
const reInstall = new Install({}, workspaceConfig, reporter, await Lockfile.fromDirectory(config.cwd));
await reInstall.init();
const lockfileContent = await fs.readFile(`${config.cwd}/yarn.lock`);
expect(lockfileContent).toEqual(expect.stringContaining(`"b@file:b"`));
expect(lockfileContent).toEqual(expect.stringContaining(`"a@file:./a"`));
}));
test('packages installed through the link protocol should validate all peer dependencies', () =>
runInstall({checkFiles: true}, 'check-files-should-not-cross-symlinks', async config => {
expect(
JSON.parse(await fs.readFile(`${config.cwd}/node_modules/.yarn-integrity`)).files.map(file =>
file.replace(/\\/g, '/'),
),
).toEqual(['some-missing-pkg', 'some-other-pkg', 'some-pkg/package.json']);
}));
test('installing a package with a renamed file should not delete it', () =>
runInstall({}, 'case-sensitivity', async (config, reporter): Promise<void> => {
const pkgJson = await fs.readJson(`${config.cwd}/package.json`);
pkgJson.dependencies['pkg'] = 'file:./pkg-b';
await fs.writeFile(`${config.cwd}/package.json`, JSON.stringify(pkgJson));
const reInstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await reInstall.init();
expect(await fs.exists(`${config.cwd}/node_modules/pkg/state.js`)).toEqual(true);
}));
test("installing a tree shouldn't remove preexisting cache directories", () =>
runInstall({}, 'cache-folder-nm', async (config, reporter): Promise<void> => {
expect(await fs.exists(`${config.cwd}/node_modules/.cache/hello.txt`)).toEqual(true);
const reInstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await reInstall.init();
expect(await fs.exists(`${config.cwd}/node_modules/.cache/hello.txt`)).toEqual(true);
}));
test("installing a new package should correctly update it, even if the files mtime didn't change", () =>
runInstall({}, 'mtime-same', async (config, reporter): Promise<void> => {
await misc.sleep(2000);
const pkgJson = await fs.readJson(`${config.cwd}/package.json`);
pkgJson.dependencies['pkg'] = 'file:./pkg-b.tgz';
await fs.writeFile(`${config.cwd}/package.json`, JSON.stringify(pkgJson));
const reInstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await reInstall.init();
expect(await fs.readJson(`${config.cwd}/node_modules/pkg/package.json`)).toMatchObject({version: '2.0.0'});
}));
test('properly find and save build artifacts', () =>
runInstall({}, 'artifacts-finds-and-saves', async config => {
const integrity = await fs.readJson(path.join(config.cwd, 'node_modules', constants.INTEGRITY_FILENAME));
expect(integrity.artifacts['[email protected]']).toEqual(['dummy', path.join('dummy', 'dummy.txt'), 'dummy.txt']);
// retains artifact
const moduleFolder = path.join(config.cwd, 'node_modules', 'dummy');
expect(fs.readFile(path.join(moduleFolder, 'dummy.txt'))).resolves.toEqual('foobar');
expect(fs.readFile(path.join(moduleFolder, 'dummy', 'dummy.txt'))).resolves.toEqual('foobar');
}));
test('reading a lockfile should not optimize it', () =>
runInstall({}, 'lockfile-optimization', async (config, reporter): Promise<void> => {
const was = await fs.readFile(`${__dirname}/../../fixtures/install/lockfile-optimization/yarn.lock`);
const is = await fs.readFile(`${config.cwd}/yarn.lock`);
expect(is).toEqual(was);
}));
test('creates a symlink to a directory when using the link: protocol', () =>
runInstall({}, 'install-link', async config => {
const expectPath = path.join(config.cwd, 'node_modules', 'test-absolute');
const stat = await fs.lstat(expectPath);
expect(stat.isSymbolicLink()).toEqual(true);
const target = await fs.readlink(expectPath);
expect(path.resolve(config.cwd, target)).toMatch(/[\\\/]bar$/);
}));
test('creates a symlink to a non-existing directory when using the link: protocol', () =>
runInstall({}, 'install-link', async config => {
const expectPath = path.join(config.cwd, 'node_modules', 'test-missing');
const stat = await fs.lstat(expectPath);
expect(stat.isSymbolicLink()).toEqual(true);
const target = await fs.readlink(expectPath);
if (process.platform !== 'win32') {
expect(target).toEqual('../baz');
} else {
expect(target).toMatch(/[\\\/]baz[\\\/]$/);
}
}));
test('resolves the symlinks relative to the package path when using the link: protocol; not the node_modules', () =>
runInstall({}, 'install-link', async config => {
const expectPath = path.join(config.cwd, 'node_modules', 'test-relative');
const stat = await fs.lstat(expectPath);
expect(stat.isSymbolicLink()).toEqual(true);
const target = await fs.readlink(expectPath);
if (process.platform !== 'win32') {
expect(target).toEqual('../bar');
} else {
expect(target).toMatch(/[\\\/]bar[\\\/]$/);
}
}));
test('resolves the symlinks of other symlinked packages relative to the package using the link: protocol', () =>
runInstall({}, 'install-link-nested', async config => {
const expectPath = path.join(config.cwd, 'node_modules', 'b');
const stat = await fs.lstat(expectPath);
expect(stat.isSymbolicLink()).toEqual(true);
const target = await fs.readlink(expectPath);
if (process.platform !== 'win32') {
expect(target).toEqual('../a/b');
} else {
expect(target).toMatch(/[\\\/]b[\\\/]$/);
}
}));
test('replace the symlink when it changes, when using the link: protocol', () =>
runInstall({}, 'install-link', async (config, reporter): Promise<void> => {
const lockfile = await Lockfile.fromDirectory(config.cwd);
const pkgJson = await fs.readJson(`${config.cwd}/package.json`);
pkgJson.dependencies['test-missing'] = 'link:barbaz';
await fs.writeFile(`${config.cwd}/package.json`, JSON.stringify(pkgJson));
const reInstall = new Install({}, config, reporter, lockfile);
await reInstall.init();
const expectPath = path.join(config.cwd, 'node_modules', 'test-missing');
const stat = await fs.lstat(expectPath);
expect(stat.isSymbolicLink()).toEqual(true);
const target = await fs.readlink(expectPath);
if (process.platform !== 'win32') {
expect(target).toEqual('../barbaz');
} else {
expect(target).toMatch(/[\\\/]barbaz[\\\/]$/);
}
}));
test('changes the cache path when bumping the cache version', () =>
runInstall({}, 'install-github', async config => {
const inOut = new stream.PassThrough();
const reporter = new reporters.JSONReporter({stdout: inOut});
await cache(config, reporter, {}, ['dir']);
expect((JSON.parse(String(inOut.read())): any).data).toMatch(/[\\\/]v(?!42[\\\/]?$)[0-9]+[\\\/]?$/);
await mockConstants(config, {CACHE_VERSION: 42}, async config => {
await cache(config, reporter, {}, ['dir']);
expect((JSON.parse(String(inOut.read())): any).data).toMatch(/[\\\/]v42([\\\/].*)?$/);
});
}));
test('changes the cache directory when bumping the cache version', () =>
runInstall({}, 'install-production', async (config, reporter): Promise<void> => {
const lockfile = await Lockfile.fromDirectory(config.cwd);
const resolver = new PackageResolver(config, lockfile);
await resolver.init([{pattern: 'is-array', registry: 'npm'}]);
const ref = resolver.getManifests()[0]._reference;
const cachePath = config.generateModuleCachePath(ref);
await fs.writeFile(path.join(cachePath, 'yarn.test'), 'YARN TEST');
await fs.unlink(path.join(config.cwd, 'node_modules'));
const firstReinstall = new Install({skipIntegrityCheck: true}, config, reporter, lockfile);
await firstReinstall.init();
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'is-array', 'yarn.test'))).toEqual(true);
await mockConstants(config, {CACHE_VERSION: 42}, async config => {
const secondReinstall = new Install({skipIntegrityCheck: true}, config, reporter, lockfile);
await secondReinstall.init();
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'is-array', 'yarn.test'))).toEqual(false);
});
}));
test("removes extraneous files that aren't in module or artifacts", () => {
async function check(cwd: string): Promise<void> {
// retains artifact
const moduleFolder = path.join(cwd, 'node_modules', 'dummy');
expect(await fs.readFile(path.join(moduleFolder, 'dummy.txt'))).toEqual('foobar');
expect(await fs.readFile(path.join(moduleFolder, 'dummy', 'dummy.txt'))).toEqual('foobar');
// removes extraneous
expect(await fs.exists(path.join(moduleFolder, 'dummy2.txt'))).toEqual(false);
}
async function create(cwd: string): Promise<void> {
// create an extraneous file
const moduleFolder = path.join(cwd, 'node_modules', 'dummy');
await fs.mkdirp(moduleFolder);
await fs.writeFile(path.join(moduleFolder, 'dummy2.txt'), 'foobar');
}
return runInstall(
{},
'artifacts-finds-and-saves',
async config => {
await check(config.cwd);
await create(config.cwd);
// run install again
const install = new Install({force: true}, config, config.reporter, new Lockfile());
await install.init();
await check(config.cwd);
},
create,
);
});
test("production mode with deduped dev dep shouldn't be removed", () =>
runInstall({production: true}, 'install-prod-deduped-dev-dep', async config => {
expect((await fs.readJson(path.join(config.cwd, 'node_modules', 'a', 'package.json'))).version).toEqual('1.0.0');
expect((await fs.readJson(path.join(config.cwd, 'node_modules', 'c', 'package.json'))).version).toEqual('1.0.0');
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'b'))).toEqual(false);
}));
test("production mode dep on package in dev deps shouldn't be removed", () =>
runInstall({production: true}, 'install-prod-deduped-direct-dev-dep', async config => {
expect((await fs.readJson(path.join(config.cwd, 'node_modules', 'a', 'package.json'))).version).toEqual('1.0.0');
expect((await fs.readJson(path.join(config.cwd, 'node_modules', 'b', 'package.json'))).version).toEqual('1.0.0');
expect((await fs.readJson(path.join(config.cwd, 'node_modules', 'c', 'package.json'))).version).toEqual('1.0.0');
}));
test('hoisting should factor ignored dependencies', async () => {
// you should only modify this test if you know what you're doing
// when we calculate hoisting we need to factor in ignored dependencies in it
// so we get deterministic hoisting across environments, for example in production mode
// we should still be taking dev dependencies into consideration
async function checkNormal(config): Promise<void> {
expect((await fs.readJson(path.join(config.cwd, 'node_modules', 'a', 'package.json'))).version).toEqual('1.0.0');
expect((await fs.readJson(path.join(config.cwd, 'node_modules', 'd', 'package.json'))).version).toEqual('1.0.0');
expect(
(await fs.readJson(path.join(config.cwd, 'node_modules', 'd', 'node_modules', 'c', 'package.json'))).version,
).toEqual('2.0.0');
}
await runInstall({}, 'install-ignored-retains-hoisting-structure', async config => {
await checkNormal(config);
expect((await fs.readJson(path.join(config.cwd, 'node_modules', 'b', 'package.json'))).version).toEqual('3.0.0');
expect((await fs.readJson(path.join(config.cwd, 'node_modules', 'c', 'package.json'))).version).toEqual('5.0.0');
});
await runInstall({production: true}, 'install-ignored-retains-hoisting-structure', async config => {
await checkNormal(config);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'b'))).toEqual(false);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'c'))).toEqual(false);
});
});
test('--production flag ignores dev dependencies', () =>
runInstall({production: true}, 'install-production', async config => {
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'left-pad'))).toEqual(false);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'is-array'))).toEqual(true);
}));
test('--production flag does not link dev dependency bin scripts', () =>
runInstall({production: true, binLinks: true}, 'install-production-bin', async config => {
expect(await fs.exists(path.join(config.cwd, 'node_modules', '.bin', 'touch'))).toEqual(false);
expect(await fs.exists(path.join(config.cwd, 'node_modules', '.bin', 'rimraf'))).toEqual(true);
}));
test('root install with optional deps', () => runInstall({}, 'root-install-with-optional-dependency'));
test('install file: protocol with relative paths', () =>
runInstall({}, 'install-file-relative', async config => {
expect(await fs.readFile(path.join(config.cwd, 'node_modules', 'root-a', 'index.js'))).toEqual('foobar;\n');
}));
test('install file: protocol without force retains installed package', () =>
runInstall({}, 'install-file-without-cache', async (config, reporter) => {
expect(await fs.readFile(path.join(config.cwd, 'node_modules', 'comp', 'index.js'))).toEqual('foo\n');
await fs.writeFile(path.join(config.cwd, 'comp', 'index.js'), 'bar\n');
const reinstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await reinstall.init();
expect(await fs.readFile(path.join(config.cwd, 'node_modules', 'comp', 'index.js'))).not.toEqual('bar\n');
}));
test('install file: protocol with force re-installs local package', () =>
runInstall({}, 'install-file-without-cache', async (config, reporter) => {
expect(await fs.readFile(path.join(config.cwd, 'node_modules', 'comp', 'index.js'))).toEqual('foo\n');
await fs.writeFile(path.join(config.cwd, 'comp', 'index.js'), 'bar\n');
const reinstall = new Install({force: true}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await reinstall.init();
expect(await fs.readFile(path.join(config.cwd, 'node_modules', 'comp', 'index.js'))).toEqual('bar\n');
}));
test('install file: local packages with local dependencies', () =>
runInstall({}, 'install-file-local-dependency', async (config, reporter) => {
const reinstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await reinstall.init();
expect(await fs.readFile(path.join(config.cwd, 'node_modules', 'a', 'index.js'))).toEqual('foo;\n');
expect(await fs.readFile(path.join(config.cwd, 'node_modules', 'b', 'index.js'))).toEqual('bar;\n');
}));
test('install file: install without manifest of dependency', () =>
runInstall({}, 'install-file-without-manifest', async config => {
expect(await fs.readFile(path.join(config.cwd, 'node_modules', 'foo', 'index.js'))).toEqual('bar\n');
}));
test('install file: link file dependencies', () =>
runInstall({}, 'install-file-link-dependencies', async config => {
const statA = await fs.lstat(path.join(config.cwd, 'node_modules', 'a'));
expect(statA.isSymbolicLink()).toEqual(true);
const statB = await fs.lstat(path.join(config.cwd, 'node_modules', 'b'));
expect(statB.isSymbolicLink()).toEqual(true);
const statC = await fs.lstat(path.join(config.cwd, 'node_modules', 'c'));
expect(statC.isSymbolicLink()).toEqual(true);
expect(await fs.readFile(path.join(config.cwd, 'node_modules', 'a', 'index.js'))).toEqual('foo;\n');
expect(await fs.readFile(path.join(config.cwd, 'node_modules', 'b', 'index.js'))).toEqual('bar;\n');
}));
test('install file: protocol', () =>
runInstall({lockfile: false}, 'install-file', async config => {
expect(await fs.readFile(path.join(config.cwd, 'node_modules', 'foo', 'index.js'))).toEqual('foobar;\n');
}));
test('install with file: protocol as default', () =>
runInstall({}, 'install-file-as-default', async (config, reporter, install, getOutput) => {
expect(await fs.readFile(path.join(config.cwd, 'node_modules', 'foo', 'index.js'))).toEqual('foobar;\n');
expect(getOutput()).toContain(reporter.lang('implicitFileDeprecated', 'bar'));
}));
test("don't install with file: protocol as default if target is a file", () =>
expect(runInstall({lockfile: false}, 'install-file-as-default-no-file')).rejects.toMatchObject({
message: expect.stringContaining('Couldn\'t find any versions for "foo" that matches "bar"'),
}));
test("don't install with implicit file: protocol if target does not have package.json", () =>
expect(runInstall({lockfile: false}, 'install-file-as-default-no-package')).rejects.toMatchObject({
message: expect.stringContaining('Couldn\'t find any versions for "foo" that matches "bar"'),
}));
test('install with explicit file: protocol if target does not have package.json', () =>
runInstall({}, 'install-file-no-package', async config => {
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'foo', 'bar.js'))).toEqual(true);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'bar', 'bar.js'))).toEqual(true);
}));
test("don't install with file: protocol as default if target is valid semver", () =>
runInstall({}, 'install-file-as-default-no-semver', async config => {
expect(JSON.parse(await fs.readFile(path.join(config.cwd, 'node_modules', 'foo', 'package.json')))).toMatchObject({
name: 'foo',
});
}));
test("don't hang when an install script tries to read from stdin", () =>
runInstall({}, 'install-blocking-script', (_config, _reporter, _install, getStdout) =>
expect(getStdout()).toMatch(/Building fresh packages/),
));
// When local packages are installed, dependencies with different forms of the same relative path
// should be deduped e.g. 'file:b' and 'file:./b'
test('install file: dedupe dependencies 1', () =>
runInstall({}, 'install-file-dedupe-dependencies-1', async config => {
// Check that b is not added as a sub-dependency of a
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'a', 'node_modules'))).toEqual(false);
}));
// When local packages are installed, dependencies with relative and absolute paths should be
// deduped e.g. 'file:b' and 'file:/absolute/path/to/b'
test('install file: dedupe dependencies 2', () =>
runInstall({}, 'install-file-dedupe-dependencies-2', async (config, reporter) => {
// Add b as a dependency, using an absolute path
await add(config, reporter, {}, [`b@file:${path.resolve(config.cwd, 'b')}`]);
// Check that b is not added as a sub-dependency of a
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'a', 'node_modules'))).toEqual(false);
}));
// When local packages are installed from a repo with a lockfile, the multiple packages
// unpacking in the same location warning should not occur
test('install file: dedupe dependencies 3', () =>
runInstall({}, 'install-file-dedupe-dependencies-3', (config, reporter, install, getStdout) => {
const stdout = getStdout();
// Need to check if message is logged, but don't need to check for any specific parameters
// so splitting on undefined and testing if all message parts are in stdout
const messageParts = reporter.lang('multiplePackagesCantUnpackInSameDestination').split('undefined');
const warningMessage = messageParts.every(part => stdout.includes(part));
expect(warningMessage).toBe(false);
}));
test('install everything when flat is enabled', () =>
runInstall({lockfile: false, flat: true}, 'install-file', async config => {
expect(await fs.readFile(path.join(config.cwd, 'node_modules', 'foo', 'index.js'))).toEqual('foobar;\n');
}));
test('install renamed packages', () =>
runInstall({}, 'install-renamed-packages', async config => {
const dir = path.join(config.cwd, 'node_modules');
const json = await fs.readJson(path.join(dir, 'left-pad', 'package.json'));
expect(json.version).toEqual('1.0.0');
const json2 = await fs.readJson(path.join(dir, 'left-pad2', 'package.json'));
expect(json2.version).toEqual('1.1.0');
const json3 = await fs.readJson(path.join(dir, 'unscoped-turf-helpers', 'package.json'));
expect(json3.version).toEqual('3.0.16');
expect(json3.name).toEqual('@turf/helpers');
}));
test('install from git cache', () =>
runInstall({}, 'install-from-git-cache', async config => {
expect(await getPackageVersion(config, 'dep-a')).toEqual('0.0.1');
}));
test('install from github', () => runInstall({}, 'install-github'));
test('check and install should verify integrity in the same way when flat', () =>
runInstall({flat: true}, 'install-should-dedupe-avoiding-conflicts-1', async (config, reporter) => {
// Will raise if check doesn't flatten the patterns
await check(config, reporter, {flat: true, integrity: true}, []);
}));
test('check should verify that top level dependencies are installed correctly', () =>
runInstall({}, 'check-top-correct', async (config, reporter) => {
const pkgDep = JSON.parse(
await fs.readFile(path.join(config.cwd, 'node_modules/fake-yarn-dependency/package.json')),
);
pkgDep.version = '2.0.0';
await fs.writeFile(
path.join(config.cwd, 'node_modules/fake-yarn-dependency/package.json'),
JSON.stringify(pkgDep, null, 4),
);
let allCorrect = false;
try {
await check(config, reporter, {}, []);
} catch (err) {
allCorrect = true;
}
expect(allCorrect).toBe(true);
}));
test('install should run install scripts in the order of dependencies', () =>
runInstall({}, 'scripts-order', async (config, reporter) => {
expect(await fs.exists(path.join(config.cwd, 'node_modules/dep-a/dep-a-built'))).toBe(true);
expect(await fs.exists(path.join(config.cwd, 'node_modules/dep-b/dep-b-built'))).toBe(true);
expect(await fs.exists(path.join(config.cwd, 'node_modules/dep-c/dep-c-built'))).toBe(true);
}));
test('install with comments in manifest', () =>
runInstall({lockfile: false}, 'install-with-comments', async config => {
expect(await fs.readFile(path.join(config.cwd, 'node_modules', 'foo', 'index.js'))).toEqual('foobar;\n');
}));
test('install with comments in manifest resolutions does not result in warning', () => {
const fixturesLoc = path.join(__dirname, '..', '..', 'fixtures', 'install');
return buildRun(
reporters.BufferReporter,
fixturesLoc,
async (args, flags, config, reporter): Promise<void> => {
await install(config, reporter, flags, args);
const output = reporter.getBuffer();
const warnings = output.filter(entry => entry.type === 'warning');
expect(
warnings.some(warning => {
return warning.data.toString().indexOf(reporter.lang('invalidResolutionName', '//')) > -1;
}),
).toEqual(false);
},
[],
{lockfile: false},
'install-with-comments',
);
});
test('install with null versions in manifest', () =>
runInstall({}, 'install-with-null-version', async config => {
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'left-pad'))).toEqual(true);
}));
test('run install scripts in the order when one dependency does not have install script', () =>
runInstall({}, 'scripts-order-with-one-package-missing-install-script', async (config, reporter) => {
expect(await fs.exists(path.join(config.cwd, 'node_modules/dep-a/dep-a-built'))).toBe(true);
expect(await fs.exists(path.join(config.cwd, 'node_modules/dep-b/dep-b-built'))).toBe(true);
expect(await fs.exists(path.join(config.cwd, 'node_modules/dep-d/dep-d-built'))).toBe(true);
}));
test('install should circumvent circular dependencies', () =>
runInstall({}, 'install-should-circumvent-circular-dependencies', async (config, reporter) => {
expect(await getPackageVersion(config, 'dep-a')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-b')).toEqual('1.0.0');
expect(await getPackageVersion(config, 'dep-c')).toEqual('1.0.0');
}));
test('install should resolve circular dependencies 2', () =>
runInstall({}, 'install-should-circumvent-circular-dependencies-2', async (config, reporter) => {
expect(await getPackageVersion(config, 'es5-ext')).toEqual('0.10.12');
}));
// Install a package twice
test('install should be idempotent', () =>
runInstall(
{},
'install-should-be-idempotent',
async (config, reporter) => {
expect(await getPackageVersion(config, 'dep-a')).toEqual('1.0.0');
await runInstall({}, 'install-should-be-idempotent', async (config, reporter) => {
expect(await getPackageVersion(config, 'dep-a')).toEqual('1.0.0');
});
},
null,
));
test('install should fail to authenticate integrity with incorrect hash and correct sha512', () =>
expect(runInstall({}, 'invalid-checksum-good-integrity')).rejects.toMatchObject({
message: expect.stringContaining("computed integrity doesn't match our records"),
}));
test('install should authenticate integrity field with sha1 checksums', () =>
runInstall({}, 'install-update-auth-sha1', async config => {
const lockFileContent = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
const lockFileLines = explodeLockfile(lockFileContent);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'abab'))).toEqual(true);
expect(lockFileLines[3].indexOf('integrity sha1-X6rZwsB/YN12dw9xzwJbYqY8/U4=')).toEqual(2);
}));
test('install should authenticate integrity field with sha512 checksums', () =>
runInstall({}, 'install-update-auth-sha512', async config => {
const lockFileContent = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
const lockFileLines = explodeLockfile(lockFileContent);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'safe-buffer'))).toEqual(true);
expect(
lockFileLines[3].indexOf(
'integrity sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==',
),
).toEqual(2);
}));
test('install should authenticate integrity field with sha384 checksums', () =>
runInstall({}, 'install-update-auth-sha384', async config => {
const lockFileContent = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
const lockFileLines = explodeLockfile(lockFileContent);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'safe-buffer'))).toEqual(true);
expect(
lockFileLines[3].indexOf('integrity sha384-waRmooJr/yhkTilj4++XOO8GFMGUq0RhoiKo7GymDwFU/Ij8vRNGoI7RwAKzyXSM'),
).toEqual(2);
}));
test('install should authenticate integrity field with options', () =>
runInstall({}, 'install-update-auth-sha512-options', async config => {
const lockFileContent = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
const lockFileLines = explodeLockfile(lockFileContent);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'safe-buffer'))).toEqual(true);
expect(
lockFileLines[3].indexOf(
'integrity ' +
'sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==?foo=bar',
),
).toEqual(2);
}));
test('install should authenticate integrity field with combined sha1 and sha512 checksums', () =>
runInstall({}, 'install-update-auth-combined-sha1-sha512', async config => {
const lockFileContent = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
const lockFileLines = explodeLockfile(lockFileContent);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'safe-buffer'))).toEqual(true);
// if this fails on a newer version of node or the ssri module,
// it (might) mean the sorting algorithm within the sri string changed
expect(lockFileLines[3]).toMatchSnapshot('integrity stable');
}));
test('install should authenticate integrity with multiple differing sha1 checksums', () =>
runInstall({}, 'install-update-auth-multiple-sha1', async config => {
const lockFileContent = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
const lockFileLines = explodeLockfile(lockFileContent);
expect(lockFileLines[3].indexOf('integrity "sha1-foo sha1-iTMSr2myEj3vcfV4iQAWce6yyFM=')).toEqual(2);
}));
test('install should authenticate integrity with multiple differing sha512 checksums', () =>
runInstall({}, 'install-update-auth-multiple-sha512', async config => {
const lockFileContent = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
const lockFileLines = explodeLockfile(lockFileContent);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'safe-buffer'))).toEqual(true);
expect(
lockFileLines[3].indexOf(
'integrity "sha512-foo ' +
'sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg=="',
),
).toEqual(2);
}));
test('install should authenticate integrity with wrong sha1 and right sha512 checksums', () =>
runInstall({}, 'install-update-auth-multiple-wrong-sha1-right-sha512', async config => {
const lockFileContent = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
const lockFileLines = explodeLockfile(lockFileContent);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'safe-buffer'))).toEqual(true);
expect(
lockFileLines[3].indexOf(
'integrity "sha1-foo ' +
'sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg=="',
),
).toEqual(2);
}));
test('install should fail to authenticate integrity with correct sha1 and incorrect sha512', () =>
expect(runInstall({}, 'install-update-auth-right-sha1-wrong-sha512')).rejects.toMatchObject({
message: expect.stringContaining("computed integrity doesn't match our records"),
}));
test('install should fail to authenticate on sha512 integrity mismatch', () =>
expect(runInstall({}, 'install-update-auth-wrong-sha512')).rejects.toMatchObject({
message: expect.stringContaining("computed integrity doesn't match our records"),
}));
test('install should fail to authenticate on sha1 integrity mismatch', () =>
expect(runInstall({}, 'install-update-auth-wrong-sha1')).rejects.toMatchObject({
message: expect.stringContaining("computed integrity doesn't match our records"),
}));
test.skip('install should create integrity field if not present', () =>
runInstall({}, 'install-update-auth-no-integrity-field', async config => {
const lockFileContent = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
const lockFileLines = explodeLockfile(lockFileContent);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'safe-buffer'))).toEqual(true);
expect(
lockFileLines[3].indexOf(
'integrity sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==',
),
).toEqual(2);
expect(lockFileLines[2].indexOf('#893312af69b2123def71f57889001671eeb2c853')).toBeGreaterThan(0);
// backwards-compatibility
}),
);
test('install should not create the integrity field if missing and auto-add-integrity is false', () =>
runInstall({}, 'install-update-auth-no-integrity-field-no-auto-add', async config => {
const lockFileContent = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
const lockFileLines = explodeLockfile(lockFileContent);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'safe-buffer'))).toEqual(true);
expect(lockFileLines[2].indexOf('#893312af69b2123def71f57889001671eeb2c853')).toBeGreaterThan(0);
expect(lockFileLines.length).toEqual(3);
}));
test('install should not create integrity field if not present and in offline mode', () =>
runInstall({offline: true}, 'install-update-auth-no-offline-integrity', async config => {
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'abab'))).toEqual(true);
}));
test('install should ignore existing hash if integrity is present even if it fails to authenticate it', () =>
expect(runInstall({}, 'install-update-auth-bad-sha512-good-hash')).rejects.toMatchObject({
message: expect.stringContaining("computed integrity doesn't match our records"),
}));
test('install should ignore unknown integrity algorithms if it has other options in the sri', () =>
runInstall({}, 'install-update-auth-madeup-right-sha512', async config => {
const lockFileContent = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
const lockFileLines = explodeLockfile(lockFileContent);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'safe-buffer'))).toEqual(true);
expect(
lockFileLines[3].indexOf(
'integrity "madeupalgorithm-abad1dea ' +
'sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg=="',
),
).toEqual(2);
}));
test('install should fail if the only algorithms in the sri are unknown', () =>
expect(runInstall({}, 'install-update-auth-madeup')).rejects.toMatchObject({
message: expect.stringContaining('none of the specified algorithms are supported'),
}));
test('install should fail if the sri is malformed', () =>
expect(runInstall({}, 'install-update-auth-malformed')).rejects.toMatchObject({
message: expect.stringContaining('none of the specified algorithms are supported'),
}));
test('install should fail with unsupported algorithms', () =>
expect(runInstall({}, 'install-update-auth-sha3')).rejects.toMatchObject({
message: expect.stringContaining('none of the specified algorithms are supported'),
}));
test.concurrent('install should update integrity in yarn.lock (--update-checksums)', () =>
runInstall({updateChecksums: true}, 'install-update-checksums', async config => {
const lockFileLines = explodeLockfile(await fs.readFile(path.join(config.cwd, 'yarn.lock')));
expect(lockFileLines[3]).toEqual(
expect.stringContaining(
'sha512-I+Wi+qiE2kUXyrRhNsWv6XsjUTBJjSoVSctKNBfLG5zG/Xe7Rjbxf13+vqYHNTwHaFU+FtSlVxOCTiMEVtPv0A==',
),
);
}),
);
test.concurrent('install should update malformed integrity string in yarn.lock (--update-checksums)', () =>
runInstall({updateChecksums: true}, 'install-update-checksums-malformed', async config => {
const lockFileLines = explodeLockfile(await fs.readFile(path.join(config.cwd, 'yarn.lock')));
expect(lockFileLines[3]).toEqual(
expect.stringContaining(
'sha512-I+Wi+qiE2kUXyrRhNsWv6XsjUTBJjSoVSctKNBfLG5zG/Xe7Rjbxf13+vqYHNTwHaFU+FtSlVxOCTiMEVtPv0A==',
),
);
}),
);
if (process.platform !== 'win32') {
// TODO: This seems like a real issue, not just a config issue
test('install cache symlinks properly', () =>
runInstall({}, 'cache-symlinks', async (config, reporter) => {
const symlink = path.resolve(config.cwd, 'node_modules', 'dep-a', 'link-index.js');
expect(await fs.exists(symlink)).toBe(true);
await fs.unlink(path.join(config.cwd, 'node_modules'));
const lockfile = await createLockfile(config.cwd);
const install = new Install({}, config, reporter, lockfile);
await install.init();
expect(await fs.exists(symlink)).toBe(true);
}));
}
test('install a scoped module from authed private registry', () =>
runInstall({}, 'install-from-authed-private-registry', async config => {
const authedRequests = request.__getAuthedRequests();
expect(authedRequests[0].url).toEqual('https://registry.yarnpkg.com/@types%2flodash');
expect(authedRequests[0].headers.authorization).toEqual('Bearer abc123');
expect(authedRequests[1].url).toEqual('https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.37.tgz');
expect(authedRequests[1].headers.authorization).toEqual('Bearer abc123');
expect(
(await fs.readFile(path.join(config.cwd, 'node_modules', '@types', 'lodash', 'index.d.ts'))).split('\n')[0],
).toEqual('// Type definitions for Lo-Dash 4.14');
}));
test('install a scoped module from authed private registry with a missing trailing slash', () =>
runInstall({}, 'install-from-authed-private-registry-no-slash', async config => {
const authedRequests = request.__getAuthedRequests();
expect(authedRequests[0].url).toEqual('https://registry.yarnpkg.com/@types%2flodash');
expect(authedRequests[0].headers.authorization).toEqual('Bearer abc123');
expect(authedRequests[1].url).toEqual('https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.37.tgz');
expect(authedRequests[1].headers.authorization).toEqual('Bearer abc123');
expect(
(await fs.readFile(path.join(config.cwd, 'node_modules', '@types', 'lodash', 'index.d.ts'))).split('\n')[0],
).toEqual('// Type definitions for Lo-Dash 4.14');
}));
test('install of scoped package with subdependency conflict should pass check', () =>
runInstall({}, 'install-scoped-package-with-subdependency-conflict', async (config, reporter) => {
let allCorrect = true;
try {
await check(config, reporter, {integrity: false}, []);
} catch (err) {
allCorrect = false;
}
expect(allCorrect).toBe(true);
}));
test('install a module with incompatible optional dependency should skip dependency', () =>
runInstall({}, 'install-should-skip-incompatible-optional-dep', async config => {
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'dep-incompatible'))).toEqual(false);
}));
test('install a module with incompatible optional dependency should skip transient dependencies', () =>
runInstall({}, 'install-should-skip-incompatible-optional-dep', async config => {
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'dep-a'))).toEqual(false);
}));
test('install a module with optional dependency should skip incompatible transient dependency', () =>
runInstall({}, 'install-should-skip-incompatible-optional-sub-dep', async config => {
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'dep-optional'))).toEqual(true);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'dep-incompatible'))).toEqual(false);
}));
// this tests for a problem occurring due to optional dependency incompatible with os, in this case fsevents
// this would fail on os's incompatible with fsevents, which is everything except osx.
if (process.platform !== 'darwin') {
test('install incompatible optional dependency should still install shared child dependencies', () =>
runInstall({}, 'install-should-not-skip-required-shared-deps', async config => {
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'deep-extend'))).toEqual(true);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'ini'))).toEqual(true);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'strip-json-comments'))).toEqual(true);
}));
}
test('optional dependency that fails to build should not be installed', () =>
runInstall({}, 'should-not-install-failing-optional-deps', async config => {
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'optional-failing'))).toEqual(false);
}));
test('failing dependency of optional dependency should not be installed', () =>
runInstall({}, 'should-not-install-failing-deps-of-optional-deps', async config => {
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'optional-dep'))).toEqual(true);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'sub-failing'))).toEqual(false);
}));
// Covers current behavior, issue opened whether this should be changed https://github.com/yarnpkg/yarn/issues/2274
test('a subdependency of an optional dependency that fails should be installed', () =>
runInstall({}, 'should-install-failing-optional-sub-deps', async config => {
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'optional-failing'))).toEqual(false);
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'sub-dep'))).toEqual(true);
}));
test('a sub-dependency should be non-optional if any parents mark it non-optional', () =>
runInstall({ignoreOptional: true}, 'install-sub-dependency-if-any-parents-mark-it-non-optional', async config => {
const deps = await fs.readdir(path.join(config.cwd, 'node_modules'));
expect(deps).toEqual([
'.yarn-integrity',
'normal-dep',
'normal-sub-dep',
'normal-sub-sub-dep',
'sub-dep',
'sub-dep-2',
'sub-sub-dep',
]);
}));
// revealed https://github.com/yarnpkg/yarn/issues/2263
test('should not loose dependencies when installing with --production', () =>
runInstall({production: true}, 'prod-should-keep-subdeps', async config => {
// would be hoisted from gulp/vinyl-fs/glob-stream/minimatch/brace-expansion/balanced-match
expect(await getPackageVersion(config, 'balanced-match')).toEqual('0.4.2');
}));
// https://github.com/yarnpkg/yarn/issues/2470
test('a allows dependency with [] in os cpu requirements', () =>
runInstall({}, 'empty-os', async config => {
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'feed'))).toEqual(true);
}));
test('should skip integrity check and do install when --skip-integrity-check flag is passed', () =>
runInstall({}, 'skip-integrity-check', async (config, reporter) => {
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'sub-dep'))).toEqual(true);
await fs.unlink(path.join(config.cwd, 'node_modules', 'sub-dep'));
let lockContent = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
lockContent += `
# changed the file, integrity should be fine
`;
await fs.writeFile(path.join(config.cwd, 'yarn.lock'), lockContent);
let reinstall = new Install({}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await reinstall.init();
// reinstall will be successful but it won't reinstall anything
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'sub-dep'))).toEqual(false);
reinstall = new Install({skipIntegrityCheck: true}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await reinstall.init();
// reinstall will reinstall deps
expect(await fs.exists(path.join(config.cwd, 'node_modules', 'sub-dep'))).toEqual(true);
let newLockContent = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
expect(lockContent).toEqual(newLockContent);
reinstall = new Install({force: true}, config, reporter, await Lockfile.fromDirectory(config.cwd));
await reinstall.init();
// force rewrites lockfile
newLockContent = await fs.readFile(path.join(config.cwd, 'yarn.lock'));
expect(lockContent).not.toEqual(newLockContent);
}));
test('bailout should work with --production flag too', () =>
runInstall({production: true}, 'bailout-prod', async (config, reporter): Promise<void> => {
// remove file
await fs.unlink(path.join(config.cwd, 'node_modules', 'left-pad', 'index.js'));