-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(feature-detector): introduces findDependencies() which returns t…
…he list of globals.
- Loading branch information
Showing
13 changed files
with
2,358 additions
and
18,272 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
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,31 @@ | ||
// run with ts-node | ||
import { build } from 'esbuild' | ||
import { readdir, readFile, writeFile } from 'node:fs/promises' | ||
import { join } from 'node:path' | ||
|
||
const fixtureFolder = join(__dirname, '../test/fixtures') | ||
const resultExtension = '.out.js' | ||
|
||
async function transpileAll() { | ||
for (const file of await readdir(fixtureFolder)) { | ||
if (!file.endsWith(resultExtension)) { | ||
await transpileFile(file) | ||
} | ||
} | ||
} | ||
|
||
async function transpileFile(file: string) { | ||
const filePath = join(fixtureFolder, file) | ||
await build({ | ||
entryPoints: [filePath], | ||
bundle: true, | ||
outfile: filePath.replace(/\..+$/, resultExtension), | ||
}) | ||
} | ||
|
||
transpileAll() | ||
.then(() => process.exit(0)) | ||
.catch((error) => { | ||
console.log('Errored', error) | ||
process.exit(1) | ||
}) |
107 changes: 0 additions & 107 deletions
107
packages/feature-detector/scripts/patch-type-definition.ts
This file was deleted.
Oops, something went wrong.
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,37 @@ | ||
import { Project, ts } from 'ts-morph' | ||
import { buildProject } from './utils/project' | ||
|
||
/** | ||
* Find the list of globals used by source files in the provided project. | ||
* Analyzed source files can be filtered by provided a list of glob patterns (default to all TypeScript and JavaScript files, excluding type definitions) | ||
*/ | ||
export function findDependencies( | ||
sourcePath: string, | ||
project: Project = buildProject() | ||
): { | ||
globals: string[] | ||
} { | ||
const globals = new Set<string>() | ||
const sourceFile = project.addSourceFileAtPath(sourcePath) | ||
const program = project.getProgram().compilerObject | ||
const diagnostics = program.getSemanticDiagnostics(sourceFile.compilerNode) | ||
for (const { code, messageText } of diagnostics) { | ||
if ( | ||
// see all messages: https://github.com/microsoft/TypeScript/blob/main/src/compiler/diagnosticMessages.json#L1631 | ||
code === 2304 || | ||
code === 2311 || | ||
code === 2552 || | ||
(code >= 2562 && code <= 2563) || | ||
(code >= 2580 && code <= 2584) || | ||
(code >= 2591 && code <= 2593) | ||
) { | ||
const match = ts | ||
.flattenDiagnosticMessageText(messageText, '\n') | ||
.match(/^Cannot find name '([^']+)'\./) | ||
if (match) { | ||
globals.add(match[1]) | ||
} | ||
} | ||
} | ||
return { globals: [...globals] } | ||
} |
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 |
---|---|---|
@@ -1 +1,2 @@ | ||
export * from './find-dependencies' | ||
export * from './has-edge-signature' |
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.