@web/dev-server-rollup
Advanced tools
Comparing version 0.1.3 to 0.1.4
# @web/dev-server-rollup | ||
## 0.1.4 | ||
### Patch Changes | ||
- 1c915d0: handle inline scripts | ||
## 0.1.3 | ||
@@ -4,0 +10,0 @@ |
@@ -11,2 +11,4 @@ "use strict"; | ||
const dev_server_core_1 = require("@web/dev-server-core"); | ||
const dom5_1 = require("@web/dev-server-core/dist/dom5"); | ||
const parse5_1 = require("parse5"); | ||
const url_1 = require("url"); | ||
@@ -156,3 +158,3 @@ const chalk_1 = require("chalk"); | ||
async transform(context) { | ||
var _a; | ||
var _a, _b; | ||
if (!rollupPlugin.transform) { | ||
@@ -183,2 +185,29 @@ return; | ||
} | ||
if (context.response.is('html')) { | ||
const documentAst = parse5_1.parse(context.body); | ||
const inlineModuleNodes = dom5_1.queryAll(documentAst, dom5_1.predicates.AND(dom5_1.predicates.hasTagName('script'), dom5_1.predicates.hasAttrValue('type', 'module'), dom5_1.predicates.NOT(dom5_1.predicates.hasAttr('src')))); | ||
const filePath = resolveFilePath(rootDir, context.path); | ||
try { | ||
for (const node of inlineModuleNodes) { | ||
const code = dom5_1.getTextContent(node); | ||
const rollupPluginContext = createRollupPluginContextAdapter_1.createRollupPluginContextAdapter(rollupPluginContexts.transformPluginContext, wdsPlugin, config, fileWatcher, context); | ||
const result = await ((_b = rollupPlugin.transform) === null || _b === void 0 ? void 0 : _b.call(rollupPluginContext, code, filePath)); | ||
let transformedCode = undefined; | ||
if (typeof result === 'string') { | ||
transformedCode = result; | ||
} | ||
if (typeof result === 'object' && typeof (result === null || result === void 0 ? void 0 : result.code) === 'string') { | ||
transformedCode = result.code; | ||
} | ||
if (transformedCode) { | ||
transformedFiles.add(context.path); | ||
context.body = context.body.replace(code, transformedCode); | ||
} | ||
} | ||
return context.body; | ||
} | ||
catch (error) { | ||
throw wrapRollupError(filePath, context, error); | ||
} | ||
} | ||
}, | ||
@@ -185,0 +214,0 @@ }; |
{ | ||
"name": "@web/dev-server-rollup", | ||
"version": "0.1.3", | ||
"version": "0.1.4", | ||
"publishConfig": { | ||
@@ -5,0 +5,0 @@ "access": "public" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
40383
406
0