Skip to content

Commit c5d8882

Browse files
committed
fix(npm): the path error when upgrade template from npm
1 parent cd7321a commit c5d8882

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

src/load-config/load-milirc.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const cosmiconfig = require('cosmiconfig')
33
const semver = require('semver')
44
const throwError = require('../utils/throw-error')
55
const { join, relative } = require('path')
6+
const isRelativePath = require('../utils/is-relative-path')
67

78

89
const explorer = cosmiconfig('mili')
@@ -45,7 +46,10 @@ module.exports = async (cwd) => {
4546
].join('\n'))
4647

4748

48-
config.template.repository = relative(process.cwd(), join(cwd, config.template.repository))
49+
// The relative template path saved in .milirc is relative to the dir of .milirc
50+
if (isRelativePath(config.template.repository)) {
51+
config.template.repository = relative(process.cwd(), join(cwd, config.template.repository))
52+
}
4953

5054
return config
5155
}

src/utils/format-repository.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@ const throwError = require('./throw-error')
22
const fs = require('fs-extra')
33
const { join, isAbsolute, relative } = require('path')
44
const validateNpmPackageName = require("validate-npm-package-name")
5+
const isRelativePath = require('./is-relative-path')
6+
57

68
const githubSH = /^(github:)?[-a-zA-Z0-9@:%._\+~#=]+\/[-a-zA-Z0-9@:%._\+~#=]+$/
79
const gitUrlRegexp = /((git|ssh|http(s)?)|(git@[\w.]+))(:(\/\/)?)([\w.@:/\-~]+)(\.git)(\/)?$/
8-
const isRelative = path => /^\.\.?\//.test(path)
9-
1010

1111
const formatRepository = repository => {
1212
if (gitUrlRegexp.test(repository)) {
@@ -38,7 +38,7 @@ const dirExist = async link => {
3838
module.exports = (link) => {
3939
const cwd = process.cwd()
4040

41-
if (isRelative(link) || isAbsolute(link)) {
41+
if (isRelativePath(link) || isAbsolute(link)) {
4242
if (isAbsolute(link) && dirExist(link)) {
4343
return { type: 'local', url: link, owner: null, name: null, path: link }
4444
}

src/utils/is-relative-path.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = path => /^\.\.?\//.test(path)

0 commit comments

Comments
 (0)