From 7c3aca50774058ffc27cbb81dc73e32c03154d01 Mon Sep 17 00:00:00 2001 From: Bogdan Chadkin Date: Wed, 29 Dec 2021 18:52:22 +0300 Subject: [PATCH] fix: replace source-map with source-map-js source-map-js is a js fork with applied optimisations comparable with rust optimisation in latest source-map versions. Staying on js allows us to bundle package and not increase install size. As a bonus I added support for importing from lib directly so we could avoid bundling whole package. See https://github.com/7rulnik/source-map-js/pull/13 ``` du -ck dist/node ``` before: 4164 kB after: 4140 kB --- packages/vite/LICENSE.md | 57 +------------------ packages/vite/package.json | 2 +- .../vite/src/node/server/pluginContainer.ts | 2 +- packages/vite/src/node/ssr/ssrStacktrace.ts | 6 +- pnpm-lock.yaml | 26 +++------ 5 files changed, 16 insertions(+), 77 deletions(-) diff --git a/packages/vite/LICENSE.md b/packages/vite/LICENSE.md index db47d365b4ad22..a4169a00039134 100644 --- a/packages/vite/LICENSE.md +++ b/packages/vite/LICENSE.md @@ -1685,40 +1685,6 @@ Repository: git+https://github.com/css-modules/icss-utils.git --------------------------------------- -## import-cwd -License: MIT -By: Sindre Sorhus -Repository: sindresorhus/import-cwd - -> MIT License -> -> Copyright (c) Sindre Sorhus (sindresorhus.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. - ---------------------------------------- - -## import-from -License: MIT -By: Sindre Sorhus -Repository: sindresorhus/import-from - -> MIT License -> -> Copyright (c) Sindre Sorhus (sindresorhus.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. - ---------------------------------------- - ## inflight License: ISC By: Isaac Z. Schlueter @@ -3338,23 +3304,6 @@ Repository: https://github.com/unshiftio/requires-port --------------------------------------- -## resolve-from -License: MIT -By: Sindre Sorhus -Repository: sindresorhus/resolve-from - -> MIT License -> -> Copyright (c) Sindre Sorhus (sindresorhus.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. - ---------------------------------------- - ## resolve.exports License: MIT By: Luke Edwards @@ -3543,10 +3492,10 @@ Repository: lukeed/sirv --------------------------------------- -## source-map +## source-map-js License: BSD-3-Clause -By: Nick Fitzgerald, Tobias Koppers, Duncan Beevers, Stephen Crane, Ryan Seddon, Miles Elam, Mihai Bazon, Michael Ficarra, Todd Wolfson, Alexander Solovyov, Felix Gnass, Conrad Irwin, usrbincc, David Glasser, Chase Douglas, Evan Wallace, Heather Arthur, Hugh Kennedy, Simon Lydell, Jmeas Smith, Michael Z Goddard, azu, John Gozde, Adam Kirkton, Chris Montgomery, J. Ryan Stinnett, Jack Herrington, Chris Truter, Daniel Espeset, Jamie Wong, Eddy Bruël, Hawken Rives, Gilad Peleg, djchie, Gary Ye, Nicolas Lalevée -Repository: http://github.com/mozilla/source-map.git +By: Valentin 7rulnik Semirulnik, Nick Fitzgerald, Tobias Koppers, Duncan Beevers, Stephen Crane, Ryan Seddon, Miles Elam, Mihai Bazon, Michael Ficarra, Todd Wolfson, Alexander Solovyov, Felix Gnass, Conrad Irwin, usrbincc, David Glasser, Chase Douglas, Evan Wallace, Heather Arthur, Hugh Kennedy, Simon Lydell, Jmeas Smith, Michael Z Goddard, azu, John Gozde, Adam Kirkton, Chris Montgomery, J. Ryan Stinnett, Jack Herrington, Chris Truter, Daniel Espeset, Jamie Wong, Eddy Bruël, Hawken Rives, Gilad Peleg, djchie, Gary Ye, Nicolas Lalevée +Repository: 7rulnik/source-map-js > Copyright (c) 2009-2011, Mozilla Foundation and contributors > All rights reserved. diff --git a/packages/vite/package.json b/packages/vite/package.json index 62fa3d3b88d5e8..dc0f53b048157c 100644 --- a/packages/vite/package.json +++ b/packages/vite/package.json @@ -110,7 +110,7 @@ "resolve.exports": "^1.1.0", "rollup-plugin-license": "^2.6.0", "sirv": "^2.0.0", - "source-map": "^0.6.1", + "source-map-js": "^1.0.2", "source-map-support": "^0.5.21", "strip-ansi": "^6.0.1", "terser": "^5.10.0", diff --git a/packages/vite/src/node/server/pluginContainer.ts b/packages/vite/src/node/server/pluginContainer.ts index bb3e8fa36db624..b5eca4b58dbf75 100644 --- a/packages/vite/src/node/server/pluginContainer.ts +++ b/packages/vite/src/node/server/pluginContainer.ts @@ -70,7 +70,7 @@ import type { ResolvedConfig } from '../config' import { buildErrorMessage } from './middlewares/error' import type { ModuleGraph } from './moduleGraph' import { performance } from 'perf_hooks' -import { SourceMapConsumer } from 'source-map' +import { SourceMapConsumer } from 'source-map-js/lib/source-map-consumer' import type * as postcss from 'postcss' export interface PluginContainerOptions { diff --git a/packages/vite/src/node/ssr/ssrStacktrace.ts b/packages/vite/src/node/ssr/ssrStacktrace.ts index d70381062d062e..75fcd8d2933c6f 100644 --- a/packages/vite/src/node/ssr/ssrStacktrace.ts +++ b/packages/vite/src/node/ssr/ssrStacktrace.ts @@ -1,5 +1,5 @@ -import type { RawSourceMap } from 'source-map' -import { SourceMapConsumer } from 'source-map' +import type { RawSourceMap } from 'source-map-js' +import { SourceMapConsumer } from 'source-map-js/lib/source-map-consumer' import type { ModuleGraph } from '../server/moduleGraph' let offset: number @@ -32,8 +32,6 @@ export function ssrRewriteStacktrace( return input } - // In `source-map:v0.7.0+` this constructor returns a Promise... - // How can we make this block async? const consumer = new SourceMapConsumer( rawSourceMap as unknown as RawSourceMap ) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0cbdc75dcc4abc..0b6c2c6e9de114 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -796,7 +796,7 @@ importers: rollup: ^2.59.0 rollup-plugin-license: ^2.6.0 sirv: ^2.0.0 - source-map: ^0.6.1 + source-map-js: ^1.0.2 source-map-support: ^0.5.21 strip-ansi: ^6.0.1 terser: ^5.10.0 @@ -869,7 +869,7 @@ importers: resolve.exports: 1.1.0 rollup-plugin-license: 2.6.0_rollup@2.62.0 sirv: 2.0.0 - source-map: 0.6.1 + source-map-js: 1.0.2 source-map-support: 0.5.21 strip-ansi: 6.0.1 terser: 5.10.0_acorn@8.7.0 @@ -4556,19 +4556,6 @@ packages: peerDependenciesMeta: debug: optional: true - dev: false - - /follow-redirects/1.14.6_debug@4.3.3: - resolution: {integrity: sha512-fhUl5EwSJbbl8AR+uYL2KQDxLkdSjZGR36xy46AO7cOMTrCMON6Sa28FmAnC2tRTDbd/Uuzz3aJBv7EBN7JH8A==} - engines: {node: '>=4.0'} - peerDependencies: - debug: '*' - peerDependenciesMeta: - debug: - optional: true - dependencies: - debug: 4.3.3 - dev: true /form-data/3.0.1: resolution: {integrity: sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==} @@ -4955,7 +4942,7 @@ packages: engines: {node: '>=8.0.0'} dependencies: eventemitter3: 4.0.7 - follow-redirects: 1.14.6_debug@4.3.3 + follow-redirects: 1.14.6 requires-port: 1.0.0 transitivePeerDependencies: - debug @@ -7082,7 +7069,7 @@ packages: dependencies: nanoid: 3.1.30 picocolors: 1.0.0 - source-map-js: 1.0.1 + source-map-js: 1.0.2 /preact/10.6.4: resolution: {integrity: sha512-WyosM7pxGcndU8hY0OQlLd54tOU+qmG45QXj2dAYrL11HoyU/EzOSTlpJsirbBr1QW7lICxSsVJJmcmUglovHQ==} @@ -7892,6 +7879,11 @@ packages: /source-map-js/1.0.1: resolution: {integrity: sha512-4+TN2b3tqOCd/kaGRJ/sTYA0tR0mdXx26ipdolxcwtJVqEnqNYvlCAt1q3ypy4QMlYus+Zh34RNtYLoq2oQ4IA==} engines: {node: '>=0.10.0'} + dev: true + + /source-map-js/1.0.2: + resolution: {integrity: sha512-R0XvVJ9WusLiqTCEiGCmICCMplcCkIwwR11mOSD9CR5u+IXYdiseeEuXCVAjS54zqwkLcPNnmU4OeJ6tUrWhDw==} + engines: {node: '>=0.10.0'} /source-map-resolve/0.6.0: resolution: {integrity: sha512-KXBr9d/fO/bWo97NXsPIAW1bFSBOuCnjbNTBMO7N59hsv5i9yzRDfcYwwt0l04+VqnKC+EwzvJZIP/qkuMgR/w==}