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(ssr): no external symlink package #9296

Merged
merged 4 commits into from Jul 22, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/vite/src/node/plugins/resolve.ts
Expand Up @@ -656,6 +656,10 @@ export function tryNodeResolve(
if (!externalize) {
return resolved
}
// dont external symlink packages
if (!resolved.id.includes('node_modules')) {
return
}
const resolvedExt = path.extname(resolved.id)
let resolvedId = id
if (isDeepImport) {
Expand Down
5 changes: 5 additions & 0 deletions playground/ssr-deps/__tests__/ssr-deps.spec.ts
Expand Up @@ -98,3 +98,8 @@ test('msg from external using external entry', async () => {
'Hello World!'
)
})

test('msg from linked no external', async () => {
await page.goto(url)
expect(await page.textContent('.linked-no-external')).toMatch('Hello World!')
})
5 changes: 5 additions & 0 deletions playground/ssr-deps/linked-no-external/index.js
@@ -0,0 +1,5 @@
export const hello = function () {
// make sure linked package is not externalized so Vite features like
// import.meta.env works (or handling TS files)
return import.meta.env.DEV && 'Hello World!'
}
6 changes: 6 additions & 0 deletions playground/ssr-deps/linked-no-external/package.json
@@ -0,0 +1,6 @@
{
"name": "linked-no-external",
"private": true,
"type": "module",
"version": "0.0.0"
}
3 changes: 2 additions & 1 deletion playground/ssr-deps/package.json
Expand Up @@ -26,7 +26,8 @@
"optimized-with-nested-external": "file:./optimized-with-nested-external",
"optimized-cjs-with-nested-external": "file:./optimized-with-nested-external",
"external-using-external-entry": "file:./external-using-external-entry",
"external-entry": "file:./external-entry"
"external-entry": "file:./external-entry",
"linked-no-external": "link:./linked-no-external"
},
"devDependencies": {
"cross-env": "^7.0.3",
Expand Down
4 changes: 4 additions & 0 deletions playground/ssr-deps/src/app.js
Expand Up @@ -11,6 +11,7 @@ import onlyObjectAssignedExports from 'only-object-assigned-exports'
import requireAbsolute from 'require-absolute'
import noExternalCjs from 'no-external-cjs'
import importBuiltinCjs from 'import-builtin-cjs'
import { hello as linkedNoExternal } from 'linked-no-external'

// This import will set a 'Hello World!" message in the nested-external non-entry dependency
import 'non-optimized-with-nested-external'
Expand Down Expand Up @@ -75,5 +76,8 @@ export async function render(url, rootDir) {
const externalUsingExternalEntryMessage = externalUsingExternalEntry.hello()
html += `\n<p class="external-using-external-entry">message from external-using-external-entry: ${externalUsingExternalEntryMessage}</p>`

const linkedNoExternalMessage = linkedNoExternal()
html += `\n<p class="linked-no-external">message from linked-no-external: ${linkedNoExternalMessage}</p>`

return html + '\n'
}
5 changes: 5 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.