Skip to content
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

Scss modules #135

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ root = true
[*]
indent_style = space
charset = utf-8
indent_size = 4
trim_trailing_whitespace = true
insert_final_newline = true
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"comma-dangle": "off",
"generator-star-spacing": "off",
"no-return-assign": "off",
"indent": ["error", 4],
"no-trailing-spaces": [
"error",
{
Expand Down
1 change: 0 additions & 1 deletion .npm/plugin/mss/.gitignore

This file was deleted.

7 changes: 0 additions & 7 deletions .npm/plugin/mss/README

This file was deleted.

2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [2.1.3] - 2016-07-26
### Fixed
- Updated to nathantreid:[email protected] to fix issues with importing files from Atmosphere packages
- Updated to wolasss:[email protected] to fix issues with importing files from Atmosphere packages

## [2.1.2] - 2016-07-26
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
The MIT License (MIT)
Copyright © 2017 Nathan Reid
Copyright © 2022 Adam Wolski

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Or, as stated on the main CSS modules page:
Install using Meteor's package management system:

```bash
meteor add nathantreid:css-modules
meteor add wolasss:css-modules
```

By default, this plugin will handle .css files as well as .m.css and .mss files (legacy). This can be adjusted in the [package options](https://github.com/nathantreid/meteor-css-modules/wiki/Package-Options).
Expand Down
44 changes: 0 additions & 44 deletions check-npm-package.js

This file was deleted.

58 changes: 0 additions & 58 deletions check-npm-package.tests.js

This file was deleted.

56 changes: 24 additions & 32 deletions css-modules-build-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@ import { Babel } from 'meteor/babel-compiler';

import recursiveUnwrapped from 'recursive-readdir';
import ScssProcessor from './scss-processor';
import LessProcessor from './less-processor';
import StylusProcessor from './stylus-processor';
import CssModulesProcessor from './css-modules-processor';
import IncludedFile from './included-file';
import pluginOptionsWrapper, { reloadOptions } from './options';
import getOutputPath from './get-output-path';
import profile from './helpers/profile';
import ImportPathHelpers from './helpers/import-path-helpers';
import { stripIndent, stripIndents } from 'common-tags';

if (process.platform !== 'darwin' || process.arch !== 'arm64') {
return;
}

let pluginOptions = pluginOptionsWrapper.options;
const recursive = Meteor.wrapAsync(recursiveUnwrapped);
Expand All @@ -39,7 +40,7 @@ class FileMap extends Map {
export default class CssModulesBuildPlugin extends MultiFileCachingCompiler {
constructor() {
super({
compilerName: 'mss',
compilerName: 'scss-compiler',
defaultCacheSize: 1024 * 1024 * 10
});
this.profilingResults = {
Expand Down Expand Up @@ -73,7 +74,11 @@ export default class CssModulesBuildPlugin extends MultiFileCachingCompiler {
files = removeFilesFromExcludedFolders(files);
files = addFilesFromIncludedFolders(files);

this._setupPreprocessors();
const scssProcessor = new ScssProcessor(pluginOptions);
await scssProcessor.init();

this.preprocessors = [];
this.preprocessors.push(scssProcessor);
this.cssModulesProcessor = new CssModulesProcessor(pluginOptions, this);

await super.processFilesForTarget(files);
Expand Down Expand Up @@ -121,19 +126,6 @@ export default class CssModulesBuildPlugin extends MultiFileCachingCompiler {
});
}

_setupPreprocessors() {
this.preprocessors = [];
if (pluginOptions.enableSassCompilation) {
this.preprocessors.push(new ScssProcessor(pluginOptions));
}
if (pluginOptions.enableStylusCompilation) {
this.preprocessors.push(new StylusProcessor(pluginOptions));
}
if (pluginOptions.enableLessCompilation) {
this.preprocessors.push(new LessProcessor(pluginOptions));
}
}

isRoot(inputFile) {
if ('isRoot' in inputFile) {
return inputFile.isRoot;
Expand All @@ -156,20 +148,20 @@ export default class CssModulesBuildPlugin extends MultiFileCachingCompiler {
return inputFile.isRoot;
}

compileOneFile(inputFile) {
async compileOneFile(inputFile) {
const filesByName = this.filesByName;

this._prepInputFile(inputFile);
this._preprocessFile(inputFile, filesByName);
await this._preprocessFile(inputFile, filesByName);
if (inputFile.transpileCssModules !== false) {
this._transpileCssModulesToCss(inputFile, filesByName).await();
await this._transpileCssModulesToCss(inputFile, filesByName);
}

const compileResult = this._generateOutput(inputFile);
return { compileResult, referencedImportPaths: inputFile.referencedImportPaths };
}

compileFromSource(source, backingInputFile, { transpileCssModules = true } = {}) {
async compileFromSource(source, backingInputFile, { transpileCssModules = true } = {}) {
pluginOptions = this.reloadOptions();
if (!pluginOptions.cache.enableCache) {
this._cache.reset();
Expand All @@ -186,7 +178,7 @@ export default class CssModulesBuildPlugin extends MultiFileCachingCompiler {
const inputFile = this._createIncludedFile(backingInputFile.getPathInPackage(), backingInputFile, source);

inputFile.transpileCssModules = transpileCssModules;
return this.compileOneFile(inputFile, this.filesByName);
return await this.compileOneFile(inputFile, this.filesByName);
}

_createIncludedFile(importPath, rootFile, contents) {
Expand Down Expand Up @@ -234,7 +226,7 @@ export default class CssModulesBuildPlugin extends MultiFileCachingCompiler {

const shouldAddStylesheet = inputFile.getArch().indexOf('web') === 0;
compileResult.stylesheetCode = (isLazy && shouldAddStylesheet && inputFile.contents)
? tryBabelCompile(stripIndent`
? tryBabelCompile(`
import modules from 'meteor/modules';
modules.addStyles(${JSON.stringify(inputFile.contents)});`)
: '';
Expand All @@ -243,7 +235,7 @@ export default class CssModulesBuildPlugin extends MultiFileCachingCompiler {
const isLegacy = inputFile.getArch() === 'web.browser.legacy';
compileResult.stylesCode = inputFile.tokens ? addMissingStylesHandler(JSON.stringify(inputFile.tokens), filePath, isLegacy) : '';
compileResult.tokensCode = inputFile.tokens
? tryBabelCompile(stripIndent`
? tryBabelCompile(`
const styles = ${compileResult.stylesCode};
export { styles as default, styles };
exports.__esModule = true;`, diskCache)
Expand All @@ -268,12 +260,12 @@ export default class CssModulesBuildPlugin extends MultiFileCachingCompiler {
function addMissingStylesHandler(stylesJson, filePath, isLegacy) {
if (!isLegacy && pluginOptions.missingClassErrorLevel) {
const logFunction = `console.${pluginOptions.missingClassErrorLevel}`;
return `new Proxy(${stylesJson}, {
return `new Proxy(${stylesJson}, {
get: function(target, name) {
if (typeof name === 'symbol') {
return;
}

var ignoredProperties = [
'toJSON',
'state',
Expand All @@ -283,8 +275,8 @@ export default class CssModulesBuildPlugin extends MultiFileCachingCompiler {
Symbol.toStringTag,
${(pluginOptions.missingClassIgnoreList).map(JSON.stringify).join(',')}
];
return name in target

return name in target
? target[name]
: ignoredProperties.indexOf(name) === -1
? ${logFunction}(name, ': CSS module class not found in ${filePath}')
Expand Down Expand Up @@ -312,9 +304,9 @@ export default class CssModulesBuildPlugin extends MultiFileCachingCompiler {
file.isPrepped = true;
}

_preprocessFile(inputFile, filesByName) {
async _preprocessFile(inputFile, filesByName) {
if (inputFile.preprocessor) {
inputFile.preprocessor.process(inputFile, filesByName);
await inputFile.preprocessor.process(inputFile, filesByName);
}
}

Expand All @@ -340,7 +332,7 @@ export default class CssModulesBuildPlugin extends MultiFileCachingCompiler {
}

const js = (result.importsCode || result.stylesheetCode || result.tokensCode)
? stripIndents`
? `
${result.importsCode}
${isWebArchitecture ? result.stylesheetCode : ''}
${result.tokensCode}`
Expand Down
Loading