-
Notifications
You must be signed in to change notification settings - Fork 293
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
Major: use swc-loader
for TypeScript compilation
#777
Draft
styfle
wants to merge
13
commits into
main
Choose a base branch
from
swc-loader
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
4deed52
Fix missing variable declaration
styfle ef9d66c
Always use cwd for tsconfig.json
styfle 85e8d2a
Use custom ts paths resolve plugin
styfle 5854dae
Add swc for ts compliation
styfle 792130a
Add missing file
styfle d38a35f
Add back resolveModules
styfle c754575
Remove unused ts-loader
styfle 573b1cf
Remove ts-loader from build
styfle c68542c
Fallback to undefined for resolve.modules instead of empty array
styfle 4a2ed8f
Add back missing assets
styfle d64de86
Use `@swc/wasm`
styfle 50449d4
Fix tsconfig.json detection
styfle 3fa8528
Bump `@swc/[email protected]`
styfle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// Source code from https://github.com/swc-project/swc-loader/blob/master/src/index.js | ||
// with the following changes: | ||
// - swapped out `@swc/core` for `@swc/wasm` | ||
// - swapped out `swc.transform()` for `swc.transformSync()` | ||
|
||
const loaderUtils = require("loader-utils"); | ||
const swc = require("@swc/wasm"); | ||
|
||
function makeLoader() { | ||
return function (source, inputSourceMap) { | ||
// Make the loader async | ||
const callback = this.async(); | ||
const filename = this.resourcePath; | ||
|
||
let loaderOptions = loaderUtils.getOptions(this) || {}; | ||
|
||
// Standardize on 'sourceMaps' as the key passed through to Webpack, so that | ||
// users may safely use either one alongside our default use of | ||
// 'this.sourceMap' below without getting error about conflicting aliases. | ||
if ( | ||
Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMap") && | ||
!Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMaps") | ||
) { | ||
loaderOptions = Object.assign({}, loaderOptions, { | ||
sourceMaps: loaderOptions.sourceMap, | ||
}); | ||
delete loaderOptions.sourceMap; | ||
} | ||
|
||
if (inputSourceMap) { | ||
inputSourceMap = JSON.stringify(inputSourceMap); | ||
} | ||
|
||
const programmaticOptions = Object.assign({}, loaderOptions, { | ||
filename, | ||
inputSourceMap: inputSourceMap || undefined, | ||
|
||
// Set the default sourcemap behavior based on Webpack's mapping flag, | ||
// but allow users to override if they want. | ||
sourceMaps: | ||
loaderOptions.sourceMaps === undefined | ||
? this.sourceMap | ||
: loaderOptions.sourceMaps, | ||
|
||
// Ensure that Webpack will get a full absolute path in the sourcemap | ||
// so that it can properly map the module back to its internal cached | ||
// modules. | ||
sourceFileName: filename, | ||
}); | ||
if (!programmaticOptions.inputSourceMap) { | ||
delete programmaticOptions.inputSourceMap; | ||
} | ||
|
||
const parseMap = programmaticOptions.parseMap; | ||
|
||
delete programmaticOptions.parseMap; | ||
delete programmaticOptions.customize; | ||
delete programmaticOptions.cacheDirectory; | ||
delete programmaticOptions.cacheIdentifier; | ||
delete programmaticOptions.cacheCompression; | ||
delete programmaticOptions.metadataSubscribers; | ||
|
||
// auto detect development mode | ||
if (this.mode && programmaticOptions.jsc && programmaticOptions.jsc.transform | ||
&& programmaticOptions.jsc.transform.react && | ||
!Object.prototype.hasOwnProperty.call(programmaticOptions.jsc.transform.react, "development")) { | ||
programmaticOptions.jsc.transform.react.development = this.mode === 'development' | ||
} | ||
|
||
if (programmaticOptions.sourceMaps === "inline") { | ||
// Babel has this weird behavior where if you set "inline", we | ||
// inline the sourcemap, and set 'result.map = null'. This results | ||
// in bad behavior from Babel since the maps get put into the code, | ||
// which Webpack does not expect, and because the map we return to | ||
// Webpack is null, which is also bad. To avoid that, we override the | ||
// behavior here so "inline" just behaves like 'true'. | ||
programmaticOptions.sourceMaps = true; | ||
} | ||
|
||
try { | ||
const output = swc.transformSync(source, programmaticOptions); | ||
callback( | ||
null, | ||
output.code, | ||
parseMap ? JSON.parse(output.map) : output.map | ||
); | ||
} catch (e) { | ||
callback(e); | ||
} | ||
}; | ||
} | ||
|
||
module.exports = makeLoader(); | ||
module.exports.custom = makeLoader; |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@kdy1 The
paths
andbaseUrl
tests are failing with: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.
@kdy1 The new
@swc/wasm
no longer panics, but it still fails with very strange behavior.Input:
https://github.com/vercel/ncc/blob/main/test/unit/tsconfig-paths/input.ts
Output:
Runtime result: