02:13
<Jack Works>
write a webpack plugin to support import(spec, { reflect: true }), it returns a VirtualModuleSource (since there is no native ModuleSource available
02:14
<Jack Works>
but with slightly different semantics, it will call esbuild to bundle all transitive dependencies of ./danger.js, which is different than our proposal proposed.
02:25
<Jack Works>
I think we need to consider this case in the module reflection proposal:
02:26
<Jack Works>
when using a library, it might contains many dependencies, but if we're reflecting them one-by-one and use importHook to provide all those files, it will be annoying to adopt, also with worse performance
02:28
<Jack Works>
e.g. lodash-es has 1000+ esm files, it is unrealistic to import them all as Reflected Module and provide them in importHook, because you need to enumerate all files under that package.
02:29
<Jack Works>
maybe we can change how import reflection works to make this case more convenient (and easier to be implemented in a bundler)
02:39
<Jack Works>

proposed change:

the import reflection "bundles"/"includes" all transitive dependencies by default, but takes an exclude list for Virtualization.

e.g.

danger/index.js

import * as fs from 'node:fs'
import { get } from 'lodash-es'
import { helper } from './utils.js'

When we reflect this module, await import('danger/index.js', { reflect: true }), and feed it to a Module constructor, it will call importHook to acquire node:fs, lodash-es and ./utils.js

This is not coinvent if we have many dependencies to virtualize

02:42
<Jack Works>

Proposed behavior:

it will fetch lodash-es and utils.js in it's Module cache except node:fs (because it is a privilege/native module with no (?) source code)

now it will only call importHook for node:fs to fetch I/O ability

02:47
<Jack Works>
with a new option to "exclude" some module from the module tree
02:48
<Jack Works>
e.g. await import('./lib.js', { reflect: true, excludes: ["react"] }). This allows something like "peer dependency"
02:48
<Jack Works>
The problem of this new proposed way is we need to introduce referrer back again