summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Ben Holmes <hey@bholmes.dev> 2022-06-27 17:20:28 -0400
committerGravatar GitHub <noreply@github.com> 2022-06-27 17:20:28 -0400
commit4acd245d8f59871eb9c0083ae1a0fe7aa70c84f5 (patch)
tree1ae08bb6c7014521175bacdb7437673e56321d8c
parent701799c6d68bc48b75a13e64ffff6f51dc4f4858 (diff)
downloadastro-4acd245d8f59871eb9c0083ae1a0fe7aa70c84f5.tar.gz
astro-4acd245d8f59871eb9c0083ae1a0fe7aa70c84f5.tar.zst
astro-4acd245d8f59871eb9c0083ae1a0fe7aa70c84f5.zip
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
-rw-r--r--.changeset/spotty-islands-raise.md6
-rw-r--r--packages/integrations/deno/src/index.ts8
-rw-r--r--packages/integrations/deno/src/server.ts5
-rw-r--r--packages/integrations/deno/src/shim.ts5
-rw-r--r--packages/integrations/netlify/src/edge-shim.ts4
-rw-r--r--packages/integrations/netlify/src/integration-edge-functions.ts8
-rw-r--r--packages/integrations/netlify/src/netlify-edge-functions.ts1
7 files changed, 22 insertions, 15 deletions
diff --git a/.changeset/spotty-islands-raise.md b/.changeset/spotty-islands-raise.md
new file mode 100644
index 000000000..f8246006d
--- /dev/null
+++ b/.changeset/spotty-islands-raise.md
@@ -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
diff --git a/packages/integrations/deno/src/index.ts b/packages/integrations/deno/src/index.ts
index 0dad8e8ef..a104ba863 100644
--- a/packages/integrations/deno/src/index.ts
+++ b/packages/integrations/deno/src/index.ts
@@ -9,6 +9,11 @@ interface Options {
hostname?: string;
}
+const SHIM = `globalThis.process = {
+ argv: [],
+ env: Deno.env.toObject(),
+};`
+
export function getAdapter(args?: Options): AstroAdapter {
return {
name: '@astrojs/deno',
@@ -63,6 +68,9 @@ export default function createIntegration(args?: Options): AstroIntegration {
format: 'esm',
bundle: true,
external: ['@astrojs/markdown-remark'],
+ banner: {
+ js: SHIM,
+ }
});
// Remove chunks, if they exist. Since we have bundled via esbuild these chunks are trash.
diff --git a/packages/integrations/deno/src/server.ts b/packages/integrations/deno/src/server.ts
index 9d2fc98a9..f6dbcb62c 100644
--- a/packages/integrations/deno/src/server.ts
+++ b/packages/integrations/deno/src/server.ts
@@ -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
import type { SSRManifest } from 'astro';
import { App } from 'astro/app';
diff --git a/packages/integrations/deno/src/shim.ts b/packages/integrations/deno/src/shim.ts
deleted file mode 100644
index 62e82ba30..000000000
--- a/packages/integrations/deno/src/shim.ts
+++ /dev/null
@@ -1,5 +0,0 @@
-(globalThis as any).process = {
- argv: [],
- // @ts-ignore
- env: Deno.env.toObject(),
-};
diff --git a/packages/integrations/netlify/src/edge-shim.ts b/packages/integrations/netlify/src/edge-shim.ts
deleted file mode 100644
index 1a4a6ee9b..000000000
--- a/packages/integrations/netlify/src/edge-shim.ts
+++ /dev/null
@@ -1,4 +0,0 @@
-(globalThis as any).process = {
- argv: [],
- env: {},
-};
diff --git a/packages/integrations/netlify/src/integration-edge-functions.ts b/packages/integrations/netlify/src/integration-edge-functions.ts
index 72788abaf..17eaf8350 100644
--- a/packages/integrations/netlify/src/integration-edge-functions.ts
+++ b/packages/integrations/netlify/src/integration-edge-functions.ts
@@ -6,6 +6,11 @@ import { fileURLToPath } from 'url';
import type { Plugin as VitePlugin } from 'vite';
import { createRedirects } from './shared.js';
+const SHIM = `globalThis.process = {
+ argv: [],
+ env: {},
+};`;
+
export function getAdapter(): AstroAdapter {
return {
name: '@astrojs/netlify/edge-functions',
@@ -78,6 +83,9 @@ async function bundleServerEntry(buildConfig: BuildConfig, vite: any) {
format: 'esm',
bundle: true,
external: ['@astrojs/markdown-remark'],
+ banner: {
+ js: SHIM,
+ }
});
// Remove chunks, if they exist. Since we have bundled via esbuild these chunks are trash.
diff --git a/packages/integrations/netlify/src/netlify-edge-functions.ts b/packages/integrations/netlify/src/netlify-edge-functions.ts
index 8d3ecf107..0d2974c61 100644
--- a/packages/integrations/netlify/src/netlify-edge-functions.ts
+++ b/packages/integrations/netlify/src/netlify-edge-functions.ts
@@ -1,6 +1,5 @@
import type { SSRManifest } from 'astro';
import { App } from 'astro/app';
-import './edge-shim.js';
export function createExports(manifest: SSRManifest) {
const app = new App(manifest);