From 207deb5e1ecde4dd2355c74f5888aa7cb20058c0 Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Mon, 9 Jan 2023 15:12:51 -0800 Subject: [PATCH 01/12] add ts support --- packages/gatsby-source-drupal/.babelrc | 2 +- packages/gatsby-source-drupal/package.json | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/gatsby-source-drupal/.babelrc b/packages/gatsby-source-drupal/.babelrc index ac0ad292bb087..67bb53e836ce1 100644 --- a/packages/gatsby-source-drupal/.babelrc +++ b/packages/gatsby-source-drupal/.babelrc @@ -1,3 +1,3 @@ { - "presets": [["babel-preset-gatsby-package"]] + "presets": [["babel-preset-gatsby-package"], "@babel/preset-typescript"] } diff --git a/packages/gatsby-source-drupal/package.json b/packages/gatsby-source-drupal/package.json index 4c0196372ab8c..8d222f01ff15a 100644 --- a/packages/gatsby-source-drupal/package.json +++ b/packages/gatsby-source-drupal/package.json @@ -26,6 +26,7 @@ "devDependencies": { "@babel/cli": "^7.20.7", "@babel/core": "^7.20.7", + "@babel/preset-typescript": "^7.18.6", "babel-preset-gatsby-package": "^3.5.0-next.0", "cross-env": "^7.0.3" }, @@ -48,8 +49,8 @@ "directory": "packages/gatsby-source-drupal" }, "scripts": { - "build": "babel src --out-dir . --ignore \"**/__tests__\"", + "build": "babel src --out-dir . --ignore \"**/__tests__\" --extensions \".ts,.js\"", "prepare": "cross-env NODE_ENV=production npm run build", - "watch": "babel -w src --out-dir . --ignore \"**/__tests__\"" + "watch": "babel -w src --out-dir . --ignore \"**/__tests__\" --extensions \".ts,.js\"" } } From 4dbfea1694ab4684b3043b3a3c065a660b843daa Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Mon, 9 Jan 2023 15:13:57 -0800 Subject: [PATCH 02/12] make all files ts --- .../gatsby-source-drupal/src/{gatsby-node.js => gatsby-node.ts} | 0 packages/gatsby-source-drupal/src/{normalize.js => normalize.ts} | 0 .../src/{plugin-options.js => plugin-options.ts} | 0 packages/gatsby-source-drupal/src/{utils.js => utils.ts} | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename packages/gatsby-source-drupal/src/{gatsby-node.js => gatsby-node.ts} (100%) rename packages/gatsby-source-drupal/src/{normalize.js => normalize.ts} (100%) rename packages/gatsby-source-drupal/src/{plugin-options.js => plugin-options.ts} (100%) rename packages/gatsby-source-drupal/src/{utils.js => utils.ts} (100%) diff --git a/packages/gatsby-source-drupal/src/gatsby-node.js b/packages/gatsby-source-drupal/src/gatsby-node.ts similarity index 100% rename from packages/gatsby-source-drupal/src/gatsby-node.js rename to packages/gatsby-source-drupal/src/gatsby-node.ts diff --git a/packages/gatsby-source-drupal/src/normalize.js b/packages/gatsby-source-drupal/src/normalize.ts similarity index 100% rename from packages/gatsby-source-drupal/src/normalize.js rename to packages/gatsby-source-drupal/src/normalize.ts diff --git a/packages/gatsby-source-drupal/src/plugin-options.js b/packages/gatsby-source-drupal/src/plugin-options.ts similarity index 100% rename from packages/gatsby-source-drupal/src/plugin-options.js rename to packages/gatsby-source-drupal/src/plugin-options.ts diff --git a/packages/gatsby-source-drupal/src/utils.js b/packages/gatsby-source-drupal/src/utils.ts similarity index 100% rename from packages/gatsby-source-drupal/src/utils.js rename to packages/gatsby-source-drupal/src/utils.ts From 05f640507cad931d234715b23871fe7b97295f6c Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Mon, 9 Jan 2023 15:17:48 -0800 Subject: [PATCH 03/12] add new enabled languages plugin option object types/docs --- packages/gatsby-source-drupal/README.md | 10 ++++- .../gatsby-source-drupal/src/gatsby-node.ts | 10 ++++- .../src/plugin-options.ts | 42 ++++++++++++++++--- 3 files changed, 55 insertions(+), 7 deletions(-) diff --git a/packages/gatsby-source-drupal/README.md b/packages/gatsby-source-drupal/README.md index 046a4a4e91e27..422f30df06b93 100644 --- a/packages/gatsby-source-drupal/README.md +++ b/packages/gatsby-source-drupal/README.md @@ -465,7 +465,15 @@ module.exports = { baseUrl: `https://live-contentacms.pantheonsite.io/`, languageConfig: { defaultLanguage: `en`, - enabledLanguages: [`en`, `fil`], + enabledLanguages: [ + `en`, + `fil`, + // add an object here if you've renamed a langcode in Drupal + { + langCode: `en-gb`, + as: `uk`, + }, + ], translatableEntities: [`node--article`], nonTranslatableEntities: [`file--file`], }, diff --git a/packages/gatsby-source-drupal/src/gatsby-node.ts b/packages/gatsby-source-drupal/src/gatsby-node.ts index ab9d72d1fc4d3..af81c260dbc9e 100644 --- a/packages/gatsby-source-drupal/src/gatsby-node.ts +++ b/packages/gatsby-source-drupal/src/gatsby-node.ts @@ -869,7 +869,15 @@ exports.pluginOptionsSchema = ({ Joi }) => ), languageConfig: Joi.object({ defaultLanguage: Joi.string().required(), - enabledLanguages: Joi.array().items(Joi.string()).required(), + enabledLanguages: Joi.array() + .items( + Joi.string(), + Joi.Object({ + langCode: Joi.string().required(), + as: Joi.string().required(), + }) + ) + .required(), translatableEntities: Joi.array().items(Joi.string()).required(), nonTranslatableEntities: Joi.array().items(Joi.string()).required(), }), diff --git a/packages/gatsby-source-drupal/src/plugin-options.ts b/packages/gatsby-source-drupal/src/plugin-options.ts index 58ad0be37822f..d907e03957811 100644 --- a/packages/gatsby-source-drupal/src/plugin-options.ts +++ b/packages/gatsby-source-drupal/src/plugin-options.ts @@ -1,10 +1,42 @@ let options = {} -const setOptions = newOptions => { - options = newOptions +type RenamedLangCode = { + langCode: string + as: string } -const getOptions = () => options +type Options = { + // TODO: type all options + [key: string]: any +} & { + languageConfig?: { + enabledLanguages?: Array + complexEnabledLanguages?: Array + defaultLanguage?: string + translatableEntities?: Array + nonTranslatableEntities?: Array + } +} + +const mutateOptions = (options: Options) => { + // Support renamed language codes in Drupal + options?.languageConfig?.enabledLanguages?.forEach?.((lang, index) => { + if (typeof lang === `object`) { + // move the as langcode of the complex code to the enabled languages array + options!.languageConfig!.enabledLanguages!.push(lang.as) + // then move the complex lang-code to a different array + options!.languageConfig!.complexEnabledLanguages ||= [] + options!.languageConfig!.complexEnabledLanguages.push(lang) + // and remove it from enabledLanguages + delete options!.languageConfig!.enabledLanguages![index] + } + }) + + return options +} + +export const setOptions = (newOptions: Options) => { + options = mutateOptions(newOptions) +} -exports.setOptions = setOptions -exports.getOptions = getOptions +export const getOptions = () => options From c94b8f2f6f440c38206fa632536871f58747fc64 Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Mon, 9 Jan 2023 15:21:35 -0800 Subject: [PATCH 04/12] add local test scripts --- packages/gatsby-source-drupal/package.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/gatsby-source-drupal/package.json b/packages/gatsby-source-drupal/package.json index 8d222f01ff15a..f1ac96e730815 100644 --- a/packages/gatsby-source-drupal/package.json +++ b/packages/gatsby-source-drupal/package.json @@ -51,6 +51,8 @@ "scripts": { "build": "babel src --out-dir . --ignore \"**/__tests__\" --extensions \".ts,.js\"", "prepare": "cross-env NODE_ENV=production npm run build", - "watch": "babel -w src --out-dir . --ignore \"**/__tests__\" --extensions \".ts,.js\"" + "watch": "babel -w src --out-dir . --ignore \"**/__tests__\" --extensions \".ts,.js\"", + "test": "npx jest ./src/__tests__ --runInBand", + "test:watch": "npx jest --watch ./src/__tests__ --runInBand" } } From 29f1656c915b846b22135c4afab3874a59f3421d Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Mon, 9 Jan 2023 15:29:30 -0800 Subject: [PATCH 05/12] add normalization code for langCode as def --- .../src/__tests__/index.js | 8 ++++- .../src/plugin-options.ts | 30 +++++++++++-------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/packages/gatsby-source-drupal/src/__tests__/index.js b/packages/gatsby-source-drupal/src/__tests__/index.js index ef8ded945c761..90d4b322440b1 100644 --- a/packages/gatsby-source-drupal/src/__tests__/index.js +++ b/packages/gatsby-source-drupal/src/__tests__/index.js @@ -551,7 +551,13 @@ describe(`gatsby-source-drupal`, () => { apiBase, languageConfig: { defaultLanguage: `en_US`, - enabledLanguages: [`en_US`, `i18n-test`], + enabledLanguages: [ + `en_US`, + { + langCode: `en-gb`, + as: `i18n-test`, + }, + ], translatableEntities: [`node--article`], nonTranslatableEntities: [], }, diff --git a/packages/gatsby-source-drupal/src/plugin-options.ts b/packages/gatsby-source-drupal/src/plugin-options.ts index d907e03957811..76d8c4714c5cd 100644 --- a/packages/gatsby-source-drupal/src/plugin-options.ts +++ b/packages/gatsby-source-drupal/src/plugin-options.ts @@ -19,18 +19,24 @@ type Options = { } const mutateOptions = (options: Options) => { - // Support renamed language codes in Drupal - options?.languageConfig?.enabledLanguages?.forEach?.((lang, index) => { - if (typeof lang === `object`) { - // move the as langcode of the complex code to the enabled languages array - options!.languageConfig!.enabledLanguages!.push(lang.as) - // then move the complex lang-code to a different array - options!.languageConfig!.complexEnabledLanguages ||= [] - options!.languageConfig!.complexEnabledLanguages.push(lang) - // and remove it from enabledLanguages - delete options!.languageConfig!.enabledLanguages![index] - } - }) + if (options?.languageConfig?.enabledLanguages?.length) { + // Support renamed language codes in Drupal + options.languageConfig.enabledLanguages.forEach(lang => { + if (typeof lang === `object`) { + // move the as langcode of the complex code to the enabled languages array + options!.languageConfig!.enabledLanguages!.push(lang.as) + // then move the complex lang-code to a different array + options!.languageConfig!.complexEnabledLanguages ||= [] + options!.languageConfig!.complexEnabledLanguages.push(lang) + } + }) + + // since we moved all the object enabled languages to a new array, we can remove them from enabledLanguages + options.languageConfig.enabledLanguages = + options.languageConfig.enabledLanguages.filter( + lang => typeof lang === `string` + ) + } return options } From c8db51a5497db5a195d76b059d4709ee08449f01 Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Tue, 10 Jan 2023 15:08:05 -0800 Subject: [PATCH 06/12] use proper joi method name --- packages/gatsby-source-drupal/src/gatsby-node.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-source-drupal/src/gatsby-node.ts b/packages/gatsby-source-drupal/src/gatsby-node.ts index af81c260dbc9e..41e9725d58e4b 100644 --- a/packages/gatsby-source-drupal/src/gatsby-node.ts +++ b/packages/gatsby-source-drupal/src/gatsby-node.ts @@ -872,7 +872,7 @@ exports.pluginOptionsSchema = ({ Joi }) => enabledLanguages: Joi.array() .items( Joi.string(), - Joi.Object({ + Joi.object({ langCode: Joi.string().required(), as: Joi.string().required(), }) From 92255b73fc9ce36ed88d842402495032a8aea833 Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Tue, 10 Jan 2023 15:08:34 -0800 Subject: [PATCH 07/12] change property name --- packages/gatsby-source-drupal/src/plugin-options.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/gatsby-source-drupal/src/plugin-options.ts b/packages/gatsby-source-drupal/src/plugin-options.ts index 76d8c4714c5cd..e03aa1d1c7b4e 100644 --- a/packages/gatsby-source-drupal/src/plugin-options.ts +++ b/packages/gatsby-source-drupal/src/plugin-options.ts @@ -1,4 +1,4 @@ -let options = {} +let options: Options = {} type RenamedLangCode = { langCode: string @@ -11,7 +11,7 @@ type Options = { } & { languageConfig?: { enabledLanguages?: Array - complexEnabledLanguages?: Array + renamedEnabledLanguages?: Array defaultLanguage?: string translatableEntities?: Array nonTranslatableEntities?: Array @@ -26,8 +26,8 @@ const mutateOptions = (options: Options) => { // move the as langcode of the complex code to the enabled languages array options!.languageConfig!.enabledLanguages!.push(lang.as) // then move the complex lang-code to a different array - options!.languageConfig!.complexEnabledLanguages ||= [] - options!.languageConfig!.complexEnabledLanguages.push(lang) + options!.languageConfig!.renamedEnabledLanguages ||= [] + options!.languageConfig!.renamedEnabledLanguages.push(lang) } }) From feb9d763bbdd8a2b6a36de1dfb6dda28d9daefee Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Tue, 10 Jan 2023 15:08:50 -0800 Subject: [PATCH 08/12] refactor for TS --- .../gatsby-source-drupal/src/normalize.ts | 36 ++++++++++++------- 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/packages/gatsby-source-drupal/src/normalize.ts b/packages/gatsby-source-drupal/src/normalize.ts index 4f68c185065be..e23cab3f6050d 100644 --- a/packages/gatsby-source-drupal/src/normalize.ts +++ b/packages/gatsby-source-drupal/src/normalize.ts @@ -3,7 +3,8 @@ const { createRemoteFileNode } = require(`gatsby-source-filesystem`) const path = require(`path`) const probeImageSize = require(`probe-image-size`) -const { getOptions } = require(`./plugin-options`) +import { getOptions } from "./plugin-options" + const getHref = link => { if (typeof link === `object`) { return link.href @@ -197,33 +198,44 @@ const isEntityReferenceRevision = (type, entityReferenceRevisions = []) => ) !== -1 const createNodeIdWithVersion = ( - id, - type, - langcode, - revisionId, + id: string, + type: string, + langcode: string, + revisionId: string, entityReferenceRevisions = [] ) => { + const options = getOptions() + // Fallback to default language for entities that don't translate. - if (getOptions()?.languageConfig?.nonTranslatableEntities.includes(type)) { - langcode = getOptions().languageConfig.defaultLanguage + if ( + options?.languageConfig?.nonTranslatableEntities?.includes(type) && + options.languageConfig.defaultLanguage + ) { + langcode = options.languageConfig.defaultLanguage } // If the source plugin hasn't enabled `translation` then always just set langcode // to "undefined". - let langcodeNormalized = getOptions().languageConfig ? langcode : `und` + let langcodeNormalized = options.languageConfig ? langcode : `und` if ( - getOptions().languageConfig && - !getOptions().languageConfig?.enabledLanguages.includes(langcodeNormalized) + options.languageConfig && + options.languageConfig.defaultLanguage && + (!options?.languageConfig?.enabledLanguages?.includes(langcodeNormalized) || + !options?.languageConfig?.renamedEnabledLanguages?.find( + lang => lang.as === langcodeNormalized + )) ) { - langcodeNormalized = getOptions().languageConfig.defaultLanguage + langcodeNormalized = options.languageConfig.defaultLanguage } // The relationship between an entity and another entity also depends on the revision ID if the field is of type // entity reference revision such as for paragraphs. - return isEntityReferenceRevision(type, entityReferenceRevisions) + const idVersion = isEntityReferenceRevision(type, entityReferenceRevisions) ? `${langcodeNormalized}.${id}.${revisionId || 0}` : `${langcodeNormalized}.${id}` + + return idVersion } exports.createNodeIdWithVersion = createNodeIdWithVersion From 6cde5c2039a070cc4b1fb1da0d20f78a10b77244 Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Wed, 11 Jan 2023 14:07:53 -0800 Subject: [PATCH 09/12] ts changes --- .../gatsby-source-drupal/src/gatsby-node.ts | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/packages/gatsby-source-drupal/src/gatsby-node.ts b/packages/gatsby-source-drupal/src/gatsby-node.ts index ceb3150b08364..b4a618a189679 100644 --- a/packages/gatsby-source-drupal/src/gatsby-node.ts +++ b/packages/gatsby-source-drupal/src/gatsby-node.ts @@ -2,6 +2,7 @@ const got = require(`got`) const _ = require(`lodash`) const urlJoin = require(`url-join`) import HttpAgent from "agentkeepalive" + // const http2wrapper = require(`http2-wrapper`) const opentracing = require(`opentracing`) const { SemanticAttributes } = require(`@opentelemetry/semantic-conventions`) @@ -15,12 +16,13 @@ const { HttpsAgent } = HttpAgent const { setOptions, getOptions } = require(`./plugin-options`) -const { +import { nodeFromData, downloadFile, isFileNode, imageCDNState, -} = require(`./normalize`) +} from "./normalize" + const { handleReferences, handleWebhookUpdate, @@ -567,15 +569,19 @@ ${JSON.stringify(webhookBody, null, 4)}` throw error } } + if (d.body.data) { - dataArray.push(...d.body.data) + // @ts-ignore + dataArray.push(...(d.body.data || [])) } + // Add support for includes. Includes allow entity data to be expanded // based on relationships. The expanded data is exposed as `included` // in the JSON API response. // See https://www.drupal.org/docs/8/modules/jsonapi/includes if (d.body.included) { - dataArray.push(...d.body.included) + // @ts-ignore + dataArray.push(...(d.body.included || [])) } // If JSON:API extras is configured to add the resource count, we can queue @@ -593,8 +599,8 @@ ${JSON.stringify(webhookBody, null, 4)}` // Get count of API requests // We round down as we've already gotten the first page at this point. - const pageSize = new URL(d.body.links.next.href).searchParams.get( - `page[limit]` + const pageSize = Number( + new URL(d.body.links.next.href).searchParams.get(`page[limit]`) ) const requestsCount = Math.floor(d.body.meta.count / pageSize) @@ -604,11 +610,14 @@ ${JSON.stringify(webhookBody, null, 4)}` const newUrl = new URL(d.body.links.next.href) await Promise.all( - _.range(requestsCount).map(pageOffset => { + _.range(requestsCount).map((pageOffset: number) => { // We're starting 1 ahead. pageOffset += 1 // Construct URL with new pageOffset. - newUrl.searchParams.set(`page[offset]`, pageOffset * pageSize) + newUrl.searchParams.set( + `page[offset]`, + String(pageOffset * pageSize) + ) return getNext(newUrl.toString(), currentLanguage) }) ) @@ -626,6 +635,7 @@ ${JSON.stringify(webhookBody, null, 4)}` const urlPath = url.href.split(`${apiBase}/`).pop() const baseUrlWithoutTrailingSlash = baseUrl.replace(/\/$/, ``) // The default language's JSON API is at the root. + if ( currentLanguage === getOptions().languageConfig.defaultLanguage || baseUrlWithoutTrailingSlash.slice(-currentLanguage.length) == From 090b91f997ffbc2383b5489d8d0afbf5c2a0e3d6 Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Wed, 11 Jan 2023 14:08:29 -0800 Subject: [PATCH 10/12] ts fixes --- .../gatsby-source-drupal/src/normalize.ts | 56 +++++++++---------- 1 file changed, 28 insertions(+), 28 deletions(-) diff --git a/packages/gatsby-source-drupal/src/normalize.ts b/packages/gatsby-source-drupal/src/normalize.ts index e23cab3f6050d..ff9a2ad66aae4 100644 --- a/packages/gatsby-source-drupal/src/normalize.ts +++ b/packages/gatsby-source-drupal/src/normalize.ts @@ -5,22 +5,18 @@ const probeImageSize = require(`probe-image-size`) import { getOptions } from "./plugin-options" -const getHref = link => { +export const getHref = link => { if (typeof link === `object`) { return link.href } return link } -exports.getHref = getHref - -const imageCDNState = { +export const imageCDNState = { foundPlaceholderStyle: false, hasLoggedNoPlaceholderStyle: false, } -exports.imageCDNState = imageCDNState - let four04WarningCount = 0 let corruptFileWarningCount = 0 /** @@ -143,7 +139,7 @@ const getGatsbyImageCdnFields = async ({ return {} } -const nodeFromData = async ( +export const nodeFromData = async ( datum, createNodeId, entityReferenceRevisions = [], @@ -151,9 +147,12 @@ const nodeFromData = async ( fileNodesExtendedData, reporter ) => { - const { attributes: { id: attributeId, ...attributes } = {} } = datum + const { attributes: { id: attributeId, ...attributes } = { id: null } } = + datum + const preservedId = typeof attributeId !== `undefined` ? { _attributes_id: attributeId } : {} + const langcode = attributes.langcode || `und` const type = datum.type.replace(/-|__|:|\.|\s/g, `_`) @@ -165,16 +164,18 @@ const nodeFromData = async ( reporter, }) + const versionedId = createNodeIdWithVersion( + datum.id, + datum.type, + langcode, + attributes.drupal_internal__revision_id, + entityReferenceRevisions + ) + + const gatsbyId = createNodeId(versionedId) + return { - id: createNodeId( - createNodeIdWithVersion( - datum.id, - datum.type, - langcode, - attributes.drupal_internal__revision_id, - entityReferenceRevisions - ) - ), + id: gatsbyId, drupal_id: datum.id, parent: null, drupal_parent_menu_item: attributes.parent, @@ -190,14 +191,12 @@ const nodeFromData = async ( } } -exports.nodeFromData = nodeFromData - const isEntityReferenceRevision = (type, entityReferenceRevisions = []) => entityReferenceRevisions.findIndex( revisionType => type.indexOf(revisionType) === 0 ) !== -1 -const createNodeIdWithVersion = ( +export const createNodeIdWithVersion = ( id: string, type: string, langcode: string, @@ -229,24 +228,25 @@ const createNodeIdWithVersion = ( langcodeNormalized = options.languageConfig.defaultLanguage } + const isReferenceRevision = isEntityReferenceRevision( + type, + entityReferenceRevisions + ) + // The relationship between an entity and another entity also depends on the revision ID if the field is of type // entity reference revision such as for paragraphs. - const idVersion = isEntityReferenceRevision(type, entityReferenceRevisions) + const idVersion = isReferenceRevision ? `${langcodeNormalized}.${id}.${revisionId || 0}` : `${langcodeNormalized}.${id}` return idVersion } -exports.createNodeIdWithVersion = createNodeIdWithVersion - -const isFileNode = node => { +export const isFileNode = node => { const type = node?.internal?.type return type === `files` || type === `file__file` } -exports.isFileNode = isFileNode - const getFileUrl = (node, baseUrl) => { let fileUrl = node.url @@ -261,8 +261,8 @@ const getFileUrl = (node, baseUrl) => { return url } -exports.downloadFile = async ( - { node, store, cache, createNode, createNodeId, getCache, reporter }, +export const downloadFile = async ( + { node, cache, createNode, createNodeId, getCache }, { basicAuth, baseUrl } ) => { // handle file downloads From 249713d7cbae7787f4519cbadc5a1e48d9652d87 Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Wed, 11 Jan 2023 14:12:20 -0800 Subject: [PATCH 11/12] use renamed code in node id --- packages/gatsby-source-drupal/src/normalize.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/packages/gatsby-source-drupal/src/normalize.ts b/packages/gatsby-source-drupal/src/normalize.ts index ff9a2ad66aae4..498f7624ec2c4 100644 --- a/packages/gatsby-source-drupal/src/normalize.ts +++ b/packages/gatsby-source-drupal/src/normalize.ts @@ -217,13 +217,19 @@ export const createNodeIdWithVersion = ( // to "undefined". let langcodeNormalized = options.languageConfig ? langcode : `und` + const renamedCode = options?.languageConfig?.renamedEnabledLanguages?.find( + lang => lang.langCode === langcodeNormalized + ) + + if (renamedCode) { + langcodeNormalized = renamedCode.as + } + if ( + !renamedCode && options.languageConfig && options.languageConfig.defaultLanguage && - (!options?.languageConfig?.enabledLanguages?.includes(langcodeNormalized) || - !options?.languageConfig?.renamedEnabledLanguages?.find( - lang => lang.as === langcodeNormalized - )) + !options?.languageConfig?.enabledLanguages?.includes(langcodeNormalized) ) { langcodeNormalized = options.languageConfig.defaultLanguage } From 789e77e4e8d26c6aac9743e9daf2f8fc7b4d1d25 Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Wed, 11 Jan 2023 14:33:46 -0800 Subject: [PATCH 12/12] attempt to disable easlint rules for source-drupal --- packages/gatsby-source-drupal/.eslintrc | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 packages/gatsby-source-drupal/.eslintrc diff --git a/packages/gatsby-source-drupal/.eslintrc b/packages/gatsby-source-drupal/.eslintrc new file mode 100644 index 0000000000000..0e9ba9e2a52a8 --- /dev/null +++ b/packages/gatsby-source-drupal/.eslintrc @@ -0,0 +1,8 @@ +{ + "rules": { + "@typescript-eslint/explicit-function-return-type": "off", + "@typescript-eslint/no-use-before-define": "off", + "@typescript-eslint/naming-convention": "off", + "@typescript-eslint/consistent-type-definitions": "off" + } +}