-
-
Notifications
You must be signed in to change notification settings - Fork 632
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: using dojang to render runtime_template (#9422)
* feat: using dojang to render runtime_template * fix: normalize line endings in runtime template rendering * refactor: use cow_replace for line ending normalization * chore: add comment explaining line ending normalization * fix: update variable names to use camelCase in auto public path template
- Loading branch information
1 parent
cf4d882
commit 7df06cf
Showing
19 changed files
with
126 additions
and
132 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
25 changes: 25 additions & 0 deletions
25
crates/rspack_plugin_runtime/src/runtime_module/runtime/auto_public_path.ejs
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,25 @@ | ||
var scriptUrl; | ||
<% if (script_type == "module") { %> | ||
if (typeof <%- import_meta_name %>.url === "string") scriptUrl = <%- import_meta_name %>.url | ||
<% } else { %> | ||
if (<%- GLOBAL %>.importScripts) scriptUrl = <%- GLOBAL %>.location + ""; | ||
var document = <%- GLOBAL %>.document; | ||
if (!scriptUrl && document) { | ||
// Technically we could use `document.currentScript instanceof window.HTMLScriptElement`, | ||
// but an attacker could try to inject `<script>HTMLScriptElement = HTMLImageElement</script>` | ||
// and use `<img name="currentScript" src="https://attacker.controlled.server/"></img>` | ||
if (document.currentScript && document.currentScript.tagName.toUpperCase() === 'SCRIPT') scriptUrl = document.currentScript.src; | ||
if (!scriptUrl) { | ||
var scripts = document.getElementsByTagName("script"); | ||
if (scripts.length) { | ||
var i = scripts.length - 1; | ||
while (i > -1 && (!scriptUrl || !/^http(s?):/.test(scriptUrl))) scriptUrl = scripts[i--].src; | ||
} | ||
} | ||
} | ||
<% } %> | ||
// When supporting browsers where an automatic publicPath is not supported you must specify an output.publicPath manually via configuration", | ||
// or pass an empty string ("") and set the __webpack_public_path__ variable from your code to use your own logic.', | ||
if (!scriptUrl) throw new Error("Automatic publicPath is not supported in this browser"); | ||
scriptUrl = scriptUrl.replace(/^blob:/, "").replace(/#.*$/, "").replace(/\?.*$/, "").replace(/\/[^\/]+$/, "/"); | ||
<%- assign %> |
8 changes: 8 additions & 0 deletions
8
crates/rspack_plugin_runtime/src/runtime_module/runtime/compat_get_default_export.ejs
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,8 @@ | ||
// getDefaultExport function for compatibility with non-ESM modules | ||
<%- COMPAT_GET_DEFAULT_EXPORT %> = <%- basicFunction("module") %> { | ||
var getter = module && module.__esModule ? | ||
<%- returningFunction("module['default']", "") %> : | ||
<%- returningFunction("module", "") %>; | ||
<%- DEFINE_PROPERTY_GETTERS %>(getter, { a: getter }); | ||
return getter; | ||
}; |
11 changes: 0 additions & 11 deletions
11
crates/rspack_plugin_runtime/src/runtime_module/runtime/compat_get_default_export.js
This file was deleted.
Oops, something went wrong.
12 changes: 6 additions & 6 deletions
12
...e/runtime/create_fake_namespace_object.js → .../runtime/create_fake_namespace_object.ejs
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 |
---|---|---|
@@ -1,26 +1,26 @@ | ||
var getProto = Object.getPrototypeOf ? function(obj) { return Object.getPrototypeOf(obj); } : function(obj) { return obj.__proto__ }; | ||
var getProto = Object.getPrototypeOf ? <%- returningFunction("Object.getPrototypeOf(obj)", "obj") %> : <%- returningFunction("obj.__proto__", "obj") %>; | ||
var leafPrototypes; | ||
// create a fake namespace object | ||
// mode & 1: value is a module id, require it | ||
// mode & 2: merge all properties of value into the ns | ||
// mode & 4: return value when already ns object | ||
// mode & 16: return value when it's Promise-like | ||
// mode & 8|1: behave like require | ||
__webpack_require__.t = function(value, mode) { | ||
<%- CREATE_FAKE_NAMESPACE_OBJECT %> = function(value, mode) { | ||
if(mode & 1) value = this(value); | ||
if(mode & 8) return value; | ||
if(typeof value === 'object' && value) { | ||
if((mode & 4) && value.__esModule) return value; | ||
if((mode & 16) && typeof value.then === 'function') return value; | ||
} | ||
var ns = Object.create(null); | ||
__webpack_require__.r(ns); | ||
<%- MAKE_NAMESPACE_OBJECT %>(ns); | ||
var def = {}; | ||
leafPrototypes = leafPrototypes || [null, getProto({}), getProto([]), getProto(getProto)]; | ||
for(var current = mode & 2 && value; typeof current == 'object' && !~leafPrototypes.indexOf(current); current = getProto(current)) { | ||
Object.getOwnPropertyNames(current).forEach(function(key) { def[key] = function() { return value[key]; } }); | ||
Object.getOwnPropertyNames(current).forEach(<%- basicFunction("key") %> { def[key] = <%- returningFunction("value[key]", "") %> }); | ||
} | ||
def['default'] = function() { return value }; | ||
__webpack_require__.d(ns, def); | ||
def['default'] = <%- returningFunction("value", "") %>; | ||
<%- DEFINE_PROPERTY_GETTERS %>(ns, def); | ||
return ns; | ||
}; |
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
Oops, something went wrong.
7df06cf
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.
📝 Benchmark detail: Open
7df06cf
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.
📝 Ecosystem CI detail: Open