turbo
102d4ea5 - feat(turbopack-ecmascript): calculate import.meta.url as an absolute path (#6318)

Commit
2 years ago
feat(turbopack-ecmascript): calculate import.meta.url as an absolute path (#6318) ### Description This PR attempts to support `import.meta.url` to resolve as an actual absolute path. Currently, it resolves to a relative path with `/ROOT/` placeholder. In contrast to typical path resolution logics in turbopack, we are required to supply a genuine absolute path for the assets. Node.js can consider a stagnant value as constant and refer to it in any way. To support those, this PR performs below steps: - When we create turbopack_runtime, calculate absolute path of the `project` via node.js's `__filename` and the `OUTPUT_ROOT` (which is a distDir) - create a fn `resolveAbsolutePath` can compute an absolute path to a given module path in runtime - inject `resolveAbsolutePath` into each module chunks - convert `import.meta.url` as getter, which can be lazily evaluated when it's being called - so we can access runtime-injected fn to actually calculate paths. PR allows to pass one of import.meta.url based test cases (in dynamic metadata). Once this is approved & landed, would apply same approach for the __dirname and trying to verify against remaining test cases.
Author
Parents
Loading