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

vite/rollup: Return empty sourcemaps #706

Merged
merged 4 commits into from
Jun 3, 2022
Merged
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
6 changes: 6 additions & 0 deletions .changeset/rich-bobcats-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@vanilla-extract/rollup-plugin': patch
'@vanilla-extract/vite-plugin': patch
---

Suppress empty sourcemap warnings
12 changes: 10 additions & 2 deletions packages/rollup-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,15 @@ export function vanillaExtractPlugin({
this.addWatchFile(file);
}

return processVanillaFile({
const output = await processVanillaFile({
source,
filePath,
identOption: identifiers ?? (isProduction ? 'short' : 'debug'),
});
return {
code: output,
map: { mappings: '' },
};
},
async resolveId(id) {
if (!virtualCssFileFilter.test(id)) {
Expand Down Expand Up @@ -81,14 +85,18 @@ export function vanillaExtractPlugin({

// ...replace import paths with relative paths to emitted css files
const chunkPath = dirname(chunkInfo.fileName);
return importsToReplace.reduce((codeResult, importPath) => {
const output = importsToReplace.reduce((codeResult, importPath) => {
const assetId = emittedFiles.get(importPath)!;
const assetName = this.getFileName(assetId);
const fixedImportPath = `./${normalize(
relative(chunkPath, assetName),
)}`;
return codeResult.replace(importPath, fixedImportPath);
}, code);
return {
code: output,
map: chunkInfo.map ?? null,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is null handled differently than undefined?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes it seems so. When I tested it chunkInfo.map actually was undefined and still resulted in the same warning. But with null it is suppressed.

};
},
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -494,6 +494,43 @@ export { altTheme, responsiveTheme, theme, vars };
]
`;

exports[`rollup-plugin should build with sourcemaps 1`] = `
Array [
Array [
"assets/src/shared.css.ts.vanilla-31027048.css",
"",
],
Array [
"assets/src/styles.css.ts.vanilla-eb3ed277.css",
"",
],
Array [
"assets/src/themes.css.ts.vanilla-9cd4611f.css",
"",
],
Array [
"src/index.js",
";;;;;;AAKA,MAAM,WAAW,GAAG,gBAAgB,CAAC,IAAI,EAAE;AAC3C,EAAE,MAAM,EAAE;AACV,IAAI,eAAe,EAAE,QAAQ;AAC7B,IAAI,IAAI,EAAE,OAAO;AACjB,GAAG;AACH,EAAE,KAAK,EAAE;AACT,IAAI,CAAC,EAAE,KAAK;AACZ,IAAI,CAAC,EAAE,KAAK;AACZ,IAAI,CAAC,EAAE,MAAM;AACb,GAAG;AACH,CAAC,CAAC,CAAC;AACH,SAAS,MAAM,GAAG;AAClB,EAAE,QAAQ,CAAC,IAAI,CAAC,SAAS,GAAG,CAAC;AAC7B,WAAW,EAAE,SAAS,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC;AAC9C;AACA,aAAa,EAAE,SAAS,CAAC,aAAa,CAAC,SAAS,EAAE,SAAS,CAAC;AAC5D,kBAAkB,EAAE,SAAS,CAAC,UAAU,CAAC,SAAS,EAAE,MAAM,CAAC;AAC3D,kBAAkB,EAAE,QAAQ,CAAC;AAC7B;AACA,iBAAiB,EAAE,SAAS,CAAC,YAAY,CAAC,SAAS,EAAE,SAAS,CAAC;AAC/D,sBAAsB,EAAE,SAAS,CAAC,SAAS,CAAC,SAAS,EAAE,MAAM,CAAC;AAC9D,sBAAsB,EAAE,KAAK,CAAC;AAC9B;AACA,qBAAqB,EAAE,SAAS,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC;AAC1E,0BAA0B,EAAE,SAAS,CAAC,gBAAgB,CAAC,SAAS,EAAE,MAAM,CAAC;AACzE,wBAAwB,EA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AACL,CAAC;AACD,MAAM,EAAE",
],
Array [
"src/shared.css.js",
";;;;;;",
],
Array [
"src/styles.css.js",
";;;;;;;;;;",
],
Array [
"src/themes.css.js",
";;;;;;;;;",
],
Array [
"test-nodes.json.js",
";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;",
],
]
`;

exports[`rollup-plugin should build without preserveModules 1`] = `
Array [
Array [
Expand Down
24 changes: 20 additions & 4 deletions packages/rollup-plugin/test/rollup-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import path from 'path';

import { vanillaExtractPlugin } from '..';

async function buildAndMatchSnapshot(outputOptions: OutputOptions) {
async function build(outputOptions: OutputOptions) {
const bundle = await rollup({
input: require.resolve('@fixtures/themed'),
plugins: [
Expand All @@ -19,15 +19,17 @@ async function buildAndMatchSnapshot(outputOptions: OutputOptions) {
});
const { output } = await bundle.generate(outputOptions);
output.sort((a, b) => a.fileName.localeCompare(b.fileName));
return output;
}

async function buildAndMatchSnapshot(outputOptions: OutputOptions) {
const output = await build(outputOptions);
expect(
output.map((chunkOrAsset) => [
chunkOrAsset.fileName,
chunkOrAsset.type === 'asset' ? chunkOrAsset.source : chunkOrAsset.code,
]),
).toMatchSnapshot();
if (bundle) {
await bundle.close();
}
}

describe('rollup-plugin', () => {
Expand Down Expand Up @@ -57,4 +59,18 @@ describe('rollup-plugin', () => {
},
});
});

it('should build with sourcemaps', async () => {
const output = await build({
format: 'esm',
preserveModules: true,
sourcemap: true,
});
expect(
output.map((chunkOrAsset) => [
chunkOrAsset.fileName,
chunkOrAsset.type === 'asset' ? '' : chunkOrAsset.map?.mappings,
]),
).toMatchSnapshot();
});
});
7 changes: 6 additions & 1 deletion packages/vite-plugin/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ export function vanillaExtractPlugin({ identifiers }: Options = {}): Plugin {
}
}

return processVanillaFile({
const output = await processVanillaFile({
source,
filePath: validId,
identOption:
Expand Down Expand Up @@ -182,6 +182,11 @@ export function vanillaExtractPlugin({ identifiers }: Options = {}): Plugin {
return `import "${id}";`;
},
});

return {
code: output,
map: { mappings: '' },
};
},
};
}