-
Notifications
You must be signed in to change notification settings - Fork 915
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow plugins that transform code to return source maps, and compose …
…them together. (#1048) * Allow plugins that transform code to return source maps, and compose them together. * Ensure map snapshots look the same no matter what directory we're running from. * Split out V2 and V1 result handling, and tighten up types.
- Loading branch information
Showing
11 changed files
with
121 additions
and
13 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
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
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,16 @@ | ||
const MagicString = require('magic-string'); | ||
|
||
module.exports = function () { | ||
return { | ||
transform: async ({id, fileExt, contents}) => { | ||
const ms = new MagicString(contents); | ||
ms.appendLeft(contents.indexOf('console.log'), `console.log('transformed');\n`); | ||
const map = ms.generateMap({source: id, hires: false, includeContent: true}); | ||
return { | ||
contents: ms.toString(), | ||
// Try returning both object and string map formats. | ||
map: fileExt === '.js' ? map : map.toString() | ||
} | ||
}, | ||
}; | ||
}; |
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,14 @@ | ||
{ | ||
"private": true, | ||
"version": "1.0.1", | ||
"name": "@snowpack/test-plugin-transform", | ||
"description": "A test to make sure that the plugin transform() hook is working as expected", | ||
"scripts": { | ||
"start": "snowpack dev", | ||
"testbuild": "snowpack build" | ||
}, | ||
"devDependencies": { | ||
"magic-string": "^0.25.7", | ||
"snowpack": "^2.7.0" | ||
} | ||
} |
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,11 @@ | ||
{ | ||
"mount": { | ||
"./src": "/_dist_" | ||
}, | ||
"buildOptions": { | ||
"clean": true, | ||
"minify": false, | ||
"sourceMaps": true | ||
}, | ||
"plugins": ["./custom-transform-plugin.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,3 @@ | ||
import './submodule.ts'; | ||
|
||
console.log('loaded'); |
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 @@ | ||
console.log('ts loaded'); |
d8131c2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: