From bf6aab7427895fcc9def5de6ac4bf764df52a164 Mon Sep 17 00:00:00 2001 From: matthewp Date: Wed, 23 Jun 2021 20:02:44 +0000 Subject: [PATCH] [ci] yarn format --- docs/api.md | 7 ++++--- packages/astro/src/compiler/codegen/index.ts | 2 +- packages/astro/src/external.ts | 8 +------- packages/astro/src/node_builtins.ts | 5 ++--- packages/astro/src/runtime.ts | 4 ++-- 5 files changed, 10 insertions(+), 16 deletions(-) diff --git a/docs/api.md b/docs/api.md index 205d4d92a..05b722747 100644 --- a/docs/api.md +++ b/docs/api.md @@ -179,9 +179,9 @@ export default function () { Astro aims to be compatible with multiple JavaScript runtimes in the future. This includes [Deno](https://deno.land/) and [Cloudflare Workers](https://workers.cloudflare.com/) which do not support Node builtin modules such as `fs`. We encourage Astro users to write their code as cross-environment as possible. -Due to that, you cannot use Node modules that you're familiar with such as `fs` and `path`. Our aim is to provide alternative built in to Astro. If you're use case is not covered please let us know. +Due to that, you cannot use Node modules that you're familiar with such as `fs` and `path`. Our aim is to provide alternative built in to Astro. If you're use case is not covered please let us know. -However, if you *really* need to use these builtin modules we don't want to stop you. Node supports the `node:` prefix for importing builtins, and this is also supported by Astro. If you want to read a file, for example, you can do so like this: +However, if you _really_ need to use these builtin modules we don't want to stop you. Node supports the `node:` prefix for importing builtins, and this is also supported by Astro. If you want to read a file, for example, you can do so like this: ```jsx --- @@ -192,4 +192,5 @@ const json = await fs.readFile(url, 'utf-8'); const data = JSON.parse(json); --- -Version: {data.version} \ No newline at end of file +Version: {data.version} +``` diff --git a/packages/astro/src/compiler/codegen/index.ts b/packages/astro/src/compiler/codegen/index.ts index 96de21796..531c502f7 100644 --- a/packages/astro/src/compiler/codegen/index.ts +++ b/packages/astro/src/compiler/codegen/index.ts @@ -328,7 +328,7 @@ function compileModule(module: Script, state: CodegenState, compileOptions: Comp for (const componentImport of componentImports) { const importUrl = componentImport.source.value; - if(nodeBuiltinsSet.has(importUrl)) { + if (nodeBuiltinsSet.has(importUrl)) { throw new Error(`Node builtins must be prefixed with 'node:'. Use node:${importUrl} instead.`); } for (const specifier of componentImport.specifiers) { diff --git a/packages/astro/src/external.ts b/packages/astro/src/external.ts index c48d6d4e1..f87a9b00f 100644 --- a/packages/astro/src/external.ts +++ b/packages/astro/src/external.ts @@ -18,13 +18,7 @@ const isAstroRenderer = (name: string) => { // These packages should NOT be built by `esinstall` // But might not be explicit dependencies of `astro` -const denyList = [ - 'prismjs/components/index.js', - '@vue/server-renderer', - '@astrojs/markdown-support', - 'node:fs/promises', - ...nodeBuiltinsMap.values() -]; +const denyList = ['prismjs/components/index.js', '@vue/server-renderer', '@astrojs/markdown-support', 'node:fs/promises', ...nodeBuiltinsMap.values()]; export default Object.keys(pkg.dependencies) // Filter out packages that should be loaded threw Snowpack diff --git a/packages/astro/src/node_builtins.ts b/packages/astro/src/node_builtins.ts index dad2afd96..e0d0bc797 100644 --- a/packages/astro/src/node_builtins.ts +++ b/packages/astro/src/node_builtins.ts @@ -1,5 +1,4 @@ - -import {builtinModules} from 'module'; +import { builtinModules } from 'module'; export const nodeBuiltinsSet = new Set(builtinModules); -export const nodeBuiltinsMap = new Map(builtinModules.map(bareName => [bareName, 'node:' + bareName])); \ No newline at end of file +export const nodeBuiltinsMap = new Map(builtinModules.map((bareName) => [bareName, 'node:' + bareName])); diff --git a/packages/astro/src/runtime.ts b/packages/astro/src/runtime.ts index 477da6df8..e859a60d5 100644 --- a/packages/astro/src/runtime.ts +++ b/packages/astro/src/runtime.ts @@ -391,8 +391,8 @@ async function createSnowpack(astroConfig: AstroConfig, options: CreateSnowpackO external: snowpackExternals, }, alias: { - ...Object.fromEntries(nodeBuiltinsMap) - } + ...Object.fromEntries(nodeBuiltinsMap), + }, }); snowpack = await startSnowpackServer(