Skip to content

the new API #59

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
resolving filename inside promise in order to handle errors propely
  • Loading branch information
mightyaleksey committed Nov 23, 2015
commit da9603e25da2d841ec1cf0c7019e55e4a3bb5b8b
19 changes: 10 additions & 9 deletions src/file-system-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,18 @@ export default class FileSystemLoader {
}

fetch( _to, from ) {
let to = _to.replace( /^["']|["']$/g, '' ),
trace = String.fromCharCode( this.importNr++ )
let to = _to.replace( /^["']|["']$/g, '' )

const filename = /\w/i.test(to[0])
? require.resolve(to)
: resolve(dirname(from), to)
return new Promise(( _resolve, _reject ) => {
const filename = /\w/i.test(to[0])
? require.resolve(to)
: resolve(dirname(from), to)

const trace = String.fromCharCode( this.importNr++ )

return new Promise(( resolve, reject ) => {
readFile( filename, 'utf8', (err, source) => {
if (err) {
return void reject(err);
return void _reject(err);
}

this.core.process( source, Object.assign( this.processorOptions, { from: filename } ) )
Expand All @@ -50,9 +51,9 @@ export default class FileSystemLoader {
// https://github.com/postcss/postcss/blob/master/docs/api.md#lazywarnings
result.warnings().forEach(message => console.warn(message.text));

resolve( this.tokensByFile[filename] )
_resolve( this.tokensByFile[filename] )
} )
.catch( reject )
.catch( _reject )
} )
})
}
Expand Down