|
1 | 1 | constfs=require('fs')
|
| 2 | +constpath=require('path') |
2 | 3 |
|
3 | 4 | module.exports=(api)=>{
|
4 | 5 | api.extendPackage({
|
@@ -99,23 +100,31 @@ module.exports = (api) => {
|
99 | 100 | api.transformScript(api.entryFile,globalApiTransform)
|
100 | 101 |
|
101 | 102 | constresolveFile=(file)=>{
|
102 |
| -letfilePath=api.resolve(file) |
103 |
| -if(fs.existsSync(filePath))returnfilePath |
104 |
| -filePath=api.resolve(file.replace('.js','.ts')) |
105 |
| -if(fs.existsSync(filePath))returnfilePath |
106 |
| -filePath=api.resolve(path.join(file.replace('.js',''),'index.js')) |
107 |
| -if(fs.existsSync(filePath))returnfilePath |
108 |
| -filePath=api.resolve(path.join(file.replace('.js',''),'index.ts')) |
109 |
| -if(fs.existsSync(filePath))returnfilePath |
| 103 | +if(!/\.(j|t)s$/ig.test(file)){ |
| 104 | +file+='.js' |
| 105 | +} |
| 106 | +letresolvedPath=api.resolve(file) |
| 107 | +constpossiblePaths=[ |
| 108 | +resolvedPath, |
| 109 | +resolvedPath.replace(/\.js$/ig,'.ts'), |
| 110 | +path.join(resolvedPath.replace(/\.js$/ig,''),'index.js'), |
| 111 | +path.join(resolvedPath.replace(/\.js$/ig,''),'index.ts') |
| 112 | +] |
| 113 | +for(constpofpossiblePaths){ |
| 114 | +if(fs.existsSync(p)){ |
| 115 | +returnpath.relative(api.resolve('.'),p) |
| 116 | +} |
| 117 | +} |
110 | 118 | }
|
111 | 119 |
|
112 |
| -constrouterPath=resolveFile('router') |
| 120 | +constrouterPath=resolveFile('src/router') |
| 121 | +console.log(routerPath) |
113 | 122 | if(routerPath){
|
114 | 123 | api.transformScript(routerPath,globalApiTransform)
|
115 | 124 | api.transformScript(routerPath,require('./codemods/router'))
|
116 | 125 | }
|
117 | 126 |
|
118 |
| -conststorePath=resolveFile('store') |
| 127 | +conststorePath=resolveFile('src/store') |
119 | 128 | if(storePath){
|
120 | 129 | api.transformScript(storePath,globalApiTransform)
|
121 | 130 | api.transformScript(storePath,require('./codemods/vuex'))
|
|