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

Chore: Modernize Dependencies #236

Closed
wants to merge 6 commits into from
Closed
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
14 changes: 14 additions & 0 deletions .babelrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"presets": [
[
"@babel/preset-env", {
"loose": true,
"modules": "commonjs",
"targets": {
"node": "6"
}
}
]
],
"plugins": ["add-module-exports"]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was needed because Babel 6 (and thus 7) no longer transform to module.exports by default. So in order to maintain current API this plugin was needed.

}
38 changes: 20 additions & 18 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
{
"parser": "babel-eslint",
"env": {
"node": true
},
"ecmaFeatures": {
"arrowFunctions": true,
"blockBindings": true,
"classes": true,
"defaultParams": true,
"destructuring": true,
"forOf": true,
"modules": true,
"objectLiteralComputedProperties": true,
"objectLiteralShorthandMethods": true,
"objectLiteralShorthandProperties": true,
"spread": true,
"superInFunctions": true,
"templateStrings": true,
"unicodeCodePointEscapes": true,
"jsx": true
"parser": "babel-eslint",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only structure/formatting changes in this file. ESLint threw errors with the old config.

"parserOptions": {
"ecmaFeatures": {
"arrowFunctions": true,
"blockBindings": true,
"classes": true,
"defaultParams": true,
"destructuring": true,
"forOf": true,
"modules": true,
"objectLiteralComputedProperties": true,
"objectLiteralShorthandMethods": true,
"objectLiteralShorthandProperties": true,
"spread": true,
"superInFunctions": true,
"templateStrings": true,
"unicodeCodePointEscapes": true,
"jsx": true
}
},
"rules": {
"quotes": "single"
"quotes": [2, "single"]
}
}
33 changes: 18 additions & 15 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,30 @@
"test": "test"
},
"dependencies": {
"icss-replace-symbols": "1.1.0",
"postcss": "6.0.1",
"postcss-modules-extract-imports": "1.1.0",
"postcss-modules-local-by-default": "1.2.0",
"postcss-modules-scope": "1.1.0",
"postcss-modules-values": "1.3.0"
"icss-replace-symbols": "^1.1.0",
"postcss": "^7.0.32",
"postcss-modules-extract-imports": "^2.0.0",
"postcss-modules-local-by-default": "^3.0.2",
"postcss-modules-scope": "^2.2.0",
"postcss-modules-values": "^3.0.0"
},
"devDependencies": {
"babel": "5.8.29",
"babel-eslint": "7.1.0",
"babelify": "7.3.0",
"chokidar-cli": "1.1.0",
"eslint": "3.10.1",
"mocha": "3.1.2"
"@babel/cli": "7.10.3",
"@babel/core": "7.10.3",
"@babel/preset-env": "7.10.3",
"@babel/register": "7.10.3",
"babel-eslint": "10.1.0",
"babel-plugin-add-module-exports": "1.0.2",
"chokidar-cli": "2.1.0",
"eslint": "7.3.0",
"mocha": "8.0.1"
},
"scripts": {
"lint": "eslint src",
"lint": "eslint src test",
"build": "babel --out-dir lib src",
"autotest": "chokidar src test -c 'npm test'",
"test": "mocha --compilers js:babel/register",
"prepublish": "rm -rf lib/* && npm run build"
"test": "mocha -r @babel/register",
"prepublishOnly": "rm -rf lib/* && npm run build"
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "prepublish" hook is deprecated

},
"repository": {
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions src/file-system-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export default class FileSystemLoader {
}

fetch( _newPath, relativeTo, _trace ) {
let newPath = _newPath.replace( /^["']|["']$/g, "" ),
let newPath = _newPath.replace( /^["']|["']$/g, '' ),
trace = _trace || String.fromCharCode( this.importNr++ )
return new Promise( ( resolve, reject ) => {
let relativeDir = path.dirname( relativeTo ),
Expand All @@ -48,7 +48,7 @@ export default class FileSystemLoader {
const tokens = this.tokensByFile[fileRelativePath]
if (tokens) { return resolve(tokens) }

fs.readFile( fileRelativePath, "utf-8", ( err, source ) => {
fs.readFile( fileRelativePath, 'utf-8', ( err, source ) => {
if ( err ) reject( err )
this.core.load( source, rootRelativePath, trace, this.fetch.bind( this ) )
.then( ( { injectableSource, exportTokens } ) => {
Expand All @@ -72,6 +72,6 @@ export default class FileSystemLoader {
written.add(filename)

return sources[filename];
}).join( "" )
}).join( '' )
}
}
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default class Core {
let parser = new Parser( pathFetcher, trace )

return postcss( this.plugins.concat( [parser.plugin] ) )
.process( sourceString, { from: "/" + sourcePath } )
.process( sourceString, { from: '/' + sourcePath } )
.then( result => {
return { injectableSource: result.css, exportTokens: parser.exportTokens }
} )
Expand Down
4 changes: 2 additions & 2 deletions src/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default class Parser {
fetchAllImports( css ) {
let imports = []
css.each( node => {
if ( node.type == "rule" && node.selector.match( importRegexp ) ) {
if ( node.type == 'rule' && node.selector.match( importRegexp ) ) {
imports.push( this.fetchImport( node, css.source.input.from, imports.length ) )
}
} )
Expand All @@ -32,7 +32,7 @@ export default class Parser {

extractExports( css ) {
css.each( node => {
if ( node.type == "rule" && node.selector == ":export" ) this.handleExport( node )
if ( node.type == 'rule' && node.selector == ':export' ) this.handleExport( node )
} )
}

Expand Down
38 changes: 19 additions & 19 deletions test/test-cases.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
"use strict";
'use strict';

import assert from "assert"
import fs from "fs"
import path from "path"
import FileSystemLoader from "../src/file-system-loader"
import assert from 'assert'
import fs from 'fs'
import path from 'path'
import FileSystemLoader from '../src/file-system-loader'

let normalize = ( str ) => {
return str.replace( /\r\n?/g, "\n" );
return str.replace( /\r\n?/g, '\n' );
}

const pipelines = {
"test-cases": undefined,
"cssi": []
'test-cases': undefined,
'cssi': []
}

Object.keys( pipelines ).forEach( dirname => {
describe( dirname, () => {
let testDir = path.join( __dirname, dirname )
fs.readdirSync( testDir ).forEach( testCase => {
if ( fs.existsSync( path.join( testDir, testCase, "source.css" ) ) ) {
it( "should " + testCase.replace( /-/g, " " ), done => {
let expected = normalize( fs.readFileSync( path.join( testDir, testCase, "expected.css" ), "utf-8" ) )
if ( fs.existsSync( path.join( testDir, testCase, 'source.css' ) ) ) {
it( 'should ' + testCase.replace( /-/g, ' ' ), done => {
let expected = normalize( fs.readFileSync( path.join( testDir, testCase, 'expected.css' ), 'utf-8' ) )
let loader = new FileSystemLoader( testDir, pipelines[dirname] )
let expectedTokens = JSON.parse( fs.readFileSync( path.join( testDir, testCase, "expected.json" ), "utf-8" ) )
loader.fetch( `${testCase}/source.css`, "/" ).then( tokens => {
let expectedTokens = JSON.parse( fs.readFileSync( path.join( testDir, testCase, 'expected.json' ), 'utf-8' ) )
loader.fetch( `${testCase}/source.css`, '/' ).then( tokens => {
assert.equal( loader.finalSource, expected )
assert.equal( JSON.stringify( tokens ), JSON.stringify( expectedTokens ) )
} ).then( done, done )
Expand All @@ -38,13 +38,13 @@ describe( 'multiple sources', () => {
let testDir = path.join( __dirname, 'test-cases' )
let testCase = 'multiple-sources';
let dirname = 'test-cases';
if ( fs.existsSync( path.join( testDir, testCase, "source1.css" ) ) ) {
it( "should " + testCase.replace( /-/g, " " ), done => {
let expected = normalize( fs.readFileSync( path.join( testDir, testCase, "expected.css" ), "utf-8" ) )
if ( fs.existsSync( path.join( testDir, testCase, 'source1.css' ) ) ) {
it( 'should ' + testCase.replace( /-/g, ' ' ), done => {
let expected = normalize( fs.readFileSync( path.join( testDir, testCase, 'expected.css' ), 'utf-8' ) )
let loader = new FileSystemLoader( testDir, pipelines[dirname] )
let expectedTokens = JSON.parse( fs.readFileSync( path.join( testDir, testCase, "expected.json" ), "utf-8" ) )
loader.fetch( `${testCase}/source1.css`, "/" ).then( tokens1 => {
loader.fetch( `${testCase}/source2.css`, "/" ).then( tokens2 => {
let expectedTokens = JSON.parse( fs.readFileSync( path.join( testDir, testCase, 'expected.json' ), 'utf-8' ) )
loader.fetch( `${testCase}/source1.css`, '/' ).then( tokens1 => {
loader.fetch( `${testCase}/source2.css`, '/' ).then( tokens2 => {
assert.equal( loader.finalSource, expected )
const tokens = Object.assign({}, tokens1, tokens2);
assert.equal( JSON.stringify( tokens ), JSON.stringify( expectedTokens ) )
Expand Down
2 changes: 1 addition & 1 deletion test/test-cases/values/expected.css
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is all that changed given the new dependency set!

._values_borders__dashed {
border: 4px dashed;
}

._values_colors__text-primary {
color: #f01;
}
Expand Down