Skip to content

Commit

Permalink
Migrate Gatsby packages to ESM
Browse files Browse the repository at this point in the history
build scripts on postinstall are no longer required

See https://www.gatsbyjs.com/docs/how-to/custom-configuration/es-modules
  • Loading branch information
cometkim committed Jun 5, 2024
1 parent 0ce6446 commit 9b1f807
Show file tree
Hide file tree
Showing 55 changed files with 626 additions and 852 deletions.
3 changes: 0 additions & 3 deletions _packages/@karrotmarket/gatsby-theme-post/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import type { GatsbyConfig } from 'gatsby';
// @ts-check

/**
* @typedef {import('gatsby').GatsbyConfig} GatsbyConfig
*/

// @ts-ignore
import { linkResolver } from '@karrotmarket/gatsby-theme-post/src/@karrotmarket/gatsby-theme-prismic/linkResolver';

const config = (): GatsbyConfig => ({
/**
* @return {GatsbyConfig}
*/
export default {
plugins: [
'gatsby-theme-stitches',
'gatsby-plugin-svgr',
Expand Down Expand Up @@ -50,6 +56,4 @@ const config = (): GatsbyConfig => ({
},
},
],
});

export default config;
};
Original file line number Diff line number Diff line change
@@ -1,28 +1,42 @@
import type { GatsbyNode, Page } from 'gatsby';
// @ts-check

/**
* @typedef {import('gatsby').GatsbyNode} GatsbyNode
* @typedef {import('gatsby').Page} Page
*/

const gql = String.raw;

