Skip to content

Commit e2f1c92

Browse files
FrozenPandazjaysoo
andauthored
feat(js): introduce rust-based typescript dependency processor (nrwl#17976)
Co-authored-by: Jack Hsu <[email protected]>
1 parent d4f0e30 commit e2f1c92

File tree

16 files changed

+1936
-48
lines changed

16 files changed

+1936
-48
lines changed

Cargo.lock

+576-12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/nx/Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ watchexec-filterer-ignore = "1.2.1"
2727
watchexec-signals = "1.0.0"
2828
xxhash-rust = { version = '0.8.5', features = ['xxh3', 'xxh64'] }
2929

30+
swc_common = "0.31.16"
31+
swc_ecma_parser = { version = "0.137.1", features = ["typescript"] }
32+
swc_ecma_visit = "0.93.0"
33+
swc_ecma_ast = "0.107.0"
34+
3035
[lib]
3136
crate-type = ['cdylib']
3237

@@ -35,3 +40,5 @@ napi-build = '2.0.1'
3540

3641
[dev-dependencies]
3742
assert_fs = "1.0.10"
43+
# This is only used for unit tests
44+
swc_ecma_dep_graph = "0.109.1"

packages/nx/src/adapter/angular-json.ts

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export function shouldMergeAngularProjects(
2828

2929
export function isAngularPluginInstalled() {
3030
try {
31+
// nx-ignore-next-line
3132
require.resolve('@nx/angular');
3233
return true;
3334
} catch {

packages/nx/src/native/index.d.ts

+7
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export function hashArray(input: Array<string>): string
1414
export function hashFile(file: string): FileData | null
1515
export function hashFiles(workspaceRoot: string): Record<string, string>
1616
export function hashFilesMatchingGlobs(directory: string, globPatterns: Array<string>): string | null
17+
export function findImports(projectFileMap: Record<string, Array<string>>): Array<ImportResult>
1718
export interface FileData {
1819
file: string
1920
hash: string
@@ -44,6 +45,12 @@ export interface NxWorkspaceFiles {
4445
projectConfigurations: Record<string, object>
4546
}
4647
export function getWorkspaceFilesNative(workspaceRoot: string, globs: Array<string>, parseConfigurations: (arg0: Array<string>) => Record<string, object>): NxWorkspaceFiles
48+
export class ImportResult {
49+
file: string
50+
sourceProject: string
51+
dynamicImportExpressions: Array<string>
52+
staticImportExpressions: Array<string>
53+
}
4754
export class Watcher {
4855
origin: string
4956
/**

packages/nx/src/native/index.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ if (!nativeBinding) {
246246
throw new Error(`Failed to load native binding`)
247247
}
248248

249-
const { expandOutputs, remove, copy, hashArray, hashFile, hashFiles, hashFilesMatchingGlobs, EventType, Watcher, WorkspaceErrors, getProjectConfigurations, getWorkspaceFilesNative } = nativeBinding
249+
const { expandOutputs, remove, copy, hashArray, hashFile, hashFiles, hashFilesMatchingGlobs, ImportResult, findImports, EventType, Watcher, WorkspaceErrors, getProjectConfigurations, getWorkspaceFilesNative } = nativeBinding
250250

251251
module.exports.expandOutputs = expandOutputs
252252
module.exports.remove = remove
@@ -255,6 +255,8 @@ module.exports.hashArray = hashArray
255255
module.exports.hashFile = hashFile
256256
module.exports.hashFiles = hashFiles
257257
module.exports.hashFilesMatchingGlobs = hashFilesMatchingGlobs
258+
module.exports.ImportResult = ImportResult
259+
module.exports.findImports = findImports
258260
module.exports.EventType = EventType
259261
module.exports.Watcher = Watcher
260262
module.exports.WorkspaceErrors = WorkspaceErrors

packages/nx/src/native/logger/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ where
6363

6464
pub(crate) fn enable_logger() {
6565
let env_filter =
66-
EnvFilter::try_from_env("NX_NATIVE_LOGGING").unwrap_or_else(|_| EnvFilter::new("INFO"));
66+
EnvFilter::try_from_env("NX_NATIVE_LOGGING").unwrap_or_else(|_| EnvFilter::new("ERROR"));
6767
_ = tracing_subscriber::fmt()
6868
.with_env_filter(env_filter)
6969
.event_format(NxLogFormatter)

packages/nx/src/native/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub mod cache;
22
pub mod hasher;
33
mod logger;
4+
pub mod plugins;
45
mod types;
56
mod utils;
67
mod walker;

packages/nx/src/native/plugins/js.rs

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mod ts_import_locators;

0 commit comments

Comments
 (0)