Skip to content

Commit 640ab28

Browse files
committed
Improve linting of packages
- Only lint packages when we're actually going to use the output - The linter adds the files it uses to the corresponding unibuild WatchSets
1 parent 3c98084 commit 640ab28

6 files changed

Lines changed: 70 additions & 49 deletions

File tree

tools/bundler.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,6 @@ Find out more about Meteor at meteor.com.
19291929
* fallback option for Windows). For isopacks (meteor packages), link to the
19301930
* location of the locally stored isopack build (e.g.
19311931
* ~/.meteor/packages/package/version/npm)
1932-
* - lint: specifies if linting is required
19331932
*
19341933
* - buildOptions: may include
19351934
* - minify: string, type of minification for the CSS and JS assets
@@ -1971,12 +1970,11 @@ exports.bundle = function ({
19711970
outputPath,
19721971
includeNodeModules,
19731972
buildOptions,
1974-
lint: shouldLint,
19751973
previousBuilders,
19761974
hasCachedBundle
19771975
}) {
19781976
buildOptions = buildOptions || {};
1979-
shouldLint = shouldLint || false;
1977+
const shouldLint = !!projectContext.lintAppAndLocalPackages;
19801978

19811979
var appDir = projectContext.projectDir;
19821980

tools/commands.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,8 @@ function doRunCommand (options) {
275275

276276
var projectContext = new projectContextModule.ProjectContext({
277277
projectDir: options.appDir,
278-
allowIncompatibleUpdate: options['allow-incompatible-update']
278+
allowIncompatibleUpdate: options['allow-incompatible-update'],
279+
lintAppAndLocalPackages: !options['no-lint']
279280
});
280281

281282
main.captureAndExit("=> Errors while initializing project:", function () {
@@ -400,7 +401,6 @@ function doRunCommand (options) {
400401
appHost: appHost,
401402
debugPort: options['debug-port'],
402403
settingsFile: options.settings,
403-
lint: ! options['no-lint'],
404404
buildOptions: {
405405
minify: options.production ? 'production' : 'development',
406406
includeDebug: ! options.production
@@ -983,7 +983,8 @@ main.registerCommand({
983983
var projectContext = new projectContextModule.ProjectContext({
984984
projectDir: options.appDir,
985985
serverArchitectures: [archinfo.host()],
986-
allowIncompatibleUpdate: options['allow-incompatible-update']
986+
allowIncompatibleUpdate: options['allow-incompatible-update'],
987+
lintAppAndLocalPackages: true
987988
});
988989
var messages = buildmessage.capture(function () {
989990
projectContext.prepareProjectForBuild();
@@ -998,7 +999,6 @@ main.registerCommand({
998999
var bundle = bundler.bundle({
9991000
projectContext: projectContext,
10001001
outputPath: null,
1001-
lint: true,
10021002
buildOptions: {
10031003
minify: 'development'
10041004
}
@@ -1445,7 +1445,8 @@ main.registerCommand({
14451445
projectDirForLocalPackages: options.appDir,
14461446
explicitlyAddedLocalPackageDirs: packagesByPath,
14471447
serverArchitectures: serverArchitectures,
1448-
allowIncompatibleUpdate: options['allow-incompatible-update']
1448+
allowIncompatibleUpdate: options['allow-incompatible-update'],
1449+
lintAppAndLocalPackages: !options['no-lint']
14491450
});
14501451

14511452
main.captureAndExit("=> Errors while setting up tests:", function () {
@@ -1608,8 +1609,7 @@ var getTestPackageNames = function (projectContext, packageNames) {
16081609
var runTestAppForPackages = function (projectContext, options) {
16091610
var buildOptions = {
16101611
minify: options.production ? 'production' : 'development',
1611-
includeDebug: ! options.production,
1612-
lint: ! options['no-lint']
1612+
includeDebug: ! options.production
16131613
};
16141614

16151615
if (options.deploy) {

tools/compiler.js

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,8 @@ compiler.lint = function (packageSource, options) {
175175
// skip Cordova if not required
176176
if (! options.includeCordovaUnibuild
177177
&& architecture.arch === 'web.cordova') {
178-
return;
179-
}
178+
return;
179+
}
180180

181181
lintUnibuild({
182182
isopack: options.isopack,
@@ -246,14 +246,20 @@ var lintUnibuild = function ({isopack, isopackCache, sourceArch}) {
246246
return;
247247
}
248248

249-
var watchSet = new watch.WatchSet;
250-
var sourceItems = sourceArch.getSourcesFunc(sourceProcessorSet, watchSet);
249+
const unibuild = _.findWhere(isopack.unibuilds, {arch: sourceArch.arch});
250+
if (! unibuild) {
251+
throw Error(`No ${ sourceArch.arch } unibuild for ${ isopack.name }!`);
252+
}
253+
254+
var sourceItems = sourceArch.getSourcesFunc(
255+
sourceProcessorSet, unibuild.watchSet);
251256

252257
runLinters({
253-
inputSourceArch: sourceArch,
254258
isopackCache,
255259
sourceItems,
256-
sourceProcessorSet
260+
sourceProcessorSet,
261+
inputSourceArch: sourceArch,
262+
watchSet: unibuild.watchSet
257263
});
258264
};
259265

@@ -525,7 +531,7 @@ var compileUnibuild = function (options) {
525531
};
526532

527533
function runLinters({inputSourceArch, isopackCache, sourceItems,
528-
sourceProcessorSet}) {
534+
sourceProcessorSet, watchSet}) {
529535
if (sourceProcessorSet.isEmpty()) {
530536
return;
531537
}
@@ -591,7 +597,6 @@ function runLinters({inputSourceArch, isopackCache, sourceItems,
591597
}
592598

593599
// Read the file and add it to the WatchSet.
594-
// XXX BBP there is no watchSet yet!!!!!!!
595600
const {hash, contents} = watch.readAndWatchFileWithHash(
596601
watchSet,
597602
files.pathResolve(inputSourceArch.pkg.sourceRoot, relPath));

tools/isopack-cache.js

Lines changed: 39 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ exports.IsopackCache = function (options) {
5050

5151
self._noLineNumbers = !! options.noLineNumbers;
5252

53+
self._lintLocalPackages = !! options.lintLocalPackages;
54+
5355
self.allLoadedLocalPackagesWatchSet = new watch.WatchSet;
5456
};
5557

@@ -226,6 +228,8 @@ _.extend(exports.IsopackCache.prototype, {
226228
var isopack;
227229
if (previousIsopack && self._checkUpToDatePreloaded(previousIsopack)) {
228230
isopack = previousIsopack;
231+
// We don't need to call self._lintLocalPackage here, because
232+
// lintingMessages is saved on the isopack.
229233
} else {
230234
var pluginCacheDir;
231235
if (self._pluginCacheDirRoot) {
@@ -241,8 +245,7 @@ _.extend(exports.IsopackCache.prototype, {
241245
// Reuse existing plugin cache dir
242246
pluginCacheDir && files.mkdir_p(pluginCacheDir);
243247

244-
var Isopack = isopackModule.Isopack;
245-
isopack = new Isopack();
248+
isopack = new isopackModule.Isopack();
246249
isopack.initFromPath(name, self._isopackDir(name), {
247250
isopackBuildInfoJson: isopackBuildInfoJson,
248251
pluginCacheDir: pluginCacheDir
@@ -255,6 +258,10 @@ _.extend(exports.IsopackCache.prototype, {
255258
isopack.setPluginProviderPackageMap(
256259
self._packageMap.makeSubsetMap(
257260
_.keys(isopackBuildInfoJson.pluginProviderPackageMap)));
261+
// Because we don't save linter messages to disk, we have to relint
262+
// this package.
263+
// XXX save linter messages to disk?
264+
self._lintLocalPackage(packageInfo.packageSource, isopack);
258265
} else {
259266
// Nope! Compile it again. Give it a fresh plugin cache.
260267
if (pluginCacheDir) {
@@ -272,37 +279,45 @@ _.extend(exports.IsopackCache.prototype, {
272279
// Accept the compiler's result, even if there were errors (since it
273280
// at least will have a useful WatchSet and will allow us to keep
274281
// going and compile other packages that depend on this one). However,
275-
// only save it to disk if there were no errors.
276-
if (self.cacheDir && ! buildmessage.jobHasMessages()) {
277-
// Save to disk, for next time!
278-
isopack.saveToPath(self._isopackDir(name), {
279-
includeIsopackBuildInfo: true
280-
});
282+
// only lint it and save it to disk if there were no errors.
283+
if (! buildmessage.jobHasMessages()) {
284+
// Lint the package. We do this before saving so that the linter can
285+
// augment the saved-to-disk WatchSet with linter-specific files.
286+
self._lintLocalPackage(packageInfo.packageSource, isopack);
287+
if (self.cacheDir) {
288+
// Save to disk, for next time!
289+
isopack.saveToPath(self._isopackDir(name), {
290+
includeIsopackBuildInfo: true
291+
});
292+
}
281293
}
282294
}
283295
}
284296

285297
self.allLoadedLocalPackagesWatchSet.merge(isopack.getMergedWatchSet());
286298
self._isopacks[name] = isopack;
299+
});
300+
},
287301

288-
// lint isopack if compilation succeeded or if we loaded it from cache
289-
if (! buildmessage.jobHasMessages()) {
290-
var lintingMessages = buildmessage.capture({
291-
title: "linting isopack " + name
292-
}, function () {
293-
compiler.lint(packageInfo.packageSource, {
294-
isopackCache: self,
295-
isopack: isopack,
296-
includeCordovaUnibuild: self._includeCordovaUnibuild
297-
});
298-
});
299-
if (! lintingMessages.hasMessages()) {
300-
lintingMessages = null;
301-
}
302+
// Runs appropriate linters on a package. It also augments their unibuilds'
303+
// WatchSets with files used by the linter.
304+
_lintLocalPackage(packageSource, isopack) {
305+
const self = this;
306+
if (! self._lintLocalPackages)
307+
return;
302308

303-
isopack.lintingMessages = lintingMessages;
304-
}
309+
const lintingMessages = buildmessage.capture({
310+
title: "linting isopack " + isopack.name
311+
}, function () {
312+
compiler.lint(packageSource, {
313+
isopackCache: self,
314+
isopack: isopack,
315+
includeCordovaUnibuild: self._includeCordovaUnibuild
316+
});
305317
});
318+
if (lintingMessages.hasMessages()) {
319+
isopack.lintingMessages = lintingMessages;
320+
}
306321
},
307322

308323
_checkUpToDate: function (isopackBuildInfoJson) {
@@ -405,7 +420,6 @@ _.extend(exports.IsopackCache.prototype, {
405420

406421
var messages = new buildmessage._MessageSet();
407422
self._packageMap.eachPackage(function (name, packageInfo) {
408-
var packageInfo = self._packageMap.getInfo(name);
409423
var isopack = self._isopacks[name];
410424
if (packageInfo.kind === 'local') {
411425
var isopackMessages = isopack.lintingMessages;

tools/project-context.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ _.extend(ProjectContext.prototype, {
159159
// them or change their major version).
160160
self._allowIncompatibleUpdate = options.allowIncompatibleUpdate;
161161

162+
// If set, we run the linter on the app and local packages. Set by 'meteor
163+
// lint', and the runner commands (run/test-packages/debug) when --no-lint
164+
// is not passed.
165+
self.lintAppAndLocalPackages = options.lintAppAndLocalPackages;
166+
162167
// Initialized by readProjectMetadata.
163168
self.releaseFile = null;
164169
self.projectConstraintsFile = null;
@@ -711,7 +716,8 @@ _.extend(ProjectContext.prototype, {
711716
cacheDir: self.getProjectLocalDirectory('isopacks'),
712717
pluginCacheDirRoot: self.getProjectLocalDirectory('plugin-cache'),
713718
tropohouse: self.tropohouse,
714-
previousIsopackCache: self._previousIsopackCache
719+
previousIsopackCache: self._previousIsopackCache,
720+
lintLocalPackages: self.lintAppAndLocalPackages
715721
});
716722

717723
if (self._forceRebuildPackages) {

tools/run-app.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ var AppProcess = function (options) {
7070
self.proc = null;
7171
self.madeExitCallback = false;
7272
self.ipcPipe = options.ipcPipe;
73-
self.lint = options.lint;
7473
};
7574

7675
_.extend(AppProcess.prototype, {
@@ -354,7 +353,6 @@ var AppRunner = function (options) {
354353
self.mobileServerUrl = options.mobileServerUrl;
355354
self.settingsFile = options.settingsFile;
356355
self.debugPort = options.debugPort;
357-
self.lint = options.lint;
358356
self.proxy = options.proxy;
359357
self.watchForChanges =
360358
options.watchForChanges === undefined ? true : options.watchForChanges;
@@ -562,7 +560,6 @@ _.extend(AppRunner.prototype, {
562560
includeNodeModules: includeNodeModules,
563561
buildOptions: self.buildOptions,
564562
hasCachedBundle: !! cachedServerWatchSet,
565-
lint: self.lint,
566563
previousBuilders: builders
567564
});
568565

@@ -711,7 +708,7 @@ _.extend(AppRunner.prototype, {
711708
}
712709

713710
appProcess.start();
714-
if (self.lint) {
711+
if (self.projectContext.lintAppAndLocalPackages) {
715712
var warnings = bundleResult.warnings;
716713

717714
if (warnings && warnings.hasMessages()) {
@@ -772,7 +769,8 @@ _.extend(AppRunner.prototype, {
772769
if (bundleResultOrRunResult.runResult)
773770
return bundleResultOrRunResult.runResult;
774771
bundleResult = bundleResultOrRunResult.bundleResult;
775-
if (self.lint && bundleResult.warnings) {
772+
if (self.projectContext.lintAppAndLocalPackages &&
773+
bundleResult.warnings) {
776774
runLog.log(
777775
'Linting your app.\n\n' +
778776
bundleResult.warnings.formatMessages(), { arrow: true });

0 commit comments

Comments
 (0)