-
-
Notifications
You must be signed in to change notification settings - Fork 144
feat: ESM resolver hardening, HTTP module loader, ns:module dev surface #1965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
NathanWalker
wants to merge
8
commits into
main
Choose a base branch
from
feat/hmr-dev-sessions
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+5,658
−1,559
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
20aa932
feat(runtime): ESM resolver hardening and async module-graph loader
NathanWalker 9bc1561
feat(runtime): HMR dev-sessions and a hardened HTTP session loader
NathanWalker 97ff014
feat(runtime): expose the dev-loader surface as the ns:module builtin
NathanWalker 2f5bd38
fix(worker): surface entry-script load errors and buffer early messages
NathanWalker 3205f49
test: cover the ESM loader, remote-module security, and worker behavior
NathanWalker 1c5e92b
refactor(runtime): drop the require() optional-module placeholder
NathanWalker a20f2bc
refactor(runtime): rename HMRSupport to HttpLoader and fold DevFlags …
NathanWalker 054748c
fix(runtime): harden HTTP fetch, extend names, and worker drain retries
NathanWalker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| describe("ns:module", function () { | ||
| it("should expose the dev-loader primitives via the ns:module builtin", function () { | ||
| var nsModule = require("ns:module"); | ||
| expect(Object.isFrozen(nsModule)).toBe(true); | ||
| expect(typeof nsModule.configureLoader).toBe("function"); | ||
| expect(typeof nsModule.invalidateModules).toBe("function"); | ||
| expect(typeof nsModule.getLoadedModuleUrls).toBe("function"); | ||
| expect(typeof nsModule.setDevBootComplete).toBe("function"); | ||
| expect(nsModule.terminateAllWorkers).toBeUndefined(); | ||
| expect(global.__NS_DEV__).toBeUndefined(); | ||
| }); | ||
|
|
||
| it("exposes exactly the declared surface", function () { | ||
| var nsModule = require("ns:module"); | ||
| var expected = ["configureLoader", "getLoadedModuleUrls", "invalidateModules", "setDevBootComplete"]; | ||
| if (typeof nsModule.canonicalizeHttpUrlKey === "function") { | ||
| expected.push("canonicalizeHttpUrlKey"); | ||
| } | ||
| expect(Object.keys(nsModule).sort()).toEqual(expected.sort()); | ||
| }); | ||
|
|
||
| it("resolves ns:module to the same members for require and import()", function (done) { | ||
| var nsModule = require("ns:module"); | ||
| import("ns:module").then(function (ns) { | ||
| expect(ns.default).toBe(nsModule); | ||
| expect(ns.invalidateModules).toBe(nsModule.invalidateModules); | ||
| expect(ns.configureLoader).toBe(nsModule.configureLoader); | ||
| done(); | ||
| }).catch(function (error) { | ||
| fail("import('ns:module') rejected: " + error.message); | ||
| done(); | ||
| }); | ||
| }); | ||
|
|
||
| it("setDevBootComplete flips the JS-visible boot-complete global", function () { | ||
| var nsModule = require("ns:module"); | ||
| nsModule.setDevBootComplete(true); | ||
| expect(global.__NS_HMR_BOOT_COMPLETE__).toBe(true); | ||
| nsModule.setDevBootComplete(false); | ||
| expect(global.__NS_HMR_BOOT_COMPLETE__).toBe(false); | ||
| nsModule.setDevBootComplete(); | ||
| expect(global.__NS_HMR_BOOT_COMPLETE__).toBe(true); | ||
| nsModule.setDevBootComplete(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe("HTTP canonical key (ns:module canonicalizeHttpUrlKey)", function () { | ||
| function getCanon() { | ||
| return require("ns:module").canonicalizeHttpUrlKey; | ||
| } | ||
|
|
||
| function checkKey(input, expected) { | ||
| var canon = getCanon(); | ||
| if (typeof canon !== "function") { | ||
| pending("ns:module.canonicalizeHttpUrlKey not exposed (release build)"); | ||
| return; | ||
| } | ||
| expect(canon(input)).toBe(expected); | ||
| } | ||
|
|
||
| it("is exposed as a function in debug builds", function () { | ||
| var canon = getCanon(); | ||
| if (typeof canon !== "function") { | ||
| pending("ns:module.canonicalizeHttpUrlKey not exposed (release build)"); | ||
| return; | ||
| } | ||
| expect(typeof canon).toBe("function"); | ||
| }); | ||
|
|
||
| it("drops dev cache-busters (t/v/import) but keeps real query params", function () { | ||
| checkKey("http://h/ns/core?p=x&t=123&v=9&import=1", "http://h/ns/core?p=x"); | ||
| }); | ||
|
|
||
| it("leaves public (non-dev, non-volatile) URLs untouched", function () { | ||
| checkKey("https://cdn.example.com/lib.js?token=abc", "https://cdn.example.com/lib.js?token=abc"); | ||
| }); | ||
|
|
||
| it("treats module identity as literally the URL — no path-tag collapses", function () { | ||
| checkKey("http://h/ns/m/foo.js", "http://h/ns/m/foo.js"); | ||
| checkKey("http://h/ns/rt", "http://h/ns/rt"); | ||
| checkKey("http://h/ns/core", "http://h/ns/core"); | ||
| }); | ||
|
|
||
| it("ignores URL fragments for dev endpoints", function () { | ||
| checkKey("http://h/ns/m/foo.js#frag", "http://h/ns/m/foo.js"); | ||
| }); | ||
|
|
||
| it("honors a client-supplied canonicalization vocabulary via configureLoader", function () { | ||
| var canon = getCanon(); | ||
| if (typeof canon !== "function") { | ||
| pending("ns:module.canonicalizeHttpUrlKey not exposed (release build)"); | ||
| return; | ||
| } | ||
| require("ns:module").configureLoader({ | ||
| canonicalization: { | ||
| stripParams: ["t", "v", "import"], | ||
| forPathPrefixes: ["/ns/", "/node_modules/.vite/", "/@id/", "/@fs/"], | ||
| preserveQueryFor: ["/@ng/component"], | ||
| }, | ||
| }); | ||
| expect(canon("http://h/ns/core?p=x&t=123&v=9&import=1")).toBe("http://h/ns/core?p=x"); | ||
| expect(canon("http://h/ns/m/comp/@ng/component?c=a&t=42")).toBe("http://h/ns/m/comp/@ng/component?c=a&t=42"); | ||
| expect(canon("https://cdn.example.com/lib.js?token=abc")).toBe("https://cdn.example.com/lib.js?token=abc"); | ||
| }); | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| describe("ns:runtime", function () { | ||
| var runtime = require("ns:runtime"); | ||
|
|
||
| it("exposes frozen exports", function () { | ||
| expect(Object.isFrozen(runtime)).toBe(true); | ||
| expect(typeof runtime.setConfig).toBe("function"); | ||
| expect(typeof runtime.getConfig).toBe("function"); | ||
| }); | ||
|
|
||
| it("exposes exactly the declared surface", function () { | ||
| expect(Object.keys(runtime).sort()).toEqual(["getConfig", "setConfig"]); | ||
| }); | ||
|
|
||
| it("rejects unknown keys", function () { | ||
| expect(function () { | ||
| runtime.setConfig("noSuchKey", 1); | ||
| }).toThrowError(TypeError, /Unknown runtime config key/); | ||
| expect(function () { | ||
| runtime.getConfig("noSuchKey"); | ||
| }).toThrowError(TypeError, /Unknown runtime config key/); | ||
| }); | ||
|
|
||
| it("defaults logScriptLoading and httpFetchUrlLog from app config", function () { | ||
| expect(runtime.getConfig("logScriptLoading")).toBe(false); | ||
| expect(runtime.getConfig("httpFetchUrlLog")).toBe(false); | ||
| }); | ||
|
|
||
| it("round-trips logScriptLoading and httpFetchUrlLog", function () { | ||
| runtime.setConfig("logScriptLoading", true); | ||
| expect(runtime.getConfig("logScriptLoading")).toBe(true); | ||
| runtime.setConfig("logScriptLoading", false); | ||
| expect(runtime.getConfig("logScriptLoading")).toBe(false); | ||
|
|
||
| runtime.setConfig("httpFetchUrlLog", true); | ||
| expect(runtime.getConfig("httpFetchUrlLog")).toBe(true); | ||
| runtime.setConfig("httpFetchUrlLog", false); | ||
| expect(runtime.getConfig("httpFetchUrlLog")).toBe(false); | ||
| }); | ||
|
|
||
| it("rejects non-boolean log flag values and keeps the current one", function () { | ||
| expect(function () { | ||
| runtime.setConfig("logScriptLoading", "yes"); | ||
| }).toThrowError(TypeError, /must be a boolean/); | ||
| expect(runtime.getConfig("logScriptLoading")).toBe(false); | ||
| expect(function () { | ||
| runtime.setConfig("httpFetchUrlLog", 1); | ||
| }).toThrowError(TypeError, /must be a boolean/); | ||
| expect(runtime.getConfig("httpFetchUrlLog")).toBe(false); | ||
| }); | ||
|
|
||
| it("does not expose remote-module security through getConfig or setConfig", function () { | ||
| ["security", "allowRemoteModules", "remoteModuleAllowlist"].forEach(function (key) { | ||
| expect(function () { | ||
| runtime.getConfig(key); | ||
| }).toThrowError(TypeError, /Unknown runtime config key/); | ||
| expect(function () { | ||
| runtime.setConfig(key, true); | ||
| }).toThrowError(TypeError, /Unknown runtime config key/); | ||
| }); | ||
| }); | ||
|
|
||
| it("does not expose releasedObjectPolicy (iOS-only)", function () { | ||
| expect(function () { | ||
| runtime.getConfig("releasedObjectPolicy"); | ||
| }).toThrowError(TypeError, /Unknown runtime config key/); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.