fix: enable node builtins (#1771)
* fix: enable node builtins * fix: update bare node builtin test * test: update fixture to support node@12
This commit is contained in:
parent
ae553a145d
commit
06446d14a3
4 changed files with 12 additions and 15 deletions
|
@ -2,6 +2,7 @@ import type { AstroConfig } from '../@types/astro';
|
||||||
import type { AstroDevServer } from './dev';
|
import type { AstroDevServer } from './dev';
|
||||||
import type { LogOptions } from './logger';
|
import type { LogOptions } from './logger';
|
||||||
|
|
||||||
|
import { builtinModules } from 'module';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import vite from './vite.js';
|
import vite from './vite.js';
|
||||||
import astroVitePlugin from '../vite-plugin-astro/index.js';
|
import astroVitePlugin from '../vite-plugin-astro/index.js';
|
||||||
|
@ -14,6 +15,7 @@ import { resolveDependency } from './util.js';
|
||||||
|
|
||||||
// Some packages are just external, and that’s the way it goes.
|
// Some packages are just external, and that’s the way it goes.
|
||||||
const ALWAYS_EXTERNAL = new Set([
|
const ALWAYS_EXTERNAL = new Set([
|
||||||
|
...builtinModules.map(name => `node:${name}`),
|
||||||
'@sveltejs/vite-plugin-svelte',
|
'@sveltejs/vite-plugin-svelte',
|
||||||
'estree-util-value-to-estree',
|
'estree-util-value-to-estree',
|
||||||
'micromark-util-events-to-acorn',
|
'micromark-util-events-to-acorn',
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
/**
|
|
||||||
* UNCOMMENT: Fix "Unexpected "\x00" bug
|
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import cheerio from 'cheerio';
|
import cheerio from 'cheerio';
|
||||||
import { loadFixture } from './test-utils.js';
|
import { loadFixture } from './test-utils.js';
|
||||||
|
@ -11,7 +9,6 @@ before(async () => {
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
});
|
});
|
||||||
|
|
||||||
// TODO: find a way to build one file at-a-time (different fixtures?)
|
|
||||||
describe('Node builtins', () => {
|
describe('Node builtins', () => {
|
||||||
it('Can be used with the node: prefix', async () => {
|
it('Can be used with the node: prefix', async () => {
|
||||||
// node:fs/promise is not supported in Node v12. Test currently throws.
|
// node:fs/promise is not supported in Node v12. Test currently throws.
|
||||||
|
@ -25,12 +22,10 @@ describe('Node builtins', () => {
|
||||||
expect($('#dep-version').text()).to.equal('0.0.1');
|
expect($('#dep-version').text()).to.equal('0.0.1');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Throw if using the non-prefixed version', async () => {
|
it('Can also be used with the non-prefixed version', async () => {
|
||||||
const result = await fixture.readFile('/bare/index.html');
|
const html = await fixture.readFile('/bare/index.html');
|
||||||
expect(result.status).to.equal(500);
|
const $ = cheerio.load(html);
|
||||||
expect(result.body).to.include('Use node:fs instead');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
|
|
||||||
it.skip('is skipped', () => {});
|
expect($('h1').text()).to.equal('true');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
---
|
---
|
||||||
import fs from 'node:fs/promises';
|
import { promises as fs } from 'node:fs';
|
||||||
|
|
||||||
const url = new URL('../../package.json', import.meta.url);
|
const url = new URL('../../package.json', import.meta.url);
|
||||||
const json = await fs.readFile(url, 'utf-8');
|
const json = await fs.readFile(url, 'utf-8');
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
---
|
---
|
||||||
import fs from 'fs';
|
import { builtinModules } from 'module';
|
||||||
---
|
---
|
||||||
|
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>This should throw</title>
|
<title>Bare node import</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Test</h1>
|
<h1>{Array.isArray(builtinModules)}</h1>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
Loading…
Reference in a new issue