Skip to content

Fix 'Cannot find module' error of meta.js when using local template #150

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 27, 2016
Merged
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
2 changes: 1 addition & 1 deletion lib/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function getMetadata (dir) {
if (exists(json)) {
opts = metadata.sync(json)
} else if (exists(js)) {
var req = require(js)
var req = require(path.resolve(js))
if (req !== Object(req)) {
throw new Error('meta.js needs to expose an object')
}
Expand Down
6 changes: 3 additions & 3 deletions test/e2e/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const metadata = require('../../lib/options')

const MOCK_TEMPLATE_REPO_PATH = './test/e2e/mock-template-repo'
const MOCK_TEMPLATE_BUILD_PATH = path.resolve('./test/e2e/mock-template-build')
const MOCK_METADATA_REPO_JS_PATH = './test/e2e/mock-metadata-repo-js'

function monkeyPatchInquirer (answers) {
// monkey patch inquirer
Expand Down Expand Up @@ -50,16 +51,15 @@ describe('vue-cli', () => {
})

it('read metadata from js', done => {
const meta = metadata('test-pkg', path.join(__dirname, '/mock-metadata-repo-js'))
const meta = metadata('test-pkg', MOCK_METADATA_REPO_JS_PATH)
expect(meta).to.be.an('object')
expect(meta.prompts).to.have.property('description')
done()
})

it('helpers', done => {
monkeyPatchInquirer(answers)
const buildPath = path.join(__dirname, '/mock-metadata-repo-js')
generate('test', buildPath, MOCK_TEMPLATE_BUILD_PATH, err => {
generate('test', MOCK_METADATA_REPO_JS_PATH, MOCK_TEMPLATE_BUILD_PATH, err => {
if (err) done(err)
const contents = fs.readFileSync(`${MOCK_TEMPLATE_BUILD_PATH}/readme.md`, 'utf-8')
expect(contents).to.equal(answers.name.toUpperCase())
Expand Down