-
Notifications
You must be signed in to change notification settings - Fork 915
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
Esinstall: Allow resolution of inner package files #1689
Conversation
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/pikapkg/snowpack/ogu613izn |
388acff
to
939a058
Compare
@@ -302,7 +303,8 @@ export async function install( | |||
const aliasEntry = findMatchingAliasEntry(installAlias, specifier); | |||
return aliasEntry && aliasEntry.type === 'package' ? aliasEntry.to : specifier; | |||
}) | |||
.sort(), | |||
.map((specifier) => specifier.replace(/(\/|\\)+$/, '')) // remove trailing slash from end of specifier (easier for Node to resolve) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes a small but important problem: when using import maps, a .
will resolve to preact/
when using path.join()
. This makes esinstall generate preact/.js
rather than preact.js
.
Here, if a slash is the very last character(s), we simply remove it. Shouldn’t affect Node generation, and it seems to produce more consistently-named files on esinstall’s end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
939a058
to
ec351b4
Compare
ec351b4
to
e80871d
Compare
const ext = path.basename(resolvedResult.loc).replace(/[^.]+/, ''); | ||
targetName += ext; | ||
proxiedName += ext; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fixes another bug where for non-JS assets, the extension was often stripped (e.g. when installing bulma
, esinstall would create an extensionless web_modules/bulma
file that was supposed to be web_modules/bulma.sass
.
While this probably isn’t a perfect solution, I think it’s better, as it more closely matches the JS behavior. Also of note: we don’t add extensions if there aren’t any.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the thinking here makes sense, but resolvedResult.loc
should already be a fully resolved file location. If we want to fix/handle this, the fix should live inside of resolveWebDependency()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So resolvedResult.loc
is correct, and there‘s nothing to change there. That‘s why we correctly get the extension from there.
I was just making a change here where getWebDependencyName()
and sanitizePackageName()
were producing bad extensions for targetName
and proxiedName
for assets. Because we were adding asset handling here, I felt it safer to make the change here than in those 2 functions. But happy for you to make the call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
got it, makes sense!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
woo! 🎉 left a couple comments
@@ -302,7 +303,8 @@ export async function install( | |||
const aliasEntry = findMatchingAliasEntry(installAlias, specifier); | |||
return aliasEntry && aliasEntry.type === 'package' ? aliasEntry.to : specifier; | |||
}) | |||
.sort(), | |||
.map((specifier) => specifier.replace(/(\/|\\)+$/, '')) // remove trailing slash from end of specifier (easier for Node to resolve) | |||
.sort((a, b) => a.localeCompare(b, undefined, {numeric: true})), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious, why is this needed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I default to localeCompare()
more out of habit these days (it‘s recommended to do in browsers; probably doesn‘t make a difference in Node). But mainly I thought it‘d be a nice QoL improvement here to add {numeric: true}
.
Whereas before it would sort file1.js, file10.js, file2.js
, now it will sort file1.js, file2.js, file10.js
.
@@ -302,7 +303,8 @@ export async function install( | |||
const aliasEntry = findMatchingAliasEntry(installAlias, specifier); | |||
return aliasEntry && aliasEntry.type === 'package' ? aliasEntry.to : specifier; | |||
}) | |||
.sort(), | |||
.map((specifier) => specifier.replace(/(\/|\\)+$/, '')) // remove trailing slash from end of specifier (easier for Node to resolve) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice!
const ext = path.basename(resolvedResult.loc).replace(/[^.]+/, ''); | ||
targetName += ext; | ||
proxiedName += ext; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the thinking here makes sense, but resolvedResult.loc
should already be a fully resolved file location. If we want to fix/handle this, the fix should live inside of resolveWebDependency()
7563e2a
to
f44cb30
Compare
f44cb30
to
3c216cf
Compare
@@ -6,6 +6,7 @@ const PROCESS_MODULE_NAME = 'process'; | |||
export function rollupPluginNodeProcessPolyfill(env = {}): Plugin { | |||
const injectPlugin = inject({ | |||
process: PROCESS_MODULE_NAME, | |||
include: ['*.js', '*.mjs', '*.cjs'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is needed for Rollup to not blow up for non-JS assets.
Snapshots seem to be failing due to minification differences; don‘t seem to be related to this PR at all. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Changes
Before
After
Testing
Tested in local build setup. Tested against:
Docs