Skip to content

Commit 71ad598

Browse files
committed
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
1 parent 238b863 commit 71ad598

File tree

2 files changed

+23
-26
lines changed

2 files changed

+23
-26
lines changed

lib/importer/services/resource-inclusion.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ const glob = require('glob');
66

77
let ResourceInclusion = class {
88

9-
static inject() { return [UI, 'package']; }
9+
static inject() { return [UI, 'package', 'project']; }
1010

11-
constructor(ui, pkg) {
11+
constructor(ui, pkg, project) {
1212
this.ui = ui;
1313
this.package = pkg;
14+
this.project = project;
1415
}
1516

1617
getCSS() {
@@ -57,15 +58,10 @@ let ResourceInclusion = class {
5758
}
5859

5960
getResources(globExpr) {
60-
return this.glob(globExpr, { cwd: this.package.rootPath })
61-
.then(files => files.map(file => {
62-
let directoryFromPath = this.package.path.substring(this.package.path.lastIndexOf('/') + 1);
63-
let directoryFromFile = file.split('/').shift();
64-
if (directoryFromPath === directoryFromFile) {
65-
file = file.substring(file.indexOf('/') + 1);
66-
}
67-
return path.posix.join(file);
68-
}));
61+
const distPath = path.resolve(process.cwd(), this.project.model.paths.root, this.package.path);
62+
63+
return this.glob(globExpr, { cwd: distPath })
64+
.then(files => files.map(file => path.posix.join(file)));
6965
}
7066

7167
glob(globExpr, options) {

spec/lib/importer/services/resource-inclusion.spec.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ describe('The ResourceInclusion module', () => {
66
let sut;
77
let container;
88
let pkg;
9+
let project;
910

1011
beforeEach(() => {
1112
mockfs = require('mock-fs');
@@ -19,7 +20,16 @@ describe('The ResourceInclusion module', () => {
1920
path: '../node_modules/some-package'
2021
};
2122

23+
project = {
24+
model: {
25+
paths: {
26+
root: 'src'
27+
}
28+
}
29+
};
30+
2231
container.registerInstance('package', pkg);
32+
container.registerInstance('project', project);
2333
container.registerAlias(FakeUI, UI);
2434

2535
ResourceInclusion = require('../../../../lib/importer/services/resource-inclusion');
@@ -31,7 +41,7 @@ describe('The ResourceInclusion module', () => {
3141
'some-package': {
3242
dist: {
3343
'test.css': 'body { background-color: red }',
34-
output: {
44+
css: {
3545
'test.css': 'body { background-color: red }'
3646
}
3747
}
@@ -41,30 +51,21 @@ describe('The ResourceInclusion module', () => {
4151
});
4252

4353
describe('getResources', () => {
44-
it('returns resource paths from package root', (done) => {
45-
sut.getResources('?(dist|build|lib|css|style|styles)/*.css')
46-
.then(result => {
47-
expect(result[0]).toBe('dist/test.css');
48-
done();
49-
})
50-
.catch(e => done.fail());
51-
});
52-
53-
it('removes duplicate dist', (done) => {
54+
it('returns resources directly under package path (dist folder)', (done) => {
5455
pkg.path = '../node_modules/some-package/dist';
55-
sut.getResources('?(dist|build|lib|css|style|styles)/*.css')
56+
sut.getResources('*.css')
5657
.then(result => {
5758
expect(result[0]).toBe('test.css');
5859
done();
5960
})
6061
.catch(e => done.fail());
6162
});
6263

63-
it('removes duplicate dist (deeper folder structure)', (done) => {
64-
pkg.path = '../node_modules/some-package/dist/output';
64+
it('supports deeper folder structure', (done) => {
65+
pkg.path = '../node_modules/some-package/dist';
6566
sut.getResources('?(dist|build|lib|css|style|styles)/*.css')
6667
.then(result => {
67-
expect(result[0]).toBe('test.css');
68+
expect(result[0]).toBe('css/test.css');
6869
done();
6970
})
7071
.catch(e => done.fail());

0 commit comments

Comments
 (0)