tsconfig fix (#752)

This commit is contained in:
Fred K. Schott 2021-07-19 18:23:39 -07:00 committed by GitHub
parent 11100d62ef
commit a7e66666e4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 49 additions and 33 deletions

View file

@ -0,0 +1,7 @@
---
'astro': patch
'@astrojs/parser': patch
'create-astro': patch
---
compile javascript to target Node v12.x

View file

@ -54,7 +54,7 @@ jobs:
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest, windows-latest] os: [ubuntu-latest, windows-latest]
node-version: [14.x, 16.x] node-version: [12.x, 14.x, 16.x]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }} - name: Use Node.js ${{ matrix.node-version }}

View file

@ -6,7 +6,7 @@ import authorData from '../data/authors.json';
const { content } = Astro.props; const { content } = Astro.props;
--- ---
<html lang={ content.lang ?? 'en' }> <html lang={ content.lang || 'en' }>
<head> <head>
<title>{content.title}</title> <title>{content.title}</title>
<MainHead title={content.title} description={content.description} image={content.image} canonicalURL={Astro.request.canonicalURL} /> <MainHead title={content.title} description={content.description} image={content.image} canonicalURL={Astro.request.canonicalURL} />

View file

@ -7,7 +7,7 @@ import BlogPost from '../components/BlogPost.astro';
const {content} = Astro.props; const {content} = Astro.props;
const {title, description, publishDate, author, heroImage, permalink} = content; const {title, description, publishDate, author, heroImage, permalink} = content;
--- ---
<html lang={ content.lang ?? 'en' }> <html lang={ content.lang || 'en' }>
<head> <head>
<BaseHead title={title} description={description} permalink={permalink} /> <BaseHead title={title} description={description} permalink={permalink} />
<link rel="stylesheet" href="/blog.css" /> <link rel="stylesheet" href="/blog.css" />

View file

@ -10,7 +10,7 @@ import DocSidebar from '../components/DocSidebar.tsx';
// It will run during the build, but never in the browser. // It will run during the build, but never in the browser.
// All variables are available to use in the HTML template below. // All variables are available to use in the HTML template below.
const { content } = Astro.props; const { content } = Astro.props;
const headers = content?.astro?.headers; const headers = content.astro.headers;
const currentPage = Astro.request.url.pathname; const currentPage = Astro.request.url.pathname;
const currentFile = currentPage === '/' ? 'src/pages/index.md' : `src/pages${currentPage.replace(/\/$/, "")}.md`; const currentFile = currentPage === '/' ? 'src/pages/index.md' : `src/pages${currentPage.replace(/\/$/, "")}.md`;
const githubEditUrl = `https://github.com/USER/REPO/blob/main/${currentFile}` 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: // Full Astro Component Syntax:
// https://docs.astro.build/core-concepts/astro-components/ // https://docs.astro.build/core-concepts/astro-components/
--- ---
<html lang={ content.lang ?? 'en' }> <html lang={ content.lang || 'en' }>
<head> <head>
<title>{content.title}</title> <title>{content.title}</title>

View file

@ -6,7 +6,7 @@ import Nav from '../components/Nav/index.jsx';
const { content } = Astro.props; const { content } = Astro.props;
--- ---
<html lang={ content.lang ?? 'en' }> <html lang={ content.lang || 'en' }>
<head> <head>
<MainHead title={content.title} /> <MainHead title={content.title} />
<style lang="scss"> <style lang="scss">

View file

@ -8,7 +8,7 @@ const { content } = Astro.props;
--- ---
<!doctype html> <!doctype html>
<html lang={ content.lang ?? 'en' }> <html lang={ content.lang || 'en' }>
<head> <head>
<style> <style>

View file

@ -8,7 +8,7 @@ const { content } = Astro.props;
--- ---
<!doctype html> <!doctype html>
<html lang={ content.lang ?? 'en' }> <html lang={ content.lang || 'en' }>
<head> <head>
<BaseHead title={content.title} description={content.description} permalink="TODO" /> <BaseHead title={content.title} description={content.description} permalink="TODO" />

View file

@ -7,7 +7,7 @@ const { content } = Astro.props;
--- ---
<!doctype html> <!doctype html>
<html lang={ content.lang ?? 'en' }> <html lang={ content.lang || 'en' }>
<head> <head>
<style lang="scss"> <style lang="scss">

View file

@ -2,7 +2,7 @@
const { content } = Astro.props; const { content } = Astro.props;
--- ---
<html lang={ content.lang ?? 'en' }> <html lang={ content.lang || 'en' }>
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title>{content.title}</title> <title>{content.title}</title>

View file

@ -2,7 +2,7 @@
const { content } = Astro.props; const { content } = Astro.props;
--- ---
<html lang={ content.lang ?? 'en' }> <html lang={ content.lang || 'en' }>
<head> <head>
<meta charset="utf-8"> <meta charset="utf-8">
<title>{content.title}</title> <title>{content.title}</title>

View file

@ -64,6 +64,6 @@
"uvu": "^0.5.1" "uvu": "^0.5.1"
}, },
"engines": { "engines": {
"node": ">=14.15.1" "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
} }
} }

View file

@ -2,7 +2,7 @@
"extends": "../../tsconfig.base.json", "extends": "../../tsconfig.base.json",
"include": ["src"], "include": ["src"],
"compilerOptions": { "compilerOptions": {
"target": "ES2020", "target": "ES2019",
"module": "CommonJS", "module": "CommonJS",
"outDir": "./dist" "outDir": "./dist"
} }

View file

