Permalink
Browse files

fix(importer): search for resources from package dist

Previously `au install` and `au import` were looking for resources (css files currently) from the package root, but this should be the package path (the distribution folder of the package) as anything outside of the dist folder is unreachable
  • Loading branch information...
JeroenVinke committed Sep 3, 2017
1 parent 238b863 commit 71ad598dc69d6517a64ee95e1c9600f1e64bd19a
Showing with 23 additions and 26 deletions.
  1. +7 −11 lib/importer/services/resource-inclusion.js
  2. +16 −15 spec/lib/importer/services/resource-inclusion.spec.js
@@ -6,11 +6,12 @@ const glob = require('glob');
let ResourceInclusion = class {
static inject() { return [UI, 'package']; }
static inject() { return [UI, 'package', 'project']; }
constructor(ui, pkg) {
constructor(ui, pkg, project) {
this.ui = ui;
this.package = pkg;
this.project = project;
}
getCSS() {
@@ -57,15 +58,10 @@ let ResourceInclusion = class {
}
getResources(globExpr) {
return this.glob(globExpr, { cwd: this.package.rootPath })
.then(files => files.map(file => {
let directoryFromPath = this.package.path.substring(this.package.path.lastIndexOf('/') + 1);
let directoryFromFile = file.split('/').shift();
if (directoryFromPath === directoryFromFile) {
file = file.substring(file.indexOf('/') + 1);
}
return path.posix.join(file);
}));
const distPath = path.resolve(process.cwd(), this.project.model.paths.root, this.package.path);
return this.glob(globExpr, { cwd: distPath })
.then(files => files.map(file => path.posix.join(file)));
}
glob(globExpr, options) {
@@ -6,6 +6,7 @@ describe('The ResourceInclusion module', () => {
let sut;
let container;
let pkg;
let project;
beforeEach(() => {
mockfs = require('mock-fs');
@@ -19,7 +20,16 @@ describe('The ResourceInclusion module', () => {
path: '../node_modules/some-package'
};
project = {
model: {
paths: {
root: 'src'
}
}
};
container.registerInstance('package', pkg);
container.registerInstance('project', project);
container.registerAlias(FakeUI, UI);
ResourceInclusion = require('../../../../lib/importer/services/resource-inclusion');
@@ -31,7 +41,7 @@ describe('The ResourceInclusion module', () => {
'some-package': {
dist: {
'test.css': 'body { background-color: red }',
output: {
css: {
'test.css': 'body { background-color: red }'
}
}
@@ -41,30 +51,21 @@ describe('The ResourceInclusion module', () => {
});
describe('getResources', () => {
it('returns resource paths from package root', (done) => {
sut.getResources('?(dist|build|lib|css|style|styles)/*.css')
.then(result => {
expect(result[0]).toBe('dist/test.css');
done();
})
.catch(e => done.fail());
});
it('removes duplicate dist', (done) => {
it('returns resources directly under package path (dist folder)', (done) => {
pkg.path = '../node_modules/some-package/dist';
sut.getResources('?(dist|build|lib|css|style|styles)/*.css')
sut.getResources('*.css')
.then(result => {
expect(result[0]).toBe('test.css');
done();
})
.catch(e => done.fail());
});
it('removes duplicate dist (deeper folder structure)', (done) => {
pkg.path = '../node_modules/some-package/dist/output';
it('supports deeper folder structure', (done) => {
pkg.path = '../node_modules/some-package/dist';
sut.getResources('?(dist|build|lib|css|style|styles)/*.css')
.then(result => {
expect(result[0]).toBe('test.css');
expect(result[0]).toBe('css/test.css');
done();
})
.catch(e => done.fail());

0 comments on commit 71ad598

Please sign in to comment.