Skip to content

Added option EOL which add feature to change EOL for css.d.ts files #4

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

Merged
merged 1 commit into from
Aug 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ These can be accessed using the object literal syntax; eg styles['delete'] inste
// Prefix banner to CSS module
cssModuleDefinition = query.banner + '\n' + cssModuleDefinition;
}
persist.writeToFileIfChanged(cssModuleInterfaceFilename, cssModuleDefinition);
persist.writeToFileIfChanged(cssModuleInterfaceFilename, cssModuleDefinition, query);
// mock async step 3 - make `async` return the actual callback again before calling the 'real' css-loader
delegateToCssLoader(this, input, callback);
};
Expand Down
10 changes: 5 additions & 5 deletions src/persist.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import fs from 'graceful-fs';
import os from 'os';

export const writeToFileIfChanged = (filename, content) => {
export const writeToFileIfChanged = (filename, content, options) => {
if (fs.existsSync(filename)) {
const currentInput = fs.readFileSync(filename, 'utf-8');

if (currentInput !== content) {
writeFile(filename, content);
writeFile(filename, content, options);
}
} else {
writeFile(filename, content);
writeFile(filename, content, options);
}
};

const writeFile = (filename, content) => {
const writeFile = (filename, content, options) => {
//Replace new lines with OS-specific new lines
content = content.replace(/\n/g, os.EOL);
content = content.replace(/\n/g, options.EOL || os.EOL);

fs.writeFileSync(filename, content, 'utf8');
};