Skip to content

Commit

Permalink
Use a simplified hashing strategy when a file system is available (#498)
Browse files Browse the repository at this point in the history
avoiding the file contents when hashing helps alleviate some pains
that can occur if build environments make subtle changes, like running
a particular loader for an SSR build that changes unrelated code
  • Loading branch information
quantizor authored and emmatown committed Dec 21, 2017
1 parent 2f774e6 commit 301c724
Show file tree
Hide file tree
Showing 13 changed files with 150 additions and 101 deletions.
15 changes: 10 additions & 5 deletions packages/babel-plugin-emotion/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,17 @@ function buildTargetObjectProperty(path, state, t) {
filename === rootPath ? basename(filename) : filename.slice(rootPath.length)

const positionInFile = state.count++

const stuffToHash = [moduleName]

if (finalPath) {
stuffToHash.push(normalize(finalPath))
} else {
stuffToHash.push(state.file.code)
}

const stableClassName = getName(
`${hashArray([
normalize(finalPath),
moduleName,
state.file.code
])}${positionInFile}`,
`${hashArray(stuffToHash)}${positionInFile}`,
'css'
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,15 @@ exports[`styled macro babel 6 tagged template literal function 1`] = `
"import _styled from './styled';
const SomeComponent = /*#__PURE__*/_styled('div', {
target: 'css-gx73fp0'
target: 'css-o9rakq0'
})('display:flex;');"
`;
exports[`styled macro babel 6 tagged template literal member 1`] = `
"import _styled from './styled';
const SomeComponent = /*#__PURE__*/_styled('div', {
target: 'css-5a9af00'
target: 'css-o9rakq0'
})('display:flex;');"
`;
Expand Down Expand Up @@ -232,7 +232,7 @@ exports[`styled macro babel 7 tagged template literal function 1`] = `
const SomeComponent =
/*#__PURE__*/
_styled('div', {
target: \\"css-gx73fp0\\"
target: \\"css-o9rakq0\\"
})(\\"display:flex;\\");"
`;
Expand All @@ -242,6 +242,6 @@ exports[`styled macro babel 7 tagged template literal member 1`] = `
const SomeComponent =
/*#__PURE__*/
_styled(\\"div\\", {
target: \\"css-5a9af00\\"
target: \\"css-o9rakq0\\"
})(\\"display:flex;\\");"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ exports[`source map babel 6 styled object styles source map 1`] = `

exports[`source map babel 6 styled source map 1`] = `
"const Avatar = /*#__PURE__*/styled('img', {
target: 'css-1xslkpx0'
target: 'css-1367ks30'
})('width:96px;height:96px;border-radius:', props => props.theme.borderRadius, ';border:1px solid ', props => props.theme.borderColor, ';/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0eWxlZC5zb3VyY2UtbWFwLnRlc3QuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQTRCIiwiZmlsZSI6InN0eWxlZC5zb3VyY2UtbWFwLnRlc3QuanMiLCJzb3VyY2VzQ29udGVudCI6WyJjb25zdCBBdmF0YXIgPSBzdHlsZWQoJ2ltZycpYFxuICAgICAgICB3aWR0aDogOTZweDtcbiAgICAgICAgaGVpZ2h0OiA5NnB4O1xuXG4gICAgICAgIGJvcmRlci1yYWRpdXM6ICR7cHJvcHMgPT5cbiAgICAgICAgICBwcm9wcy50aGVtZS5ib3JkZXJSYWRpdXN9O1xuXG4gICAgICAgIGJvcmRlcjogMXB4IHNvbGlkICR7cHJvcHMgPT5cbiAgICAgICAgICBwcm9wcy50aGVtZS5ib3JkZXJDb2xvcn07XG4gICAgICBgIl19 */');"
`;

Expand Down Expand Up @@ -124,6 +124,6 @@ exports[`source map babel 7 styled source map 1`] = `
"const Avatar =
/*#__PURE__*/
styled('img', {
target: \\"css-1xslkpx0\\"
target: \\"css-1367ks30\\"
})(\\"width:96px;height:96px;border-radius:\\", props => props.theme.borderRadius, \\";border:1px solid \\", props => props.theme.borderColor, \\";/*# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbInN0eWxlZC5zb3VyY2UtbWFwLnRlc3QuanMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQTRCIiwiZmlsZSI6InN0eWxlZC5zb3VyY2UtbWFwLnRlc3QuanMiLCJzb3VyY2VzQ29udGVudCI6WyJjb25zdCBBdmF0YXIgPSBzdHlsZWQoJ2ltZycpYFxuICAgICAgICB3aWR0aDogOTZweDtcbiAgICAgICAgaGVpZ2h0OiA5NnB4O1xuXG4gICAgICAgIGJvcmRlci1yYWRpdXM6ICR7cHJvcHMgPT5cbiAgICAgICAgICBwcm9wcy50aGVtZS5ib3JkZXJSYWRpdXN9O1xuXG4gICAgICAgIGJvcmRlcjogMXB4IHNvbGlkICR7cHJvcHMgPT5cbiAgICAgICAgICBwcm9wcy50aGVtZS5ib3JkZXJDb2xvcn07XG4gICAgICBgIl19 */\\");"
`;
Loading

0 comments on commit 301c724

Please sign in to comment.