summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Fred K. Schott <fkschott@gmail.com> 2021-07-19 18:23:39 -0700
committerGravatar GitHub <noreply@github.com> 2021-07-19 18:23:39 -0700
commita7e66666e49e3286639439cc993869b3a87ff251 (patch)
treee7d33647bdc5099a5b23268aab11fcae3d78628b
parent11100d62ef02a90ea9d0615b942e8839adc0ea45 (diff)
downloadastro-a7e66666e49e3286639439cc993869b3a87ff251.tar.gz
astro-a7e66666e49e3286639439cc993869b3a87ff251.tar.zst
astro-a7e66666e49e3286639439cc993869b3a87ff251.zip
tsconfig fix (#752)
-rw-r--r--.changeset/eight-mangos-pretend.md7
-rw-r--r--.github/workflows/nodejs.yml2
-rw-r--r--examples/blog-multiple-authors/src/layouts/post.astro2
-rw-r--r--examples/blog/src/layouts/BlogPost.astro2
-rw-r--r--examples/docs/src/layouts/Main.astro4
-rw-r--r--examples/portfolio/src/layouts/project.astro2
-rw-r--r--examples/snowpack/src/layouts/content-with-cover.astro2
-rw-r--r--examples/snowpack/src/layouts/content.astro2
-rw-r--r--examples/snowpack/src/layouts/post.astro2
-rw-r--r--examples/with-markdown-plugins/src/layouts/main.astro2
-rw-r--r--examples/with-markdown/src/layouts/main.astro2
-rw-r--r--package.json2
-rw-r--r--packages/astro-parser/tsconfig.json2
-rw-r--r--packages/astro/src/compiler/index.ts6
-rw-r--r--packages/astro/test/builtins.test.js4
-rw-r--r--packages/astro/test/helpers.js4
-rw-r--r--packages/astro/test/lit-element.test.js6
-rw-r--r--packages/astro/tsconfig.json2
-rw-r--r--packages/create-astro/tsconfig.json2
-rw-r--r--packages/markdown-support/tsconfig.json2
-rw-r--r--packages/renderers/renderer-lit/client-shim.js13
-rw-r--r--scripts/cmd/build.js6
-rwxr-xr-xscripts/index.js4
23 files changed, 49 insertions, 33 deletions
diff --git a/.changeset/eight-mangos-pretend.md b/.changeset/eight-mangos-pretend.md
new file mode 100644
index 000000000..7af96468b
--- /dev/null
+++ b/.changeset/eight-mangos-pretend.md
@@ -0,0 +1,7 @@
+---
+'astro': patch
+'@astrojs/parser': patch
+'create-astro': patch
+---
+
+compile javascript to target Node v12.x
diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml
index db7ef212f..7aefe0cc5 100644
--- a/.github/workflows/nodejs.yml
+++ b/.github/workflows/nodejs.yml
@@ -54,7 +54,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
- node-version: [14.x, 16.x]
+ node-version: [12.x, 14.x, 16.x]
steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
diff --git a/examples/blog-multiple-authors/src/layouts/post.astro b/examples/blog-multiple-authors/src/layouts/post.astro
index b34275d84..ed68459ee 100644
--- a/examples/blog-multiple-authors/src/layouts/post.astro
+++ b/examples/blog-multiple-authors/src/layouts/post.astro
@@ -6,7 +6,7 @@ import authorData from '../data/authors.json';
const { content } = Astro.props;
---
-<html lang={ content.lang ?? 'en' }>
+<html lang={ content.lang || 'en' }>
<head>
<title>{content.title}</title>
<MainHead title={content.title} description={content.description} image={content.image} canonicalURL={Astro.request.canonicalURL} />
diff --git a/examples/blog/src/layouts/BlogPost.astro b/examples/blog/src/layouts/BlogPost.astro
index 1b02d7aad..b27effe54 100644
--- a/examples/blog/src/layouts/BlogPost.astro
+++ b/examples/blog/src/layouts/BlogPost.astro
@@ -7,7 +7,7 @@ import BlogPost from '../components/BlogPost.astro';
const {content} = Astro.props;
const {title, description, publishDate, author, heroImage, permalink} = content;
---
-<html lang={ content.lang ?? 'en' }>
+<html lang={ content.lang || 'en' }>
<head>
<BaseHead title={title} description={description} permalink={permalink} />
<link rel="stylesheet" href="/blog.css" />
diff --git a/examples/docs/src/layouts/Main.astro b/examples/docs/src/layouts/Main.astro
index f358f8045..47b09a18f 100644
--- a/examples/docs/src/layouts/Main.astro
+++ b/examples/docs/src/layouts/Main.astro
@@ -10,7 +10,7 @@ import DocSidebar from '../components/DocSidebar.tsx';
// It will run during the build, but never in the browser.
// All variables are available to use in the HTML template below.
const { content } = Astro.props;
-const headers = content?.astro?.headers;
+const headers = content.astro.headers;
const currentPage = Astro.request.url.pathname;
const currentFile = currentPage === '/' ? 'src/pages/index.md' : `src/pages${currentPage.replace(/\/$/, "")}.md`;
const githubEditUrl = `https://github.com/USER/REPO/blob/main/${currentFile}`
@@ -18,7 +18,7 @@ const githubEditUrl = `https://github.com/USER/REPO/blob/main/${currentFile}`
// Full Astro Component Syntax:
// https://docs.astro.build/core-concepts/astro-components/
---
-<html lang={ content.lang ?? 'en' }>
+<html lang={ content.lang || 'en' }>
<head>
<title>{content.title}</title>
diff --git a/examples/portfolio/src/layouts/project.astro b/examples/portfolio/src/layouts/project.astro
index 3ef6d1b88..8e649ee1f 100644
--- a/examples/portfolio/src/layouts/project.astro
+++ b/examples/portfolio/src/layouts/project.astro
@@ -6,7 +6,7 @@ import Nav from '../components/Nav/index.jsx';
const { content } = Astro.props;
---
-<html lang={ content.lang ?? 'en' }>
+<html lang={ content.lang || 'en' }>
<head>
<MainHead title={content.title} />
<style lang="scss">
diff --git a/examples/snowpack/src/layouts/content-with-cover.astro b/examples/snowpack/src/layouts/content-with-cover.astro
index ccc1f671b..92b02a4cc 100644
--- a/examples/snowpack/src/layouts/content-with-cover.astro
+++ b/examples/snowpack/src/layouts/content-with-cover.astro
@@ -8,7 +8,7 @@ const { content } = Astro.props;
---
<!doctype html>
-<html lang={ content.lang ?? 'en' }>
+<html lang={ content.lang || 'en' }>
<head>
<style>
diff --git a/examples/snowpack/src/layouts/content.astro b/examples/snowpack/src/layouts/content.astro
index a69f78f17..4c442c92e 100644
--- a/examples/snowpack/src/layouts/content.astro
+++ b/examples/snowpack/src/layouts/content.astro
@@ -8,7 +8,7 @@ const { content } = Astro.props;
---
<!doctype html>
-<html lang={ content.lang ?? 'en' }>
+<html lang={ content.lang || 'en' }>
<head>
<BaseHead title={content.title} description={content.description} permalink="TODO" />
diff --git a/examples/snowpack/src/layouts/post.astro b/examples/snowpack/src/layouts/post.astro
index 0662b3f1b..bcdd697e6 100644
--- a/examples/snowpack/src/layouts/post.astro
+++ b/examples/snowpack/src/layouts/post.astro
@@ -7,7 +7,7 @@ const { content } = Astro.props;
---
<!doctype html>
-<html lang={ content.lang ?? 'en' }>
+<html lang={ content.lang || 'en' }>
<head>
<style lang="scss">
diff --git a/examples/with-markdown-plugins/src/layouts/main.astro b/examples/with-markdown-plugins/src/layouts/main.astro
index 46427fa8f..a55693970 100644
--- a/examples/with-markdown-plugins/src/layouts/main.astro
+++ b/examples/with-markdown-plugins/src/layouts/main.astro
@@ -2,7 +2,7 @@
const { content } = Astro.props;
---
-<html lang={ content.lang ?? 'en' }>
+<html lang={ content.lang || 'en' }>
<head>
<meta charset="utf-8" />
<title>{content.title}</title>
diff --git a/examples/with-markdown/src/layouts/main.astro b/examples/with-markdown/src/layouts/main.astro
index 431c0f28e..b413aa826 100644
--- a/examples/with-markdown/src/layouts/main.astro
+++ b/examples/with-markdown/src/layouts/main.astro
@@ -2,7 +2,7 @@
const { content } = Astro.props;
---
-<html lang={ content.lang ?? 'en' }>
+<html lang={ content.lang || 'en' }>
<head>
<meta charset="utf-8">
<title>{content.title}</title>
diff --git a/package.json b/package.json
index 30054ee33..7e5ec0468 100644
--- a/package.json
+++ b/package.json
@@ -64,6 +64,6 @@
"uvu": "^0.5.1"
},
"engines": {
- "node": ">=14.15.1"
+ "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
}
}
diff --git a/packages/astro-parser/tsconfig.json b/packages/astro-parser/tsconfig.json
index 7456703e4..ce4208f31 100644
--- a/packages/astro-parser/tsconfig.json
+++ b/packages/astro-parser/tsconfig.json
@@ -2,7 +2,7 @@
"extends": "../../tsconfig.base.json",
"include": ["src"],
"compilerOptions": {
- "target": "ES2020",
+ "target": "ES2019",
"module": "CommonJS",
"outDir": "./dist"
}
diff --git a/packages/astro/src/compiler/index.ts b/packages/astro/src/compiler/index.ts
index ff9c47680..329ffccc1 100644
--- a/packages/astro/src/compiler/index.ts
+++ b/packages/astro/src/compiler/index.ts
@@ -140,9 +140,9 @@ async function __render(props, ...children) {
const Astro = {
...__TopLevelAstro,
props,
- css: props[__astroInternal]?.css || [],
- request: props[__astroInternal]?.request || {},
- isPage: props[__astroInternal]?.isPage || false,
+ css: (props[__astroInternal] && props[__astroInternal].css) || [],
+ request: (props[__astroInternal] && props[__astroInternal].request) || {},
+ isPage: (props[__astroInternal] && props[__astroInternal].isPage) || false,
};
${result.script}
diff --git a/packages/astro/test/builtins.test.js b/packages/astro/test/builtins.test.js
index 23625e6f7..e54016fbd 100644
--- a/packages/astro/test/builtins.test.js
+++ b/packages/astro/test/builtins.test.js
@@ -8,6 +8,10 @@ const Builtins = suite('Node builtins');
setup(Builtins, './fixtures/builtins');
Builtins('Can be used with the node: prefix', async ({ runtime }) => {
+ // node:fs/promise is not supported in Node v12. Test currently throws.
+ if (process.versions.node <= '13') {
+ return;
+ }
const result = await runtime.load('/');
if (result.error) throw new Error(result.error);
diff --git a/packages/astro/test/helpers.js b/packages/astro/test/helpers.js
index b2eb0d9a6..33b439242 100644
--- a/packages/astro/test/helpers.js
+++ b/packages/astro/test/helpers.js
@@ -1,6 +1,6 @@
import { fileURLToPath } from 'url';
import { build as astroBuild } from '#astro/build';
-import { readFile } from 'fs/promises';
+import { readFileSync } from 'fs';
import { createRuntime } from '#astro/runtime';
import { loadConfig } from '#astro/config';
import execa from 'execa';
@@ -86,7 +86,7 @@ export function setupBuild(Suite, fixturePath) {
context.build = () => astroBuild(astroConfig, { level: 'error', dest: process.stderr });
context.readFile = async (path) => {
const resolved = fileURLToPath(new URL(`${fixturePath}/${astroConfig.dist}${path}`, import.meta.url));
- return readFile(resolved).then((r) => r.toString('utf8'));
+ return readFileSync(resolved, {encoding: 'utf8'});
};
clearTimeout(timeout);
diff --git a/packages/astro/test/lit-element.test.js b/packages/astro/test/lit-element.test.js
index d976eb67b..ef1d5ebae 100644
--- a/packages/astro/test/lit-element.test.js
+++ b/packages/astro/test/lit-element.test.js
@@ -8,6 +8,10 @@ const LitElement = suite('LitElement test');
setup(LitElement, './fixtures/lit-element');
LitElement('Renders a custom element by tag name', async ({ runtime }) => {
+ // lit SSR is not currently supported on Node.js < 13
+ if (process.versions.node <= '13') {
+ return;
+ }
const result = await runtime.load('/');
if (result.error) throw new Error(result.error);
@@ -30,7 +34,7 @@ LitElement.skip('Renders a custom element by the constructor', async ({ runtime
// The Lit renderer adds browser globals that interfere with other tests, so remove them now.
LitElement.after(() => {
- const globals = Object.keys(globalThis.window);
+ const globals = Object.keys(globalThis.window || {});
globals.splice(globals.indexOf('global'), 1);
for (let name of globals) {
delete globalThis[name];
diff --git a/packages/astro/tsconfig.json b/packages/astro/tsconfig.json
index 8f0cdf74d..6b3c4ca88 100644
--- a/packages/astro/tsconfig.json
+++ b/packages/astro/tsconfig.json
@@ -3,7 +3,7 @@
"include": ["src", "index.d.ts"],
"compilerOptions": {
"allowJs": true,
- "target": "ES2020",
+ "target": "ES2019",
"module": "ES2020",
"outDir": "./dist",
"declarationDir": "./dist/types"
diff --git a/packages/create-astro/tsconfig.json b/packages/create-astro/tsconfig.json
index 8f0cdf74d..6b3c4ca88 100644
--- a/packages/create-astro/tsconfig.json
+++ b/packages/create-astro/tsconfig.json
@@ -3,7 +3,7 @@
"include": ["src", "index.d.ts"],
"compilerOptions": {
"allowJs": true,
- "target": "ES2020",
+ "target": "ES2019",
"module": "ES2020",
"outDir": "./dist",
"declarationDir": "./dist/types"
diff --git a/packages/markdown-support/tsconfig.json b/packages/markdown-support/tsconfig.json
index c56abb57e..67a76c52b 100644
--- a/packages/markdown-support/tsconfig.json
+++ b/packages/markdown-support/tsconfig.json
@@ -3,7 +3,7 @@
"include": ["src"],
"compilerOptions": {
"allowJs": true,
- "target": "ES2020",
+ "target": "ES2019",
"module": "ES2020",
"outDir": "./dist"
}
diff --git a/packages/renderers/renderer-lit/client-shim.js b/packages/renderers/renderer-lit/client-shim.js
index 3f4788fc1..5ae6e8181 100644
--- a/packages/renderers/renderer-lit/client-shim.js
+++ b/packages/renderers/renderer-lit/client-shim.js
@@ -3,11 +3,10 @@ async function polyfill() {
hydrateShadowRoots(document.body);
}
-if (
- !new DOMParser()
- .parseFromString(`<p><template shadowroot="open"></template></p>`, 'text/html', {
- includeShadowRoots: true,
- })
- .querySelector('p')?.shadowRoot
-)
+const polyfillCheckEl = new DOMParser()
+ .parseFromString(`<p><template shadowroot="open"></template></p>`, 'text/html', {includeShadowRoots: true})
+ .querySelector('p');
+
+if (!polyfillCheckEl || !polyfillCheckEl.shadowRoot) {
polyfill();
+}
diff --git a/scripts/cmd/build.js b/scripts/cmd/build.js
index 27941b514..92cb724bf 100644
--- a/scripts/cmd/build.js
+++ b/scripts/cmd/build.js
@@ -10,7 +10,9 @@ const defaultConfig = {
minify: false,
format: 'esm',
platform: 'node',
- target: 'node14.16.1',
+ // There's an issue with 'node12.20' compiling ESM to CJS
+ // so use 'node13.2' instead. V8 support should be similar.
+ target: 'node13.2',
sourcemap: 'inline',
sourcesContent: false,
};
@@ -63,7 +65,7 @@ export default async function build(...args) {
});
process.on('beforeExit', () => {
- builder.stop?.();
+ builder.stop && builder.stop();
});
}
diff --git a/scripts/index.js b/scripts/index.js
index 9025e4781..7908b112c 100755
--- a/scripts/index.js
+++ b/scripts/index.js
@@ -5,12 +5,12 @@ export default async function run() {
case 'dev':
case 'build': {
const { default: build } = await import('./cmd/build.js');
- build(...args, cmd === 'dev' ? 'IS_DEV' : undefined);
+ await build(...args, cmd === 'dev' ? 'IS_DEV' : undefined);
break;
}
case 'copy': {
const { default: copy } = await import('./cmd/copy.js');
- copy(...args);
+ await copy(...args);
break;
}
}