@ -140,9 +140,9 @@ async function __render(props, ...children) {
const Astro = { const Astro = {
...__TopLevelAstro, ...__TopLevelAstro,
props, props,
css: props[__astroInternal]?.css || [], css: (props[__astroInternal] && props[__astroInternal].css) || [],
request: props[__astroInternal]?.request || {}, request: (props[__astroInternal] && props[__astroInternal].request) || {},
isPage: props[__astroInternal]?.isPage || false, isPage: (props[__astroInternal] && props[__astroInternal].isPage) || false,
}; };
${result.script} ${result.script}

View file

@ -8,6 +8,10 @@ const Builtins = suite('Node builtins');
setup(Builtins, './fixtures/builtins'); setup(Builtins, './fixtures/builtins');
Builtins('Can be used with the node: prefix', async ({ runtime }) => { 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('/'); const result = await runtime.load('/');
if (result.error) throw new Error(result.error); if (result.error) throw new Error(result.error);

View file

@ -1,6 +1,6 @@
import { fileURLToPath } from 'url'; import { fileURLToPath } from 'url';
import { build as astroBuild } from '#astro/build'; import { build as astroBuild } from '#astro/build';
import { readFile } from 'fs/promises'; import { readFileSync } from 'fs';
import { createRuntime } from '#astro/runtime'; import { createRuntime } from '#astro/runtime';
import { loadConfig } from '#astro/config'; import { loadConfig } from '#astro/config';
import execa from 'execa'; import execa from 'execa';
@ -86,7 +86,7 @@ export function setupBuild(Suite, fixturePath) {
context.build = () => astroBuild(astroConfig, { level: 'error', dest: process.stderr }); context.build = () => astroBuild(astroConfig, { level: 'error', dest: process.stderr });
context.readFile = async (path) => { context.readFile = async (path) => {
const resolved = fileURLToPath(new URL(`${fixturePath}/${astroConfig.dist}${path}`, import.meta.url)); 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); clearTimeout(timeout);

View file

@ -8,6 +8,10 @@ const LitElement = suite('LitElement test');
setup(LitElement, './fixtures/lit-element'); setup(LitElement, './fixtures/lit-element');
LitElement('Renders a custom element by tag name', async ({ runtime }) => { 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('/'); const result = await runtime.load('/');
if (result.error) throw new Error(result.error); 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. // The Lit renderer adds browser globals that interfere with other tests, so remove them now.
LitElement.after(() => { LitElement.after(() => {
const globals = Object.keys(globalThis.window); const globals = Object.keys(globalThis.window || {});
globals.splice(globals.indexOf('global'), 1); globals.splice(globals.indexOf('global'), 1);
for (let name of globals) { for (let name of globals) {
delete globalThis[name]; delete globalThis[name];

View file

@ -3,7 +3,7 @@
"include": ["src", "index.d.ts"], "include": ["src", "index.d.ts"],
"compilerOptions": { "compilerOptions": {
"allowJs": true, "allowJs": true,
"target": "ES2020", "target": "ES2019",
"module": "ES2020", "module": "ES2020",
"outDir": "./dist", "outDir": "./dist",
"declarationDir": "./dist/types" "declarationDir": "./dist/types"

View file

@ -3,7 +3,7 @@
"include": ["src", "index.d.ts"], "include": ["src", "index.d.ts"],
"compilerOptions": { "compilerOptions": {
"allowJs": true, "allowJs": true,
"target": "ES2020", "target": "ES2019",
"module": "ES2020", "module": "ES2020",
"outDir": "./dist", "outDir": "./dist",
"declarationDir": "./dist/types" "declarationDir": "./dist/types"

View file

@ -3,7 +3,7 @@
"include": ["src"], "include": ["src"],
"compilerOptions": { "compilerOptions": {
"allowJs": true, "allowJs": true,
"target": "ES2020", "target": "ES2019",
"module": "ES2020", "module": "ES2020",
"outDir": "./dist" "outDir": "./dist"
} }

View file

@ -3,11 +3,10 @@ async function polyfill() {
hydrateShadowRoots(document.body); hydrateShadowRoots(document.body);
} }
if ( const polyfillCheckEl = new DOMParser()
!new DOMParser() .parseFromString(`<p><template shadowroot="open"></template></p>`, 'text/html', {includeShadowRoots: true})
.parseFromString(`<p><template shadowroot="open"></template></p>`, 'text/html', { .querySelector('p');
includeShadowRoots: true,
}) if (!polyfillCheckEl || !polyfillCheckEl.shadowRoot) {
.querySelector('p')?.shadowRoot
)
polyfill(); polyfill();
}

View file

@ -10,7 +10,9 @@ const defaultConfig = {
minify: false, minify: false,
format: 'esm', format: 'esm',
platform: 'node', 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', sourcemap: 'inline',
sourcesContent: false, sourcesContent: false,
}; };
@ -63,7 +65,7 @@ export default async function build(...args) {
}); });
process.on('beforeExit', () => { process.on('beforeExit', () => {
builder.stop?.(); builder.stop && builder.stop();
}); });
} }

View file

@ -5,12 +5,12 @@ export default async function run() {
case 'dev': case 'dev':
case 'build': { case 'build': {
const { default: build } = await import('./cmd/build.js'); const { default: build } = await import('./cmd/build.js');
build(...args, cmd === 'dev' ? 'IS_DEV' : undefined); await build(...args, cmd === 'dev' ? 'IS_DEV' : undefined);
break; break;
} }
case 'copy': { case 'copy': {
const { default: copy } = await import('./cmd/copy.js'); const { default: copy } = await import('./cmd/copy.js');
copy(...args); await copy(...args);
break; break;
} }
} }