-
Notifications
You must be signed in to change notification settings - Fork 107
[WIP]feat(pack): library runtime code compitable with Array #2467
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
base: next
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -42,8 +42,7 @@ type RuntimeParams = { | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| type ChunkRegistration = [ | ||||||||||||||||||||||||
| chunkPath: ChunkScript, | ||||||||||||||||||||||||
| chunkModules: CompressedModuleFactories, | ||||||||||||||||||||||||
| params: RuntimeParams | undefined, | ||||||||||||||||||||||||
| ...(CompressedModuleFactories | [RuntimeParams]), | ||||||||||||||||||||||||
| ]; | ||||||||||||||||||||||||
|
Comment on lines
43
to
46
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type definition for
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| type ChunkList = { | ||||||||||||||||||||||||
|
|
@@ -85,18 +84,18 @@ interface RuntimeBackend { | |||||||||||||||||||||||
| ) => Promise<void>; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const moduleFactories: ModuleFactories = Object.create(null); | ||||||||||||||||||||||||
| const moduleFactories: ModuleFactories = new Map(); | ||||||||||||||||||||||||
| contextPrototype.M = moduleFactories; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const availableModules: Map<ModuleId, Promise<any> | true> = new Map(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const availableModuleChunks: Map<ChunkPath, Promise<any> | true> = new Map(); | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| function factoryNotAvailable( | ||||||||||||||||||||||||
| function factoryNotAvailableMessage( | ||||||||||||||||||||||||
| moduleId: ModuleId, | ||||||||||||||||||||||||
| sourceType: SourceType, | ||||||||||||||||||||||||
| sourceData: SourceData, | ||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||
| ): string { | ||||||||||||||||||||||||
| let instantiationReason; | ||||||||||||||||||||||||
| switch (sourceType) { | ||||||||||||||||||||||||
| case SourceType.Runtime: | ||||||||||||||||||||||||
|
|
@@ -114,9 +113,7 @@ function factoryNotAvailable( | |||||||||||||||||||||||
| (sourceType) => `Unknown source type: ${sourceType}`, | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| throw new Error( | ||||||||||||||||||||||||
| `Module ${moduleId} was instantiated ${instantiationReason}, but the module factory is not available. It might have been deleted in an HMR update.`, | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| return `Module ${moduleId} was instantiated ${instantiationReason}, but the module factory is not available.`; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const loadedChunk = Promise.resolve(undefined); | ||||||||||||||||||||||||
|
|
@@ -259,23 +256,6 @@ function getPathFromScript( | |||||||||||||||||||||||
| return path as ChunkPath | ChunkListPath; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| function registerCompressedModuleFactory( | ||||||||||||||||||||||||
| moduleId: ModuleId, | ||||||||||||||||||||||||
| moduleFactory: Function | [Function, ModuleId[]], | ||||||||||||||||||||||||
| ) { | ||||||||||||||||||||||||
| if (!moduleFactories[moduleId]) { | ||||||||||||||||||||||||
| if (Array.isArray(moduleFactory)) { | ||||||||||||||||||||||||
| let [moduleFactoryFn, otherIds] = moduleFactory; | ||||||||||||||||||||||||
| moduleFactories[moduleId] = moduleFactoryFn; | ||||||||||||||||||||||||
| for (const otherModuleId of otherIds) { | ||||||||||||||||||||||||
| moduleFactories[otherModuleId] = moduleFactoryFn; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||
| moduleFactories[moduleId] = moduleFactory; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| const regexJsUrl = /\.js(?:\?[^#]*)?(?:#.*)?$/; | ||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * Checks if a given path/URL ends with .js, optionally followed by ?query or #fragment. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The logic in
registerChunkis flawed. Whenregistration.length === 3, it correctly extractsruntimeParamsbut fails to processregistration[1], which contains the module factories. This will prevent any modules from being registered for chunks that have runtime parameters.