Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: remove Deno shim to esbuild "banner" #3734

Merged
merged 4 commits into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/spotty-islands-raise.md
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions packages/integrations/deno/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions packages/integrations/deno/src/server.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
5 changes: 0 additions & 5 deletions packages/integrations/deno/src/shim.ts

This file was deleted.

4 changes: 0 additions & 4 deletions packages/integrations/netlify/src/edge-shim.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
Expand Down