diff --git a/packages/antora-zip-contents-collector-extension/lib/index.js b/packages/antora-zip-contents-collector-extension/lib/index.js index 3624bb6..ee71de7 100644 --- a/packages/antora-zip-contents-collector-extension/lib/index.js +++ b/packages/antora-zip-contents-collector-extension/lib/index.js @@ -98,13 +98,14 @@ function register ({ config, downloadLog }) { async function uiLoaded ({ uiCatalog }) { const layouts = uiCatalog.findByType('layout') - if (layouts.filter((file) => file.path === 'layouts/bare.hbs').length === 0) { + if (layouts.filter((file) => file.src.path === 'layouts/bare.hbs').length === 0) { logger.trace("Adding 'bare' layout to UI catalog") const file = new Vinyl({ path: 'layouts/bare.hbs', contents: Buffer.from('{{{page.contents}}}'), }) file.type = 'layout' + file.src = {path: 'layouts/bare.hbs'} uiCatalog.addFile(file) } } @@ -362,9 +363,9 @@ function register ({ config, downloadLog }) { let destination = include.module && ospath.join('modules', include.module) destination = include.path && (destination ? ospath.join(destination, include.path) : include.path) file = asAntoraFile(include, zipFile, file, destination) - logger.trace(`Adding ${file.path} to content aggregate`) - const existing = componentVersionBucket.files.find(({ path: candidate }) => candidate === file.path) - if (file.path === 'antora.yml' || file.path === 'modules/antora.yml') { + logger.trace(`Adding ${file.src.path} to content aggregate`) + const existing = componentVersionBucket.files.find(candidate => candidate.src.path === file.src.path) + if (file.src.path === 'antora.yml' || file.src.path === 'modules/antora.yml') { const generated = yaml.load(file.contents) Object.assign(componentVersionBucket, generated) if (!('prerelease' in generated)) delete componentVersionBucket.prerelease @@ -407,11 +408,9 @@ function register ({ config, downloadLog }) { const extname = ospath.extname(path) const stem = basename.slice(0, basename.length - extname.length) const mediaType = mimeTypes.lookup(extname) || fallbackMediaType - const result = Object.assign(file.clone(), { + return Object.assign(file.clone(), { src: { origin: include.origin, path, basename, stem, extname, abspath: path, mediaType, zipFile, ...src }, }) - result.path = path - return result } async function cleanupCollectorCacheDir (collectorCacheDir) { diff --git a/packages/antora-zip-contents-collector-extension/test/zip-contents-collector-extension-test.js b/packages/antora-zip-contents-collector-extension/test/zip-contents-collector-extension-test.js index 2d45086..809a634 100644 --- a/packages/antora-zip-contents-collector-extension/test/zip-contents-collector-extension-test.js +++ b/packages/antora-zip-contents-collector-extension/test/zip-contents-collector-extension-test.js @@ -94,7 +94,7 @@ describe('zip contents collector extension', () => { }, after: ({ contentAggregate }) => { expect(contentAggregate[0].files).to.have.lengthOf(1) - expect(contentAggregate[0].files[0].path).to.equal('modules/ROOT/pages/index.adoc') + expect(contentAggregate[0].files[0].src.path).to.equal('modules/ROOT/pages/index.adoc') }, }) }) @@ -116,7 +116,7 @@ describe('zip contents collector extension', () => { }, after: ({ contentAggregate }) => { expect(contentAggregate[0].files).to.have.lengthOf(1) - expect(contentAggregate[0].files[0].path).to.equal('modules/ROOT/pages/index.adoc') + expect(contentAggregate[0].files[0].src.path).to.equal('modules/ROOT/pages/index.adoc') }, }) }) @@ -142,7 +142,7 @@ describe('zip contents collector extension', () => { }, after: ({ contentAggregate }) => { expect(contentAggregate[0].files).to.have.lengthOf(1) - expect(contentAggregate[0].files[0].path).to.equal('modules/ROOT/pages/index.adoc') + expect(contentAggregate[0].files[0].src.path).to.equal('modules/ROOT/pages/index.adoc') }, }) }) @@ -165,8 +165,8 @@ describe('zip contents collector extension', () => { httpPath: '/', after: ({ contentAggregate }) => { expect(contentAggregate[0].files).to.have.lengthOf(2) - expect(contentAggregate[0].files[0].path).to.equal('modules/ROOT/pages/c1.adoc') - expect(contentAggregate[0].files[1].path).to.equal('modules/ROOT/pages/c2.adoc') + expect(contentAggregate[0].files[0].src.path).to.equal('modules/ROOT/pages/c1.adoc') + expect(contentAggregate[0].files[1].src.path).to.equal('modules/ROOT/pages/c2.adoc') }, }) }) @@ -188,7 +188,7 @@ describe('zip contents collector extension', () => { }, after: ({ contentAggregate }) => { expect(contentAggregate[0].files).to.have.lengthOf(1) - expect(contentAggregate[0].files[0].path).to.equal('modules/ROOT/pages/index.adoc') + expect(contentAggregate[0].files[0].src.path).to.equal('modules/ROOT/pages/index.adoc') }, }) }) @@ -264,7 +264,7 @@ describe('zip contents collector extension', () => { httpPath: '/v1.2.3', after: ({ contentAggregate }) => { expect(contentAggregate[0].files).to.have.lengthOf(2) - const page = contentAggregate[0].files.find((it) => it.relative === 'modules/ROOT/pages/index.adoc') + const page = contentAggregate[0].files.find((it) => it.src.path === 'modules/ROOT/pages/index.adoc') expect(page).to.be.exist() }, }) @@ -284,7 +284,7 @@ describe('zip contents collector extension', () => { httpPath: '/v1.2.3', after: ({ contentAggregate }) => { expect(contentAggregate[0].files).to.have.lengthOf(2) - const page = contentAggregate[0].files.find((it) => it.relative === 'modules/ROOT/pages/index.adoc') + const page = contentAggregate[0].files.find((it) => it.src.path === 'modules/ROOT/pages/index.adoc') expect(page).to.be.exist() }, }) @@ -304,7 +304,7 @@ describe('zip contents collector extension', () => { httpPath: '/v1.2.3', after: ({ contentAggregate }) => { expect(contentAggregate[0].files).to.have.lengthOf(2) - const page = contentAggregate[0].files.find((it) => it.relative === 'modules/ROOT/pages/index.adoc') + const page = contentAggregate[0].files.find((it) => it.src.path === 'modules/ROOT/pages/index.adoc') expect(page).to.be.exist() }, }) @@ -325,7 +325,7 @@ describe('zip contents collector extension', () => { httpPath: '/v1.2.3', after: ({ contentAggregate }) => { expect(contentAggregate[0].files).to.have.lengthOf(2) - const page = contentAggregate[0].files.find((it) => it.relative === 'modules/ROOT/pages/index.adoc') + const page = contentAggregate[0].files.find((it) => it.src.path === 'modules/ROOT/pages/index.adoc') expect(page).to.be.exist() }, }) @@ -356,7 +356,7 @@ describe('zip contents collector extension', () => { downloadLog, after: ({ contentAggregate }) => { expect(contentAggregate[0].files).to.have.lengthOf(2) - const page = contentAggregate[0].files.find((it) => it.relative === 'modules/ROOT/pages/index.adoc') + const page = contentAggregate[0].files.find((it) => it.src.path === 'modules/ROOT/pages/index.adoc') expect(page).to.be.exist() expect(downloadLog.length).to.equal(1) expect(downloadLog[0].url).to.equal(`http://localhost:${httpServerPort}/release/v1.2.3/start-page.zip`) @@ -418,7 +418,7 @@ describe('zip contents collector extension', () => { }, after: ({ contentAggregate }) => { expect(contentAggregate[0].files).to.have.lengthOf(1) - expect(contentAggregate[0].files[0].path).to.equal('modules/ROOT/pages/index.adoc') + expect(contentAggregate[0].files[0].src.path).to.equal('modules/ROOT/pages/index.adoc') }, }) }) @@ -447,7 +447,7 @@ describe('zip contents collector extension', () => { }, after: ({ contentAggregate }) => { expect(contentAggregate[0].files).to.have.lengthOf(1) - expect(contentAggregate[0].files[0].path).to.equal('modules/ROOT/pages/index.adoc') + expect(contentAggregate[0].files[0].src.path).to.equal('modules/ROOT/pages/index.adoc') }, }) }) @@ -552,7 +552,7 @@ describe('zip contents collector extension', () => { times: 2, after: ({ contentAggregate }) => { expect(contentAggregate[0].files).to.have.lengthOf(1) - expect(contentAggregate[0].files[0].path).to.equal('modules/ROOT/pages/index.adoc') + expect(contentAggregate[0].files[0].src.path).to.equal('modules/ROOT/pages/index.adoc') expect(downloadLog.length).to.equal(2) expect(downloadLog[0].statusCode).to.equal(200) expect(downloadLog[1].statusCode).to.equal(304) @@ -579,7 +579,7 @@ describe('zip contents collector extension', () => { times: 2, after: ({ contentAggregate }) => { expect(contentAggregate[0].files).to.have.lengthOf(1) - expect(contentAggregate[0].files[0].path).to.equal('modules/ROOT/pages/index.adoc') + expect(contentAggregate[0].files[0].src.path).to.equal('modules/ROOT/pages/index.adoc') expect(downloadLog.length).to.equal(4) expect(downloadLog[0].statusCode).to.equal(404) expect(downloadLog[1].statusCode).to.equal(200) @@ -610,7 +610,7 @@ describe('zip contents collector extension', () => { }, after: ({ contentAggregate }) => { expect(contentAggregate[0].files).to.have.lengthOf(1) - expect(contentAggregate[0].files[0].path).to.equal('modules/ROOT/pages/index.adoc') + expect(contentAggregate[0].files[0].src.path).to.equal('modules/ROOT/pages/index.adoc') }, }) }) @@ -632,7 +632,7 @@ describe('zip contents collector extension', () => { }, after: ({ contentAggregate }) => { expect(contentAggregate[0].files).to.have.lengthOf(1) - expect(contentAggregate[0].files[0].path).to.equal('modules/ROOT/pages/index.adoc') + expect(contentAggregate[0].files[0].src.path).to.equal('modules/ROOT/pages/index.adoc') }, }) }) @@ -662,7 +662,7 @@ describe('zip contents collector extension', () => { This is the real deal. ` - expect(contentAggregate[0].files[0].contents.toString()).to.equal(expectedContents + '\n') + expect(contentAggregate[0].files[0].contents.toString().replace(/\r/g, '')).to.equal(expectedContents + '\n') expect(contentAggregate[0].files[0].stat).to.not.equal(originalStat) expect(contentAggregate[0].files[0].stat.size).to.not.equal(originalStat.size) expect(contentAggregate[0].files[0].src).to.not.have.property('scanned') @@ -690,13 +690,12 @@ describe('zip contents collector extension', () => { expect(contentAggregate[0].files).to.have.lengthOf(0) const files = contentCatalog.getFiles() const src = files[0].src - expect(files.filter((file) => file.path === 'api/java/README')).to.have.lengthOf(1) - expect(files.filter((file) => file.path === 'api/java/javadoc.css')).to.have.lengthOf(1) - expect(files.filter((file) => file.path === 'api/java/javadoc.html')).to.have.lengthOf(1) + expect(files.filter((file) => file.src.path === 'api/java/README')).to.have.lengthOf(1) + expect(files.filter((file) => file.src.path === 'api/java/javadoc.css')).to.have.lengthOf(1) + expect(files.filter((file) => file.src.path === 'api/java/javadoc.html')).to.have.lengthOf(1) expect(src.module).to.be.equal('ROOT') expect(src.family).to.be.equal('page') expect(src.component).to.be.equal('test') - expect(src.relative).to.be.equal('api/java/README') }, }) }) @@ -719,13 +718,12 @@ describe('zip contents collector extension', () => { expect(contentAggregate[0].files).to.have.lengthOf(0) const files = contentCatalog.getFiles() const src = files[0].src - expect(files.filter((file) => file.path === 'api/java/README')).to.have.lengthOf(1) - expect(files.filter((file) => file.path === 'api/java/javadoc.css')).to.have.lengthOf(1) - expect(files.filter((file) => file.path === 'api/java/javadoc.html')).to.have.lengthOf(1) + expect(files.filter((file) => file.src.path === 'api/java/README')).to.have.lengthOf(1) + expect(files.filter((file) => file.src.path === 'api/java/javadoc.css')).to.have.lengthOf(1) + expect(files.filter((file) => file.src.path === 'api/java/javadoc.html')).to.have.lengthOf(1) expect(src.module).to.be.equal('mymodule') expect(src.family).to.be.equal('page') expect(src.component).to.be.equal('test') - expect(src.relative).to.be.equal('api/java/README') }, }) }) @@ -794,7 +792,7 @@ describe('zip contents collector extension', () => { after: ({ uiCatalog }) => { const layouts = uiCatalog.findByType('layout') expect(layouts).to.have.lengthOf(1) - expect(layouts[0].path).to.be.equal('layouts/bare.hbs') + expect(layouts[0].src.path).to.be.equal('layouts/bare.hbs') }, }) }) @@ -816,12 +814,13 @@ describe('zip contents collector extension', () => { contents: Buffer.from('test'), }) file.type = 'layout' + file.src = {path: 'layouts/bare.hbs'} uiCatalog.addFile(file) }, after: ({ uiCatalog }) => { const layouts = uiCatalog.findByType('layout') expect(layouts).to.have.lengthOf(1) - expect(layouts[0].path).to.be.equal('layouts/bare.hbs') + expect(layouts[0].src.path).to.be.equal('layouts/bare.hbs') expect(layouts[0].contents.toString()).to.be.equal('test') }, }) @@ -845,7 +844,7 @@ describe('zip contents collector extension', () => { }, after: ({ contentAggregate }) => { expect(contentAggregate[0].files).to.have.lengthOf(1) - expect(contentAggregate[0].files[0].path).to.equal('modules/ROOT/pages/index.adoc') + expect(contentAggregate[0].files[0].src.path).to.equal('modules/ROOT/pages/index.adoc') }, }) })