Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
pmelab committed Jan 5, 2024
1 parent 7a6f5ee commit 652f13a
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 0 deletions.
23 changes: 23 additions & 0 deletions packages/gatsby-operations/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "@amazeelabs/gatsby-operations",
"version": "1.0.0",
"description": "",
"type": "module",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@babel/types": "^7.23.6",
"@types/babel__core": "^7.20.5",
"babel-plugin-tester": "^11.0.4",
"typescript": "^5.3.3",
"vitest": "^1.1.0"
},
"dependencies": {
"@babel/core": "^7.23.6"
}
}
22 changes: 22 additions & 0 deletions packages/gatsby-operations/src/plugin.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { pluginTester } from 'babel-plugin-tester';

import plugin from './plugin';

pluginTester({
plugin,
pluginOptions: {},
tests: [
{
code: `
import { MyOperation } from '@custom/schema';
import { useStaticQuery } from '@amazeelabs/gatsby-operations';
function useData() { return useStaticQuery(MyOperation); }
`,
output: `
import { MyOperation } from '@custom/schema';
import { graphql, useStaticQuery, } from 'gatsby';
function useData() { return useStaticQuery(graphql\`{ field }\`); }
`,
},
],
});
23 changes: 23 additions & 0 deletions packages/gatsby-operations/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { PluginObj, PluginPass, types } from '@babel/core';

export default () =>
({
visitor: {
ImportDeclaration(path, { opts }) {
if (path.node.source.value !== '@amazeelabs/gatsby-operations') {
path.replaceWith(
types.importDeclaration(
path.node.specifiers,
types.stringLiteral('gatsby'),
),
);
}
},
},
} as PluginObj<
PluginPass & {
opts: {
operations: Record<string, string>;
};
}
>);
19 changes: 19 additions & 0 deletions packages/gatsby-operations/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"compilerOptions": {
"target": "ESNext",
"allowJs": false,
"skipLibCheck": true,
"esModuleInterop": false,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "ESNext",
"moduleResolution": "Node",
"resolveJsonModule": true,
"isolatedModules": true,
"declaration": true,
"declarationDir": "build",
"outDir": "build"
},
"include": ["src"]
}
7 changes: 7 additions & 0 deletions packages/gatsby-operations/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { defineConfig } from 'vitest/config';

export default defineConfig({
test: {
globals: true,
},
});

0 comments on commit 652f13a

Please sign in to comment.