Created
March 2, 2024 11:14
-
-
Save thepassle/6333707c003ef8c91cc0b35cec08a2ad to your computer and use it in GitHub Desktop.
This file contains 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
import { pathToFileURL } from 'url'; | |
import { createModuleGraph } from '@thepassle/module-graph'; | |
import { nodeResolve } from '@rollup/plugin-node-resolve'; | |
function createResolve(resolveOptions = {}) { | |
const r = nodeResolve(resolveOptions); | |
return { | |
resolve() { | |
return null; | |
}, | |
handler(importee, importer) { | |
const boundResolve = r.resolveId.handler.bind(this); | |
return boundResolve(importee, importer, {}) | |
} | |
} | |
} | |
const r = createResolve(); | |
function resolvePlugin(resolveOptions) { | |
const r = createResolve(resolveOptions); | |
return { | |
name: 'resolve', | |
async resolve({importee, importer, conditions, preserveSymlinks}) { | |
const resolved = await r.handler(importee, importer.pathname); | |
return pathToFileURL(resolved.id); | |
} | |
} | |
} | |
const graph = await createModuleGraph('./ing-feat-flexible-page.js', { | |
plugins: [ | |
resolvePlugin() | |
] | |
}); | |
console.log(graph.get('node_modules/@popperjs/core/dist/esm/dom-utils/getClippingRect.js')); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment