Refactor: remove Deno shim to esbuild "banner" (#3734)
* refactor: remove Deno shim to esbuild "banner" * refactor: move shim to const * refactor: add shim to netlify edge * chore: changeset
This commit is contained in:
parent
701799c6d6
commit
4acd245d8f
7 changed files with 22 additions and 15 deletions
6
.changeset/spotty-islands-raise.md
Normal file
6
.changeset/spotty-islands-raise.md
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
---
|
||||||
|
'@astrojs/deno': patch
|
||||||
|
'@astrojs/netlify': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fix: append shim to top of built file to avoid "can't read process of undefined" issues
|
|
@ -9,6 +9,11 @@ interface Options {
|
||||||
hostname?: string;
|
hostname?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SHIM = `globalThis.process = {
|
||||||
|
argv: [],
|
||||||
|
env: Deno.env.toObject(),
|
||||||
|
};`
|
||||||
|
|
||||||
export function getAdapter(args?: Options): AstroAdapter {
|
export function getAdapter(args?: Options): AstroAdapter {
|
||||||
return {
|
return {
|
||||||
name: '@astrojs/deno',
|
name: '@astrojs/deno',
|
||||||
|
@ -63,6 +68,9 @@ export default function createIntegration(args?: Options): AstroIntegration {
|
||||||
format: 'esm',
|
format: 'esm',
|
||||||
bundle: true,
|
bundle: true,
|
||||||
external: ['@astrojs/markdown-remark'],
|
external: ['@astrojs/markdown-remark'],
|
||||||
|
banner: {
|
||||||
|
js: SHIM,
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove chunks, if they exist. Since we have bundled via esbuild these chunks are trash.
|
// Remove chunks, if they exist. Since we have bundled via esbuild these chunks are trash.
|
||||||
|
|
|
@ -1,8 +1,3 @@
|
||||||
// NOTE(fks): Side-effect -- shim.js must run first. This isn't guaranteed by
|
|
||||||
// the language, but it is a Node.js behavior that we rely on here. Keep this
|
|
||||||
// separate from the other imports so that it doesn't get organized & reordered.
|
|
||||||
import './shim.js';
|
|
||||||
|
|
||||||
// Normal Imports
|
// Normal Imports
|
||||||
import type { SSRManifest } from 'astro';
|
import type { SSRManifest } from 'astro';
|
||||||
import { App } from 'astro/app';
|
import { App } from 'astro/app';
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
(globalThis as any).process = {
|
|
||||||
argv: [],
|
|
||||||
// @ts-ignore
|
|
||||||
env: Deno.env.toObject(),
|
|
||||||
};
|
|
|
@ -1,4 +0,0 @@
|
||||||
(globalThis as any).process = {
|
|
||||||
argv: [],
|
|
||||||
env: {},
|
|
||||||
};
|
|
|
@ -6,6 +6,11 @@ import { fileURLToPath } from 'url';
|
||||||
import type { Plugin as VitePlugin } from 'vite';
|
import type { Plugin as VitePlugin } from 'vite';
|
||||||
import { createRedirects } from './shared.js';
|
import { createRedirects } from './shared.js';
|
||||||
|
|
||||||
|
const SHIM = `globalThis.process = {
|
||||||
|
argv: [],
|
||||||
|
env: {},
|
||||||
|
};`;
|
||||||
|
|
||||||
export function getAdapter(): AstroAdapter {
|
export function getAdapter(): AstroAdapter {
|
||||||
return {
|
return {
|
||||||
name: '@astrojs/netlify/edge-functions',
|
name: '@astrojs/netlify/edge-functions',
|
||||||
|
@ -78,6 +83,9 @@ async function bundleServerEntry(buildConfig: BuildConfig, vite: any) {
|
||||||
format: 'esm',
|
format: 'esm',
|
||||||
bundle: true,
|
bundle: true,
|
||||||
external: ['@astrojs/markdown-remark'],
|
external: ['@astrojs/markdown-remark'],
|
||||||
|
banner: {
|
||||||
|
js: SHIM,
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Remove chunks, if they exist. Since we have bundled via esbuild these chunks are trash.
|
// Remove chunks, if they exist. Since we have bundled via esbuild these chunks are trash.
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import type { SSRManifest } from 'astro';
|
import type { SSRManifest } from 'astro';
|
||||||
import { App } from 'astro/app';
|
import { App } from 'astro/app';
|
||||||
import './edge-shim.js';
|
|
||||||
|
|
||||||
export function createExports(manifest: SSRManifest) {
|
export function createExports(manifest: SSRManifest) {
|
||||||
const app = new App(manifest);
|
const app = new App(manifest);
|
||||||
|
|
Loading…
Reference in a new issue