diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index cc9ef81..68f20f5 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -15,15 +15,17 @@ jobs: FORCE_COLOR: '1' steps: - name: Checkout repo - uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # 5.0.0 - - name: Use Node.js 24 - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # 5.0.0 + uses: actions/checkout@df4cb1c069e1874edd31b4311f1884172cec0e10 # 6.0.3 + - name: Use Node.js 26 + uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # 6.4.0 with: - node-version: 24 + node-version: 26 registry-url: https://registry.npmjs.org/ + - name: Enable Corepack + run: corepack enable - name: Install packages run: YARN_ENABLE_COLORS=true yarn install - name: Publish packages to npm run: | - npm --version - npm publish + yarn --version + yarn npm publish diff --git a/.yarn/install-state.gz b/.yarn/install-state.gz new file mode 100644 index 0000000..bcffcd6 Binary files /dev/null and b/.yarn/install-state.gz differ diff --git a/.yarnrc.yml b/.yarnrc.yml new file mode 100644 index 0000000..d1ae5d6 --- /dev/null +++ b/.yarnrc.yml @@ -0,0 +1,9 @@ +approvedGitRepositories: [] + +enableScripts: true + +nodeLinker: node-modules + +npmMinimalAgeGate: 10080 + +npmRegistryServer: "https://registry.npmjs.org" diff --git a/index.js b/index.js index 3bd639c..49b3545 100644 --- a/index.js +++ b/index.js @@ -1,5 +1,5 @@ -const sourceMap = require('source-map'); -const acorn = require('acorn'); +import sourceMap from 'source-map'; +import * as acorn from 'acorn'; /** * @type {{ @@ -26,12 +26,12 @@ let LocationSpan; * sourcesContent: (!Array|undefined), * names: !Array, * mappings: string - * }} + * }} */ let SourceMap; /** - * @param {!string} input + * @param {!string} input * @return {!Array} Array of indexes indicating the index in the original string of start each new line */ function getLineIndexes(input) { @@ -45,7 +45,7 @@ function getLineIndexes(input) { } /** - * @param {number} index + * @param {number} index * @param {!Array} lineIndexes * @return {number} */ @@ -61,8 +61,8 @@ function getLineNumForIndex(index, lineIndexes) { } /** - * @param {!LocationSpan} a - * @param {!LocationSpan} b + * @param {!LocationSpan} a + * @param {!LocationSpan} b * @return {number} */ function compareLocations(a, b) { @@ -81,7 +81,7 @@ function compareLocations(a, b) { return a.id - b.id; } -class StringReplaceSourceMap { +export default class StringReplaceSourceMap { /** * @param {!string} originalString * @param {string|SourceMap|null} originalSourceMap @@ -117,9 +117,9 @@ class StringReplaceSourceMap { } /** - * @param {number} start - * @param {number} end - * @param {?string=} newString + * @param {number} start + * @param {number} end + * @param {?string=} newString */ replace(start, end, newString) { const lineIndexesForNewString = getLineIndexes(newString); @@ -178,7 +178,7 @@ class StringReplaceSourceMap { let updatedString = this.string; for (let i = locationUpdates.length - 1; i >= 0; i--) { updatedString = updatedString.substr(0, locationUpdates[i].start.index) + - (locationUpdates[i].newString || '') + + (locationUpdates[i].newString || '') + updatedString.substr(locationUpdates[i].end.index); } return updatedString; @@ -269,7 +269,7 @@ class StringReplaceSourceMap { if (mappingRecord) { let columnOffset = 0; - if (mappingRecord.generated.line === columnOffsets.line) { + if (mappingRecord.generated.line === columnOffsets.line) { columnOffset = columnOffsets.offsets.reduce((calculatedOffset, offsetInfo) => { if (offsetInfo.resetColumn) { return offsetInfo.offset; @@ -305,7 +305,7 @@ class StringReplaceSourceMap { /** * Helper method to generate an identity source map for a JS file - * + * * @param {string} sourcePath of the file * @param {string} jsSource * @return {!Object} @@ -317,7 +317,7 @@ class StringReplaceSourceMap { locations: true, ecmaVersion: 'latest' }); - + for (let token = tokenizer.getToken(); token.type.label !== 'eof'; token = tokenizer.getToken()) { const mapping = { original: token.loc.start, @@ -333,5 +333,3 @@ class StringReplaceSourceMap { return generator.toJSON(); } } - -module.exports = StringReplaceSourceMap; diff --git a/package.json b/package.json index c7c0a29..f9a94af 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,9 @@ { "name": "string-replace-source-map", - "version": "1.3.1", + "version": "2.0.0", "description": "Replace strings in a file with a source map and update the mappings at the same time.", "main": "index.js", + "type": "module", "repository": "https://github.com/Banno/string-replace-source-map", "author": "Chad Killingsworth ", "license": "Apache-2.0", @@ -15,9 +16,10 @@ ], "dependencies": { "acorn": "8.x", - "source-map": "0.8.0-beta.0 || 0.8.x" + "source-map": "^0.7.6" }, "devDependencies": { - "jasmine": "^3.5.0" - } + "jasmine": "^6.2.0" + }, + "packageManager": "yarn@4.16.0" } diff --git a/test/string-replace-source-map.spec.js b/test/string-replace-source-map.spec.js index b18aaf7..c4b0b73 100644 --- a/test/string-replace-source-map.spec.js +++ b/test/string-replace-source-map.spec.js @@ -1,6 +1,11 @@ -const fs = require('fs'); -const path = require('path'); -const sourceMap = require('source-map'); +import * as fs from 'node:fs'; +import path from 'node:path'; +import {fileURLToPath, URL} from 'node:url'; +import sourceMap from 'source-map'; +import StringReplaceSourceMap from '../index.js'; + +const __dirname = fileURLToPath(new URL('.', import.meta.url)); + function verifySourceMap(originalContents, newContents, generatedSourceMap, replacementIndex) { const originalLines = originalContents.split('\n'); @@ -30,7 +35,6 @@ function verifySourceMap(originalContents, newContents, generatedSourceMap, repl } describe('string-replace-source-map', () => { - const StringReplaceSourceMap = require('../'); const originalFile = fs.readFileSync(path.resolve(__dirname, 'fixtures/original-file.js'), 'utf8'); const originalSourceMap = fs.readFileSync(path.resolve(__dirname, 'fixtures/original-file.js.map'), 'utf8'); /** @type {!StringReplaceSourceMap} */ diff --git a/yarn.lock b/yarn.lock index ee68577..822363a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1,131 +1,119 @@ -# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. -# yarn lockfile v1 - - -acorn@8.x: - version "8.7.1" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.7.1.tgz#0197122c843d1bf6d0a5e83220a788f278f63c30" - integrity sha512-Xx54uLJQZ19lKygFXOWsscKUbsBZW0CPykPhVQdhIeIwrbPmJzqeASDInc8nKBnp/JT6igTs82qPXz069H8I/A== - -balanced-match@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" - integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c= - -brace-expansion@^1.1.7: - version "1.1.11" - resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" - integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA== - dependencies: - balanced-match "^1.0.0" - concat-map "0.0.1" - -concat-map@0.0.1: - version "0.0.1" - resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" - integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= - -fs.realpath@^1.0.0: - version "1.0.0" - resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" - integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= - -glob@^7.1.4: - version "7.1.6" - resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6" - integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA== - dependencies: - fs.realpath "^1.0.0" - inflight "^1.0.4" - inherits "2" - minimatch "^3.0.4" - once "^1.3.0" - path-is-absolute "^1.0.0" - -inflight@^1.0.4: - version "1.0.6" - resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" - integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk= - dependencies: - once "^1.3.0" - wrappy "1" - -inherits@2: - version "2.0.4" - resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" - integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== - -jasmine-core@~3.5.0: - version "3.5.0" - resolved "https://registry.yarnpkg.com/jasmine-core/-/jasmine-core-3.5.0.tgz#132c23e645af96d85c8bca13c8758b18429fc1e4" - integrity sha512-nCeAiw37MIMA9w9IXso7bRaLl+c/ef3wnxsoSAlYrzS+Ot0zTG6nU8G/cIfGkqpkjX2wNaIW9RFG0TwIFnG6bA== - -jasmine@^3.5.0: - version "3.5.0" - resolved "https://registry.yarnpkg.com/jasmine/-/jasmine-3.5.0.tgz#7101eabfd043a1fc82ac24e0ab6ec56081357f9e" - integrity sha512-DYypSryORqzsGoMazemIHUfMkXM7I7easFaxAvNM3Mr6Xz3Fy36TupTrAOxZWN8MVKEU5xECv22J4tUQf3uBzQ== +# This file is generated by running "yarn install" inside your project. +# Manual changes might be lost - proceed with caution! + +__metadata: + version: 10 + cacheKey: 10c0 + +"@jasminejs/reporters@npm:^1.0.0": + version: 1.0.0 + resolution: "@jasminejs/reporters@npm:1.0.0" + checksum: 10c0/0175057c1dd7dda080ea7ec208a2bc6d98c2fca4c7458afaec951d94011d30749b3af751f6dda2d85b074a8fef6765a04558ec714cedb3d81819839c5254ca01 + languageName: node + linkType: hard + +"acorn@npm:8.x": + version: 8.16.0 + resolution: "acorn@npm:8.16.0" + bin: + acorn: bin/acorn + checksum: 10c0/c9c52697227661b68d0debaf972222d4f622aa06b185824164e153438afa7b08273432ca43ea792cadb24dada1d46f6f6bb1ef8de9956979288cc1b96bf9914e + languageName: node + linkType: hard + +"balanced-match@npm:^4.0.2": + version: 4.0.4 + resolution: "balanced-match@npm:4.0.4" + checksum: 10c0/07e86102a3eb2ee2a6a1a89164f29d0dbaebd28f2ca3f5ca786f36b8b23d9e417eb3be45a4acf754f837be5ac0a2317de90d3fcb7f4f4dc95720a1f36b26a17b + languageName: node + linkType: hard + +"brace-expansion@npm:^5.0.5": + version: 5.0.6 + resolution: "brace-expansion@npm:5.0.6" dependencies: - glob "^7.1.4" - jasmine-core "~3.5.0" - -lodash.sortby@^4.7.0: - version "4.7.0" - resolved "https://registry.yarnpkg.com/lodash.sortby/-/lodash.sortby-4.7.0.tgz#edd14c824e2cc9c1e0b0a1b42bb5210516a42438" - integrity sha1-7dFMgk4sycHgsKG0K7UhBRakJDg= - -minimatch@^3.0.4: - version "3.1.5" - resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.1.5.tgz#580c88f8d5445f2bd6aa8f3cadefa0de79fbd69e" - integrity sha512-VgjWUsnnT6n+NUk6eZq77zeFdpW2LWDzP6zFGrCbHXiYNul5Dzqk2HHQ5uFH2DNW5Xbp8+jVzaeNt94ssEEl4w== + balanced-match: "npm:^4.0.2" + checksum: 10c0/8c919869b90f61d533b341d3340be5ee4413232ea89b8246cbc2f38eb014f1d8182785c98a006eaf6111d02dc9eeffefdc240d5ac158625b2ed084dccd4bbf9b + languageName: node + linkType: hard + +"glob@npm:^10.2.2 || ^11.0.3 || ^12.0.0 || ^13.0.0": + version: 13.0.6 + resolution: "glob@npm:13.0.6" dependencies: - brace-expansion "^1.1.7" - -once@^1.3.0: - version "1.4.0" - resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" - integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E= + minimatch: "npm:^10.2.2" + minipass: "npm:^7.1.3" + path-scurry: "npm:^2.0.2" + checksum: 10c0/269c236f11a9b50357fe7a8c6aadac667e01deb5242b19c84975628f05f4438d8ee1354bb62c5d6c10f37fd59911b54d7799730633a2786660d8c69f1d18120a + languageName: node + linkType: hard + +"jasmine-core@npm:~6.2.0": + version: 6.2.0 + resolution: "jasmine-core@npm:6.2.0" + checksum: 10c0/4845ce6e93b5a48abbc0d37d748189ff826568e11bc594e527b173cd77dbd371e7a9f16c4a5e9bde7fb864ac60e1e3b21ddc930343f4d51d766128c55f4ceab6 + languageName: node + linkType: hard + +"jasmine@npm:^6.2.0": + version: 6.2.0 + resolution: "jasmine@npm:6.2.0" dependencies: - wrappy "1" - -path-is-absolute@^1.0.0: - version "1.0.1" - resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" - integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18= - -punycode@^2.1.0: - version "2.1.1" - resolved "https://registry.yarnpkg.com/punycode/-/punycode-2.1.1.tgz#b58b010ac40c22c5657616c8d2c2c02c7bf479ec" - integrity sha512-XRsRjdf+j5ml+y/6GKHPZbrF/8p2Yga0JPtdqTIY2Xe5ohJPD9saDJJLPvp9+NSBprVvevdXZybnj2cv8OEd0A== - -"source-map@0.8.0-beta.0 || 0.8.x": - version "0.8.0-beta.0" - resolved "https://registry.yarnpkg.com/source-map/-/source-map-0.8.0-beta.0.tgz#d4c1bb42c3f7ee925f005927ba10709e0d1d1f11" - integrity sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA== + "@jasminejs/reporters": "npm:^1.0.0" + glob: "npm:^10.2.2 || ^11.0.3 || ^12.0.0 || ^13.0.0" + jasmine-core: "npm:~6.2.0" + bin: + jasmine: bin/jasmine.js + checksum: 10c0/11ce21efc28bdc76958a18c30d96ffbd84dc4e5d0d8c5f7f2ed23606b27f83f0a37e68b530808138b0adff5d2daee2d904ef35a5a2f9190b6974810a98b89339 + languageName: node + linkType: hard + +"lru-cache@npm:^11.0.0": + version: 11.5.1 + resolution: "lru-cache@npm:11.5.1" + checksum: 10c0/7b341cea79a8efe9c6a6f20c8757a77eca5b25d7ff983ccf4e11e547b81f6787824baa1c84705251dff84ab4ffac85717ac354b9d02e465f86a9f8b166409979 + languageName: node + linkType: hard + +"minimatch@npm:^10.2.2": + version: 10.2.5 + resolution: "minimatch@npm:10.2.5" dependencies: - whatwg-url "^7.0.0" - -tr46@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/tr46/-/tr46-1.0.1.tgz#a8b13fd6bfd2489519674ccde55ba3693b706d09" - integrity sha1-qLE/1r/SSJUZZ0zN5VujaTtwbQk= + brace-expansion: "npm:^5.0.5" + checksum: 10c0/6bb058bd6324104b9ec2f763476a35386d05079c1f5fe4fbf1f324a25237cd4534d6813ecd71f48208f4e635c1221899bef94c3c89f7df55698fe373aaae20fd + languageName: node + linkType: hard + +"minipass@npm:^7.1.2, minipass@npm:^7.1.3": + version: 7.1.3 + resolution: "minipass@npm:7.1.3" + checksum: 10c0/539da88daca16533211ea5a9ee98dc62ff5742f531f54640dd34429e621955e91cc280a91a776026264b7f9f6735947629f920944e9c1558369e8bf22eb33fbb + languageName: node + linkType: hard + +"path-scurry@npm:^2.0.2": + version: 2.0.2 + resolution: "path-scurry@npm:2.0.2" dependencies: - punycode "^2.1.0" - -webidl-conversions@^4.0.2: - version "4.0.2" - resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-4.0.2.tgz#a855980b1f0b6b359ba1d5d9fb39ae941faa63ad" - integrity sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg== - -whatwg-url@^7.0.0: - version "7.1.0" - resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-7.1.0.tgz#c2c492f1eca612988efd3d2266be1b9fc6170d06" - integrity sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg== + lru-cache: "npm:^11.0.0" + minipass: "npm:^7.1.2" + checksum: 10c0/b35ad37cf6557a87fd057121ce2be7695380c9138d93e87ae928609da259ea0a170fac6f3ef1eb3ece8a068e8b7f2f3adf5bb2374cf4d4a57fe484954fcc9482 + languageName: node + linkType: hard + +"source-map@npm:^0.7.6": + version: 0.7.6 + resolution: "source-map@npm:0.7.6" + checksum: 10c0/59f6f05538539b274ba771d2e9e32f6c65451982510564438e048bc1352f019c6efcdc6dd07909b1968144941c14015c2c7d4369fb7c4d7d53ae769716dcc16c + languageName: node + linkType: hard + +"string-replace-source-map@workspace:.": + version: 0.0.0-use.local + resolution: "string-replace-source-map@workspace:." dependencies: - lodash.sortby "^4.7.0" - tr46 "^1.0.1" - webidl-conversions "^4.0.2" - -wrappy@1: - version "1.0.2" - resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" - integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= + acorn: "npm:8.x" + jasmine: "npm:^6.2.0" + source-map: "npm:^0.7.6" + languageName: unknown + linkType: soft