Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(core): support TypeScript + ESM configuration #9317

Merged
merged 49 commits into from
Oct 14, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
3f54f4f
feat: support typescript configuration
harryzcy Sep 17, 2023
b9db574
Apply suggestions from code review
harryzcy Sep 19, 2023
b88e1c8
fix: handle function typed config
harryzcy Sep 19, 2023
bb5b90a
Merge branch 'main' into config-in-ts
harryzcy Sep 24, 2023
0f66191
chore: remove other usage of `import-fresh`
harryzcy Sep 24, 2023
8f48f9d
chore: remove `import-fresh` in package.json
harryzcy Sep 24, 2023
138e25e
fix: fix tests related to config loading
harryzcy Sep 24, 2023
901c95e
fix: test case when config is promise
harryzcy Sep 25, 2023
3913aa8
chore: add testcase for typescript
harryzcy Sep 25, 2023
b9a12d3
Merge branch 'main' into config-in-ts
slorber Oct 12, 2023
6932057
Attempt to use TS sidebar
slorber Oct 12, 2023
201c874
Hide jiti behind Docusaurus utils loadFreshModule abstraction
slorber Oct 13, 2023
a7752ab
Merge branch 'main' into config-in-ts
slorber Oct 13, 2023
7af9f72
Add more loadSiteConfig test fixtures
slorber Oct 13, 2023
1e4d95e
scaffold loadFreshModule tests
slorber Oct 13, 2023
2c4a2e7
loadFreshModule tests for CJS / ESM
slorber Oct 13, 2023
2f522b2
add loadFreshModule tests
slorber Oct 13, 2023
5468bf9
Migrate templates to ESM
slorber Oct 13, 2023
d187645
Refactor init templates to ESM + TS
slorber Oct 13, 2023
5b120e6
add @docusaurus/types to templates by default
slorber Oct 13, 2023
80fb76d
refactor TS docs
slorber Oct 13, 2023
bad83af
update docs to ESM
slorber Oct 13, 2023
4a36942
remove useless require.resolve from docs
slorber Oct 13, 2023
81e2ec6
do not show CJS usage of remark-math plugin because it doesn't work a…
slorber Oct 13, 2023
5c764a3
docs cleanups + use consistant module quotes in docs
slorber Oct 13, 2023
4f9047c
docs cleanups
slorber Oct 13, 2023
a646e41
refactor docs pages for ESM/TS support
slorber Oct 13, 2023
9ac8565
add ts config loading test
slorber Oct 13, 2023
c94aee2
Test support for ESM / TS presets
slorber Oct 13, 2023
2b72d98
Add plugins loading ESM + TS tests
slorber Oct 13, 2023
d6ea99a
esm config
slorber Oct 13, 2023
6105396
remove useless require.resolve
slorber Oct 13, 2023
0a20fbd
migrate website config to TS
slorber Oct 13, 2023
0fe678b
migrate website config to TS
slorber Oct 13, 2023
2355ade
fix docs Joi import
slorber Oct 13, 2023
88e7d63
fix getSwizzleComponentList docs
slorber Oct 13, 2023
2cf10ee
fix ideal image type consistency
slorber Oct 13, 2023
b165e1d
migrate more website config to TS
slorber Oct 13, 2023
b9248dd
migrate more website config to TS
slorber Oct 13, 2023
71666f2
migrate more website config to TS
slorber Oct 13, 2023
047e394
migrate more website config to TS
slorber Oct 13, 2023
7c1cc5e
fix pwa error
slorber Oct 13, 2023
708c32f
fix weird changelog plugin bug due to using CJS?
slorber Oct 13, 2023
3e53198
more website config refactors
slorber Oct 13, 2023
dd40aea
lint
slorber Oct 13, 2023
729b6f8
refactor mdx plugin docs
slorber Oct 13, 2023
22b7c8c
refactor mdx plugin docs
slorber Oct 13, 2023
4f3e37b
lint
slorber Oct 14, 2023
67c333e
templates should use ESM
slorber Oct 14, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/docusaurus-plugin-content-docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"combine-promises": "^1.1.0",
"fs-extra": "^11.1.1",
"import-fresh": "^3.3.0",
"jiti": "^1.20.0",
"js-yaml": "^4.1.0",
"lodash": "^4.17.21",
"tslib": "^2.6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import logger from '@docusaurus/logger';
import {Globby} from '@docusaurus/utils';
import Yaml from 'js-yaml';
import combinePromises from 'combine-promises';
import importFresh from 'import-fresh';
import jiti from 'jiti';
import {validateSidebars, validateCategoryMetadataFile} from './validation';
import {normalizeSidebars} from './normalization';
import {processSidebars} from './processor';
Expand Down Expand Up @@ -89,7 +89,9 @@ export async function loadSidebarsFileUnsafe(
}

// We don't want sidebars to be cached because of hot reloading.
return importFresh(sidebarFilePath);
return jiti(__filename, {
cache: false,
})(sidebarFilePath);
}

export async function loadSidebars(
Expand Down
2 changes: 1 addition & 1 deletion packages/docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
"html-minifier-terser": "^7.2.0",
"html-tags": "^3.3.1",
"html-webpack-plugin": "^5.5.3",
"import-fresh": "^3.3.0",
"jiti": "^1.20.0",
"leven": "^3.1.0",
"lodash": "^4.17.21",
"mini-css-extract-plugin": "^2.7.6",
Expand Down
11 changes: 4 additions & 7 deletions packages/docusaurus/src/server/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import path from 'path';
import fs from 'fs-extra';
import importFresh from 'import-fresh';
import jiti from 'jiti';
import logger from '@docusaurus/logger';
import {DEFAULT_CONFIG_FILE_NAME, findAsyncSequential} from '@docusaurus/utils';
import {validateConfig} from './configValidation';
Expand Down Expand Up @@ -46,12 +46,9 @@ export async function loadSiteConfig({
throw new Error(`Config file at "${siteConfigPath}" not found.`);
}

const importedConfig = importFresh(siteConfigPath);

const loadedConfig: unknown =
typeof importedConfig === 'function'
? await importedConfig()
: await importedConfig;
const loadedConfig = jiti(__filename, {
cache: false,
})(siteConfigPath);
harryzcy marked this conversation as resolved.
Show resolved Hide resolved

const siteConfig = validateConfig(
loadedConfig,
Expand Down
27 changes: 12 additions & 15 deletions project-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ cssnano
csvg
customizability
dabit
dabit
daishi
datagit
datas
Expand Down Expand Up @@ -98,20 +97,23 @@ eslintcache
estree
evaluable
execa
execa
externalwaiting
failfast
Fargate
fbid
février
fienny
flac
Flightcontrol
Flightcontrol's
harryzcy marked this conversation as resolved.
Show resolved Hide resolved
formik
fouc
froms
funboxteam
gantt
gabrielcsapo
gantt
getopts
Gifs
harryzcy marked this conversation as resolved.
Show resolved Hide resolved
gitgraph
gitpod
globbing
Expand All @@ -123,6 +125,7 @@ gtag
hahaha
hamel
hardcoding
hastscript
hasura
heavener
héctor
Expand All @@ -136,6 +139,7 @@ hoverable
husain
ianad
idempotency
Iframes
immer
infima
inlines
Expand All @@ -148,6 +152,7 @@ jakepartusch
jamstack
janvier
javadoc
jiti
jmarcey
jodyheavener
joshcena
Expand Down Expand Up @@ -183,6 +188,7 @@ mathjax
maxlynch
maxresdefault
mdast
mdwn
mdxa
mdxast
mdxhast
Expand All @@ -198,9 +204,8 @@ minifier
mkcert
mkdir
mkdirs
mkdocs
mkdn
mdwn
mkdocs
mkdown
moesif
msapplication
Expand Down Expand Up @@ -273,6 +278,7 @@ prerendered
prerendering
println
prismjs
producthunt
profilo
protobuf
protobuffet
Expand Down Expand Up @@ -319,7 +325,6 @@ serializers
setaf
setext
shiki
shiki
showinfo
sida
simen
Expand All @@ -328,7 +333,6 @@ sluggified
sluggifies
sluggify
solana
solana
spâce
stackblitz
stackblitzrc
Expand Down Expand Up @@ -373,6 +377,7 @@ typecheck
typechecks
typedoc
typesense
Unavatar
harryzcy marked this conversation as resolved.
Show resolved Hide resolved
unflat
unist
unlinkable
Expand Down Expand Up @@ -415,11 +420,3 @@ yangshunz
zhou
zoomable
zpao
hastscript
Flightcontrol
Fargate
Flightcontrol's
producthunt
Gifs
Iframes
Unavatar
34 changes: 28 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5532,6 +5532,11 @@ commander@^2.20.0:
resolved "https://registry.yarnpkg.com/commander/-/commander-2.20.3.tgz#fd485e84c03eb4881c20722ba48035e8531aeb33"
integrity sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==

commander@^4.0.0:
version "4.1.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-4.1.1.tgz#9fd602bd936294e9e9ef46a3f4d6964044b18068"
integrity sha512-NOKm8xhkzAjzFx8B2v5OAHT+u5pRQc2UCa2Vq9jYL/31o2wi9mxBA7LIFs3sV5VSC49z6pEhfbMULvShKj26WA==

commander@^5.0.0, commander@^5.1.0:
version "5.1.0"
resolved "https://registry.yarnpkg.com/commander/-/commander-5.1.0.tgz#46abbd1652f8e059bddaef99bbdcb2ad9cf179ae"
Expand Down Expand Up @@ -8315,6 +8320,18 @@ [email protected]:
once "^1.3.0"
path-is-absolute "^1.0.0"

[email protected]:
version "7.1.6"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6"
integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^3.0.4"
once "^1.3.0"
path-is-absolute "^1.0.0"

glob@^10.2.2:
version "10.3.3"
resolved "https://registry.yarnpkg.com/glob/-/glob-10.3.3.tgz#8360a4ffdd6ed90df84aa8d52f21f452e86a123b"
Expand Down Expand Up @@ -10197,10 +10214,10 @@ jest@^29.6.1:
import-local "^3.0.2"
jest-cli "^29.6.1"

jiti@^1.18.2:
version "1.19.1"
resolved "https://registry.yarnpkg.com/jiti/-/jiti-1.19.1.tgz#fa99e4b76a23053e0e7cde098efe1704a14c16f1"
integrity sha512-oVhqoRDaBXf7sjkll95LHVS6Myyyb1zaunVwk4Z0+WPSW4gjS0pl01zYKHScTuyEhQsFxV5L4DR5r+YqSyqyyg==
jiti@^1.18.2, jiti@^1.20.0:
version "1.20.0"
resolved "https://registry.yarnpkg.com/jiti/-/jiti-1.20.0.tgz#2d823b5852ee8963585c8dd8b7992ffc1ae83b42"
integrity sha512-3TV69ZbrvV6U5DfQimop50jE9Dl6J8O1ja1dvBbMba/sZ3YBEQqJ2VZRoQPVnhlzjNtU1vaXRZVrVjU4qtm8yA==

jkroso-type@1:
version "1.1.1"
Expand Down Expand Up @@ -12093,7 +12110,7 @@ [email protected], mute-stream@~0.0.4:
resolved "https://registry.yarnpkg.com/mute-stream/-/mute-stream-0.0.8.tgz#1630c42b2251ff81e2a283de96a5497ea92e5e0d"
integrity sha512-nnbWWOkoWyUsTjKrhgD0dcz22mdkSnpYqbEjIm2nhwhuxlSkpywJmBo8h0ZqJdkp73mb90SssHkN4rsRaBAfAA==

mz@^2.4.0:
mz@^2.4.0, mz@^2.7.0:
version "2.7.0"
resolved "https://registry.yarnpkg.com/mz/-/mz-2.7.0.tgz#95008057a56cafadc2bc63dde7f9ff6955948e32"
integrity sha512-z81GNO7nnYMEhrGh9LeymoE4+Yr0Wn5McHIZMK5cfQCl+NDX08sCZgUc9/6MHni9IWuFLm1Z3HTCXu2z9fN62Q==
Expand Down Expand Up @@ -13213,7 +13230,7 @@ pify@^4.0.1:
resolved "https://registry.yarnpkg.com/pify/-/pify-4.0.1.tgz#4b2cd25c50d598735c50292224fd8c6df41e3231"
integrity sha512-uB80kBFb/tfd68bVleG9T5GGsGPjJrLAUpR5PZIrhBnIaRTQRjqdJSsIKkOP6OAIFbj7GOrcudc5pNjZ+geV2g==

pirates@^4.0.4, pirates@^4.0.5:
pirates@^4.0.1, pirates@^4.0.4, pirates@^4.0.5:
version "4.0.6"
resolved "https://registry.yarnpkg.com/pirates/-/pirates-4.0.6.tgz#3018ae32ecfcff6c29ba2267cbf21166ac1f36b9"
integrity sha512-saLsH7WeYYPiD25LDuLRRY/i+6HaPYr6G1OUlN39otzkSTxKnubR9RTxS3/Kk50s1g2JTgFwWQDQyplC5/SHZg==
Expand Down Expand Up @@ -16200,6 +16217,11 @@ ts-dedent@^2.2.0:
resolved "https://registry.yarnpkg.com/ts-dedent/-/ts-dedent-2.2.0.tgz#39e4bd297cd036292ae2394eb3412be63f563bb5"
integrity sha512-q5W7tVM71e2xjHZTlgfTDoPF/SmqKG5hddq9SzR49CH2hayqRKJtQ4mtRlSxKaJlR/+9rEM+mnBHf7I2/BQcpQ==

ts-interface-checker@^0.1.9:
version "0.1.13"
resolved "https://registry.yarnpkg.com/ts-interface-checker/-/ts-interface-checker-0.1.13.tgz#784fd3d679722bc103b1b4b8030bcddb5db2a699"
integrity sha512-Y/arvbn+rrz3JCKl9C4kVNfTfSm2/mEp5FSz5EsZSANGPSlQrpRI5M4PKF+mJnE52jOO90PnPSc3Ur3bTQw0gA==

tsconfig-paths@^3.14.1:
version "3.14.2"
resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.14.2.tgz#6e32f1f79412decd261f92d633a9dc1cfa99f088"
Expand Down
Loading