New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

vite-plugin-symfony

Package Overview
Dependencies
Maintainers
1
Versions
82
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

vite-plugin-symfony - npm Package Compare versions

Comparing version 0.6.4 to 0.7.0

dist/utils.d.ts

2

dist/assetsResolver.d.ts
import type { OutputBundle } from "rollup";
import type { ResolvedConfig } from "vite";
export declare const getAssets: (config: ResolvedConfig, bundles: OutputBundle) => {};
export declare const addBuildAssets: (config: ResolvedConfig, bundles: OutputBundle, assets: StringMapping) => StringMapping;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAssets = void 0;
const getAssets = (config, bundles) => {
const assets = {};
exports.addBuildAssets = void 0;
const addBuildAssets = (config, bundles, assets) => {
Object.values(bundles)

@@ -15,3 +14,3 @@ .filter(({ type, name }) => {

};
exports.getAssets = getAssets;
exports.addBuildAssets = addBuildAssets;
//# sourceMappingURL=assetsResolver.js.map
import type { ResolvedConfig } from "vite";
import type { OutputBundle, NormalizedOutputOptions } from "rollup";
declare const getDevEntryPoints: (config: ResolvedConfig, viteDevServerUrl: string) => EntryPoints;
declare const getBuildEntryPoints: (config: ResolvedConfig, manifest: Manifest) => EntryPoints;
export { getDevEntryPoints, getBuildEntryPoints };
declare const addBuildEntryPoints: (options: NormalizedOutputOptions, config: ResolvedConfig, bundle: OutputBundle, entryPoints: EntryPoints) => EntryPoints;
export declare const getEntryFilesMapping: (config: ResolvedConfig) => EntryFilesMapping;
export { getDevEntryPoints, addBuildEntryPoints };
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBuildEntryPoints = exports.getDevEntryPoints = void 0;
exports.addBuildEntryPoints = exports.getDevEntryPoints = exports.getEntryFilesMapping = void 0;
const process_1 = require("process");
const path_1 = require("path");
const utils_1 = require("./utils");
const node_path_1 = __importDefault(require("node:path"));
const getDevEntryPoints = (config, viteDevServerUrl) => {

@@ -16,24 +21,60 @@ const entryPoints = {};

exports.getDevEntryPoints = getDevEntryPoints;
const getBuildEntryPoints = (config, manifest) => {
const entryPoints = {};
for (const [entryName, entry] of Object.entries(parseInput(config))) {
entryPoints[entryName] = parseManifestEntry(entry, manifest, config);
const addBuildEntryPoints = (options, config, bundle, entryPoints) => {
function getFileName(chunk) {
if (chunk.type === 'asset') {
return chunk.name;
}
else if (chunk.type === 'chunk') {
if (chunk.facadeModuleId) {
let name = (0, utils_1.normalizePath)(node_path_1.default.relative(config.root, chunk.facadeModuleId));
if (options.format === 'system' && !chunk.name.includes('-legacy')) {
name = (0, utils_1.getLegacyName)(name);
}
return name.replace(/\0/g, '');
}
else {
return chunk.fileName;
}
}
}
let name2exportName = {};
for (let chunkName in bundle) {
name2exportName[getFileName(bundle[chunkName])] = chunkName;
}
let entryFiles = parseInput(config);
for (const [entryName, entry] of Object.entries(entryFiles)) {
let exportPath = name2exportName[entry.entryPath];
let fileInfos = bundle[exportPath];
let isLegacy = false;
if (!fileInfos) {
let legacyEntryPath = (0, utils_1.getLegacyName)(entry.entryPath);
exportPath = name2exportName[legacyEntryPath];
fileInfos = bundle[exportPath];
if (!fileInfos) {
throw new Error(`Unable to find ${exportPath}`);
}
isLegacy = true;
}
let finalEntryName = isLegacy ? `${entryName}-legacy` : entryName;
let legacyEntryPoint = typeof entryPoints[`${finalEntryName}-legacy`] !== "undefined" ? `${finalEntryName}-legacy` : false;
entryPoints[finalEntryName] = resolveEntrypoint(fileInfos, bundle, config, legacyEntryPoint, true);
}
if (name2exportName['vite/legacy-polyfills-legacy']) {
let fileInfos = bundle[name2exportName['vite/legacy-polyfills-legacy']];
entryPoints['polyfills-legacy'] = resolveEntrypoint(fileInfos, bundle, config, false, true);
}
return entryPoints;
};
exports.getBuildEntryPoints = getBuildEntryPoints;
const parseManifestEntry = ({ entryPath, entryType }, manifest, config) => {
if (!manifest[entryPath]) {
throw new Error(`Entrypoint ${entryPath} not defined in the manifest`);
}
const manifestEntry = manifest[entryPath];
exports.addBuildEntryPoints = addBuildEntryPoints;
const resolveEntrypoint = (fileInfos, bundle, config, legacyEntryPoint, isCSSOrJsEntry) => {
const js = [];
const css = [];
const preload = [];
if (manifestEntry.imports) {
for (const importEntryName of manifestEntry.imports) {
const { css: importCss, preload: importPreload } = parseManifestEntry({
entryPath: importEntryName,
entryType: "js",
}, manifest, config);
if (fileInfos.imports) {
for (const importEntryName of fileInfos.imports) {
let importFileInfos = bundle[importEntryName];
if (!importFileInfos) {
throw new Error(`Unable to find ${importEntryName}`);
}
const { css: importCss, preload: importPreload } = resolveEntrypoint(importFileInfos, bundle, config, false, false);
for (const dependency of importCss) {

@@ -51,26 +92,27 @@ if (css.indexOf(dependency) === -1) {

}
if (manifestEntry.isEntry) {
if (entryType === "js") {
js.push(`${config.base}${manifestEntry.file}`);
let filePath = `${config.base}${fileInfos.fileName}`;
if (isCSSOrJsEntry) {
if (fileInfos.isEntry) {
// it is a JS file
js.push(filePath);
}
else if (entryType === "css") {
css.push(`${config.base}${manifestEntry.file}`);
else {
css.push(filePath);
}
}
else if (preload.indexOf(`${config.base}${manifestEntry.file}`) === -1) {
preload.push(`${config.base}${manifestEntry.file}`);
else if (preload.indexOf(filePath) === -1) {
preload.push(filePath);
}
if (manifestEntry.css) {
manifestEntry.css.forEach((cssEntry) => {
if (css.indexOf(`${config.base}${cssEntry}`) === -1) {
css.push(`${config.base}${cssEntry}`);
}
if (fileInfos.viteMetadata?.importedCss.size) {
fileInfos.viteMetadata.importedCss.forEach(cssFilePath => {
css.push(`${config.base}${cssFilePath}`);
});
}
return { js, css, preload };
return { js, css, preload, legacy: legacyEntryPoint };
};
const parseInput = (config) => {
const inputParsed = {};
// let isLegacy = (options.format === 'system' && bundle[chunkName].name.includes('-legacy'));
for (const [entryName, entryPath] of Object.entries(config.build.rollupOptions.input)) {
const entryAbsolutePath = (0, path_1.resolve)((0, process_1.cwd)(), entryPath).replace(/\\/g, "/");
const entryAbsolutePath = (0, utils_1.normalizePath)((0, path_1.resolve)((0, process_1.cwd)(), entryPath));
if (entryAbsolutePath.indexOf(config.root) !== 0) {

@@ -90,2 +132,17 @@ console.error("Entry points must be inside Vite root directory");

};
const getEntryFilesMapping = (config) => {
const inputParsed = {};
// let isLegacy = (options.format === 'system' && bundle[chunkName].name.includes('-legacy'));
for (const [entryName, entryPath] of Object.entries(config.build.rollupOptions.input)) {
const entryAbsolutePath = (0, utils_1.normalizePath)((0, path_1.resolve)((0, process_1.cwd)(), entryPath));
if (entryAbsolutePath.indexOf(config.root) !== 0) {
console.error("Entry points must be inside Vite root directory");
process.exit(1);
}
const entryRelativePath = entryAbsolutePath.substring(config.root.length + 1);
inputParsed[entryName] = entryRelativePath;
}
return inputParsed;
};
exports.getEntryFilesMapping = getEntryFilesMapping;
//# sourceMappingURL=configResolver.js.map

@@ -114,4 +114,7 @@ "use strict";

let viteConfig;
let entryPointsPath;
let viteDevServerUrl;
let entryPointsFilename = "entrypoints.json";
let entryPoints = {};
let assets = {};
let outputCount = 0;
return {

@@ -129,3 +132,2 @@ name: "symfony",

build: {
manifest: true,
outDir: userConfig.build?.outDir ?? resolveOutDir(pluginOptions),

@@ -148,3 +150,2 @@ },

viteConfig = config;
entryPointsPath = (0, path_1.resolve)(config.root, config.build.outDir, "entrypoints.json");
},

@@ -168,2 +169,3 @@ configureServer(devServer) {

const entryPoints = (0, configResolver_1.getDevEntryPoints)(viteConfig, viteDevServerUrl);
let entryPointsPath = (0, path_1.resolve)(viteConfig.root, viteConfig.build.outDir, entryPointsFilename);
(0, fileHelper_1.writeJson)(entryPointsPath, {

@@ -177,2 +179,3 @@ isProd: false,

assets: null,
legacy: false
});

@@ -232,16 +235,21 @@ }

},
writeBundle(options, bundles) {
if (!bundles["manifest.json"] || bundles["manifest.json"].type !== "asset") {
console.error("manifest.json not generated, vite-plugin-symfony need `build.manifest: true`");
process.exit(1);
generateBundle(options, bundle) {
(0, configResolver_1.addBuildEntryPoints)(options, viteConfig, bundle, entryPoints);
(0, assetsResolver_1.addBuildAssets)(viteConfig, bundle, assets);
outputCount++;
const output = viteConfig.build.rollupOptions?.output;
const outputLength = Array.isArray(output) ? output.length : 1;
if (outputCount >= outputLength) {
this.emitFile({
fileName: entryPointsFilename,
type: 'asset',
source: JSON.stringify({
isProd: true,
viteServer: false,
entryPoints,
assets,
legacy: typeof entryPoints['polyfills-legacy'] !== "undefined"
}, null, 2)
});
}
const manifest = JSON.parse(bundles["manifest.json"].source.toString());
const entryPoints = (0, configResolver_1.getBuildEntryPoints)(viteConfig, manifest);
const assets = (0, assetsResolver_1.getAssets)(viteConfig, bundles);
(0, fileHelper_1.writeJson)(entryPointsPath, {
isProd: true,
viteServer: false,
entryPoints,
assets,
});
},

@@ -248,0 +256,0 @@ };

{
"name": "vite-plugin-symfony",
"version": "0.6.4",
"version": "0.7.0",
"description": "",

@@ -51,3 +51,3 @@ "main": "dist/index.js",

"volta": {
"node": "16.16.0"
"node": "18.12.1"
},

@@ -54,0 +54,0 @@ "dependencies": {

@@ -94,2 +94,81 @@ # Vite plugin Symfony

If you use previous version of the plugin consult [migration](migration.md) page.
If you use previous version of the plugin consult [migration](migration.md) page.
## Todo
- plugin option to preload dynamic imports
## In depth
default js entryPoint
```json
{
"assets/welcome.js": {
"file": "assets/welcome.e107d3d9.js",
"src": "assets/welcome.js",
"isEntry": true
},
}
```
js entryPoint with chunk entrypoints
-> by default with vite until 2.8
-> with plugin
```js
import { splitVendorChunkPlugin } from 'vite'
export default defineConfig({
plugins: [
symfonyPlugin(),
splitVendorChunkPlugin()
]
```
```json
{
"assets/page-vue.js": {
"file": "assets/pageVue.ef10a2a2.js",
"src": "assets/page-vue.js",
"isEntry": true,
"imports": [
"_vendor.d13b263d.js"
]
},
"_vendor.d13b263d.js": {
"file": "assets/vendor.d13b263d.js"
}
}
```
we need to preload imports.
js and Dynamic imports
```json
{
"assets/page-imports.js": {
"file": "assets/pageImports.74302e69.js",
"src": "assets/page-imports.js",
"isEntry": true,
"dynamicImports": [
"assets/lib/async-dep.js"
]
},
"assets/lib/async-dep.js": {
"file": "assets/async-dep.8bc0df8e.js",
"src": "assets/lib/async-dep.js",
"isDynamicEntry": true
}
}
```
css entry point
```json
{
"assets/theme.scss": {
"file": "assets/theme.2d6210b2.css",
"src": "assets/theme.scss",
"isEntry": true
}
}
```
import type { OutputBundle } from "rollup";
import type { ResolvedConfig } from "vite";
export const getAssets = (config: ResolvedConfig, bundles: OutputBundle) => {
const assets = {};
export const addBuildAssets = (config: ResolvedConfig, bundles: OutputBundle, assets: StringMapping) => {
Object.values(bundles)

@@ -14,2 +13,2 @@ .filter(({ type, name }) => {

return assets;
};
};
import { cwd } from "process";
import { resolve, extname } from "path";
import type { ResolvedConfig } from "vite";
import type { OutputBundle, OutputChunk, OutputAsset, NormalizedOutputOptions } from "rollup";
import { normalizePath, getLegacyName } from "./utils";
import path from 'node:path'

@@ -16,17 +19,70 @@ const getDevEntryPoints = (config: ResolvedConfig, viteDevServerUrl: string) => {

const getBuildEntryPoints = (config: ResolvedConfig, manifest: Manifest) => {
const entryPoints: EntryPoints = {};
const addBuildEntryPoints = (
options: NormalizedOutputOptions,
config: ResolvedConfig,
bundle: OutputBundle,
entryPoints: EntryPoints
) => {
for (const [entryName, entry] of Object.entries(parseInput(config))) {
entryPoints[entryName] = parseManifestEntry(entry, manifest, config);
function getFileName(chunk: OutputAsset | OutputChunk) {
if (chunk.type === 'asset') {
return chunk.name;
} else if (chunk.type === 'chunk') {
if (chunk.facadeModuleId) {
let name = normalizePath(
path.relative(config.root, chunk.facadeModuleId)
)
if (options.format === 'system' && !chunk.name.includes('-legacy')) {
name = getLegacyName(name)
}
return name.replace(/\0/g, '')
} else {
return chunk.fileName;
}
}
}
let name2exportName: StringMapping = {};
for (let chunkName in bundle) {
name2exportName[getFileName(bundle[chunkName])] = chunkName;
}
let entryFiles = parseInput(config);
for (const [entryName, entry] of Object.entries(entryFiles)) {
let exportPath = name2exportName[entry.entryPath];
let fileInfos = <OutputChunk & {viteMetadata: ChunkMetadata}>bundle[exportPath];
let isLegacy = false;
if (!fileInfos) {
let legacyEntryPath = getLegacyName(entry.entryPath);
exportPath = name2exportName[legacyEntryPath];
fileInfos = <OutputChunk & {viteMetadata: ChunkMetadata}>bundle[exportPath];
if (!fileInfos) {
throw new Error(`Unable to find ${exportPath}`);
}
isLegacy = true;
}
let finalEntryName = isLegacy ? `${entryName}-legacy` : entryName
let legacyEntryPoint = typeof entryPoints[`${finalEntryName}-legacy`] !== "undefined" ? `${finalEntryName}-legacy` : false
entryPoints[finalEntryName] = resolveEntrypoint(fileInfos, bundle, config, legacyEntryPoint, true);
}
if (name2exportName['vite/legacy-polyfills-legacy']) {
let fileInfos = <OutputChunk & {viteMetadata: ChunkMetadata}>bundle[
name2exportName['vite/legacy-polyfills-legacy']
];
entryPoints['polyfills-legacy'] = resolveEntrypoint(fileInfos, bundle, config, false, true);
}
return entryPoints;
};
const parseManifestEntry = ({ entryPath, entryType }: ParsedEntry, manifest: Manifest, config: ResolvedConfig) => {
if (!manifest[entryPath]) {
throw new Error(`Entrypoint ${entryPath} not defined in the manifest`);
}
const manifestEntry = manifest[entryPath];
const resolveEntrypoint = (
fileInfos: OutputChunk & {viteMetadata: ChunkMetadata},
bundle: OutputBundle,
config: ResolvedConfig,
legacyEntryPoint: Boolean | String,
isCSSOrJsEntry: Boolean
) => {

@@ -37,11 +93,14 @@ const js: string[] = [];

if (manifestEntry.imports) {
for (const importEntryName of manifestEntry.imports) {
const { css: importCss, preload: importPreload } = parseManifestEntry(
{
entryPath: importEntryName,
entryType: "js",
},
manifest,
if (fileInfos.imports) {
for (const importEntryName of fileInfos.imports) {
let importFileInfos = <OutputChunk & {viteMetadata: ChunkMetadata}>bundle[importEntryName];
if (!importFileInfos) {
throw new Error(`Unable to find ${importEntryName}`);
}
const {css: importCss, preload: importPreload } = resolveEntrypoint(
importFileInfos,
bundle,
config,
false,
false
);

@@ -62,28 +121,29 @@

if (manifestEntry.isEntry) {
if (entryType === "js") {
js.push(`${config.base}${manifestEntry.file}`);
} else if (entryType === "css") {
css.push(`${config.base}${manifestEntry.file}`);
let filePath = `${config.base}${fileInfos.fileName}`
if (isCSSOrJsEntry) {
if (fileInfos.isEntry) {
// it is a JS file
js.push(filePath)
} else {
css.push(filePath)
}
} else if (preload.indexOf(`${config.base}${manifestEntry.file}`) === -1) {
preload.push(`${config.base}${manifestEntry.file}`);
} else if (preload.indexOf(filePath) === -1) {
preload.push(filePath);
}
if (manifestEntry.css) {
manifestEntry.css.forEach((cssEntry) => {
if (css.indexOf(`${config.base}${cssEntry}`) === -1) {
css.push(`${config.base}${cssEntry}`);
}
});
if (fileInfos.viteMetadata?.importedCss.size) {
fileInfos.viteMetadata.importedCss.forEach(cssFilePath => {
css.push(`${config.base}${cssFilePath}`);
})
}
return { js, css, preload, legacy: legacyEntryPoint };
}
return { js, css, preload };
};
const parseInput = (config: ResolvedConfig) => {
const inputParsed: ParsedInput = {};
// let isLegacy = (options.format === 'system' && bundle[chunkName].name.includes('-legacy'));
for (const [entryName, entryPath] of Object.entries(config.build.rollupOptions.input)) {
const entryAbsolutePath = resolve(cwd(), entryPath).replace(/\\/g, "/");
const entryAbsolutePath = normalizePath(resolve(cwd(), entryPath));

@@ -111,2 +171,23 @@ if (entryAbsolutePath.indexOf(config.root) !== 0) {

export { getDevEntryPoints, getBuildEntryPoints };
export const getEntryFilesMapping = (config: ResolvedConfig) => {
const inputParsed: EntryFilesMapping = {};
// let isLegacy = (options.format === 'system' && bundle[chunkName].name.includes('-legacy'));
for (const [entryName, entryPath] of Object.entries(config.build.rollupOptions.input)) {
const entryAbsolutePath = normalizePath(resolve(cwd(), entryPath));
if (entryAbsolutePath.indexOf(config.root) !== 0) {
console.error("Entry points must be inside Vite root directory");
process.exit(1);
}
const entryRelativePath = entryAbsolutePath.substring(config.root.length + 1);
inputParsed[entryName] = entryRelativePath;
}
return inputParsed;
};
export { getDevEntryPoints, addBuildEntryPoints };

@@ -8,4 +8,4 @@ import { Plugin, UserConfig, ResolvedConfig, ViteDevServer } from "vite";

import { getDevEntryPoints, getBuildEntryPoints } from "./configResolver";
import { getAssets } from "./assetsResolver";
import { getDevEntryPoints, addBuildEntryPoints } from "./configResolver";
import { addBuildAssets } from "./assetsResolver";
import { writeJson, emptyDir } from "./fileHelper";

@@ -135,5 +135,10 @@

let viteConfig: ResolvedConfig;
let entryPointsPath: string;
let viteDevServerUrl: string;
let entryPointsFilename = "entrypoints.json";
let entryPoints: EntryPoints = {};
let assets: StringMapping = {};
let outputCount: number = 0;
return {

@@ -152,3 +157,2 @@ name: "symfony",

build: {
manifest: true,
outDir: userConfig.build?.outDir ?? resolveOutDir(pluginOptions),

@@ -173,3 +177,2 @@ },

viteConfig = config;
entryPointsPath = resolve(config.root, config.build.outDir, "entrypoints.json");
},

@@ -200,2 +203,4 @@ configureServer(devServer) {

const entryPoints = getDevEntryPoints(viteConfig, viteDevServerUrl);
let entryPointsPath = resolve(viteConfig.root, viteConfig.build.outDir, entryPointsFilename);
writeJson(entryPointsPath, {

@@ -209,2 +214,3 @@ isProd: false,

assets: null,
legacy: false
});

@@ -269,20 +275,27 @@ }

},
writeBundle(options, bundles) {
if (!bundles["manifest.json"] || bundles["manifest.json"].type !== "asset") {
console.error("manifest.json not generated, vite-plugin-symfony need `build.manifest: true`");
process.exit(1);
}
const manifest = JSON.parse(bundles["manifest.json"].source.toString());
const entryPoints = getBuildEntryPoints(viteConfig, manifest);
const assets = getAssets(viteConfig, bundles);
generateBundle(options, bundle) {
writeJson(entryPointsPath, {
isProd: true,
viteServer: false,
entryPoints,
assets,
});
addBuildEntryPoints(options, viteConfig, bundle, entryPoints);
addBuildAssets(viteConfig, bundle, assets);
outputCount++;
const output = viteConfig.build.rollupOptions?.output
const outputLength = Array.isArray(output) ? output.length : 1;
if (outputCount >= outputLength) {
this.emitFile({
fileName: entryPointsFilename,
type: 'asset',
source: JSON.stringify({
isProd: true,
viteServer: false,
entryPoints,
assets,
legacy: typeof entryPoints['polyfills-legacy'] !== "undefined"
}, null, 2)
})
}
},
};
}

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

// declare module 'rollup' {
// export interface RenderedChunk {
// viteMetadata: ChunkMetadata
// }
// }
interface ChunkMetadata {
importedAssets: Set<string>
importedCss: Set<string>
}
type EntryPointsFile = {

@@ -10,2 +21,4 @@ isProd: boolean;

entryPoints: EntryPoints;
assets: StringMapping;
legacy: Boolean
};

@@ -17,2 +30,3 @@

preload?: string[];
legacy?: Boolean | String;
};

@@ -23,2 +37,6 @@ type EntryPoints = {

type StringMapping = {
[k: string]: string
};
type ParsedInput = {

@@ -33,2 +51,6 @@ [k: string]: ParsedEntry;

type EntryFilesMapping = {
[k: string]: string;
}
type ManifestEntry = {

@@ -35,0 +57,0 @@ file: string;

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