Skip to content

Commit

Permalink
Make analyzer not shit the bed on error
Browse files Browse the repository at this point in the history
  • Loading branch information
Matsuuu committed Nov 12, 2023
1 parent 78eb002 commit 50b11b7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
47 changes: 31 additions & 16 deletions lib/custom-elements-languageserver-core/src/cem/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,34 +36,45 @@ export interface AnalyzerOutput {
manifest: Package;
}

const EMPTY_OUTPUT = {
schemaVersion: "1",
modules: []
}

export async function analyzeLocalProject(basePath: string): Promise<AnalyzerOutput> {


const projectConfig = await getPossibleProjectConfig(basePath);
const frameworkPlugins = await getFrameworkPlugins(projectConfig);
const globs = projectConfig.globs ?? [];
const globExcludes = projectConfig.exclude ??
console.log("Project config: ", projectConfig);
const globExcludes = projectConfig.exclude ?? [];

const plugins = [...(projectConfig?.plugins || []), ...frameworkPlugins]
const sourceFiles = await getFilesForGlobs(globs, globExcludes, basePath);

console.log("Sourcefile count ", sourceFiles.length);

const manifest: Package = create({
modules: sourceFiles,
plugins: plugins,
context: { dev: false }
});
try {
const manifest: Package = create({
modules: sourceFiles,
plugins: plugins,
context: { dev: false }
});

normalizeManifest(basePath, manifest);
normalizeManifest(basePath, manifest);

const savePath = cacheCurrentCEM(basePath, manifest);
console.log("Manifest file written to ", savePath);
const savePath = cacheCurrentCEM(basePath, manifest);
console.log("Manifest file written to ", savePath);

return {
manifest,
filePath: savePath
return {
manifest,
filePath: savePath
}
} catch (ex) {
console.warn("Parsing through manifest failed. ", ex);
return {
manifest: EMPTY_OUTPUT,
filePath: ""
}
}
}

Expand All @@ -78,7 +89,6 @@ async function getFilesForGlobs(globs: string[], globExcludes: string[], basePat

let filesForAnalyzer: string[] = [];
try {
console.log("Using globs ", globsToUse)
filesForAnalyzer = await globby([...globsToUse, "!node_modules"], {
gitignore: true,
cwd: basePath
Expand Down Expand Up @@ -161,7 +171,12 @@ async function getPossibleProjectConfig(basePath: string) {
const cachedManifestPath = cacheManifestConfigAsModule(basePath, configFileContent);

// Now we have our config locally setup in a `mjs` file and can import it.
const importedConfig = await import(cachedManifestPath + `?cachebust=${Date.now().toString()}`);
let importedConfig;
try {
importedConfig = await import(cachedManifestPath + `?cachebust=${Date.now().toString()}`);
} catch (ex) {
console.warn("Could not import custom-elements-manifest.config. ", ex);
}

if (!importedConfig) {
return DEFAULT_CONFIG;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class CEMInstance {


if (!fs.existsSync(builderData.cemPath)) {
console.log("Could not find 'customElements' entry in package.json at " + builderData.packageJsonPath);
// console.log("Could not find 'customElements' entry in package.json at " + builderData.packageJsonPath);
return;
}
const cemFile = fs.readFileSync(builderData.cemPath, "utf8");
Expand Down

0 comments on commit 50b11b7

Please sign in to comment.