@@ -11,18 +11,18 @@ import {
1111 FileType ,
1212 ICodeStruct ,
1313 IContainerInfo ,
14- IProjectTemplate ,
1514} from '../../../types' ;
15+ import { getSlotRelativePath } from '../../../utils/pathHelper' ;
1616
1717export interface PluginConfig {
18- fileType : string ;
18+ fileType ? : string ;
1919
2020 /** prefer using class property to define utils */
2121 preferClassProperty ?: boolean ;
2222}
2323
2424const pluginFactory : BuilderComponentPluginFactory < PluginConfig > = ( config ?) => {
25- const cfg : PluginConfig = {
25+ const cfg : PluginConfig & { fileType : string } = {
2626 fileType : FileType . JSX ,
2727 ...config ,
2828 } ;
@@ -36,26 +36,12 @@ const pluginFactory: BuilderComponentPluginFactory<PluginConfig> = (config?) =>
3636 next . contextData . useRefApi = true ;
3737 const useRef = ! ! ir . analyzeResult ?. isUsingRef ;
3838
39- // const isSingleComponent = next.contextData?.projectRemark?.isSingleComponent;
40- // const template = next.contextData?.template;
41-
42- // function getRelativeUtilsPath(template: IProjectTemplate, isSingleComponent: boolean) {
43- // let relativeUtilsPath = '../../utils';
44- // const utilsPath = template.slots.utils.path;
45- // if (ir.containerType === 'Component') {
46- // // TODO: isSingleComponent
47- // relativeUtilsPath = getRelativePath(template.slots.components.path.join('/'), utilsPath.join('/'));
48- // }
49- // return relativeUtilsPath;
50- // }
51-
5239 next . chunks . push ( {
5340 type : ChunkType . STRING ,
5441 fileType : cfg . fileType ,
5542 name : COMMON_CHUNK_NAME . InternalDepsImport ,
56- // TODO: 下面这个路径有没有更好的方式来获取?而非写死
5743 content : `
58- import utils${ useRef ? ', { RefsManager }' : '' } from '../../ utils';
44+ import utils${ useRef ? ', { RefsManager }' : '' } from '${ getSlotRelativePath ( { contextData : next . contextData , from : 'components' , to : ' utils' } ) } ';
5945 ` ,
6046 linkAfter : [ COMMON_CHUNK_NAME . ExternalDepsImport ] ,
6147 } ) ;
0 commit comments