Add ESM support for @azure/functions-core virtual module#791
Open
TsuyoshiUshio wants to merge 1 commit intov3.xfrom
Open
Add ESM support for @azure/functions-core virtual module#791TsuyoshiUshio wants to merge 1 commit intov3.xfrom
TsuyoshiUshio wants to merge 1 commit intov3.xfrom
Conversation
Register Node.js ESM loader hooks via module.register so that ESM code can use import from @azure/functions-core at runtime. The existing CJS require Proxy is unchanged. - Expose coreApi on globalThis via Symbol.for azure-functions-core - Add esm-core-loader.mjs with resolve/load hooks for the virtual module - Add esmCoreLoaderHooks.ts for testable TypeScript version of the hooks - Feature-gate module.register call for Node.js 20.6 and above only - Add 8 unit tests covering CJS interception, globalThis exposure, and ESM loader hook resolve/load behavior - Add design document in docs/design-esm-core-module.md Resolves #104 Co-authored-by: Dobby <dobby@microsoft.com>
Author
|
Created PR first, however, we need to discuss the order of the merging. :) |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add ESM support for
@azure/functions-corevirtual moduleResolves #104
Summary
The
@azure/functions-corevirtual module is currently only accessible via CJSrequire()through aModule.prototype.requireProxy. This PR adds ESMimportsupport using Node.js loader hooks (module.register()), enabling ESM-based code to useimport { ... } from '@azure/functions-core'at runtime.This is Step 1 of the full-stack ESM support plan for the Azure Functions Node.js ecosystem.
Changes
src/setupCoreModule.ts(modified)coreApionglobalThisviaSymbol.for('azure-functions-core')so the ESM loader can access itmodule.register()(feature-gated for Node.js >= 20.6)require()Proxy is unchanged -- zero risk to CJS consumerssrc/esm-core-loader.mjs(new)module.register()resolve(): Maps@azure/functions-coreto a virtual URLload(): Returns synthetic ESM source that re-exports properties from theglobalThiscoreApi objectsrc/esmCoreLoaderHooks.ts(new)esm-core-loader.mjsbut importable by Mocha/ts-nodewebpack.config.js(modified).mjshandling rule so the ESM loader file is not broken by webpacktest/setupCoreModule.test.ts(new)globalThisSymbol exposure (1 test)docs/design-esm-core-module.md(new)How it works
Node.js version compatibility
module.register()Testing
Related issues