Skip to content

Commit

Permalink
fix: Ensure patched merge-source-map is included in package (#24490)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisbreiding authored Nov 2, 2022
1 parent 5a7dda8 commit 493d90c
Show file tree
Hide file tree
Showing 6 changed files with 121 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@ import { parse } from '@babel/parser'
import { default as traverse } from '@babel/traverse'
import { default as generate } from '@babel/generator'
import { NodePath, types as t } from '@babel/core'
import mergeSourceMaps from 'merge-source-map'
import * as loaderUtils from 'loader-utils'
import * as pathUtil from 'path'
import Debug from 'debug'

import mergeSourceMaps from './merge-source-map'
import { crossOriginCallbackStore } from './cross-origin-callback-store'
import utils from './utils'

Expand Down
95 changes: 95 additions & 0 deletions npm/webpack-preprocessor/lib/merge-source-map.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// https://github.com/keik/merge-source-map
//
// The MIT License (MIT)

// Copyright (c) keik <[email protected]>

// 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 sourceMap from 'source-map'

const SourceMapConsumer = sourceMap.SourceMapConsumer
const SourceMapGenerator = sourceMap.SourceMapGenerator

/**
* Merge old source map and new source map and return merged.
* If old or new source map value is falsy, return another one as it is.
*
* @param {object|string} [oldMap] old source map object
* @param {object|string} [newmap] new source map object
* @return {object|undefined} merged source map object, or undefined when both old and new source map are undefined
*/
export default function merge (oldMap, newMap) {
if (!oldMap) return newMap

if (!newMap) return oldMap

const oldMapConsumer = new SourceMapConsumer(oldMap)
const newMapConsumer = new SourceMapConsumer(newMap)
const mergedMapGenerator = new SourceMapGenerator()

// iterate on new map and overwrite original position of new map with one of old map
newMapConsumer.eachMapping(function (m) {
// pass when `originalLine` is null.
// It occurs in case that the node does not have origin in original code.
if (m.originalLine == null) return

const origPosInOldMap = oldMapConsumer.originalPositionFor({
line: m.originalLine,
column: m.originalColumn,
})

if (origPosInOldMap.source == null) return

mergedMapGenerator.addMapping({
original: {
line: origPosInOldMap.line,
column: origPosInOldMap.column,
},
generated: {
line: m.generatedLine,
column: m.generatedColumn,
},
source: origPosInOldMap.source,
name: origPosInOldMap.name,
})
})

const consumers = [newMapConsumer, oldMapConsumer]

consumers.forEach(function (consumer) {
// @ts-ignore
consumer.sources.forEach(function (sourceFile) {
// @ts-ignore
mergedMapGenerator._sources.add(sourceFile)
const sourceContent = consumer.sourceContentFor(sourceFile)

if (sourceContent != null) {
mergedMapGenerator.setSourceContent(sourceFile, sourceContent)
}
})
})

// @ts-ignore
mergedMapGenerator._sourceRoot = oldMap.sourceRoot
// @ts-ignore
mergedMapGenerator._file = oldMap.file

return JSON.parse(mergedMapGenerator.toString())
}
4 changes: 1 addition & 3 deletions npm/webpack-preprocessor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"build": "rimraf dist && tsc || echo 'built, with errors'",
"build-prod": "yarn build",
"deps": "deps-ok && dependency-check --no-dev .",
"postinstall": "patch-package",
"secure": "nsp check",
"semantic-release": "semantic-release",
"size": "npm pack --dry",
Expand All @@ -27,8 +26,7 @@
"loader-utils": "^2.0.0",
"lodash": "^4.17.20",
"md5": "2.3.0",
"merge-source-map": "1.1.0",
"patch-package": "6.4.7",
"source-map": "^0.6.1",
"webpack-virtual-modules": "^0.4.4"
},
"devDependencies": {
Expand Down
14 changes: 0 additions & 14 deletions npm/webpack-preprocessor/patches/merge-source-map+1.1.0.patch

This file was deleted.

4 changes: 2 additions & 2 deletions tooling/v8-snapshot/cache/dev-darwin/snapshot-meta.cache.json
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,7 @@
"./node_modules/ansi_up/ansi_up.js",
"./node_modules/any-base/index.js",
"./node_modules/any-base/src/converter.js",
"./node_modules/anymatch/index.js",
"./node_modules/archiver-utils/file.js",
"./node_modules/archiver-utils/index.js",
"./node_modules/archiver-utils/node_modules/glob/common.js",
Expand Down Expand Up @@ -3284,7 +3285,6 @@
"./node_modules/yn/lenient.js",
"./packages/data-context/node_modules/@babel/code-frame/lib/index.js",
"./packages/data-context/node_modules/@babel/parser/lib/index.js",
"./packages/data-context/node_modules/anymatch/index.js",
"./packages/data-context/node_modules/cross-spawn/index.js",
"./packages/data-context/node_modules/cross-spawn/lib/enoent.js",
"./packages/data-context/node_modules/cross-spawn/lib/parse.js",
Expand Down Expand Up @@ -3528,5 +3528,5 @@
"./tooling/v8-snapshot/cache/dev-darwin/snapshot-entry.js"
],
"deferredHashFile": "yarn.lock",
"deferredHash": "b23274a95457555a9102f7f660744b1a8f08324bfcfa01be64771c12fcb3ae35"
"deferredHash": "66156a5424fbd0d70c750ef2b16c22b0084a30220c67b632cff9212a7de7a226"
}
51 changes: 22 additions & 29 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7287,9 +7287,9 @@
source-map "^0.6.0"

