css-modules-typescript-loader
Advanced tools
Comparing version 1.1.0 to 1.1.1
81
index.js
@@ -20,3 +20,3 @@ const fs = require('fs'); | ||
); | ||
} | ||
}; | ||
@@ -39,4 +39,17 @@ const cssModuleToNamedExports = cssModuleKeys => { | ||
const isFileNotFound = err => err && err.code === 'ENOENT'; | ||
const makeDoneHandlers = (callback, content, rest) => ({ | ||
failed: e => callback(e), | ||
success: () => callback(null, content, ...rest) | ||
}); | ||
const makeFileHandlers = filename => ({ | ||
read: handler => fs.readFile(filename, { encoding: 'utf-8' }, handler), | ||
write: (content, handler) => | ||
fs.writeFile(filename, content, { encoding: 'utf-8' }, handler) | ||
}); | ||
module.exports = function(content, ...rest) { | ||
const callback = this.async(); | ||
const { failed, success } = makeDoneHandlers(this.async(), content, rest); | ||
@@ -50,2 +63,3 @@ const filename = this.resourcePath; | ||
const cssModuleInterfaceFilename = filenameToTypingsFilename(filename); | ||
const { read, write } = makeFileHandlers(cssModuleInterfaceFilename); | ||
@@ -67,41 +81,42 @@ const keyRegex = /"([^\\"]+)":/g; | ||
if (mode === 'verify') { | ||
fs.readFile( | ||
cssModuleInterfaceFilename, | ||
{ encoding: 'utf-8' }, | ||
(err, fileContents) => { | ||
if (err) { | ||
const error = | ||
err.code === 'ENOENT' | ||
? getNoDeclarationFileError({ | ||
filename: cssModuleInterfaceFilename | ||
}) | ||
: err; | ||
return callback(error); | ||
} | ||
read((err, fileContents) => { | ||
if (isFileNotFound(err)) { | ||
return failed( | ||
getNoDeclarationFileError({ | ||
filename: cssModuleInterfaceFilename | ||
}) | ||
); | ||
} | ||
if (cssModuleDefinition !== fileContents) { | ||
return callback(getTypeMismatchError({ | ||
if (err) { | ||
return failed(err); | ||
} | ||
if (cssModuleDefinition !== fileContents) { | ||
return failed( | ||
getTypeMismatchError({ | ||
filename: cssModuleInterfaceFilename, | ||
expected: cssModuleDefinition, | ||
actual: fileContents | ||
})); | ||
} | ||
}) | ||
); | ||
} | ||
return callback(null, content, ...rest); | ||
} | ||
); | ||
return success(); | ||
}); | ||
} else { | ||
fs.writeFile( | ||
cssModuleInterfaceFilename, | ||
cssModuleDefinition, | ||
{ encoding: 'utf-8' }, | ||
err => { | ||
if (err) { | ||
return callback(err); | ||
} else { | ||
return callback(null, content, ...rest); | ||
} | ||
read((_, fileContents) => { | ||
if (cssModuleDefinition !== fileContents) { | ||
write(cssModuleDefinition, err => { | ||
if (err) { | ||
failed(err); | ||
} else { | ||
success(); | ||
} | ||
}); | ||
} else { | ||
success(); | ||
} | ||
); | ||
}); | ||
} | ||
}; |
{ | ||
"name": "css-modules-typescript-loader", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "Webpack loader to create TypeScript declarations for CSS Modules", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
13300
230