Skip to content

Commit

Permalink
Merge pull request #2 from DevWurm/bugfix/unnormalized-asset-paths
Browse files Browse the repository at this point in the history
Bugfix/unnormalized asset paths
  • Loading branch information
DevWurm committed Apr 28, 2017
2 parents 984d5f3 + d66f658 commit e146ada
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "webpack-war-plugin",
"version": "1.0.0-beta.1",
"version": "1.0.0-beta.2",
"description": "Webpack plugin for bundling build outputs into a WAR archive",
"main": "dist/index.js",
"types": "dist/index.d.ts",
Expand Down
30 changes: 30 additions & 0 deletions src/WebpackWarPlugin.spec.ts
Expand Up @@ -144,6 +144,36 @@ describe('WebpackWarPlugin', function () {
assert.calledWith(spyAppend, resolve((compiler as any).options.output.path, asset), { name: asset }));
});

it('Should normalize asset paths', function () {
const ArchiverDummy = {
append: (() => null),
pipe: (() => null),
on: (() => null),
finalize: (() => null)
};
const spyAppend = spy(ArchiverDummy, 'append');

const assets = {
'./asset1.txt': {},
'./assets/./asset2.txt': {}
};

compilation.assets = assets;

const plugin = new WebpackWarPlugin({ archiveName: 'Test' });
(plugin as any).archiver = (() => ArchiverDummy);
plugin.apply(compiler);

assert.calledWith(spyAppend,
resolve((compiler as any).options.output.path, Object.getOwnPropertyNames(assets)[0]),
{ name: 'asset1.txt' }
);
assert.calledWith(spyAppend,
resolve((compiler as any).options.output.path, Object.getOwnPropertyNames(assets)[1]),
{ name: 'assets/asset2.txt' }
);
});

it('Should add the WEB-INF folder to the archive', function () {
const ArchiverStub = {
append: (() => null),
Expand Down
2 changes: 1 addition & 1 deletion src/WebpackWarPlugin.ts
Expand Up @@ -42,7 +42,7 @@ export class WebpackWarPlugin implements Plugin {

Object.getOwnPropertyNames(compilation.assets).forEach(asset => {
const srcPath = resolve(outputPath, asset);
archive.append(srcPath, { name: asset });
archive.append(srcPath, { name: normalize(asset) });
});

additionalElements.forEach(({ path, destPath }) => {
Expand Down

0 comments on commit e146ada

Please sign in to comment.