-
Notifications
You must be signed in to change notification settings - Fork 878
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
745 additions
and
735 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
'@lit-labs/analyzer': minor | ||
'@lit-labs/gen-wrapper-angular': minor | ||
'@lit-labs/gen-wrapper-react': minor | ||
'@lit-labs/gen-wrapper-vue': minor | ||
--- | ||
|
||
Refactored Analyzer into better fit for use in plugins. Analyzer class now takes a ts.Program, and PackageAnalyzer takes a package path and creates a program to analyze a package on the filesystem. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import ts from 'typescript'; | ||
import {AbsolutePath} from './paths.js'; | ||
import * as path from 'path'; | ||
import {DiagnosticsError} from './errors.js'; | ||
import {Analyzer} from './analyzer.js'; | ||
|
||
/** | ||
* Returns an analyzer for a Lit npm package based on a filesystem path. | ||
*/ | ||
export const createPackageAnalyzer = (packageRoot: AbsolutePath) => { | ||
const configFileName = ts.findConfigFile( | ||
packageRoot, | ||
ts.sys.fileExists, | ||
'tsconfig.json' | ||
); | ||
if (configFileName === undefined) { | ||
// TODO: use a hard-coded tsconfig for JS projects. | ||
throw new Error(`tsconfig.json not found in ${packageRoot}`); | ||
} | ||
const configFile = ts.readConfigFile(configFileName, ts.sys.readFile); | ||
// Note `configFileName` is optional but must be set for | ||
// `getOutputFileNames` to work correctly; however, it must be relative to | ||
// `packageRoot` | ||
const commandLine = ts.parseJsonConfigFileContent( | ||
configFile.config /* json */, | ||
ts.sys /* host */, | ||
packageRoot /* basePath */, | ||
undefined /* existingOptions */, | ||
path.relative(packageRoot, configFileName) /* configFileName */ | ||
); | ||
|
||
const program = ts.createProgram(commandLine.fileNames, commandLine.options); | ||
|
||
const analyzer = new Analyzer({getProgram: () => program, fs: ts.sys, path}); | ||
|
||
const diagnostics = program.getSemanticDiagnostics(); | ||
if (diagnostics.length > 0) { | ||
throw new DiagnosticsError( | ||
diagnostics, | ||
`Error analyzing package '${packageRoot}': Please fix errors first` | ||
); | ||
} | ||
|
||
return analyzer; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.