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

chore: update jiti to v2 #10716

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion packages/docusaurus-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
20 changes: 14 additions & 6 deletions packages/docusaurus-utils/src/__tests__/moduleUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,10 @@
import dependency1 from "./dependency1";
import dependency2 from "./dependency2";

export const entryValue = "entryVal1";

export default {
someEntryValue: "entryVal",
someEntryValue: "entryVal2",
dependency1,
dependency2
};
Expand All @@ -131,8 +133,9 @@
);

// Should be able to read the initial module graph
await expect(entryFile.load()).resolves.toEqual({

Check failure on line 136 in packages/docusaurus-utils/src/__tests__/moduleUtils.test.ts

View workflow job for this annotation

GitHub Actions / Windows Tests (18.0)

loadFreshModule › module graph › can load and reload fresh module graph

expect(received).resolves.toEqual(expected) // deep equality - Expected - 1 + Received + 0 @@ -1,8 +1,7 @@ Object { "dependency1": Object { - "dep1Export": "dep1 val1", "dep1Val": "dep1 val2", }, "dependency2": Object { "dep2Val": "dep2 val", }, at Object.toEqual (node_modules/expect/build/index.js:174:22) at Object.toEqual (packages/docusaurus-utils/src/__tests__/moduleUtils.test.ts:136:47)

Check failure on line 136 in packages/docusaurus-utils/src/__tests__/moduleUtils.test.ts

View workflow job for this annotation

GitHub Actions / Windows Tests (20)

loadFreshModule › module graph › can load and reload fresh module graph

expect(received).resolves.toEqual(expected) // deep equality - Expected - 1 + Received + 0 @@ -1,8 +1,7 @@ Object { "dependency1": Object { - "dep1Export": "dep1 val1", "dep1Val": "dep1 val2", }, "dependency2": Object { "dep2Val": "dep2 val", }, at Object.toEqual (node_modules/expect/build/index.js:174:22) at Object.toEqual (packages/docusaurus-utils/src/__tests__/moduleUtils.test.ts:136:47)

Check failure on line 136 in packages/docusaurus-utils/src/__tests__/moduleUtils.test.ts

View workflow job for this annotation

GitHub Actions / Tests (20)

loadFreshModule › module graph › can load and reload fresh module graph

expect(received).resolves.toEqual(expected) // deep equality - Expected - 1 + Received + 0 @@ -1,8 +1,7 @@ Object { "dependency1": Object { - "dep1Export": "dep1 val1", "dep1Val": "dep1 val2", }, "dependency2": Object { "dep2Val": "dep2 val", }, at Object.toEqual (node_modules/expect/build/index.js:174:22) at Object.toEqual (packages/docusaurus-utils/src/__tests__/moduleUtils.test.ts:136:47)

Check failure on line 136 in packages/docusaurus-utils/src/__tests__/moduleUtils.test.ts

View workflow job for this annotation

GitHub Actions / Windows Tests (22)

loadFreshModule › module graph › can load and reload fresh module graph

expect(received).resolves.toEqual(expected) // deep equality - Expected - 1 + Received + 0 @@ -1,8 +1,7 @@ Object { "dependency1": Object { - "dep1Export": "dep1 val1", "dep1Val": "dep1 val2", }, "dependency2": Object { "dep2Val": "dep2 val", }, at Object.toEqual (node_modules/expect/build/index.js:174:22) at Object.toEqual (packages/docusaurus-utils/src/__tests__/moduleUtils.test.ts:136:47)

Check failure on line 136 in packages/docusaurus-utils/src/__tests__/moduleUtils.test.ts

View workflow job for this annotation

GitHub Actions / Tests (22)

loadFreshModule › module graph › can load and reload fresh module graph

expect(received).resolves.toEqual(expected) // deep equality - Expected - 1 + Received + 0 @@ -1,8 +1,7 @@ Object { "dependency1": Object { - "dep1Export": "dep1 val1", "dep1Val": "dep1 val2", }, "dependency2": Object { "dep2Val": "dep2 val", }, at Object.toEqual (node_modules/expect/build/index.js:174:22) at Object.toEqual (packages/docusaurus-utils/src/__tests__/moduleUtils.test.ts:136:47)
someEntryValue: 'entryVal',
entryValue: 'entryVal1',
someEntryValue: 'entryVal2',
dependency1: {
dep1Export: 'dep1 val1',
dep1Val: 'dep1 val2',
Expand All @@ -159,7 +162,8 @@
`,
);
await expect(entryFile.load()).resolves.toEqual({
someEntryValue: 'entryVal',
entryValue: 'entryVal1',
someEntryValue: 'entryVal2',
dependency1: {
dep1Export: 'dep1 val1 updated',
dep1Val: 'dep1 val2 updated',
Expand All @@ -184,7 +188,8 @@
`,
);
await expect(entryFile.load()).resolves.toEqual({
someEntryValue: 'entryVal',
entryValue: 'entryVal1',
someEntryValue: 'entryVal2',
dependency1: {
dep1Export: 'dep1 val1 updated',
dep1Val: 'dep1 val2 updated',
Expand All @@ -208,16 +213,19 @@
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"
}
`,
);
await expect(entryFile.load()).resolves.toEqual({
someEntryValue: 'entryVal updated',
entryValue: 'entryVal1 updated',
someEntryValue: 'entryVal2 updated',
newAttribute: 'is there',
dependency1: {
dep1Export: 'dep1 val1 updated',
Expand Down
12 changes: 7 additions & 5 deletions packages/docusaurus-utils/src/moduleUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';

/*
Expand All @@ -18,20 +18,22 @@ export async function loadFreshModule(modulePath: string): Promise<unknown> {
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
interopDefault: true,
// 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: ${
Expand Down
49 changes: 27 additions & 22 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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==

[email protected]:
version "1.1.12"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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==
Expand Down
Loading