@lagon/astro
Advanced tools
Comparing version 0.2.3 to 0.3.0
# @lagon/astro | ||
## 0.3.0 | ||
### Minor Changes | ||
- [#845](https://github.com/lagonapp/lagon/pull/845) [`56cb476`](https://github.com/lagonapp/lagon/commit/56cb476e3d5edf32499ac20bf36c77c9fc2cb4e0) Thanks [@QuiiBz](https://github.com/QuiiBz)! - Write Lagon config if not present when building | ||
## 0.2.3 | ||
@@ -4,0 +10,0 @@ |
// src/index.ts | ||
import esbuild from "esbuild"; | ||
import * as fs from "fs"; | ||
import * as npath from "path"; | ||
import { fileURLToPath } from "url"; | ||
import * as fs from "node:fs/promises"; | ||
import * as path from "node:path"; | ||
import { fileURLToPath } from "node:url"; | ||
function getAdapter(args) { | ||
@@ -40,5 +40,4 @@ return { | ||
} | ||
vite.ssr = { | ||
noExternal: true | ||
}; | ||
vite.ssr = vite.ssr || {}; | ||
vite.ssr.target = vite.ssr.target || "webworker"; | ||
} | ||
@@ -57,11 +56,39 @@ }, | ||
bundle: true, | ||
external: ["@astrojs/markdown-remark"] | ||
minify: _vite.build?.minify !== false | ||
}); | ||
const configPath = path.join(_vite.root, ".lagon/config.json"); | ||
let shouldCreateConfig = false; | ||
try { | ||
const chunkFileNames = _vite?.build?.rollupOptions?.output?.chunkFileNames ?? "chunks/chunk.[hash].mjs"; | ||
const chunkPath = npath.dirname(chunkFileNames); | ||
await fs.access(configPath); | ||
shouldCreateConfig = false; | ||
} catch { | ||
shouldCreateConfig = true; | ||
} | ||
if (shouldCreateConfig) { | ||
const index = path.relative(_vite.root, pth); | ||
const assets = path.relative(_vite.root, fileURLToPath(_buildConfig.client)); | ||
console.log(); | ||
console.log("Wrote Lagon configuration to .lagon/config.json"); | ||
await fs.mkdir(path.dirname(configPath), { recursive: true }); | ||
await fs.writeFile( | ||
configPath, | ||
JSON.stringify({ | ||
function_id: "", | ||
organization_id: "", | ||
index, | ||
client: null, | ||
assets | ||
}) | ||
); | ||
} | ||
try { | ||
const chunkFileNames = _vite.build?.rollupOptions?.output?.chunkFileNames ?? "chunks/chunk.[hash].mjs"; | ||
const chunkPath = path.dirname(chunkFileNames); | ||
const chunksDirUrl = new URL(chunkPath + "/", _buildConfig.server); | ||
await fs.promises.rm(chunksDirUrl, { recursive: true, force: true }); | ||
await fs.rm(chunksDirUrl, { recursive: true, force: true }); | ||
} catch { | ||
} | ||
console.log(); | ||
console.log("Run `lagon dev` / `lagon deploy` to start your app!"); | ||
console.log(); | ||
} | ||
@@ -68,0 +95,0 @@ } |
{ | ||
"name": "@lagon/astro", | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"description": "Astro integration to deploy your site to Lagon", | ||
@@ -5,0 +5,0 @@ "type": "module", |
import type { AstroAdapter, AstroIntegration } from 'astro'; | ||
import esbuild from 'esbuild'; | ||
import * as fs from 'fs'; | ||
import * as npath from 'path'; | ||
import { fileURLToPath } from 'url'; | ||
import * as fs from 'node:fs/promises'; | ||
import * as path from 'node:path'; | ||
import { fileURLToPath } from 'node:url'; | ||
@@ -50,6 +50,4 @@ interface Options { | ||
} | ||
vite.ssr = { | ||
noExternal: true, | ||
}; | ||
vite.ssr = vite.ssr || {}; | ||
vite.ssr.target = vite.ssr.target || 'webworker'; | ||
} | ||
@@ -68,14 +66,48 @@ }, | ||
bundle: true, | ||
external: ['@astrojs/markdown-remark'], | ||
minify: _vite.build?.minify !== false, | ||
}); | ||
const configPath = path.join(_vite.root, '.lagon/config.json'); | ||
let shouldCreateConfig = false; | ||
try { | ||
await fs.access(configPath); | ||
shouldCreateConfig = false; | ||
} catch { | ||
shouldCreateConfig = true; | ||
} | ||
if (shouldCreateConfig) { | ||
const index = path.relative(_vite.root, pth); | ||
const assets = path.relative(_vite.root, fileURLToPath(_buildConfig.client)); | ||
console.log(); | ||
console.log('Wrote Lagon configuration to .lagon/config.json'); | ||
await fs.mkdir(path.dirname(configPath), { recursive: true }); | ||
await fs.writeFile( | ||
configPath, | ||
JSON.stringify({ | ||
function_id: '', | ||
organization_id: '', | ||
index, | ||
client: null, | ||
assets, | ||
}), | ||
); | ||
} | ||
// Remove chunks, if they exist. Since we have bundled via esbuild these chunks are trash. | ||
try { | ||
const chunkFileNames = _vite?.build?.rollupOptions?.output?.chunkFileNames ?? 'chunks/chunk.[hash].mjs'; | ||
const chunkPath = npath.dirname(chunkFileNames); | ||
const chunkFileNames = _vite.build?.rollupOptions?.output?.chunkFileNames ?? 'chunks/chunk.[hash].mjs'; | ||
const chunkPath = path.dirname(chunkFileNames); | ||
const chunksDirUrl = new URL(chunkPath + '/', _buildConfig.server); | ||
await fs.promises.rm(chunksDirUrl, { recursive: true, force: true }); | ||
await fs.rm(chunksDirUrl, { recursive: true, force: true }); | ||
} catch { | ||
// No chunks to remove. | ||
} | ||
console.log(); | ||
console.log('Run `lagon dev` / `lagon deploy` to start your app!'); | ||
console.log(); | ||
}, | ||
@@ -82,0 +114,0 @@ }, |
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
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
47897
266
0