Skip to content

Commit

Permalink
[All] Don't scan System packages for Fable plugins
Browse files Browse the repository at this point in the history
Fix #3974
  • Loading branch information
MangelMaxime committed Feb 24, 2025
1 parent 9b6ba61 commit 2f3f36e
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 26 deletions.
1 change: 1 addition & 0 deletions src/Fable.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [JS/TS] Propagate non-captured exception when running `Async.Start` or `Async.StartImmediate` (by @MangelMaxime)
* [JS/TS] Report an error at compilation time when trying to use `Async.RunSynchronously` (by @MangelMaxime)
* [JS/TS] Fix short `DateTime` and `DateTimeOffset` short format strings (by @MangelMaxime)
* [All] Don't scan system packages for plugins (by @MangelMaxime)

## 5.0.0-alpha.10 - 2025-02-16

Expand Down
1 change: 1 addition & 0 deletions src/Fable.Compiler/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* [JS/TS] Propagate non-captured exception when running `Async.Start` or `Async.StartImmediate` (by @MangelMaxime)
* [JS/TS] Report an error at compilation time when trying to use `Async.RunSynchronously` (by @MangelMaxime)
* [JS/TS] Fix short `DateTime` and `DateTimeOffset` short format strings (by @MangelMaxime)
* [All] Don't scan system packages for plugins (by @MangelMaxime)

## 5.0.0-alpha.10 - 2025-02-16

Expand Down
14 changes: 3 additions & 11 deletions src/Fable.Compiler/ProjectCracker.fs
Original file line number Diff line number Diff line change
Expand Up @@ -177,14 +177,6 @@ type ProjectCrackerResolver =
abstract member GetProjectOptionsFromProjectFile:
isMain: bool * options: CrackerOptions * projectFile: string -> ProjectOptionsResponse

let isSystemPackage (pkgName: string) =
pkgName.StartsWith("System.", StringComparison.Ordinal)
|| pkgName.StartsWith("Microsoft.", StringComparison.Ordinal)
|| pkgName.StartsWith("runtime.", StringComparison.Ordinal)
|| pkgName = "NETStandard.Library"
|| pkgName = "FSharp.Core"
|| pkgName = "Fable.Core"

type CrackedFsproj =
{
ProjectFile: string
Expand Down Expand Up @@ -260,7 +252,7 @@ let tryGetFablePackage (opts: CrackerOptions) (dllPath: string) =
| Some firstGroup -> elements firstGroup
| None -> dependencies

if Path.GetFileNameWithoutExtension(dllPath) |> isSystemPackage then
if Path.GetFileNameWithoutExtension(dllPath) |> Metadata.isSystemPackage then
None
else
let rootDir = IO.Path.Combine(IO.Path.GetDirectoryName(dllPath), "..", "..")
Expand Down Expand Up @@ -295,7 +287,7 @@ let tryGetFablePackage (opts: CrackerOptions) (dllPath: string) =
// We don't consider different frameworks
|> firstGroupOrAllDependencies
|> Seq.map (attr "id")
|> Seq.filter (isSystemPackage >> not)
|> Seq.filter (Metadata.isSystemPackage >> not)
|> Set
}
: FablePackage
Expand Down Expand Up @@ -847,8 +839,8 @@ let getFullProjectOpts (resolver: ProjectCrackerResolver) (opts: CrackerOptions)

if not (IO.File.Exists(paketReferences)) then
true
// Only check paket.lock for main project and assume it's the same for references
else if isOlderThanCache paketReferences then
// Only check paket.lock for main project and assume it's the same for references
if fsproj <> cacheInfo.ProjectPath then
true
else
Expand Down
11 changes: 11 additions & 0 deletions src/Fable.Transforms/Global/Metadata.fs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Fable.Metadata

open System

let coreAssemblies =
[|
"Fable.Core"
Expand Down Expand Up @@ -39,3 +41,12 @@ let coreAssemblies =
"System.Threading.Thread"
"System.ValueTuple"
|]

let isSystemPackage (pkgName: string) =
pkgName.StartsWith("System.", StringComparison.Ordinal)
|| pkgName.StartsWith("Microsoft.", StringComparison.Ordinal)
|| pkgName.StartsWith("runtime.", StringComparison.Ordinal)
|| pkgName = "NETStandard.Library"
|| pkgName = "FSharp.Core"
|| pkgName = "Fable.Core"
|| pkgName = "testhost"
33 changes: 18 additions & 15 deletions src/Fable.Transforms/State.fs
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,25 @@ type Assemblies(getPlugin, fsharpAssemblies: FSharpAssembly list, addLog: Severi
coreAssemblies.Add(asmName, asm)
else
let scanForPlugins =
try
asm.Contents.Attributes
|> Seq.exists (fun attr ->
attr.AttributeType.TryFullName = Some "Fable.ScanForPluginsAttribute"
)
with error ->
// To help identify problem, log information about the exception
// but keep the process going to mimic previous Fable behavior
// and because these exception seems harmless
let errorMessage =
$"Could not scan {path} for Fable plugins, skipping this assembly. Original error: {error.Message}"

addLog Severity.Info errorMessage

hasSkippedAssembly <- true
if Metadata.isSystemPackage asmName then
false
else
try
asm.Contents.Attributes
|> Seq.exists (fun attr ->
attr.AttributeType.TryFullName = Some "Fable.ScanForPluginsAttribute"
)
with error ->
// To help identify problem, log information about the exception
// but keep the process going to mimic previous Fable behavior
// and because these exception seems harmless
let errorMessage =
$"Could not scan {path} for Fable plugins, skipping this assembly. Original error: {error.Message}"

addLog Severity.Info errorMessage

hasSkippedAssembly <- true
false

if scanForPlugins then
for e in asm.Contents.Entities do
Expand Down

0 comments on commit 2f3f36e

Please sign in to comment.