polymer-project-config
Advanced tools
Comparing version 1.0.2 to 1.1.0
@@ -65,2 +65,7 @@ /** | ||
isShell(filepath: string): boolean; | ||
/** | ||
* Validates that a configuration is accurate, and that all paths are | ||
* contained within the project root. | ||
*/ | ||
validate(): boolean; | ||
} |
@@ -32,2 +32,10 @@ /** | ||
} | ||
function getPositiveGlob(glob) { | ||
if (glob.startsWith('!')) { | ||
return glob.substring(1); | ||
} | ||
else { | ||
return glob; | ||
} | ||
} | ||
/** | ||
@@ -128,3 +136,2 @@ * Given a user-provided options object, check for deprecated options. When one | ||
static loadOptionsFromFile(filepath) { | ||
let configParsed; | ||
try { | ||
@@ -161,3 +168,31 @@ const configContent = fs.readFileSync(filepath, 'utf-8'); | ||
} | ||
/** | ||
* Validates that a configuration is accurate, and that all paths are | ||
* contained within the project root. | ||
*/ | ||
validate() { | ||
const validateErrorPrefix = `Polymer Config Error`; | ||
if (this.entrypoint) { | ||
console.assert(this.entrypoint.startsWith(this.root), `${validateErrorPrefix}: entrypoint (${this.entrypoint}) ` + | ||
`does not resolve within root (${this.root})`); | ||
} | ||
if (this.shell) { | ||
console.assert(this.shell.startsWith(this.root), `${validateErrorPrefix}: shell (${this.shell}) ` + | ||
`does not resolve within root (${this.root})`); | ||
} | ||
this.fragments.forEach((f) => { | ||
console.assert(f.startsWith(this.root), `${validateErrorPrefix}: a "fragments" path (${f}) ` + | ||
`does not resolve within root (${this.root})`); | ||
}); | ||
this.sources.forEach((s) => { | ||
console.assert(getPositiveGlob(s).startsWith(this.root), `${validateErrorPrefix}: a "sources" path (${s}) ` + | ||
`does not resolve within root (${this.root})`); | ||
}); | ||
this.extraDependencies.forEach((d) => { | ||
console.assert(getPositiveGlob(d).startsWith(this.root), `${validateErrorPrefix}: an "extraDependencies" path (${d}) ` + | ||
`does not resolve within root (${this.root})`); | ||
}); | ||
return true; | ||
} | ||
} | ||
exports.ProjectConfig = ProjectConfig; |
{ | ||
"name": "polymer-project-config", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "reads, validates, and shapes your polymer.json project configuration", | ||
@@ -22,2 +22,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@types/node": "^6.0.41", | ||
"plylog": "^0.4.0" | ||
@@ -24,0 +25,0 @@ }, |
@@ -36,2 +36,13 @@ /** | ||
/** | ||
* Returns a positive glob, even if glob is negative (begins with '!') | ||
*/ | ||
function getPositiveGlob(glob: string): string { | ||
if (glob.startsWith('!')) { | ||
return glob.substring(1); | ||
} else { | ||
return glob; | ||
} | ||
} | ||
/** | ||
* Given a user-provided options object, check for deprecated options. When one | ||
@@ -108,3 +119,2 @@ * is found, warn the user and fix if possible. | ||
static loadOptionsFromFile(filepath: string): ProjectOptions { | ||
let configParsed: ProjectOptions; | ||
try { | ||
@@ -222,2 +232,41 @@ const configContent = fs.readFileSync(filepath, 'utf-8'); | ||
/** | ||
* Validates that a configuration is accurate, and that all paths are | ||
* contained within the project root. | ||
*/ | ||
validate(): boolean { | ||
const validateErrorPrefix = `Polymer Config Error`; | ||
if (this.entrypoint) { | ||
console.assert( | ||
this.entrypoint.startsWith(this.root), | ||
`${validateErrorPrefix}: entrypoint (${this.entrypoint}) ` + | ||
`does not resolve within root (${this.root})`); | ||
} | ||
if (this.shell) { | ||
console.assert(this.shell.startsWith(this.root), | ||
`${validateErrorPrefix}: shell (${this.shell}) ` + | ||
`does not resolve within root (${this.root})`); | ||
} | ||
this.fragments.forEach((f) => { | ||
console.assert(f.startsWith(this.root), | ||
`${validateErrorPrefix}: a "fragments" path (${f}) ` + | ||
`does not resolve within root (${this.root})`); | ||
}); | ||
this.sources.forEach((s) => { | ||
console.assert(getPositiveGlob(s).startsWith(this.root), | ||
`${validateErrorPrefix}: a "sources" path (${s}) ` + | ||
`does not resolve within root (${this.root})`); | ||
}); | ||
this.extraDependencies.forEach((d) => { | ||
console.assert(getPositiveGlob(d).startsWith(this.root), | ||
`${validateErrorPrefix}: an "extraDependencies" path (${d}) ` + | ||
`does not resolve within root (${this.root})`); | ||
}); | ||
// TODO(fks) 11-14-2016: Validate that files actually exist in the file | ||
// system. Potentially become async function for this. | ||
return true; | ||
} | ||
} |
@@ -241,2 +241,77 @@ /** | ||
suite('validate()', () => { | ||
test('returns true for valid configuration', () => { | ||
const relativeRoot = 'public'; | ||
const absoluteRoot = path.resolve(relativeRoot); | ||
const config = new ProjectConfig({ | ||
root: relativeRoot, | ||
entrypoint: 'foo.html', | ||
fragments: ['bar.html'], | ||
shell: 'baz.html', | ||
sources: ['src/**/*', 'images/**/*'], | ||
extraDependencies: [ | ||
'bower_components/**/*.js', | ||
], | ||
}); | ||
const validateResult = config.validate(); | ||
assert.isTrue(validateResult); | ||
}); | ||
test('returns true for negative globs that resolve within root', () => { | ||
const relativeRoot = 'public'; | ||
const absoluteRoot = path.resolve(relativeRoot); | ||
const config = new ProjectConfig({ | ||
root: relativeRoot, | ||
sources: [ | ||
'src/**/*', | ||
'images/**/*', | ||
'!images/ignore-some-images', | ||
], | ||
extraDependencies: [ | ||
'bower_components/**/*.js', | ||
'!bower_components/ignore-big-package', | ||
], | ||
}); | ||
const validateResult = config.validate(); | ||
assert.isTrue(validateResult); | ||
}); | ||
test('throws an exception when a fragment does not resolve within root', () => { | ||
const relativeRoot = 'public'; | ||
const absoluteRoot = path.resolve(relativeRoot); | ||
const config = new ProjectConfig({ | ||
root: relativeRoot, | ||
fragments: ['../bar.html'], | ||
}); | ||
assert.throws(() => config.validate(), /AssertionError: Polymer Config Error: a "fragments" path \(.*bar.html\) does not resolve within root \(.*public\)/); | ||
}); | ||
test('throws an exception when entrypoint does not resolve within root', () => { | ||
const relativeRoot = 'public'; | ||
const absoluteRoot = path.resolve(relativeRoot); | ||
const config = new ProjectConfig({ | ||
root: relativeRoot, | ||
entrypoint: '../bar.html', | ||
}); | ||
assert.throws(() => config.validate(), /AssertionError: Polymer Config Error: entrypoint \(.*bar.html\) does not resolve within root \(.*public\)/); | ||
}); | ||
test('throws an exception when shell does not resolve within root', () => { | ||
const relativeRoot = 'public'; | ||
const absoluteRoot = path.resolve(relativeRoot); | ||
const config = new ProjectConfig({ | ||
root: relativeRoot, | ||
shell: '/some/absolute/path/bar.html', | ||
}); | ||
assert.throws(() => config.validate(), /AssertionError: Polymer Config Error: shell \(.*bar.html\) does not resolve within root \(.*public\)/); | ||
}); | ||
}); | ||
}); | ||
@@ -243,0 +318,0 @@ |
{ | ||
"compilerOptions": { | ||
"target": "es6", | ||
"lib": ["es2016"], | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"isolatedModules": false, | ||
"experimentalDecorators": true, | ||
"emitDecoratorMetadata": true, | ||
"declaration": true, | ||
"noUnusedLocals": true, | ||
"noUnusedParameters": true, | ||
"noImplicitAny": true, | ||
"removeComments": false, | ||
"preserveConstEnums": true, | ||
"preserveConstEnums": true, | ||
"suppressImplicitAnyIndexErrors": false, | ||
@@ -17,8 +18,6 @@ "outDir": "lib", | ||
}, | ||
"filesGlob": [ | ||
"node_modules/typescript/lib/lib.es2016.d.ts", | ||
"typings/index.d.ts", | ||
"custom_typings/**", | ||
"src/**" | ||
"include": [ | ||
"custom_typings/**/*.ts", | ||
"src/**/*.ts" | ||
] | ||
} |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
34823
2
15
892
1
+ Added@types/node@^6.0.41
+ Added@types/node@6.14.13(transitive)