Skip to content

Commit

Permalink
fix(bundle): fix directory index resolution
Browse files Browse the repository at this point in the history
Closes #537
  • Loading branch information
adamdbradley committed Feb 15, 2018
1 parent fe213a0 commit 605aa54
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
7 changes: 3 additions & 4 deletions src/compiler/bundle/rollup-plugins/local-resolution.ts
Expand Up @@ -2,9 +2,9 @@ import { CompilerCtx, Config } from '../../../declarations';
import { normalizePath } from '../../util';


export default function localResolver(config: Config, compilerCtx: CompilerCtx) {
export default function localResolution(config: Config, compilerCtx: CompilerCtx) {
return {
name: 'localResolverPlugin',
name: 'localResolution',

async resolveId(importee: string, importer: string) {
importee = normalizePath(importee);
Expand All @@ -28,9 +28,8 @@ export default function localResolver(config: Config, compilerCtx: CompilerCtx)
const dirIndexFile = config.sys.path.join(directory + importee, 'index.js');

let stats;

try {
stats = await compilerCtx.fs.stat(importee);
stats = await compilerCtx.fs.stat(dirIndexFile);
} catch (e) {
return null;
}
Expand Down
33 changes: 32 additions & 1 deletion src/compiler/bundle/test/bundle.spec.ts
Expand Up @@ -10,11 +10,42 @@ describe('bundle', () => {

beforeEach(async () => {
c = new TestingCompiler();
await c.fs.writeFile('/src/index.html', `<cmp-a></cmp-a>`);
await c.fs.commit();
});


it('should resolve directory index w/ exports', async () => {
c.config.bundles = [ { components: ['x-bar']} ];
await c.fs.writeFiles({
'/src/components/bar/bar.tsx': `
import { foo } from '../../utils';
@Component({
tag: 'x-bar'
})
export class Bar {
render() {
foo();
return <div/>;
}
}
`,
'/src/utils/index.ts': `
export * from './foo';
`,
'/src/utils/foo.ts': `
export const foo = () => {
console.log('foo');
};
`,
}, { clearFileCache: true });

await c.fs.commit();

const r = await c.build();
expect(r.diagnostics).toEqual([]);

});

it('wildcard imports should remain within component files', async () => {
c.config.bundles = [ { components: ['cmp-a']}, { components: ['cmp-b'] } ];
await c.fs.writeFiles({
Expand Down

0 comments on commit 605aa54

Please sign in to comment.