From 05b97afc1bc6bcdfff495b32e60608def2f65c44 Mon Sep 17 00:00:00 2001 From: Ben McCann <322311+benmccann@users.noreply.github.com> Date: Wed, 2 Mar 2022 09:15:11 -0800 Subject: [PATCH] fix: ssrExternal should not skip nested dependencies --- packages/vite/LICENSE.md | 89 +------------------ .../node/ssr/__tests__/ssrExternal.spec.ts | 5 ++ packages/vite/src/node/ssr/ssrExternal.ts | 14 +++ 3 files changed, 22 insertions(+), 86 deletions(-) create mode 100644 packages/vite/src/node/ssr/__tests__/ssrExternal.spec.ts diff --git a/packages/vite/LICENSE.md b/packages/vite/LICENSE.md index 8b4d641a09f199..a4169a00039134 100644 --- a/packages/vite/LICENSE.md +++ b/packages/vite/LICENSE.md @@ -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 -> -> 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 -> -> 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 @@ -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) > @@ -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) > @@ -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) > diff --git a/packages/vite/src/node/ssr/__tests__/ssrExternal.spec.ts b/packages/vite/src/node/ssr/__tests__/ssrExternal.spec.ts new file mode 100644 index 00000000000000..ad16534b088e2b --- /dev/null +++ b/packages/vite/src/node/ssr/__tests__/ssrExternal.spec.ts @@ -0,0 +1,5 @@ +import { stripNesting } from '../ssrExternal' + +test('stripNesting', async () => { + expect(stripNesting(['c', 'p1>c1', 'p2 > c2'])).toEqual(['c', 'c1', 'c2']) +}) diff --git a/packages/vite/src/node/ssr/ssrExternal.ts b/packages/vite/src/node/ssr/ssrExternal.ts index 0e2eade85c21f1..800a2307dabae6 100644 --- a/packages/vite/src/node/ssr/ssrExternal.ts +++ b/packages/vite/src/node/ssr/ssrExternal.ts @@ -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. @@ -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 []