Skip to content

test: contenthash should not changed on different operating systems #1074

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

Closed
wants to merge 11 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
68 changes: 68 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
"jest-junit": "^10.0.0",
"lint-staged": "^10.1.2",
"memfs": "^3.1.2",
"mini-css-extract-plugin": "^0.9.0",
"npm-run-all": "^4.1.5",
"postcss-loader": "^3.0.0",
"postcss-preset-env": "^6.7.0",
Expand Down
9 changes: 5 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
getImportCode,
getModuleCode,
getModulesPlugins,
normalizeSourceMap,
shouldUseModulesPlugins,
} from './utils';

Expand Down Expand Up @@ -83,11 +82,12 @@ export default function loader(content, map, meta) {
postcss(plugins)
.process(content, {
from: this.remainingRequest.split('!').pop(),
to: this.currentRequest.split('!').pop(),
// eslint-disable-next-line no-undefined
to: undefined,
map: options.sourceMap
? {
// Some loaders (example `"postcss-loader": "1.x.x"`) always generates source map, we should remove it
prev: sourceMap && map ? normalizeSourceMap(map) : null,
prev: sourceMap && map ? map : null,
inline: false,
annotation: false,
}
Expand Down Expand Up @@ -137,7 +137,8 @@ export default function loader(content, map, meta) {
apiImports,
urlReplacements,
icssReplacements,
esModule
esModule,
this
);
const exportCode = getExportCode(
exports,
Expand Down
18 changes: 8 additions & 10 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,19 +190,13 @@ function getModulesPlugins(options, loaderContext) {
}

function normalizeSourceMap(map) {
let newMap = map;

// Some loader emit source map as string
// Strip any JSON XSSI avoidance prefix from the string (as documented in the source maps specification), and then parse the string as JSON.
if (typeof newMap === 'string') {
newMap = JSON.parse(newMap);
}
const newMap = map.toJSON();

// Source maps should use forward slash because it is URLs (https://github.com/mozilla/source-map/issues/91)
// We should normalize path because previous loaders like `sass-loader` using backslash when generate source map

if (newMap.file) {
newMap.file = normalizePath(newMap.file);
delete newMap.file;
}

if (newMap.sourceRoot) {
Expand Down Expand Up @@ -274,14 +268,18 @@ function getModuleCode(
apiImports,
urlReplacements,
icssReplacements,
esModule
esModule,
loaderContext
) {
if (exportType !== 'full') {
return '';
}

const { css, map } = result;
const sourceMapValue = sourceMap && map ? `,${map}` : '';
const sourceMapValue =
sourceMap && map
? `,${JSON.stringify(normalizeSourceMap(map, loaderContext))}`
: '';

let code = JSON.stringify(css);
let beforeCode = '';
Expand Down
Loading