Socket
Socket
Sign inDemoInstall

@web/dev-server-esbuild

Package Overview
Dependencies
Maintainers
7
Versions
64
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

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

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

4

dist/browser-targets.d.ts

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

declare type Release = {
type Release = {
status: string;
};
export declare type Browser = {
export type Browser = {
name: string;

@@ -6,0 +6,0 @@ version: string;

@@ -1,20 +0,18 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isLatestModernBrowser = exports.isLatestSafari = exports.getLatestStableMajor = exports.TARGET_LOWEST_ESM_SUPPORT = exports.TARGET_LATEST_MODERN = void 0;
const browser_compat_data_1 = require("@mdn/browser-compat-data");
exports.TARGET_LATEST_MODERN = createModernTarget();
import pkg from '@mdn/browser-compat-data';
const { browsers } = pkg;
export const TARGET_LATEST_MODERN = createModernTarget();
// earliest browser versions to support module scripts, dynamic imports and import.meta
exports.TARGET_LOWEST_ESM_SUPPORT = ['chrome64', 'edge79', 'firefox67', 'safari11.1'];
export const TARGET_LOWEST_ESM_SUPPORT = ['chrome64', 'edge79', 'firefox67', 'safari11.1'];
function createModernTarget() {
try {
const latestChrome = getLatestStableMajor(browser_compat_data_1.browsers.chrome.releases);
const latestChrome = getLatestStableMajor(browsers.chrome.releases);
if (!latestChrome)
throw new Error('Could not find latest Chrome major version');
const latestEdge = getLatestStableMajor(browser_compat_data_1.browsers.edge.releases);
const latestEdge = getLatestStableMajor(browsers.edge.releases);
if (!latestEdge)
throw new Error('Could not find latest Edge major version');
const latestSafari = getLatestStableMajor(browser_compat_data_1.browsers.safari.releases);
const latestSafari = getLatestStableMajor(browsers.safari.releases);
if (!latestSafari)
throw new Error('Could not find latest Safari major version');
const latestFirefox = getLatestStableMajor(browser_compat_data_1.browsers.firefox.releases);
const latestFirefox = getLatestStableMajor(browsers.firefox.releases);
if (!latestFirefox)

@@ -36,5 +34,4 @@ throw new Error('Could not find latest Firefox major version');

}
function getLatestStableMajor(releases) {
var _a;
const release = (_a = Object.entries(releases).find(([, release]) => release.status === 'current')) === null || _a === void 0 ? void 0 : _a[0];
export function getLatestStableMajor(releases) {
const release = Object.entries(releases).find(([, release]) => release.status === 'current')?.[0];
if (release) {

@@ -45,3 +42,2 @@ return getMajorVersion(release);

}
exports.getLatestStableMajor = getLatestStableMajor;
function isWithinRange(releases, version, range) {

@@ -55,25 +51,23 @@ const currentMajorVersion = getMajorVersion(version);

}
function isLatestSafari({ name, version }) {
export function isLatestSafari({ name, version }) {
const nameLowerCase = name.toLowerCase();
// don't use include to avoid matching safari iOS
if (nameLowerCase === 'safari') {
return isWithinRange(browser_compat_data_1.browsers.safari.releases, version, 0);
return isWithinRange(browsers.safari.releases, version, 0);
}
return false;
}
exports.isLatestSafari = isLatestSafari;
function isLatestModernBrowser({ name, version }) {
export function isLatestModernBrowser({ name, version }) {
const nameLowerCase = name.toLowerCase();
if (['chrome', 'chromium'].some(name => nameLowerCase.includes(name))) {
return isWithinRange(browser_compat_data_1.browsers.chrome.releases, version, 1);
return isWithinRange(browsers.chrome.releases, version, 1);
}
if (nameLowerCase.includes('edge')) {
return isWithinRange(browser_compat_data_1.browsers.edge.releases, version, 1);
return isWithinRange(browsers.edge.releases, version, 1);
}
if (nameLowerCase.includes('firefox')) {
return isWithinRange(browser_compat_data_1.browsers.firefox.releases, version, 0);
return isWithinRange(browsers.firefox.releases, version, 0);
}
return false;
}
exports.isLatestModernBrowser = isLatestModernBrowser;
//# sourceMappingURL=browser-targets.js.map

@@ -1,29 +0,27 @@

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.EsbuildPlugin = void 0;
const dev_server_core_1 = require("@web/dev-server-core");
const esbuild_1 = require("esbuild");
const util_1 = require("util");
const path_1 = __importDefault(require("path"));
const fs_1 = __importDefault(require("fs"));
const dom5_1 = require("@web/dev-server-core/dist/dom5");
const parse5_1 = require("parse5");
const getEsbuildTarget_1 = require("./getEsbuildTarget");
import { PluginSyntaxError, getRequestFilePath, } from '@web/dev-server-core';
import { transform } from 'esbuild';
import { promisify } from 'util';
import path from 'path';
import fs from 'fs';
import { queryAll, predicates, getTextContent, setTextContent, } from '@web/dev-server-core/dist/dom5';
import { parse as parseHtml, serialize as serializeHtml } from 'parse5';
import { getEsbuildTarget } from './getEsbuildTarget.js';
const filteredWarnings = ['Unsupported source map comment'];
async function fileExists(path) {
try {
await util_1.promisify(fs_1.default.access)(path);
await promisify(fs.access)(path);
return true;
}
catch (_a) {
catch {
return false;
}
}
class EsbuildPlugin {
export class EsbuildPlugin {
config;
esbuildConfig;
logger;
transformedHtmlFiles = [];
tsconfigRaw;
name = 'esbuild';
constructor(esbuildConfig) {
this.transformedHtmlFiles = [];
this.name = 'esbuild';
this.esbuildConfig = esbuildConfig;

@@ -35,7 +33,7 @@ }

if (this.esbuildConfig.tsconfig) {
this.tsconfigRaw = await util_1.promisify(fs_1.default.readFile)(this.esbuildConfig.tsconfig, 'utf8');
this.tsconfigRaw = await promisify(fs.readFile)(this.esbuildConfig.tsconfig, 'utf8');
}
}
resolveMimeType(context) {
const fileExtension = path_1.default.posix.extname(context.path);
const fileExtension = path.posix.extname(context.path);
if (this.esbuildConfig.handledExtensions.includes(fileExtension)) {

@@ -46,3 +44,3 @@ return 'js';

async resolveImport({ source, context }) {
const fileExtension = path_1.default.posix.extname(context.path);
const fileExtension = path.posix.extname(context.path);
if (!this.esbuildConfig.tsFileExtensions.includes(fileExtension)) {

@@ -58,6 +56,6 @@ // only handle typescript files

// check if the .ts file exists, and rewrite it in that case
const filePath = dev_server_core_1.getRequestFilePath(context.url, this.config.rootDir);
const fileDir = path_1.default.dirname(filePath);
const filePath = getRequestFilePath(context.url, this.config.rootDir);
const fileDir = path.dirname(filePath);
const importAsTs = source.substring(0, source.length - 3) + '.ts';
const importedTsFilePath = path_1.default.join(fileDir, importAsTs);
const importedTsFilePath = path.join(fileDir, importAsTs);
if (!(await fileExists(importedTsFilePath))) {

@@ -70,3 +68,3 @@ return;

// the transformed files are cached per esbuild transform target
const target = getEsbuildTarget_1.getEsbuildTarget(this.esbuildConfig.target, context.headers['user-agent']);
const target = getEsbuildTarget(this.esbuildConfig.target, context.headers['user-agent']);
return Array.isArray(target) ? target.join('_') : target;

@@ -81,3 +79,3 @@ }

else {
const fileExtension = path_1.default.posix.extname(context.path);
const fileExtension = path.posix.extname(context.path);
loader = this.esbuildConfig.loaders[fileExtension];

@@ -89,3 +87,3 @@ }

}
const target = getEsbuildTarget_1.getEsbuildTarget(this.esbuildConfig.target, context.headers['user-agent']);
const target = getEsbuildTarget(this.esbuildConfig.target, context.headers['user-agent']);
if (target === 'esnext' && loader === 'js') {

@@ -95,3 +93,3 @@ // no need run esbuild, this happens when compile target is set to auto and the user is on a modern browser

}
const filePath = dev_server_core_1.getRequestFilePath(context.url, this.config.rootDir);
const filePath = getRequestFilePath(context.url, this.config.rootDir);
if (context.response.is('html')) {

@@ -104,4 +102,4 @@ this.transformedHtmlFiles.push(context.path);

async __transformHtml(context, filePath, loader, target) {
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')), dom5_1.predicates.OR(dom5_1.predicates.NOT(dom5_1.predicates.hasAttr('type')), dom5_1.predicates.hasAttrValue('type', 'module'))));
const documentAst = parseHtml(context.body);
const inlineScripts = queryAll(documentAst, predicates.AND(predicates.hasTagName('script'), predicates.NOT(predicates.hasAttr('src')), predicates.OR(predicates.NOT(predicates.hasAttr('type')), predicates.hasAttrValue('type', 'module'))));
if (inlineScripts.length === 0) {

@@ -111,7 +109,7 @@ return;

for (const node of inlineScripts) {
const code = dom5_1.getTextContent(node);
const code = getTextContent(node);
const transformedCode = await this.__transformCode(code, filePath, loader, target);
dom5_1.setTextContent(node, transformedCode);
setTextContent(node, transformedCode);
}
return parse5_1.serialize(documentAst);
return serializeHtml(documentAst);
}

@@ -134,5 +132,5 @@ async __transformCode(code, filePath, loader, target) {

};
const { code: transformedCode, warnings } = await esbuild_1.transform(code, transformOptions);
const { code: transformedCode, warnings } = await transform(code, transformOptions);
if (warnings) {
const relativePath = path_1.default.relative(process.cwd(), filePath);
const relativePath = path.relative(process.cwd(), filePath);
for (const warning of warnings) {

@@ -150,3 +148,3 @@ if (!filteredWarnings.some(w => warning.text.includes(w))) {

if (msg.location) {
throw new dev_server_core_1.PluginSyntaxError(msg.text, filePath, code, msg.location.line, msg.location.column);
throw new PluginSyntaxError(msg.text, filePath, code, msg.location.line, msg.location.column);
}

@@ -159,3 +157,2 @@ throw new Error(msg.text);

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

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.esbuildPlugin = void 0;
const EsbuildPlugin_1 = require("./EsbuildPlugin");
function esbuildPlugin(args = {}) {
var _a, _b;
const target = (_a = args.target) !== null && _a !== void 0 ? _a : 'auto';
import { EsbuildPlugin } from './EsbuildPlugin.js';
export function esbuildPlugin(args = {}) {
const target = args.target ?? 'auto';
const loaders = {};
for (const [key, value] of Object.entries((_b = args.loaders) !== null && _b !== void 0 ? _b : {})) {
for (const [key, value] of Object.entries(args.loaders ?? {})) {
loaders[key.startsWith('.') ? key : `.${key}`] = value;

@@ -38,3 +34,3 @@ }

}
return new EsbuildPlugin_1.EsbuildPlugin({
return new EsbuildPlugin({
loaders,

@@ -52,3 +48,2 @@ target,

}
exports.esbuildPlugin = esbuildPlugin;
//# sourceMappingURL=esbuildPluginFactory.js.map

@@ -1,16 +0,13 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getEsbuildTarget = void 0;
const parseUserAgent_1 = require("./parseUserAgent");
const browser_targets_1 = require("./browser-targets");
import { parseUserAgent } from './parseUserAgent.js';
import { TARGET_LATEST_MODERN, TARGET_LOWEST_ESM_SUPPORT, isLatestModernBrowser, isLatestSafari, } from './browser-targets.js';
const cache = new Map();
function getTargetForUserAgent(target, userAgent) {
const browser = parseUserAgent_1.parseUserAgent(userAgent);
const browser = parseUserAgent(userAgent);
if (typeof browser.name === 'string' && typeof browser.version === 'string') {
if (target === 'auto') {
if (browser_targets_1.isLatestModernBrowser(browser)) {
if (isLatestModernBrowser(browser)) {
// skip compiling on latest chrome/firefox/edge
return 'esnext';
}
if (browser_targets_1.isLatestSafari(browser)) {
if (isLatestSafari(browser)) {
// we don't skip safari, but we also don't want to compile to the lowest common denominator

@@ -21,5 +18,5 @@ return `safari${browser.version}`;

if (target === 'auto-always') {
if (browser_targets_1.isLatestModernBrowser(browser) || browser_targets_1.isLatestSafari(browser)) {
if (isLatestModernBrowser(browser) || isLatestSafari(browser)) {
// compile to JS compatible with latest chrome/firefox/edge/safari
return browser_targets_1.TARGET_LATEST_MODERN;
return TARGET_LATEST_MODERN;
}

@@ -29,5 +26,5 @@ }

// fall back to compiling to the lowest compatible with browsers that support es modules
return browser_targets_1.TARGET_LOWEST_ESM_SUPPORT;
return TARGET_LOWEST_ESM_SUPPORT;
}
function getEsbuildTarget(targets, userAgent) {
export function getEsbuildTarget(targets, userAgent) {
const target = typeof targets === 'string' ? targets : targets.length === 1 ? targets[0] : undefined;

@@ -40,3 +37,3 @@ if (!target || !['auto-always', 'auto'].includes(target)) {

// user has auto but there is no user agent, fall back to the lowest compatible with browsers that support es modules
return browser_targets_1.TARGET_LOWEST_ESM_SUPPORT;
return TARGET_LOWEST_ESM_SUPPORT;
}

@@ -51,3 +48,2 @@ const cached = cache.get(userAgent);

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

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

export { esbuildPlugin } from './esbuildPluginFactory';
export { esbuildPlugin } from './esbuildPluginFactory.js';
//# sourceMappingURL=index.d.ts.map

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

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.esbuildPlugin = void 0;
var esbuildPluginFactory_1 = require("./esbuildPluginFactory");
Object.defineProperty(exports, "esbuildPlugin", { enumerable: true, get: function () { return esbuildPluginFactory_1.esbuildPlugin; } });
export { esbuildPlugin } from './esbuildPluginFactory.js';
//# sourceMappingURL=index.js.map

@@ -1,7 +0,4 @@

"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseUserAgent = void 0;
const ua_parser_js_1 = require("ua-parser-js");
function parseUserAgent(userAgent) {
const parser = new ua_parser_js_1.UAParser(userAgent);
import { UAParser } from 'ua-parser-js';
export function parseUserAgent(userAgent) {
const parser = new UAParser(userAgent);
const browser = parser.getBrowser();

@@ -13,3 +10,2 @@ return {

}
exports.parseUserAgent = parseUserAgent;
//# sourceMappingURL=parseUserAgent.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-esbuild",
"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"
},

@@ -56,4 +58,4 @@ "scripts": {

"@mdn/browser-compat-data": "^4.0.0",
"@web/dev-server-core": "0.0.0-canary-20230420104136",
"esbuild": "^0.16 || ^0.17",
"@web/dev-server-core": "0.0.0-canary-20231122093600",
"esbuild": "^0.19.5",
"parse5": "^6.0.1",

@@ -64,7 +66,6 @@ "ua-parser-js": "^1.0.33"

"@types/ua-parser-js": "^0.7.35",
"@web/dev-server-rollup": "0.0.0-canary-20230420104136",
"lit-element": "^3.0.0",
"node-fetch": "3.0.0-beta.9",
"@web/dev-server-rollup": "0.0.0-canary-20231122093600",
"lit-element": "^3.0.0 || ^4.0.1",
"preact": "^10.5.9"
}
}

@@ -1,2 +0,3 @@

import { browsers } from '@mdn/browser-compat-data';
import pkg from '@mdn/browser-compat-data';
const { browsers } = pkg;

@@ -32,3 +33,5 @@ type Release = { status: string };

throw new Error(
`Error while initializing default browser targets for @web/dev-server-esbuild: ${error.message}`,
`Error while initializing default browser targets for @web/dev-server-esbuild: ${
(error as Error).message
}`,
);

@@ -35,0 +38,0 @@ }

@@ -9,3 +9,3 @@ import {

} from '@web/dev-server-core';
import type { TransformOptions } from 'esbuild';
import type { TransformOptions, BuildFailure } from 'esbuild';
import { Loader, Message, transform } from 'esbuild';

@@ -23,3 +23,3 @@ import { promisify } from 'util';

import { getEsbuildTarget } from './getEsbuildTarget';
import { getEsbuildTarget } from './getEsbuildTarget.js';

@@ -208,4 +208,4 @@ const filteredWarnings = ['Unsupported source map comment'];

} catch (e) {
if (Array.isArray(e.errors)) {
const msg = e.errors[0] as Message;
if (Array.isArray((e as BuildFailure).errors)) {
const msg = (e as BuildFailure).errors[0] as Message;

@@ -212,0 +212,0 @@ if (msg.location) {

import { Plugin } from '@web/dev-server-core';
import { Loader } from 'esbuild';
import { EsbuildPlugin } from './EsbuildPlugin';
import { EsbuildPlugin } from './EsbuildPlugin.js';

@@ -5,0 +5,0 @@ export interface EsBuildPluginArgs {

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

import { parseUserAgent } from './parseUserAgent';
import { parseUserAgent } from './parseUserAgent.js';
import {

@@ -8,3 +8,3 @@ TARGET_LATEST_MODERN,

isLatestSafari,
} from './browser-targets';
} from './browser-targets.js';

@@ -11,0 +11,0 @@ const cache = new Map<string, undefined | string | string[]>();

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

export { esbuildPlugin } from './esbuildPluginFactory';
export { esbuildPlugin } from './esbuildPluginFactory.js';

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