Skip to content

Commit

Permalink
Fix casing of module locations to match that used by Rollup. (#999)
Browse files Browse the repository at this point in the history
* Fix casing of module locations to match that used by Rollup.

* Add test for case sensitivity of install entrypoints.

* Add comment pointing to PR.
  • Loading branch information
pkaminski authored Sep 11, 2020
1 parent eaba0f3 commit 936b524
Show file tree
Hide file tree
Showing 7 changed files with 1,519 additions and 22 deletions.
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]})),
};
}
// 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 @@ -109,7 +109,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 @@ -125,7 +125,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

0 comments on commit 936b524

Please sign in to comment.