"@types/webpack@^4", "@types/webpack@^4.41.12", "@types/webpack@^4.41.21", "@types/webpack@^4.41.8":
version "4.41.32"
resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.41.32.tgz#a7bab03b72904070162b2f169415492209e94212"
integrity sha512-cb+0ioil/7oz5//7tZUSwbrSAN/NWHrQylz5cW8G0dWTcF/g+/dSdMlKVZspBYuMAN1+WnwHrkxiRrLcwd0Heg==
version "4.41.33"
resolved "https://registry.yarnpkg.com/@types/webpack/-/webpack-4.41.33.tgz#16164845a5be6a306bcbe554a8e67f9cac215ffc"
integrity sha512-PPajH64Ft2vWevkerISMtnZ8rTs4YmRbs+23c402J0INmxDKCrhZNvwZYtzx96gY2wAtXdrK1BS2fiC8MlLr3g==
dependencies:
"@types/node" "*"
"@types/tapable" "^1"
Expand Down Expand Up @@ -8391,10 +8391,10 @@ acorn@^7.0.0, acorn@^7.1.1, acorn@^7.4.0:
resolved "https://registry.yarnpkg.com/acorn/-/acorn-7.4.1.tgz#feaed255973d2e77555b83dbc08851a6c63520fa"
integrity sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==

acorn@^8.4.1, acorn@^8.5.0:
version "8.7.0"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.0.tgz#90951fde0f8f09df93549481e5fc141445b791cf"
integrity sha512-V/LGr1APy+PXIwKebEWrkZPwoeoF+w1jiOBUmuxuiUIaOHtob8Qc9BTrYo7VuI5fR8tqsy+buA2WFooR5olqvQ==
acorn@^8.4.1, acorn@^8.5.0, acorn@^8.7.1:
version "8.8.1"
resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.8.1.tgz#0a3f9cbecc4ec3bea6f0a80b66ae8dd2da250b73"
integrity sha512-7zFpHzhnqYKrkYdUjF1HI1bzd0VygEGX8lFk4k5zVMqHEoES+P+7TKI+EvLO9WVMJ8eekdO0aDEK044xTXwPPA==

[email protected], address@^1.0.1:
version "1.1.2"
Expand Down Expand Up @@ -15144,10 +15144,10 @@ enhanced-resolve@^4.0.0, enhanced-resolve@^4.1.0, enhanced-resolve@^4.3.0, enhan
memory-fs "^0.5.0"
tapable "^1.0.0"

enhanced-resolve@^5.7.0, enhanced-resolve@^5.9.2:
version "5.9.2"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.9.2.tgz#0224dcd6a43389ebfb2d55efee517e5466772dd9"
integrity sha512-GIm3fQfwLJ8YZx2smuHpBKkXC1yOk+OBEmKckVyL0i/ea8mqDEykK3ld5dgH1QYPNyT/lIllxV2LULnxCHaHkA==
enhanced-resolve@^5.10.0, enhanced-resolve@^5.7.0, enhanced-resolve@^5.9.2:
version "5.10.0"
resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.10.0.tgz#0dc579c3bb2a1032e357ac45b8f3a6f3ad4fb1e6"
integrity sha512-T0yTFjdpldGY8PmuXXR0PyQ1ufZpEGiHVrp7zHKB7jdR4qlmZHhONVM5AQOAWXuF/w3dnHbEQVrNptJgt7F+cQ==
dependencies:
graceful-fs "^4.2.4"
tapable "^2.2.0"
Expand Down Expand Up @@ -23423,13 +23423,6 @@ [email protected], merge-descriptors@~1.0.0:
resolved "https://registry.yarnpkg.com/merge-descriptors/-/merge-descriptors-1.0.1.tgz#b00aaa556dd8b44568150ec9d1b953f3f90cbb61"
integrity sha1-sAqqVW3YtEVoFQ7J0blT8/kMu2E=

