Socket
Socket
Sign inDemoInstall

@web/dev-server-rollup

Package Overview
Dependencies
Maintainers
7
Versions
81
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@web/dev-server-rollup - npm Package Compare versions

Comparing version 0.0.0-canary-20230420104136 to 0.0.0-canary-20231122093600

56

dist/createRollupPluginContextAdapter.js

@@ -1,22 +0,6 @@

"use strict";
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.createRollupPluginContextAdapter = void 0;
const path_1 = __importDefault(require("path"));
function createRollupPluginContextAdapter(pluginContext, wdsPlugin, config, fileWatcher, context, pluginMetaPerModule) {
return Object.assign(Object.assign({}, pluginContext), { getModuleInfo(id) {
var _a;
import path from 'path';
export function createRollupPluginContextAdapter(pluginContext, wdsPlugin, config, fileWatcher, context, pluginMetaPerModule) {
return {
...pluginContext,
getModuleInfo(id) {
return {

@@ -38,12 +22,12 @@ id,

isIncluded: false,
hasModuleSideEffects: false,
moduleSideEffects: false,
syntheticNamedExports: false,
meta: (_a = pluginMetaPerModule.get(id)) !== null && _a !== void 0 ? _a : {},
meta: pluginMetaPerModule.get(id) ?? {},
};
},
addWatchFile(id) {
const filePath = path_1.default.join(process.cwd(), id);
const filePath = path.join(process.cwd(), id);
fileWatcher.add(filePath);
}, emitAsset() {
},
emitAsset() {
throw new Error('Emitting files is not yet supported');

@@ -62,10 +46,10 @@ },

throw new Error('Emitting files is not yet supported');
}, async resolve(source, importer, options) {
var _a, _b;
},
async resolve(source, importer, options) {
if (!context)
throw new Error('Context is required.');
const { skipSelf } = options, resolveOptions = __rest(options, ["skipSelf"]);
const { skipSelf, ...resolveOptions } = options;
if (skipSelf)
(_a = wdsPlugin.resolveImportSkip) === null || _a === void 0 ? void 0 : _a.call(wdsPlugin, context, source, importer);
for (const pl of (_b = config.plugins) !== null && _b !== void 0 ? _b : []) {
wdsPlugin.resolveImportSkip?.(context, source, importer);
for (const pl of config.plugins ?? []) {
if (pl.resolveImport && (!skipSelf || pl !== wdsPlugin)) {

@@ -82,8 +66,8 @@ const result = await pl.resolveImport({

else if (typeof result === 'object') {
resolvedId = result === null || result === void 0 ? void 0 : result.id;
resolvedId = result?.id;
}
if (resolvedId) {
const importerDir = path_1.default.dirname(importer);
const importerDir = path.dirname(importer);
return {
id: path_1.default.isAbsolute(resolvedId) ? resolvedId : path_1.default.join(importerDir, resolvedId),
id: path.isAbsolute(resolvedId) ? resolvedId : path.join(importerDir, resolvedId),
};

@@ -100,8 +84,8 @@ }

if (typeof resolveResult === 'object') {
return resolveResult === null || resolveResult === void 0 ? void 0 : resolveResult.id;
return resolveResult?.id;
}
return resolveResult;
} });
},
};
}
exports.createRollupPluginContextAdapter = createRollupPluginContextAdapter;
//# sourceMappingURL=createRollupPluginContextAdapter.js.map

@@ -1,6 +0,6 @@

import { InputOptions, NormalizedInputOptions, PluginContext, TransformPluginContext, MinimalPluginContext } from 'rollup';
import { InputOptions, NormalizedInputOptions, PluginContext, TransformPluginContext } from 'rollup';
export interface RollupPluginContexts {
normalizedInputOptions: NormalizedInputOptions;
pluginContext: PluginContext;
minimalPluginContext: MinimalPluginContext;
minimalPluginContext: any;
transformPluginContext: TransformPluginContext;

@@ -7,0 +7,0 @@ }

@@ -1,5 +0,2 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createRollupPluginContexts = void 0;
const rollup_1 = require("rollup");
import { rollup, } from 'rollup';
/**

@@ -10,7 +7,10 @@ * Runs rollup with an empty module in order to capture the plugin context and

*/
async function createRollupPluginContexts(inputOptions) {
export async function createRollupPluginContexts(inputOptions) {
let normalizedInputOptions = undefined;
let pluginContext = undefined;
let transformPluginContext = undefined;
await rollup_1.rollup(Object.assign(Object.assign({}, inputOptions), { input: 'noop', plugins: [
await rollup({
...inputOptions,
input: 'noop',
plugins: [
{

@@ -33,3 +33,4 @@ name: 'noop',

},
] }));
],
});
if (!normalizedInputOptions || !pluginContext || !transformPluginContext) {

@@ -45,3 +46,2 @@ throw new TypeError();

}
exports.createRollupPluginContexts = createRollupPluginContexts;
//# sourceMappingURL=createRollupPluginContexts.js.map
import { InputOptions, Plugin as RollupPlugin } from 'rollup';
declare type FnArgs = readonly unknown[];
declare type RollupPluginFn<T extends FnArgs> = (...args: T) => RollupPlugin;
type FnArgs = readonly unknown[];
type RollupPluginFn<T extends FnArgs> = (...args: T) => RollupPlugin;
export interface FromRollupOptions {

@@ -5,0 +5,0 @@ throwOnUnresolvedImport?: boolean;

@@ -1,6 +0,3 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fromRollup = void 0;
const rollupAdapter_1 = require("./rollupAdapter");
function fromRollup(rollupPluginFn, rollupInputOptions = {}, options = {}) {
import { rollupAdapter } from './rollupAdapter.js';
export function fromRollup(rollupPluginFn, rollupInputOptions = {}, options = {}) {
if (typeof rollupPluginFn !== 'function') {

@@ -14,6 +11,5 @@ throw new Error(`fromRollup should be called with a rollup plugin function. Received: ${rollupPluginFn}`);

// wrap the rollup plugin in an adapter for web dev server
return rollupAdapter_1.rollupAdapter(rollupPlugin, rollupInputOptions, options);
return rollupAdapter(rollupPlugin, rollupInputOptions, options);
};
}
exports.fromRollup = fromRollup;
//# sourceMappingURL=fromRollup.js.map
export { RollupNodeResolveOptions, nodeResolve } from '@rollup/plugin-node-resolve';
export { fromRollup } from './fromRollup';
export { rollupAdapter } from './rollupAdapter';
export { rollupBundlePlugin } from './rollupBundlePlugin';
export { fromRollup } from './fromRollup.js';
export { rollupAdapter } from './rollupAdapter.js';
export { rollupBundlePlugin } from './rollupBundlePlugin.js';
//# sourceMappingURL=index.d.ts.map

@@ -1,12 +0,5 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.rollupBundlePlugin = exports.rollupAdapter = exports.fromRollup = exports.nodeResolve = void 0;
var plugin_node_resolve_1 = require("@rollup/plugin-node-resolve");
Object.defineProperty(exports, "nodeResolve", { enumerable: true, get: function () { return plugin_node_resolve_1.nodeResolve; } });
var fromRollup_1 = require("./fromRollup");
Object.defineProperty(exports, "fromRollup", { enumerable: true, get: function () { return fromRollup_1.fromRollup; } });
var rollupAdapter_1 = require("./rollupAdapter");
Object.defineProperty(exports, "rollupAdapter", { enumerable: true, get: function () { return rollupAdapter_1.rollupAdapter; } });
var rollupBundlePlugin_1 = require("./rollupBundlePlugin");
Object.defineProperty(exports, "rollupBundlePlugin", { enumerable: true, get: function () { return rollupBundlePlugin_1.rollupBundlePlugin; } });
export { nodeResolve } from '@rollup/plugin-node-resolve';
export { fromRollup } from './fromRollup.js';
export { rollupAdapter } from './rollupAdapter.js';
export { rollupBundlePlugin } from './rollupBundlePlugin.js';
//# sourceMappingURL=index.js.map

@@ -1,17 +0,11 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.rollupAdapter = void 0;
/* eslint-disable no-control-regex */
const path_1 = __importDefault(require("path"));
const whatwg_url_1 = __importDefault(require("whatwg-url"));
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 nanocolors_1 = require("nanocolors");
const utils_1 = require("./utils");
const createRollupPluginContextAdapter_1 = require("./createRollupPluginContextAdapter");
const createRollupPluginContexts_1 = require("./createRollupPluginContexts");
import path from 'path';
import whatwgUrl from 'whatwg-url';
import { PluginError, PluginSyntaxError, getRequestFilePath, } from '@web/dev-server-core';
import { queryAll, predicates, getTextContent, setTextContent, } from '@web/dev-server-core/dist/dom5';
import { parse as parseHtml, serialize as serializeHtml } from 'parse5';
import { red, cyan } from 'nanocolors';
import { toBrowserPath, isAbsoluteFilePath, isOutsideRootDir } from './utils.js';
import { createRollupPluginContextAdapter } from './createRollupPluginContextAdapter.js';
import { createRollupPluginContexts } from './createRollupPluginContexts.js';
const NULL_BYTE_PARAM = 'web-dev-server-rollup-null-byte';

@@ -25,8 +19,7 @@ const VIRTUAL_FILE_PREFIX = '/__web-dev-server__/rollup';

function wrapRollupError(filePath, context, error) {
var _a, _b;
if (typeof error == null || typeof error !== 'object') {
return error;
}
if (typeof ((_a = error === null || error === void 0 ? void 0 : error.loc) === null || _a === void 0 ? void 0 : _a.line) === 'number' && typeof ((_b = error === null || error === void 0 ? void 0 : error.loc) === null || _b === void 0 ? void 0 : _b.column) === 'number') {
return new dev_server_core_1.PluginSyntaxError(
if (typeof error?.loc?.line === 'number' && typeof error?.loc?.column === 'number') {
return new PluginSyntaxError(
// replace file path in error message since it will be reported be the dev server

@@ -38,3 +31,3 @@ error.message.replace(new RegExp(`(\\s*in\\s*)?(${filePath})`), ''), filePath, context.body, error.loc.line, error.loc.column);

const resolverCache = new WeakMap();
function rollupAdapter(rollupPlugin, rollupInputOptions = {}, adapterOptions = {}) {
export function rollupAdapter(rollupPlugin, rollupInputOptions = {}, adapterOptions = {}) {
if (typeof rollupPlugin !== 'object') {

@@ -55,3 +48,3 @@ throw new Error('rollupAdapter should be called with a rollup plugin object.');

const previousMeta = pluginMetaPerModule.get(id);
pluginMetaPerModule.set(id, Object.assign(Object.assign({}, previousMeta), meta));
pluginMetaPerModule.set(id, { ...previousMeta, ...meta });
}

@@ -61,6 +54,5 @@ const wdsPlugin = {

async serverStart(args) {
var _a, _b, _c;
({ fileWatcher, config } = args);
({ rootDir } = config);
rollupPluginContexts = await createRollupPluginContexts_1.createRollupPluginContexts(rollupInputOptions);
rollupPluginContexts = await createRollupPluginContexts(rollupInputOptions);
idResolvers = [];

@@ -71,3 +63,3 @@ // call the options and buildStart hooks

transformedOptions =
(_b = (await ((_a = rollupPlugin.options) === null || _a === void 0 ? void 0 : _a.call(rollupPluginContexts.minimalPluginContext, rollupInputOptions)))) !== null && _b !== void 0 ? _b : rollupInputOptions;
(await rollupPlugin.options?.call(rollupPluginContexts.minimalPluginContext, rollupInputOptions)) ?? rollupInputOptions;
}

@@ -78,3 +70,3 @@ else {

if (typeof rollupPlugin.buildStart === 'function') {
(_c = rollupPlugin.buildStart) === null || _c === void 0 ? void 0 : _c.call(rollupPluginContexts.pluginContext, rollupPluginContexts.normalizedInputOptions);
await rollupPlugin.buildStart?.call(rollupPluginContexts.pluginContext, rollupPluginContexts.normalizedInputOptions);
}

@@ -98,6 +90,5 @@ if (transformedOptions &&

resolveImportSkip(context, source, importer) {
var _a, _b;
const resolverCacheForContext = (_a = resolverCache.get(context)) !== null && _a !== void 0 ? _a : new WeakMap();
const resolverCacheForContext = resolverCache.get(context) ?? new WeakMap();
resolverCache.set(context, resolverCacheForContext);
const resolverCacheForPlugin = (_b = resolverCacheForContext.get(wdsPlugin)) !== null && _b !== void 0 ? _b : new Set();
const resolverCacheForPlugin = resolverCacheForContext.get(wdsPlugin) ?? new Set();
resolverCacheForContext.set(wdsPlugin, resolverCacheForPlugin);

@@ -107,3 +98,2 @@ resolverCacheForPlugin.add(`${source}:${importer}`);

async resolveImport({ source, context, code, column, line, resolveOptions }) {
var _a, _b, _c;
if (context.response.is('html') && source.startsWith('�')) {

@@ -117,3 +107,3 @@ // when serving HTML a null byte gets parsed as an unknown character

// we need to rewrite it to a browser path
const injectedFilePath = path_1.default.normalize(source).startsWith(rootDir);
const injectedFilePath = path.normalize(source).startsWith(rootDir);
if (!injectedFilePath && idResolvers.length === 0) {

@@ -124,4 +114,4 @@ return;

if (!injectedFilePath &&
!path_1.default.isAbsolute(source) &&
whatwg_url_1.default.parseURL(source) != null &&
!path.isAbsolute(source) &&
whatwgUrl.parseURL(source) != null &&
!isVirtualModule) {

@@ -131,5 +121,5 @@ // don't resolve relative and valid urls

}
const filePath = dev_server_core_1.getRequestFilePath(context.url, rootDir);
const filePath = getRequestFilePath(context.url, rootDir);
try {
const rollupPluginContext = createRollupPluginContextAdapter_1.createRollupPluginContextAdapter(rollupPluginContexts.pluginContext, wdsPlugin, config, fileWatcher, context, pluginMetaPerModule);
const rollupPluginContext = createRollupPluginContextAdapter(rollupPluginContexts.pluginContext, wdsPlugin, config, fileWatcher, context, pluginMetaPerModule);
let resolvableImport = source;

@@ -152,5 +142,5 @@ let importSuffix = '';

let result = null;
const resolverCacheForContext = (_a = resolverCache.get(context)) !== null && _a !== void 0 ? _a : new WeakMap();
const resolverCacheForContext = resolverCache.get(context) ?? new WeakMap();
resolverCache.set(context, resolverCacheForContext);
const resolverCacheForPlugin = (_b = resolverCacheForContext.get(wdsPlugin)) !== null && _b !== void 0 ? _b : new Set();
const resolverCacheForPlugin = resolverCacheForContext.get(wdsPlugin) ?? new Set();
resolverCacheForContext.set(wdsPlugin, resolverCacheForPlugin);

@@ -162,3 +152,9 @@ if (resolverCacheForPlugin.has(`${source}:${filePath}`)) {

const idResolverHandler = typeof idResolver === 'function' ? idResolver : idResolver.handler;
result = await idResolverHandler.call(rollupPluginContext, resolvableImport, filePath, Object.assign(Object.assign({}, resolveOptions), { assertions: Object.assign({}, ((_c = resolveOptions === null || resolveOptions === void 0 ? void 0 : resolveOptions.assertions) !== null && _c !== void 0 ? _c : {})), isEntry: false }));
result = await idResolverHandler.call(rollupPluginContext, resolvableImport, filePath, {
...resolveOptions,
attributes: {
...(resolveOptions?.assertions ?? {}),
},
isEntry: false,
});
if (result) {

@@ -177,3 +173,3 @@ break;

}
else if (typeof result === 'object' && typeof (result === null || result === void 0 ? void 0 : result.id) === 'string') {
else if (typeof result === 'object' && typeof result?.id === 'string') {
resolvedImportPath = result.id;

@@ -185,10 +181,10 @@ savePluginMeta(result.id, result);

adapterOptions.throwOnUnresolvedImport) {
const errorMessage = nanocolors_1.red(`Could not resolve import ${nanocolors_1.cyan(`"${source}"`)}.`);
const errorMessage = red(`Could not resolve import ${cyan(`"${source}"`)}.`);
if (typeof code === 'string' &&
typeof column === 'number' &&
typeof line === 'number') {
throw new dev_server_core_1.PluginSyntaxError(errorMessage, filePath, code, column, line);
throw new PluginSyntaxError(errorMessage, filePath, code, column, line);
}
else {
throw new dev_server_core_1.PluginError(errorMessage);
throw new PluginError(errorMessage);
}

@@ -202,8 +198,8 @@ }

if (resolvedImportPath.includes('\0')) {
const filename = path_1.default.basename(resolvedImportPath.replace(/\0*/g, '').split('?')[0].split('#')[0]);
const filename = path.basename(resolvedImportPath.replace(/\0*/g, '').split('?')[0].split('#')[0]);
// if the resolve import path is outside our normal root, fully resolve the file path for rollup
const matches = resolvedImportPath.match(OUTSIDE_ROOT_REGEXP);
if (matches) {
const upDirs = new Array(parseInt(matches[1], 10) + 1).join(`..${path_1.default.sep}`);
resolvedImportPath = `\0${path_1.default.resolve(`${upDirs}${matches[2]}`)}`;
const upDirs = new Array(parseInt(matches[1], 10) + 1).join(`..${path.sep}`);
resolvedImportPath = `\0${path.resolve(`${upDirs}${matches[2]}`)}`;
}

@@ -214,38 +210,38 @@ const urlParam = encodeURIComponent(resolvedImportPath);

// some plugins don't return a file path, so we just return it as is
if (!utils_1.isAbsoluteFilePath(resolvedImportPath)) {
if (!isAbsoluteFilePath(resolvedImportPath)) {
return `${resolvedImportPath}`;
}
// file already resolved outsided root dir
if (utils_1.isOutsideRootDir(resolvedImportPath)) {
if (isOutsideRootDir(resolvedImportPath)) {
return `${resolvedImportPath}`;
}
const normalizedPath = path_1.default.normalize(resolvedImportPath);
const normalizedPath = path.normalize(resolvedImportPath);
// append a path separator to rootDir so we are actually testing containment
// of the normalized path within the rootDir folder
const checkRootDir = rootDir.endsWith(path_1.default.sep) ? rootDir : rootDir + path_1.default.sep;
const checkRootDir = rootDir.endsWith(path.sep) ? rootDir : rootDir + path.sep;
if (!normalizedPath.startsWith(checkRootDir)) {
const relativePath = path_1.default.relative(rootDir, normalizedPath);
const dirUp = `..${path_1.default.sep}`;
const relativePath = path.relative(rootDir, normalizedPath);
const dirUp = `..${path.sep}`;
const lastDirUpIndex = relativePath.lastIndexOf(dirUp) + 3;
const dirUpStrings = relativePath.substring(0, lastDirUpIndex).split(path_1.default.sep);
const dirUpStrings = relativePath.substring(0, lastDirUpIndex).split(path.sep);
if (dirUpStrings.length === 0 || dirUpStrings.some(str => !['..', ''].includes(str))) {
// we expect the relative part to consist of only ../ or ..\\
const errorMessage = nanocolors_1.red(`\n\nResolved ${nanocolors_1.cyan(source)} to ${nanocolors_1.cyan(resolvedImportPath)}.\n\n`) +
nanocolors_1.red('This path could not be converted to a browser path. Please file an issue with a reproduction.');
const errorMessage = red(`\n\nResolved ${cyan(source)} to ${cyan(resolvedImportPath)}.\n\n`) +
red('This path could not be converted to a browser path. Please file an issue with a reproduction.');
if (typeof code === 'string' &&
typeof column === 'number' &&
typeof line === 'number') {
throw new dev_server_core_1.PluginSyntaxError(errorMessage, filePath, code, column, line);
throw new PluginSyntaxError(errorMessage, filePath, code, column, line);
}
else {
throw new dev_server_core_1.PluginError(errorMessage);
throw new PluginError(errorMessage);
}
}
const importPath = utils_1.toBrowserPath(relativePath.substring(lastDirUpIndex));
const importPath = toBrowserPath(relativePath.substring(lastDirUpIndex));
resolvedImportPath = `/__wds-outside-root__/${dirUpStrings.length - 1}/${importPath}`;
}
else {
const resolveRelativeTo = path_1.default.extname(filePath) ? path_1.default.dirname(filePath) : filePath;
const relativeImportFilePath = path_1.default.relative(resolveRelativeTo, resolvedImportPath);
resolvedImportPath = `./${utils_1.toBrowserPath(relativeImportFilePath)}`;
const resolveRelativeTo = path.dirname(filePath);
const relativeImportFilePath = path.relative(resolveRelativeTo, resolvedImportPath);
resolvedImportPath = `./${toBrowserPath(relativeImportFilePath)}`;
}

@@ -259,3 +255,2 @@ return `${resolvedImportPath}${importSuffix}`;

async serve(context) {
var _a;
if (!rollupPlugin.load) {

@@ -276,9 +271,9 @@ return;

else {
filePath = path_1.default.join(rootDir, context.path);
filePath = path.join(rootDir, context.path);
}
try {
const rollupPluginContext = createRollupPluginContextAdapter_1.createRollupPluginContextAdapter(rollupPluginContexts.pluginContext, wdsPlugin, config, fileWatcher, context, pluginMetaPerModule);
const rollupPluginContext = createRollupPluginContextAdapter(rollupPluginContexts.pluginContext, wdsPlugin, config, fileWatcher, context, pluginMetaPerModule);
let result;
if (typeof rollupPlugin.load === 'function') {
result = await ((_a = rollupPlugin.load) === null || _a === void 0 ? void 0 : _a.call(rollupPluginContext, filePath));
result = await rollupPlugin.load?.call(rollupPluginContext, filePath);
}

@@ -288,3 +283,3 @@ if (typeof result === 'string') {

}
if (result != null && typeof (result === null || result === void 0 ? void 0 : result.code) === 'string') {
if (result != null && typeof result?.code === 'string') {
savePluginMeta(filePath, result);

@@ -300,3 +295,2 @@ return { body: result.code, type: 'js' };

async transform(context) {
var _a, _b;
if (!rollupPlugin.transform) {

@@ -309,8 +303,8 @@ return;

if (context.response.is('js')) {
const filePath = path_1.default.join(rootDir, context.path);
const filePath = path.join(rootDir, context.path);
try {
const rollupPluginContext = createRollupPluginContextAdapter_1.createRollupPluginContextAdapter(rollupPluginContexts.transformPluginContext, wdsPlugin, config, fileWatcher, context, pluginMetaPerModule);
const rollupPluginContext = createRollupPluginContextAdapter(rollupPluginContexts.transformPluginContext, wdsPlugin, config, fileWatcher, context, pluginMetaPerModule);
let result;
if (typeof rollupPlugin.transform === 'function') {
result = await ((_a = rollupPlugin.transform) === null || _a === void 0 ? void 0 : _a.call(rollupPluginContext, context.body, filePath));
result = await rollupPlugin.transform?.call(rollupPluginContext, context.body, filePath);
}

@@ -321,3 +315,3 @@ let transformedCode = undefined;

}
if (typeof result === 'object' && typeof (result === null || result === void 0 ? void 0 : result.code) === 'string') {
if (typeof result === 'object' && typeof result?.code === 'string') {
savePluginMeta(filePath, result);

@@ -337,13 +331,13 @@ transformedCode = result.code;

if (context.response.is('html')) {
const documentAst = parse5_1.parse(context.body);
const inlineScripts = dom5_1.queryAll(documentAst, dom5_1.predicates.AND(dom5_1.predicates.hasTagName('script'), dom5_1.predicates.NOT(dom5_1.predicates.hasAttr('src'))));
const filePath = dev_server_core_1.getRequestFilePath(context.url, rootDir);
const documentAst = parseHtml(context.body);
const inlineScripts = queryAll(documentAst, predicates.AND(predicates.hasTagName('script'), predicates.NOT(predicates.hasAttr('src'))));
const filePath = getRequestFilePath(context.url, rootDir);
let transformed = false;
try {
for (const node of inlineScripts) {
const code = dom5_1.getTextContent(node);
const rollupPluginContext = createRollupPluginContextAdapter_1.createRollupPluginContextAdapter(rollupPluginContexts.transformPluginContext, wdsPlugin, config, fileWatcher, context, pluginMetaPerModule);
const code = getTextContent(node);
const rollupPluginContext = createRollupPluginContextAdapter(rollupPluginContexts.transformPluginContext, wdsPlugin, config, fileWatcher, context, pluginMetaPerModule);
let result;
if (typeof rollupPlugin.transform === 'function') {
result = await ((_b = rollupPlugin.transform) === null || _b === void 0 ? void 0 : _b.call(rollupPluginContext, code, filePath));
result = await rollupPlugin.transform?.call(rollupPluginContext, code, filePath);
}

@@ -354,3 +348,3 @@ let transformedCode = undefined;

}
if (typeof result === 'object' && typeof (result === null || result === void 0 ? void 0 : result.code) === 'string') {
if (typeof result === 'object' && typeof result?.code === 'string') {
savePluginMeta(filePath, result);

@@ -361,3 +355,3 @@ transformedCode = result.code;

transformedFiles.add(context.path);
dom5_1.setTextContent(node, transformedCode);
setTextContent(node, transformedCode);
transformed = true;

@@ -367,3 +361,3 @@ }

if (transformed) {
return parse5_1.serialize(documentAst);
return serializeHtml(documentAst);
}

@@ -377,8 +371,7 @@ }

fileParsed(context) {
var _a;
if (!rollupPlugin.moduleParsed) {
return;
}
const rollupPluginContext = createRollupPluginContextAdapter_1.createRollupPluginContextAdapter(rollupPluginContexts.transformPluginContext, wdsPlugin, config, fileWatcher, context, pluginMetaPerModule);
const filePath = dev_server_core_1.getRequestFilePath(context.url, rootDir);
const rollupPluginContext = createRollupPluginContextAdapter(rollupPluginContexts.transformPluginContext, wdsPlugin, config, fileWatcher, context, pluginMetaPerModule);
const filePath = getRequestFilePath(context.url, rootDir);
const info = rollupPluginContext.getModuleInfo(filePath);

@@ -388,3 +381,3 @@ if (!info)

if (typeof rollupPlugin.moduleParsed === 'function') {
(_a = rollupPlugin.moduleParsed) === null || _a === void 0 ? void 0 : _a.call(rollupPluginContext, info);
rollupPlugin.moduleParsed?.call(rollupPluginContext, info);
}

@@ -395,3 +388,2 @@ },

}
exports.rollupAdapter = rollupAdapter;
//# sourceMappingURL=rollupAdapter.js.map

@@ -1,17 +0,15 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.rollupBundlePlugin = void 0;
const path_1 = __importDefault(require("path"));
const rollup_1 = require("rollup");
import path from 'path';
import { rollup } from 'rollup';
async function bundleEntrypoints(rollupConfig) {
const bundle = await rollup_1.rollup(rollupConfig);
const bundle = await rollup(rollupConfig);
if (Array.isArray(rollupConfig.output)) {
throw new Error('Multiple outputs not supported.');
}
return bundle.generate(Object.assign(Object.assign({}, rollupConfig.output), { chunkFileNames: '__rollup-generated__[name].js', assetFileNames: '__rollup-generated__[name][extname]' }));
return bundle.generate({
...rollupConfig.output,
chunkFileNames: '__rollup-generated__[name].js',
assetFileNames: '__rollup-generated__[name][extname]',
});
}
function rollupBundlePlugin(pluginOptions) {
export function rollupBundlePlugin(pluginOptions) {
const servedFiles = new Map();

@@ -33,3 +31,3 @@ return {

}
relativeFilePath = path_1.default.relative(config.rootDir, file.facadeModuleId);
relativeFilePath = path.relative(config.rootDir, file.facadeModuleId);
}

@@ -48,3 +46,3 @@ else {

}
const browserPath = `/${relativeFilePath.split(path_1.default.sep).join('/')}`;
const browserPath = `/${relativeFilePath.split(path.sep).join('/')}`;
servedFiles.set(browserPath, content);

@@ -59,3 +57,3 @@ }

else if (context.path.includes('__rollup-generated__')) {
return servedFiles.get(`/${path_1.default.basename(context.path)}`);
return servedFiles.get(`/${path.basename(context.path)}`);
}

@@ -65,3 +63,2 @@ },

}
exports.rollupBundlePlugin = rollupBundlePlugin;
//# sourceMappingURL=rollupBundlePlugin.js.map

@@ -1,8 +0,2 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.isOutsideRootDir = exports.isAbsoluteFilePath = exports.toBrowserPath = void 0;
const path_1 = __importDefault(require("path"));
import path from 'path';
const REGEXP_ABSOLUTE = /^(?:\/|(?:[A-Za-z]:)?[\\|/])/;

@@ -14,14 +8,11 @@ /**

*/
function toBrowserPath(filePath) {
return filePath.split(path_1.default.sep).join('/');
export function toBrowserPath(filePath) {
return filePath.split(path.sep).join('/');
}
exports.toBrowserPath = toBrowserPath;
function isAbsoluteFilePath(path) {
export function isAbsoluteFilePath(path) {
return REGEXP_ABSOLUTE.test(path);
}
exports.isAbsoluteFilePath = isAbsoluteFilePath;
function isOutsideRootDir(path) {
export function isOutsideRootDir(path) {
return path.startsWith('/__wds-outside-root__/');
}
exports.isOutsideRootDir = isOutsideRootDir;
//# sourceMappingURL=utils.js.map
// this file is autogenerated with the generate-mjs-dts-entrypoints script
export * from './dist/index';
export * from './dist/index.js';
{
"name": "@web/dev-server-rollup",
"version": "0.0.0-canary-20230420104136",
"version": "0.0.0-canary-20231122093600",
"publishConfig": {

@@ -17,4 +17,6 @@ "access": "public"

"main": "dist/index.js",
"type": "module",
"exports": {
".": {
"types": "./index.d.ts",
"import": "./index.mjs",

@@ -25,3 +27,3 @@ "require": "./dist/index.js"

"engines": {
"node": ">=16.0.0"
"node": ">=18.0.0"
},

@@ -53,6 +55,6 @@ "scripts": {

"@rollup/plugin-node-resolve": "^15.0.1",
"@web/dev-server-core": "0.0.0-canary-20230420104136",
"@web/dev-server-core": "0.0.0-canary-20231122093600",
"nanocolors": "^0.2.1",
"parse5": "^6.0.1",
"rollup": "^3.15.0",
"rollup": "^4.4.0",
"whatwg-url": "^11.0.0"

@@ -62,16 +64,15 @@ },

"@babel/plugin-transform-template-literals": "^7.12.1",
"@rollup/plugin-alias": "^4.0.3",
"@rollup/plugin-babel": "^6.0.3",
"@rollup/plugin-commonjs": "^24.0.1",
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-alias": "^5.0.1",
"@rollup/plugin-babel": "^6.0.4",
"@rollup/plugin-commonjs": "25.0.7",
"@rollup/plugin-replace": "^5.0.5",
"@types/parse5": "^6.0.1",
"@types/whatwg-url": "^11.0.0",
"@web/test-runner-chrome": "0.0.0-canary-20230420104136",
"@web/test-runner-core": "0.0.0-canary-20230420104136",
"@web/test-runner-chrome": "0.0.0-canary-20231122093600",
"@web/test-runner-core": "0.0.0-canary-20231122093600",
"chai": "^4.2.0",
"mocha": "^10.2.0",
"node-fetch": "3.0.0-beta.9",
"postcss": "^8.0.0",
"postcss": "^8.4.31",
"rollup-plugin-postcss": "^4.0.2"
}
}

@@ -47,3 +47,2 @@ import path from 'path';

isIncluded: false,
hasModuleSideEffects: false,
moduleSideEffects: false,

@@ -50,0 +49,0 @@ syntheticNamedExports: false,

@@ -7,3 +7,2 @@ import {

TransformPluginContext,
MinimalPluginContext,
} from 'rollup';

@@ -14,3 +13,3 @@

pluginContext: PluginContext;
minimalPluginContext: MinimalPluginContext;
minimalPluginContext: any;
transformPluginContext: TransformPluginContext;

@@ -17,0 +16,0 @@ }

import { InputOptions, Plugin as RollupPlugin } from 'rollup';
import { rollupAdapter } from './rollupAdapter';
import { rollupAdapter } from './rollupAdapter.js';

@@ -4,0 +4,0 @@ type FnArgs = readonly unknown[];

export { RollupNodeResolveOptions, nodeResolve } from '@rollup/plugin-node-resolve';
export { fromRollup } from './fromRollup';
export { rollupAdapter } from './rollupAdapter';
export { rollupBundlePlugin } from './rollupBundlePlugin';
export { fromRollup } from './fromRollup.js';
export { rollupAdapter } from './rollupAdapter.js';
export { rollupBundlePlugin } from './rollupBundlePlugin.js';

@@ -24,5 +24,5 @@ /* eslint-disable no-control-regex */

import { toBrowserPath, isAbsoluteFilePath, isOutsideRootDir } from './utils';
import { createRollupPluginContextAdapter } from './createRollupPluginContextAdapter';
import { createRollupPluginContexts, RollupPluginContexts } from './createRollupPluginContexts';
import { toBrowserPath, isAbsoluteFilePath, isOutsideRootDir } from './utils.js';
import { createRollupPluginContextAdapter } from './createRollupPluginContextAdapter.js';
import { createRollupPluginContexts, RollupPluginContexts } from './createRollupPluginContexts.js';

@@ -110,3 +110,3 @@ const NULL_BYTE_PARAM = 'web-dev-server-rollup-null-byte';

if (typeof rollupPlugin.buildStart === 'function') {
rollupPlugin.buildStart?.call(
await rollupPlugin.buildStart?.call(
rollupPluginContexts.pluginContext,

@@ -219,3 +219,3 @@ rollupPluginContexts.normalizedInputOptions,

...resolveOptions,
assertions: {
attributes: {
...((resolveOptions?.assertions as Record<string, string>) ?? {}),

@@ -323,3 +323,3 @@ },

} else {
const resolveRelativeTo = path.extname(filePath) ? path.dirname(filePath) : filePath;
const resolveRelativeTo = path.dirname(filePath);
const relativeImportFilePath = path.relative(resolveRelativeTo, resolvedImportPath);

@@ -326,0 +326,0 @@ resolvedImportPath = `./${toBrowserPath(relativeImportFilePath)}`;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc