-
Notifications
You must be signed in to change notification settings - Fork 194
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loader - capabilities and module system detection (#338)
- Loading branch information
Showing
34 changed files
with
1,933 additions
and
687 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,37 @@ | ||
{ | ||
"additionalProperties": false, | ||
"type": "object", | ||
"definitions": { | ||
"MatchCondition": { | ||
"anyOf": [{ "instanceof": "RegExp", "tsType": "RegExp" }, { "$ref": "#/definitions/Path" }] | ||
}, | ||
"MatchConditions": { | ||
"type": "array", | ||
"items": { "$ref": "#/definitions/MatchCondition" }, | ||
"minItems": 1 | ||
}, | ||
"Path": { "type": "string" }, | ||
"ESModuleOptions": { | ||
"additionalProperties": false, | ||
"type": "object", | ||
"properties": { | ||
"exclude": { | ||
"anyOf": [ | ||
{ "$ref": "#/definitions/MatchCondition" }, | ||
{ "$ref": "#/definitions/MatchConditions" } | ||
] | ||
}, | ||
"include": { | ||
"anyOf": [ | ||
{ "$ref": "#/definitions/MatchCondition" }, | ||
{ "$ref": "#/definitions/MatchConditions" } | ||
] | ||
} | ||
} | ||
} | ||
}, | ||
"properties": { | ||
"const": { "type": "boolean" }, | ||
"esModule": { "anyOf": [{ "type": "boolean" }, { "$ref": "#/definitions/ESModuleOptions" }] } | ||
} | ||
} |
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,17 @@ | ||
/** | ||
* @typedef {Object} ESModuleOptions | ||
* @property {string | RegExp | Array<string | RegExp>} [exclude] Files to explicitly exclude from flagged as ES Modules. | ||
* @property {string | RegExp | Array<string | RegExp>} [include] Files to explicitly include for flagged as ES Modules. | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} ReactRefreshLoaderOptions | ||
* @property {boolean} [const] Enables usage of ES6 `const` and `let` in generated runtime code. | ||
* @property {boolean | ESModuleOptions} [esModule] Enables strict ES Modules compatible runtime. | ||
*/ | ||
|
||
/** | ||
* @typedef {import('type-fest').SetRequired<ReactRefreshLoaderOptions, 'const'>} NormalizedLoaderOptions | ||
*/ | ||
|
||
module.exports = {}; |
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,30 @@ | ||
const { SourceMapGenerator } = require('source-map'); | ||
|
||
/** | ||
* Generates an identity source map from a source file. | ||
* @param {string} source The content of the source file. | ||
* @param {string} resourcePath The name of the source file. | ||
* @returns {import('source-map').RawSourceMap} The identity source map. | ||
*/ | ||
function getIdentitySourceMap(source, resourcePath) { | ||
const sourceMap = new SourceMapGenerator(); | ||
sourceMap.setSourceContent(resourcePath, source); | ||
|
||
source.split('\n').forEach((line, index) => { | ||
sourceMap.addMapping({ | ||
source: resourcePath, | ||
original: { | ||
line: index + 1, | ||
column: 0, | ||
}, | ||
generated: { | ||
line: index + 1, | ||
column: 0, | ||
}, | ||
}); | ||
}); | ||
|
||
return sourceMap.toJSON(); | ||
} | ||
|
||
module.exports = getIdentitySourceMap; |
Oops, something went wrong.