@retailmenot/roux
Advanced tools
Comparing version 1.0.4 to 2.0.0
254
index.js
@@ -152,52 +152,52 @@ 'use strict'; | ||
}) | ||
.then(function (pantryStats) { | ||
if (!pantryStats.isDirectory()) { | ||
throw new PantryNotADirectoryError(pantryBasePath); | ||
} | ||
}) | ||
.then(function () { | ||
.then(function (pantryStats) { | ||
if (!pantryStats.isDirectory()) { | ||
throw new PantryNotADirectoryError(pantryBasePath); | ||
} | ||
}) | ||
.then(function () { | ||
// if package.json exists in the pantry root directory and the | ||
// roux.pantryRoot key exists, resolve that path from the pantry root to | ||
// determine the actual directory that ingredients live under. | ||
var packageJsonPath = path.join(pantryBasePath, 'package.json'); | ||
return fs.readFileAsync(packageJsonPath) | ||
.then(function (packageJsonBuffer) { | ||
var packageJson = JSON.parse(packageJsonBuffer); | ||
var packageJsonPath = path.join(pantryBasePath, 'package.json'); | ||
return fs.readFileAsync(packageJsonPath) | ||
.then(function (packageJsonBuffer) { | ||
var packageJson = JSON.parse(packageJsonBuffer); | ||
if (_.isString(packageJson.roux.pantryRoot)) { | ||
pantryPathPrefix = packageJson.roux.pantryRoot; | ||
return path.join(pantryBasePath, pantryPathPrefix); | ||
} | ||
if (_.isString(packageJson.roux.pantryRoot)) { | ||
pantryPathPrefix = packageJson.roux.pantryRoot; | ||
return path.join(pantryBasePath, pantryPathPrefix); | ||
} | ||
return pantryBasePath; | ||
}) | ||
.catch(function () { | ||
return pantryBasePath; | ||
return pantryBasePath; | ||
}) | ||
.catch(function () { | ||
return pantryBasePath; | ||
}); | ||
}) | ||
.then(function (pantryPath) { | ||
pantryConfig.path = pantryPath; | ||
return globAsync('**/ingredient.md', { | ||
cwd: pantryPath, | ||
strict: true | ||
}); | ||
}) | ||
.then(function (pantryPath) { | ||
pantryConfig.path = pantryPath; | ||
return globAsync('**/ingredient.md', { | ||
cwd: pantryPath, | ||
strict: true | ||
}); | ||
}) | ||
.then(function (ingredients) { | ||
var ingredientPaths = []; | ||
}) | ||
.then(function (ingredients) { | ||
var ingredientPaths = []; | ||
pantryConfig.ingredients = _.chain(ingredients) | ||
.map(function (ingredient) { | ||
pantryConfig.ingredients = _.chain(ingredients) | ||
.map(function (ingredient) { | ||
// we get foo/bar/ingredient.md and need foo/bar | ||
var ingredientPath = path.resolve( | ||
pantryBasePath, | ||
pantryPathPrefix, | ||
pathParse(ingredient).dir | ||
); | ||
var ingredientPath = path.resolve( | ||
pantryBasePath, | ||
pantryPathPrefix, | ||
pathParse(ingredient).dir | ||
); | ||
// save the path for detecting nested ingredients | ||
ingredientPaths.push(ingredientPath); | ||
// save the path for detecting nested ingredients | ||
ingredientPaths.push(ingredientPath); | ||
return ingredientPath; | ||
}) | ||
.filter(function (ingredientPathToFilter) { | ||
return ingredientPath; | ||
}) | ||
.filter(function (ingredientPathToFilter) { | ||
// to verify that a given ingredient is not nested in any other | ||
@@ -207,46 +207,46 @@ // ingredient, we check that the given ingredient's path does not | ||
// avoid false positives like this: path/to/foo and path/to/foobar | ||
return _.every(ingredientPaths, function (ingredientPath) { | ||
return !_.startsWith( | ||
ingredientPathToFilter, | ||
ingredientPath + path.sep | ||
return _.every(ingredientPaths, function (ingredientPath) { | ||
return !_.startsWith( | ||
ingredientPathToFilter, | ||
ingredientPath + path.sep | ||
); | ||
}); | ||
}) | ||
.reduce(function (result, ingredient) { | ||
var name = path.relative( | ||
path.join(pantryBasePath, pantryPathPrefix), | ||
ingredient | ||
); | ||
}); | ||
}) | ||
.reduce(function (result, ingredient) { | ||
var name = path.relative( | ||
path.join(pantryBasePath, pantryPathPrefix), | ||
ingredient | ||
); | ||
result[name] = new Ingredient({ | ||
name: name, | ||
path: ingredient, | ||
pantryName: config.name, | ||
entryPoints: {} | ||
}); | ||
result[name] = new Ingredient({ | ||
name: name, | ||
path: ingredient, | ||
pantryName: config.name, | ||
entryPoints: {} | ||
}); | ||
return result; | ||
}, | ||
{}) | ||
.value(); | ||
return result; | ||
}, | ||
{}) | ||
.value(); | ||
return Promise.all( | ||
_.map(pantryConfig.ingredients, | ||
function (ingredient) { | ||
return Promise.all( | ||
_.map(pantryConfig.ingredients, | ||
function (ingredient) { | ||
// for each predicate, call it with the ingredient path | ||
return Promise.all( | ||
_.map(config.predicates, function (predicate, predicateName) { | ||
return hasEntryPointAsync(ingredient.path, predicate) | ||
.then(function (result) { | ||
ingredient.entryPoints[predicateName] = result; | ||
}); | ||
}) | ||
); | ||
}) | ||
return Promise.all( | ||
_.map(config.predicates, function (predicate, predicateName) { | ||
return hasEntryPointAsync(ingredient.path, predicate) | ||
.then(function (result) { | ||
ingredient.entryPoints[predicateName] = result; | ||
}); | ||
}) | ||
); | ||
}) | ||
) | ||
.then(function () { | ||
return new Pantry(pantryConfig); | ||
} | ||
); | ||
}); | ||
.then(function () { | ||
return new Pantry(pantryConfig); | ||
} | ||
); | ||
}); | ||
@@ -390,60 +390,60 @@ if (typeof callback === 'function') { | ||
}) | ||
.then(function (pantryInstance) { | ||
assert( | ||
Pantry.isPantry(pantryInstance), | ||
util.format( | ||
'Pantry must be a pantry. Got: %s', | ||
typeof pantryInstance | ||
) | ||
); | ||
.then(function (pantryInstance) { | ||
assert( | ||
Pantry.isPantry(pantryInstance), | ||
util.format( | ||
'Pantry must be a pantry. Got: %s', | ||
typeof pantryInstance | ||
) | ||
); | ||
if (!ingredient) { | ||
if (!ingredient) { | ||
// we are resolving a pantry, so we're done | ||
return pantryInstance; | ||
} | ||
return pantryInstance; | ||
} | ||
if (!pantryInstance.ingredients.hasOwnProperty(ingredient)) { | ||
throw new IngredientDoesNotExistError(pantry, ingredient); | ||
} | ||
if (!pantryInstance.ingredients.hasOwnProperty(ingredient)) { | ||
throw new IngredientDoesNotExistError(pantry, ingredient); | ||
} | ||
var ingredientInstance = pantryInstance.ingredients[ingredient]; | ||
var ingredientInstance = pantryInstance.ingredients[ingredient]; | ||
if (!entryPoint) { | ||
if (!entryPoint) { | ||
// we are resolving an ingredient, so we're done | ||
return ingredientInstance; | ||
} | ||
return ingredientInstance; | ||
} | ||
if (!ingredientInstance.entryPoints[entryPoint]) { | ||
throw new IngredientHasNoSuchEntrypointError( | ||
pantry, | ||
ingredient, | ||
entryPoint | ||
if (!ingredientInstance.entryPoints[entryPoint]) { | ||
throw new IngredientHasNoSuchEntrypointError( | ||
pantry, | ||
ingredient, | ||
entryPoint | ||
); | ||
} | ||
return path.join( | ||
ingredientInstance.path, | ||
ingredientInstance.entryPoints[entryPoint].filename | ||
); | ||
} | ||
return path.join( | ||
ingredientInstance.path, | ||
ingredientInstance.entryPoints[entryPoint].filename | ||
); | ||
}) | ||
.catch(function (error) { | ||
debug('got error', error); | ||
debug(error.stack); | ||
if (error instanceof Promise.AggregateError) { | ||
if (_.every(error, function (e) { | ||
}) | ||
.catch(function (error) { | ||
debug('got error', error); | ||
debug(error.stack); | ||
if (error instanceof Promise.AggregateError) { | ||
if (_.every(error, function (e) { | ||
// Ensure that every error is a PantryDoesNotExistError | ||
// and if so throw the first instance of that error. | ||
// Otherwise, just throw the aggregate error. | ||
return e instanceof PantryDoesNotExistError; | ||
})) { | ||
throw error[0]; | ||
} else if (_.every(error, function (e) { | ||
return e instanceof PantryDoesNotExistError; | ||
})) { | ||
throw error[0]; | ||
} else if (_.every(error, function (e) { | ||
// Do the same thing for PantryNotADirectoryError | ||
return e instanceof PantryNotADirectoryError; | ||
})) { | ||
throw error[0]; | ||
return e instanceof PantryNotADirectoryError; | ||
})) { | ||
throw error[0]; | ||
} | ||
} | ||
} | ||
throw error; | ||
}); | ||
throw error; | ||
}); | ||
} | ||
@@ -462,7 +462,7 @@ | ||
return initialize(config) | ||
.then(function (initializedPantry) { | ||
.then(function (initializedPantry) { | ||
// cache the pantry for next time | ||
pantryCache[config.name] = initializedPantry; | ||
return initializedPantry; | ||
}); | ||
pantryCache[config.name] = initializedPantry; | ||
return initializedPantry; | ||
}); | ||
} | ||
@@ -469,0 +469,0 @@ |
{ | ||
"name": "@retailmenot/roux", | ||
"version": "1.0.4", | ||
"version": "2.0.0", | ||
"description": "Roux SDK and specification", | ||
@@ -15,3 +15,3 @@ "main": "index.js", | ||
"engines": { | ||
"node": ">= 4" | ||
"node": ">=8" | ||
}, | ||
@@ -24,2 +24,5 @@ "keywords": [ | ||
"author": "RMN Engineering", | ||
"maintainers": [ | ||
"Ray Pierce <rpierce@rmn.com>" | ||
], | ||
"contributors": [ | ||
@@ -29,3 +32,4 @@ "Elyse Holladay <eholladay@rmn.com>", | ||
"Kyle Smith <kbsmith@rmn.com>", | ||
"Luke Zilioli <lzilioli@rmn.com>" | ||
"Luke Zilioli <lzilioli@rmn.com>", | ||
"Ray Pierce <rpierce@rmn.com>" | ||
], | ||
@@ -35,18 +39,18 @@ "license": "MIT", | ||
"@retailmenot/core-ui-editorconfig": "^1.0.2", | ||
"@retailmenot/core-ui-eslintrc": "^4.0.0", | ||
"eslint": "^2.11.1", | ||
"mock-fs": "^3.6.0", | ||
"mockery": "^1.4.0", | ||
"sinon": "^1.17.2", | ||
"tap": "^2.2.0" | ||
"@retailmenot/core-ui-eslintrc": "^7.0.0", | ||
"eslint": "^5.16.0", | ||
"mock-fs": "^4.9.0", | ||
"mockery": "^2.1.0", | ||
"sinon": "^7.3.2", | ||
"tap": "^13.0.3" | ||
}, | ||
"dependencies": { | ||
"bluebird": "^3.0.5", | ||
"bluebird": "^3.5.4", | ||
"core-error-predicates": "^1.1.0", | ||
"debug": "^2.2.0", | ||
"glob": "^6.0.1", | ||
"lodash": "^3.10.1", | ||
"debug": "^4.1.0", | ||
"glob": "^6.0.4", | ||
"lodash": "^4.17.11", | ||
"path-parse": "^1.0.5", | ||
"validate-npm-package-name": "^2.2.2" | ||
"validate-npm-package-name": "^3.0.0" | ||
} | ||
} |
@@ -41,3 +41,7 @@ 'use strict'; | ||
t.type(initialize, 'function', 'exports an initialize method'); | ||
t.type( | ||
initialize, | ||
'function', | ||
'exports an initialize method' | ||
); | ||
@@ -298,10 +302,12 @@ t.test('initialize', function (t) { | ||
t.equals(pantry, undefined, 'pantry should be undefined'); | ||
t.end(); | ||
}) | ||
.catch(function (e) { | ||
if (e.code !== 'ENOENT') { | ||
if (!e.message.match(/Pantry .* does not exist\.$/)) { | ||
throw e; | ||
} | ||
}) | ||
.finally(restoreMockFS); | ||
.finally(function () { | ||
restoreMockFS(); | ||
t.end(); | ||
}); | ||
}); | ||
@@ -778,3 +784,3 @@ }); | ||
); | ||
Ingredient.isValidName.reset(); | ||
Ingredient.isValidName.resetHistory(); | ||
parseIngredientPath('@namespace/pantry/ingredient'); | ||
@@ -798,3 +804,3 @@ t.ok( | ||
Pantry.isValidName.reset(); | ||
Pantry.isValidName.resetHistory(); | ||
expected = '@namespace/pantry'; | ||
@@ -1170,5 +1176,5 @@ parseIngredientPath('@namespace/pantry/ingredient'); | ||
}) | ||
.then(function (actual) { | ||
t.same(actual, expected, 'resolves to cached pantry'); | ||
}); | ||
.then(function (actual) { | ||
t.same(actual, expected, 'resolves to cached pantry'); | ||
}); | ||
}); | ||
@@ -1193,6 +1199,6 @@ | ||
}) | ||
.then(function (actual) { | ||
t.type(actual, Pantry, 'looks up pantry in search paths'); | ||
}) | ||
.finally(restoreMockFS); | ||
.then(function (actual) { | ||
t.type(actual, Pantry, 'looks up pantry in search paths'); | ||
}) | ||
.finally(restoreMockFS); | ||
}); | ||
@@ -1208,6 +1214,6 @@ | ||
}) | ||
.catch(function (error) { | ||
t.type(error, Error, 'resolves with an error if not found'); | ||
}) | ||
.finally(restoreMockFS); | ||
.catch(function (error) { | ||
t.type(error, Error, 'resolves with an error if not found'); | ||
}) | ||
.finally(restoreMockFS); | ||
}); | ||
@@ -1239,6 +1245,6 @@ }); | ||
}) | ||
.then(function (actual) { | ||
t.type(actual, Pantry, 'resolves string to pantry'); | ||
}) | ||
.finally(restoreMockFS); | ||
.then(function (actual) { | ||
t.type(actual, Pantry, 'resolves string to pantry'); | ||
}) | ||
.finally(restoreMockFS); | ||
}); | ||
@@ -1264,7 +1270,7 @@ | ||
return resolve('pantry', config) | ||
.then(function (actual) { | ||
t.type(config.pantries.pantry, Pantry, 'modifies the cache'); | ||
t.same(config.pantries.pantry, actual, 'modifies the cache'); | ||
}) | ||
.finally(restoreMockFS); | ||
.then(function (actual) { | ||
t.type(config.pantries.pantry, Pantry, 'modifies the cache'); | ||
t.same(config.pantries.pantry, actual, 'modifies the cache'); | ||
}) | ||
.finally(restoreMockFS); | ||
}); | ||
@@ -1290,9 +1296,9 @@ }); | ||
}) | ||
.then(function (actual) { | ||
t.same( | ||
actual, | ||
expected.ingredients.ingredient, | ||
'resolves to ingredient from cached pantry' | ||
); | ||
}); | ||
.then(function (actual) { | ||
t.same( | ||
actual, | ||
expected.ingredients.ingredient, | ||
'resolves to ingredient from cached pantry' | ||
); | ||
}); | ||
}); | ||
@@ -1318,6 +1324,6 @@ | ||
}) | ||
.then(function (actual) { | ||
t.type(actual, Ingredient, 'looks up ingredient in search paths'); | ||
}) | ||
.finally(restoreMockFS); | ||
.then(function (actual) { | ||
t.type(actual, Ingredient, 'looks up ingredient in search paths'); | ||
}) | ||
.finally(restoreMockFS); | ||
}); | ||
@@ -1339,6 +1345,6 @@ | ||
}) | ||
.catch(function (error) { | ||
t.type(error, Error, 'resolves with an error if not found'); | ||
}) | ||
.finally(restoreMockFS); | ||
.catch(function (error) { | ||
t.type(error, Error, 'resolves with an error if not found'); | ||
}) | ||
.finally(restoreMockFS); | ||
}); | ||
@@ -1365,6 +1371,6 @@ | ||
}) | ||
.catch(function (error) { | ||
t.type(error, pantryErrors.PantryDoesNotExistError, 'rejects with a PantryDoesNotExistError if pantry not found'); | ||
}) | ||
.finally(restoreMockFS); | ||
.catch(function (error) { | ||
t.type(error, pantryErrors.PantryDoesNotExistError, 'rejects with a PantryDoesNotExistError if pantry not found'); | ||
}) | ||
.finally(restoreMockFS); | ||
}); | ||
@@ -1382,6 +1388,6 @@ | ||
}) | ||
.catch(function (error) { | ||
t.type(error, pantryErrors.PantryNotADirectoryError, 'rejects with a PantryNotADirectoryError if pantry found but not a directory'); | ||
}) | ||
.finally(restoreMockFS); | ||
.catch(function (error) { | ||
t.type(error, pantryErrors.PantryNotADirectoryError, 'rejects with a PantryNotADirectoryError if pantry found but not a directory'); | ||
}) | ||
.finally(restoreMockFS); | ||
}); | ||
@@ -1403,6 +1409,6 @@ | ||
}) | ||
.catch(function (error) { | ||
t.type(error, pantryErrors.IngredientDoesNotExistError, 'rejects with a IngredientDoesNotExistError if ingredient not found'); | ||
}) | ||
.finally(restoreMockFS); | ||
.catch(function (error) { | ||
t.type(error, pantryErrors.IngredientDoesNotExistError, 'rejects with a IngredientDoesNotExistError if ingredient not found'); | ||
}) | ||
.finally(restoreMockFS); | ||
}); | ||
@@ -1412,16 +1418,16 @@ | ||
'ingredient entryPoint not found', | ||
function (t) { | ||
mockfs({ | ||
resolve: { | ||
pantry: { | ||
ingredient: { | ||
'ingredient.md': '' | ||
} | ||
function (t) { | ||
mockfs({ | ||
resolve: { | ||
pantry: { | ||
ingredient: { | ||
'ingredient.md': '' | ||
} | ||
} | ||
}); | ||
} | ||
}); | ||
return resolve('pantry', 'ingredient', 'handlebars', { | ||
pantrySearchPaths: [path.resolve('resolve')] | ||
}) | ||
return resolve('pantry', 'ingredient', 'handlebars', { | ||
pantrySearchPaths: [path.resolve('resolve')] | ||
}) | ||
.catch(function (error) { | ||
@@ -1436,3 +1442,3 @@ t.type( | ||
.finally(restoreMockFS); | ||
} | ||
} | ||
); | ||
@@ -1464,9 +1470,9 @@ }); | ||
}) | ||
.then(function (actual) { | ||
t.same( | ||
actual, | ||
expected, | ||
'resolves to the entry point from the cached pantry' | ||
); | ||
}); | ||
.then(function (actual) { | ||
t.same( | ||
actual, | ||
expected, | ||
'resolves to the entry point from the cached pantry' | ||
); | ||
}); | ||
}); | ||
@@ -1493,6 +1499,6 @@ | ||
}) | ||
.then(function (actual) { | ||
t.equal(actual, expected, 'looks up entry point in search paths'); | ||
}) | ||
.finally(restoreMockFS); | ||
.then(function (actual) { | ||
t.equal(actual, expected, 'looks up entry point in search paths'); | ||
}) | ||
.finally(restoreMockFS); | ||
}); | ||
@@ -1514,6 +1520,6 @@ | ||
}) | ||
.catch(function (error) { | ||
t.type(error, Error, 'resolves with an error if not found'); | ||
}) | ||
.finally(restoreMockFS); | ||
.catch(function (error) { | ||
t.type(error, Error, 'resolves with an error if not found'); | ||
}) | ||
.finally(restoreMockFS); | ||
}); | ||
@@ -1520,0 +1526,0 @@ }); |
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
71010
2042
12
+ Addedbuiltins@1.0.3(transitive)
+ Addeddebug@4.4.0(transitive)
+ Addedlodash@4.17.21(transitive)
+ Addedms@2.1.3(transitive)
+ Addedvalidate-npm-package-name@3.0.0(transitive)
- Removedbuiltins@0.0.7(transitive)
- Removeddebug@2.6.9(transitive)
- Removedlodash@3.10.1(transitive)
- Removedms@2.0.0(transitive)
- Removedvalidate-npm-package-name@2.2.2(transitive)
Updatedbluebird@^3.5.4
Updateddebug@^4.1.0
Updatedglob@^6.0.4
Updatedlodash@^4.17.11