summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Matthew Phillips <matthew@matthewphillips.info> 2021-07-01 16:22:47 -0400
committerGravatar GitHub <noreply@github.com> 2021-07-01 16:22:47 -0400
commit2d3e369da70fd4132430de4747f883a9d5f30c7b (patch)
treea8df5a9a4708626c54e0408bfd85b409f68c83f8
parent816797e350c452882fdbe1b8ed845cd74ef6cd44 (diff)
downloadastro-2d3e369da70fd4132430de4747f883a9d5f30c7b.tar.gz
astro-2d3e369da70fd4132430de4747f883a9d5f30c7b.tar.zst
astro-2d3e369da70fd4132430de4747f883a9d5f30c7b.zip
Don't alias builtins if polyfillNode is used (#601)
* Don't alias builtins if polyfillNode is used * Add the changeset * Make test be OS agnostic
-rw-r--r--.changeset/bright-cherries-juggle.md5
-rw-r--r--package.json1
-rw-r--r--packages/astro/src/runtime.ts10
-rw-r--r--packages/astro/test/builtins-polyfillnode.test.js19
-rw-r--r--packages/astro/test/fixtures/builtins-polyfillnode/package.json7
-rw-r--r--packages/astro/test/fixtures/builtins-polyfillnode/snowpack.config.json6
-rw-r--r--packages/astro/test/fixtures/builtins-polyfillnode/src/pages/index.astro12
-rw-r--r--yarn.lock8
8 files changed, 64 insertions, 4 deletions
diff --git a/.changeset/bright-cherries-juggle.md b/.changeset/bright-cherries-juggle.md
new file mode 100644
index 000000000..bc9fc6134
--- /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 b6a6cec00..b68d1596b 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 53a5fa8bb..a12f5d4fe 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 000000000..8fef5e8e9
--- /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 000000000..1c1382619
--- /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 000000000..3c503c831
--- /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 000000000..8286f1ed1
--- /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');
+---
+
+<html>
+<head><title>Testing</title></head>
+<body>
+ <div id="url">{r}</div>
+</body>
+</html> \ No newline at end of file
diff --git a/yarn.lock b/yarn.lock
index 5cd35649d..e29b9886d 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -62,6 +62,9 @@
time-require "^0.1.2"
valid-url "^1.0.9"
+"@astrojs/astro-test-builtins-dep2@file:./packages/astro/test/fixtures/builtins-polyfillnode/packages/dep":
+ version "0.0.1"
+
"@babel/code-frame@7.12.11":
version "7.12.11"
resolved "https://registry.npmjs.org/@babel/code-frame/-/code-frame-7.12.11.tgz"
@@ -4143,6 +4146,11 @@ file-entry-cache@^6.0.1:
dependencies:
flat-cache "^3.0.4"
+file-url@4.0.0:
+ version "4.0.0"
+ resolved "https://registry.yarnpkg.com/file-url/-/file-url-4.0.0.tgz#6fe05262d3187da70bc69889091932b6bc7df270"
+ integrity sha512-vRCdScQ6j3Ku6Kd7W1kZk9c++5SqD6Xz5Jotrjr/nkY714M14RFHy/AAVA2WQvpsqVAVgTbDrYyBpU205F0cLw==
+
fill-range@^7.0.1:
version "7.0.1"
resolved "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz"