gatsby 5.3.0 → 5.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bootstrap/get-config-file.js +1 -1
- package/dist/bootstrap/get-config-file.js.map +1 -1
- package/dist/bootstrap/resolve-js-file-path.d.ts +6 -0
- package/dist/bootstrap/resolve-js-file-path.js +12 -0
- package/dist/bootstrap/resolve-js-file-path.js.map +1 -1
- package/dist/bootstrap/resolve-module-exports.js +1 -1
- package/dist/bootstrap/resolve-module-exports.js.map +1 -1
- package/dist/datastore/lmdb/lmdb-datastore.js.map +1 -1
- package/dist/utils/cache-lmdb.js +1 -4
- package/dist/utils/cache-lmdb.js.map +1 -1
- package/dist/utils/import-gatsby-plugin.js +1 -1
- package/dist/utils/import-gatsby-plugin.js.map +1 -1
- package/package.json +14 -14
|
@@ -45,7 +45,7 @@ async function attemptImport(siteDirectory, configPath) {
|
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
const importedModule = await import(configFilePath);
|
|
48
|
+
const importedModule = await import((0, _resolveJsFilePath.maybeAddFileProtocol)(configFilePath));
|
|
49
49
|
const configModule = (0, _preferDefault.preferDefault)(importedModule);
|
|
50
50
|
return {
|
|
51
51
|
configFilePath,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-config-file.js","names":["getConfigFile","siteDirectory","configName","distance","compiledResult","attemptImportCompiled","configModule","configFilePath","uncompiledResult","attemptImportUncompiled","attemptImport","configPath","resolveJSFilepath","rootDir","filePath","undefined","importedModule","preferDefault","compiledConfigPath","path","join","COMPILED_CACHE_DIR","error","report","panic","id","context","message","uncompiledConfigPath","testImportError","Error","tsConfig","nearMatch","checkTsAndNearMatch","isTSX","endsWith","isInSrcDir","warn","files","fs","readdir","file","name","ext","parse","isNearMatch"],"sources":["../../src/bootstrap/get-config-file.ts"],"sourcesContent":["import fs from \"fs-extra\"\nimport { testImportError } from \"../utils/test-import-error\"\nimport report from \"gatsby-cli/lib/reporter\"\nimport path from \"path\"\nimport { COMPILED_CACHE_DIR } from \"../utils/parcel/compile-gatsby-files\"\nimport { isNearMatch } from \"../utils/is-near-match\"\nimport { resolveJSFilepath } from \"./resolve-js-file-path\"\nimport { preferDefault } from \"./prefer-default\"\n\nexport async function getConfigFile(\n siteDirectory: string,\n configName: string,\n distance: number = 3\n): Promise<{\n configModule: any\n configFilePath: string\n}> {\n const compiledResult = await attemptImportCompiled(siteDirectory, configName)\n\n if (compiledResult?.configModule && compiledResult?.configFilePath) {\n return compiledResult\n }\n\n const uncompiledResult = await attemptImportUncompiled(\n siteDirectory,\n configName,\n distance\n )\n\n return uncompiledResult || {}\n}\n\nasync function attemptImport(\n siteDirectory: string,\n configPath: string\n): Promise<{\n configModule: unknown\n configFilePath: string\n}> {\n const configFilePath = await resolveJSFilepath({\n rootDir: siteDirectory,\n filePath: configPath,\n })\n\n // The file does not exist, no sense trying to import it\n if (!configFilePath) {\n return { configFilePath: ``, configModule: undefined }\n }\n\n const importedModule = await import(configFilePath)\n const configModule = preferDefault(importedModule)\n\n return { configFilePath, configModule }\n}\n\nasync function attemptImportCompiled(\n siteDirectory: string,\n configName: string\n): Promise<{\n configModule: unknown\n configFilePath: string\n}> {\n let compiledResult\n\n try {\n const compiledConfigPath = path.join(\n `${siteDirectory}/${COMPILED_CACHE_DIR}`,\n configName\n )\n compiledResult = await attemptImport(siteDirectory, compiledConfigPath)\n } catch (error) {\n report.panic({\n id: `11902`,\n error: error,\n context: {\n configName,\n message: error.message,\n },\n })\n }\n\n return compiledResult\n}\n\nasync function attemptImportUncompiled(\n siteDirectory: string,\n configName: string,\n distance: number\n): Promise<{\n configModule: unknown\n configFilePath: string\n}> {\n let uncompiledResult\n\n const uncompiledConfigPath = path.join(siteDirectory, configName)\n\n try {\n uncompiledResult = await attemptImport(siteDirectory, uncompiledConfigPath)\n } catch (error) {\n if (!testImportError(uncompiledConfigPath, error)) {\n report.panic({\n id: `10123`,\n error,\n context: {\n configName,\n message: error.message,\n },\n })\n }\n }\n\n if (uncompiledResult?.configFilePath) {\n return uncompiledResult\n }\n\n const error = new Error(`Cannot find package '${uncompiledConfigPath}'`)\n\n const { tsConfig, nearMatch } = await checkTsAndNearMatch(\n siteDirectory,\n configName,\n distance\n )\n\n // gatsby-config.ts exists but compiled gatsby-config.js does not\n if (tsConfig) {\n report.panic({\n id: `10127`,\n error,\n context: {\n configName,\n },\n })\n }\n\n // gatsby-config is misnamed\n if (nearMatch) {\n const isTSX = nearMatch.endsWith(`.tsx`)\n report.panic({\n id: `10124`,\n error,\n context: {\n configName,\n nearMatch,\n isTSX,\n },\n })\n }\n\n // gatsby-config is incorrectly located in src directory\n const isInSrcDir = await resolveJSFilepath({\n rootDir: siteDirectory,\n filePath: path.join(siteDirectory, `src`, configName),\n warn: false,\n })\n\n if (isInSrcDir) {\n report.panic({\n id: `10125`,\n context: {\n configName,\n },\n })\n }\n\n return uncompiledResult\n}\n\nasync function checkTsAndNearMatch(\n siteDirectory: string,\n configName: string,\n distance: number\n): Promise<{\n tsConfig: boolean\n nearMatch: string\n}> {\n const files = await fs.readdir(siteDirectory)\n\n let tsConfig = false\n let nearMatch = ``\n\n for (const file of files) {\n if (tsConfig || nearMatch) {\n break\n }\n\n const { name, ext } = path.parse(file)\n\n if (name === configName && ext === `.ts`) {\n tsConfig = true\n break\n }\n\n if (isNearMatch(name, configName, distance)) {\n nearMatch = file\n }\n }\n\n return {\n tsConfig,\n nearMatch,\n }\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEO,eAAeA,aAAf,CACLC,aADK,EAELC,UAFK,EAGLC,QAAgB,GAAG,CAHd,EAOJ;EACD,MAAMC,cAAc,GAAG,MAAMC,qBAAqB,CAACJ,aAAD,EAAgBC,UAAhB,CAAlD;;EAEA,IAAIE,cAAc,SAAd,IAAAA,cAAc,WAAd,IAAAA,cAAc,CAAEE,YAAhB,IAAgCF,cAAhC,aAAgCA,cAAhC,eAAgCA,cAAc,CAAEG,cAApD,EAAoE;IAClE,OAAOH,cAAP;EACD;;EAED,MAAMI,gBAAgB,GAAG,MAAMC,uBAAuB,CACpDR,aADoD,EAEpDC,UAFoD,EAGpDC,QAHoD,CAAtD;EAMA,OAAOK,gBAAgB,IAAI,EAA3B;AACD;;AAED,eAAeE,aAAf,CACET,aADF,EAEEU,UAFF,EAMG;EACD,MAAMJ,cAAc,GAAG,MAAM,IAAAK,oCAAA,EAAkB;IAC7CC,OAAO,EAAEZ,aADoC;IAE7Ca,QAAQ,EAAEH;EAFmC,CAAlB,CAA7B,CADC,CAMD;;EACA,IAAI,CAACJ,cAAL,EAAqB;IACnB,OAAO;MAAEA,cAAc,EAAG,EAAnB;MAAsBD,YAAY,EAAES;IAApC,CAAP;EACD;;EAED,MAAMC,cAAc,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"get-config-file.js","names":["getConfigFile","siteDirectory","configName","distance","compiledResult","attemptImportCompiled","configModule","configFilePath","uncompiledResult","attemptImportUncompiled","attemptImport","configPath","resolveJSFilepath","rootDir","filePath","undefined","importedModule","maybeAddFileProtocol","preferDefault","compiledConfigPath","path","join","COMPILED_CACHE_DIR","error","report","panic","id","context","message","uncompiledConfigPath","testImportError","Error","tsConfig","nearMatch","checkTsAndNearMatch","isTSX","endsWith","isInSrcDir","warn","files","fs","readdir","file","name","ext","parse","isNearMatch"],"sources":["../../src/bootstrap/get-config-file.ts"],"sourcesContent":["import fs from \"fs-extra\"\nimport { testImportError } from \"../utils/test-import-error\"\nimport report from \"gatsby-cli/lib/reporter\"\nimport path from \"path\"\nimport { COMPILED_CACHE_DIR } from \"../utils/parcel/compile-gatsby-files\"\nimport { isNearMatch } from \"../utils/is-near-match\"\nimport { resolveJSFilepath, maybeAddFileProtocol } from \"./resolve-js-file-path\"\nimport { preferDefault } from \"./prefer-default\"\n\nexport async function getConfigFile(\n siteDirectory: string,\n configName: string,\n distance: number = 3\n): Promise<{\n configModule: any\n configFilePath: string\n}> {\n const compiledResult = await attemptImportCompiled(siteDirectory, configName)\n\n if (compiledResult?.configModule && compiledResult?.configFilePath) {\n return compiledResult\n }\n\n const uncompiledResult = await attemptImportUncompiled(\n siteDirectory,\n configName,\n distance\n )\n\n return uncompiledResult || {}\n}\n\nasync function attemptImport(\n siteDirectory: string,\n configPath: string\n): Promise<{\n configModule: unknown\n configFilePath: string\n}> {\n const configFilePath = await resolveJSFilepath({\n rootDir: siteDirectory,\n filePath: configPath,\n })\n\n // The file does not exist, no sense trying to import it\n if (!configFilePath) {\n return { configFilePath: ``, configModule: undefined }\n }\n\n const importedModule = await import(maybeAddFileProtocol(configFilePath))\n const configModule = preferDefault(importedModule)\n\n return { configFilePath, configModule }\n}\n\nasync function attemptImportCompiled(\n siteDirectory: string,\n configName: string\n): Promise<{\n configModule: unknown\n configFilePath: string\n}> {\n let compiledResult\n\n try {\n const compiledConfigPath = path.join(\n `${siteDirectory}/${COMPILED_CACHE_DIR}`,\n configName\n )\n compiledResult = await attemptImport(siteDirectory, compiledConfigPath)\n } catch (error) {\n report.panic({\n id: `11902`,\n error: error,\n context: {\n configName,\n message: error.message,\n },\n })\n }\n\n return compiledResult\n}\n\nasync function attemptImportUncompiled(\n siteDirectory: string,\n configName: string,\n distance: number\n): Promise<{\n configModule: unknown\n configFilePath: string\n}> {\n let uncompiledResult\n\n const uncompiledConfigPath = path.join(siteDirectory, configName)\n\n try {\n uncompiledResult = await attemptImport(siteDirectory, uncompiledConfigPath)\n } catch (error) {\n if (!testImportError(uncompiledConfigPath, error)) {\n report.panic({\n id: `10123`,\n error,\n context: {\n configName,\n message: error.message,\n },\n })\n }\n }\n\n if (uncompiledResult?.configFilePath) {\n return uncompiledResult\n }\n\n const error = new Error(`Cannot find package '${uncompiledConfigPath}'`)\n\n const { tsConfig, nearMatch } = await checkTsAndNearMatch(\n siteDirectory,\n configName,\n distance\n )\n\n // gatsby-config.ts exists but compiled gatsby-config.js does not\n if (tsConfig) {\n report.panic({\n id: `10127`,\n error,\n context: {\n configName,\n },\n })\n }\n\n // gatsby-config is misnamed\n if (nearMatch) {\n const isTSX = nearMatch.endsWith(`.tsx`)\n report.panic({\n id: `10124`,\n error,\n context: {\n configName,\n nearMatch,\n isTSX,\n },\n })\n }\n\n // gatsby-config is incorrectly located in src directory\n const isInSrcDir = await resolveJSFilepath({\n rootDir: siteDirectory,\n filePath: path.join(siteDirectory, `src`, configName),\n warn: false,\n })\n\n if (isInSrcDir) {\n report.panic({\n id: `10125`,\n context: {\n configName,\n },\n })\n }\n\n return uncompiledResult\n}\n\nasync function checkTsAndNearMatch(\n siteDirectory: string,\n configName: string,\n distance: number\n): Promise<{\n tsConfig: boolean\n nearMatch: string\n}> {\n const files = await fs.readdir(siteDirectory)\n\n let tsConfig = false\n let nearMatch = ``\n\n for (const file of files) {\n if (tsConfig || nearMatch) {\n break\n }\n\n const { name, ext } = path.parse(file)\n\n if (name === configName && ext === `.ts`) {\n tsConfig = true\n break\n }\n\n if (isNearMatch(name, configName, distance)) {\n nearMatch = file\n }\n }\n\n return {\n tsConfig,\n nearMatch,\n }\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEO,eAAeA,aAAf,CACLC,aADK,EAELC,UAFK,EAGLC,QAAgB,GAAG,CAHd,EAOJ;EACD,MAAMC,cAAc,GAAG,MAAMC,qBAAqB,CAACJ,aAAD,EAAgBC,UAAhB,CAAlD;;EAEA,IAAIE,cAAc,SAAd,IAAAA,cAAc,WAAd,IAAAA,cAAc,CAAEE,YAAhB,IAAgCF,cAAhC,aAAgCA,cAAhC,eAAgCA,cAAc,CAAEG,cAApD,EAAoE;IAClE,OAAOH,cAAP;EACD;;EAED,MAAMI,gBAAgB,GAAG,MAAMC,uBAAuB,CACpDR,aADoD,EAEpDC,UAFoD,EAGpDC,QAHoD,CAAtD;EAMA,OAAOK,gBAAgB,IAAI,EAA3B;AACD;;AAED,eAAeE,aAAf,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KAAP,CAAa;MACXC,EAAE,EAAG,OADM;MAEXC,OAAO,EAAE;QACPzB;MADO;IAFE,CAAb;EAMD;;EAED,OAAOM,gBAAP;AACD;;AAED,eAAe0B,mBAAf,CACEjC,aADF,EAEEC,UAFF,EAGEC,QAHF,EAOG;EACD,MAAMoC,KAAK,GAAG,MAAMC,gBAAA,CAAGC,OAAH,CAAWxC,aAAX,CAApB;EAEA,IAAI+B,QAAQ,GAAG,KAAf;EACA,IAAIC,SAAS,GAAI,EAAjB;;EAEA,KAAK,MAAMS,IAAX,IAAmBH,KAAnB,EAA0B;IACxB,IAAIP,QAAQ,IAAIC,SAAhB,EAA2B;MACzB;IACD;;IAED,MAAM;MAAEU,IAAF;MAAQC;IAAR,IAAgBxB,aAAA,CAAKyB,KAAL,CAAWH,IAAX,CAAtB;;IAEA,IAAIC,IAAI,KAAKzC,UAAT,IAAuB0C,GAAG,KAAM,KAApC,EAA0C;MACxCZ,QAAQ,GAAG,IAAX;MACA;IACD;;IAED,IAAI,IAAAc,wBAAA,EAAYH,IAAZ,EAAkBzC,UAAlB,EAA8BC,QAA9B,CAAJ,EAA6C;MAC3C8B,SAAS,GAAGS,IAAZ;IACD;EACF;;EAED,OAAO;IACLV,QADK;IAELC;EAFK,CAAP;AAID"}
|
|
@@ -1,3 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* On Windows, the file protocol is required for the path to be resolved correctly.
|
|
3
|
+
* On other platforms, the file protocol is not required, but supported, so we want to just always use it.
|
|
4
|
+
* Except jest doesn't work with that and in that environment we never add the file protocol.
|
|
5
|
+
*/
|
|
6
|
+
export declare const maybeAddFileProtocol: (module: string) => string;
|
|
1
7
|
/**
|
|
2
8
|
* Figure out if the file path is .js or .mjs without relying on the fs module, and return the file path if it exists.
|
|
3
9
|
*/
|
|
@@ -3,15 +3,27 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
5
|
exports.__esModule = true;
|
|
6
|
+
exports.maybeAddFileProtocol = void 0;
|
|
6
7
|
exports.resolveJSFilepath = resolveJSFilepath;
|
|
7
8
|
|
|
8
9
|
var _path = _interopRequireDefault(require("path"));
|
|
9
10
|
|
|
11
|
+
var _url = require("url");
|
|
12
|
+
|
|
10
13
|
var _reporter = _interopRequireDefault(require("gatsby-cli/lib/reporter"));
|
|
11
14
|
|
|
15
|
+
/**
|
|
16
|
+
* On Windows, the file protocol is required for the path to be resolved correctly.
|
|
17
|
+
* On other platforms, the file protocol is not required, but supported, so we want to just always use it.
|
|
18
|
+
* Except jest doesn't work with that and in that environment we never add the file protocol.
|
|
19
|
+
*/
|
|
20
|
+
const maybeAddFileProtocol = process.env.JEST_WORKER_ID ? module => module : module => (0, _url.pathToFileURL)(module).href;
|
|
12
21
|
/**
|
|
13
22
|
* Figure out if the file path is .js or .mjs without relying on the fs module, and return the file path if it exists.
|
|
14
23
|
*/
|
|
24
|
+
|
|
25
|
+
exports.maybeAddFileProtocol = maybeAddFileProtocol;
|
|
26
|
+
|
|
15
27
|
async function resolveJSFilepath({
|
|
16
28
|
rootDir,
|
|
17
29
|
filePath,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-js-file-path.js","names":["resolveJSFilepath","rootDir","filePath","warn","filePathWithJSExtension","endsWith","filePathWithMJSExtension","require","resolve","report","path","relative","_"],"sources":["../../src/bootstrap/resolve-js-file-path.ts"],"sourcesContent":["import path from \"path\"\nimport report from \"gatsby-cli/lib/reporter\"\n\n/**\n * Figure out if the file path is .js or .mjs without relying on the fs module, and return the file path if it exists.\n */\nexport async function resolveJSFilepath({\n rootDir,\n filePath,\n warn = true,\n}: {\n rootDir: string\n filePath: string\n warn?: boolean\n}): Promise<string> {\n const filePathWithJSExtension = filePath.endsWith(`.js`)\n ? filePath\n : `${filePath}.js`\n const filePathWithMJSExtension = filePath.endsWith(`.mjs`)\n ? filePath\n : `${filePath}.mjs`\n\n // Check if both variants exist\n try {\n if (\n require.resolve(filePathWithJSExtension) &&\n require.resolve(filePathWithMJSExtension)\n ) {\n if (warn) {\n report.warn(\n `The file '${path.relative(\n rootDir,\n filePath\n )}' has both .js and .mjs variants, please use one or the other. Using .js by default.`\n )\n }\n return filePathWithJSExtension\n }\n } catch (_) {\n // Do nothing\n }\n\n // Check if .js variant exists\n try {\n if (require.resolve(filePathWithJSExtension)) {\n return filePathWithJSExtension\n }\n } catch (_) {\n // Do nothing\n }\n\n try {\n if (require.resolve(filePathWithMJSExtension)) {\n return filePathWithMJSExtension\n }\n } catch (_) {\n // Do nothing\n }\n\n return ``\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"resolve-js-file-path.js","names":["maybeAddFileProtocol","process","env","JEST_WORKER_ID","module","pathToFileURL","href","resolveJSFilepath","rootDir","filePath","warn","filePathWithJSExtension","endsWith","filePathWithMJSExtension","require","resolve","report","path","relative","_"],"sources":["../../src/bootstrap/resolve-js-file-path.ts"],"sourcesContent":["import path from \"path\"\nimport { pathToFileURL } from \"url\"\nimport report from \"gatsby-cli/lib/reporter\"\n\n/**\n * On Windows, the file protocol is required for the path to be resolved correctly.\n * On other platforms, the file protocol is not required, but supported, so we want to just always use it.\n * Except jest doesn't work with that and in that environment we never add the file protocol.\n */\nexport const maybeAddFileProtocol = process.env.JEST_WORKER_ID\n ? (module: string): string => module\n : (module: string): string => pathToFileURL(module).href\n\n/**\n * Figure out if the file path is .js or .mjs without relying on the fs module, and return the file path if it exists.\n */\nexport async function resolveJSFilepath({\n rootDir,\n filePath,\n warn = true,\n}: {\n rootDir: string\n filePath: string\n warn?: boolean\n}): Promise<string> {\n const filePathWithJSExtension = filePath.endsWith(`.js`)\n ? filePath\n : `${filePath}.js`\n const filePathWithMJSExtension = filePath.endsWith(`.mjs`)\n ? filePath\n : `${filePath}.mjs`\n\n // Check if both variants exist\n try {\n if (\n require.resolve(filePathWithJSExtension) &&\n require.resolve(filePathWithMJSExtension)\n ) {\n if (warn) {\n report.warn(\n `The file '${path.relative(\n rootDir,\n filePath\n )}' has both .js and .mjs variants, please use one or the other. Using .js by default.`\n )\n }\n return filePathWithJSExtension\n }\n } catch (_) {\n // Do nothing\n }\n\n // Check if .js variant exists\n try {\n if (require.resolve(filePathWithJSExtension)) {\n return filePathWithJSExtension\n }\n } catch (_) {\n // Do nothing\n }\n\n try {\n if (require.resolve(filePathWithMJSExtension)) {\n return filePathWithMJSExtension\n }\n } catch (_) {\n // Do nothing\n }\n\n return ``\n}\n"],"mappings":";;;;;;;;AAAA;;AACA;;AACA;;AAEA;AACA;AACA;AACA;AACA;AACO,MAAMA,oBAAoB,GAAGC,OAAO,CAACC,GAAR,CAAYC,cAAZ,GAC/BC,MAAD,IAA4BA,MADI,GAE/BA,MAAD,IAA4B,IAAAC,kBAAA,EAAcD,MAAd,EAAsBE,IAF/C;AAIP;AACA;AACA;;;;AACO,eAAeC,iBAAf,CAAiC;EACtCC,OADsC;EAEtCC,QAFsC;EAGtCC,IAAI,GAAG;AAH+B,CAAjC,EAQa;EAClB,MAAMC,uBAAuB,GAAGF,QAAQ,CAACG,QAAT,CAAmB,KAAnB,IAC5BH,QAD4B,GAE3B,GAAEA,QAAS,KAFhB;EAGA,MAAMI,wBAAwB,GAAGJ,QAAQ,CAACG,QAAT,CAAmB,MAAnB,IAC7BH,QAD6B,GAE5B,GAAEA,QAAS,MAFhB,CAJkB,CAQlB;;EACA,IAAI;IACF,IACEK,OAAO,CAACC,OAAR,CAAgBJ,uBAAhB,KACAG,OAAO,CAACC,OAAR,CAAgBF,wBAAhB,CAFF,EAGE;MACA,IAAIH,IAAJ,EAAU;QACRM,iBAAA,CAAON,IAAP,CACG,aAAYO,aAAA,CAAKC,QAAL,CACXV,OADW,EAEXC,QAFW,CAGX,sFAJJ;MAMD;;MACD,OAAOE,uBAAP;IACD;EACF,CAfD,CAeE,OAAOQ,CAAP,EAAU,CACV;EACD,CA1BiB,CA4BlB;;;EACA,IAAI;IACF,IAAIL,OAAO,CAACC,OAAR,CAAgBJ,uBAAhB,CAAJ,EAA8C;MAC5C,OAAOA,uBAAP;IACD;EACF,CAJD,CAIE,OAAOQ,CAAP,EAAU,CACV;EACD;;EAED,IAAI;IACF,IAAIL,OAAO,CAACC,OAAR,CAAgBF,wBAAhB,CAAJ,EAA+C;MAC7C,OAAOA,wBAAP;IACD;EACF,CAJD,CAIE,OAAOM,CAAP,EAAU,CACV;EACD;;EAED,OAAQ,EAAR;AACD"}
|
|
@@ -200,7 +200,7 @@ async function resolveModuleExports(modulePath, {
|
|
|
200
200
|
return [];
|
|
201
201
|
}
|
|
202
202
|
|
|
203
|
-
const rawImportedModule = await import(moduleFilePath); // If the module is cjs, the properties we care about are nested under a top-level `default` property
|
|
203
|
+
const rawImportedModule = await import((0, _resolveJsFilePath.maybeAddFileProtocol)(moduleFilePath)); // If the module is cjs, the properties we care about are nested under a top-level `default` property
|
|
204
204
|
|
|
205
205
|
const importedModule = (0, _preferDefault.preferDefault)(rawImportedModule);
|
|
206
206
|
return Object.keys(importedModule).filter(exportName => exportName !== `__esModule`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resolve-module-exports.js","names":["staticallyAnalyzeExports","modulePath","resolver","resolveModule","absPath","exportNames","err","code","fs","readFileSync","ast","babelParseToAst","SyntaxError","codeFrame","codeFrameColumns","start","loc","highlightCode","report","panic","message","isCommonJS","isES6","traverse","ImportDeclaration","ExportNamedDeclaration","astPath","declaration","node","type","declarations","id","push","name","ExportSpecifier","exp","exported","exportName","ExportDefaultDeclaration","t","isIdentifier","isArrowFunctionExpression","isFunctionDeclaration","AssignmentExpression","nodeLeft","left","isMemberExpression","property","object","process","env","NODE_ENV","resolveModuleExports","mode","rootDir","cwd","moduleFilePath","resolveJSFilepath","filePath","rawImportedModule","importedModule","preferDefault","Object","keys","filter","error","testImportError"],"sources":["../../src/bootstrap/resolve-module-exports.ts"],"sourcesContent":["import * as fs from \"fs-extra\"\nimport * as t from \"@babel/types\"\nimport traverse from \"@babel/traverse\"\nimport { codeFrameColumns, SourceLocation } from \"@babel/code-frame\"\nimport report from \"gatsby-cli/lib/reporter\"\nimport { babelParseToAst } from \"../utils/babel-parse-to-ast\"\nimport { testImportError } from \"../utils/test-import-error\"\nimport { resolveModule, ModuleResolver } from \"../utils/module-resolver\"\nimport { resolveJSFilepath } from \"./resolve-js-file-path\"\nimport { preferDefault } from \"./prefer-default\"\n\nconst staticallyAnalyzeExports = (\n modulePath: string,\n resolver = resolveModule\n): Array<string> => {\n let absPath: string | undefined\n const exportNames: Array<string> = []\n\n try {\n absPath = resolver(modulePath) as string\n } catch (err) {\n return exportNames // doesn't exist\n }\n const code = fs.readFileSync(absPath, `utf8`) // get file contents\n\n let ast\n try {\n ast = babelParseToAst(code, absPath)\n } catch (err) {\n if (err instanceof SyntaxError) {\n // Pretty print syntax errors\n const codeFrame = codeFrameColumns(\n code,\n {\n start: (err as unknown as { loc: SourceLocation[\"start\"] }).loc,\n },\n {\n highlightCode: true,\n }\n )\n\n report.panic(\n `Syntax error in \"${absPath}\":\\n${err.message}\\n${codeFrame}`\n )\n } else {\n // if it's not syntax error, just throw it\n throw err\n }\n }\n\n let isCommonJS = false\n let isES6 = false\n\n // extract names of exports from file\n traverse(ast, {\n // Check if the file is using ES6 imports\n ImportDeclaration: function ImportDeclaration() {\n isES6 = true\n },\n\n ExportNamedDeclaration: function ExportNamedDeclaration(astPath) {\n const declaration = astPath.node.declaration\n\n // get foo from `export const foo = bar`\n if (\n declaration?.type === `VariableDeclaration` &&\n declaration.declarations[0]?.id.type === `Identifier`\n ) {\n isES6 = true\n exportNames.push(declaration.declarations[0].id.name)\n }\n\n // get foo from `export function foo()`\n if (\n declaration?.type === `FunctionDeclaration` &&\n declaration.id?.type === `Identifier`\n ) {\n isES6 = true\n exportNames.push(declaration.id.name)\n }\n },\n\n // get foo from `export { foo } from 'bar'`\n // get foo from `export { foo }`\n ExportSpecifier: function ExportSpecifier(astPath) {\n isES6 = true\n const exp = astPath?.node?.exported\n if (!exp) {\n return\n }\n if (exp.type === `Identifier`) {\n const exportName = exp.name\n if (exportName) {\n exportNames.push(exportName)\n }\n }\n },\n\n // export default () => {}\n // export default function() {}\n // export default function foo() {}\n // const foo = () => {}; export default foo\n ExportDefaultDeclaration: function ExportDefaultDeclaration(astPath) {\n const declaration = astPath.node.declaration\n if (\n !t.isIdentifier(declaration) &&\n !t.isArrowFunctionExpression(declaration) &&\n !t.isFunctionDeclaration(declaration)\n ) {\n return\n }\n\n let name = ``\n if (t.isIdentifier(declaration)) {\n name = declaration.name\n } else if (t.isFunctionDeclaration(declaration) && declaration.id) {\n name = declaration.id.name\n }\n\n const exportName = `export default${name ? ` ${name}` : ``}`\n isES6 = true\n exportNames.push(exportName)\n },\n\n AssignmentExpression: function AssignmentExpression(astPath) {\n const nodeLeft = astPath.node.left\n\n if (!t.isMemberExpression(nodeLeft)) {\n return\n }\n\n // ignore marker property `__esModule`\n if (\n t.isIdentifier(nodeLeft.property) &&\n nodeLeft.property.name === `__esModule`\n ) {\n return\n }\n\n // get foo from `exports.foo = bar`\n if (\n t.isIdentifier(nodeLeft.object) &&\n nodeLeft.object.name === `exports`\n ) {\n isCommonJS = true\n exportNames.push((nodeLeft.property as t.Identifier).name)\n }\n\n // get foo from `module.exports.foo = bar`\n if (t.isMemberExpression(nodeLeft.object)) {\n const exp: t.MemberExpression = nodeLeft.object\n\n if (\n t.isIdentifier(exp.object) &&\n t.isIdentifier(exp.property) &&\n exp.object.name === `module` &&\n exp.property.name === `exports`\n ) {\n isCommonJS = true\n exportNames.push((nodeLeft.property as t.Identifier).name)\n }\n }\n },\n })\n\n if (isES6 && isCommonJS && process.env.NODE_ENV !== `test`) {\n report.panic(\n `This plugin file is using both CommonJS and ES6 module systems together which we don't support.\nYou'll need to edit the file to use just one or the other.\n\nplugin: ${modulePath}.js\n\nThis didn't cause a problem in Gatsby v1 so you might want to review the migration doc for this:\nhttps://gatsby.dev/no-mixed-modules\n `\n )\n }\n return exportNames\n}\n\ninterface IResolveModuleExportsOptions {\n mode?: `analysis` | `import`\n resolver?: ModuleResolver\n rootDir?: string\n}\n\n/**\n * Given a path to a module, return an array of the module's exports.\n *\n * It can run in two modes:\n * 1. `analysis` mode gets exports via static analysis by traversing the file's AST with babel\n * 2. `import` mode gets exports by directly importing the module and accessing its properties\n *\n * At the time of writing, analysis mode is used for files that can be jsx (e.g. gatsby-browser, gatsby-ssr)\n * and import mode is used for files that can be js or mjs.\n *\n * Returns [] for invalid paths and modules without exports.\n */\nexport async function resolveModuleExports(\n modulePath: string,\n {\n mode = `analysis`,\n resolver = resolveModule,\n rootDir = process.cwd(),\n }: IResolveModuleExportsOptions = {}\n): Promise<Array<string>> {\n if (mode === `import`) {\n try {\n const moduleFilePath = await resolveJSFilepath({\n rootDir,\n filePath: modulePath,\n })\n\n if (!moduleFilePath) {\n return []\n }\n\n const rawImportedModule = await import(moduleFilePath)\n\n // If the module is cjs, the properties we care about are nested under a top-level `default` property\n const importedModule = preferDefault(rawImportedModule)\n\n return Object.keys(importedModule).filter(\n exportName => exportName !== `__esModule`\n )\n } catch (error) {\n if (!testImportError(modulePath, error)) {\n // if module exists, but requiring it cause errors,\n // show the error to the user and terminate build\n report.panic(`Error in \"${modulePath}\":`, error)\n }\n }\n } else {\n return staticallyAnalyzeExports(modulePath, resolver)\n }\n\n return []\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,MAAMA,wBAAwB,GAAG,CAC/BC,UAD+B,EAE/BC,QAAQ,GAAGC,6BAFoB,KAGb;EAClB,IAAIC,OAAJ;EACA,MAAMC,WAA0B,GAAG,EAAnC;;EAEA,IAAI;IACFD,OAAO,GAAGF,QAAQ,CAACD,UAAD,CAAlB;EACD,CAFD,CAEE,OAAOK,GAAP,EAAY;IACZ,OAAOD,WAAP,CADY,CACO;EACpB;;EACD,MAAME,IAAI,GAAGC,EAAE,CAACC,YAAH,CAAgBL,OAAhB,EAA0B,MAA1B,C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AO,EAAP;AACD"}
|
|
1
|
+
{"version":3,"file":"resolve-module-exports.js","names":["staticallyAnalyzeExports","modulePath","resolver","resolveModule","absPath","exportNames","err","code","fs","readFileSync","ast","babelParseToAst","SyntaxError","codeFrame","codeFrameColumns","start","loc","highlightCode","report","panic","message","isCommonJS","isES6","traverse","ImportDeclaration","ExportNamedDeclaration","astPath","declaration","node","type","declarations","id","push","name","ExportSpecifier","exp","exported","exportName","ExportDefaultDeclaration","t","isIdentifier","isArrowFunctionExpression","isFunctionDeclaration","AssignmentExpression","nodeLeft","left","isMemberExpression","property","object","process","env","NODE_ENV","resolveModuleExports","mode","rootDir","cwd","moduleFilePath","resolveJSFilepath","filePath","rawImportedModule","maybeAddFileProtocol","importedModule","preferDefault","Object","keys","filter","error","testImportError"],"sources":["../../src/bootstrap/resolve-module-exports.ts"],"sourcesContent":["import * as fs from \"fs-extra\"\nimport * as t from \"@babel/types\"\nimport traverse from \"@babel/traverse\"\nimport { codeFrameColumns, SourceLocation } from \"@babel/code-frame\"\nimport report from \"gatsby-cli/lib/reporter\"\nimport { babelParseToAst } from \"../utils/babel-parse-to-ast\"\nimport { testImportError } from \"../utils/test-import-error\"\nimport { resolveModule, ModuleResolver } from \"../utils/module-resolver\"\nimport { maybeAddFileProtocol, resolveJSFilepath } from \"./resolve-js-file-path\"\nimport { preferDefault } from \"./prefer-default\"\n\nconst staticallyAnalyzeExports = (\n modulePath: string,\n resolver = resolveModule\n): Array<string> => {\n let absPath: string | undefined\n const exportNames: Array<string> = []\n\n try {\n absPath = resolver(modulePath) as string\n } catch (err) {\n return exportNames // doesn't exist\n }\n const code = fs.readFileSync(absPath, `utf8`) // get file contents\n\n let ast\n try {\n ast = babelParseToAst(code, absPath)\n } catch (err) {\n if (err instanceof SyntaxError) {\n // Pretty print syntax errors\n const codeFrame = codeFrameColumns(\n code,\n {\n start: (err as unknown as { loc: SourceLocation[\"start\"] }).loc,\n },\n {\n highlightCode: true,\n }\n )\n\n report.panic(\n `Syntax error in \"${absPath}\":\\n${err.message}\\n${codeFrame}`\n )\n } else {\n // if it's not syntax error, just throw it\n throw err\n }\n }\n\n let isCommonJS = false\n let isES6 = false\n\n // extract names of exports from file\n traverse(ast, {\n // Check if the file is using ES6 imports\n ImportDeclaration: function ImportDeclaration() {\n isES6 = true\n },\n\n ExportNamedDeclaration: function ExportNamedDeclaration(astPath) {\n const declaration = astPath.node.declaration\n\n // get foo from `export const foo = bar`\n if (\n declaration?.type === `VariableDeclaration` &&\n declaration.declarations[0]?.id.type === `Identifier`\n ) {\n isES6 = true\n exportNames.push(declaration.declarations[0].id.name)\n }\n\n // get foo from `export function foo()`\n if (\n declaration?.type === `FunctionDeclaration` &&\n declaration.id?.type === `Identifier`\n ) {\n isES6 = true\n exportNames.push(declaration.id.name)\n }\n },\n\n // get foo from `export { foo } from 'bar'`\n // get foo from `export { foo }`\n ExportSpecifier: function ExportSpecifier(astPath) {\n isES6 = true\n const exp = astPath?.node?.exported\n if (!exp) {\n return\n }\n if (exp.type === `Identifier`) {\n const exportName = exp.name\n if (exportName) {\n exportNames.push(exportName)\n }\n }\n },\n\n // export default () => {}\n // export default function() {}\n // export default function foo() {}\n // const foo = () => {}; export default foo\n ExportDefaultDeclaration: function ExportDefaultDeclaration(astPath) {\n const declaration = astPath.node.declaration\n if (\n !t.isIdentifier(declaration) &&\n !t.isArrowFunctionExpression(declaration) &&\n !t.isFunctionDeclaration(declaration)\n ) {\n return\n }\n\n let name = ``\n if (t.isIdentifier(declaration)) {\n name = declaration.name\n } else if (t.isFunctionDeclaration(declaration) && declaration.id) {\n name = declaration.id.name\n }\n\n const exportName = `export default${name ? ` ${name}` : ``}`\n isES6 = true\n exportNames.push(exportName)\n },\n\n AssignmentExpression: function AssignmentExpression(astPath) {\n const nodeLeft = astPath.node.left\n\n if (!t.isMemberExpression(nodeLeft)) {\n return\n }\n\n // ignore marker property `__esModule`\n if (\n t.isIdentifier(nodeLeft.property) &&\n nodeLeft.property.name === `__esModule`\n ) {\n return\n }\n\n // get foo from `exports.foo = bar`\n if (\n t.isIdentifier(nodeLeft.object) &&\n nodeLeft.object.name === `exports`\n ) {\n isCommonJS = true\n exportNames.push((nodeLeft.property as t.Identifier).name)\n }\n\n // get foo from `module.exports.foo = bar`\n if (t.isMemberExpression(nodeLeft.object)) {\n const exp: t.MemberExpression = nodeLeft.object\n\n if (\n t.isIdentifier(exp.object) &&\n t.isIdentifier(exp.property) &&\n exp.object.name === `module` &&\n exp.property.name === `exports`\n ) {\n isCommonJS = true\n exportNames.push((nodeLeft.property as t.Identifier).name)\n }\n }\n },\n })\n\n if (isES6 && isCommonJS && process.env.NODE_ENV !== `test`) {\n report.panic(\n `This plugin file is using both CommonJS and ES6 module systems together which we don't support.\nYou'll need to edit the file to use just one or the other.\n\nplugin: ${modulePath}.js\n\nThis didn't cause a problem in Gatsby v1 so you might want to review the migration doc for this:\nhttps://gatsby.dev/no-mixed-modules\n `\n )\n }\n return exportNames\n}\n\ninterface IResolveModuleExportsOptions {\n mode?: `analysis` | `import`\n resolver?: ModuleResolver\n rootDir?: string\n}\n\n/**\n * Given a path to a module, return an array of the module's exports.\n *\n * It can run in two modes:\n * 1. `analysis` mode gets exports via static analysis by traversing the file's AST with babel\n * 2. `import` mode gets exports by directly importing the module and accessing its properties\n *\n * At the time of writing, analysis mode is used for files that can be jsx (e.g. gatsby-browser, gatsby-ssr)\n * and import mode is used for files that can be js or mjs.\n *\n * Returns [] for invalid paths and modules without exports.\n */\nexport async function resolveModuleExports(\n modulePath: string,\n {\n mode = `analysis`,\n resolver = resolveModule,\n rootDir = process.cwd(),\n }: IResolveModuleExportsOptions = {}\n): Promise<Array<string>> {\n if (mode === `import`) {\n try {\n const moduleFilePath = await resolveJSFilepath({\n rootDir,\n filePath: modulePath,\n })\n\n if (!moduleFilePath) {\n return []\n }\n\n const rawImportedModule = await import(\n maybeAddFileProtocol(moduleFilePath)\n )\n\n // If the module is cjs, the properties we care about are nested under a top-level `default` property\n const importedModule = preferDefault(rawImportedModule)\n\n return Object.keys(importedModule).filter(\n exportName => exportName !== `__esModule`\n )\n } catch (error) {\n if (!testImportError(modulePath, error)) {\n // if module exists, but requiring it cause errors,\n // show the error to the user and terminate build\n report.panic(`Error in \"${modulePath}\":`, error)\n }\n }\n } else {\n return staticallyAnalyzeExports(modulePath, resolver)\n }\n\n return []\n}\n"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;AAEA,MAAMA,wBAAwB,GAAG,CAC/BC,UAD+B,EAE/BC,QAAQ,GAAGC,6BAFoB,KAGb;EAClB,IAAIC,OAAJ;EACA,MAAMC,WAA0B,GAAG,EAAnC;;EAEA,IAAI;IACFD,OAAO,GAAGF,QAAQ,CAACD,UAAD,CAAlB;EACD,CAFD,CAEE,OAAOK,GAAP,EAAY;IACZ,OAAOD,WAAP,CADY,CACO;EACpB;;EACD,MAAME,IAAI,GAAGC,EAAE,CAACC,YAAH,CAAgBL,OAAhB,EAA0B,MAA1B,CAAb,CATkB,CAS4B;;EAE9C,IAAIM,GAAJ;;EACA,IAAI;IACFA,GAAG,GAAG,IAAAC,gCAAA,EAAgBJ,IAAhB,EAAsBH,OAAtB,CAAN;EACD,CAFD,CAEE,OAAOE,GAAP,EAAY;IACZ,IAAIA,GAAG,YAAYM,WAAnB,EAAgC;MAC9B;MACA,MAAMC,SAAS,GAAG,IAAAC,2BAAA,EAChBP,IADgB,EAEhB;QACEQ,KAAK,EAAGT,GAAD,CAAqDU;MAD9D,CAFgB,EAKhB;QACEC,aAAa,EAAE;MADjB,CALgB,CAAlB;;MAUAC,iBAAA,CAAOC,KAAP,CACG,oBAAmBf,OAAQ,OAAME,GAAG,CAACc,OAAQ,KAAIP,SAAU,EAD9D;IAGD,CAfD,MAeO;MACL;MACA,MAAMP,GAAN;IACD;EACF;;EAED,IAAIe,UAAU,GAAG,KAAjB;EACA,IAAIC,KAAK,GAAG,KAAZ,CArCkB,CAuClB;;EACA,IAAAC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;QAE7CI,QAAQ,EAAEzD;MAFmC,CAAlB,CAA7B;;MAKA,IAAI,CAACuD,cAAL,EAAqB;QACnB,OAAO,EAAP;MACD;;MAED,MAAMG,iBAAiB,GAAG,MAAM,OAC9B,IAAAC,uCAAA,EAAqBJ,cAArB,CAD8B,CAAhC,CAVE,CAcF;;MACA,MAAMK,cAAc,GAAG,IAAAC,4BAAA,EAAcH,iBAAd,CAAvB;MAEA,OAAOI,MAAM,CAACC,IAAP,CAAYH,cAAZ,EAA4BI,MAA5B,CACL5B,UAAU,IAAIA,UAAU,KAAM,YADzB,CAAP;IAGD,CApBD,CAoBE,OAAO6B,KAAP,EAAc;MACd,IAAI,CAAC,IAAAC,gCAAA,EAAgBlE,UAAhB,EAA4BiE,KAA5B,CAAL,EAAyC;QACvC;QACA;QACAhD,iBAAA,CAAOC,KAAP,CAAc,aAAYlB,UAAW,IAArC,EAA0CiE,KAA1C;MACD;IACF;EACF,CA5BD,MA4BO;IACL,OAAOlE,wBAAwB,CAACC,UAAD,EAAaC,QAAb,CAA/B;EACD;;EAED,OAAO,EAAP;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lmdb-datastore.js","names":["lmdbDatastore","getNode","getTypes","countNodes","iterateNodes","iterateNodesByType","updateDataStore","ready","runQuery","getNodes","getNodesByType","preSyncDeletedNodeIdsCache","Set","getDefaultDbPath","dbFileName","process","env","NODE_ENV","FORCE_TEST_DATABASE_ID","JEST_WORKER_ID","cwd","fullDbPath","rootDb","databases","getRootDb","Error","globalThis","__GATSBY_OPEN_ROOT_LMDBS","Map","get","open","name","path","compression","set","getDatabases","__GATSBY_OPEN_LMDBS","nodes","openDB","cache","expirer","nodesByType","dupSort","metadata","useVersions","indexes","result","Array","from","type","nodesDb","GatsbyIterable","getKeys","snapshot","map","nodeId","undefined","filter","Boolean","getValues","id","has","asArray","typeName","stats","getStats","Math","max","Number","entryCount","size","getValuesCount","args","GATSBY_EXPERIMENTAL_LMDB_INDEXES","doRunQuery","datastore","Promise","resolve","runFastFiltersAndSort","lastOperationPromise","action","dbs","transactionSync","clearSync","clearIndexes","operationPromise","all","updateNodes","updateNodesByType","delete","payload","add","then","clear","setupLmdbStore","dbPath","replaceReducer","state","emitter","on"],"sources":["../../../src/datastore/lmdb/lmdb-datastore.ts"],"sourcesContent":["import { RootDatabase, open, RangeIterable } from \"lmdb\"\n// import { performance } from \"perf_hooks\"\nimport { ActionsUnion, IGatsbyNode } from \"../../redux/types\"\nimport { updateNodes } from \"./updates/nodes\"\nimport { updateNodesByType } from \"./updates/nodes-by-type\"\nimport { IDataStore, ILmdbDatabases, IQueryResult } from \"../types\"\nimport { emitter, replaceReducer } from \"../../redux\"\nimport { GatsbyIterable } from \"../common/iterable\"\nimport { doRunQuery } from \"./query/run-query\"\nimport {\n IRunFilterArg,\n runFastFiltersAndSort,\n} from \"../in-memory/run-fast-filters\"\n\nconst lmdbDatastore = {\n getNode,\n getTypes,\n countNodes,\n iterateNodes,\n iterateNodesByType,\n updateDataStore,\n ready,\n runQuery,\n\n // deprecated:\n getNodes,\n getNodesByType,\n}\n\nconst preSyncDeletedNodeIdsCache = new Set()\n\nfunction getDefaultDbPath(): string {\n const dbFileName =\n process.env.NODE_ENV === `test`\n ? `test-datastore-${\n // FORCE_TEST_DATABASE_ID will be set if this gets executed in worker context\n // when running jest tests. JEST_WORKER_ID will be set when this gets executed directly\n // in test context (jest will use jest-worker internally).\n process.env.FORCE_TEST_DATABASE_ID ?? process.env.JEST_WORKER_ID\n }`\n : `datastore`\n\n return process.cwd() + `/.cache/data/` + dbFileName\n}\n\nlet fullDbPath\nlet rootDb\nlet databases\n\n/* eslint-disable @typescript-eslint/no-namespace */\ndeclare global {\n namespace NodeJS {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n interface Global {\n __GATSBY_OPEN_LMDBS?: Map<string, ILmdbDatabases>\n __GATSBY_OPEN_ROOT_LMDBS?: Map<string, RootDatabase>\n }\n }\n}\n\nfunction getRootDb(): RootDatabase {\n if (!rootDb) {\n if (!fullDbPath) {\n throw new Error(`LMDB path is not set!`)\n }\n\n if (!globalThis.__GATSBY_OPEN_ROOT_LMDBS) {\n globalThis.__GATSBY_OPEN_ROOT_LMDBS = new Map()\n }\n rootDb = globalThis.__GATSBY_OPEN_ROOT_LMDBS.get(fullDbPath)\n if (rootDb) {\n return rootDb\n }\n\n rootDb = open({\n name: `root`,\n path: fullDbPath,\n compression: true,\n })\n\n globalThis.__GATSBY_OPEN_ROOT_LMDBS.set(fullDbPath, rootDb)\n }\n return rootDb\n}\n\nfunction getDatabases(): ILmdbDatabases {\n if (!databases) {\n // __GATSBY_OPEN_LMDBS tracks if we already opened given db in this process\n // In `gatsby serve` case we might try to open it twice - once for engines\n // and second to get access to `SitePage` nodes (to power trailing slashes\n // redirect middleware). This ensure there is single instance within a process.\n // Using more instances seems to cause weird random errors.\n if (!globalThis.__GATSBY_OPEN_LMDBS) {\n globalThis.__GATSBY_OPEN_LMDBS = new Map()\n }\n databases = globalThis.__GATSBY_OPEN_LMDBS.get(fullDbPath)\n if (databases) {\n return databases\n }\n\n const rootDb = getRootDb()\n databases = {\n nodes: rootDb.openDB({\n name: `nodes`,\n // FIXME: sharedStructuresKey breaks tests - probably need some cleanup for it on DELETE_CACHE\n // sharedStructuresKey: Symbol.for(`structures`),\n // @ts-ignore\n cache: {\n // expirer: false disables LRU part and only take care of WeakRefs\n // this way we don't retain nodes strongly, but will continue to\n // reuse them if they are loaded already\n expirer: false,\n },\n }),\n nodesByType: rootDb.openDB({\n name: `nodesByType`,\n dupSort: true,\n }),\n metadata: rootDb.openDB({\n name: `metadata`,\n useVersions: true,\n }),\n indexes: rootDb.openDB({\n name: `indexes`,\n // TODO: use dupSort when this is ready: https://github.com/DoctorEvidence/lmdb-store/issues/66\n // dupSort: true\n }),\n }\n globalThis.__GATSBY_OPEN_LMDBS.set(fullDbPath, databases)\n }\n return databases\n}\n\n/**\n * @deprecated\n */\nfunction getNodes(): Array<IGatsbyNode> {\n // const start = performance.now()\n const result = Array.from<IGatsbyNode>(iterateNodes())\n // const timeTotal = performance.now() - start\n // console.warn(\n // `getNodes() is deprecated, use iterateNodes() instead; ` +\n // `array length: ${result.length}; time(ms): ${timeTotal}`\n // )\n return result ?? []\n}\n\n/**\n * @deprecated\n */\nfunction getNodesByType(type: string): Array<IGatsbyNode> {\n // const start = performance.now()\n const result = Array.from<IGatsbyNode>(iterateNodesByType(type))\n // const timeTotal = performance.now() - start\n // console.warn(\n // `getNodesByType() is deprecated, use iterateNodesByType() instead; ` +\n // `array length: ${result.length}; time(ms): ${timeTotal}`\n // )\n return result ?? []\n}\n\nfunction iterateNodes(): GatsbyIterable<IGatsbyNode> {\n // Additionally fetching items by id to leverage lmdb-store cache\n const nodesDb = getDatabases().nodes\n return new GatsbyIterable(\n nodesDb\n .getKeys({ snapshot: false })\n .map(nodeId => (typeof nodeId === `string` ? getNode(nodeId) : undefined))\n .filter(Boolean) as RangeIterable<IGatsbyNode>\n )\n}\n\nfunction iterateNodesByType(type: string): GatsbyIterable<IGatsbyNode> {\n const nodesByType = getDatabases().nodesByType\n return new GatsbyIterable(\n nodesByType\n .getValues(type)\n .map(nodeId => getNode(nodeId))\n .filter(Boolean) as RangeIterable<IGatsbyNode>\n )\n}\n\nfunction getNode(id: string): IGatsbyNode | undefined {\n if (!id || preSyncDeletedNodeIdsCache.has(id)) {\n return undefined\n }\n\n const { nodes } = getDatabases()\n return nodes.get(id)\n}\n\nfunction getTypes(): Array<string> {\n return getDatabases().nodesByType.getKeys({}).asArray\n}\n\nfunction countNodes(typeName?: string): number {\n if (!typeName) {\n const stats = getDatabases().nodes.getStats() as { entryCount: number }\n return Math.max(\n Number(stats.entryCount) - preSyncDeletedNodeIdsCache.size,\n 0\n ) // FIXME: add -1 when restoring shared structures key\n }\n\n const { nodesByType } = getDatabases()\n return nodesByType.getValuesCount(typeName)\n}\n\nasync function runQuery(args: IRunFilterArg): Promise<IQueryResult> {\n if (process.env.GATSBY_EXPERIMENTAL_LMDB_INDEXES) {\n return await doRunQuery({\n datastore: lmdbDatastore,\n databases: getDatabases(),\n ...args,\n })\n }\n return Promise.resolve(runFastFiltersAndSort(args))\n}\n\nlet lastOperationPromise: Promise<any> = Promise.resolve()\n\nfunction updateDataStore(action: ActionsUnion): void {\n switch (action.type) {\n case `DELETE_CACHE`: {\n const dbs = getDatabases()\n // Force sync commit\n dbs.nodes.transactionSync(() => {\n dbs.nodes.clearSync()\n dbs.nodesByType.clearSync()\n dbs.metadata.clearSync()\n dbs.indexes.clearSync()\n })\n break\n }\n case `SET_PROGRAM`: {\n // TODO: remove this when we have support for incremental indexes in lmdb\n clearIndexes()\n break\n }\n case `CREATE_NODE`:\n case `DELETE_NODE`:\n case `ADD_FIELD_TO_NODE`:\n case `ADD_CHILD_NODE_TO_PARENT_NODE`:\n case `MATERIALIZE_PAGE_MODE`: {\n const dbs = getDatabases()\n const operationPromise = Promise.all([\n updateNodes(dbs.nodes, action),\n updateNodesByType(dbs.nodesByType, action),\n ])\n lastOperationPromise = operationPromise\n\n // if create is used in the same transaction as delete we should remove it from cache\n if (action.type === `CREATE_NODE`) {\n preSyncDeletedNodeIdsCache.delete(action.payload.id)\n }\n\n if (action.type === `DELETE_NODE` && action.payload?.id) {\n preSyncDeletedNodeIdsCache.add(action.payload.id)\n operationPromise.then(() => {\n // only clear if no other operations have been done in the meantime\n if (lastOperationPromise === operationPromise) {\n preSyncDeletedNodeIdsCache.clear()\n }\n })\n }\n }\n }\n}\n\nfunction clearIndexes(): void {\n const dbs = getDatabases()\n dbs.nodes.transactionSync(() => {\n dbs.metadata.clearSync()\n dbs.indexes.clearSync()\n })\n}\n\n/**\n * Resolves when all the data is synced\n */\nasync function ready(): Promise<void> {\n await lastOperationPromise\n}\n\nexport function setupLmdbStore({\n dbPath = getDefaultDbPath(),\n}: { dbPath?: string } = {}): IDataStore {\n fullDbPath = dbPath\n\n replaceReducer({\n nodes: (state = new Map(), action) =>\n action.type === `DELETE_CACHE` ? new Map() : state,\n nodesByType: (state = new Map(), action) =>\n action.type === `DELETE_CACHE` ? new Map() : state,\n })\n emitter.on(`*`, action => {\n if (action) {\n updateDataStore(action)\n }\n })\n // TODO: remove this when we have support for incremental indexes in lmdb\n clearIndexes()\n return lmdbDatastore\n}\n"],"mappings":";;;;;AAAA;;AAGA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAKA,MAAMA,aAAa,GAAG;EACpBC,OADoB;EAEpBC,QAFoB;EAGpBC,UAHoB;EAIpBC,YAJoB;EAKpBC,kBALoB;EAMpBC,eANoB;EAOpBC,KAPoB;EAQpBC,QARoB;EAUpB;EACAC,QAXoB;EAYpBC;AAZoB,CAAtB;AAeA,MAAMC,0BAA0B,GAAG,IAAIC,GAAJ,EAAnC;;AAEA,SAASC,gBAAT,GAAoC;EAAA;;EAClC,MAAMC,UAAU,GACdC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAA0B,MAA1B,GACK,kBACC;EACA;EACA;EAHF,yBAIEF,OAAO,CAACC,GAAR,CAAYE,sBAJd,yEAIwCH,OAAO,CAACC,GAAR,CAAYG,cACnD,EANL,GAOK,WARP;EAUA,OAAOJ,OAAO,CAACK,GAAR,KAAiB,eAAjB,GAAkCN,UAAzC;AACD;;AAED,IAAIO,UAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,SAAJ;AAEA;;AAWA,SAASC,SAAT,GAAmC;EACjC,IAAI,CAACF,MAAL,EAAa;IACX,IAAI,CAACD,UAAL,EAAiB;MACf,MAAM,IAAII,KAAJ,CAAW,uBAAX,CAAN;IACD;;IAED,IAAI,CAACC,UAAU,CAACC,wBAAhB,EAA0C;MACxCD,UAAU,CAACC,wBAAX,GAAsC,IAAIC,GAAJ,EAAtC;IACD;;IACDN,MAAM,GAAGI,UAAU,CAACC,wBAAX,CAAoCE,GAApC,CAAwCR,UAAxC,CAAT;;IACA,IAAIC,MAAJ,EAAY;MACV,OAAOA,MAAP;IACD;;IAEDA,MAAM,GAAG,IAAAQ,UAAA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;AAED;AACA;AACA;;;AACA,eAAe5E,KAAf,GAAsC;EACpC,MAAMwE,oBAAN;AACD;;AAEM,SAASe,cAAT,CAAwB;EAC7BC,MAAM,GAAGlF,gBAAgB;AADI,IAEN,EAFlB,EAEkC;EACvCQ,UAAU,GAAG0E,MAAb;EAEA,IAAAC,qBAAA,EAAe;IACb3D,KAAK,EAAE,CAAC4D,KAAK,GAAG,IAAIrE,GAAJ,EAAT,EAAoBoD,MAApB,KACLA,MAAM,CAAC/B,IAAP,KAAiB,cAAjB,GAAiC,IAAIrB,GAAJ,EAAjC,GAA6CqE,KAFlC;IAGbxD,WAAW,EAAE,CAACwD,KAAK,GAAG,IAAIrE,GAAJ,EAAT,EAAoBoD,MAApB,KACXA,MAAM,CAAC/B,IAAP,KAAiB,cAAjB,GAAiC,IAAIrB,GAAJ,EAAjC,GAA6CqE;EAJlC,CAAf;;EAMAC,cAAA,CAAQC,EAAR,CAAY,GAAZ,EAAgBnB,MAAM,IAAI;IACxB,IAAIA,MAAJ,EAAY;MACV1E,eAAe,CAAC0E,MAAD,CAAf;IACD;EACF,CAJD,EATuC,CAcvC;;;EACAI,YAAY;EACZ,OAAOpF,aAAP;AACD"}
|
|
1
|
+
{"version":3,"file":"lmdb-datastore.js","names":["lmdbDatastore","getNode","getTypes","countNodes","iterateNodes","iterateNodesByType","updateDataStore","ready","runQuery","getNodes","getNodesByType","preSyncDeletedNodeIdsCache","Set","getDefaultDbPath","dbFileName","process","env","NODE_ENV","FORCE_TEST_DATABASE_ID","JEST_WORKER_ID","cwd","fullDbPath","rootDb","databases","getRootDb","Error","globalThis","__GATSBY_OPEN_ROOT_LMDBS","Map","get","open","name","path","compression","set","getDatabases","__GATSBY_OPEN_LMDBS","nodes","openDB","cache","expirer","nodesByType","dupSort","metadata","useVersions","indexes","result","Array","from","type","nodesDb","GatsbyIterable","getKeys","snapshot","map","nodeId","undefined","filter","Boolean","getValues","id","has","asArray","typeName","stats","getStats","Math","max","Number","entryCount","size","getValuesCount","args","GATSBY_EXPERIMENTAL_LMDB_INDEXES","doRunQuery","datastore","Promise","resolve","runFastFiltersAndSort","lastOperationPromise","action","dbs","transactionSync","clearSync","clearIndexes","operationPromise","all","updateNodes","updateNodesByType","delete","payload","add","then","clear","setupLmdbStore","dbPath","replaceReducer","state","emitter","on"],"sources":["../../../src/datastore/lmdb/lmdb-datastore.ts"],"sourcesContent":["import { RootDatabase, open, ArrayLikeIterable } from \"lmdb\"\n// import { performance } from \"perf_hooks\"\nimport { ActionsUnion, IGatsbyNode } from \"../../redux/types\"\nimport { updateNodes } from \"./updates/nodes\"\nimport { updateNodesByType } from \"./updates/nodes-by-type\"\nimport { IDataStore, ILmdbDatabases, IQueryResult } from \"../types\"\nimport { emitter, replaceReducer } from \"../../redux\"\nimport { GatsbyIterable } from \"../common/iterable\"\nimport { doRunQuery } from \"./query/run-query\"\nimport {\n IRunFilterArg,\n runFastFiltersAndSort,\n} from \"../in-memory/run-fast-filters\"\n\nconst lmdbDatastore = {\n getNode,\n getTypes,\n countNodes,\n iterateNodes,\n iterateNodesByType,\n updateDataStore,\n ready,\n runQuery,\n\n // deprecated:\n getNodes,\n getNodesByType,\n}\n\nconst preSyncDeletedNodeIdsCache = new Set()\n\nfunction getDefaultDbPath(): string {\n const dbFileName =\n process.env.NODE_ENV === `test`\n ? `test-datastore-${\n // FORCE_TEST_DATABASE_ID will be set if this gets executed in worker context\n // when running jest tests. JEST_WORKER_ID will be set when this gets executed directly\n // in test context (jest will use jest-worker internally).\n process.env.FORCE_TEST_DATABASE_ID ?? process.env.JEST_WORKER_ID\n }`\n : `datastore`\n\n return process.cwd() + `/.cache/data/` + dbFileName\n}\n\nlet fullDbPath\nlet rootDb\nlet databases\n\n/* eslint-disable @typescript-eslint/no-namespace */\ndeclare global {\n namespace NodeJS {\n // eslint-disable-next-line @typescript-eslint/naming-convention\n interface Global {\n __GATSBY_OPEN_LMDBS?: Map<string, ILmdbDatabases>\n __GATSBY_OPEN_ROOT_LMDBS?: Map<string, RootDatabase>\n }\n }\n}\n\nfunction getRootDb(): RootDatabase {\n if (!rootDb) {\n if (!fullDbPath) {\n throw new Error(`LMDB path is not set!`)\n }\n\n if (!globalThis.__GATSBY_OPEN_ROOT_LMDBS) {\n globalThis.__GATSBY_OPEN_ROOT_LMDBS = new Map()\n }\n rootDb = globalThis.__GATSBY_OPEN_ROOT_LMDBS.get(fullDbPath)\n if (rootDb) {\n return rootDb\n }\n\n rootDb = open({\n name: `root`,\n path: fullDbPath,\n compression: true,\n })\n\n globalThis.__GATSBY_OPEN_ROOT_LMDBS.set(fullDbPath, rootDb)\n }\n return rootDb\n}\n\nfunction getDatabases(): ILmdbDatabases {\n if (!databases) {\n // __GATSBY_OPEN_LMDBS tracks if we already opened given db in this process\n // In `gatsby serve` case we might try to open it twice - once for engines\n // and second to get access to `SitePage` nodes (to power trailing slashes\n // redirect middleware). This ensure there is single instance within a process.\n // Using more instances seems to cause weird random errors.\n if (!globalThis.__GATSBY_OPEN_LMDBS) {\n globalThis.__GATSBY_OPEN_LMDBS = new Map()\n }\n databases = globalThis.__GATSBY_OPEN_LMDBS.get(fullDbPath)\n if (databases) {\n return databases\n }\n\n const rootDb = getRootDb()\n databases = {\n nodes: rootDb.openDB({\n name: `nodes`,\n // FIXME: sharedStructuresKey breaks tests - probably need some cleanup for it on DELETE_CACHE\n // sharedStructuresKey: Symbol.for(`structures`),\n // @ts-ignore\n cache: {\n // expirer: false disables LRU part and only take care of WeakRefs\n // this way we don't retain nodes strongly, but will continue to\n // reuse them if they are loaded already\n expirer: false,\n },\n }),\n nodesByType: rootDb.openDB({\n name: `nodesByType`,\n dupSort: true,\n }),\n metadata: rootDb.openDB({\n name: `metadata`,\n useVersions: true,\n }),\n indexes: rootDb.openDB({\n name: `indexes`,\n // TODO: use dupSort when this is ready: https://github.com/DoctorEvidence/lmdb-store/issues/66\n // dupSort: true\n }),\n }\n globalThis.__GATSBY_OPEN_LMDBS.set(fullDbPath, databases)\n }\n return databases\n}\n\n/**\n * @deprecated\n */\nfunction getNodes(): Array<IGatsbyNode> {\n // const start = performance.now()\n const result = Array.from<IGatsbyNode>(iterateNodes())\n // const timeTotal = performance.now() - start\n // console.warn(\n // `getNodes() is deprecated, use iterateNodes() instead; ` +\n // `array length: ${result.length}; time(ms): ${timeTotal}`\n // )\n return result ?? []\n}\n\n/**\n * @deprecated\n */\nfunction getNodesByType(type: string): Array<IGatsbyNode> {\n // const start = performance.now()\n const result = Array.from<IGatsbyNode>(iterateNodesByType(type))\n // const timeTotal = performance.now() - start\n // console.warn(\n // `getNodesByType() is deprecated, use iterateNodesByType() instead; ` +\n // `array length: ${result.length}; time(ms): ${timeTotal}`\n // )\n return result ?? []\n}\n\nfunction iterateNodes(): GatsbyIterable<IGatsbyNode> {\n // Additionally fetching items by id to leverage lmdb-store cache\n const nodesDb = getDatabases().nodes\n return new GatsbyIterable(\n nodesDb\n .getKeys({ snapshot: false })\n .map(nodeId => (typeof nodeId === `string` ? getNode(nodeId) : undefined))\n .filter(Boolean) as ArrayLikeIterable<IGatsbyNode>\n )\n}\n\nfunction iterateNodesByType(type: string): GatsbyIterable<IGatsbyNode> {\n const nodesByType = getDatabases().nodesByType\n return new GatsbyIterable(\n nodesByType\n .getValues(type)\n .map(nodeId => getNode(nodeId))\n .filter(Boolean) as ArrayLikeIterable<IGatsbyNode>\n )\n}\n\nfunction getNode(id: string): IGatsbyNode | undefined {\n if (!id || preSyncDeletedNodeIdsCache.has(id)) {\n return undefined\n }\n\n const { nodes } = getDatabases()\n return nodes.get(id)\n}\n\nfunction getTypes(): Array<string> {\n return getDatabases().nodesByType.getKeys({}).asArray\n}\n\nfunction countNodes(typeName?: string): number {\n if (!typeName) {\n const stats = getDatabases().nodes.getStats() as { entryCount: number }\n return Math.max(\n Number(stats.entryCount) - preSyncDeletedNodeIdsCache.size,\n 0\n ) // FIXME: add -1 when restoring shared structures key\n }\n\n const { nodesByType } = getDatabases()\n return nodesByType.getValuesCount(typeName)\n}\n\nasync function runQuery(args: IRunFilterArg): Promise<IQueryResult> {\n if (process.env.GATSBY_EXPERIMENTAL_LMDB_INDEXES) {\n return await doRunQuery({\n datastore: lmdbDatastore,\n databases: getDatabases(),\n ...args,\n })\n }\n return Promise.resolve(runFastFiltersAndSort(args))\n}\n\nlet lastOperationPromise: Promise<any> = Promise.resolve()\n\nfunction updateDataStore(action: ActionsUnion): void {\n switch (action.type) {\n case `DELETE_CACHE`: {\n const dbs = getDatabases()\n // Force sync commit\n dbs.nodes.transactionSync(() => {\n dbs.nodes.clearSync()\n dbs.nodesByType.clearSync()\n dbs.metadata.clearSync()\n dbs.indexes.clearSync()\n })\n break\n }\n case `SET_PROGRAM`: {\n // TODO: remove this when we have support for incremental indexes in lmdb\n clearIndexes()\n break\n }\n case `CREATE_NODE`:\n case `DELETE_NODE`:\n case `ADD_FIELD_TO_NODE`:\n case `ADD_CHILD_NODE_TO_PARENT_NODE`:\n case `MATERIALIZE_PAGE_MODE`: {\n const dbs = getDatabases()\n const operationPromise = Promise.all([\n updateNodes(dbs.nodes, action),\n updateNodesByType(dbs.nodesByType, action),\n ])\n lastOperationPromise = operationPromise\n\n // if create is used in the same transaction as delete we should remove it from cache\n if (action.type === `CREATE_NODE`) {\n preSyncDeletedNodeIdsCache.delete(action.payload.id)\n }\n\n if (action.type === `DELETE_NODE` && action.payload?.id) {\n preSyncDeletedNodeIdsCache.add(action.payload.id)\n operationPromise.then(() => {\n // only clear if no other operations have been done in the meantime\n if (lastOperationPromise === operationPromise) {\n preSyncDeletedNodeIdsCache.clear()\n }\n })\n }\n }\n }\n}\n\nfunction clearIndexes(): void {\n const dbs = getDatabases()\n dbs.nodes.transactionSync(() => {\n dbs.metadata.clearSync()\n dbs.indexes.clearSync()\n })\n}\n\n/**\n * Resolves when all the data is synced\n */\nasync function ready(): Promise<void> {\n await lastOperationPromise\n}\n\nexport function setupLmdbStore({\n dbPath = getDefaultDbPath(),\n}: { dbPath?: string } = {}): IDataStore {\n fullDbPath = dbPath\n\n replaceReducer({\n nodes: (state = new Map(), action) =>\n action.type === `DELETE_CACHE` ? new Map() : state,\n nodesByType: (state = new Map(), action) =>\n action.type === `DELETE_CACHE` ? new Map() : state,\n })\n emitter.on(`*`, action => {\n if (action) {\n updateDataStore(action)\n }\n })\n // TODO: remove this when we have support for incremental indexes in lmdb\n clearIndexes()\n return lmdbDatastore\n}\n"],"mappings":";;;;;AAAA;;AAGA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AAKA,MAAMA,aAAa,GAAG;EACpBC,OADoB;EAEpBC,QAFoB;EAGpBC,UAHoB;EAIpBC,YAJoB;EAKpBC,kBALoB;EAMpBC,eANoB;EAOpBC,KAPoB;EAQpBC,QARoB;EAUpB;EACAC,QAXoB;EAYpBC;AAZoB,CAAtB;AAeA,MAAMC,0BAA0B,GAAG,IAAIC,GAAJ,EAAnC;;AAEA,SAASC,gBAAT,GAAoC;EAAA;;EAClC,MAAMC,UAAU,GACdC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAA0B,MAA1B,GACK,kBACC;EACA;EACA;EAHF,yBAIEF,OAAO,CAACC,GAAR,CAAYE,sBAJd,yEAIwCH,OAAO,CAACC,GAAR,CAAYG,cACnD,EANL,GAOK,WARP;EAUA,OAAOJ,OAAO,CAACK,GAAR,KAAiB,eAAjB,GAAkCN,UAAzC;AACD;;AAED,IAAIO,UAAJ;AACA,IAAIC,MAAJ;AACA,IAAIC,SAAJ;AAEA;;AAWA,SAASC,SAAT,GAAmC;EACjC,IAAI,CAACF,MAAL,EAAa;IACX,IAAI,CAACD,UAAL,EAAiB;MACf,MAAM,IAAII,KAAJ,CAAW,uBAAX,CAAN;IACD;;IAED,IAAI,CAACC,UAAU,CAACC,wBAAhB,EAA0C;MACxCD,UAAU,CAACC,wBAAX,GAAsC,IAAIC,GAAJ,EAAtC;IACD;;IACDN,MAAM,GAAGI,UAAU,CAACC,wBAAX,CAAoCE,GAApC,CAAwCR,UAAxC,CAAT;;IACA,IAAIC,MAAJ,EAAY;MACV,O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GAAG,CAACpC,OAAJ,CAAYsC,SAAZ;EACD,CAHD;AAID;AAED;AACA;AACA;;;AACA,eAAe5E,KAAf,GAAsC;EACpC,MAAMwE,oBAAN;AACD;;AAEM,SAASe,cAAT,CAAwB;EAC7BC,MAAM,GAAGlF,gBAAgB;AADI,IAEN,EAFlB,EAEkC;EACvCQ,UAAU,GAAG0E,MAAb;EAEA,IAAAC,qBAAA,EAAe;IACb3D,KAAK,EAAE,CAAC4D,KAAK,GAAG,IAAIrE,GAAJ,EAAT,EAAoBoD,MAApB,KACLA,MAAM,CAAC/B,IAAP,KAAiB,cAAjB,GAAiC,IAAIrB,GAAJ,EAAjC,GAA6CqE,KAFlC;IAGbxD,WAAW,EAAE,CAACwD,KAAK,GAAG,IAAIrE,GAAJ,EAAT,EAAoBoD,MAApB,KACXA,MAAM,CAAC/B,IAAP,KAAiB,cAAjB,GAAiC,IAAIrB,GAAJ,EAAjC,GAA6CqE;EAJlC,CAAf;;EAMAC,cAAA,CAAQC,EAAR,CAAY,GAAZ,EAAgBnB,MAAM,IAAI;IACxB,IAAIA,MAAJ,EAAY;MACV1E,eAAe,CAAC0E,MAAD,CAAf;IACD;EACF,CAJD,EATuC,CAcvC;;;EACAI,YAAY;EACZ,OAAOpF,aAAP;AACD"}
|
package/dist/utils/cache-lmdb.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cache-lmdb.js","names":["cacheDbFile","process","env","NODE_ENV","FORCE_TEST_DATABASE_ID","JEST_WORKER_ID","dbPath","path","join","cwd","getAlreadyOpenedStore","globalThis","__GATSBY_OPEN_ROOT_LMDBS","Map","get","GatsbyCacheLmdb","constructor","name","encoding","directory","cache","init","fs","ensureDirSync","getStore","rootDb","open","compression","maxDbs","set","getDb","db","openDB","
|
|
1
|
+
{"version":3,"file":"cache-lmdb.js","names":["cacheDbFile","process","env","NODE_ENV","FORCE_TEST_DATABASE_ID","JEST_WORKER_ID","dbPath","path","join","cwd","getAlreadyOpenedStore","globalThis","__GATSBY_OPEN_ROOT_LMDBS","Map","get","GatsbyCacheLmdb","constructor","name","encoding","directory","cache","init","fs","ensureDirSync","getStore","rootDb","open","compression","maxDbs","set","getDb","db","openDB","key","value","put","del","remove","resetCache","store","close","delete","emptyDir"],"sources":["../../src/utils/cache-lmdb.ts"],"sourcesContent":["import { open, RootDatabase, Database, DatabaseOptions } from \"lmdb\"\nimport * as fs from \"fs-extra\"\nimport * as path from \"path\"\n\n// Since the regular GatsbyCache saves to \"caches\" this should be \"caches-lmdb\"\nconst cacheDbFile =\n process.env.NODE_ENV === `test`\n ? `caches-lmdb-${\n // FORCE_TEST_DATABASE_ID will be set if this gets executed in worker context\n // when running jest tests. JEST_WORKER_ID will be set when this gets executed directly\n // in test context (jest will use jest-worker internally).\n process.env.FORCE_TEST_DATABASE_ID ?? process.env.JEST_WORKER_ID\n }`\n : `caches-lmdb`\n\nconst dbPath = path.join(process.cwd(), `.cache/${cacheDbFile}`)\n\nfunction getAlreadyOpenedStore(): RootDatabase | undefined {\n if (!globalThis.__GATSBY_OPEN_ROOT_LMDBS) {\n globalThis.__GATSBY_OPEN_ROOT_LMDBS = new Map()\n }\n return globalThis.__GATSBY_OPEN_ROOT_LMDBS.get(dbPath)\n}\n\nexport default class GatsbyCacheLmdb {\n private db: Database | undefined\n private encoding: DatabaseOptions[\"encoding\"]\n public readonly name: string\n // Needed for plugins that want to write data to the cache directory\n public readonly directory: string\n // TODO: remove `.cache` in v4. This is compat mode - cache-manager cache implementation\n // expose internal cache that gives access to `.del` function that wasn't available in public\n // cache interface (gatsby-plugin-sharp use it to clear no longer needed data)\n public readonly cache: GatsbyCacheLmdb\n\n constructor({\n name = `db`,\n encoding = `json`,\n }: {\n name: string\n encoding?: DatabaseOptions[\"encoding\"]\n }) {\n this.name = name\n this.encoding = encoding\n this.directory = path.join(process.cwd(), `.cache/caches/${name}`)\n this.cache = this\n }\n\n init(): GatsbyCacheLmdb {\n fs.ensureDirSync(this.directory)\n return this\n }\n\n private static getStore(): RootDatabase {\n let rootDb = getAlreadyOpenedStore()\n if (rootDb) {\n return rootDb\n }\n\n rootDb = open({\n name: `root`,\n path: dbPath,\n compression: true,\n maxDbs: 200,\n })\n\n globalThis.__GATSBY_OPEN_ROOT_LMDBS.set(dbPath, rootDb)\n\n return rootDb\n }\n\n private getDb(): Database {\n if (!this.db) {\n this.db = GatsbyCacheLmdb.getStore().openDB({\n name: this.name,\n encoding: this.encoding,\n })\n }\n return this.db\n }\n\n async get<T = unknown>(key): Promise<T | undefined> {\n return this.getDb().get(key)\n }\n\n async set<T>(key: string, value: T): Promise<T | undefined> {\n await this.getDb().put(key, value)\n return value\n }\n\n async del(key: string): Promise<void> {\n return this.getDb().remove(key) as unknown as Promise<void>\n }\n}\n\nexport async function resetCache(): Promise<void> {\n const store = getAlreadyOpenedStore()\n if (store) {\n await store.close()\n globalThis.__GATSBY_OPEN_ROOT_LMDBS.delete(dbPath)\n }\n\n await fs.emptyDir(dbPath)\n}\n"],"mappings":";;;;;;AAAA;;AACA;;AACA;;;;;;;;AAEA;AACA,MAAMA,WAAW,GACfC,OAAO,CAACC,GAAR,CAAYC,QAAZ,KAA0B,MAA1B,GACK,eACC;AACA;AACA;AAHF,yBAIEF,OAAO,CAACC,GAAR,CAAYE,sBAJd,yEAIwCH,OAAO,CAACC,GAAR,CAAYG,cACnD,EANL,GAOK,aARP;AAUA,MAAMC,MAAM,GAAGC,IAAI,CAACC,IAAL,CAAUP,OAAO,CAACQ,GAAR,EAAV,EAA0B,UAAST,WAAY,EAA/C,CAAf;;AAEA,SAASU,qBAAT,GAA2D;EACzD,IAAI,CAACC,UAAU,CAACC,wBAAhB,EAA0C;IACxCD,UAAU,CAACC,wBAAX,GAAsC,IAAIC,GAAJ,EAAtC;EACD;;EACD,OAAOF,UAAU,CAACC,wBAAX,CAAoCE,GAApC,CAAwCR,MAAxC,CAAP;AACD;;AAEc,MAAMS,eAAN,CAAsB;EAInC;EAEA;EACA;EACA;EAGAC,WAAW,CA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C,KAAtB,CAAN;IACA,OAAOA,KAAP;EACD;;EAEQ,MAAHE,GAAG,CAACH,GAAD,EAA6B;IACpC,OAAO,KAAKH,KAAL,GAAaO,MAAb,CAAoBJ,GAApB,CAAP;EACD;;AApEkC;;;;AAuE9B,eAAeK,UAAf,GAA2C;EAChD,MAAMC,KAAK,GAAG7B,qBAAqB,EAAnC;;EACA,IAAI6B,KAAJ,EAAW;IACT,MAAMA,KAAK,CAACC,KAAN,EAAN;;IACA7B,UAAU,CAACC,wBAAX,CAAoC6B,MAApC,CAA2CnC,MAA3C;EACD;;EAED,MAAMgB,EAAE,CAACoB,QAAH,CAAYpC,MAAZ,CAAN;AACD"}
|
|
@@ -32,7 +32,7 @@ async function importGatsbyPlugin(plugin, module) {
|
|
|
32
32
|
rootDir: process.cwd(),
|
|
33
33
|
filePath: importPluginModulePath
|
|
34
34
|
});
|
|
35
|
-
const rawPluginModule = await import(pluginFilePath); // If the module is cjs, the properties we care about are nested under a top-level `default` property
|
|
35
|
+
const rawPluginModule = await import((0, _resolveJsFilePath.maybeAddFileProtocol)(pluginFilePath)); // If the module is cjs, the properties we care about are nested under a top-level `default` property
|
|
36
36
|
|
|
37
37
|
pluginModule = (0, _preferDefault.preferDefault)(rawPluginModule);
|
|
38
38
|
pluginModuleCache.set(key, pluginModule);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"import-gatsby-plugin.js","names":["pluginModuleCache","Map","setGatsbyPluginCache","plugin","module","moduleObject","key","name","set","importGatsbyPlugin","pluginModule","get","importPluginModulePath","resolvedCompiledGatsbyNode","resolve","pluginFilePath","resolveJSFilepath","rootDir","process","cwd","filePath","rawPluginModule","preferDefault"],"sources":["../../src/utils/import-gatsby-plugin.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"import-gatsby-plugin.js","names":["pluginModuleCache","Map","setGatsbyPluginCache","plugin","module","moduleObject","key","name","set","importGatsbyPlugin","pluginModule","get","importPluginModulePath","resolvedCompiledGatsbyNode","resolve","pluginFilePath","resolveJSFilepath","rootDir","process","cwd","filePath","rawPluginModule","maybeAddFileProtocol","preferDefault"],"sources":["../../src/utils/import-gatsby-plugin.ts"],"sourcesContent":["import {\n resolveJSFilepath,\n maybeAddFileProtocol,\n} from \"../bootstrap/resolve-js-file-path\"\nimport { preferDefault } from \"../bootstrap/prefer-default\"\n\nconst pluginModuleCache = new Map<string, any>()\n\nexport function setGatsbyPluginCache(\n plugin: { name: string; resolve: string },\n module: string,\n moduleObject: any\n): void {\n const key = `${plugin.name}/${module}`\n pluginModuleCache.set(key, moduleObject)\n}\n\nexport async function importGatsbyPlugin(\n plugin: {\n name: string\n resolve: string\n resolvedCompiledGatsbyNode?: string\n },\n module: string\n): Promise<any> {\n const key = `${plugin.name}/${module}`\n\n let pluginModule = pluginModuleCache.get(key)\n\n if (!pluginModule) {\n let importPluginModulePath: string\n\n if (module === `gatsby-node` && plugin.resolvedCompiledGatsbyNode) {\n importPluginModulePath = plugin.resolvedCompiledGatsbyNode\n } else {\n importPluginModulePath = `${plugin.resolve}/${module}`\n }\n\n const pluginFilePath = await resolveJSFilepath({\n rootDir: process.cwd(),\n filePath: importPluginModulePath,\n })\n\n const rawPluginModule = await import(maybeAddFileProtocol(pluginFilePath))\n\n // If the module is cjs, the properties we care about are nested under a top-level `default` property\n pluginModule = preferDefault(rawPluginModule)\n\n pluginModuleCache.set(key, pluginModule)\n }\n\n return pluginModule\n}\n"],"mappings":";;;;;;AAAA;;AAIA;;AAEA,MAAMA,iBAAiB,GAAG,IAAIC,GAAJ,EAA1B;;AAEO,SAASC,oBAAT,CACLC,MADK,EAELC,MAFK,EAGLC,YAHK,EAIC;EACN,MAAMC,GAAG,GAAI,GAAEH,MAAM,CAACI,IAAK,IAAGH,MAAO,EAArC;EACAJ,iBAAiB,CAACQ,GAAlB,CAAsBF,GAAtB,EAA2BD,YAA3B;AACD;;AAEM,eAAeI,kBAAf,CACLN,MADK,EAMLC,MANK,EAOS;EACd,MAAME,GAAG,GAAI,GAAEH,MAAM,CAACI,IAAK,IAAGH,MAAO,EAArC;EAEA,IAAIM,YAAY,GAAGV,iBAAiB,CAACW,GAAlB,CAAsBL,GAAtB,CAAnB;;EAEA,IAAI,CAACI,YAAL,EAAmB;IACjB,IAAIE,sBAAJ;;IAEA,IAAIR,MAAM,KAAM,aAAZ,IAA4BD,MAAM,CAACU,0BAAvC,EAAmE;MACjED,sBAAsB,GAAGT,MAAM,CAACU,0BAAhC;IACD,CAFD,MAEO;MACLD,sBAAsB,GAAI,GAAET,MAAM,CAACW,OAAQ,IAAGV,MAAO,EAArD;IACD;;IAED,MAAMW,cAAc,GAAG,MAAM,IAAAC,oCAAA,EAAkB;MAC7CC,OAAO,EAAEC,OAAO,CAACC,GAAR,EADoC;MAE7CC,QAAQ,EAAER;IAFmC,CAAlB,CAA7B;IAKA,MAAMS,eAAe,GAAG,MAAM,OAAO,IAAAC,uCAAA,EAAqBP,cAArB,CAAP,CAA9B,CAdiB,CAgBjB;;IACAL,YAAY,GAAG,IAAAa,4BAAA,EAAcF,eAAd,CAAf;IAEArB,iBAAiB,CAACQ,GAAlB,CAAsBF,GAAtB,EAA2BI,YAA3B;EACD;;EAED,OAAOA,YAAP;AACD"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "gatsby",
|
|
3
3
|
"description": "Blazing fast modern site generator for React",
|
|
4
|
-
"version": "5.3.
|
|
4
|
+
"version": "5.3.2",
|
|
5
5
|
"author": "Kyle Mathews <mathews.kyle@gmail.com>",
|
|
6
6
|
"bin": {
|
|
7
7
|
"gatsby": "./cli.js"
|
|
@@ -48,8 +48,8 @@
|
|
|
48
48
|
"babel-plugin-add-module-exports": "^1.0.4",
|
|
49
49
|
"babel-plugin-dynamic-import-node": "^2.3.3",
|
|
50
50
|
"babel-plugin-lodash": "^3.3.4",
|
|
51
|
-
"babel-plugin-remove-graphql-queries": "^5.3.
|
|
52
|
-
"babel-preset-gatsby": "^3.3.
|
|
51
|
+
"babel-plugin-remove-graphql-queries": "^5.3.1",
|
|
52
|
+
"babel-preset-gatsby": "^3.3.1",
|
|
53
53
|
"better-opn": "^2.1.1",
|
|
54
54
|
"bluebird": "^3.7.2",
|
|
55
55
|
"browserslist": "^4.17.5",
|
|
@@ -90,19 +90,19 @@
|
|
|
90
90
|
"find-cache-dir": "^3.3.2",
|
|
91
91
|
"fs-exists-cached": "1.0.0",
|
|
92
92
|
"fs-extra": "^10.1.0",
|
|
93
|
-
"gatsby-cli": "^5.3.
|
|
94
|
-
"gatsby-core-utils": "^4.3.
|
|
93
|
+
"gatsby-cli": "^5.3.1",
|
|
94
|
+
"gatsby-core-utils": "^4.3.1",
|
|
95
95
|
"gatsby-graphiql-explorer": "^3.3.0",
|
|
96
96
|
"gatsby-legacy-polyfills": "^3.3.0",
|
|
97
|
-
"gatsby-link": "^5.3.
|
|
98
|
-
"gatsby-page-utils": "^3.3.
|
|
99
|
-
"gatsby-parcel-config": "
|
|
100
|
-
"gatsby-plugin-page-creator": "^5.3.
|
|
101
|
-
"gatsby-plugin-typescript": "^5.3.
|
|
102
|
-
"gatsby-plugin-utils": "^4.3.
|
|
97
|
+
"gatsby-link": "^5.3.1",
|
|
98
|
+
"gatsby-page-utils": "^3.3.1",
|
|
99
|
+
"gatsby-parcel-config": "1.3.1",
|
|
100
|
+
"gatsby-plugin-page-creator": "^5.3.1",
|
|
101
|
+
"gatsby-plugin-typescript": "^5.3.1",
|
|
102
|
+
"gatsby-plugin-utils": "^4.3.1",
|
|
103
103
|
"gatsby-react-router-scroll": "^6.3.0",
|
|
104
104
|
"gatsby-script": "^2.3.0",
|
|
105
|
-
"gatsby-telemetry": "^4.3.
|
|
105
|
+
"gatsby-telemetry": "^4.3.1",
|
|
106
106
|
"gatsby-worker": "^2.3.0",
|
|
107
107
|
"glob": "^7.2.3",
|
|
108
108
|
"globby": "^11.1.0",
|
|
@@ -118,7 +118,7 @@
|
|
|
118
118
|
"joi": "^17.4.2",
|
|
119
119
|
"json-loader": "^0.5.7",
|
|
120
120
|
"latest-version": "^7.0.0",
|
|
121
|
-
"lmdb": "2.
|
|
121
|
+
"lmdb": "2.5.3",
|
|
122
122
|
"lodash": "^4.17.21",
|
|
123
123
|
"md5-file": "^5.0.0",
|
|
124
124
|
"meant": "^1.0.3",
|
|
@@ -277,5 +277,5 @@
|
|
|
277
277
|
"yargs": {
|
|
278
278
|
"boolean-negation": false
|
|
279
279
|
},
|
|
280
|
-
"gitHead": "
|
|
280
|
+
"gitHead": "98cbee12f2f8a303b11c338fa3f980cb6c5f5d6c"
|
|
281
281
|
}
|