@angular-devkit/core#resolve TypeScript Examples
The following examples show how to use
@angular-devkit/core#resolve.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: dynamic-watch-entry.plugin.ts From angular-miniprogram with MIT License | 6 votes |
apply(compiler: webpack.Compiler) {
compiler.hooks.beforeCompile.tapPromise(
'DynamicWatchEntryPlugin',
async (compilation) => {
this.entryPattern$.next({
pageList: await this.generateModuleInfo(this.options.pages || []),
componentList: await this.generateModuleInfo(
this.options.components || []
),
});
}
);
compiler.hooks.thisCompilation.tap(
'DynamicWatchEntryPlugin',
(compilation) => {
if (this.first) {
this.first = false;
const patternList = normalizeAssetPatterns(
[...(this.options.pages || []), ...(this.options.components || [])],
this.options.workspaceRoot,
this.absoluteProjectRoot,
this.absoluteProjectSourceRoot
);
for (const pattern of patternList) {
const cwd = path.resolve(
this.options.context.workspaceRoot,
pattern.input
);
compilation.fileDependencies.add(cwd);
}
}
}
);
}
Example #2
Source File: merge-using-component-path.ts From angular-miniprogram with MIT License | 6 votes |
export function getUseComponents(
libraryPath: UseComponent[],
localPath: UseComponent[],
moduleId: string
) {
const list = [...libraryPath];
list.push(
...localPath.map((item) => {
item.path = getComponentOutputPath(moduleId, item.className);
return item;
})
);
return list.reduce((pre, cur) => {
pre[cur.selector] = resolve(
normalize('/'),
join(normalize(LIBRARY_OUTPUT_ROOTDIR), cur.path)
);
return pre;
}, {} as Record<string, string>);
}
Example #3
Source File: output-template-metadata.service.ts From angular-miniprogram with MIT License | 6 votes |
private getSelfTemplate() {
const selfMetaCollection = this.dataGroup.otherMetaCollectionGroup['$self'];
if (!selfMetaCollection) {
return '';
}
this.selfMetaCollection = selfMetaCollection;
const templateStr = selfMetaCollection.templateList
.map((item) => item.content)
.join('');
const extraTemplateData: ExtraTemplateData = {
template: templateStr,
outputPath: resolve(
normalize('/'),
join(normalize(LIBRARY_OUTPUT_ROOTDIR), this.entryPoint, 'self')
),
};
delete this.dataGroup.otherMetaCollectionGroup['$self'];
return `let $self_${GLOBAL_TEMPLATE_SUFFIX}=${JSON.stringify(
extraTemplateData
)}`;
}
Example #4
Source File: dynamic-watch-entry.plugin.ts From angular-miniprogram with MIT License | 5 votes |
async init() {
const projectName =
this.options.context.target && this.options.context.target.project;
if (!projectName) {
throw new Error('The builder requires a target.');
}
const projectMetadata = await this.options.context.getProjectMetadata(
projectName
);
this.absoluteProjectRoot = normalize(
getSystemPath(
resolve(
this.options.workspaceRoot,
normalize((projectMetadata.root as string) || '')
)
)
);
const relativeSourceRoot = projectMetadata.sourceRoot as string | undefined;
const absoluteSourceRootPath =
typeof relativeSourceRoot === 'string'
? resolve(this.options.workspaceRoot, normalize(relativeSourceRoot))
: undefined;
if (relativeSourceRoot) {
this.absoluteProjectSourceRoot = normalize(
getSystemPath(absoluteSourceRootPath!)
)!;
}
const originEntryConfig = this.options.config.entry as webpack.EntryObject;
this.options.config.entry = async () => {
const entryPattern = this.entryPattern$.value;
if (!entryPattern) {
throw new Error('未匹配入口');
}
const list = [...entryPattern.pageList, ...entryPattern.componentList];
if (originEntryConfig['app']) {
throw new Error(
'资源文件不能指定为app文件名或bundleName,请重新修改(不影响导出)'
);
}
return {
...originEntryConfig,
...list.reduce((pre, cur) => {
pre[cur.entryName] = [cur.src];
return pre;
}, {} as webpack.EntryObject),
};
};
}
Example #5
Source File: dynamic-watch-entry.plugin.ts From angular-miniprogram with MIT License | 5 votes |
private async generateModuleInfo(list: AssetPattern[]) {
const patternList = normalizeAssetPatterns(
list,
this.options.workspaceRoot,
this.absoluteProjectRoot,
this.absoluteProjectSourceRoot
);
const moduleList: PagePattern[] = [];
for (const pattern of patternList) {
const cwd = path.resolve(
this.options.context.workspaceRoot,
pattern.input
);
/** 当前匹配匹配到的文件 */
const files = await globAsync(pattern.glob, {
cwd,
dot: true,
nodir: true,
ignore: pattern.ignore || [],
follow: pattern.followSymlinks,
});
moduleList.push(
...files.map((file) => {
const object: Partial<PagePattern> = {
entryName: path.basename(file, '.ts').replace(/\./g, '-'),
fileName: file,
src: path.join(cwd, file),
...pattern,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
outputFiles: {} as any,
// eslint-disable-next-line @typescript-eslint/no-explicit-any
inputFiles: {} as any,
};
object.inputFiles!.config = object.src!.replace(
/\.ts$/,
this.buildPlatform.fileExtname.config!
);
const outputFileName =
object.fileName!.replace(/\.ts$/, '').replace(/\./g, '-') + '.ts';
object.outputFiles!.path = path
.join(pattern.output, outputFileName)
.replace(/\.ts$/, '');
object.outputFiles!.logic =
object.outputFiles!.path + this.buildPlatform.fileExtname.logic;
object.outputFiles!.style =
object.outputFiles!.path + this.buildPlatform.fileExtname.style;
object.outputFiles!.content =
object.outputFiles!.path + this.buildPlatform.fileExtname.content;
object.outputFiles!.config =
object.outputFiles!.path + this.buildPlatform.fileExtname.config;
return object as PagePattern;
})
);
}
return moduleList;
}
Example #6
Source File: dynamic-watch-entry.plugin.ts From angular-miniprogram with MIT License | 5 votes |
function globAsync(pattern: string, options: glob.IOptions) {
return new Promise<string[]>((resolve, reject) =>
glob.default(pattern, options, (e, m) => (e ? reject(e) : resolve(m)))
);
}
Example #7
Source File: setup-component-data.service.ts From angular-miniprogram with MIT License | 5 votes |
run(
data: string,
originFileName: string,
customStyleSheetProcessor: CustomStyleSheetProcessor
) {
const changedData = changeComponent(data);
if (!changedData) {
return data;
}
const useComponentPath =
this.dataGroup.useComponentPath.get(originFileName)!;
const componentClassName = changedData.componentName;
const componentDirName = strings.dasherize(
strings.camelize(componentClassName)
);
const libraryPath = getComponentOutputPath(
this.entryPoint,
componentClassName
);
const styleUrlList = this.dataGroup.style.get(originFileName);
const styleContentList: string[] = [];
styleUrlList?.forEach((item) => {
styleContentList.push(customStyleSheetProcessor.styleMap.get(item)!);
});
const selfTemplateImportStr = this.dataGroup.otherMetaCollectionGroup[
'$self'
]
? `<import src="${resolve(
normalize('/'),
join(
normalize(LIBRARY_OUTPUT_ROOTDIR),
this.entryPoint,
'self' + this.buildPlatform.fileExtname.contentTemplate
)
)}"/>`
: '';
const insertComponentData: ExportLibraryComponentMeta = {
id:
strings.classify(this.entryPoint) +
strings.classify(strings.camelize(componentDirName)),
className: componentClassName,
content:
selfTemplateImportStr +
this.dataGroup.outputContent.get(originFileName)!,
libraryPath: libraryPath,
useComponents: {
...getUseComponents(
useComponentPath.libraryPath,
useComponentPath.localPath,
this.entryPoint
),
...this.addGlobalTemplateService.getSelfUseComponents(),
},
moduleId: this.entryPoint,
};
if (styleContentList.length) {
insertComponentData.style = styleContentList.join('\n');
}
return `${
changedData.content
}\nlet ${componentClassName}_${LIBRARY_COMPONENT_METADATA_SUFFIX}=${JSON.stringify(
insertComponentData
)}`;
}
Example #8
Source File: mini-program-application-analysis.service.ts From angular-miniprogram with MIT License | 4 votes |
async exportComponentBuildMetaMap() {
const injector = Injector.create({
providers: [
{
provide: MiniProgramCompilerService,
useFactory: (injector: Injector, buildPlatform: BuildPlatform) => {
return new MiniProgramCompilerService(
this.ngTscProgram,
injector,
buildPlatform
);
},
deps: [Injector, BuildPlatform],
},
],
parent: this.injector,
});
const miniProgramCompilerService = injector.get(MiniProgramCompilerService);
miniProgramCompilerService.init();
const metaMap =
await miniProgramCompilerService.exportComponentBuildMetaMap();
const selfMetaCollection = metaMap.otherMetaCollectionGroup['$self'];
const selfTemplate: Record<string, string> = {};
if (selfMetaCollection) {
const importSelfTemplatePath = `/self-template/self${this.buildPlatform.fileExtname.contentTemplate}`;
const importSelfTemplate = `<import src="${importSelfTemplatePath}"/>`;
metaMap.outputContent.forEach((value, key) => {
value = `${importSelfTemplate}${value}`;
metaMap.outputContent.set(key, value);
});
metaMap.useComponentPath.forEach((value, key) => {
value.libraryPath.push(...selfMetaCollection.libraryPath);
value.localPath.push(...selfMetaCollection.localPath);
});
selfTemplate[importSelfTemplatePath] = selfMetaCollection.templateList
.map((item) => item.content)
.join('');
delete metaMap.otherMetaCollectionGroup['$self'];
}
metaMap.useComponentPath.forEach((value, key) => {
value.libraryPath = Array.from(new Set(value.libraryPath));
value.localPath = Array.from(new Set(value.localPath));
});
const styleMap = new Map<string, string[]>();
metaMap.style.forEach((value, key) => {
const entryPattern = this.getComponentPagePattern(key);
styleMap.set(entryPattern.outputFiles.style, value);
});
const contentMap = new Map<string, string>();
metaMap.outputContent.forEach((value, key) => {
const entryPattern = this.getComponentPagePattern(key);
contentMap.set(entryPattern.outputFiles.content, value);
});
metaMap.style = styleMap;
const config = new Map<
string,
{
usingComponents: { selector: string; path: string }[];
existConfig: string;
}
>();
metaMap.useComponentPath.forEach((value, key) => {
const entryPattern = this.getComponentPagePattern(key);
const list = [
...value.libraryPath.map((item) => {
item.path = resolve(
normalize('/'),
join(normalize(LIBRARY_OUTPUT_ROOTDIR), item.path)
);
return item;
}),
];
list.push(
...value.localPath.map((item) => ({
selector: item.selector,
path: resolve(
normalize('/'),
normalize(this.getComponentPagePattern(item.path).outputFiles.path)
),
className: item.className,
}))
);
config.set(entryPattern.outputFiles.config, {
usingComponents: list,
existConfig: entryPattern.inputFiles.config,
});
});
for (const key in metaMap.otherMetaCollectionGroup) {
if (
Object.prototype.hasOwnProperty.call(
metaMap.otherMetaCollectionGroup,
key
)
) {
const element = metaMap.otherMetaCollectionGroup[key];
element.libraryPath.forEach((item) => {
item.path = resolve(
normalize('/'),
join(normalize(LIBRARY_OUTPUT_ROOTDIR), item.path)
);
});
element.localPath.forEach((item) => {
item.path = resolve(
normalize('/'),
normalize(this.getComponentPagePattern(item.path).outputFiles.path)
);
});
}
}
return {
style: styleMap,
outputContent: contentMap,
config: config,
otherMetaCollectionGroup: metaMap.otherMetaCollectionGroup,
selfTemplate,
};
}