import-html-entry
Advanced tools
Comparing version 1.15.2 to 1.16.0
@@ -10,2 +10,3 @@ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty"; | ||
import { allSettled } from './allSettled'; | ||
import processTpl, { genLinkReplaceSymbol, genScriptReplaceSymbol } from './process-tpl'; | ||
@@ -69,3 +70,3 @@ import { defaultGetPublicPath, evalCode, getGlobalProp, getInlineCode, noteGlobalProps, readResAsString, requestIdleCallback } from './utils'; | ||
var fetch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultFetch; | ||
return Promise.all(styles.map(function (styleLink) { | ||
return allSettled(styles.map(function (styleLink) { | ||
if (isInlineCode(styleLink)) { | ||
@@ -80,3 +81,13 @@ // if it is inline style | ||
} | ||
})); | ||
})).then(function (results) { | ||
return results.filter(function (result) { | ||
// 忽略失败的请求,避免异常下载阻塞后续资源加载 | ||
if (result.status === 'rejected') { | ||
Promise.reject(result.reason); | ||
} | ||
return result.status === 'fulfilled'; | ||
}).map(function (result) { | ||
return result.value; | ||
}); | ||
}); | ||
} | ||
@@ -98,3 +109,3 @@ | ||
}; | ||
return Promise.all(scripts.map(function (script) { | ||
return allSettled(scripts.map(function (script) { | ||
if (typeof script === 'string') { | ||
@@ -129,3 +140,21 @@ if (isInlineCode(script)) { | ||
} | ||
})); | ||
})).then(function (results) { | ||
return results.map(function (result, i) { | ||
if (result.status === 'fulfilled') { | ||
result.value = { | ||
src: scripts[i], | ||
value: result.value | ||
}; | ||
} | ||
return result; | ||
}).filter(function (result) { | ||
// 忽略失败的请求,避免异常下载阻塞后续资源加载 | ||
if (result.status === 'rejected') { | ||
Promise.reject(result.reason); | ||
} | ||
return result.status === 'fulfilled'; | ||
}).map(function (result) { | ||
return result.value; | ||
}); | ||
}); | ||
} | ||
@@ -221,8 +250,9 @@ export { _getExternalScripts as getExternalScripts }; | ||
function schedule(i, resolvePromise) { | ||
if (i < scripts.length) { | ||
var scriptSrc = scripts[i]; | ||
var inlineScript = scriptsText[i]; | ||
if (i < scriptsText.length) { | ||
var script = scriptsText[i]; | ||
var scriptSrc = script.src; | ||
var inlineScript = script.value; | ||
exec(scriptSrc, inlineScript, resolvePromise); | ||
// resolve the promise while the last script executed and entry not provided | ||
if (!entry && i === scripts.length - 1) { | ||
if (!entry && i === scriptsText.length - 1) { | ||
resolvePromise(); | ||
@@ -229,0 +259,0 @@ } else { |
@@ -14,2 +14,3 @@ "use strict"; | ||
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty")); | ||
var _allSettled = require("./allSettled"); | ||
var _processTpl2 = _interopRequireWildcard(require("./process-tpl")); | ||
@@ -77,3 +78,3 @@ var _utils = require("./utils"); | ||
var fetch = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultFetch; | ||
return Promise.all(styles.map(function (styleLink) { | ||
return (0, _allSettled.allSettled)(styles.map(function (styleLink) { | ||
if (isInlineCode(styleLink)) { | ||
@@ -88,3 +89,13 @@ // if it is inline style | ||
} | ||
})); | ||
})).then(function (results) { | ||
return results.filter(function (result) { | ||
// 忽略失败的请求,避免异常下载阻塞后续资源加载 | ||
if (result.status === 'rejected') { | ||
Promise.reject(result.reason); | ||
} | ||
return result.status === 'fulfilled'; | ||
}).map(function (result) { | ||
return result.value; | ||
}); | ||
}); | ||
} | ||
@@ -105,3 +116,3 @@ | ||
}; | ||
return Promise.all(scripts.map(function (script) { | ||
return (0, _allSettled.allSettled)(scripts.map(function (script) { | ||
if (typeof script === 'string') { | ||
@@ -136,3 +147,21 @@ if (isInlineCode(script)) { | ||
} | ||
})); | ||
})).then(function (results) { | ||
return results.map(function (result, i) { | ||
if (result.status === 'fulfilled') { | ||
result.value = { | ||
src: scripts[i], | ||
value: result.value | ||
}; | ||
} | ||
return result; | ||
}).filter(function (result) { | ||
// 忽略失败的请求,避免异常下载阻塞后续资源加载 | ||
if (result.status === 'rejected') { | ||
Promise.reject(result.reason); | ||
} | ||
return result.status === 'fulfilled'; | ||
}).map(function (result) { | ||
return result.value; | ||
}); | ||
}); | ||
} | ||
@@ -227,8 +256,9 @@ function throwNonBlockingError(error, msg) { | ||
function schedule(i, resolvePromise) { | ||
if (i < scripts.length) { | ||
var scriptSrc = scripts[i]; | ||
var inlineScript = scriptsText[i]; | ||
if (i < scriptsText.length) { | ||
var script = scriptsText[i]; | ||
var scriptSrc = script.src; | ||
var inlineScript = script.value; | ||
exec(scriptSrc, inlineScript, resolvePromise); | ||
// resolve the promise while the last script executed and entry not provided | ||
if (!entry && i === scripts.length - 1) { | ||
if (!entry && i === scriptsText.length - 1) { | ||
resolvePromise(); | ||
@@ -235,0 +265,0 @@ } else { |
{ | ||
"name": "import-html-entry", | ||
"version": "1.15.2", | ||
"version": "1.16.0", | ||
"description": "import html and get the exports of entry", | ||
@@ -20,2 +20,3 @@ "main": "./lib/index.js", | ||
"build": "npm run build:lib && npm run build:esm", | ||
"build:test-bundle": "esbuild ./src/index.js --bundle --outfile=./dist/index.js --format=esm", | ||
"build:lib": "rm -fr ./lib && babel ./src --out-dir ./lib --ignore 'src/**/__tests__/**/*.js'", | ||
@@ -59,2 +60,3 @@ "build:esm": "rm -fr ./esm && BABEL_ENV=esm babel ./src --out-dir ./esm --ignore 'src/**/__tests__/**/*.js'", | ||
"codecov": "^3.7.0", | ||
"esbuild": "^0.21.5", | ||
"husky": "^1.3.1", | ||
@@ -61,0 +63,0 @@ "iconv-lite": "^0.6.2", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
AI-detected potential code anomaly
Supply chain riskAI has identified unusual behaviors that may pose a security risk.
Found 1 instance in 1 package
77726
12
1571
4
14