Skip to content

Commit

Permalink
Fix Windows related issues
Browse files Browse the repository at this point in the history
Fixes gh-2
  • Loading branch information
philwebb committed Mar 21, 2024
1 parent e40659e commit 7ca63b1
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 39 deletions.
27 changes: 17 additions & 10 deletions packages/antora-zip-contents-collector-extension/lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ 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) => posixify(file.path) === 'layouts/bare.hbs').length === 0) {
logger.trace("Adding 'bare' layout to UI catalog")
const file = new Vinyl({
path: 'layouts/bare.hbs',
Expand Down Expand Up @@ -363,8 +363,8 @@ function register ({ config, downloadLog }) {
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') {
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
Expand All @@ -383,7 +383,6 @@ function register ({ config, downloadLog }) {
module: moduleName,
family: 'page',
})
file.src.relative = file.relative
const pageAttributes = {
'page-layout': 'bare',
'page-component-name': component.name,
Expand All @@ -392,7 +391,7 @@ function register ({ config, downloadLog }) {
'page-component-display-version': version.displayVersion,
'page-component-title': component.title,
'page-module': moduleName,
'page-relative': file.src.relative,
'page-relative': file.src.path,
'page-origin-type': file.src.origin.type,
'page-origin-url': file.src.origin.url,
}
Expand All @@ -407,11 +406,19 @@ 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(), {
src: { origin: include.origin, path, basename, stem, extname, abspath: path, mediaType, zipFile, ...src },
})
result.path = path
return result
src = {
origin: include.origin,
path,
basename,
stem,
extname,
abspath: path,
relative: path,
mediaType,
zipFile,
...src,
}
return { path, contents: file.contents, stat: file.stat, src }
}

async function cleanupCollectorCacheDir (collectorCacheDir) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ const os = require('os')
const ospath = require('path')
const Vinyl = require('vinyl')

const posixify = ospath.sep === '\\' ? (p) => p.replace(/\\/g, '/') : (p) => p

const FIXTURES_DIR = ospath.join(__dirname, 'fixtures')
const FIXTURES_REPOS_DIR = ospath.join(FIXTURES_DIR, 'repos')
const FIXTURES_ZIPS_DIR = ospath.join(FIXTURES_DIR, 'zips')
Expand Down Expand Up @@ -94,7 +96,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')
},
})
})
Expand All @@ -116,7 +118,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')
},
})
})
Expand All @@ -142,7 +144,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')
},
})
})
Expand All @@ -165,8 +167,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')
},
})
})
Expand All @@ -188,7 +190,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')
},
})
})
Expand Down Expand Up @@ -264,7 +266,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()
},
})
Expand All @@ -284,7 +286,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()
},
})
Expand All @@ -304,7 +306,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()
},
})
Expand All @@ -325,7 +327,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()
},
})
Expand Down Expand Up @@ -356,7 +358,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`)
Expand Down Expand Up @@ -386,6 +388,7 @@ describe('zip contents collector extension', () => {
expect(files[0]).to.have.property('stat')
expect(files[0].src).to.eql({
path: 'modules/ROOT/pages/index.adoc',
relative: 'modules/ROOT/pages/index.adoc',
abspath: 'modules/ROOT/pages/index.adoc',
basename: 'index.adoc',
stem: 'index',
Expand Down Expand Up @@ -418,7 +421,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')
},
})
})
Expand Down Expand Up @@ -447,7 +450,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')
},
})
})
Expand Down Expand Up @@ -552,7 +555,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)
Expand All @@ -579,7 +582,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)
Expand Down Expand Up @@ -610,7 +613,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')
},
})
})
Expand All @@ -632,7 +635,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')
},
})
})
Expand Down Expand Up @@ -662,7 +665,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')
Expand Down Expand Up @@ -690,13 +693,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')
},
})
})
Expand All @@ -719,13 +721,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')
},
})
})
Expand Down Expand Up @@ -794,7 +795,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(posixify(layouts[0].path)).to.be.equal('layouts/bare.hbs')
},
})
})
Expand All @@ -821,7 +822,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(posixify(layouts[0].path)).to.be.equal('layouts/bare.hbs')
expect(layouts[0].contents.toString()).to.be.equal('test')
},
})
Expand All @@ -845,7 +846,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')
},
})
})
Expand Down

0 comments on commit 7ca63b1

Please sign in to comment.