-
Notifications
You must be signed in to change notification settings - Fork 5.2k
/
commands-packages.js
2580 lines (2327 loc) · 95.4 KB
/
commands-packages.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
var main = require('./main.js');
var _ = require('underscore');
var files = require('../fs/files.js');
var buildmessage = require('../utils/buildmessage.js');
var auth = require('../meteor-services/auth.js');
var config = require('../meteor-services/config.js');
var utils = require('../utils/utils.js');
var httpHelpers = require('../utils/http-helpers.js');
var compiler = require('../isobuild/compiler.js');
var catalog = require('../packaging/catalog/catalog.js');
var catalogRemote = require('../packaging/catalog/catalog-remote.js');
var isopack = require('../isobuild/isopack.js');
var updater = require('../packaging/updater.js');
var Console = require('../console/console.js').Console;
var projectContextModule = require('../project-context.js');
var colonConverter = require('../utils/colon-converter.js');
var catalogUtils = require('../packaging/catalog/catalog-utils.js');
var release = require('../packaging/release.js');
var packageVersionParser = require('../packaging/package-version-parser.js');
var updater = require('../packaging/updater.js');
var packageMapModule = require('../packaging/package-map.js');
var packageClient = require('../packaging/package-client.js');
var tropohouse = require('../packaging/tropohouse.js');
import * as cordova from '../cordova';
// For each release (or package), we store a meta-record with its name,
// maintainers, etc. This function takes in a name, figures out if
// it is a release or a package, and fetches the correct record.
//
// Specifically, it returns an object with the following keys:
// - record : (a package or version record)
// - isRelease : true if it is a release instead of a package.
var getReleaseOrPackageRecord = function(name) {
var rec = catalog.official.getPackage(name);
var rel = false;
if (!rec) {
// Not a package! But is it a release track?
rec = catalog.official.getReleaseTrack(name);
if (rec)
rel = true;
}
return { record: rec, isRelease: rel };
};
// Seriously, this dies if it can't refresh. Only call it if you're sure you're
// OK that the command doesn't work while offline.
var refreshOfficialCatalogOrDie = function (options) {
if (!catalog.refreshOrWarn(options)) {
Console.error(
"This command requires an up-to-date package catalog. Exiting.");
throw new main.ExitWithCode(1);
}
};
var removeIfEndsWith = function (s, suffix) {
if (s.endsWith(suffix)) {
return s.substring(0, s.length - suffix.length);
}
return s;
};
// Internal use only. Makes sure that your Meteor install is totally good to go
// (is "airplane safe"). Specifically, it:
// - Builds all local packages, even those you're not using in your current
// app. (If you're not in an app, it still does this even though there is
// no persistent IsopackCache, because this still causes npm dependencies
// to be downloaded.)
// - Ensures that all packages in your current release are downloaded, even
// those you're not using in your current app.
// - Ensures that all packages used by your app (if any) are downloaded
// (It also ensures you have the dev bundle downloaded, just like every command
// in a checkout.)
//
// The use case is, for example, cloning an app from github, running this
// command, then getting on an airplane.
//
// This does NOT guarantee a *re*build of all local packages (though it will
// download any new dependencies): we still trust the buildinfo files in your
// app's IsopackCache. If you want to rebuild all local packages that are used
// in your app, call meteor rebuild. That said, rebuild should only be necessary
// if there's a bug in the build tool... otherwise, packages should be rebuilt
// whenever necessary!
main.registerCommand({
name: '--get-ready',
catalogRefresh: new catalog.Refresh.OnceAtStart({ ignoreErrors: false }),
options: {
'allow-incompatible-update': { type: Boolean }
}
}, function (options) {
// If we're in an app, make sure that we can build the current app. Otherwise
// just make sure that we can build some fake app.
var projectContext = new projectContextModule.ProjectContext({
projectDir: options.appDir || files.mkdtemp('meteor-get-ready'),
neverWriteProjectConstraintsFile: true,
neverWritePackageMap: true,
allowIncompatibleUpdate: options['allow-incompatible-update']
});
main.captureAndExit("=> Errors while initializing project:", function () {
projectContext.initializeCatalog();
});
// Add every local package (including tests) and every release package to this
// project. (Hopefully they can all be built at once!)
var addPackages = function (packageNames) {
projectContext.projectConstraintsFile.addConstraints(
_.map(packageNames, function (p) {
return utils.parsePackageConstraint(p);
})
);
};
addPackages(projectContext.localCatalog.getAllPackageNames());
if (release.current.isProperRelease()) {
addPackages(_.keys(release.current.getPackages()));
}
// Now finish building and downloading.
main.captureAndExit("=> Errors while initializing project:", function () {
projectContext.prepareProjectForBuild();
});
// We don't display package changes because they'd include all these packages
// not actually in the app!
// XXX Maybe we should do a first pass that only builds packages actually in
// the app and does display the PackageMapDelta?
return 0;
});
// Internal use only. A simpler version of --get-ready which doesn't try to also
// build/download local and release packages that aren't currently used. Just
// builds and downloads packages used by the current app.
main.registerCommand({
name: '--prepare-app',
requiresApp: true,
catalogRefresh: new catalog.Refresh.Never(),
options: {
'allow-incompatible-update': { type: Boolean }
}
}, function (options) {
var projectContext = new projectContextModule.ProjectContext({
projectDir: options.appDir,
allowIncompatibleUpdate: options['allow-incompatible-update']
});
main.captureAndExit("=> Errors while initializing project:", function () {
projectContext.prepareProjectForBuild();
});
projectContext.packageMapDelta.displayOnConsole();
});
///////////////////////////////////////////////////////////////////////////////
// publish a package
///////////////////////////////////////////////////////////////////////////////
// Updates the metadata for a given package version. Prints user-friendly
// messages if certain new values are invalid; calls to the packageClient to
// perform the actual update.
//
// Takes in a packageSource and a connection to the package server. Returns 0 on
// success and an exit code on failure.
var updatePackageMetadata = function (packageSource, conn) {
var name = packageSource.name;
var version = packageSource.version;
// You can't change the metadata of a record that doesn't exist.
var existingRecord =
catalog.official.getVersion(name, version);
if (! existingRecord) {
Console.error(
"You can't call", Console.command("`meteor publish --update`"),
"on version " + version + " of " + "package '" + name +
"' without publishing it first.");
return 1;
}
// Load in the user's documentation, and check that it isn't blank.
var readmeInfo;
main.captureAndExit(
"=> Errors while publishing:", "reading documentation",
function () {
readmeInfo = packageSource.processReadme();
});
// You are still not allowed to upload a blank README.md.
if (readmeInfo && readmeInfo.hash === files.blankHash) {
Console.error(
"Your documentation file is blank, so users may have trouble",
"figuring out how to use your package. Please fill it out, or",
"set 'documentation: null' in your Package.describe.");
return 1;
};
// Finally, call to the server.
main.captureAndExit(
"=> Errors while publishing:",
"updating package metadata",
function () {
packageClient.updatePackageMetadata({
packageSource: packageSource,
readmeInfo: readmeInfo,
connection: conn
});
});
Console.info(
"Success. You can take a look at the new metadata by running",
Console.command("'meteor show " + name + "@" + version + "'"),
"outside the current project directory.");
// Refresh, so that we actually learn about the thing we just published.
refreshOfficialCatalogOrDie();
return 0;
}
main.registerCommand({
name: 'publish',
minArgs: 0,
maxArgs: 0,
options: {
create: { type: Boolean },
update: { type: Boolean },
// This is similar to publish-for-arch, but uses the source code you have
// locally (and other local packages you may have) instead of downloading
// the source bundle. It does verify that the source is the same, though.
// Good for bootstrapping things in the core release.
'existing-version': { type: Boolean },
// This is the equivalent of "sudo": make sure that administrators don't
// accidentally put their personal packages in the top level namespace.
'top-level': { type: Boolean },
// An option to publish despite linting errors
'no-lint': { type: Boolean }
},
requiresPackage: true,
// We optimize the workflow by using up-to-date package data to weed out
// obviously incorrect submissions before they ever hit the wire.
catalogRefresh: new catalog.Refresh.OnceAtStart({ ignoreErrors: false }),
'allow-incompatible-update': { type: Boolean }
}, function (options) {
if (options.create && options['existing-version']) {
// Make up your mind!
Console.error(
"The --create and --existing-version options cannot",
"both be specified.");
return 1;
}
if (options.update && options.create) {
Console.error(
"The --create and --update options cannot both be specified.");
return 1;
}
if (options.update && options["existing-version"]) {
Console.error(
"The --update option implies that the version already exists.",
"You do not need to use the --existing-version flag with --update.");
return 1;
}
var projectContext;
if (! options.appDir) {
// We're not in an app? OK, make a temporary app directory, and make sure
// that the current package directory is found by its local catalog.
var tempProjectDir = files.mkdtemp('meteor-package-build');
projectContext = new projectContextModule.ProjectContext({
projectDir: tempProjectDir, // won't have a packages dir, that's OK
explicitlyAddedLocalPackageDirs: [options.packageDir],
packageMapFilename: files.pathJoin(options.packageDir, '.versions'),
// We always want to write our '.versions' package map, overriding a
// comparison against the value of a release file that doesn't exist.
alwaysWritePackageMap: true,
// When we publish, we should always include web.cordova unibuilds, even
// though this temporary directory does not have any cordova platforms
forceIncludeCordovaUnibuild: true,
allowIncompatibleUpdate: options['allow-incompatible-update'],
lintPackageWithSourceRoot: options['no-lint'] ? null : options.packageDir,
});
} else {
// We're in an app; let the app be our context, but make sure we don't
// overwrite .meteor/packages or .meteor/versions when we add some temporary
// constraints (which ensure that we can actually build the package and its
// tests).
projectContext = new projectContextModule.ProjectContext({
projectDir: options.appDir,
neverWriteProjectConstraintsFile: true,
neverWritePackageMap: true,
// When we publish, we should always include web.cordova unibuilds, even
// if this project does not have any cordova platforms
forceIncludeCordovaUnibuild: true,
allowIncompatibleUpdate: options['allow-incompatible-update'],
lintPackageWithSourceRoot: options['no-lint'] ? null : options.packageDir,
});
}
main.captureAndExit("=> Errors while initializing project:", function () {
// Just get up to initializing the catalog. We're going to mutate the
// constraints file a bit before we prepare the build.
projectContext.initializeCatalog();
});
if (!process.env.METEOR_TEST_NO_PUBLISH) {
// Connect to the package server and log in.
try {
var conn = packageClient.loggedInPackagesConnection();
} catch (err) {
packageClient.handlePackageServerConnectionError(err);
return 1;
}
if (! conn) {
Console.error('No connection: Publish failed.');
return 1;
}
}
var localVersionRecord = projectContext.localCatalog.getVersionBySourceRoot(
options.packageDir);
if (! localVersionRecord) {
// OK, we're inside a package (ie, a directory with a package.js) and we're
// inside an app (ie, a directory with a file named .meteor/packages) but
// the package is not on the app's search path (ie, it's probably not
// directly inside the app's packages directory). That's kind of
// weird. Let's not allow this.
Console.error(
"The package you are in appears to be inside a Meteor app but is not " +
"in its packages directory. You may only publish packages that are " +
"entirely outside of a project or that are loaded by the project " +
"that they are inside.");
return 1;
}
var packageName = localVersionRecord.packageName;
var packageSource = projectContext.localCatalog.getPackageSource(packageName);
if (! packageSource)
throw Error("no PackageSource for " + packageName);
// Anything published to the server must explicitly set a version.
if (! packageSource.versionExplicitlyProvided) {
Console.error("A version must be specified for the package. Set it with " +
"Package.describe.");
return 1;
}
// If we just want to update the package metadata, then we have all we
// need. Don't bother building the package, just update the metadata and
// return the result.
if (options.update) {
return updatePackageMetadata(packageSource, conn);
}
// Fail early if the package record exists, but we don't think that it does
// and are passing in the --create flag!
if (options.create) {
var packageInfo = catalog.official.getPackage(packageName);
if (packageInfo) {
Console.error(
"Package already exists. To create a new version of an existing "+
"package, do not use the --create flag!");
return 2;
}
if (!options['top-level'] && !packageName.match(/:/)) {
Console.error(
"Only administrators can create top-level packages without an",
"account prefix. (To confirm that you wish to create a top-level",
"package with no account prefix, please run this command again",
"with the --top-level option.)");
// You actually shouldn't be able to get here without being logged in, but
// it seems poor form to assume anything like that for the point of a
// brief error message.
if (auth.isLoggedIn()) {
var properName = auth.loggedInUsername() + ":" + packageName;
Console.error(
"\nDid you mean to create " + properName + " instead?"
);
}
return 2;
}
}
// Make sure that both the package and its test (if any) are actually built.
_.each([packageName, packageSource.testName], function (name) {
if (! name) // for testName
return;
// If we're already using this package, that's OK; no need to override.
if (projectContext.projectConstraintsFile.getConstraint(name))
return;
projectContext.projectConstraintsFile.addConstraints(
[utils.parsePackageConstraint(name)]);
});
// Now resolve constraints and build packages.
main.captureAndExit("=> Errors while initializing project:", function () {
projectContext.prepareProjectForBuild();
});
// We don't display the package map delta here, because it includes adding the
// package's test and all the test's dependencies.
if (!options['no-lint']) {
const warnings = projectContext.getLintingMessagesForLocalPackages();
if (warnings && warnings.hasMessages()) {
Console.arrowError(
"Errors linting your package; run with --no-lint to ignore.");
Console.printMessages(warnings);
return 1;
} else if (warnings) {
Console.arrowInfo('Linted your package. No linting errors.');
}
}
if (process.env.METEOR_TEST_NO_PUBLISH) {
Console.error(
'Would publish the package at this point, but since the ' +
'METEOR_TEST_NO_PUBLISH environment variable is set, just going ' +
'to finish here.');
return 0;
}
var isopack = projectContext.isopackCache.getIsopack(packageName);
if (! isopack) {
// This shouldn't happen; we already threw a different error if the package
// wasn't even in the local catalog, and we explicitly added this package to
// the project's constraints file, so it should have been built.
throw Error("package not built even though added to constraints?");
}
// We have initialized everything, so perform the publish operation.
var binary = isopack.platformSpecific();
main.captureAndExit(
"=> Errors while publishing:",
"publishing the package",
function () {
packageClient.publishPackage({
projectContext: projectContext,
packageSource: packageSource,
connection: conn,
new: options.create,
existingVersion: options['existing-version'],
doNotPublishBuild: binary && !options['existing-version']
});
});
Console.info('Published ' + packageName + '@' + localVersionRecord.version +
'.');
// We are only publishing one package, so we should close the connection, and
// then exit with the previous error code.
conn.close();
// Warn the user if their package is not good for all architectures.
if (binary && options['existing-version']) {
// This is an undocumented command that you are not supposed to run! We
// assume that you know what you are doing, if you ran it, and are OK with
// overrwriting normal compatibilities.
Console.warn();
Console.labelWarn("Your package contains binary code.");
} else if (binary) {
// Normal publish flow. Tell the user nicely.
Console.warn();
Console.warn(
"You're not done publishing yet! This package contains binary code and",
"must be built on all of Meteor's architectures, including this",
"machine's architecture.");
Console.warn();
Console.info(
"You can access Meteor provided build machines, pre-configured to",
"support older versions of MacOS and Linux, by running:");
_.each(["os.osx.x86_64", "os.linux.x86_64",
"os.linux.x86_32", "os.windows.x86_32"],
function (a) {
Console.info(
Console.command("meteor admin get-machine " + a),
Console.options({ indent: 2 }));
});
Console.info();
Console.info("On each machine, run:");
Console.info();
Console.info(
Console.command(
"meteor publish-for-arch " +
packageSource.name + "@" + packageSource.version),
Console.options({ indent: 2 }));
Console.info();
Console.info(
"For more information on binary ABIs and consistent builds, see:");
Console.info(
Console.url("https://github.com/meteor/meteor/wiki/Build-Machines"),
Console.options({ indent: 2 })
);
Console.info();
}
// Refresh, so that we actually learn about the thing we just published.
refreshOfficialCatalogOrDie();
return 0;
});
main.registerCommand({
name: 'publish-for-arch',
minArgs: 1,
maxArgs: 1,
catalogRefresh: new catalog.Refresh.OnceAtStart({ ignoreErrors: false }),
// in theory, this option shouldn't be necessary, because when you run
// publish-for-arch you want to reproduce the exact same setup as when
// you ran 'publish', but support the option in case it comes up.
'allow-incompatible-update': { type: Boolean }
}, function (options) {
// argument processing
var all = options.args[0].split('@');
if (all.length !== 2) {
Console.error(
'Incorrect argument. Please use the form of <packageName>@<version>');
throw new main.ShowUsage;
}
var name = all[0];
var versionString = all[1];
var packageInfo = catalog.official.getPackage(name);
if (! packageInfo) {
Console.error(
"You can't call " + Console.command("`meteor publish-for-arch`") +
"on package '" + name + "' without " +" publishing it first."
);
Console.error();
Console.error(
"To publish the package, run " +
Console.command("`meteor publish --create` ") +
"from the package directory.");
Console.error();
return 1;
}
var pkgVersion = catalog.official.getVersion(name, versionString);
if (! pkgVersion) {
Console.error(
"You can't call", Console.command("`meteor publish-for-arch`"),
"on version " + versionString + " of " + "package '" + name +
"' without publishing it first.");
Console.error();
Console.error(
"To publish the package, run " + Console.command("`meteor publish ` ") +
"from the package directory.");
Console.error();
return 1;
}
if (! pkgVersion.source || ! pkgVersion.source.url) {
Console.error(
"There is no source uploaded for",
name + '@' + versionString);
return 1;
}
// No releaseName (not even null): this predates the isopack-cache
// refactorings. Let's just springboard to Meteor 1.0 and let it deal with any
// further springboarding based on reading a nested json file.
if (! _.has(pkgVersion, 'releaseName')) {
if (files.inCheckout()) {
Console.error(
"This package was published from an old version of meteor, " +
"but you are running from checkout! Consider running " +
Console.command("`meteor --release 1.0`"),
"so we can springboard correctly.");
process.exit(1);
}
throw new main.SpringboardToSpecificRelease("METEOR@1.0");
}
if (pkgVersion.releaseName === null) {
if (! files.inCheckout()) {
Console.error(
"This package was published from a checkout of meteor!",
"The tool cannot replicate that environment and will not even try.",
"Please check out meteor at the " +
"corresponding git commit and try again.");
process.exit(1);
}
} else if (files.inCheckout()) {
Console.error(
"This package was published from a built version of meteor, " +
"but you are running from checkout! Consider running from a " +
"proper Meteor release with " +
Console.command("`meteor --release " + pkgVersion.releaseName + "`"),
"so we can springboard correctly.");
process.exit(1);
} else if (pkgVersion.releaseName !== release.current.name) {
// We are in a built release, and so is the package, but it's a different
// one. Springboard!
throw new main.SpringboardToSpecificRelease(pkgVersion.releaseName);
}
// OK, either we're running from a checkout and so was the published package,
// or we're running from the same release as the published package.
// Download the source to the package.
var sourceTarball = buildmessage.enterJob("downloading package source", function () {
return httpHelpers.getUrl({
url: pkgVersion.source.url,
encoding: null
});
});
var sourcePath = files.mkdtemp('package-source');
// XXX check tarballHash!
files.extractTarGz(sourceTarball, sourcePath);
// XXX Factor out with packageClient.bundleSource so that we don't
// have knowledge of the tarball structure in two places.
var packageDir = files.pathJoin(sourcePath, colonConverter.convert(name));
if (! files.exists(packageDir)) {
Console.error('Malformed source tarball');
return 1;
}
var tempProjectDir = files.mkdtemp('meteor-package-arch-build');
// Copy over a version lock file from the source tarball.
var versionsFile = files.pathJoin(packageDir, '.versions');
if (! files.exists(versionsFile)) {
Console.error(
"This package has no valid version lock file: are you trying to use " +
"publish-for-arch on a core package? Publish-for-arch cannot " +
"guarantee safety. Please use",
Console.command("'meteor publish --existing-version'"), "instead.");
process.exit(1);
}
files.copyFile(files.pathJoin(packageDir, '.versions'),
files.pathJoin(tempProjectDir, '.meteor', 'versions'));
// Set up the project.
var projectContext = new projectContextModule.ProjectContext({
projectDir: tempProjectDir,
explicitlyAddedLocalPackageDirs: [packageDir],
// When we publish, we should always include web.cordova unibuilds, even
// though this temporary directory does not have any cordova platforms
forceIncludeCordovaUnibuild: true,
allowIncompatibleUpdate: options['allow-incompatible-update']
});
// Just get up to initializing the catalog. We're going to mutate the
// constraints file a bit before we prepare the build.
main.captureAndExit("=> Errors while initializing project:", function () {
projectContext.initializeCatalog();
});
projectContext.projectConstraintsFile.addConstraints(
[utils.parsePackageConstraint(name + "@=" + versionString)]);
main.captureAndExit("=> Errors while initializing project:", function () {
projectContext.prepareProjectForBuild();
});
projectContext.packageMapDelta.displayOnConsole({
title: "Some package versions changed since this package was published!"
});
var isopk = projectContext.isopackCache.getIsopack(name);
if (! isopk)
throw Error("didn't build isopack for " + name);
var conn;
try {
conn = packageClient.loggedInPackagesConnection();
} catch (err) {
packageClient.handlePackageServerConnectionError(err);
return 1;
}
main.captureAndExit(
"=> Errors while publishing build:",
("publishing package " + name + " for architecture "
+ isopk.buildArchitectures()),
function () {
packageClient.createAndPublishBuiltPackage(conn, isopk);
}
);
Console.info('Published ' + name + '@' + versionString + '.');
refreshOfficialCatalogOrDie();
return 0;
});
main.registerCommand({
name: 'publish-release',
minArgs: 1,
maxArgs: 1,
options: {
'create-track': { type: Boolean },
'from-checkout': { type: Boolean }
},
catalogRefresh: new catalog.Refresh.OnceAtStart({ ignoreErrors: false })
}, function (options) {
try {
var conn = packageClient.loggedInPackagesConnection();
} catch (err) {
packageClient.handlePackageServerConnectionError(err);
return 1;
}
var relConf = {};
// Let's read the json release file. It should, at the very minimum contain
// the release track name, the release version and some short freeform
// description.
try {
var data = files.readFile(options.args[0], 'utf8');
relConf = JSON.parse(data);
} catch (e) {
Console.error("Could not parse release file: " + e.message);
return 1;
}
// Fill in the order key and any other generated release.json fields.
main.captureAndExit(
"=> Errors in release schema:",
"double-checking release schema",
function () {
// Check that the schema is valid -- release.json contains all the
// required fields, does not contain contradicting information, etc.
// XXX Check for unknown keys?
if (! _.has(relConf, 'track')) {
buildmessage.error(
"Configuration file must specify release track. (track).");
}
if (! _.has(relConf, 'version')) {
buildmessage.error(
"Configuration file must specify release version. (version).");
}
if (! _.has(relConf, 'description')) {
buildmessage.error(
"Configuration file must contain a description (description).");
} else if (relConf.description.length > 100) {
buildmessage.error("Description must be under 100 characters.");
}
if (! options['from-checkout']) {
if (! _.has(relConf, 'tool')) {
buildmessage.error(
"Configuration file must specify a tool version (tool) unless in " +
"--from-checkout mode.");
}
if (! _.has(relConf, 'packages')) {
buildmessage.error(
"Configuration file must specify package versions (packages) " +
"unless in --from-checkout mode.");
}
}
// If you didn't specify an orderKey and it's compatible with our
// conventional orderKey generation algorithm, use the algorithm. If you
// explicitly specify orderKey: null, don't include one.
if (! _.has(relConf, 'orderKey')) {
relConf.orderKey = utils.defaultOrderKeyForReleaseVersion(
relConf.version);
}
// This covers both the case of "explicitly specified {orderKey: null}"
// and "defaultOrderKeyForReleaseVersion returned null".
if (relConf.orderKey === null) {
delete relConf.orderKey;
}
if (! _.has(relConf, 'orderKey') && relConf.recommended) {
buildmessage.error("Recommended releases must have order keys.");
}
// On the main release track, we can't name the release anything beginning
// with 0.8 and below, because those are taken for pre-troposphere
// releases.
if ((relConf.track === catalog.DEFAULT_TRACK)) {
var start = relConf.version.slice(0,4);
if (start === "0.8." || start === "0.7." ||
start === "0.6." || start === "0.5.") {
buildmessage.error(
"It looks like you are trying to publish a pre-package-server " +
"meteor release. Doing this through the package server is going " +
"to cause a lot of confusion. Please use the old release process.");
}
}
}
);
// Let's check if this is a known release track/ a track to which we are
// authorized to publish before we do any complicated/long operations, and
// before we publish its packages.
if (! options['create-track']) {
var trackRecord = catalog.official.getReleaseTrack(relConf.track);
if (!trackRecord) {
Console.error(
'There is no release track named ' + relConf.track +
'. If you are creating a new track, use the --create-track flag.');
return 1;
}
// Check with the server to see if we're organized (we can't due this
// locally due to organizations).
if (!packageClient.amIAuthorized(relConf.track,conn, true)) {
Console.error('You are not an authorized maintainer of ' +
relConf.track + ".");
Console.error('Only authorized maintainers may publish new versions.');
return 1;
}
}
// This is sort of a hidden option to just take your entire meteor checkout
// and make a release out of it. That's what we do now (that's what releases
// meant pre-0.90), and it is very convenient to do that here.
//
// If you have any unpublished packages at new versions in your checkout, this
// WILL PUBLISH THEM at specified versions. (If you have unpublished changes,
// including changes to build-time dependencies, but have not incremented the
// version number, this will use buildmessage to error and exit.)
//
// Without any modifications about forks and package names, this particular
// option is not very useful outside of MDG. Right now, to run this option on
// a non-MDG fork of meteor, someone would probably need to go through and
// change the package names to have proper prefixes, etc.
if (options['from-checkout']) {
// You must be running from checkout to bundle up your checkout as a release.
if (!files.inCheckout()) {
Console.error("Must run from checkout to make release from checkout.");
return 1;
};
// You should not use a release configuration with packages&tool *and* a
// from checkout option, at least for now. That's potentially confusing
// (which ones did you mean to use) and makes it likely that you did one of
// these by accident. So, we will disallow it for now.
if (relConf.packages || relConf.tool) {
Console.error(
"Setting the --from-checkout option will use the tool and packages " +
"in your meteor checkout. " +
"Your release configuration file should not contain that information.");
return 1;
}
// Set up a temporary project context and build everything.
var tempProjectDir = files.mkdtemp('meteor-release-build');
var projectContext = new projectContextModule.ProjectContext({
projectDir: tempProjectDir, // won't have a packages dir, that's OK
// seriously, we only want checkout packages
ignorePackageDirsEnvVar: true,
// When we publish, we should always include web.cordova unibuilds, even
// though this temporary directory does not have any cordova platforms
forceIncludeCordovaUnibuild: true
});
// Read metadata and initialize catalog.
main.captureAndExit("=> Errors while building for release:", function () {
projectContext.initializeCatalog();
});
// Ensure that all packages and their tests are built. (We need to build
// tests so that we can include their sources in source tarballs.)
var allPackagesWithTests = projectContext.localCatalog.getAllPackageNames();
var allPackages = projectContext.localCatalog.getAllNonTestPackageNames();
projectContext.projectConstraintsFile.addConstraints(
_.map(allPackagesWithTests, function (p) {
return utils.parsePackageConstraint(p);
})
);
// Build!
main.captureAndExit("=> Errors while building for release:", function () {
projectContext.prepareProjectForBuild();
});
// No need to display the PackageMapDelta here, since it would include all
// of the packages!
relConf.packages = {};
var toPublish = [];
main.captureAndExit("=> Errors in release packages:", function () {
_.each(allPackages, function (packageName) {
buildmessage.enterJob("checking consistency of " + packageName, function () {
var packageSource = projectContext.localCatalog.getPackageSource(
packageName);
if (! packageSource)
throw Error("no PackageSource for built package " + packageName);
if (! packageSource.versionExplicitlyProvided) {
buildmessage.error(
"A version must be specified for the package. Set it with " +
"Package.describe.");
return;
}
// Let's get the server version that this local package is
// overwriting. If such a version exists, we will need to make sure
// that the contents are the same.
var oldVersionRecord = catalog.official.getVersion(
packageName, packageSource.version);
// Include this package in our release.
relConf.packages[packageName] = packageSource.version;
// If there is no old version, then we need to publish this package.
if (! oldVersionRecord) {
// We are going to check if we are publishing an official
// release. If this is an experimental or pre-release, then we are
// not ready to commit to these package semver versions either. Any
// packages that we should publish as part of this release should
// have a -(something) at the end.
var newVersion = packageSource.version;
if (! relConf.official && newVersion.split("-").length < 2) {
buildmessage.error(
"It looks like you are building an experimental release or " +
"pre-release. Any packages we publish here should have an " +
"pre-release identifier at the end (eg, 1.0.0-dev). If " +
"this is an official release, please set official to true " +
"in the release configuration file.");
return;
}
toPublish.push(packageName);
Console.info("Will publish new version for " + packageName);
return;
} else {
var isopk = projectContext.isopackCache.getIsopack(packageName);
if (! isopk)
throw Error("no isopack for " + packageName);
var existingBuild =
catalog.official.getBuildWithPreciseBuildArchitectures(
oldVersionRecord, isopk.buildArchitectures());
var somethingChanged;
if (! existingBuild) {
// If the version number mentioned in package.js exists,
// but there's no build of this architecture, then
// either the old version was only semi-published, or
// you've added some platform-specific dependencies but
// haven't bumped the version number yet; either way,
// you should probably bump the version number.
somethingChanged = true;
} else {
// Save the isopack, just to get its hash.
var bundleBuildResult = packageClient.bundleBuild(isopk);
somethingChanged =
(bundleBuildResult.treeHash !== existingBuild.build.treeHash);
}
if (somethingChanged) {
buildmessage.error(
"Something changed in package " + packageName + "@" +
isopk.version + ". Please upgrade its version number.");
}
}
});
});
});
// We now have an object of packages that have new versions on disk that
// don't exist in the server catalog. Publish them.
var unfinishedBuilds = {};
_.each(toPublish, function (packageName) {
main.captureAndExit(
"=> Errors while publishing:",
"publishing package " + packageName,
function () {
var isopk = projectContext.isopackCache.getIsopack(packageName);
if (! isopk)
throw Error("no isopack for " + packageName);
var packageSource = projectContext.localCatalog.getPackageSource(
packageName);
if (! packageSource)
throw Error("no PackageSource for built package " + packageName);
var binary = isopk.platformSpecific();
packageClient.publishPackage({
projectContext: projectContext,
packageSource: packageSource,
connection: conn,
new: ! catalog.official.getPackage(packageName),
doNotPublishBuild: binary
});
if (buildmessage.jobHasMessages())
return;
Console.info(
'Published ' + packageName + '@' + packageSource.version + '.');
if (binary) {
unfinishedBuilds[packageName] = packageSource.version;
}
});
});
// Set the remaining release information. For now, when we publish from
// checkout, we always set 'meteor-tool' as the tool. We don't include the
// tool in the packages list.
relConf.tool="meteor-tool@" + relConf.packages["meteor-tool"];
delete relConf.packages["meteor-tool"];
}
main.captureAndExit(
"=> Errors while publishing release:",
"publishing release",
function () {
// Create the new track, if we have been told to.
if (options['create-track']) {
// XXX maybe this job title should be left on the screen too? some sort
// of enterJob/progress option that lets you do that?
buildmessage.enterJob("creating a new release track", function () {
packageClient.callPackageServerBM(