diff --git a/.changeset/bright-cherries-juggle.md b/.changeset/bright-cherries-juggle.md new file mode 100644 index 0000000000..bc9fc61340 --- /dev/null +++ b/.changeset/bright-cherries-juggle.md @@ -0,0 +1,5 @@ +--- +'astro': patch +--- + +Fix for using the snowpack polyfillNode option diff --git a/package.json b/package.json index b6a6cec00d..b68d1596bd 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ "www", "docs-www", "packages/astro/test/fixtures/builtins/packages/*", + "packages/astro/test/fixtures/builtins-polyfillnode", "packages/astro/test/fixtures/custom-elements/my-component-lib" ], "volta": { diff --git a/packages/astro/src/runtime.ts b/packages/astro/src/runtime.ts index 53a5fa8bb0..a12f5d4fed 100644 --- a/packages/astro/src/runtime.ts +++ b/packages/astro/src/runtime.ts @@ -418,12 +418,14 @@ async function createSnowpack(astroConfig: AstroConfig, options: CreateSnowpackO packageOptions: { knownEntrypoints, external, - }, - alias: { - ...Object.fromEntries(nodeBuiltinsMap), - }, + } }); + const polyfillNode = (snowpackConfig.packageOptions as any).polyfillNode as boolean; + if(!polyfillNode) { + snowpackConfig.alias = Object.fromEntries(nodeBuiltinsMap); + } + snowpack = await startSnowpackServer( { config: snowpackConfig, diff --git a/packages/astro/test/builtins-polyfillnode.test.js b/packages/astro/test/builtins-polyfillnode.test.js new file mode 100644 index 0000000000..8fef5e8e9f --- /dev/null +++ b/packages/astro/test/builtins-polyfillnode.test.js @@ -0,0 +1,19 @@ +import { suite } from 'uvu'; +import * as assert from 'uvu/assert'; +import { doc } from './test-utils.js'; +import { setup } from './helpers.js'; + +const Builtins = suite('Node builtins with polyfillNode option'); + +setup(Builtins, './fixtures/builtins-polyfillnode'); + +Builtins('Doesnt alias to node: prefix', async ({ runtime }) => { + const result = await runtime.load('/'); + if (result.error) throw new Error(result.error); + + const $ = doc(result.contents); + + assert.match($('#url').text(), new RegExp('unicorn.jpg')); +}); + +Builtins.run(); diff --git a/packages/astro/test/fixtures/builtins-polyfillnode/package.json b/packages/astro/test/fixtures/builtins-polyfillnode/package.json new file mode 100644 index 0000000000..1c13826191 --- /dev/null +++ b/packages/astro/test/fixtures/builtins-polyfillnode/package.json @@ -0,0 +1,7 @@ +{ + "name": "@astrojs/astro-test-builtins-polyfillnode", + "version": "1.2.0", + "dependencies": { + "file-url": "4.0.0" + } +} \ No newline at end of file diff --git a/packages/astro/test/fixtures/builtins-polyfillnode/snowpack.config.json b/packages/astro/test/fixtures/builtins-polyfillnode/snowpack.config.json new file mode 100644 index 0000000000..3c503c831e --- /dev/null +++ b/packages/astro/test/fixtures/builtins-polyfillnode/snowpack.config.json @@ -0,0 +1,6 @@ +{ + "workspaceRoot": "../../../../../", + "packageOptions": { + "polyfillNode": false + } +} diff --git a/packages/astro/test/fixtures/builtins-polyfillnode/src/pages/index.astro b/packages/astro/test/fixtures/builtins-polyfillnode/src/pages/index.astro new file mode 100644 index 0000000000..8286f1ed16 --- /dev/null +++ b/packages/astro/test/fixtures/builtins-polyfillnode/src/pages/index.astro @@ -0,0 +1,12 @@ +--- +import fileUrl from 'file-url'; + +const r = fileUrl('unicorn.jpg'); +--- + + +