You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR simplifies code from #141 (native PolicyPlugin exports) to improve clarity and reduce duplication while preserving all functionality.
Files Simplified
packages/core/src/services/policy.ts — extracted resolveNativePlugin() helper to deduplicate repeated validate+normalize pattern
packages/core/src/services/policy/loader.ts — removed redundant meta spread (normalization already done by loadPolicy)
packages/core/src/services/readiness/index.ts — replaced options parameter reassignment with a local shadow boolean
Improvements Made
Reduced Duplication
The validateNativePlugin(config, source); return normalizeNativePlugin(config) pair appeared identically twice in loadPolicy (local file path branch and npm package branch). Extracted into a private resolveNativePlugin() helper.
Removed Redundant Code
In loadPluginChain, native plugins returned by loadPolicy were being spread again with sourceType: "module" and trust: "trusted-code" — but loadPolicy already unconditionally sets these via normalizeNativePlugin. The redundant spread is removed; plugins.push(loaded) is sufficient.
Cleaner State Management
runReadinessReport was reassigning the options function parameter (options = { ...options, shadow: true }) to avoid mutating the caller's object. Replaced with a local shadow boolean initialized from options.shadow ?? false and set to true when native plugins are encountered — same semantics, no parameter mutation.
This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch simplify/policy-native-plugin-2026-05-11-3344a8cef306257f.
To fix the permissions issue, go to Settings → Actions → General and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ
Show patch preview (138 of 138 lines)
From 43a857e987f3abe77a605988b098a6bcfb355f34 Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Mon, 11 May 2026 11:52:38 +0000
Subject: [PATCH] refactor(policy): simplify native plugin handling after PR
#141
- Extract resolveNativePlugin() helper in policy.ts to deduplicate
the repeated validateNativePlugin + normalizeNativePlugin call pair
- Remove redundant meta spread in loadPluginChain (loadPolicy already
normalizes sourceType/trust via normalizeNativePlugin before returning)
- Replace options parameter reassignment in runReadinessReport with a
local shadow boolean variable for clearer intent
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
packages/core/src/services/policy.ts | 17 +++++++++++------
packages/core/src/services/policy/loader.ts | 14 +++-----------
packages/core/src/services/readiness/index.ts | 13 ++++---------
3 files changed, 18 insertions(+), 26 deletions(-)
diff --git a/packages/core/src/services/policy.ts b/packages/core/src/services/policy.ts
index 3a299e2..d276eb2 100644
--- a/packages/core/src/services/policy.ts+++ b/packages/core/src/services/policy.ts@@ -178,6 +178,15 @@ function normalizeNativePlugin(plugin: PolicyPlugin): PolicyPlugin {
};
}
+/**+ * Validate and normalize a module export that passed the isNativePlugin check.+ * Throws if the plugin is structurally invalid; otherwise returns normalized form.+ */+function resolveNativePlugin(config: PolicyPlugin, source: string): PolicyPlugin {+ validateNativePlugin(config, source);+ return normalizeNativePlugin(config);+}+
/**
* Load a policy from a file path or npm specifier.
*
@@ -219,11 +228,8 @@ export async function loadPolicy(
// import() treats as a URL scheme (c:), causing ERR_UNSUPPORTED_ESM_URL_SCHEME.
const mod = (await import(pathToFileURL(resolved).href)) as Record<string, unknown>;
const config = (mod.default ?? mod) as
... (truncated)
Code Simplification - 2026-05-11
This PR simplifies code from #141 (native
PolicyPluginexports) to improve clarity and reduce duplication while preserving all functionality.Files Simplified
packages/core/src/services/policy.ts— extractedresolveNativePlugin()helper to deduplicate repeated validate+normalize patternpackages/core/src/services/policy/loader.ts— removed redundant meta spread (normalization already done byloadPolicy)packages/core/src/services/readiness/index.ts— replacedoptionsparameter reassignment with a localshadowbooleanImprovements Made
Reduced Duplication
validateNativePlugin(config, source); return normalizeNativePlugin(config)pair appeared identically twice inloadPolicy(local file path branch and npm package branch). Extracted into a privateresolveNativePlugin()helper.Removed Redundant Code
loadPluginChain, native plugins returned byloadPolicywere being spread again withsourceType: "module"andtrust: "trusted-code"— butloadPolicyalready unconditionally sets these vianormalizeNativePlugin. The redundant spread is removed;plugins.push(loaded)is sufficient.Cleaner State Management
runReadinessReportwas reassigning theoptionsfunction parameter (options = { ...options, shadow: true }) to avoid mutating the caller's object. Replaced with a localshadowboolean initialized fromoptions.shadow ?? falseand set totruewhen native plugins are encountered — same semantics, no parameter mutation.Changes Based On
Recent changes from:
Testing
Note
This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch
simplify/policy-native-plugin-2026-05-11-3344a8cef306257f.Click here to create the pull request
To fix the permissions issue, go to Settings → Actions → General and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ
Show patch preview (138 of 138 lines)