Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: adamreisnz/replace-in-file
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: a8619da2db61ee3247f5161279c95ab61e0bb0db
Choose a base ref
...
head repository: adamreisnz/replace-in-file
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 40a3b59894e87a74182903259029366ab55a99b4
Choose a head ref
  • 5 commits
  • 22 files changed
  • 3 contributors

Commits on May 29, 2023

  1. Update replace-in-file.js

    adamreisnz committed May 29, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    8dc0b08 View commit details

Commits on Oct 27, 2023

  1. Export 'replaceInFile' namespace. (#173)

    Co-authored-by: gnyar <gergo.nyarai@cae.com>
    kukko and gnyar authored Oct 27, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6f698cf View commit details
  2. Remove strict

    adamreisnz committed Oct 27, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    802e830 View commit details
  3. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f74f9b0 View commit details
  4. Update package.json

    adamreisnz committed Oct 27, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    40a3b59 View commit details
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -492,4 +492,4 @@ See the [Changelog](CHANGELOG.md) for more information.
## License
(MIT License)

Copyright 2015-2020, Adam Reis, Co-founder at [Hello Club](https://helloclub.com/?source=npm)
Copyright 2015-2023, Adam Reis, Co-founder at [Hello Club](https://helloclub.com/?source=npm) and [Frello](https://getfrello.com/?source=npm)
4 changes: 0 additions & 4 deletions bin/cli.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
#!/usr/bin/env node
'use strict';

/**
* Dependencies
*/
const {argv} = require('yargs');
const replace = require('../lib/replace-in-file');
const loadConfig = require('../lib/helpers/load-config');
4 changes: 0 additions & 4 deletions lib/helpers/combine-config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
'use strict';

/**
* Dependencies
*/
const parseConfig = require('./parse-config');

/**
1 change: 0 additions & 1 deletion lib/helpers/error-handler.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

/**
* Error handler
4 changes: 0 additions & 4 deletions lib/helpers/get-paths-async.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
'use strict';

/**
* Dependencies
*/
const globAsync = require('./glob-async');

/**
4 changes: 0 additions & 4 deletions lib/helpers/get-paths-sync.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
'use strict';

/**
* Dependencies
*/
const glob = require('glob');

/**
4 changes: 0 additions & 4 deletions lib/helpers/glob-async.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
'use strict';

/**
* Dependencies
*/
const glob = require('glob');

/**
4 changes: 0 additions & 4 deletions lib/helpers/load-config.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
'use strict';

/**
* Dependencies
*/
const path = require('path');

/**
1 change: 0 additions & 1 deletion lib/helpers/make-replacements.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

/**
* Get replacement helper
5 changes: 2 additions & 3 deletions lib/helpers/parse-config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

/**
* Defaults
@@ -33,12 +32,12 @@ module.exports = function parseConfig(config) {
//Extract data
const {files, from, to, processor, ignore, encoding} = config;


if (typeof processor !== 'undefined') {
if (typeof processor !== 'function' && !Array.isArray(processor)) {
throw new Error('Processor should be either a function or an array of functions');
}
} else {
}
else {
//Validate values
if (typeof files === 'undefined') {
throw new Error('Must specify file or files');
6 changes: 1 addition & 5 deletions lib/helpers/process-async.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
'use strict';

/**
* Dependencies
*/
const fs = require('fs');
const runProcessors = require('./run-processors');

@@ -24,7 +20,7 @@ module.exports = function processAsync(file, processor, config) {

//Make replacements
const [result, newContents] = runProcessors(
contents, processor, file,
contents, processor, file
);

//Not changed or dry run?
6 changes: 1 addition & 5 deletions lib/helpers/process-sync.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
'use strict';

/**
* Dependencies
*/
const fs = require('fs');
const runProcessors = require('./run-processors');

@@ -17,7 +13,7 @@ module.exports = function processSync(file, processor, config) {

//Process contents and check if anything changed
const [result, newContents] = runProcessors(
contents, processor, file,
contents, processor, file
);

//Contents changed and not a dry run? Write to file
4 changes: 0 additions & 4 deletions lib/helpers/replace-async.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
'use strict';

/**
* Dependencies
*/
const fs = require('fs');
const makeReplacements = require('./make-replacements');

4 changes: 0 additions & 4 deletions lib/helpers/replace-sync.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
'use strict';

/**
* Dependencies
*/
const fs = require('fs');
const makeReplacements = require('./make-replacements');

4 changes: 0 additions & 4 deletions lib/helpers/success-handler.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
'use strict';

/**
* Dependencies
*/
const chalk = require('chalk');

/**
4 changes: 0 additions & 4 deletions lib/process-file.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
'use strict';

/**
* Dependencies
*/
const chalk = require('chalk');
const parseConfig = require('./helpers/parse-config');
const getPathsSync = require('./helpers/get-paths-sync');
4 changes: 0 additions & 4 deletions lib/process-file.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
'use strict';

/**
* Dependencies
*/
import transform, {sync, processFile, processFileSync} from './process-file';
const fs = require('fs');
const writeFile = Promise.promisify(fs.writeFile);
6 changes: 1 addition & 5 deletions lib/replace-in-file.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
'use strict';

/**
* Dependencies
*/
const chalk = require('chalk');
const parseConfig = require('./helpers/parse-config');
const getPathsSync = require('./helpers/get-paths-sync');
@@ -73,7 +69,7 @@ function replaceInFile(config, cb) {
*/
function replaceInFileSync(config) {

// If custom processor is provided use it instead
//If custom processor is provided use it instead
if (config && config.processor) {
return processFile.processFileSync(config);
}
4 changes: 0 additions & 4 deletions lib/replace-in-file.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
'use strict';

/**
* Dependencies
*/
import replace, {sync, replaceInFile, replaceInFileSync} from './replace-in-file';
const fs = require('fs');
const writeFile = Promise.promisify(fs.writeFile);
5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
{
"name": "replace-in-file",
"version": "7.0.1",
"version": "7.0.2",
"description": "A simple utility to quickly replace text in one or more files.",
"homepage": "https://github.com/adamreisnz/replace-in-file#readme",
"author": {
"name": "Adam Reis",
"email": "adam@reis.nz",
"url": "https://adam.reiz.nz/"
"email": "adam@reis.nz"
},
"license": "MIT",
"repository": {
1 change: 0 additions & 1 deletion test/helpers/setup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
'use strict';

//Load dependencies
const Promise = require('bluebird');
2 changes: 1 addition & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ declare module 'replace-in-file' {
export function replaceInFile(config: ReplaceInFileConfig, cb: (error: Error, results: ReplaceResult[]) => void): void;
export default replaceInFile;

namespace replaceInFile {
export namespace replaceInFile {
export function sync(config: ReplaceInFileConfig): ReplaceResult[];
export function replaceInFileSync(config: ReplaceInFileConfig): ReplaceResult[];
export function replaceInFile(config: ReplaceInFileConfig): Promise<ReplaceResult[]>;