From 585dd97c38c34c3d8cdda7d47635606cdbe443fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20M=C3=A9tral?= Date: Wed, 4 Mar 2020 21:32:02 +0100 Subject: [PATCH] fix: avoid array.prototype.flat (#15) Update tsconfig to reflect that we are using ES2018 (Node 10). Array.prototype.flat is only available in Node 11. Instead of using a polyfill, we will use concat to flatten the array of object arrays --- src/gatsby-node.ts | 7 +++++-- tsconfig.json | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/gatsby-node.ts b/src/gatsby-node.ts index 53ab6a6b..7e00000d 100644 --- a/src/gatsby-node.ts +++ b/src/gatsby-node.ts @@ -50,13 +50,16 @@ export async function sourceNodes( }; try { - const objects = await Promise.all( + let objects: Array = await Promise.all( buckets.map(bucket => listObjects(bucket)) ); + // flatten objects + // flat() is not supported in node 10 + objects = [].concat(...objects); // create file nodes // todo touch nodes if they exist already - objects?.flat().forEach(async object => { + objects?.forEach(async object => { const { Key, Bucket } = object; const { region } = awsConfig; diff --git a/tsconfig.json b/tsconfig.json index 6befb10d..3778b818 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,6 +1,6 @@ { "compilerOptions": { - "lib": ["ESNext"], + "lib": ["ES2018"], "module": "CommonJS", // support node 10 and newer "target": "ES2018",