Skip to content
This repository was archived by the owner on Dec 1, 2019. It is now read-only.

Emit declaration files into the correct location based on WebPack's context #136

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,17 @@ async function compiler(webpack: IWebPack, text: string): Promise<void> {
}

if (result.declaration) {
webpack.emitFile(
path.relative(process.cwd(), result.declaration.sourceName),
result.declaration.text
const dtsPath: string = loaderUtils.interpolateName(
{
resourcePath: result.declaration.sourceName,
options: webpack.options
},
'[path][name].[ext]',
{
context: webpack.options.context
}
);
webpack.emitFile(dtsPath, result.declaration.text);
}

resultText = result.text;
Expand Down
1 change: 1 addition & 0 deletions src/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ export interface IWebPack {
clearDependencies: () => void;
emitFile: (fileName: string, text: string) => void;
options: {
context: string;
atl?: {
plugins: LoaderPluginDef[]
}
Expand Down
26 changes: 26 additions & 0 deletions src/test/declaration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,30 @@ describe('main test', function() {
// elided import
expect(assets).to.include('src/test/fixtures/declaration/iface.d.ts');
});

it('should emit declaration files in context', async function() {
this.timeout(10000);

let config = {
context: fixturePath(['declaration']),
entry: {
'basic': fixturePath(['declaration', 'basic.ts'])
}
};

let loaderQuery = {
declaration: true
};

let stats = await cleanAndCompile(createConfig(config, { loaderQuery }));
expect(stats.compilation.errors.length).eq(0);

let assets = Object.keys(stats.compilation.assets);

expect(assets).to.include('basic.d.ts');
expect(assets).to.include('basic.js');

// TODO: Code should be changed to output elided import into the correct location
expect(assets).to.include('src/test/fixtures/declaration/iface.d.ts');
});
});