@atelier-wb/vite-plugin-atelier
Advanced tools
Comparing version 0.12.0-beta.0 to 0.12.0-beta.1
{ | ||
"name": "@atelier-wb/vite-plugin-atelier", | ||
"version": "0.12.0-beta.0", | ||
"version": "0.12.0-beta.1", | ||
"description": "Helps you buildind Component Driven UIs with Atelier and Vite", | ||
@@ -10,3 +10,3 @@ "main": "src/index.js", | ||
"sirv": "^2.0.3", | ||
"@atelier-wb/ui": "0.12.0-beta.0" | ||
"@atelier-wb/ui": "0.12.0-beta.1" | ||
}, | ||
@@ -13,0 +13,0 @@ "peerDependencies": { |
import Ajv from 'ajv' | ||
import { createReadStream } from 'fs' | ||
import { cp, readdir, readFile, rm, stat, writeFile } from 'fs/promises' | ||
@@ -8,3 +7,3 @@ import { createRequire } from 'module' | ||
import { fileURLToPath } from 'url' | ||
import { normalizePath, searchForWorkspaceRoot } from 'vite' | ||
import { mergeConfig, normalizePath, searchForWorkspaceRoot } from 'vite' | ||
@@ -56,3 +55,4 @@ const ui = dirname(createRequire(import.meta.url).resolve('@atelier-wb/ui')) | ||
uiSettings: {}, | ||
outDir: 'dist-atelier' | ||
outDir: 'dist-atelier', | ||
unoGlobalCSSPlaceholder: '%unocss-svelte-scoped.global%' | ||
} | ||
@@ -124,2 +124,29 @@ | ||
async function invokeConfigResolved(plugins, config) { | ||
for (const plugin of plugins) { | ||
if ( | ||
plugin?.name !== pluginName && | ||
typeof plugin?.configResolved === 'function' | ||
) { | ||
config = mergeConfig((await plugin.configResolved(config)) ?? {}, config) | ||
} | ||
} | ||
} | ||
async function invokeTransformIndexHtml(plugins, content, context) { | ||
for (const plugin of plugins) { | ||
if (typeof plugin?.transformIndexHtml === 'function') { | ||
const result = await plugin.transformIndexHtml(content, context) | ||
// https://vitejs.dev/guide/api-plugin.html#transformindexhtml | ||
// HtmlTagDescriptor are not supported yet | ||
if (typeof result === 'string') { | ||
content = result | ||
} else if (typeof result === 'object' && result.html) { | ||
content = result.html | ||
} | ||
} | ||
} | ||
return content | ||
} | ||
export default function AtelierPlugin( | ||
@@ -155,2 +182,3 @@ pluginOptions = {}, | ||
let entryFile | ||
let vitePlugins = [] | ||
@@ -187,2 +215,5 @@ return { | ||
async configResolved(viteConfig) { | ||
vitePlugins = viteConfig.plugins ?? [] | ||
await invokeConfigResolved(vitePlugins, viteConfig) | ||
if (isExporting) { | ||
@@ -207,2 +238,10 @@ root = viteConfig.root | ||
const serves = statics.map(dir => sirv(dir, { etag: true })) | ||
const content = (await readFile(options.workframeHtml, 'utf8')).replace( | ||
vitePlugins.some( | ||
({ name }) => name === 'unocss:svelte-scoped:global-styles' | ||
) | ||
? '</head>' | ||
: 'does-not-exist', | ||
`${options.unoGlobalCSSPlaceholder}\n</head>` | ||
) | ||
@@ -217,3 +256,7 @@ // configure a middleware for serving Atelier | ||
}) | ||
createReadStream(options.workframeHtml).pipe(response) | ||
invokeTransformIndexHtml(vitePlugins, content, { | ||
path: options.workframeHtml, | ||
fileName: options.workframeHtml | ||
}).then(result => response.end(result)) | ||
} else if (request.url === `/${settingsFile}`) { | ||
@@ -220,0 +263,0 @@ response.writeHead(200, { |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
14861
298
3
+ Added@atelier-wb/ui@0.12.0-beta.1(transitive)
- Removed@atelier-wb/ui@0.12.0-beta.0(transitive)
Updated@atelier-wb/ui@0.12.0-beta.1