-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
be4e50c
commit a7084d6
Showing
12 changed files
with
167 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
environment: | ||
matrix: | ||
- nodejs_version: 4.0.0 | ||
- nodejs_version: 4 | ||
|
||
version: "{build}" | ||
build: off | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
node_modules | ||
index.bundle.js | ||
package-lock.json | ||
*.log* | ||
*.result.css | ||
.* | ||
!.appveyor.yml | ||
!.editorconfig | ||
!.gitignore | ||
!.rollup.js | ||
!.tape.js | ||
!.travis.yml | ||
*.log* | ||
*.result.css | ||
index.js |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import babel from 'rollup-plugin-babel'; | ||
|
||
export default { | ||
input: 'index.js', | ||
output: { file: 'index.bundle.js', format: 'cjs' }, | ||
plugins: [ | ||
babel({ | ||
presets: [ | ||
['env', { modules: false, targets: { node: 4 } }] | ||
] | ||
}) | ||
] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
language: node_js | ||
|
||
node_js: | ||
- 4.0.0 | ||
- 4 | ||
|
||
install: | ||
- npm install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// tooling | ||
import { SourceMapConsumer, SourceMapGenerator } from 'source-map'; | ||
|
||
// special sass source matcher | ||
const sassMatch = /#sass$/; | ||
|
||
// returns merged source maps | ||
export default function (...maps) { | ||
// new sourcemap | ||
const generator = new SourceMapGenerator(); | ||
|
||
// existing sourcemaps | ||
const consumers = maps.map( | ||
map => new SourceMapConsumer(map) | ||
); | ||
|
||
consumers.forEach( | ||
consumer => { | ||
// copy each original mapping to the new sourcemap | ||
consumer.eachMapping( | ||
mapping => { | ||
const originalPosition = originalPositionFor(mapping, consumers); | ||
|
||
if (originalPosition.source) { | ||
generator.addMapping({ | ||
generated: { | ||
line: mapping.generatedLine, | ||
column: mapping.generatedColumn | ||
}, | ||
original: { | ||
// use positive numbers to work around sass/libsass#2312 | ||
line: Math.abs(originalPosition.line), | ||
column: Math.abs(originalPosition.column) | ||
}, | ||
source: originalPosition.source, | ||
name: originalPosition.name | ||
}); | ||
} | ||
} | ||
); | ||
|
||
// copy each original source to the new sourcemap | ||
consumer.sources.forEach( | ||
source => { | ||
generator._sources.add(source); | ||
|
||
const content = consumer.sourceContentFor(source); | ||
|
||
if (content !== null) { | ||
generator.setSourceContent(source, content); | ||
} | ||
} | ||
); | ||
} | ||
); | ||
|
||
// merged map as json | ||
const mergedMap = JSON.parse(generator); | ||
|
||
// clean all special sass sources in merged map | ||
mergedMap.sources = mergedMap.sources.map( | ||
source => source.replace(sassMatch, '') | ||
); | ||
|
||
return mergedMap; | ||
} | ||
|
||
function originalPositionFor(mapping, consumers) { | ||
// initial positioning | ||
let originalPosition = { | ||
line: mapping.generatedLine, | ||
column: mapping.generatedColumn | ||
}; | ||
|
||
// special sass sources are mapped in reverse | ||
consumers.slice(0).reverse().forEach( | ||
consumer => { | ||
const possiblePosition = consumer.originalPositionFor(originalPosition); | ||
|
||
if (possiblePosition.source) { | ||
if (sassMatch.test(possiblePosition.source)) { | ||
originalPosition = possiblePosition; | ||
} | ||
} | ||
} | ||
); | ||
|
||
// regular sources are mapped regularly | ||
consumers.forEach( | ||
consumer => { | ||
const possiblePosition = consumer.originalPositionFor(originalPosition); | ||
|
||
if (possiblePosition.source) { | ||
if (!sassMatch.test(possiblePosition.source)) { | ||
originalPosition = possiblePosition; | ||
} | ||
} | ||
} | ||
); | ||
|
||
return originalPosition; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,68 @@ | ||
{ | ||
"name": "@csstools/postcss-sass", | ||
"version": "1.0.0", | ||
"version": "2.0.0", | ||
"description": "Use Sass as a PostCSS plugin", | ||
"author": "Jonathan Neal <jonathantneal@hotmail.com>", | ||
"license": "CC0-1.0", | ||
"repository": "jonathantneal/postcss-sass", | ||
"homepage": "https://github.com/jonathantneal/postcss-sass#readme", | ||
"bugs": "https://github.com/jonathantneal/postcss-sass/issues", | ||
"main": "index.js", | ||
"module": "index.mjs", | ||
"main": "index.bundle.js", | ||
"module": "index.js", | ||
"files": [ | ||
"index.mjs", | ||
"index.js" | ||
"index.js", | ||
"index.bundle.js", | ||
"lib" | ||
], | ||
"scripts": { | ||
"clean": "git clean -X -d -f", | ||
"prepublishOnly": "npm test", | ||
"pretest": "babel index.mjs --presets=env --plugins=add-module-exports --out-file index.js", | ||
"test": "echo 'Running tests...'; npm run test:js && npm run test:tape", | ||
"test:ec": "echint --ignore index.js *.expect.css *.result.css", | ||
"test:js": "eslint *.mjs --cache --ignore-pattern .gitignore", | ||
"pretest": "rollup --silent -c .rollup.js", | ||
"test": "echo 'Running tests...'; npm run test:ec && npm run test:js && npm run test:tape", | ||
"test:ec": "echint --ignore index.bundle.js test", | ||
"test:js": "eslint index.js --cache", | ||
"test:tape": "postcss-tape" | ||
}, | ||
"engines": { | ||
"node": ">=4.0.0" | ||
}, | ||
"dependencies": { | ||
"@csstools/sass-import-resolve": "^1.0.0", | ||
"merge-source-map": "^1.0.4", | ||
"node-sass": "^4.7.2", | ||
"postcss": "^6.0.14" | ||
"@csstools/sass-import-resolve": "^1.0", | ||
"node-sass": "^4.7", | ||
"postcss": "^6.0", | ||
"source-map": "^0.6" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.26", | ||
"babel-plugin-add-module-exports": "^0.2", | ||
"babel-core": "^6.26", | ||
"babel-eslint": "^8.1", | ||
"babel-preset-env": "^1.6", | ||
"echint": "^4.0", | ||
"eslint": "^4.12", | ||
"eslint": "^4.14", | ||
"eslint-config-dev": "2.0", | ||
"postcss-import": "^11.0", | ||
"postcss-tape": "2.2", | ||
"postcss-unroot": "^1.0", | ||
"pre-commit": "^1.2" | ||
"pre-commit": "^1.2", | ||
"rollup": "^0.53", | ||
"rollup-plugin-babel": "^3.0" | ||
}, | ||
"eslintConfig": { | ||
"extends": "dev" | ||
"extends": "dev", | ||
"parser": "babel-eslint" | ||
}, | ||
"keywords": [ | ||
"postcss", | ||
"css", | ||
"postcss-plugin", | ||
"sass", | ||
"node", | ||
"lib", | ||
"libsass", | ||
"node-sass", | ||
"preprocessor", | ||
"scss", | ||
"css", | ||
"style" | ||
"style", | ||
"extension" | ||
] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.