Skip to content

Commit

Permalink
Merge pull request #242 from realrunner/bug/sourcemap-fixes-squashed
Browse files Browse the repository at this point in the history
fix(dev): Preserve source maps in transformations
  • Loading branch information
ShafSpecs authored Jul 20, 2024
2 parents 2f94e3c + 141e7ef commit c6990c7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
7 changes: 7 additions & 0 deletions packages/client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## @remix-pwa/client 3.0.5 (2024-05-29)


### Bug Fixes

* **client:** added callback feature to installation prompt b17500a

## @remix-pwa/client 3.0.5-dev.1 (2024-05-29)


Expand Down
2 changes: 1 addition & 1 deletion packages/client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@remix-pwa/client",
"version": "3.0.5-dev.1",
"version": "3.0.5",
"description": "A set of utilities for client-side development to enhance the native feel of your Remix App",
"repository": {
"type": "git",
Expand Down
4 changes: 2 additions & 2 deletions packages/dev/src/plugins/__test__/loader-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('Remix PWA Vite Loader Plugin', () => {

const transformed = plugin.transform(code, id);

expect(transformed).toBe(code);
expect(transformed).toBe(undefined);
});

test('should not transform target code when id does not match', () => {
Expand All @@ -80,7 +80,7 @@ describe('Remix PWA Vite Loader Plugin', () => {

const transformed = plugin.transform(code, id);

expect(transformed).toBe(code);
expect(transformed).toBe(undefined);
});
});

Expand Down
6 changes: 4 additions & 2 deletions packages/dev/src/plugins/__test__/virtual-sw-plugin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,15 +308,17 @@ describe('Remix PWA Vite VirtualSW Plugin', () => {
* This is a license comment
*/
const a = 1;`;
expect((await plugin[0].transform(code)).trim()).toBe('const a = 1;');
const result = await plugin[0].transform(code);
expect(result.code.trim()).toBe('const a = 1;');
expect(result.map).toEqual({ mappings: '' });

const code2 = `
/**
* @license MIT
* This is a license comment
*/
const a = 1;`;
expect((await plugin[0].transform(code2)).trimStart()).toBe(`/**
expect((await plugin[0].transform(code2)).code.trimStart()).toBe(`/**
* @license MIT
* This is a license comment
*/
Expand Down
2 changes: 0 additions & 2 deletions packages/dev/src/plugins/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ export function LoaderPlugin(ctx: PWAPluginContext): Plugin {
.join('\n')
.trim()
);
} else {
return code;
}
},
};
Expand Down
6 changes: 5 additions & 1 deletion packages/dev/src/plugins/virtual-sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,14 @@ export function VirtualSWPlugins(ctx: PWAPluginContext): Plugin[] {
const regex = /\/\*\*[\s\S]*?\*\//g;

const licenseComments = code.match(regex)?.filter(predicate => /@license/.test(predicate)) ?? [];
return code.replaceAll(regex, match => {
code = code.replaceAll(regex, match => {
if (licenseComments?.includes(match)) return match;
return '';
});
return {
code,
map: { mappings: '' },
};
},
},
{
Expand Down

0 comments on commit c6990c7

Please sign in to comment.