polymer-project-config
Advanced tools
Comparing version 3.10.0 to 3.11.0
@@ -11,2 +11,11 @@ # Change Log | ||
## [3.11.0] - 2018-03-27 | ||
* JSON serialization will now include `npm`, `componentDir`, and `moduleResolution` fields. | ||
* Add a method to initialize an Analyzer based on a config, as well as | ||
a static function ProjectConfig to initialize an Analyzer from a project | ||
directory. | ||
Because polymer-analyzer 3.0.0 is in prerelease, project-config depends on it | ||
as a peer dependency, so that the dependant can choose the specific pre-release version of analyzer to use. | ||
## [3.10.0] - 2018-03-12 | ||
@@ -13,0 +22,0 @@ * Added new option: `moduleResolution`. Determines algorithm used for resolving module specifiers. Can be 'none' or 'node'. |
import { ProjectBuildOptions } from './builds'; | ||
import { FsUrlLoader, PackageUrlResolver, WarningFilter, Analyzer } from 'polymer-analyzer'; | ||
export { ProjectBuildOptions, applyBuildPreset } from './builds'; | ||
@@ -143,2 +144,13 @@ /** | ||
/** | ||
* Given a project directory, return an Analyzer (and related objects) with | ||
* configuration inferred from polymer.json (and possibly other config files | ||
* that we find and interpret). | ||
*/ | ||
static initializeAnalyzerFromDirectory(dirname: string): Promise<{ | ||
urlLoader: FsUrlLoader; | ||
urlResolver: PackageUrlResolver; | ||
analyzer: Analyzer; | ||
warningFilter: WarningFilter; | ||
}>; | ||
/** | ||
* constructor - given a ProjectOptions object, create the correct project | ||
@@ -150,2 +162,12 @@ * configuration for those options. This involves setting the correct | ||
constructor(options: ProjectOptions); | ||
/** | ||
* Get an analyzer (and other related objects) with configuration determined | ||
* by this ProjectConfig. | ||
*/ | ||
initializeAnalyzer(): Promise<{ | ||
urlLoader: FsUrlLoader; | ||
urlResolver: PackageUrlResolver; | ||
analyzer: Analyzer; | ||
warningFilter: WarningFilter; | ||
}>; | ||
isFragment(filepath: string): boolean; | ||
@@ -152,0 +174,0 @@ isShell(filepath: string): boolean; |
@@ -15,2 +15,10 @@ "use strict"; | ||
*/ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -23,2 +31,3 @@ const fs = require("fs"); | ||
const minimatchAll = require("minimatch-all"); | ||
const polymer_analyzer_1 = require("polymer-analyzer"); | ||
var builds_2 = require("./builds"); | ||
@@ -273,2 +282,36 @@ exports.applyBuildPreset = builds_2.applyBuildPreset; | ||
} | ||
/** | ||
* Given a project directory, return an Analyzer (and related objects) with | ||
* configuration inferred from polymer.json (and possibly other config files | ||
* that we find and interpret). | ||
*/ | ||
static initializeAnalyzerFromDirectory(dirname) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const config = this.loadConfigFromFile(path.join(dirname, 'polymer.json')) || | ||
new ProjectConfig({}); | ||
return config.initializeAnalyzer(); | ||
}); | ||
} | ||
/** | ||
* Get an analyzer (and other related objects) with configuration determined | ||
* by this ProjectConfig. | ||
*/ | ||
initializeAnalyzer() { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
const urlLoader = new polymer_analyzer_1.FsUrlLoader(this.root); | ||
const urlResolver = new polymer_analyzer_1.PackageUrlResolver({ packageDir: this.root, componentDir: this.componentDir }); | ||
const analyzer = new polymer_analyzer_1.Analyzer({ | ||
urlLoader, | ||
urlResolver, | ||
moduleResolution: convertModuleResolution(this.moduleResolution) | ||
}); | ||
const lintConfig = this.lint || {}; | ||
const warningFilter = new polymer_analyzer_1.WarningFilter({ | ||
minimumSeverity: polymer_analyzer_1.Severity.WARNING, | ||
warningCodesToIgnore: new Set(lintConfig.warningsToIgnore || []), | ||
filesToIgnore: lintConfig.filesToIgnore || [] | ||
}); | ||
return { urlLoader, urlResolver, analyzer, warningFilter }; | ||
}); | ||
} | ||
isFragment(filepath) { | ||
@@ -358,2 +401,5 @@ return this.allFragments.indexOf(filepath) !== -1; | ||
lint: lintObj, | ||
npm: this.npm, | ||
componentDir: this.componentDir, | ||
moduleResolution: this.moduleResolution, | ||
}; | ||
@@ -376,1 +422,16 @@ return JSON.stringify(obj, null, 2); | ||
})(); | ||
/** | ||
* Module resolution in ProjectConfig is different than the same-named parameter | ||
* in the analyzer. So we need to convert between the two. | ||
*/ | ||
function convertModuleResolution(moduleResolution) { | ||
switch (moduleResolution) { | ||
case 'node': | ||
return 'node'; | ||
case 'none': | ||
return undefined; | ||
default: | ||
const never = moduleResolution; | ||
throw new Error(`Unknown module resolution parameter: ${never}`); | ||
} | ||
} |
{ | ||
"name": "polymer-project-config", | ||
"version": "3.10.0", | ||
"version": "3.11.0", | ||
"description": "reads, validates, and shapes your polymer.json project configuration", | ||
@@ -33,4 +33,8 @@ "main": "lib/index.js", | ||
"typescript-json-schema": "^0.9.0", | ||
"clang-format": "1.0.49" | ||
"clang-format": "1.0.49", | ||
"polymer-analyzer": "^3.0.0-pre.17 || ^3.0.0" | ||
}, | ||
"peerDependencies": { | ||
"polymer-analyzer": "^3.0.0-pre.17 || ^3.0.0" | ||
} | ||
} |
@@ -21,2 +21,3 @@ /** | ||
import minimatchAll = require('minimatch-all'); | ||
import {FsUrlLoader, PackageUrlResolver, WarningFilter, Analyzer, Severity} from 'polymer-analyzer'; | ||
@@ -32,3 +33,3 @@ export {ProjectBuildOptions, applyBuildPreset} from './builds'; | ||
export type ModuleResolutionStrategy = 'none'|'node'; | ||
export type ModuleResolutionStrategy = 'none' | 'node'; | ||
const moduleResolutionStrategies = | ||
@@ -294,2 +295,14 @@ new Set<ModuleResolutionStrategy>(['none', 'node']); | ||
/** | ||
* Given a project directory, return an Analyzer (and related objects) with | ||
* configuration inferred from polymer.json (and possibly other config files | ||
* that we find and interpret). | ||
*/ | ||
static async initializeAnalyzerFromDirectory(dirname: string) { | ||
const config = | ||
this.loadConfigFromFile(path.join(dirname, 'polymer.json')) || | ||
new ProjectConfig({}); | ||
return config.initializeAnalyzer(); | ||
} | ||
/** | ||
* constructor - given a ProjectOptions object, create the correct project | ||
@@ -419,2 +432,25 @@ * configuration for those options. This involves setting the correct | ||
/** | ||
* Get an analyzer (and other related objects) with configuration determined | ||
* by this ProjectConfig. | ||
*/ | ||
async initializeAnalyzer() { | ||
const urlLoader = new FsUrlLoader(this.root); | ||
const urlResolver = new PackageUrlResolver( | ||
{packageDir: this.root, componentDir: this.componentDir}); | ||
const analyzer = new Analyzer({ | ||
urlLoader, | ||
urlResolver, | ||
moduleResolution: convertModuleResolution(this.moduleResolution) | ||
}); | ||
const lintConfig: Partial<LintOptions> = this.lint || {}; | ||
const warningFilter = new WarningFilter({ | ||
minimumSeverity: Severity.WARNING, | ||
warningCodesToIgnore: new Set(lintConfig.warningsToIgnore || []), | ||
filesToIgnore: lintConfig.filesToIgnore || [] | ||
}); | ||
return {urlLoader, urlResolver, analyzer, warningFilter}; | ||
} | ||
isFragment(filepath: string): boolean { | ||
@@ -532,2 +568,5 @@ return this.allFragments.indexOf(filepath) !== -1; | ||
lint: lintObj, | ||
npm: this.npm, | ||
componentDir: this.componentDir, | ||
moduleResolution: this.moduleResolution, | ||
}; | ||
@@ -552,1 +591,19 @@ return JSON.stringify(obj, null, 2); | ||
})(); | ||
/** | ||
* Module resolution in ProjectConfig is different than the same-named parameter | ||
* in the analyzer. So we need to convert between the two. | ||
*/ | ||
function convertModuleResolution(moduleResolution: 'node'|'none'): 'node'| | ||
undefined { | ||
switch (moduleResolution) { | ||
case 'node': | ||
return 'node'; | ||
case 'none': | ||
return undefined; | ||
default: | ||
const never: never = moduleResolution; | ||
throw new Error(`Unknown module resolution parameter: ${never}`); | ||
} | ||
} |
@@ -660,2 +660,3 @@ /** | ||
extraDependencies: [], | ||
moduleResolution: 'none', | ||
}); | ||
@@ -679,2 +680,3 @@ }); | ||
extraDependencies: ['extra.html'], | ||
moduleResolution: 'none', | ||
builds: [ | ||
@@ -681,0 +683,0 @@ { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
113834
23
2810
5
6