Skip to content

Instantly share code, notes, and snippets.

@thepassle
Created March 2, 2024 11:14
Show Gist options
  • Save thepassle/6333707c003ef8c91cc0b35cec08a2ad to your computer and use it in GitHub Desktop.
Save thepassle/6333707c003ef8c91cc0b35cec08a2ad to your computer and use it in GitHub Desktop.
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