0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-03-10 23:01:26 -05:00

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
This commit is contained in:
Matthew Phillips 2021-07-01 16:22:47 -04:00 committed by GitHub
parent 816797e350
commit 2d3e369da7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 64 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
'astro': patch
---
Fix for using the snowpack polyfillNode option

View file

@ -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": {

View file

@ -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,

View file

@ -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();

View file

@ -0,0 +1,7 @@
{
"name": "@astrojs/astro-test-builtins-polyfillnode",
"version": "1.2.0",
"dependencies": {
"file-url": "4.0.0"
}
}

View file

@ -0,0 +1,6 @@
{
"workspaceRoot": "../../../../../",
"packageOptions": {
"polyfillNode": false
}
}

View file

@ -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>

View file

@ -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"