diff --git a/Cargo.lock b/Cargo.lock index b50c6e97e05e37..70e5b51b804997 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,27 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" +dependencies = [ + "lazy_static", + "regex", +] + +[[package]] +name = "ahash" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" +dependencies = [ + "getrandom", + "once_cell", + "version_check", +] + [[package]] name = "ahash" version = "0.8.3" @@ -48,6 +69,19 @@ dependencies = [ "tempfile", ] +[[package]] +name = "ast_node" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c09c69dffe06d222d072c878c3afe86eee2179806f20503faec97250268b4c24" +dependencies = [ + "pmutil", + "proc-macro2", + "quote", + "swc_macros_common", + "syn 2.0.15", +] + [[package]] name = "async-priority-channel" version = "0.1.0" @@ -102,6 +136,15 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +[[package]] +name = "better_scoped_tls" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "794edcc9b3fb07bb4aecaa11f093fd45663b4feadb782d68303a2268bc2701de" +dependencies = [ + "scoped-tls", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -355,6 +398,27 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" +[[package]] +name = "form_urlencoded" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a62bc1cf6f830c2ec14a513a9fb124d0a213a629668a4186f329db21fe045652" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "from_variant" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03ec5dc38ee19078d84a692b1c41181ff9f94331c76cee66ff0208c770b5e54f" +dependencies = [ + "pmutil", + "proc-macro2", + "swc_macros_common", + "syn 2.0.15", +] + [[package]] name = "fs_extra" version = "1.3.0" @@ -710,7 +774,7 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" dependencies = [ - "ahash", + "ahash 0.8.3", "allocator-api2", "rayon", ] @@ -754,6 +818,16 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "idna" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d20d6b07bfbc108882d88ed8e37d39636dcc260e15e30c45e6ba089610b917c" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "ignore" version = "0.4.20" @@ -829,6 +903,19 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "is-macro" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4467ed1321b310c2625c5aa6c1b1ffc5de4d9e42668cf697a08fb033ee8265e" +dependencies = [ + "Inflector", + "pmutil", + "proc-macro2", + "quote", + "syn 2.0.15", +] + [[package]] name = "itertools" version = "0.10.5" @@ -870,6 +957,79 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" +[[package]] +name = "lexical" +version = "6.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7aefb36fd43fef7003334742cbf77b243fcd36418a1d1bdd480d613a67968f6" +dependencies = [ + "lexical-core", +] + +[[package]] +name = "lexical-core" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2cde5de06e8d4c2faabc400238f9ae1c74d5412d03a7bd067645ccbc47070e46" +dependencies = [ + "lexical-parse-float", + "lexical-parse-integer", + "lexical-util", + "lexical-write-float", + "lexical-write-integer", +] + +[[package]] +name = "lexical-parse-float" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "683b3a5ebd0130b8fb52ba0bdc718cc56815b6a097e28ae5a6997d0ad17dc05f" +dependencies = [ + "lexical-parse-integer", + "lexical-util", + "static_assertions", +] + +[[package]] +name = "lexical-parse-integer" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d0994485ed0c312f6d965766754ea177d07f9c00c9b82a5ee62ed5b47945ee9" +dependencies = [ + "lexical-util", + "static_assertions", +] + +[[package]] +name = "lexical-util" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5255b9ff16ff898710eb9eb63cb39248ea8a5bb036bea8085b1a767ff6c4e3fc" +dependencies = [ + "static_assertions", +] + +[[package]] +name = "lexical-write-float" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "accabaa1c4581f05a3923d1b4cfd124c329352288b7b9da09e766b0668116862" +dependencies = [ + "lexical-util", + "lexical-write-integer", + "static_assertions", +] + +[[package]] +name = "lexical-write-integer" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1b6f3d1f4422866b68192d62f77bc5c700bee84f3069f2469d7bc8c77852446" +dependencies = [ + "lexical-util", + "static_assertions", +] + [[package]] name = "libc" version = "0.2.139" @@ -1053,6 +1213,12 @@ dependencies = [ "libloading", ] +[[package]] +name = "new_debug_unreachable" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4a24736216ec316047a1fc4252e27dabb04218aa4a3f37c6e7ddbf1f9782b54" + [[package]] name = "nibble_vec" version = "0.1.0" @@ -1120,6 +1286,28 @@ dependencies = [ "winapi", ] +[[package]] +name = "num-bigint" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", + "serde", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + [[package]] name = "num-traits" version = "0.2.15" @@ -1166,6 +1354,10 @@ dependencies = [ "napi-build", "napi-derive", "rayon", + "swc_common", + "swc_ecma_ast", + "swc_ecma_parser", + "swc_ecma_visit", "thiserror", "tokio", "tracing", @@ -1213,13 +1405,19 @@ dependencies = [ "windows-sys 0.45.0", ] +[[package]] +name = "percent-encoding" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" + [[package]] name = "phf" version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "928c6535de93548188ef63bb7c4036bd415cd8f36ad25af44b9789b2ee72a48c" dependencies = [ - "phf_shared", + "phf_shared 0.11.1", ] [[package]] @@ -1228,8 +1426,18 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a56ac890c5e3ca598bbdeaa99964edb5b0258a583a9eb6ef4e89fc85d9224770" dependencies = [ - "phf_generator", - "phf_shared", + "phf_generator 0.11.1", + "phf_shared 0.11.1", +] + +[[package]] +name = "phf_generator" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6" +dependencies = [ + "phf_shared 0.10.0", + "rand", ] [[package]] @@ -1238,10 +1446,19 @@ version = "0.11.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b1181c94580fa345f50f19d738aaa39c0ed30a600d95cb2d3e23f94266f14fbf" dependencies = [ - "phf_shared", + "phf_shared 0.11.1", "rand", ] +[[package]] +name = "phf_shared" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096" +dependencies = [ + "siphasher", +] + [[package]] name = "phf_shared" version = "0.11.1" @@ -1263,6 +1480,29 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "pmutil" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52a40bc70c2c58040d2d8b167ba9a5ff59fc9dab7ad44771cfde3dcfde7a09c6" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.15", +] + +[[package]] +name = "ppv-lite86" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + [[package]] name = "predicates" version = "2.1.5" @@ -1310,6 +1550,15 @@ dependencies = [ "tokio-stream", ] +[[package]] +name = "psm" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5787f7cda34e3033a72192c018bc5883100330f362ef279a8cbccfce8bb4e874" +dependencies = [ + "cc", +] + [[package]] name = "quote" version = "1.0.27" @@ -1335,6 +1584,18 @@ version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ + "libc", + "rand_chacha", + "rand_core", +] + +[[package]] +name = "rand_chacha" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" +dependencies = [ + "ppv-lite86", "rand_core", ] @@ -1343,6 +1604,9 @@ name = "rand_core" version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" +dependencies = [ + "getrandom", +] [[package]] name = "rayon" @@ -1421,6 +1685,12 @@ version = "0.6.28" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "456c603be3e8d448b072f410900c09faf164fbce2d480456f50eea6e25f9c848" +[[package]] +name = "rustc-hash" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" + [[package]] name = "rustix" version = "0.37.3" @@ -1444,6 +1714,12 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "scoped-tls" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" + [[package]] name = "scopeguard" version = "1.1.0" @@ -1461,6 +1737,20 @@ name = "serde" version = "1.0.152" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bb7d1f0d3021d347a83e556fc4683dea2ea09d87bccdf88ff5c12545d89d5efb" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.152" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af487d118eecd09402d70a5d72551860e788df87b464af30e5ea6a38c75c541e" +dependencies = [ + "proc-macro2", + "quote", + "syn 1.0.107", +] [[package]] name = "sha1_smol" @@ -1507,12 +1797,220 @@ version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" +[[package]] +name = "smartstring" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fb72c633efbaa2dd666986505016c32c3044395ceaf881518399d2f4127ee29" +dependencies = [ + "autocfg", + "static_assertions", + "version_check", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a8f112729512f8e442d81f95a8a7ddf2b7c6b8a1a6f509a95864142b30cab2d3" + +[[package]] +name = "stacker" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c886bd4480155fd3ef527d45e9ac8dd7118a898a46530b7b94c3e21866259fce" +dependencies = [ + "cc", + "cfg-if", + "libc", + "psm", + "winapi", +] + [[package]] name = "static_assertions" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "string_cache" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f91138e76242f575eb1d3b38b4f1362f10d3a43f47d182a5b359af488a02293b" +dependencies = [ + "new_debug_unreachable", + "once_cell", + "parking_lot", + "phf_shared 0.10.0", + "precomputed-hash", + "serde", +] + +[[package]] +name = "string_cache_codegen" +version = "0.5.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988" +dependencies = [ + "phf_generator 0.10.0", + "phf_shared 0.10.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "string_enum" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8fa4d4f81d7c05b9161f8de839975d3326328b8ba2831164b465524cc2f55252" +dependencies = [ + "pmutil", + "proc-macro2", + "quote", + "swc_macros_common", + "syn 2.0.15", +] + +[[package]] +name = "swc_atoms" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b1370fa1d31e18a999928aaf18f166616b16c5cb7033ced7d50d06858c5fd90" +dependencies = [ + "once_cell", + "rustc-hash", + "serde", + "string_cache", + "string_cache_codegen", + "triomphe", +] + +[[package]] +name = "swc_common" +version = "0.31.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe738c06147072c476d7e12ee0e99fd947549909c7c0404abd78d95433f75a67" +dependencies = [ + "ahash 0.7.6", + "ast_node", + "better_scoped_tls", + "cfg-if", + "either", + "from_variant", + "new_debug_unreachable", + "num-bigint", + "once_cell", + "rustc-hash", + "serde", + "siphasher", + "string_cache", + "swc_atoms", + "swc_eq_ignore_macros", + "swc_visit", + "tracing", + "unicode-width", + "url", +] + +[[package]] +name = "swc_ecma_ast" +version = "0.106.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad6c7a25a43568de41e9a4c111b7015b78bb269414395574a2604853748ca71c" +dependencies = [ + "bitflags 2.2.1", + "is-macro", + "num-bigint", + "scoped-tls", + "string_enum", + "swc_atoms", + "swc_common", + "unicode-id", +] + +[[package]] +name = "swc_ecma_parser" +version = "0.136.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d401703f48f2cbb6045d45a6874f72fa5b3fb8f7da4981338764220b33f7b" +dependencies = [ + "either", + "lexical", + "num-bigint", + "serde", + "smallvec", + "smartstring", + "stacker", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "tracing", + "typed-arena", +] + +[[package]] +name = "swc_ecma_visit" +version = "0.92.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20fa5bf3383dbf864d85e4f8e3bc574b1b1bca9f0ca0bb11da3d6add717484be" +dependencies = [ + "num-bigint", + "swc_atoms", + "swc_common", + "swc_ecma_ast", + "swc_visit", + "tracing", +] + +[[package]] +name = "swc_eq_ignore_macros" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05a95d367e228d52484c53336991fdcf47b6b553ef835d9159db4ba40efb0ee8" +dependencies = [ + "pmutil", + "proc-macro2", + "quote", + "syn 2.0.15", +] + +[[package]] +name = "swc_macros_common" +version = "0.3.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7a273205ccb09b51fabe88c49f3b34c5a4631c4c00a16ae20e03111d6a42e832" +dependencies = [ + "pmutil", + "proc-macro2", + "quote", + "syn 2.0.15", +] + +[[package]] +name = "swc_visit" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e87c337fbb2d191bf371173dea6a957f01899adb8f189c6c31b122a6cfc98fc3" +dependencies = [ + "either", + "swc_visit_macros", +] + +[[package]] +name = "swc_visit_macros" +version = "0.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f322730fb82f3930a450ac24de8c98523af7d34ab8cb2f46bcb405839891a99" +dependencies = [ + "Inflector", + "pmutil", + "proc-macro2", + "quote", + "swc_macros_common", + "syn 2.0.15", +] + [[package]] name = "syn" version = "1.0.107" @@ -1625,6 +2123,21 @@ dependencies = [ "time-core", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "tokio" version = "1.28.2" @@ -1727,18 +2240,55 @@ dependencies = [ "tracing-log", ] +[[package]] +name = "triomphe" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee8098afad3fb0c54a9007aab6804558410503ad676d4633f9c2559a00ac0f" +dependencies = [ + "serde", + "stable_deref_trait", +] + +[[package]] +name = "typed-arena" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6af6ae20167a9ece4bcb41af5b80f8a1f1df981f6391189ce00fd257af04126a" + +[[package]] +name = "unicode-bidi" +version = "0.3.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" + [[package]] name = "unicode-bom" version = "2.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "98e90c70c9f0d4d1ee6d0a7d04aa06cb9bbd53d8cfbdd62a0269a7c2eb640552" +[[package]] +name = "unicode-id" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d70b6494226b36008c8366c288d77190b3fad2eb4c10533139c1c1f461127f1a" + [[package]] name = "unicode-ident" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + [[package]] name = "unicode-segmentation" version = "1.10.0" @@ -1751,6 +2301,17 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" +[[package]] +name = "url" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50bff7831e19200a85b17131d085c25d7811bc4e186efdaf54bbd132994a88cb" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + [[package]] name = "valuable" version = "0.1.0" diff --git a/packages/nx/Cargo.toml b/packages/nx/Cargo.toml index 2443f8823382cd..b0f31b027e0379 100644 --- a/packages/nx/Cargo.toml +++ b/packages/nx/Cargo.toml @@ -27,6 +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" + [lib] crate-type = ['cdylib'] diff --git a/packages/nx/src/native/index.d.ts b/packages/nx/src/native/index.d.ts index d5445ab9341d42..e914bacfd9d902 100644 --- a/packages/nx/src/native/index.d.ts +++ b/packages/nx/src/native/index.d.ts @@ -44,6 +44,7 @@ export interface NxWorkspaceFiles { projectConfigurations: Record } export function getWorkspaceFilesNative(workspaceRoot: string, globs: Array, parseConfigurations: (arg0: Array) => Record): NxWorkspaceFiles +export function findImports(filePaths: Array, callback: (obj: null, result: {file: string, importExpr: string}) => void): void export class Watcher { origin: string /** @@ -54,3 +55,7 @@ export class Watcher { watch(callback: (err: string | null, events: WatchEvent[]) => void): void stop(): Promise } +export class ImportResult { + file: string + importExpr: string +} diff --git a/packages/nx/src/native/index.js b/packages/nx/src/native/index.js index a1c22704faa12d..a718534006cde7 100644 --- a/packages/nx/src/native/index.js +++ b/packages/nx/src/native/index.js @@ -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 } = nativeBinding +const { expandOutputs, remove, copy, hashArray, hashFile, hashFiles, hashFilesMatchingGlobs, EventType, Watcher, WorkspaceErrors, getProjectConfigurations, getWorkspaceFilesNative, ImportResult, findImports } = nativeBinding module.exports.expandOutputs = expandOutputs module.exports.remove = remove @@ -260,3 +260,5 @@ module.exports.Watcher = Watcher module.exports.WorkspaceErrors = WorkspaceErrors module.exports.getProjectConfigurations = getProjectConfigurations module.exports.getWorkspaceFilesNative = getWorkspaceFilesNative +module.exports.ImportResult = ImportResult +module.exports.findImports = findImports diff --git a/packages/nx/src/native/mod.rs b/packages/nx/src/native/mod.rs index 8225da804196ab..8101c51be7cadf 100644 --- a/packages/nx/src/native/mod.rs +++ b/packages/nx/src/native/mod.rs @@ -6,3 +6,4 @@ mod utils; mod walker; pub mod watch; pub mod workspace; +pub mod ts_import_locators; diff --git a/packages/nx/src/native/ts_import_locators.rs b/packages/nx/src/native/ts_import_locators.rs new file mode 100644 index 00000000000000..17e0b7ea52b9e2 --- /dev/null +++ b/packages/nx/src/native/ts_import_locators.rs @@ -0,0 +1,119 @@ +use std::fs::read_to_string; +use std::io::{Error, ErrorKind}; + +use rayon::prelude::*; +use napi::bindgen_prelude::*; +use napi::JsFunction; +use napi::threadsafe_function::{ + ThreadSafeCallContext, + ThreadsafeFunction, + ThreadsafeFunctionCallMode, +}; +use swc_common::{ + FileName, + SourceMap, + sync::Lrc, +}; +use swc_ecma_ast::{CallExpr, Expr, ImportDecl, Lit, Str}; +use swc_ecma_parser::{ + lexer::Lexer, + Parser, + StringInput, + Syntax, + TsConfig, +}; +use swc_ecma_visit::{Visit, VisitWith}; + +#[napi] +pub struct ImportResult { + pub file: String, + pub import_expr: String, +} + +struct ImportVisitor<'a> { + pub file: String, + pub callback: &'a ThreadsafeFunction, +} + +impl Visit for ImportVisitor<'_> { + fn visit_import_decl(&mut self, import_decl: &ImportDecl) { + self.callback.call(Ok(ImportResult { + file: self.file.to_owned(), + import_expr: import_decl.src.value.to_string(), + }), ThreadsafeFunctionCallMode::NonBlocking); + } + + fn visit_call_expr(&mut self, call_expr: &CallExpr) { + if call_expr.callee.is_import() { + if let Some(arg) = call_expr.args.get(0) { + if let Expr::Lit(lit) = &*arg.expr { + if let Lit::Str(Str { value: sym, raw: _, span: _ }) = lit { + self.callback.call(Ok(ImportResult { + file: self.file.to_owned(), + import_expr: sym.to_string(), + }), ThreadsafeFunctionCallMode::NonBlocking); + } + } + } + } + } +} + +fn process_file(file_path: String, callback: &mut ThreadsafeFunction) -> () { + let file = file_path.clone(); + let tsx = file_path.ends_with(".tsx") || file_path.ends_with(".jsx"); + let content = read_to_string(&file_path); + + match content { + Ok(source) => { + let cm: Lrc = Default::default(); + let fm = cm.new_source_file(FileName::Real(file_path.into()), source.clone()); + let lexer = Lexer::new( + Syntax::Typescript(TsConfig { + tsx, + ..TsConfig::default() + }), + Default::default(), + StringInput::from(&*fm), + None, + ); + let mut parser = Parser::new_from(lexer); + let mut visitor = ImportVisitor { file, callback }; + let module = parser.parse_module() + .map_err(|_| Error::new(ErrorKind::Other, "Failed to parse file")); + + match module { + Ok(module) => { + module.visit_with(&mut visitor); + } + Err(_) => {} + } + } + Err(_) => {} + } +} + +#[napi] +fn find_imports( + file_paths: Vec, + // TODO: Figure out why the first arg is being passed as null. The result should be the first arg. + #[napi(ts_arg_type = "(obj: null, result: {file: string, importExpr: string}) => void")] + callback: JsFunction, +) -> Result<()> { + let thread_safe_callback: ThreadsafeFunction = + callback.create_threadsafe_function( + 0, + |ctx: ThreadSafeCallContext| { + let data: ImportResult = ctx.value; + Ok(vec![data]) + }, + )?; + + file_paths + .into_par_iter() + .for_each_with(thread_safe_callback, |callback, file_path| { + process_file(file_path, callback) + }); + + Ok(()) +} diff --git a/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.ts b/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.ts index 385379fb2d8b30..a8a36b78f49bca 100644 --- a/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.ts +++ b/packages/nx/src/plugins/js/project-graph/build-dependencies/explicit-project-dependencies.ts @@ -1,5 +1,6 @@ import { TypeScriptImportLocator } from './typescript-import-locator'; import { TargetProjectLocator } from './target-project-locator'; +import { findImports } from '../../../../native'; import { DependencyType, ProjectFileMap, @@ -16,11 +17,71 @@ export type ExplicitDependency = { export function buildExplicitTypeScriptDependencies( graph: ProjectGraph, filesToProcess: ProjectFileMap -) { - function isRoot(projectName: string) { - return graph.nodes[projectName]?.data?.root === '.'; +): ExplicitDependency[] { + let results: ExplicitDependency[]; + if (process.env.NX_SWC_IMPORT_LOCATOR) { + results = buildExplicitTypeScriptDependenciesWithSwc(filesToProcess, graph); + } else { + results = buildExplicitTypeScriptDependenciesWithTs(filesToProcess, graph); } + return results; +} + +function isRoot(graph: ProjectGraph, projectName: string): boolean { + return graph.nodes[projectName]?.data?.root === '.'; +} + +function buildExplicitTypeScriptDependenciesWithSwc( + filesToProcess: ProjectFileMap, + graph: ProjectGraph +): ExplicitDependency[] { + const targetProjectLocator = new TargetProjectLocator( + graph.nodes as any, + graph.externalNodes + ); + const res: ExplicitDependency[] = []; + + Object.keys(filesToProcess).forEach((source) => { + const files = filesToProcess[source]; + findImports( + files.map((f) => f.file), + (_, { file, importExpr }) => { + const target = targetProjectLocator.findProjectWithImport( + importExpr, + file + ); + let targetProjectName; + if (target) { + if (!isRoot(graph, source) && isRoot(graph, target)) { + // TODO: These edges technically should be allowed but we need to figure out how to separate config files out from root + return; + } + + targetProjectName = target; + } else { + // treat all unknowns as npm packages, they can be eiher + // - mistyped local import, which has to be fixed manually + // - node internals, which should still be tracked as a dependency + // - npm packages, which are not yet installed but should be tracked + targetProjectName = `npm:${importExpr}`; + } + + res.push({ + sourceProjectName: source, + targetProjectName, + sourceProjectFile: file, + type: DependencyType.static, + }); + } + ); + }); + return res; +} +function buildExplicitTypeScriptDependenciesWithTs( + filesToProcess: ProjectFileMap, + graph: ProjectGraph +): ExplicitDependency[] { const importLocator = new TypeScriptImportLocator(); const targetProjectLocator = new TargetProjectLocator( graph.nodes as any, @@ -42,7 +103,7 @@ export function buildExplicitTypeScriptDependencies( ); let targetProjectName; if (target) { - if (!isRoot(source) && isRoot(target)) { + if (!isRoot(graph, source) && isRoot(graph, target)) { // TODO: These edges technically should be allowed but we need to figure out how to separate config files out from root return; }