-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from marp-team/warn-local-file-access
Output warning if detected blocking local resources while rendering by Chrome
- Loading branch information
Showing
11 changed files
with
113 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
const { enterTestMode } = require('carlo') | ||
|
||
enterTestMode() | ||
|
||
jest.mock('wrap-ansi') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,42 @@ | ||
import chalk from 'chalk' | ||
import stripAnsi from 'strip-ansi' | ||
import wrapAnsi from 'wrap-ansi' | ||
import { terminalWidth } from 'yargs' | ||
|
||
interface CLIOption { | ||
singleLine?: boolean | ||
} | ||
|
||
const width: number = terminalWidth() || 80 | ||
|
||
const messageBlock = ( | ||
kind: string, | ||
message: string, | ||
opts: CLIOption | ||
): string => { | ||
const indent = stripAnsi(kind).length + 1 | ||
const target = opts.singleLine ? message : wrapAnsi(message, width - indent) | ||
|
||
return `${kind} ${target.split('\n').join(`\n${' '.repeat(indent)}`)}` | ||
} | ||
|
||
let silent = false | ||
|
||
export function silence(value: boolean) { | ||
silent = value | ||
} | ||
|
||
export function info(message: string): void { | ||
export function info(message: string, opts: CLIOption = {}): void { | ||
// Use console.warn to output into stderr | ||
if (!silent) console.warn(`${chalk.bgCyan.black('[ INFO ]')} ${message}`) | ||
if (!silent) | ||
console.warn(messageBlock(chalk.bgCyan.black('[ INFO ]'), message, opts)) | ||
} | ||
|
||
export function warn(message: string): void { | ||
if (!silent) console.warn(`${chalk.bgYellow.black('[ WARN ]')} ${message}`) | ||
export function warn(message: string, opts: CLIOption = {}): void { | ||
if (!silent) | ||
console.warn(messageBlock(chalk.bgYellow.black('[ WARN ]'), message, opts)) | ||
} | ||
|
||
export function error(message: string): void { | ||
console.error(`${chalk.bgRed.white('[ ERROR ]')} ${message}`) | ||
export function error(message: string, opts: CLIOption = {}): void { | ||
console.error(messageBlock(chalk.bgRed.white('[ ERROR ]'), message, opts)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
module.exports = jest.fn().mockImplementation(m => m) // No ops |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters