Skip to content
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

Fix casing of module locations to match that used by Rollup. #999

Merged
merged 3 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions snowpack/src/commands/install.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ function resolveWebDependency(dep: string): DependencyLoc {
const isJSFile = ['.js', '.mjs', '.cjs'].includes(path.extname(dep));
return {
type: isJSFile ? 'JS' : 'ASSET',
loc: require.resolve(dep, {paths: [cwd]}),
// For details on why we need to call fs.realpathSync.native here and other places, see
// https://github.com/pikapkg/snowpack/pull/999.
loc: fs.realpathSync.native(require.resolve(dep, {paths: [cwd]})),
pkaminski marked this conversation as resolved.
Show resolved Hide resolved
};
}
// If dep is a path within a package (but without an extension), we first need
Expand Down Expand Up @@ -128,7 +130,7 @@ function resolveWebDependency(dep: string): DependencyLoc {
const [depManifestLoc, depManifest] = resolveDependencyManifest(dep, cwd);
if (!depManifest) {
try {
const maybeLoc = require.resolve(dep, {paths: [cwd]});
const maybeLoc = fs.realpathSync.native(require.resolve(dep, {paths: [cwd]}));
return {
type: 'JS',
loc: maybeLoc,
Expand Down Expand Up @@ -182,7 +184,7 @@ function resolveWebDependency(dep: string): DependencyLoc {
try {
return {
type: 'JS',
loc: require.resolve(path.join(depManifestLoc || '', '..', foundEntrypoint)),
loc: fs.realpathSync.native(require.resolve(path.join(depManifestLoc || '', '..', foundEntrypoint))),
};
} catch (err) {
// Type only packages! Some packages are purely for TypeScript (ex: csstypes).
Expand Down
4 changes: 2 additions & 2 deletions snowpack/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function resolveDependencyManifest(dep: string, cwd: string): [string | n
// include a package.json. If we detect that to be the reason for failure,
// move on to our custom implementation.
try {
const depManifest = require.resolve(`${dep}/package.json`, {paths: [cwd]});
const depManifest = fs.realpathSync.native(require.resolve(`${dep}/package.json`, {paths: [cwd]}));
return [depManifest, require(depManifest)];
} catch (err) {
// if its an export map issue, move on to our manual resolver.
Expand All @@ -122,7 +122,7 @@ export function resolveDependencyManifest(dep: string, cwd: string): [string | n
// established & move out of experimental mode.
let result = [null, null] as [string | null, any | null];
try {
const fullPath = require.resolve(dep, {paths: [cwd]});
const fullPath = fs.realpathSync.native(require.resolve(dep, {paths: [cwd]}));
// Strip everything after the package name to get the package root path
// NOTE: This find-replace is very gross, replace with something like upath.
const searchPath = `${path.sep}node_modules${path.sep}${dep.replace('/', path.sep)}`;
Expand Down
Loading