-
Notifications
You must be signed in to change notification settings - Fork 66
fix(dts): adapt ReplaceInFileConfig interface to actual implementation #107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,7 +3,7 @@ | |
| /** | ||
| * Dependencies | ||
| */ | ||
| const replace = require('./replace-in-file'); | ||
| import replace, {sync, replaceInFile, replaceInFileSync} from './replace-in-file' | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a bit surprised that this works and passes the travis build in Node versions 8 and 10? |
||
| const fs = require('fs'); | ||
| const writeFile = Promise.promisify(fs.writeFile); | ||
| const deleteFile = Promise.promisify(fs.unlink); | ||
|
|
@@ -1151,4 +1151,22 @@ describe('Replace in file', () => { | |
| expect(results[0].numReplacements).to.equal(0); | ||
| }); | ||
| }); | ||
|
|
||
| describe('module export', () => { | ||
| it('default module export refers to async replace implementation', () => { | ||
| expect(replace).to.be.a('function'); | ||
| }); | ||
|
|
||
| it('exports named replaceInFile, replaceInFileSync and sync from module facade', () => { | ||
| expect(replaceInFile).to.be.a('function'); | ||
| expect(replaceInFileSync).to.be.a('function'); | ||
| expect(sync).to.be.a('function'); | ||
| }); | ||
|
|
||
| it('exposes inner functions as own fields of replace', () => { | ||
| expect(replace.replaceInFile).to.equal(replace); | ||
| expect(replace.sync).to.equal(replaceInFileSync); | ||
| expect(replace.replaceInFileSync).to.equal(replaceInFileSync); | ||
| }); | ||
| }) | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,18 +1,27 @@ | ||
|
|
||
| declare module 'replace-in-file' { | ||
| function replaceInFile(config: ReplaceInFileConfig): Promise<ReplaceResult[]>; | ||
| function replaceInFile(config: ReplaceInFileConfig, cb: (error: Error, results: ReplaceResult[]) => void): void; | ||
| export function replaceInFile(config: ReplaceInFileConfig): Promise<ReplaceResult[]>; | ||
| export function replaceInFile(config: ReplaceInFileConfig, cb: (error: Error, results: ReplaceResult[]) => void): void; | ||
| export default replaceInFile; | ||
|
|
||
| namespace replaceInFile { | ||
| export function sync(config: ReplaceInFileConfig): ReplaceResult[]; | ||
| export function replaceInFileSync(config: ReplaceInFileConfig): ReplaceResult[]; | ||
| export function replaceInFile(config: ReplaceInFileConfig): Promise<ReplaceResult[]>; | ||
| export function replaceInFile(config: ReplaceInFileConfig, cb: (error: Error, results: ReplaceResult[]) => void): void; | ||
| } | ||
|
|
||
| export function sync(config: ReplaceInFileConfig): ReplaceResult[]; | ||
| export function replaceInFileSync(config: ReplaceInFileConfig): ReplaceResult[]; | ||
|
|
||
| export type From = string | RegExp | FromCallback; | ||
| export type To = string | ToCallback; | ||
|
|
||
| export interface ReplaceInFileConfig { | ||
| files: string | string[]; | ||
| ignore?: string | string[]; | ||
| from: string | RegExp | string[] | RegExp[] | FromCallback; | ||
| to: string | string[] | ToCallback; | ||
| from: From | Array<From>; | ||
| to: To | Array<To>; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would this change not also suggest an Array of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's possible, but let's inspect the current implementation:
It looks that |
||
| countMatches?: boolean; | ||
| allowEmptyPaths?: boolean, | ||
| disableGlobs?: boolean, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the benefit of having both
syncandreplaceInFileSync?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syncis just a legacy alias for backward compatibilityNew named exports let us to avoid using of default module reference: