Skip to content

Commit

Permalink
Fix readConsumer() with CWD relative paths
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Jun 13, 2021
1 parent 798e376 commit 9475d0d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/reader.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const {readFileSync} = require('fs')
const {resolve} = require('path')
const {cwd} = require('process')

const {createConsumer} = require('./consumer.js')
const {resolvePath} = require('./path.js')
Expand All @@ -8,8 +10,9 @@ module.exports = {
}

function readConsumer (manifestPath) {
const manifest = readManifest(manifestPath)
const outputPath = resolvePath(manifestPath, manifest.outputPath)
const absoluteManifestPath = resolve(cwd(), manifestPath)
const manifest = readManifest(absoluteManifestPath)
const outputPath = resolvePath(absoluteManifestPath, manifest.outputPath)

return createConsumer(manifest, {outputPath})
}
Expand Down
9 changes: 5 additions & 4 deletions test/suite/consumer/read.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
const {join, resolve} = require('path')
const {join, relative, resolve} = require('path')
const {cwd} = require('process')

const {readConsumer} = require('../../../src/reader.js')

const fixtureDirPath = resolve(__dirname, '../../fixture')

describe('readConsumer()', () => {
describe('when the manifest is located directly in the output directory', () => {
const fixturePath = join(fixtureDirPath, 'flat.iconduitmanifest')
const fixturePath = relative(cwd(), join(fixtureDirPath, 'flat.iconduitmanifest'))
let consumer

beforeEach(() => {
Expand Down Expand Up @@ -47,7 +48,7 @@ describe('readConsumer()', () => {
})

describe('when the manifest is located in a sub-directory of the output directory', () => {
const fixturePath = join(fixtureDirPath, 'subdir/subdir.iconduitmanifest')
const fixturePath = relative(cwd(), join(fixtureDirPath, 'subdir/subdir.iconduitmanifest'))
let consumer

beforeEach(() => {
Expand Down Expand Up @@ -88,7 +89,7 @@ describe('readConsumer()', () => {
})

describe('when the manifest is located ouside the output directory', () => {
const fixturePath = join(fixtureDirPath, 'outside.iconduitmanifest')
const fixturePath = relative(cwd(), join(fixtureDirPath, 'outside.iconduitmanifest'))
let consumer

beforeEach(() => {
Expand Down

0 comments on commit 9475d0d

Please sign in to comment.