export const onCreateBabelConfig: GatsbyNode['onCreateBabelConfig'] = ({ actions }) => {
/**
* @type {GatsbyNode['onCreateBabelConfig']}
*/
export const onCreateBabelConfig = ({ actions }) => {
actions.setBabelPlugin({
name: require.resolve('babel-plugin-polished'),
options: {},
});
};

export const createPages: GatsbyNode['createPages'] = async ({ graphql, actions }) => {
type Data = {
allPost: {
nodes: Array<{
id: string;
slug: string;
category: {
uid: string;
};
}>;
};
};
/**
* @type {GatsbyNode['createPages']}
*/
export const createPages = async ({ graphql, actions }) => {
/**
* @typedef {{
* allPost: {
* nodes: Array<{
* id: string;
* slug: string;
* category: {
* uid: string;
* };
* }>;
* };
* }} Data
*/

const { data, errors } = await graphql<Data>(
/** @type {{ data?: Data, errors?: any }} */
const { data, errors } = await graphql(
gql`
query {
allPost{
Expand Down
12 changes: 1 addition & 11 deletions _packages/@karrotmarket/gatsby-theme-post/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@
"name": "@karrotmarket/gatsby-theme-post",
"version": "0.0.1",
"private": true,
"scripts": {
"init:gatsby": "yarn build",
"build": "concurrently \"yarn:build:*\"",
"build:babel": "babel gatsby -d . -x .ts,.tsx --presets gatsby-package",
"prepack": "yarn build"
},
"peerDependencies": {
"@stitches/react": "^0.1.0 || ^0.2.0 || ^1.0.0",
"gatsby": "^4.19.0 || ^5.0.0",
"gatsby": "^5.3.0",
"polished": "^4.0.0",
"react": "*",
"react-dom": "*"
Expand Down Expand Up @@ -42,10 +36,6 @@
"sharp": "^0.33.4"
},
"devDependencies": {
"@babel/cli": "^7.23.9",
"@babel/core": "^7.24.0",
"babel-preset-gatsby-package": "^3.13.1",
"concurrently": "^8.2.2",
"gatsby": "^5.13.5",
"polished": "^4.3.1",
"react": "^18.2.0",
Expand Down
1 change: 0 additions & 1 deletion _packages/@karrotmarket/gatsby-theme-post/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@
"gatsby-theme-stitches/src/*": ["./src/gatsby-theme-stitches/*"]
}
},
"include": ["src/**/*", "gatsby"],
"exclude": []
}
3 changes: 0 additions & 3 deletions _packages/@karrotmarket/gatsby-theme-prismic/.gitignore

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import type { LinkResolverFunction } from '@prismicio/helpers';
import type { GatsbyConfig } from 'gatsby';
// @ts-check

/**
* @typedef {import('gatsby').GatsbyConfig} GatsbyConfig
* @typedef {import('@prismicio/helpers').LinkResolverFunction} LinkResolverFunction
*/

// https://karrot.prismic.io
const repositoryName = 'karrot';
Expand All @@ -8,13 +12,20 @@ const repositoryName = 'karrot';
const customTypesApiToken =
'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ0eXBlIjoibWFjaGluZTJtYWNoaW5lIiwiZGJpZCI6ImthcnJvdC00NzU3OWU1Yy1jZjg5LTQ3YTMtODVjMS01MDkzMWM3MzU0ZTlfNSIsImRhdGUiOjE2MzcwODI3NzMsImRvbWFpbiI6ImthcnJvdCIsImlhdCI6MTYzNzA4Mjc3M30.QQfmjFJK_vPZT9765NP1UI9h6Prvr46AnIOrAiUm0fU';

type ThemeOptions = {
accessToken?: string;
linkResolver?: LinkResolverFunction;
};
/**
* @typedef {{
* accessToken?: string;
* linkResolver?: LinkResolverFunction;
* }} ThemeOptions
*/

const config = ({ accessToken, linkResolver }: ThemeOptions): GatsbyConfig => ({
/**
* @param {ThemeOptions} options
* @return {GatsbyConfig}
*/
const config = ({ accessToken, linkResolver }) => ({
plugins: [
/** @type {satisfies import('gatsby-source-prismic').PluginOptions} */
{
resolve: 'gatsby-source-prismic',
options: {
Expand All @@ -29,14 +40,15 @@ const config = ({ accessToken, linkResolver }: ThemeOptions): GatsbyConfig => ({
fit: 'max',
q: 100,
},
} satisfies import('gatsby-source-prismic').PluginOptions,
},
},
/** @type {satisfies import('gatsby-plugin-prismic-previews').PluginOptions} */
{
resolve: 'gatsby-plugin-prismic-previews',
options: {
repositoryName,
accessToken,
} satisfies import('gatsby-plugin-prismic-previews').PluginOptions,
},
},
],
});
Expand Down
13 changes: 1 addition & 12 deletions _packages/@karrotmarket/gatsby-theme-prismic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@
"url": "git+https://github.com/daangn/websites",
"directory": "_packages/@karrotmarket/gatsby-theme-prismic"
},
"scripts": {
"init:gatsby": "yarn build",
"build": "concurrently \"yarn:build:*\"",
"build:babel": "babel gatsby -d . -x .ts,.tsx --presets gatsby-package",
"build:dts": "tsc --emitDeclarationOnly --skipLibCheck",
"prepack": "yarn build"
},
"files": [
"index.js",
"src",
Expand All @@ -22,7 +15,7 @@
"gatsby-ssr.js"
],
"peerDependencies": {
"gatsby": "^4.19.0 || ^5.0.0",
"gatsby": "^5.3.0",
"react": "*",
"react-dom": "*"
},
Expand All @@ -34,13 +27,9 @@
"prismic-reactjs": "^1.3.4"
},
"devDependencies": {
"@babel/cli": "^7.23.9",
"@babel/core": "^7.24.0",
"@types/node": "^20.11.28",
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"babel-preset-gatsby-package": "^3.13.1",
"concurrently": "^8.2.2",
"gatsby": "^5.13.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
10 changes: 10 additions & 0 deletions _packages/@karrotmarket/gatsby-theme-prismic/src/linkResolver.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// @ts-check

/**
* @typedef {import('@prismicio/helpers').LinkResolverFunction} LinkResolverFunction
*/

/** @type {LinkResolverFunction} */
exports.linkResolver = (_doc) => {
return '/';
};

This file was deleted.

5 changes: 1 addition & 4 deletions _packages/@karrotmarket/gatsby-theme-prismic/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"extends": "../../../tsconfig.json",
"compilerOptions": {
"rootDir": "gatsby",
"outDir": ".",
"jsx": "react"
},
"include": ["gatsby"],
"exclude": ["node_modules"]
"exclude": []
}
3 changes: 0 additions & 3 deletions _packages/@karrotmarket/gatsby-theme-seed-design/.gitignore

This file was deleted.

28 changes: 28 additions & 0 deletions _packages/@karrotmarket/gatsby-theme-seed-design/gatsby-config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// @ts-check

/**
* @typedef {import('gatsby').GatsbyConfig} GatsbyConfig
*/

/**
* @typedef {{
* mode?: string,
* }} PluginOptions
*/

/**
* @param {PluginOptions} options
* @return {GatsbyConfig}
*/
const config = ({ mode }) => ({
plugins: [
{
resolve: 'gatsby-plugin-seed-design',
options: {
mode,
},
},
],
});

export default config;

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,20 @@
"version": "0.0.0",
"private": true,
"scripts": {
"init:gatsby": "yarn build",
"prepack": "yarn build",
"build": "babel gatsby -d . -x .ts,.tsx --presets gatsby-package",
"generate": "seed-icon generate"
},
"peerDependencies": {
"gatsby": "^4.19.0 || ^5.0.0",
"gatsby": "^5.3.0",
"react": "^18.0.0",
"react-dom": "^18.0.0"
},
"dependencies": {
"gatsby-plugin-seed-design": "^0.2.7"
},
"devDependencies": {
"@babel/cli": "^7.23.9",
"@babel/core": "^7.24.0",
"@seed-design/icon": "^0.5.8",
"@types/react": "^18.2.66",
"@types/react-dom": "^18.2.22",
"babel-preset-gatsby-package": "^3.13.1",
"gatsby": "^5.13.5",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,5 @@
"compilerOptions": {
"jsx": "react"
},
"include": ["src", "gatsby"],
"exclude": []
}
7 changes: 0 additions & 7 deletions _packages/@karrotmarket/gatsby-theme-website-team/.gitignore

This file was deleted.

Loading

0 comments on commit 9b1f807

Please sign in to comment.