Skip to content

Commit 5bd3063

Browse files
LekoArtswardpeet
andauthoredJul 1, 2022
feat: Publish some packages as ESM & CJS (#36012)
Co-authored-by: Ward Peeters <ward@coding-tech.com>

File tree

13 files changed

+89
-134
lines changed

13 files changed

+89
-134
lines changed
 

‎packages/create-gatsby/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"fs-extra": "^10.1.0",
3131
"gatsby-plugin-utils": "^3.13.0-next.0",
3232
"joi": "^17.4.2",
33-
"microbundle": "^0.14.2",
33+
"microbundle": "^0.15.0",
3434
"node-fetch": "^2.6.6",
3535
"string-length": "^4.0.2",
3636
"terminal-link": "^2.1.1",

‎packages/gatsby-design-tokens/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"devDependencies": {
3333
"agadoo": "^2.0.0",
3434
"cross-env": "^7.0.3",
35-
"microbundle": "^0.14.2",
35+
"microbundle": "^0.15.0",
3636
"preval.macro": "^5.0.0"
3737
},
3838
"engines": {

‎packages/gatsby-legacy-polyfills/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
"event-target-polyfill": "^0.0.3",
4141
"execa": "^5.1.1",
4242
"fs-extra": "^10.1.0",
43-
"microbundle": "^0.14.2",
43+
"microbundle": "^0.15.0",
4444
"npm-run-all": "^4.1.5",
4545
"object-assign": "^4.1.1",
4646
"url-polyfill": "^1.1.12",

‎packages/gatsby-link/.babelrc

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
{
2-
"presets": [["babel-preset-gatsby-package", { "browser": true, "esm": true }]]
3-
}
1+
{}

‎packages/gatsby-link/package.json

+17-12
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,30 @@
66
"bugs": {
77
"url": "https://github.com/gatsbyjs/gatsby/issues"
88
},
9+
"source": "src/index.js",
10+
"main": "dist/index.js",
11+
"module": "dist/index.modern.mjs",
12+
"types": "index.d.ts",
13+
"files": [
14+
"dist/*"
15+
],
16+
"sideEffects": false,
17+
"scripts": {
18+
"build": "microbundle -f cjs,modern --jsx React.createElement --generateTypes false",
19+
"watch": "npm run build watch --no-compress",
20+
"prepare": "cross-env NODE_ENV=production npm run clean && npm run build",
21+
"clean": "del-cli dist/*"
22+
},
923
"dependencies": {
10-
"@babel/runtime": "^7.15.4",
1124
"@types/reach__router": "^1.3.10",
1225
"gatsby-page-utils": "^2.19.0-next.0",
1326
"prop-types": "^15.8.1"
1427
},
1528
"devDependencies": {
16-
"@babel/cli": "^7.15.4",
17-
"@babel/core": "^7.15.5",
1829
"@testing-library/react": "^11.2.7",
19-
"babel-preset-gatsby-package": "^2.19.0-next.0",
20-
"cross-env": "^7.0.3"
30+
"cross-env": "^7.0.3",
31+
"del-cli": "^3.0.1",
32+
"microbundle": "^0.15.0"
2133
},
2234
"peerDependencies": {
2335
"@gatsbyjs/reach-router": "^1.3.5",
@@ -29,18 +41,11 @@
2941
"gatsby"
3042
],
3143
"license": "MIT",
32-
"main": "index.js",
3344
"repository": {
3445
"type": "git",
3546
"url": "https://github.com/gatsbyjs/gatsby.git",
3647
"directory": "packages/gatsby-link"
3748
},
38-
"scripts": {
39-
"build": "babel src --out-dir . --ignore \"**/__tests__\"",
40-
"prepare": "cross-env NODE_ENV=production npm run build",
41-
"watch": "babel -w src --out-dir . --ignore \"**/__tests__\""
42-
},
43-
"types": "index.d.ts",
4449
"engines": {
4550
"node": ">=14.15.0"
4651
}

‎packages/gatsby-link/src/index.js

+2-31
Original file line numberDiff line numberDiff line change
@@ -4,38 +4,9 @@ import { Link, Location } from "@gatsbyjs/reach-router"
44
import { parsePath } from "./parse-path"
55
import { isLocalLink } from "./is-local-link"
66
import { rewriteLinkPath } from "./rewrite-link-path"
7+
import { withPrefix, getGlobalPathPrefix } from "./prefix-helpers"
78

8-
export { parsePath }
9-
10-
export function withPrefix(path, prefix = getGlobalBasePrefix()) {
11-
if (!isLocalLink(path)) {
12-
return path
13-
}
14-
15-
if (path.startsWith(`./`) || path.startsWith(`../`)) {
16-
return path
17-
}
18-
const base = prefix ?? getGlobalPathPrefix() ?? `/`
19-
20-
return `${base?.endsWith(`/`) ? base.slice(0, -1) : base}${
21-
path.startsWith(`/`) ? path : `/${path}`
22-
}`
23-
}
24-
25-
// These global values are wrapped in typeof clauses to ensure the values exist.
26-
// This is especially problematic in unit testing of this component.
27-
const getGlobalPathPrefix = () =>
28-
process.env.NODE_ENV !== `production`
29-
? typeof __PATH_PREFIX__ !== `undefined`
30-
? __PATH_PREFIX__
31-
: undefined
32-
: __PATH_PREFIX__
33-
const getGlobalBasePrefix = () =>
34-
process.env.NODE_ENV !== `production`
35-
? typeof __BASE_PATH__ !== `undefined`
36-
? __BASE_PATH__
37-
: undefined
38-
: __BASE_PATH__
9+
export { parsePath, withPrefix }
3910

4011
export function withAssetPrefix(path) {
4112
return withPrefix(path, getGlobalPathPrefix())
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { isLocalLink } from "./is-local-link"
2+
3+
export const getGlobalBasePrefix = () =>
4+
process.env.NODE_ENV !== `production`
5+
? typeof __BASE_PATH__ !== `undefined`
6+
? __BASE_PATH__
7+
: undefined
8+
: __BASE_PATH__
9+
10+
// These global values are wrapped in typeof clauses to ensure the values exist.
11+
// This is especially problematic in unit testing of this component.
12+
export const getGlobalPathPrefix = () =>
13+
process.env.NODE_ENV !== `production`
14+
? typeof __PATH_PREFIX__ !== `undefined`
15+
? __PATH_PREFIX__
16+
: undefined
17+
: __PATH_PREFIX__
18+
19+
export function withPrefix(path, prefix = getGlobalBasePrefix()) {
20+
if (!isLocalLink(path)) {
21+
return path
22+
}
23+
24+
if (path.startsWith(`./`) || path.startsWith(`../`)) {
25+
return path
26+
}
27+
const base = prefix ?? getGlobalPathPrefix() ?? `/`
28+
29+
return `${base?.endsWith(`/`) ? base.slice(0, -1) : base}${
30+
path.startsWith(`/`) ? path : `/${path}`
31+
}`
32+
}

‎packages/gatsby-link/src/rewrite-link-path.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { resolve } from "@gatsbyjs/reach-router/lib/utils"
33
import { applyTrailingSlashOption } from "gatsby-page-utils/apply-trailing-slash-option"
44
import { parsePath } from "./parse-path"
55
import { isLocalLink } from "./is-local-link"
6-
import { withPrefix } from "."
6+
import { withPrefix } from "./prefix-helpers"
77

88
const isAbsolutePath = path => path?.startsWith(`/`)
99

‎packages/gatsby-link/tsconfig.json

-3
This file was deleted.

‎packages/gatsby-plugin-image/package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
"scripts": {
55
"build": "npm-run-all --npm-path npm -s clean -p build:*",
66
"build:gatsby-node": "tsc --jsx react --downlevelIteration true --skipLibCheck true --esModuleInterop true --outDir dist/ src/gatsby-node.ts src/babel-plugin-parse-static-images.ts src/resolver-utils.ts src/types.d.ts -d --declarationDir dist/src",
7-
"build:gatsby-ssr": "microbundle -i src/gatsby-ssr.tsx -f cjs -o ./[name].js --no-pkg-main --jsx React.createElement --no-compress --external=common-tags,react --no-sourcemap",
8-
"build:server": "microbundle -f cjs,es --jsx React.createElement --define SERVER=true",
9-
"build:browser": "microbundle -i src/index.browser.ts -f cjs,modern --jsx React.createElement -o dist/gatsby-image.browser --define SERVER=false",
7+
"build:gatsby-ssr": "microbundle -i src/gatsby-ssr.tsx -f cjs -o ./[name].js --no-pkg-main --jsx React.createElement --jsxFragment React.Fragment --no-compress --external=common-tags,react --no-sourcemap",
8+
"build:server": "microbundle -f cjs,es --jsx React.createElement --jsxFragment React.Fragment --define SERVER=true",
9+
"build:browser": "microbundle -i src/index.browser.ts -f cjs,modern --jsx React.createElement --jsxFragment React.Fragment -o dist/gatsby-image.browser --define SERVER=false",
1010
"prepare": "yarn build",
1111
"watch": "npm-run-all --npm-path npm -s clean -p watch:*",
1212
"watch:gatsby-node": "yarn build:gatsby-node --watch",
@@ -56,7 +56,7 @@
5656
"cssnano": "^4.1.10",
5757
"del-cli": "^3.0.1",
5858
"do-sync": "^3.0.11",
59-
"microbundle": "^0.13.0",
59+
"microbundle": "^0.15.0",
6060
"npm-run-all": "^4.1.5",
6161
"postcss": "^8.2.9",
6262
"semver": "^7.3.7",

‎packages/gatsby-script/.babelrc

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1 @@
1-
{
2-
"presets": [
3-
["babel-preset-gatsby-package", { "browser": true, "esm": true }],
4-
"@babel/preset-typescript"
5-
]
6-
}
1+
{}

‎packages/gatsby-script/package.json

+9-17
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,25 @@
66
"bugs": {
77
"url": "https://github.com/gatsbyjs/gatsby/issues"
88
},
9+
"source": "src/index.ts",
910
"main": "dist/index.js",
11+
"module": "dist/index.modern.mjs",
1012
"types": "dist/index.d.ts",
11-
"typesVersions": {
12-
"*": {
13-
"*": [
14-
"dist/*.d.ts",
15-
"dist/index.d.ts"
16-
]
17-
}
18-
},
1913
"files": [
2014
"dist/*"
2115
],
16+
"sideEffects": false,
2217
"scripts": {
23-
"typegen": "rimraf \"dist/**/*.d.ts\" && tsc --emitDeclarationOnly --declaration --declarationDir dist/",
24-
"build": "babel src --extensions \".js,.jsx,.ts,.tsx\" --out-dir dist --ignore \"**/__tests__\"",
25-
"watch": "babel -w src --extensions \".js,.jsx,.ts,.tsx\" --out-dir dist --ignore \"**/__tests__\"",
26-
"prepare": "cross-env NODE_ENV=production npm run build && npm run typegen"
18+
"build": "microbundle -f cjs,modern --jsx React.createElement",
19+
"watch": "microbundle watch -f cjs,modern --jsx React.createElement --no-compress",
20+
"prepare": "cross-env NODE_ENV=production npm run clean && npm run build",
21+
"clean": "del-cli dist/*"
2722
},
2823
"devDependencies": {
29-
"@babel/cli": "^7.15.4",
30-
"@babel/core": "^7.15.5",
31-
"@babel/preset-typescript": "^7.16.7",
3224
"@testing-library/react": "^11.2.7",
33-
"babel-preset-gatsby-package": "^2.19.0-next.0",
3425
"cross-env": "^7.0.3",
35-
"rimraf": "^3.0.2",
26+
"del-cli": "^3.0.1",
27+
"microbundle": "^0.15.0",
3628
"typescript": "^4.7.2"
3729
},
3830
"peerDependencies": {

‎yarn.lock

+19-54
Original file line numberDiff line numberDiff line change
@@ -16536,56 +16536,10 @@ methods@~1.1.2:
1653616536
version "1.1.2"
1653716537
resolved "https://registry.yarnpkg.com/methods/-/methods-1.1.2.tgz#5529a4d67654134edcc5266656835b0f851afcee"
1653816538

16539-
microbundle@^0.13.0:
16540-
version "0.13.3"
16541-
resolved "https://registry.yarnpkg.com/microbundle/-/microbundle-0.13.3.tgz#cfc5055b50cf7a0bcc5eec441604f4520ccd07ec"
16542-
integrity sha512-nlP20UmyqGGeh6jhk8VaVFEoRlF+JAvnwixPLQUwHEcAF59ROJCyh34eylJzUAVNvF3yrCaHxIBv8lYcphDM1g==
16543-
dependencies:
16544-
"@babel/core" "^7.12.10"
16545-
"@babel/plugin-proposal-class-properties" "7.12.1"
16546-
"@babel/plugin-syntax-import-meta" "^7.10.4"
16547-
"@babel/plugin-syntax-jsx" "^7.12.1"
16548-
"@babel/plugin-transform-flow-strip-types" "^7.12.10"
16549-
"@babel/plugin-transform-react-jsx" "^7.12.11"
16550-
"@babel/plugin-transform-regenerator" "^7.12.1"
16551-
"@babel/preset-env" "^7.12.11"
16552-
"@babel/preset-flow" "^7.12.1"
16553-
"@babel/preset-react" "^7.12.10"
16554-
"@rollup/plugin-alias" "^3.1.1"
16555-
"@rollup/plugin-babel" "^5.2.2"
16556-
"@rollup/plugin-commonjs" "^17.0.0"
16557-
"@rollup/plugin-json" "^4.1.0"
16558-
"@rollup/plugin-node-resolve" "^11.0.1"
16559-
asyncro "^3.0.0"
16560-
autoprefixer "^10.1.0"
16561-
babel-plugin-macros "^3.0.1"
16562-
babel-plugin-transform-async-to-promises "^0.8.15"
16563-
babel-plugin-transform-replace-expressions "^0.2.0"
16564-
brotli-size "^4.0.0"
16565-
builtin-modules "^3.1.0"
16566-
camelcase "^6.2.0"
16567-
escape-string-regexp "^4.0.0"
16568-
filesize "^6.1.0"
16569-
gzip-size "^6.0.0"
16570-
kleur "^4.1.3"
16571-
lodash.merge "^4.6.2"
16572-
postcss "^8.2.1"
16573-
pretty-bytes "^5.4.1"
16574-
rollup "^2.35.1"
16575-
rollup-plugin-bundle-size "^1.0.3"
16576-
rollup-plugin-postcss "^4.0.0"
16577-
rollup-plugin-terser "^7.0.2"
16578-
rollup-plugin-typescript2 "^0.29.0"
16579-
sade "^1.7.4"
16580-
terser "^5.7.0"
16581-
tiny-glob "^0.2.8"
16582-
tslib "^2.0.3"
16583-
typescript "^4.1.3"
16584-
16585-
microbundle@^0.14.2:
16586-
version "0.14.2"
16587-
resolved "https://registry.yarnpkg.com/microbundle/-/microbundle-0.14.2.tgz#2db869c8145bd159aa55058ead47223f58f93bf2"
16588-
integrity sha512-jODALfU3w7jnJAqw7Tou9uU8e8zH0GRVWzOd/V7eAvD1fsfb9pyMbmzhFZqnX6SCb54eP1EF5oRyNlSxBAxoag==
16539+
microbundle@^0.15.0:
16540+
version "0.15.0"
16541+
resolved "https://registry.yarnpkg.com/microbundle/-/microbundle-0.15.0.tgz#d5a63ce02271b20d79fd30d83a123aaf962a5191"
16542+
integrity sha512-EkFst5ntLXoQGewkvga/Kd72RcN7IuJRl5ivLihJSbvLfJQo8LDS0n9X0q81vegiC59vhtKIM6qjrl1fOAtuGw==
1658916543
dependencies:
1659016544
"@babel/core" "^7.12.10"
1659116545
"@babel/plugin-proposal-class-properties" "7.12.1"
@@ -16623,6 +16577,7 @@ microbundle@^0.14.2:
1662316577
rollup-plugin-postcss "^4.0.0"
1662416578
rollup-plugin-terser "^7.0.2"
1662516579
rollup-plugin-typescript2 "^0.29.0"
16580+
rollup-plugin-visualizer "^5.6.0"
1662616581
sade "^1.7.4"
1662716582
terser "^5.7.0"
1662816583
tiny-glob "^0.2.8"
@@ -17112,10 +17067,10 @@ nan@^2.10.0, nan@^2.14.2:
1711217067
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.2.tgz#f5376400695168f4cc694ac9393d0c9585eeea19"
1711317068
integrity sha512-M2ufzIiINKCuDfBSAUr1vWQ+vuVcA9kqx8JJUsbQi6yf1uGRyb7HfpdfUr5qLXf3B/t8dPvcjhKMmlfnP47EzQ==
1711417069

17115-
nanoid@^3.1.30:
17116-
version "3.1.30"
17117-
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.1.30.tgz#63f93cc548d2a113dc5dfbc63bfa09e2b9b64362"
17118-
integrity sha512-zJpuPDwOv8D2zq2WRoMe1HsfZthVewpel9CAvTfc/2mBD1uUT/agc5f7GHGWXlYkFvi1mVxe4IjvP2HNrop7nQ==
17070+
nanoid@^3.1.30, nanoid@^3.1.32:
17071+
version "3.3.4"
17072+
resolved "https://registry.yarnpkg.com/nanoid/-/nanoid-3.3.4.tgz#730b67e3cd09e2deacf03c027c81c9d9dbc5e8ab"
17073+
integrity sha512-MqBkQh/OHTS2egovRtLk45wEyNXwF+cokD+1YPf9u5VfJiRdAiRwB2froX5Co9Rh20xs4siNPm8naNotSD6RBw==
1711917074

1712017075
nanomatch@^1.2.9:
1712117076
version "1.2.13"
@@ -21972,6 +21927,16 @@ rollup-plugin-virtual@^1.0.1:
2197221927
resolved "https://registry.yarnpkg.com/rollup-plugin-virtual/-/rollup-plugin-virtual-1.0.1.tgz#8227c94c605b981adfe433ea74de3551e42ffeb4"
2197321928
integrity sha512-HCTBpV8MwP5lNzZrHD2moVxHIToHU1EkzkKGVj6Z0DcgUfxrxrZmeQirQeLz2yhnkJqRjwiVywK9CS8jDYakrw==
2197421929

21930+
rollup-plugin-visualizer@^5.6.0:
21931+
version "5.6.0"
21932+
resolved "https://registry.yarnpkg.com/rollup-plugin-visualizer/-/rollup-plugin-visualizer-5.6.0.tgz#06aa7cf3fd504a29d404335700f2a3f28ebb33f3"
21933+
integrity sha512-CKcc8GTUZjC+LsMytU8ocRr/cGZIfMR7+mdy4YnlyetlmIl/dM8BMnOEpD4JPIGt+ZVW7Db9ZtSsbgyeBH3uTA==
21934+
dependencies:
21935+
nanoid "^3.1.32"
21936+
open "^8.4.0"
21937+
source-map "^0.7.3"
21938+
yargs "^17.3.1"
21939+
2197521940
rollup-pluginutils@^2.8.2:
2197621941
version "2.8.2"
2197721942
resolved "https://registry.yarnpkg.com/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz#72f2af0748b592364dbd3389e600e5a9444a351e"

0 commit comments

Comments
 (0)
Please sign in to comment.