[email protected]:
version "1.1.0"
resolved "https://registry.yarnpkg.com/merge-source-map/-/merge-source-map-1.1.0.tgz#2fdde7e6020939f70906a68f2d7ae685e4c8c646"
integrity sha512-Qkcp7P2ygktpMPh2mCQZaf3jhN6D3Z/qVZHSdWvQ+2Ef5HgRAPBO57A77+ENm0CPx2+1Ce/MYKi3ymqdfuqibw==
dependencies:
source-map "^0.6.1"

merge-stream@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/merge-stream/-/merge-stream-2.0.0.tgz#52823629a14dd00c9770fb6ad47dc6310f2c1f60"
Expand Down Expand Up @@ -34399,10 +34392,10 @@ watchpack@^1.6.0, watchpack@^1.7.4:
chokidar "^3.4.1"
watchpack-chokidar2 "^2.0.1"

watchpack@^2.3.1:
version "2.3.1"
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.3.1.tgz#4200d9447b401156eeca7767ee610f8809bc9d25"
integrity sha512-x0t0JuydIo8qCNctdDrn1OzH/qDzk2+rdCOC3YzumZ42fiMqmQ7T3xQurykYMhYfHaPHTp4ZxAx2NfUo1K6QaA==
watchpack@^2.3.1, watchpack@^2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/watchpack/-/watchpack-2.4.0.tgz#fa33032374962c78113f93c7f2fb4c54c9862a5d"
integrity sha512-Lcvm7MGST/4fup+ifyKi2hjyIAwcdI4HRgtvTpIUxBRhB+RFtUh8XtDOxUfctVCnhVi+QQj49i91OyvzkJl6cg==
dependencies:
glob-to-regexp "^0.4.1"
graceful-fs "^4.1.2"
Expand Down Expand Up @@ -34731,33 +34724,33 @@ [email protected]:
webpack-sources "^1.4.1"

webpack@^5.38.1:
version "5.72.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.72.0.tgz#f8bc40d9c6bb489a4b7a8a685101d6022b8b6e28"
integrity sha512-qmSmbspI0Qo5ld49htys8GY9XhS9CGqFoHTsOVAnjBdg0Zn79y135R+k4IR4rKK6+eKaabMhJwiVB7xw0SJu5w==
version "5.74.0"
resolved "https://registry.yarnpkg.com/webpack/-/webpack-5.74.0.tgz#02a5dac19a17e0bb47093f2be67c695102a55980"
integrity sha512-A2InDwnhhGN4LYctJj6M1JEaGL7Luj6LOmyBHjcI8529cm5p6VXiTIW2sn6ffvEAKmveLzvu4jrihwXtPojlAA==
dependencies:
"@types/eslint-scope" "^3.7.3"
"@types/estree" "^0.0.51"
"@webassemblyjs/ast" "1.11.1"
"@webassemblyjs/wasm-edit" "1.11.1"
"@webassemblyjs/wasm-parser" "1.11.1"
acorn "^8.4.1"
acorn "^8.7.1"
acorn-import-assertions "^1.7.6"
browserslist "^4.14.5"
chrome-trace-event "^1.0.2"
enhanced-resolve "^5.9.2"
enhanced-resolve "^5.10.0"
es-module-lexer "^0.9.0"
eslint-scope "5.1.1"
events "^3.2.0"
glob-to-regexp "^0.4.1"
graceful-fs "^4.2.9"
json-parse-better-errors "^1.0.2"
json-parse-even-better-errors "^2.3.1"
loader-runner "^4.2.0"
mime-types "^2.1.27"
neo-async "^2.6.2"
schema-utils "^3.1.0"
tapable "^2.1.1"
terser-webpack-plugin "^5.1.3"
watchpack "^2.3.1"
watchpack "^2.4.0"
webpack-sources "^3.2.3"

"webpack@npm:webpack@^5":
Expand Down

4 comments on commit 493d90c

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 493d90c Nov 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.12.0/linux-arm64/develop-493d90c33082565a93418f39388daab348c175cf/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 493d90c Nov 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.12.0/darwin-arm64/develop-493d90c33082565a93418f39388daab348c175cf/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 493d90c Nov 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.12.0/darwin-x64/develop-493d90c33082565a93418f39388daab348c175cf/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 493d90c Nov 2, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.12.0/win32-x64/develop-493d90c33082565a93418f39388daab348c175cf/cypress.tgz

Please sign in to comment.