From 627bdb689f26282ba49a185bfc5182a7c1e734dd Mon Sep 17 00:00:00 2001 From: Adrien de Peretti Date: Tue, 27 Jun 2023 14:00:11 +0200 Subject: [PATCH] chore(gatsby-source-medusa): Cleanup plugin setup (#4419) * chore(gatsby-source-medusa): Cleanup plugin setup * fix process-node * Create gentle-cups-crash.md --- .changeset/gentle-cups-crash.md | 5 +++ packages/gatsby-source-medusa/.babelrc | 11 ------ packages/gatsby-source-medusa/.gitignore | 17 +++------ packages/gatsby-source-medusa/.npmignore | 9 ----- packages/gatsby-source-medusa/jest.config.js | 13 +++++++ packages/gatsby-source-medusa/package.json | 10 +++-- .../__snapshots__/process-node.test.ts.snap | 0 .../{ => src}/__tests__/process-node.test.ts | 18 ++++----- .../interface.d.ts => src/interface.ts} | 0 .../gatsby-source-medusa/src/process-node.ts | 6 +-- .../src/utils/capitalize.ts | 3 -- packages/gatsby-source-medusa/tsconfig.json | 38 ++++++++++++------- .../gatsby-source-medusa/tsconfig.spec.json | 5 +++ yarn.lock | 31 ++------------- 14 files changed, 74 insertions(+), 92 deletions(-) create mode 100644 .changeset/gentle-cups-crash.md delete mode 100644 packages/gatsby-source-medusa/.babelrc delete mode 100644 packages/gatsby-source-medusa/.npmignore create mode 100644 packages/gatsby-source-medusa/jest.config.js rename packages/gatsby-source-medusa/{ => src}/__tests__/__snapshots__/process-node.test.ts.snap (100%) rename packages/gatsby-source-medusa/{ => src}/__tests__/process-node.test.ts (51%) rename packages/gatsby-source-medusa/{types/interface.d.ts => src/interface.ts} (100%) delete mode 100644 packages/gatsby-source-medusa/src/utils/capitalize.ts create mode 100644 packages/gatsby-source-medusa/tsconfig.spec.json diff --git a/.changeset/gentle-cups-crash.md b/.changeset/gentle-cups-crash.md new file mode 100644 index 0000000000..7cf5a825df --- /dev/null +++ b/.changeset/gentle-cups-crash.md @@ -0,0 +1,5 @@ +--- +"gatsby-source-medusa": patch +--- + +chore(gatsby-source-medusa): Cleanup plugin setup diff --git a/packages/gatsby-source-medusa/.babelrc b/packages/gatsby-source-medusa/.babelrc deleted file mode 100644 index 5681962c15..0000000000 --- a/packages/gatsby-source-medusa/.babelrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "presets": [["babel-preset-gatsby-package"]], - "overrides": [ - { - "test": [], - "presets": [ - ["babel-preset-gatsby-package", { "browser": true, "esm": true }] - ] - } - ] -} diff --git a/packages/gatsby-source-medusa/.gitignore b/packages/gatsby-source-medusa/.gitignore index f930d4acd8..874c6c69d3 100644 --- a/packages/gatsby-source-medusa/.gitignore +++ b/packages/gatsby-source-medusa/.gitignore @@ -1,13 +1,6 @@ +/dist node_modules - -.DS_Store - -utils - - -*.js -*.js.map -*.d.ts -!/types/*.d.ts - -!jest.config.js \ No newline at end of file +.DS_store +.env* +.env +*.sql diff --git a/packages/gatsby-source-medusa/.npmignore b/packages/gatsby-source-medusa/.npmignore deleted file mode 100644 index 5645e7cbc9..0000000000 --- a/packages/gatsby-source-medusa/.npmignore +++ /dev/null @@ -1,9 +0,0 @@ -src -.prettierrc -.env -.babelrc.js -.eslintrc -.gitignore - -.yarn -.turbo \ No newline at end of file diff --git a/packages/gatsby-source-medusa/jest.config.js b/packages/gatsby-source-medusa/jest.config.js new file mode 100644 index 0000000000..e564d67c70 --- /dev/null +++ b/packages/gatsby-source-medusa/jest.config.js @@ -0,0 +1,13 @@ +module.exports = { + globals: { + "ts-jest": { + tsconfig: "tsconfig.spec.json", + isolatedModules: false, + }, + }, + transform: { + "^.+\\.[jt]s?$": "ts-jest", + }, + testEnvironment: `node`, + moduleFileExtensions: [`js`, `jsx`, `ts`, `tsx`, `json`], +} diff --git a/packages/gatsby-source-medusa/package.json b/packages/gatsby-source-medusa/package.json index 01f3c52f11..8036ecfed5 100644 --- a/packages/gatsby-source-medusa/package.json +++ b/packages/gatsby-source-medusa/package.json @@ -4,9 +4,12 @@ "description": "Gatsby source plugin for building websites using Medusa Commerce as a data source", "scripts": { "test": "jest --passWithNoTests", - "watch": "tsc-watch --outDir .", - "build": "tsc --outDir ." + "watch": "tsc-watch", + "build": "tsc" }, + "files": [ + "dist" + ], "keywords": [ "gatsby", "gatsby-plugin", @@ -27,16 +30,15 @@ }, "dependencies": { "axios": "^0.24.0", - "babel-preset-gatsby-package": "^2.0.0", "gatsby-core-utils": "^3.3.0", "gatsby-plugin-image": "^2.3.0", "gatsby-source-filesystem": "^4.3.0" }, "devDependencies": { "@types/jest": "^27.0.1", - "babel-plugin-polyfill-corejs2": "^0.3.0", "gatsby": "^4.1.0", "jest": "^27.0.6", + "ts-jest": "^27.1.5", "tsc-watch": "^4.5.0", "typescript": "^4.5.2" }, diff --git a/packages/gatsby-source-medusa/__tests__/__snapshots__/process-node.test.ts.snap b/packages/gatsby-source-medusa/src/__tests__/__snapshots__/process-node.test.ts.snap similarity index 100% rename from packages/gatsby-source-medusa/__tests__/__snapshots__/process-node.test.ts.snap rename to packages/gatsby-source-medusa/src/__tests__/__snapshots__/process-node.test.ts.snap diff --git a/packages/gatsby-source-medusa/__tests__/process-node.test.ts b/packages/gatsby-source-medusa/src/__tests__/process-node.test.ts similarity index 51% rename from packages/gatsby-source-medusa/__tests__/process-node.test.ts rename to packages/gatsby-source-medusa/src/__tests__/process-node.test.ts index 583abe21f2..d21b6b47bd 100644 --- a/packages/gatsby-source-medusa/__tests__/process-node.test.ts +++ b/packages/gatsby-source-medusa/src/__tests__/process-node.test.ts @@ -1,20 +1,20 @@ -const { processNode } = require("../src/process-node.ts"); +const { processNode } = require("../process-node.ts") describe("helper functions", () => { it("should return return a new node from processNode", () => { - const fieldName = "product"; + const fieldName = "product" const node = { id: "prod_test_1234", title: "Test Shirt", description: "A test product", unit_price: 2500, - }; + } - const createContentDigest = jest.fn(() => "digest_string"); - const processNodeResult = processNode(node, fieldName, createContentDigest); + const createContentDigest = jest.fn(() => "digest_string") + const processNodeResult = processNode(node, fieldName, createContentDigest) - expect(createContentDigest).toBeCalled(); + expect(createContentDigest).toBeCalled() - expect(processNodeResult).toMatchSnapshot(); - }); -}); + expect(processNodeResult).toMatchSnapshot() + }) +}) diff --git a/packages/gatsby-source-medusa/types/interface.d.ts b/packages/gatsby-source-medusa/src/interface.ts similarity index 100% rename from packages/gatsby-source-medusa/types/interface.d.ts rename to packages/gatsby-source-medusa/src/interface.ts diff --git a/packages/gatsby-source-medusa/src/process-node.ts b/packages/gatsby-source-medusa/src/process-node.ts index 0bd729c95a..faaa17ac4d 100644 --- a/packages/gatsby-source-medusa/src/process-node.ts +++ b/packages/gatsby-source-medusa/src/process-node.ts @@ -1,5 +1,3 @@ -import { capitalize } from "./utils/capitalize" - export const processNode = ( node: any, fieldName: string, @@ -34,12 +32,14 @@ export const processNode = ( delete node.images } + // TODO: use upperFirstCase from medusajs/utils when it's available + const type = `Medusa${fieldName[0].toUpperCase() + fieldName.slice(1)}` const nodeData = Object.assign({}, node, { id: nodeId, parent: null, children: [], internal: { - type: `Medusa${capitalize(fieldName)}`, + type, content: nodeContent, contentDigest: nodeContentDigest, }, diff --git a/packages/gatsby-source-medusa/src/utils/capitalize.ts b/packages/gatsby-source-medusa/src/utils/capitalize.ts deleted file mode 100644 index 61317e498f..0000000000 --- a/packages/gatsby-source-medusa/src/utils/capitalize.ts +++ /dev/null @@ -1,3 +0,0 @@ -export function capitalize(s: string): string { - return s[0].toUpperCase() + s.slice(1) -} diff --git a/packages/gatsby-source-medusa/tsconfig.json b/packages/gatsby-source-medusa/tsconfig.json index cab823f261..731ef8a6e0 100644 --- a/packages/gatsby-source-medusa/tsconfig.json +++ b/packages/gatsby-source-medusa/tsconfig.json @@ -1,19 +1,29 @@ { - "include": ["src/**/*.ts", "types"], - "exclude": ["node_modules"], "compilerOptions": { - "strict": true, - "noUnusedLocals": true, - "noUnusedParameters": true, - "noImplicitReturns": true, - "module": "commonjs", - "removeComments": false, - "preserveConstEnums": true, - "skipLibCheck": true, + "lib": ["es2020"], + "target": "es2020", + "outDir": "./dist", "esModuleInterop": true, - "sourceMap": true, - "target": "es2017", "declaration": true, - "lib": ["es2017", "dom", "esnext.asynciterable"] - } + "module": "commonjs", + "moduleResolution": "node", + "emitDecoratorMetadata": true, + "experimentalDecorators": true, + "sourceMap": true, + "noImplicitReturns": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "noImplicitThis": true, + "allowJs": true, + "skipLibCheck": true, + "downlevelIteration": true // to use ES5 specific tooling + }, + "include": ["src"], + "exclude": [ + "dist", + "./src/**/__tests__", + "./src/**/__mocks__", + "./src/**/__fixtures__", + "node_modules" + ] } diff --git a/packages/gatsby-source-medusa/tsconfig.spec.json b/packages/gatsby-source-medusa/tsconfig.spec.json new file mode 100644 index 0000000000..9b62409191 --- /dev/null +++ b/packages/gatsby-source-medusa/tsconfig.spec.json @@ -0,0 +1,5 @@ +{ + "extends": "./tsconfig.json", + "include": ["src"], + "exclude": ["node_modules"] +} diff --git a/yarn.lock b/yarn.lock index 4adaf2afa1..c1fb1066e0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2294,7 +2294,7 @@ __metadata: languageName: node linkType: hard -"@babel/plugin-transform-typescript@npm:^7.13.0, @babel/plugin-transform-typescript@npm:^7.15.4, @babel/plugin-transform-typescript@npm:^7.18.6": +"@babel/plugin-transform-typescript@npm:^7.13.0, @babel/plugin-transform-typescript@npm:^7.18.6": version: 7.18.8 resolution: "@babel/plugin-transform-typescript@npm:7.18.8" dependencies: @@ -2504,7 +2504,7 @@ __metadata: languageName: node linkType: hard -"@babel/preset-flow@npm:^7.12.1, @babel/preset-flow@npm:^7.14.0": +"@babel/preset-flow@npm:^7.12.1": version: 7.18.6 resolution: "@babel/preset-flow@npm:7.18.6" dependencies: @@ -15057,7 +15057,7 @@ __metadata: languageName: node linkType: hard -"babel-plugin-polyfill-corejs2@npm:^0.3.0, babel-plugin-polyfill-corejs2@npm:^0.3.1": +"babel-plugin-polyfill-corejs2@npm:^0.3.1": version: 0.3.1 resolution: "babel-plugin-polyfill-corejs2@npm:0.3.1" dependencies: @@ -15272,28 +15272,6 @@ __metadata: languageName: node linkType: hard -"babel-preset-gatsby-package@npm:^2.0.0": - version: 2.18.0 - resolution: "babel-preset-gatsby-package@npm:2.18.0" - dependencies: - "@babel/plugin-proposal-nullish-coalescing-operator": ^7.14.5 - "@babel/plugin-proposal-optional-chaining": ^7.14.5 - "@babel/plugin-syntax-dynamic-import": ^7.8.3 - "@babel/plugin-transform-runtime": ^7.15.0 - "@babel/plugin-transform-typescript": ^7.15.4 - "@babel/preset-env": ^7.15.4 - "@babel/preset-flow": ^7.14.0 - "@babel/preset-react": ^7.14.0 - "@babel/runtime": ^7.15.4 - babel-plugin-dynamic-import-node: ^2.3.3 - babel-plugin-lodash: ^3.3.4 - core-js: ^3.22.3 - peerDependencies: - "@babel/core": ^7.11.6 - checksum: 1c3aeda5169728507258d35e06da3dbb0559a132c8c6e82f6fbd9535aa76ce691451b0bc91398e5381f2c1484b5125dd8bb9473e06ead07bfe03af7d76891492 - languageName: node - linkType: hard - "babel-preset-gatsby@npm:^2.18.0": version: 2.18.0 resolution: "babel-preset-gatsby@npm:2.18.0" @@ -22912,13 +22890,12 @@ __metadata: dependencies: "@types/jest": ^27.0.1 axios: ^0.24.0 - babel-plugin-polyfill-corejs2: ^0.3.0 - babel-preset-gatsby-package: ^2.0.0 gatsby: ^4.1.0 gatsby-core-utils: ^3.3.0 gatsby-plugin-image: ^2.3.0 gatsby-source-filesystem: ^4.3.0 jest: ^27.0.6 + ts-jest: ^27.1.5 tsc-watch: ^4.5.0 typescript: ^4.5.2 peerDependencies: