Skip to content

Commit

Permalink
feat(core): switch to using a parser for imports
Browse files Browse the repository at this point in the history
  • Loading branch information
FrozenPandaz committed Jul 17, 2023
1 parent 2159e4b commit b1676df
Show file tree
Hide file tree
Showing 14 changed files with 1,187 additions and 201 deletions.
63 changes: 33 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions packages/nx/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,11 @@ watchexec-filterer-ignore = "1.2.1"
watchexec-signals = "1.0.0"
xxhash-rust = { version = '0.8.5', features = ['xxh3', 'xxh64'] }

swc_common = "0.31.12"
swc_ecma_parser = { version = "0.136.0", features = ["typescript"] }
swc_ecma_visit = "0.92.0"
swc_ecma_ast = "0.106.0"
swc_common = "0.31.16"
swc_ecma_parser = { version = "0.137.1", features = ["typescript"] }
swc_ecma_visit = "0.93.0"
swc_ecma_ast = "0.107.0"
swc_ecma_dep_graph = "0.109.1"

[lib]
crate-type = ['cdylib']
Expand Down
12 changes: 7 additions & 5 deletions packages/nx/src/native/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export function hashArray(input: Array<string>): string
export function hashFile(file: string): FileData | null
export function hashFiles(workspaceRoot: string): Record<string, string>
export function hashFilesMatchingGlobs(directory: string, globPatterns: Array<string>): string | null
export function findImports(projectFileMap: Record<string, Array<string>>): Array<ImportResult>
export interface FileData {
file: string
hash: string
Expand Down Expand Up @@ -44,7 +45,12 @@ export interface NxWorkspaceFiles {
projectConfigurations: Record<string, object>
}
export function getWorkspaceFilesNative(workspaceRoot: string, globs: Array<string>, parseConfigurations: (arg0: Array<string>) => Record<string, object>): NxWorkspaceFiles
export function findImports(filePaths: Array<string>, callback: (obj: null, result: {file: string, importExpr: string}) => void): void
export class ImportResult {
file: string
sourceProject: string
dynamicImportExpressions: Array<string>
staticImportExpressions: Array<string>
}
export class Watcher {
origin: string
/**
Expand All @@ -55,7 +61,3 @@ export class Watcher {
watch(callback: (err: string | null, events: WatchEvent[]) => void): void
stop(): Promise<void>
}
export class ImportResult {
file: string
importExpr: string
}
6 changes: 3 additions & 3 deletions packages/nx/src/native/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ if (!nativeBinding) {
throw new Error(`Failed to load native binding`)
}

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

module.exports.expandOutputs = expandOutputs
module.exports.remove = remove
Expand All @@ -255,10 +255,10 @@ module.exports.hashArray = hashArray
module.exports.hashFile = hashFile
module.exports.hashFiles = hashFiles
module.exports.hashFilesMatchingGlobs = hashFilesMatchingGlobs
module.exports.ImportResult = ImportResult
module.exports.findImports = findImports
module.exports.EventType = EventType
module.exports.Watcher = Watcher
module.exports.WorkspaceErrors = WorkspaceErrors
module.exports.getProjectConfigurations = getProjectConfigurations
module.exports.getWorkspaceFilesNative = getWorkspaceFilesNative
module.exports.ImportResult = ImportResult
module.exports.findImports = findImports
2 changes: 1 addition & 1 deletion packages/nx/src/native/logger/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ where

pub(crate) fn enable_logger() {
let env_filter =
EnvFilter::try_from_env("NX_NATIVE_LOGGING").unwrap_or_else(|_| EnvFilter::new("INFO"));
EnvFilter::try_from_env("NX_NATIVE_LOGGING").unwrap_or_else(|_| EnvFilter::new("ERROR"));
_ = tracing_subscriber::fmt()
.with_env_filter(env_filter)
.event_format(NxLogFormatter)
Expand Down
2 changes: 1 addition & 1 deletion packages/nx/src/native/mod.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
pub mod cache;
pub mod hasher;
mod logger;
pub mod plugins;
mod types;
mod utils;
mod walker;
pub mod watch;
pub mod workspace;
pub mod ts_import_locators;
1 change: 1 addition & 0 deletions packages/nx/src/native/plugins/js.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
mod ts_import_locators;
Loading

0 comments on commit b1676df

Please sign in to comment.