Skip to content

Commit

Permalink
fix: ssrExternal should not skip nested dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
benmccann committed Mar 2, 2022
1 parent 941f139 commit 05b97af
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 86 deletions.
89 changes: 3 additions & 86 deletions packages/vite/LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -237,89 +237,6 @@ Repository: git+https://github.com/ampproject/remapping.git
---------------------------------------

## @jridgewell/resolve-uri
License: MIT
By: Justin Ridgewell
Repository: https://github.com/jridgewell/resolve-uri

> Copyright 2019 Justin Ridgewell <jridgewell@google.com>
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.
---------------------------------------

## @jridgewell/sourcemap-codec
License: MIT
By: Rich Harris
Repository: git+https://github.com/jridgewell/sourcemap-codec.git

> The MIT License
>
> Copyright (c) 2015 Rich Harris
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
> THE SOFTWARE.
---------------------------------------

## @jridgewell/trace-mapping
License: MIT
By: Justin Ridgewell
Repository: git+https://github.com/jridgewell/trace-mapping.git

> Copyright 2022 Justin Ridgewell <justin@ridgewell.name>
>
> Permission is hereby granted, free of charge, to any person obtaining a copy
> of this software and associated documentation files (the "Software"), to deal
> in the Software without restriction, including without limitation the rights
> to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
> copies of the Software, and to permit persons to whom the Software is
> furnished to do so, subject to the following conditions:
>
> The above copyright notice and this permission notice shall be included in
> all copies or substantial portions of the Software.
>
> THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
> AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
> OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> SOFTWARE.
---------------------------------------

## @nodelib/fs.scandir
License: MIT
Repository: https://github.com/nodelib/nodelib/tree/master/packages/fs/fs.scandir
Expand Down Expand Up @@ -486,7 +403,7 @@ Repository: rollup/plugins
## @vue/compiler-core
License: MIT
By: Evan You
Repository: git+https://github.com/vuejs/core.git
Repository: git+https://github.com/vuejs/vue-next.git

> The MIT License (MIT)
>
Expand Down Expand Up @@ -515,7 +432,7 @@ Repository: git+https://github.com/vuejs/core.git
## @vue/compiler-dom
License: MIT
By: Evan You
Repository: git+https://github.com/vuejs/core.git
Repository: git+https://github.com/vuejs/vue-next.git

> The MIT License (MIT)
>
Expand Down Expand Up @@ -544,7 +461,7 @@ Repository: git+https://github.com/vuejs/core.git
## @vue/shared
License: MIT
By: Evan You
Repository: git+https://github.com/vuejs/core.git
Repository: git+https://github.com/vuejs/vue-next.git

> The MIT License (MIT)
>
Expand Down
5 changes: 5 additions & 0 deletions packages/vite/src/node/ssr/__tests__/ssrExternal.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { stripNesting } from '../ssrExternal'

test('stripNesting', async () => {
expect(stripNesting(['c', 'p1>c1', 'p2 > c2'])).toEqual(['c', 'c1', 'c2'])
})
14 changes: 14 additions & 0 deletions packages/vite/src/node/ssr/ssrExternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ import { createFilter } from '@rollup/pluginutils'

const debug = createDebugger('vite:ssr-external')

/**
* Converts "parent > child" syntax to just "child"
*/
export function stripNesting(packages: string[]) {
return packages.map((s) => {
const arr = s.split('>')
return arr[arr.length - 1].trim()
})
}

/**
* Heuristics for determining whether a dependency should be externalized for
* server-side rendering.
Expand All @@ -22,6 +32,10 @@ export function resolveSSRExternal(
config: ResolvedConfig,
knownImports: string[]
): string[] {
// strip nesting since knownImports may be passed in from optimizeDeps which
// supports a "parent > child" syntax
knownImports = stripNesting(knownImports)

const ssrConfig = config.ssr
if (ssrConfig?.noExternal === true) {
return []
Expand Down

0 comments on commit 05b97af

Please sign in to comment.