Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(loc-extractor): do not resolve libraries files (isApplication) #928

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import * as fs from 'node:fs';
import * as glob from 'globby';
import * as path from 'node:path';
import * as ts from 'typescript';
import type { LocalizationExtractorBuilderSchema } from '../localization-extractor/schema';

/** List of Angular decorator to look for */
const ANGULAR_ANNOTATION = ['Component', 'Injectable', 'Pipe'];
Expand Down Expand Up @@ -59,7 +60,7 @@ export class LocalizationExtractor {

private logger: logging.LoggerApi;

constructor(tsconfigPath: string, logger: logging.LoggerApi) {
constructor(tsconfigPath: string, logger: logging.LoggerApi, private options?: Partial<LocalizationExtractorBuilderSchema>) {
this.tsconfigPath = tsconfigPath;
this.logger = logger;
}
Expand Down Expand Up @@ -121,6 +122,7 @@ export class LocalizationExtractor {
}
return res;
})
.filter(({ref}) => (this.options?.libraries || []).every((lib) => !ref.startsWith(lib)))
.map(({ref}) => {
if (!ref.startsWith('.')) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export * from './schema';
export default createBuilder<LocalizationExtractorBuilderSchema>(async (options, context): Promise<BuilderOutput> => {
context.reportRunning();

const localizationExtractor = new LocalizationExtractor(path.resolve(context.workspaceRoot, options.tsConfig), context.logger);
const localizationExtractor = new LocalizationExtractor(path.resolve(context.workspaceRoot, options.tsConfig), context.logger, options);
const cache: { libs: LibraryMetadataMap; locs: LocalizationFileMap } = {libs: {}, locs: {}};

const execute = async (isFirstLoad = true, files?: { libs?: string[]; locs?: string[]; extraFiles?: string[] }): Promise<BuilderOutput> => {
Expand All @@ -28,7 +28,7 @@ export default createBuilder<LocalizationExtractorBuilderSchema>(async (options,
cache.locs = await localizationExtractor.extractLocalizationFromTsConfig(files && files.extraFiles);

context.reportProgress(STEP_NUMBER, stepValue++, 'Load metadata');
cache.libs = files && files.libs ? await localizationExtractor.getMetadataFromLibraries(files.libs) : {};
cache.libs = options.isApplication && files && files.libs ? await localizationExtractor.getMetadataFromLibraries(files.libs) : {};

// Load specific files that have changed
} else {
Expand All @@ -46,7 +46,7 @@ export default createBuilder<LocalizationExtractorBuilderSchema>(async (options,
...newLocs
};
}
if (files && files.libs) {
if (options.isApplication && files && files.libs) {
context.reportProgress(STEP_NUMBER, stepValue++, 'reload library metadata');
const newLibs = await localizationExtractor.getMetadataFromFiles(files.libs);
cache.libs = {
Expand Down Expand Up @@ -139,7 +139,6 @@ export default createBuilder<LocalizationExtractorBuilderSchema>(async (options,

await currentProcess;

/** SCSS file watcher */
const watcher = chokidar.watch([...Object.keys(cache.locs), ...(options.extraFilePatterns || [])], {ignoreInitial: true});
const metadataWatcher = chokidar.watch(Object.keys(cache.libs), {ignoreInitial: true});
const { include, exclude, cwd } = localizationExtractor.getPatternsFromTsConfig();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
"type": "boolean",
"description": "Sort metadata alphabetically by keys",
"default": false
},
"isApplication": {
"type": "boolean",
"default": true,
"description": "If true, metadata from libraries are added"
}
},
"additionalProperties": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ export interface LocalizationExtractorBuilderSchema extends JsonObject {

/** If true, metadata objects are sorted by keys */
sortKeys: boolean;

/** If true, metadata from libraries are added */
isApplication: boolean;
}