Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@namics/nitro-component-resolver

Package Overview
Dependencies
Maintainers
2
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@namics/nitro-component-resolver - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

CHANGELOG.md

0

.eslintrc.js
module.exports = require('@namics/eslint-config/configurations/es6-node.js');
module.exports.parser = 'babel-eslint';
module.exports.plugins = ['import'];

@@ -16,2 +16,3 @@ /**

const options = _.extend({
watch: true,
examples: false,

@@ -28,2 +29,3 @@ readme: true,

cwd: options.rootDirectory,
hot: options.watch,
/*

@@ -57,2 +59,3 @@ * Process the pattern.json files when load into the file cache

cwd: options.rootDirectory,
hot: options.watch,
/*

@@ -78,2 +81,3 @@ * Process the examle files when load into the file cache

cwd: options.rootDirectory,
hot: options.watch,
/*

@@ -90,2 +94,7 @@ * Process the readme.md files when load into the file cache

// Auto invalidation of readmes if an example changes
if (options.readme && options.examples) {
exampleFiles.on('cache-revoked', () => readmeFiles.invalidateEntireCache());
}
/**

@@ -92,0 +101,0 @@ * @return {object} a key value pair list for all parsed pattern.json files:

9

package.json
{
"name": "@namics/nitro-component-resolver",
"version": "0.0.1",
"version": "0.0.2",
"description": "A helper to resolve and parse the nitro pattern structure and meta files",

@@ -30,3 +30,3 @@ "main": "index.js",

"dependencies": {
"hot-file-cache": "0.0.7",
"hot-file-cache": "0.0.9",
"lodash": "^4.13.1"

@@ -41,5 +41,8 @@ },

"eslint-plugin-import": "^1.9.2",
"mkdirp": "^0.5.1",
"ncp": "^2.0.0",
"npm-run-all": "^2.2.2",
"nyc": "^6.6.1"
"nyc": "^6.6.1",
"rimraf": "^2.5.2"
}
}
# Nitro Component Resolver
[![npm version](https://badge.fury.io/js/%40namics%2Fnitro-component-resolver.svg)](https://badge.fury.io/js/%40namics%2Fnitro-component-resolver)
[![Build Status](https://travis-ci.org/namics/nitro-component-resolver.svg?branch=master)](https://travis-ci.org/namics/nitro-component-resolver)

@@ -23,3 +24,5 @@ [![Coverage Status](https://coveralls.io/repos/github/namics/nitro-component-resolver/badge.svg?branch=master)](https://coveralls.io/github/namics/nitro-component-resolver?branch=master)

// Example lookup
examples: true
examples: true,
// File watch mode
watch: true
});

@@ -26,0 +29,0 @@ resolver.getComponents()

@@ -1,9 +0,22 @@

/* eslint max-len: off, quotes:off */
/* eslint max-len: off, quotes:off, no-param-reassign: off */
import test from 'ava';
import path from 'path';
import denodeify from 'denodeify';
import ComponentResolver from '..';
const rootDirectories = {
valid: path.resolve(__dirname, 'fixtures', 'valid', 'components'),
invalid: path.resolve(__dirname, 'fixtures', 'invalid', 'components'),
const copy = denodeify(require('ncp').ncp);
const mkdirp = denodeify(require('mkdirp'));
const rimraf = denodeify(require('rimraf'));
const unlink = denodeify(require('fs').unlink);
const sleep = (duration) => new Promise((resolve) => setTimeout(resolve, duration));
const tmp = path.resolve(__dirname, '..', 'tmp', 'testing');
let testDirId = 0;
const createTestEnvironment = async(environment = 'valid') => {
const targetDir = path.resolve(tmp, `test-${testDirId++}`);
const componentDir = path.join(targetDir, 'components');
await mkdirp(targetDir);
await copy(path.resolve(__dirname, 'fixtures', environment), targetDir);
return componentDir;
};

@@ -21,4 +34,5 @@

test('should list all components of the given folder', async t => {
const rootDir = await createTestEnvironment('valid');
const resolver = new ComponentResolver({
rootDirectory: rootDirectories.valid
rootDirectory: rootDir
});

@@ -32,4 +46,5 @@ const componentNames = Object.keys(await resolver.getComponents());

test('should throw if a JSON contains errors', async t => {
const rootDir = await createTestEnvironment('invalid');
const resolver = new ComponentResolver({
rootDirectory: rootDirectories.invalid
rootDirectory: rootDir
});

@@ -39,5 +54,4 @@ const err = await getErrorMessage(async() => {

});
const invalidJsonFile = path.resolve(rootDirectories.invalid, 'atoms/button/pattern.json');
const expectedError = `Failed to parse \"${invalidJsonFile}\" SyntaxError: Unexpected end of input`;
t.is(err, expectedError);
const invalidJsonFile = path.resolve(rootDir, 'atoms/button/pattern.json');
t.regex(err, new RegExp(`^Failed to parse "${invalidJsonFile}" SyntaxError: Unexpected end`));
t.pass();

@@ -47,6 +61,7 @@ });

test('should fail listing examples if examples is set to false', async t => {
const rootDir = await createTestEnvironment('valid');
const resolver = new ComponentResolver({
rootDirectory: rootDirectories.valid
rootDirectory: rootDir
});
const buttonDirectory = path.resolve(rootDirectories.valid, 'atoms/button');
const buttonDirectory = path.resolve(rootDir, 'atoms/button');
const err = await getErrorMessage(async() => {

@@ -59,9 +74,10 @@ await resolver.getComponentExamples(buttonDirectory);

test('should return component', async t => {
const rootDir = await createTestEnvironment('valid');
const resolver = new ComponentResolver({
rootDirectory: rootDirectories.valid
rootDirectory: rootDir
});
const component = await resolver.getComponent('atoms/button');
t.deepEqual(component, {
metaFile: path.resolve(rootDirectories.valid, 'atoms/button/pattern.json'),
directory: path.resolve(rootDirectories.valid, 'atoms/button'),
metaFile: path.resolve(rootDir, 'atoms/button/pattern.json'),
directory: path.resolve(rootDir, 'atoms/button'),
path: 'atoms/button',

@@ -81,7 +97,8 @@ type: 'atoms',

test('should list examples', async t => {
const rootDir = await createTestEnvironment('valid');
const resolver = new ComponentResolver({
rootDirectory: rootDirectories.valid,
rootDirectory: rootDir,
examples: true
});
const buttonDirectory = path.resolve(rootDirectories.valid, 'atoms/button');
const buttonDirectory = path.resolve(rootDir, 'atoms/button');
const examples = await resolver.getComponentExamples(buttonDirectory);

@@ -103,4 +120,5 @@ t.deepEqual(examples, [{

test('should throw on unkown component', async t => {
const rootDir = await createTestEnvironment('valid');
const resolver = new ComponentResolver({
rootDirectory: rootDirectories.valid,
rootDirectory: rootDir
});

@@ -115,4 +133,5 @@ const err = await getErrorMessage(async() => {

test('should throw if trying to access deactivated readme', async t => {
const rootDir = await createTestEnvironment('valid');
const resolver = new ComponentResolver({
rootDirectory: rootDirectories.valid,
rootDirectory: rootDir,
readme: false

@@ -128,7 +147,8 @@ });

test('should return not readmde if no file exists', async t => {
const rootDir = await createTestEnvironment('valid');
const resolver = new ComponentResolver({
rootDirectory: rootDirectories.valid,
rootDirectory: rootDir,
readme: true
});
const buttonDirectory = path.resolve(rootDirectories.valid, 'atoms/button');
const buttonDirectory = path.resolve(rootDir, 'atoms/button');
const readme = await resolver.getComponentReadme(buttonDirectory);

@@ -140,7 +160,8 @@ t.is(readme, undefined);

test('should return readmde', async t => {
const rootDir = await createTestEnvironment('valid');
const resolver = new ComponentResolver({
rootDirectory: rootDirectories.valid,
rootDirectory: rootDir,
readme: true
});
const typographyDirectory = path.resolve(rootDirectories.valid, 'helper/typography');
const typographyDirectory = path.resolve(rootDir, 'helper/typography');
const readme = await resolver.getComponentReadme(typographyDirectory);

@@ -154,1 +175,47 @@ t.deepEqual(readme, {

test('should load the readmde from cache', async t => {
const rootDir = await createTestEnvironment('valid');
let renderIndex = 0;
const resolver = new ComponentResolver({
rootDirectory: rootDir,
readme: true,
readmeRenderer: (resolverInstance, renderData) => {
renderData.content = ++renderIndex;
return renderData;
}
});
const typographyDirectory = path.resolve(rootDir, 'helper/typography');
const readme = await resolver.getComponentReadme(typographyDirectory);
t.is(readme.content, 1);
const readme2 = await resolver.getComponentReadme(typographyDirectory);
t.is(readme, readme2);
t.pass();
});
test('should invalidate the readme cache when changing an example', async t => {
const rootDir = await createTestEnvironment('valid');
let renderIndex = 0;
const resolver = new ComponentResolver({
rootDirectory: rootDir,
readme: true,
examples: true,
readmeRenderer: (resolverInstance, renderData) => {
renderData.content = ++renderIndex;
return renderData;
}
});
const typographyDirectory = path.resolve(rootDir, 'helper/typography');
const readme = await resolver.getComponentReadme(typographyDirectory);
await resolver.getComponentExamples(typographyDirectory);
t.is(readme.content, 1);
await unlink(path.join(typographyDirectory, '_example', 'small.hbs'));
await sleep(200);
const readme2 = await resolver.getComponentReadme(typographyDirectory);
t.is(readme2.content, 2);
t.pass();
});
test.after.always('cleanup', async () => {
await rimraf(tmp);
});

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc