diff --git a/packages/docusaurus-utils/package.json b/packages/docusaurus-utils/package.json index b4bfab548f78..0ecb2b73bb58 100644 --- a/packages/docusaurus-utils/package.json +++ b/packages/docusaurus-utils/package.json @@ -28,10 +28,11 @@ "github-slugger": "^1.5.0", "globby": "^11.1.0", "gray-matter": "^4.0.3", - "jiti": "^1.20.0", + "jiti": "^2.4.0", "js-yaml": "^4.1.0", "lodash": "^4.17.21", "micromatch": "^4.0.5", + "mlly": "^1.7.3", "prompts": "^2.4.2", "resolve-pathname": "^3.0.0", "shelljs": "^0.8.5", diff --git a/packages/docusaurus-utils/src/__tests__/moduleUtils.test.ts b/packages/docusaurus-utils/src/__tests__/moduleUtils.test.ts index 653667292a9a..dd0c8bf5c3c0 100644 --- a/packages/docusaurus-utils/src/__tests__/moduleUtils.test.ts +++ b/packages/docusaurus-utils/src/__tests__/moduleUtils.test.ts @@ -122,8 +122,10 @@ describe('loadFreshModule', () => { import dependency1 from "./dependency1"; import dependency2 from "./dependency2"; + export const entryValue = "entryVal1"; + export default { - someEntryValue: "entryVal", + someEntryValue: "entryVal2", dependency1, dependency2 }; @@ -132,7 +134,8 @@ describe('loadFreshModule', () => { // Should be able to read the initial module graph await expect(entryFile.load()).resolves.toEqual({ - someEntryValue: 'entryVal', + entryValue: 'entryVal1', + someEntryValue: 'entryVal2', dependency1: { dep1Export: 'dep1 val1', dep1Val: 'dep1 val2', @@ -159,7 +162,8 @@ describe('loadFreshModule', () => { `, ); await expect(entryFile.load()).resolves.toEqual({ - someEntryValue: 'entryVal', + entryValue: 'entryVal1', + someEntryValue: 'entryVal2', dependency1: { dep1Export: 'dep1 val1 updated', dep1Val: 'dep1 val2 updated', @@ -184,7 +188,8 @@ describe('loadFreshModule', () => { `, ); await expect(entryFile.load()).resolves.toEqual({ - someEntryValue: 'entryVal', + entryValue: 'entryVal1', + someEntryValue: 'entryVal2', dependency1: { dep1Export: 'dep1 val1 updated', dep1Val: 'dep1 val2 updated', @@ -208,8 +213,10 @@ describe('loadFreshModule', () => { import dependency1 from "./dependency1"; import dependency2 from "./dependency2"; + export const entryValue = "entryVal1 updated"; + export default { - someEntryValue: "entryVal updated", + someEntryValue: "entryVal2 updated", dependency1, dependency2, newAttribute: "is there" @@ -217,7 +224,8 @@ describe('loadFreshModule', () => { `, ); await expect(entryFile.load()).resolves.toEqual({ - someEntryValue: 'entryVal updated', + entryValue: 'entryVal1 updated', + someEntryValue: 'entryVal2 updated', newAttribute: 'is there', dependency1: { dep1Export: 'dep1 val1 updated', diff --git a/packages/docusaurus-utils/src/moduleUtils.ts b/packages/docusaurus-utils/src/moduleUtils.ts index e7adaf9880e5..24faccdb8309 100644 --- a/packages/docusaurus-utils/src/moduleUtils.ts +++ b/packages/docusaurus-utils/src/moduleUtils.ts @@ -5,7 +5,7 @@ * LICENSE file in the root directory of this source tree. */ -import jiti from 'jiti'; +import {createJiti} from 'jiti'; import logger from '@docusaurus/logger'; /* @@ -18,12 +18,12 @@ export async function loadFreshModule(modulePath: string): Promise { logger.interpolate`Invalid module path of type name=${modulePath}`, ); } - const load = jiti(__filename, { + const jiti = createJiti(__filename, { // Transpilation cache, can be safely enabled - cache: true, + fsCache: true, // Bypass Node.js runtime require cache // Same as "import-fresh" package we used previously - requireCache: false, + moduleCache: false, // Only take into consideration the default export // For now we don't need named exports // This also helps normalize return value for both CJS/ESM/TS modules @@ -31,7 +31,9 @@ export async function loadFreshModule(modulePath: string): Promise { // debug: true, }); - return load(modulePath); + const module = await jiti.import(modulePath); + const {interopDefault} = await import('mlly'); + return interopDefault(module); } catch (error) { throw new Error( logger.interpolate`Docusaurus could not load module at path path=${modulePath}\nCause: ${ diff --git a/yarn.lock b/yarn.lock index 1ead5c589d83..0b01850e9e15 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4798,10 +4798,10 @@ acorn@^6.1.1: resolved "https://registry.yarnpkg.com/acorn/-/acorn-6.4.2.tgz#35866fd710528e92de10cf06016498e47e39e1e6" integrity sha512-XtGIhXwF8YM8bJhGxG5kXgjkEuNGLTkoYqVE+KMR+aspr4KGYmKYg7yUe3KghyQ9yheNwLnjmzh/7+gfDBmHCQ== -acorn@^8.0.0, acorn@^8.0.4, acorn@^8.1.0, acorn@^8.10.0, acorn@^8.11.0, acorn@^8.11.3, acorn@^8.7.1, acorn@^8.8.1, acorn@^8.8.2, acorn@^8.9.0: - version "8.13.0" - resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.13.0.tgz#2a30d670818ad16ddd6a35d3842dacec9e5d7ca3" - integrity sha512-8zSiw54Oxrdym50NlZ9sUusyO1Z1ZchgRLWRaK6c86XJFClyCgFKetdowBg5bKxyp/u+CDBJG4Mpp0m3HLZl9w== +acorn@^8.0.0, acorn@^8.0.4, acorn@^8.1.0, acorn@^8.10.0, acorn@^8.11.0, acorn@^8.14.0, acorn@^8.7.1, acorn@^8.8.1, acorn@^8.8.2, acorn@^8.9.0: + version "8.14.0" + resolved "https://registry.yarnpkg.com/acorn/-/acorn-8.14.0.tgz#063e2c70cac5fb4f6467f0b11152e04c682795b0" + integrity sha512-cl669nCJTZBsL97OF4kUQm5g5hC2uihk0NxY3WENAC0TYdILVkAyHymAntgxGkl7K+t0cXIrH5siy5S4XkFycA== add-stream@^1.0.0: version "1.0.0" @@ -6233,10 +6233,10 @@ concat-stream@^2.0.0: readable-stream "^3.0.2" typedarray "^0.0.6" -confbox@^0.1.7: - version "0.1.7" - resolved "https://registry.yarnpkg.com/confbox/-/confbox-0.1.7.tgz#ccfc0a2bcae36a84838e83a3b7f770fb17d6c579" - integrity sha512-uJcB/FKZtBMCJpK8MQji6bJHgu1tixKPxRLeGkNzBoOZzpnZUJm0jm2/sBDWcuBx1dYgxV4JU+g5hmNxCyAmdA== +confbox@^0.1.8: + version "0.1.8" + resolved "https://registry.yarnpkg.com/confbox/-/confbox-0.1.8.tgz#820d73d3b3c82d9bd910652c5d4d599ef8ff8b06" + integrity sha512-RMtmw0iFkeR4YV+fUOSucriAQNb9g8zFR52MWCtl+cCZOFRNL6zeB395vPzFhEjjn4fMxXudmELnl/KF/WrK6w== config-chain@1.1.12: version "1.1.12" @@ -11021,6 +11021,11 @@ jiti@^1.20.0: resolved "https://registry.yarnpkg.com/jiti/-/jiti-1.21.6.tgz#6c7f7398dd4b3142767f9a168af2f317a428d268" integrity sha512-2yTgeWTWzMWkHu6Jp9NKgePDaYHbntiwvYuuJLbbN9vl7DC9DvXKOB2BC3ZZ92D3cvV/aflH0osDfwpHepQ53w== +jiti@^2.4.0: + version "2.4.0" + resolved "https://registry.yarnpkg.com/jiti/-/jiti-2.4.0.tgz#393d595fb6031a11d11171b5e4fc0b989ba3e053" + integrity sha512-H5UpaUI+aHOqZXlYOaFP/8AzKsg+guWu+Pr3Y8i7+Y3zr1aXAvCvTAQ1RxSc6oVD8R8c7brgNtTVP91E7upH/g== + jkroso-type@1: version "1.1.1" resolved "https://registry.yarnpkg.com/jkroso-type/-/jkroso-type-1.1.1.tgz#bc4ced6d6c45fe0745282bafc86a9f8c4fc9ce61" @@ -12940,15 +12945,15 @@ mkdirp@^1.0.3, mkdirp@^1.0.4: resolved "https://registry.yarnpkg.com/mkdirp/-/mkdirp-1.0.4.tgz#3eb5ed62622756d79a5f0e2a221dfebad75c2f7e" integrity sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw== -mlly@^1.4.2, mlly@^1.7.1: - version "1.7.1" - resolved "https://registry.yarnpkg.com/mlly/-/mlly-1.7.1.tgz#e0336429bb0731b6a8e887b438cbdae522c8f32f" - integrity sha512-rrVRZRELyQzrIUAVMHxP97kv+G786pHmOKzuFII8zDYahFBS7qnHh2AlYSl1GAHhaMPCz6/oHjVMcfFYgFYHgA== +mlly@^1.4.2, mlly@^1.7.1, mlly@^1.7.2, mlly@^1.7.3: + version "1.7.3" + resolved "https://registry.yarnpkg.com/mlly/-/mlly-1.7.3.tgz#d86c0fcd8ad8e16395eb764a5f4b831590cee48c" + integrity sha512-xUsx5n/mN0uQf4V548PKQ+YShA4/IW0KI1dZhrNrPCLG+xizETbHTkOa1f8/xut9JRPp8kQuMnz0oqwkTiLo/A== dependencies: - acorn "^8.11.3" + acorn "^8.14.0" pathe "^1.1.2" - pkg-types "^1.1.1" - ufo "^1.5.3" + pkg-types "^1.2.1" + ufo "^1.5.4" modify-values@^1.0.0: version "1.0.1" @@ -14125,13 +14130,13 @@ pkg-dir@^7.0.0: dependencies: find-up "^6.3.0" -pkg-types@^1.0.3, pkg-types@^1.1.1: - version "1.2.0" - resolved "https://registry.yarnpkg.com/pkg-types/-/pkg-types-1.2.0.tgz#d0268e894e93acff11a6279de147e83354ebd42d" - integrity sha512-+ifYuSSqOQ8CqP4MbZA5hDpb97n3E8SVWdJe+Wms9kj745lmd3b7EZJiqvmLwAlmRfjrI7Hi5z3kdBJ93lFNPA== +pkg-types@^1.0.3, pkg-types@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/pkg-types/-/pkg-types-1.2.1.tgz#6ac4e455a5bb4b9a6185c1c79abd544c901db2e5" + integrity sha512-sQoqa8alT3nHjGuTjuKgOnvjo4cljkufdtLMnO2LBP/wRwuDlo1tkaEdMxCRhyGRPacv/ztlZgDPm2b7FAmEvw== dependencies: - confbox "^0.1.7" - mlly "^1.7.1" + confbox "^0.1.8" + mlly "^1.7.2" pathe "^1.1.2" pkg-up@^3.1.0: @@ -17642,7 +17647,7 @@ typescript@~5.6.2: resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.3.tgz#5f3449e31c9d94febb17de03cc081dd56d81db5b" integrity sha512-hjcS1mhfuyi4WW8IWtjP7brDrG2cuDZukyrYrSauoXGNgx0S7zceP07adYkJycEr56BOUTNPzbInooiN3fn1qw== -ufo@^1.5.3: +ufo@^1.5.4: version "1.5.4" resolved "https://registry.yarnpkg.com/ufo/-/ufo-1.5.4.tgz#16d6949674ca0c9e0fbbae1fa20a71d7b1ded754" integrity sha512-UsUk3byDzKd04EyoZ7U4DOlxQaD14JUKQl6/P7wiX4FNvUfm3XL246n9W5AmqwW5RSFJ27NAuM0iLscAOYUiGQ==