Skip to content

Commit

Permalink
feat(cli): enhance wxa lib import
Browse files Browse the repository at this point in the history
  • Loading branch information
Genuifx committed Mar 7, 2020
1 parent 6760bdb commit 13e4803
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions packages/wxa-cli/src/helpers/dependencyResolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,7 @@ class DependencyResolver {

getOutputPath(source, pret, mdl) {
if (pret.isRelative || pret.isAPPAbsolute || pret.isNodeModule || pret.isWXALib) {
let opath = pret.isWXALib ?
path.parse(path.join(this.meta.context, '_wxa', pret.name+pret.ext)) :
path.parse(source);

return this.getDistPath(opath, mdl);
return this.getDistPath(source, mdl);
} else if (pret.isPlugin || pret.isURI) {
// url module
return null;
Expand Down Expand Up @@ -152,19 +148,27 @@ class DependencyResolver {
return content;
}

getDistPath(absPath, mdl) {
getDistPath(fullPath, mdl) {
let relative;
absPath = typeof absPath === 'string' ? path.parse(absPath) : absPath;
fullPath = typeof fullPath === 'string' ? path.parse(fullPath) : fullPath;

if (path.relative(this.meta.current, absPath.dir).indexOf('node_modules') === 0) {
relative = path.relative(path.join(this.meta.current, 'node_modules'), absPath.dir);
// package is empty meanning the package is main one.
if (
fullPath.dir.indexOf(this.modulesPath) > -1
) {
// node_modules
relative = path.relative(this.modulesPath, fullPath.dir);
relative = path.join('npm', relative);
} else if (
fullPath.dir.indexOf(this.meta.libSrc) > -1
) {
// cli内置文件
relative = path.relative(this.meta.libSrc, fullPath.dir);
relative = path.join('_wxa', relative);
} else {
relative = path.relative(this.meta.context, absPath.dir);
relative = path.relative(this.meta.context, fullPath.dir);
}

return path.join(this.meta.output.path, relative, absPath.base);
return path.join(this.meta.output.path, relative, fullPath.base);
}
}

Expand Down

0 comments on commit 13e4803

Please sign in to comment.