Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Comment thread
ChadKillingsworth marked this conversation as resolved.
Binary file added .yarn/install-state.gz
Binary file not shown.
9 changes: 9 additions & 0 deletions .yarnrc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
approvedGitRepositories: []

enableScripts: true

nodeLinker: node-modules

npmMinimalAgeGate: 10080

npmRegistryServer: "https://registry.npmjs.org"
32 changes: 15 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const sourceMap = require('source-map');
const acorn = require('acorn');
import sourceMap from 'source-map';
import * as acorn from 'acorn';

/**
* @type {{
Expand All @@ -26,12 +26,12 @@ let LocationSpan;
* sourcesContent: (!Array<string>|undefined),
* names: !Array<string>,
* mappings: string
* }}
* }}
*/
let SourceMap;

/**
* @param {!string} input
* @param {!string} input
* @return {!Array<number>} Array of indexes indicating the index in the original string of start each new line
*/
function getLineIndexes(input) {
Expand All @@ -45,7 +45,7 @@ function getLineIndexes(input) {
}

/**
* @param {number} index
* @param {number} index
* @param {!Array<number>} lineIndexes
* @return {number}
*/
Expand All @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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}
Expand All @@ -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,
Expand All @@ -333,5 +333,3 @@ class StringReplaceSourceMap {
return generator.toJSON();
}
}

module.exports = StringReplaceSourceMap;
10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -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 <ckillingsworth@jackhenry.com>",
"license": "Apache-2.0",
Expand All @@ -15,9 +16,10 @@
],
"dependencies": {
"acorn": "8.x",
"source-map": "0.8.0-beta.0 || 0.8.x"
"source-map": "^0.7.6"
Comment thread
jrobinson01 marked this conversation as resolved.
},
"devDependencies": {
"jasmine": "^3.5.0"
}
"jasmine": "^6.2.0"
},
"packageManager": "yarn@4.16.0"
}
12 changes: 8 additions & 4 deletions test/string-replace-source-map.spec.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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} */
Expand Down
Loading