gatsby 5.13.1 → 5.13.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/internal-plugins/bundle-optimisations/gatsby-node.js +1 -1
- package/dist/internal-plugins/bundle-optimisations/gatsby-node.js.map +1 -1
- package/dist/internal-plugins/functions/api-function-webpack-loader.js +4 -4
- package/dist/internal-plugins/functions/api-function-webpack-loader.js.map +1 -1
- package/dist/internal-plugins/functions/gatsby-node.js +6 -4
- package/dist/internal-plugins/functions/gatsby-node.js.map +1 -1
- package/dist/utils/adapter/init.d.ts +2 -1
- package/dist/utils/adapter/init.js +136 -74
- package/dist/utils/adapter/init.js.map +1 -1
- package/dist/utils/adapter/types.d.ts +4 -0
- package/dist/utils/adapter/types.js.map +1 -1
- package/dist/utils/get-latest-gatsby-files.js +32 -10
- package/dist/utils/get-latest-gatsby-files.js.map +1 -1
- package/dist/utils/parcel/compile-gatsby-files.d.ts +7 -0
- package/dist/utils/parcel/compile-gatsby-files.js +59 -25
- package/dist/utils/parcel/compile-gatsby-files.js.map +1 -1
- package/dist/utils/webpack/plugins/cache-folder-resolver.d.ts +17 -1
- package/dist/utils/webpack/plugins/cache-folder-resolver.js +73 -2
- package/dist/utils/webpack/plugins/cache-folder-resolver.js.map +1 -1
- package/dist/utils/webpack.config.js +4 -1
- package/dist/utils/webpack.config.js.map +1 -1
- package/package.json +18 -18
|
@@ -6,7 +6,7 @@ exports.onCreateBabelConfig = ({
|
|
|
6
6
|
}) => {
|
|
7
7
|
// rewrites import { get }from 'lodash' into import get from 'lodash/get';
|
|
8
8
|
actions.setBabelPlugin({
|
|
9
|
-
name:
|
|
9
|
+
name: `@sigmacomputing/babel-plugin-lodash`
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
12
|
exports.onCreateWebpackConfig = function onCreateWebpackConfig({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gatsby-node.js","names":["path","require","exports","onCreateBabelConfig","actions","setBabelPlugin","name","onCreateWebpackConfig","stage","objectAssignStub","join","__dirname","noOp","fetchStub","whatwgFetchStub","alias","unfetch$","setWebpackConfig","resolve"],"sources":["../../../src/internal-plugins/bundle-optimisations/gatsby-node.js"],"sourcesContent":["const path = require(`path`)\n\nexports.onCreateBabelConfig = ({ actions }) => {\n // rewrites import { get }from 'lodash' into import get from 'lodash/get';\n actions.setBabelPlugin({\n name:
|
|
1
|
+
{"version":3,"file":"gatsby-node.js","names":["path","require","exports","onCreateBabelConfig","actions","setBabelPlugin","name","onCreateWebpackConfig","stage","objectAssignStub","join","__dirname","noOp","fetchStub","whatwgFetchStub","alias","unfetch$","setWebpackConfig","resolve"],"sources":["../../../src/internal-plugins/bundle-optimisations/gatsby-node.js"],"sourcesContent":["const path = require(`path`)\n\nexports.onCreateBabelConfig = ({ actions }) => {\n // rewrites import { get }from 'lodash' into import get from 'lodash/get';\n actions.setBabelPlugin({\n name: `@sigmacomputing/babel-plugin-lodash`,\n })\n}\n\nexports.onCreateWebpackConfig = function onCreateWebpackConfig({\n stage,\n actions,\n}) {\n const objectAssignStub = path.join(__dirname, `polyfills/object-assign.js`)\n const noOp = path.join(__dirname, `polyfills/no-op.js`)\n const fetchStub = path.join(__dirname, `polyfills/fetch.js`)\n const whatwgFetchStub = path.join(__dirname, `polyfills/whatwg-fetch.js`)\n\n const alias = {\n // These files are already polyfilled so these should return in a no-op\n // Stub Package: object.assign & object-assign\n \"object.assign\": objectAssignStub,\n \"object-assign$\": objectAssignStub,\n \"@babel/runtime/helpers/extends.js$\": objectAssignStub,\n // Stub package: fetch\n unfetch$: fetchStub,\n \"unfetch/polyfill$\": noOp,\n \"isomorphic-unfetch$\": fetchStub,\n \"isomorphic-fetch$\": fetchStub,\n \"whatwg-fetch$\": whatwgFetchStub,\n }\n\n if (stage === `build-javascript` || stage === `develop`) {\n alias[`url-polyfill$`] = noOp\n }\n\n actions.setWebpackConfig({\n resolve: {\n alias,\n },\n })\n}\n"],"mappings":";;AAAA,MAAMA,IAAI,GAAGC,OAAO,CAAE,MAAK,CAAC;AAE5BC,OAAO,CAACC,mBAAmB,GAAG,CAAC;EAAEC;AAAQ,CAAC,KAAK;EAC7C;EACAA,OAAO,CAACC,cAAc,CAAC;IACrBC,IAAI,EAAG;EACT,CAAC,CAAC;AACJ,CAAC;AAEDJ,OAAO,CAACK,qBAAqB,GAAG,SAASA,qBAAqB,CAAC;EAC7DC,KAAK;EACLJ;AACF,CAAC,EAAE;EACD,MAAMK,gBAAgB,GAAGT,IAAI,CAACU,IAAI,CAACC,SAAS,EAAG,4BAA2B,CAAC;EAC3E,MAAMC,IAAI,GAAGZ,IAAI,CAACU,IAAI,CAACC,SAAS,EAAG,oBAAmB,CAAC;EACvD,MAAME,SAAS,GAAGb,IAAI,CAACU,IAAI,CAACC,SAAS,EAAG,oBAAmB,CAAC;EAC5D,MAAMG,eAAe,GAAGd,IAAI,CAACU,IAAI,CAACC,SAAS,EAAG,2BAA0B,CAAC;EAEzE,MAAMI,KAAK,GAAG;IACZ;IACA;IACA,eAAe,EAAEN,gBAAgB;IACjC,gBAAgB,EAAEA,gBAAgB;IAClC,oCAAoC,EAAEA,gBAAgB;IACtD;IACAO,QAAQ,EAAEH,SAAS;IACnB,mBAAmB,EAAED,IAAI;IACzB,qBAAqB,EAAEC,SAAS;IAChC,mBAAmB,EAAEA,SAAS;IAC9B,eAAe,EAAEC;EACnB,CAAC;EAED,IAAIN,KAAK,KAAM,kBAAiB,IAAIA,KAAK,KAAM,SAAQ,EAAE;IACvDO,KAAK,CAAE,eAAc,CAAC,GAAGH,IAAI;EAC/B;EAEAR,OAAO,CAACa,gBAAgB,CAAC;IACvBC,OAAO,EAAE;MACPH;IACF;EACF,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -13,10 +13,10 @@ const APIFunctionLoader = async function () {
|
|
|
13
13
|
const functionModule = require('${modulePath}');
|
|
14
14
|
const functionToExecute = preferDefault(functionModule);
|
|
15
15
|
const matchPath = '${matchPath}';
|
|
16
|
-
const { match: reachMatch } = require('
|
|
17
|
-
const { urlencoded, text, json, raw } = require('body-parser')
|
|
18
|
-
const multer = require('multer')
|
|
19
|
-
const { createConfig } = require('
|
|
16
|
+
const { match: reachMatch } = require('${require.resolve(`@gatsbyjs/reach-router`)}');
|
|
17
|
+
const { urlencoded, text, json, raw } = require('${require.resolve(`body-parser`)}')
|
|
18
|
+
const multer = require('${require.resolve(`multer`)}')
|
|
19
|
+
const { createConfig } = require('${require.resolve(`./config`)}')
|
|
20
20
|
|
|
21
21
|
function functionWrapper(req, res) {
|
|
22
22
|
if (matchPath) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-function-webpack-loader.js","names":["APIFunctionLoader","params","URLSearchParams","resourceQuery","matchPath","get","modulePath","slash","resourcePath"],"sources":["../../../src/internal-plugins/functions/api-function-webpack-loader.ts"],"sourcesContent":["import { slash } from \"gatsby-core-utils\"\nimport type { LoaderDefinition } from \"webpack\"\n\nconst APIFunctionLoader: LoaderDefinition = async function () {\n const params = new URLSearchParams(this.resourceQuery)\n const matchPath = params.get(`matchPath`)\n\n const modulePath = slash(this.resourcePath)\n\n return /* javascript */ `\n const preferDefault = m => (m && m.default) || m\n\n const functionModule = require('${modulePath}');\n const functionToExecute = preferDefault(functionModule);\n const matchPath = '${matchPath}';\n const { match: reachMatch } = require('
|
|
1
|
+
{"version":3,"file":"api-function-webpack-loader.js","names":["APIFunctionLoader","params","URLSearchParams","resourceQuery","matchPath","get","modulePath","slash","resourcePath","require","resolve"],"sources":["../../../src/internal-plugins/functions/api-function-webpack-loader.ts"],"sourcesContent":["import { slash } from \"gatsby-core-utils\"\nimport type { LoaderDefinition } from \"webpack\"\n\nconst APIFunctionLoader: LoaderDefinition = async function () {\n const params = new URLSearchParams(this.resourceQuery)\n const matchPath = params.get(`matchPath`)\n\n const modulePath = slash(this.resourcePath)\n\n return /* javascript */ `\n const preferDefault = m => (m && m.default) || m\n\n const functionModule = require('${modulePath}');\n const functionToExecute = preferDefault(functionModule);\n const matchPath = '${matchPath}';\n const { match: reachMatch } = require('${require.resolve(\n `@gatsbyjs/reach-router`\n )}');\n const { urlencoded, text, json, raw } = require('${require.resolve(\n `body-parser`\n )}')\n const multer = require('${require.resolve(`multer`)}')\n const { createConfig } = require('${require.resolve(`./config`)}')\n\n function functionWrapper(req, res) {\n if (matchPath) {\n let functionPath = req.originalUrl\n\n functionPath = functionPath.replace(new RegExp('^/*' + PREFIX_TO_STRIP), '')\n functionPath = functionPath.replace(new RegExp('^/*api/?'), '')\n\n const matchResult = reachMatch(matchPath, functionPath)\n if (matchResult) {\n req.params = matchResult.params\n if (req.params['*']) {\n // TODO(v6): Remove this backwards compatability for v3\n req.params['0'] = req.params['*']\n }\n }\n }\n\n // handle body parsing if request stream was not yet consumed\n const { config } = createConfig(functionModule?.config)\n const middlewares = \n req.readableEnded \n ? [] \n : [\n multer().any(),\n raw(config?.bodyParser?.raw ?? { limit: '100kb' }),\n text(config?.bodyParser?.text ?? { limit: '100kb' }),\n urlencoded(config?.bodyParser?.urlencoded ?? { limit: '100kb', extended: true }),\n json(config?.bodyParser?.json ?? { limit: '100kb' })\n ]\n\n let i = 0\n function runMiddlewareOrFunction() {\n if (i >= middlewares.length) {\n functionToExecute(req, res);\n } else {\n middlewares[i++](req, res, runMiddlewareOrFunction)\n }\n }\n\n\n runMiddlewareOrFunction() \n }\n\n module.exports = typeof functionToExecute === 'function' \n ? {\n default: functionWrapper,\n config: functionModule?.config\n } : functionModule\n `\n}\n\nexport default APIFunctionLoader\n"],"mappings":";;;;AAAA;AAGA,MAAMA,iBAAmC,GAAG,kBAAkB;EAC5D,MAAMC,MAAM,GAAG,IAAIC,eAAe,CAAC,IAAI,CAACC,aAAa,CAAC;EACtD,MAAMC,SAAS,GAAGH,MAAM,CAACI,GAAG,CAAE,WAAU,CAAC;EAEzC,MAAMC,UAAU,GAAG,IAAAC,sBAAK,EAAC,IAAI,CAACC,YAAY,CAAC;EAE3C,OAAO,iBAAkB;AAC3B;AACA;AACA,oCAAoCF,UAAW;AAC/C;AACA,uBAAuBF,SAAU;AACjC,2CAA2CK,OAAO,CAACC,OAAO,CACrD,wBAAuB,CACxB;AACJ,qDAAqDD,OAAO,CAACC,OAAO,CAC/D,aAAY,CACb;AACJ,4BAA4BD,OAAO,CAACC,OAAO,CAAE,QAAO,CAAE;AACtD,sCAAsCD,OAAO,CAACC,OAAO,CAAE,UAAS,CAAE;AAClE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EAAG;AACH,CAAC;AAAA,eAEcV,iBAAiB;AAAA"}
|
|
@@ -18,6 +18,7 @@ var _chokidar = _interopRequireDefault(require("chokidar"));
|
|
|
18
18
|
var _webpackErrorUtils = require("../../utils/webpack-error-utils");
|
|
19
19
|
var _actions = require("../../redux/actions");
|
|
20
20
|
var _middleware = require("./middleware");
|
|
21
|
+
var _module = _interopRequireDefault(require("module"));
|
|
21
22
|
const isProductionEnv = process.env.gatsby_executing_command !== `develop`;
|
|
22
23
|
// During development, we lazily compile functions only when they're requested.
|
|
23
24
|
// Here we keep track of which functions have been requested so are "active"
|
|
@@ -233,6 +234,7 @@ const createWebpackConfig = async ({
|
|
|
233
234
|
});
|
|
234
235
|
activeEntries = entries;
|
|
235
236
|
const stage = isProductionEnv ? `functions-production` : `functions-development`;
|
|
237
|
+
const gatsbyPluginTSRequire = _module.default.createRequire(require.resolve(`gatsby-plugin-typescript`));
|
|
236
238
|
return {
|
|
237
239
|
entry: entries,
|
|
238
240
|
output: {
|
|
@@ -290,18 +292,18 @@ const createWebpackConfig = async ({
|
|
|
290
292
|
}
|
|
291
293
|
},
|
|
292
294
|
use: {
|
|
293
|
-
loader: `babel-loader
|
|
295
|
+
loader: require.resolve(`babel-loader`),
|
|
294
296
|
options: {
|
|
295
|
-
presets: [`@babel/typescript`]
|
|
297
|
+
presets: [gatsbyPluginTSRequire.resolve(`@babel/preset-typescript`)]
|
|
296
298
|
}
|
|
297
299
|
}
|
|
298
300
|
}, {
|
|
299
301
|
test: [/.js$/, /.ts$/],
|
|
300
302
|
exclude: /node_modules/,
|
|
301
303
|
use: {
|
|
302
|
-
loader: `babel-loader
|
|
304
|
+
loader: require.resolve(`babel-loader`),
|
|
303
305
|
options: {
|
|
304
|
-
presets: [`@babel/typescript`]
|
|
306
|
+
presets: [gatsbyPluginTSRequire.resolve(`@babel/preset-typescript`)]
|
|
305
307
|
}
|
|
306
308
|
}
|
|
307
309
|
}]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gatsby-node.js","names":["isProductionEnv","process","env","gatsby_executing_command","activeDevelopmentFunctions","Set","activeEntries","ensureFunctionIsCompiled","functionObj","compiledFunctionsDir","compiledFileExists","fs","stat","absoluteCompiledFilePath","e","time","Date","utimesSync","originalAbsoluteFilePath","Promise","resolve","watcher","chokidar","watch","on","_path","close","createGlobArray","siteDirectoryPath","plugins","globs","globIgnorePatterns","root","pluginName","nestedFolder","push","globPattern","ignorePattern","rootPath","path","join","forEach","plugin","name","includes","glob","globAsync","pattern","options","reject","err","files","createWebpackConfig","store","reporter","getState","flattenedPlugins","seenFunctionIds","allFunctions","all","map","knownFunctions","ignore","file","originalRelativeFilePath","relative","dir","parse","compiledFunctionName","compiledPath","finalName","urlResolve","functionIdBase","replace","functionId","has","counter","functionRoute","relativeCompiledFilePath","matchPath","getMatchPath","func","dispatch","internalActions","setFunctions","writeFileSync","JSON","stringify","config","pathPrefix","program","nodeEnv","NODE_ENV","configEnv","GATSBY_ACTIVE_ENV","envFile","parsed","dotenv","readFileSync","encoding","code","error","envObject","Object","keys","reduce","acc","key","varsFromProcessEnv","PUBLIC_DIR","mergedEnvVars","assign","processEnvVars","entries","precompileDevFunctions","GATSBY_PRECOMPILE_DEVELOP_FUNCTIONS","functionsList","parsedFile","compiledNameWithoutExtension","entryToTheFunction","stage","entry","output","filename","libraryTarget","target","optimization","minimize","extensions","cache","type","cacheLocation","mode","module","rules","test","resourceQuery","use","loader","require","byDependency","esm","fullySpecified","descriptionData","presets","exclude","webpack","DefinePlugin","PREFIX_TO_STRIP","prefixPaths","IgnorePlugin","checkResource","resource","warn","isFirstBuild","onPreBootstrap","parentSpan","activity","activityTimer","start","directory","ensureDir","emptyDir","callback","stats","rawMessages","toJson","warnings","errors","length","reportWebpackWarnings","compilation","formatted","formatWebpackMessages","message","success","run","compiler","ignoreInitial","event","values","log","panic","id","context","end","onCreateDevServer","app","verbose","functionMiddlewares","getFunctions","functions","prepareFn","add","showDebugMessageInResponse"],"sources":["../../../src/internal-plugins/functions/gatsby-node.ts"],"sourcesContent":["import fs from \"fs-extra\"\nimport glob from \"glob\"\nimport path from \"path\"\nimport webpack from \"webpack\"\nimport _ from \"lodash\"\nimport { getMatchPath, urlResolve } from \"gatsby-core-utils\"\nimport { CreateDevServerArgs, ParentSpanPluginArgs } from \"gatsby\"\nimport formatWebpackMessages from \"react-dev-utils/formatWebpackMessages\"\nimport dotenv from \"dotenv\"\nimport chokidar from \"chokidar\"\nimport { reportWebpackWarnings } from \"../../utils/webpack-error-utils\"\nimport { internalActions } from \"../../redux/actions\"\nimport { IGatsbyFunction } from \"../../redux/types\"\nimport { functionMiddlewares } from \"./middleware\"\n\nconst isProductionEnv = process.env.gatsby_executing_command !== `develop`\n\ninterface IGlobPattern {\n /** The plugin that owns this namespace **/\n pluginName: string\n /** The root path to the functions **/\n rootPath: string\n /** The glob pattern **/\n globPattern: string\n /** The glob ignore pattern */\n ignorePattern: Array<string>\n}\n\n// During development, we lazily compile functions only when they're requested.\n// Here we keep track of which functions have been requested so are \"active\"\nconst activeDevelopmentFunctions = new Set<IGatsbyFunction>()\nlet activeEntries = {}\n\nasync function ensureFunctionIsCompiled(\n functionObj: IGatsbyFunction,\n compiledFunctionsDir: string\n): Promise<any> {\n // stat the compiled function. If it's there, then return.\n let compiledFileExists = false\n try {\n compiledFileExists = !!(await fs.stat(functionObj.absoluteCompiledFilePath))\n } catch (e) {\n // ignore\n }\n if (compiledFileExists) {\n return\n } else {\n // Otherwise, restart webpack by touching the file and watch for the file to be\n // compiled.\n const time = new Date()\n fs.utimesSync(functionObj.originalAbsoluteFilePath, time, time)\n await new Promise(resolve => {\n const watcher = chokidar\n // Watch the root of the compiled function directory in .cache as chokidar\n // can't watch files in directories that don't yet exist.\n .watch(compiledFunctionsDir)\n .on(`add`, async _path => {\n if (_path === functionObj.absoluteCompiledFilePath) {\n await watcher.close()\n\n resolve(null)\n }\n })\n })\n }\n}\n\n// Create glob type w/ glob, plugin name, root path\nconst createGlobArray = (siteDirectoryPath, plugins): Array<IGlobPattern> => {\n const globs: Array<IGlobPattern> = []\n\n function globIgnorePatterns(\n root: string,\n pluginName?: string\n ): Array<string> {\n const nestedFolder = pluginName ? `/${pluginName}/**/` : `/**/`\n\n return [\n `${root}/src/api${nestedFolder}__tests__/**/*.+(js|ts)`, // Jest tests\n `${root}/src/api${nestedFolder}+(*.)+(spec|test).+(js|ts)`,\n `${root}/src/api${nestedFolder}+(*.)+(d).ts`, // .d.ts files\n ]\n }\n\n // Add the default site src/api directory.\n globs.push({\n globPattern: `${siteDirectoryPath}/src/api/**/*.{js,ts}`,\n ignorePattern: globIgnorePatterns(siteDirectoryPath),\n rootPath: path.join(siteDirectoryPath, `src/api`),\n pluginName: `default-site-plugin`,\n })\n\n // Add each plugin\n plugins.forEach(plugin => {\n // Ignore the \"default\" site plugin (aka the src tree) as we're\n // already watching that.\n if (plugin.name === `default-site-plugin`) {\n return\n }\n // Ignore any plugins we include by default. In the very unlikely case\n // we want to ship default functions, we'll special case add them. In the\n // meantime, we'll avoid extra FS IO.\n if (plugin.resolve.includes(`internal-plugin`)) {\n return\n }\n if (plugin.resolve.includes(`gatsby-plugin-typescript`)) {\n return\n }\n if (plugin.resolve.includes(`gatsby-plugin-page-creator`)) {\n return\n }\n\n const glob = {\n globPattern: `${plugin.resolve}/src/api/${plugin.name}/**/*.{js,ts}`,\n ignorePattern: globIgnorePatterns(plugin.resolve, plugin.name),\n rootPath: path.join(plugin.resolve, `src/api`),\n pluginName: plugin.name,\n } as IGlobPattern\n globs.push(glob)\n })\n\n // Only return unique paths\n return _.union(globs)\n}\n\nasync function globAsync(\n pattern: string,\n options: glob.IOptions = {}\n): Promise<Array<string>> {\n return await new Promise((resolve, reject) => {\n glob(pattern, options, (err, files) => {\n if (err) {\n reject(err)\n } else {\n resolve(files)\n }\n })\n })\n}\n\nconst createWebpackConfig = async ({\n siteDirectoryPath,\n store,\n reporter,\n}): Promise<webpack.Configuration> => {\n const compiledFunctionsDir = path.join(\n siteDirectoryPath,\n `.cache`,\n `functions`\n )\n\n const globs = createGlobArray(\n siteDirectoryPath,\n store.getState().flattenedPlugins\n )\n\n const seenFunctionIds = new Set<string>()\n // Glob and return object with relative/absolute paths + which plugin\n // they belong to.\n const allFunctions = await Promise.all(\n globs.map(async (glob): Promise<Array<IGatsbyFunction>> => {\n const knownFunctions: Array<IGatsbyFunction> = []\n const files = await globAsync(glob.globPattern, {\n ignore: glob.ignorePattern,\n })\n files.map(file => {\n const originalAbsoluteFilePath = file\n const originalRelativeFilePath = path.relative(glob.rootPath, file)\n\n const { dir, name } = path.parse(originalRelativeFilePath)\n // Ignore the original extension as all compiled functions now end with js.\n const compiledFunctionName = path.join(dir, name + `.js`)\n const compiledPath = path.join(\n compiledFunctionsDir,\n compiledFunctionName\n )\n const finalName = urlResolve(dir, name === `index` ? `` : name)\n\n // functionId should have only alphanumeric characters and dashes\n const functionIdBase = _.kebabCase(compiledFunctionName).replace(\n /[^a-zA-Z0-9-]/g,\n `-`\n )\n\n let functionId = functionIdBase\n\n if (seenFunctionIds.has(functionId)) {\n let counter = 2\n do {\n functionId = `${functionIdBase}-${counter}`\n counter++\n } while (seenFunctionIds.has(functionId))\n }\n\n knownFunctions.push({\n functionRoute: finalName,\n pluginName: glob.pluginName,\n originalAbsoluteFilePath,\n originalRelativeFilePath,\n relativeCompiledFilePath: compiledFunctionName,\n absoluteCompiledFilePath: compiledPath,\n matchPath: getMatchPath(finalName),\n functionId,\n })\n })\n\n return knownFunctions\n })\n )\n\n // Combine functions by the route name so that functions in the default\n // functions directory can override the plugin's implementations.\n // @ts-ignore - Seems like a TS bug: https://github.com/microsoft/TypeScript/issues/28010#issuecomment-713484584\n const knownFunctions = _.unionBy(...allFunctions, func => func.functionRoute)\n\n store.dispatch(internalActions.setFunctions(knownFunctions))\n\n // Write out manifest for use by `gatsby serve` and plugins\n fs.writeFileSync(\n path.join(compiledFunctionsDir, `manifest.json`),\n JSON.stringify(knownFunctions, null, 4)\n )\n\n const {\n config: { pathPrefix },\n program,\n } = store.getState()\n\n // Load environment variables from process.env.* and .env.* files.\n // Logic is shared with webpack.config.js\n\n // node env should be DEVELOPMENT | PRODUCTION as these are commonly used in node land\n const nodeEnv = process.env.NODE_ENV || `development`\n // config env is dependent on the env that it's run, this can be anything from staging-production\n // this allows you to set use different .env environments or conditions in gatsby files\n const configEnv = process.env.GATSBY_ACTIVE_ENV || nodeEnv\n const envFile = path.join(siteDirectoryPath, `./.env.${configEnv}`)\n let parsed = {}\n try {\n parsed = dotenv.parse(fs.readFileSync(envFile, { encoding: `utf8` }))\n } catch (err) {\n if (err.code !== `ENOENT`) {\n reporter.error(\n `There was a problem processing the .env file (${envFile})`,\n err\n )\n }\n }\n\n const envObject = Object.keys(parsed).reduce((acc, key) => {\n acc[key] = JSON.stringify(parsed[key])\n return acc\n }, {} as Record<string, string>)\n\n const varsFromProcessEnv = Object.keys(process.env).reduce((acc, key) => {\n acc[key] = JSON.stringify(process.env[key])\n return acc\n }, {} as Record<string, string>)\n\n // Don't allow overwriting of NODE_ENV, PUBLIC_DIR as to not break gatsby things\n envObject.NODE_ENV = JSON.stringify(nodeEnv)\n envObject.PUBLIC_DIR = JSON.stringify(`${siteDirectoryPath}/public`)\n\n const mergedEnvVars = Object.assign(envObject, varsFromProcessEnv)\n\n const processEnvVars = Object.keys(mergedEnvVars).reduce(\n (acc, key) => {\n acc[`process.env.${key}`] = mergedEnvVars[key]\n return acc\n },\n {\n \"process.env\": `({})`,\n }\n )\n\n const entries = {}\n\n const precompileDevFunctions =\n isProductionEnv ||\n process.env.GATSBY_PRECOMPILE_DEVELOP_FUNCTIONS === `true` ||\n process.env.GATSBY_PRECOMPILE_DEVELOP_FUNCTIONS === `1`\n\n const functionsList = precompileDevFunctions\n ? knownFunctions\n : activeDevelopmentFunctions\n\n functionsList.forEach(functionObj => {\n // Get path without the extension (as it could be ts or js)\n const parsedFile = path.parse(functionObj.originalRelativeFilePath)\n const compiledNameWithoutExtension = path.join(\n parsedFile.dir,\n parsedFile.name\n )\n\n let entryToTheFunction = functionObj.originalAbsoluteFilePath\n // we wrap user defined function with our preamble that handles matchPath as well as body parsing\n // see api-function-webpack-loader.ts for more info\n entryToTheFunction += `?matchPath=` + (functionObj.matchPath ?? ``)\n entries[compiledNameWithoutExtension] = entryToTheFunction\n })\n\n activeEntries = entries\n\n const stage = isProductionEnv\n ? `functions-production`\n : `functions-development`\n\n return {\n entry: entries,\n output: {\n path: compiledFunctionsDir,\n filename: `[name].js`,\n libraryTarget: `commonjs2`,\n },\n target: `node`,\n\n // Minification is expensive and not as helpful for serverless functions.\n optimization: {\n minimize: false,\n },\n\n // Resolve files ending with .ts and the default extensions of .js, .json, .wasm\n resolve: {\n extensions: [`.ts`, `...`],\n },\n\n // Have webpack save its cache to the .cache/webpack directory\n cache: {\n type: `filesystem`,\n name: stage,\n cacheLocation: path.join(\n siteDirectoryPath,\n `.cache`,\n `webpack`,\n `stage-` + stage\n ),\n },\n\n mode: isProductionEnv ? `production` : `development`,\n // watch: !isProductionEnv,\n module: {\n rules: [\n // Webpack expects extensions when importing ESM modules as that's what the spec describes.\n // Not all libraries have adapted so we don't enforce its behaviour\n // @see https://github.com/webpack/webpack/issues/11467\n {\n test: /\\.[tj]sx?$/,\n resourceQuery: /matchPath/,\n use: {\n loader: require.resolve(`./api-function-webpack-loader`),\n },\n },\n {\n test: /\\.mjs$/i,\n resolve: {\n byDependency: {\n esm: {\n fullySpecified: false,\n },\n },\n },\n },\n {\n test: /\\.js$/i,\n descriptionData: {\n type: `module`,\n },\n resolve: {\n byDependency: {\n esm: {\n fullySpecified: false,\n },\n },\n },\n use: {\n loader: `babel-loader`,\n options: {\n presets: [`@babel/typescript`],\n },\n },\n },\n {\n test: [/.js$/, /.ts$/],\n exclude: /node_modules/,\n use: {\n loader: `babel-loader`,\n options: {\n presets: [`@babel/typescript`],\n },\n },\n },\n ],\n },\n plugins: [\n new webpack.DefinePlugin({\n PREFIX_TO_STRIP: JSON.stringify(\n program.prefixPaths ? pathPrefix?.replace(/(^\\/+|\\/+$)/g, ``) : ``\n ),\n ...processEnvVars,\n }),\n new webpack.IgnorePlugin({\n checkResource(resource): boolean {\n if (resource === `lmdb`) {\n reporter.warn(\n `LMDB and other modules with native dependencies are not supported in Gatsby Functions.\\nIf you are importing utils from \\`gatsby-core-utils\\`, make sure to import from a specific module (for example \\`gatsby-core-utils/create-content-digest\\`).`\n )\n return true\n }\n return false\n },\n }),\n ],\n }\n}\n\nlet isFirstBuild = true\nexport async function onPreBootstrap({\n reporter,\n store,\n parentSpan,\n}: ParentSpanPluginArgs): Promise<void> {\n const activity = reporter.activityTimer(`Compiling Gatsby Functions`, {\n parentSpan,\n })\n activity.start()\n\n const {\n program: { directory: siteDirectoryPath },\n } = store.getState()\n\n const compiledFunctionsDir = path.join(\n siteDirectoryPath,\n `.cache`,\n `functions`\n )\n\n await fs.ensureDir(compiledFunctionsDir)\n await fs.emptyDir(compiledFunctionsDir)\n\n try {\n // We do this ungainly thing as we need to make accessible\n // the resolve/reject functions to our shared callback function\n // eslint-disable-next-line\n await new Promise<any>(async (resolve, reject) => {\n const config = await createWebpackConfig({\n siteDirectoryPath,\n store,\n reporter,\n })\n\n function callback(err, stats?: webpack.Stats): void {\n const rawMessages = stats?.toJson({\n all: false,\n warnings: true,\n errors: true,\n })\n if (rawMessages?.warnings && rawMessages.warnings.length > 0) {\n reportWebpackWarnings(rawMessages.warnings, reporter)\n }\n\n if (err) return reject(err)\n const errors = stats?.compilation.errors || []\n\n // If there's errors, reject in production and print to the console\n // in development.\n if (isProductionEnv) {\n if (errors.length > 0) return reject(errors)\n } else {\n const formatted = formatWebpackMessages({\n errors: rawMessages?.errors\n ? rawMessages.errors.map(e => e.message)\n : [],\n warnings: [],\n })\n reporter.error(formatted.errors)\n }\n\n // Log success in dev\n if (!isProductionEnv) {\n if (isFirstBuild) {\n isFirstBuild = false\n } else {\n reporter.success(`Re-building functions`)\n }\n }\n\n return resolve(null)\n }\n\n if (isProductionEnv) {\n webpack(config).run(callback)\n } else {\n // When in watch mode, you call things differently\n let compiler = webpack(config).watch({}, callback)\n\n const globs = createGlobArray(\n siteDirectoryPath,\n store.getState().flattenedPlugins\n )\n\n // Watch for env files to change and restart the webpack watcher.\n chokidar\n .watch(\n [\n `${siteDirectoryPath}/.env*`,\n ...globs.map(glob => glob.globPattern),\n ],\n { ignoreInitial: true }\n )\n .on(`all`, async (event, path) => {\n // Ignore change events from the API directory for functions we're\n // already watching.\n if (\n event === `change` &&\n Object.values(activeEntries).includes(path) &&\n path.includes(`/src/api/`)\n ) {\n return\n }\n\n reporter.log(\n `Restarting function watcher due to change to \"${path}\"`\n )\n\n // Otherwise, restart the watcher\n compiler.close(async () => {\n const config = await createWebpackConfig({\n siteDirectoryPath,\n store,\n reporter,\n })\n compiler = webpack(config).watch({}, callback)\n })\n })\n }\n })\n } catch (error) {\n activity.panic({\n id: `11332`,\n error,\n context: {},\n })\n }\n\n activity.end()\n}\n\nexport async function onCreateDevServer({\n reporter,\n app,\n store,\n}: CreateDevServerArgs): Promise<void> {\n reporter.verbose(`Attaching functions to development server`)\n\n const {\n program: { directory: siteDirectoryPath },\n } = store.getState()\n\n const compiledFunctionsDir = path.join(\n siteDirectoryPath,\n `.cache`,\n `functions`\n )\n\n app.use(\n `/api/*`,\n ...functionMiddlewares({\n getFunctions(): Array<IGatsbyFunction> {\n const { functions }: { functions: Array<IGatsbyFunction> } =\n store.getState()\n return functions\n },\n async prepareFn(functionObj: IGatsbyFunction): Promise<void> {\n activeDevelopmentFunctions.add(functionObj)\n await ensureFunctionIsCompiled(functionObj, compiledFunctionsDir)\n },\n showDebugMessageInResponse: true,\n })\n )\n}\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AACA;AACA;AAEA;AAEA,MAAMA,eAAe,GAAGC,OAAO,CAACC,GAAG,CAACC,wBAAwB,KAAM,SAAQ;AAa1E;AACA;AACA,MAAMC,0BAA0B,GAAG,IAAIC,GAAG,EAAmB;AAC7D,IAAIC,aAAa,GAAG,CAAC,CAAC;AAEtB,eAAeC,wBAAwB,CACrCC,WAA4B,EAC5BC,oBAA4B,EACd;EACd;EACA,IAAIC,kBAAkB,GAAG,KAAK;EAC9B,IAAI;IACFA,kBAAkB,GAAG,CAAC,EAAE,MAAMC,gBAAE,CAACC,IAAI,CAACJ,WAAW,CAACK,wBAAwB,CAAC,CAAC;EAC9E,CAAC,CAAC,OAAOC,CAAC,EAAE;IACV;EAAA;EAEF,IAAIJ,kBAAkB,EAAE;IACtB;EACF,CAAC,MAAM;IACL;IACA;IACA,MAAMK,IAAI,GAAG,IAAIC,IAAI,EAAE;IACvBL,gBAAE,CAACM,UAAU,CAACT,WAAW,CAACU,wBAAwB,EAAEH,IAAI,EAAEA,IAAI,CAAC;IAC/D,MAAM,IAAII,OAAO,CAACC,OAAO,IAAI;MAC3B,MAAMC,OAAO,GAAGC;MACd;MACA;MAAA,CACCC,KAAK,CAACd,oBAAoB,CAAC,CAC3Be,EAAE,CAAE,KAAI,EAAE,MAAMC,KAAK,IAAI;QACxB,IAAIA,KAAK,KAAKjB,WAAW,CAACK,wBAAwB,EAAE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AAI,CACpCZ,iBAAiB,EAChB,QAAO,EACP,WAAU,CACZ;EAED+J,GAAG,CAAClD,GAAG,CACJ,QAAO,EACR,GAAG,IAAAoD,+BAAmB,EAAC;IACrBC,YAAY,GAA2B;MACrC,MAAM;QAAEC;MAAiD,CAAC,GACxD1I,KAAK,CAACE,QAAQ,EAAE;MAClB,OAAOwI,SAAS;IAClB,CAAC;IACD,MAAMC,SAAS,CAACxL,WAA4B,EAAiB;MAC3DJ,0BAA0B,CAAC6L,GAAG,CAACzL,WAAW,CAAC;MAC3C,MAAMD,wBAAwB,CAACC,WAAW,EAAEC,oBAAoB,CAAC;IACnE,CAAC;IACDyL,0BAA0B,EAAE;EAC9B,CAAC,CAAC,CACH;AACH"}
|
|
1
|
+
{"version":3,"file":"gatsby-node.js","names":["isProductionEnv","process","env","gatsby_executing_command","activeDevelopmentFunctions","Set","activeEntries","ensureFunctionIsCompiled","functionObj","compiledFunctionsDir","compiledFileExists","fs","stat","absoluteCompiledFilePath","e","time","Date","utimesSync","originalAbsoluteFilePath","Promise","resolve","watcher","chokidar","watch","on","_path","close","createGlobArray","siteDirectoryPath","plugins","globs","globIgnorePatterns","root","pluginName","nestedFolder","push","globPattern","ignorePattern","rootPath","path","join","forEach","plugin","name","includes","glob","globAsync","pattern","options","reject","err","files","createWebpackConfig","store","reporter","getState","flattenedPlugins","seenFunctionIds","allFunctions","all","map","knownFunctions","ignore","file","originalRelativeFilePath","relative","dir","parse","compiledFunctionName","compiledPath","finalName","urlResolve","functionIdBase","replace","functionId","has","counter","functionRoute","relativeCompiledFilePath","matchPath","getMatchPath","func","dispatch","internalActions","setFunctions","writeFileSync","JSON","stringify","config","pathPrefix","program","nodeEnv","NODE_ENV","configEnv","GATSBY_ACTIVE_ENV","envFile","parsed","dotenv","readFileSync","encoding","code","error","envObject","Object","keys","reduce","acc","key","varsFromProcessEnv","PUBLIC_DIR","mergedEnvVars","assign","processEnvVars","entries","precompileDevFunctions","GATSBY_PRECOMPILE_DEVELOP_FUNCTIONS","functionsList","parsedFile","compiledNameWithoutExtension","entryToTheFunction","stage","gatsbyPluginTSRequire","mod","createRequire","require","entry","output","filename","libraryTarget","target","optimization","minimize","extensions","cache","type","cacheLocation","mode","module","rules","test","resourceQuery","use","loader","byDependency","esm","fullySpecified","descriptionData","presets","exclude","webpack","DefinePlugin","PREFIX_TO_STRIP","prefixPaths","IgnorePlugin","checkResource","resource","warn","isFirstBuild","onPreBootstrap","parentSpan","activity","activityTimer","start","directory","ensureDir","emptyDir","callback","stats","rawMessages","toJson","warnings","errors","length","reportWebpackWarnings","compilation","formatted","formatWebpackMessages","message","success","run","compiler","ignoreInitial","event","values","log","panic","id","context","end","onCreateDevServer","app","verbose","functionMiddlewares","getFunctions","functions","prepareFn","add","showDebugMessageInResponse"],"sources":["../../../src/internal-plugins/functions/gatsby-node.ts"],"sourcesContent":["import fs from \"fs-extra\"\nimport glob from \"glob\"\nimport path from \"path\"\nimport webpack from \"webpack\"\nimport _ from \"lodash\"\nimport { getMatchPath, urlResolve } from \"gatsby-core-utils\"\nimport { CreateDevServerArgs, ParentSpanPluginArgs } from \"gatsby\"\nimport formatWebpackMessages from \"react-dev-utils/formatWebpackMessages\"\nimport dotenv from \"dotenv\"\nimport chokidar from \"chokidar\"\nimport { reportWebpackWarnings } from \"../../utils/webpack-error-utils\"\nimport { internalActions } from \"../../redux/actions\"\nimport { IGatsbyFunction } from \"../../redux/types\"\nimport { functionMiddlewares } from \"./middleware\"\nimport mod from \"module\"\n\nconst isProductionEnv = process.env.gatsby_executing_command !== `develop`\n\ninterface IGlobPattern {\n /** The plugin that owns this namespace **/\n pluginName: string\n /** The root path to the functions **/\n rootPath: string\n /** The glob pattern **/\n globPattern: string\n /** The glob ignore pattern */\n ignorePattern: Array<string>\n}\n\n// During development, we lazily compile functions only when they're requested.\n// Here we keep track of which functions have been requested so are \"active\"\nconst activeDevelopmentFunctions = new Set<IGatsbyFunction>()\nlet activeEntries = {}\n\nasync function ensureFunctionIsCompiled(\n functionObj: IGatsbyFunction,\n compiledFunctionsDir: string\n): Promise<any> {\n // stat the compiled function. If it's there, then return.\n let compiledFileExists = false\n try {\n compiledFileExists = !!(await fs.stat(functionObj.absoluteCompiledFilePath))\n } catch (e) {\n // ignore\n }\n if (compiledFileExists) {\n return\n } else {\n // Otherwise, restart webpack by touching the file and watch for the file to be\n // compiled.\n const time = new Date()\n fs.utimesSync(functionObj.originalAbsoluteFilePath, time, time)\n await new Promise(resolve => {\n const watcher = chokidar\n // Watch the root of the compiled function directory in .cache as chokidar\n // can't watch files in directories that don't yet exist.\n .watch(compiledFunctionsDir)\n .on(`add`, async _path => {\n if (_path === functionObj.absoluteCompiledFilePath) {\n await watcher.close()\n\n resolve(null)\n }\n })\n })\n }\n}\n\n// Create glob type w/ glob, plugin name, root path\nconst createGlobArray = (siteDirectoryPath, plugins): Array<IGlobPattern> => {\n const globs: Array<IGlobPattern> = []\n\n function globIgnorePatterns(\n root: string,\n pluginName?: string\n ): Array<string> {\n const nestedFolder = pluginName ? `/${pluginName}/**/` : `/**/`\n\n return [\n `${root}/src/api${nestedFolder}__tests__/**/*.+(js|ts)`, // Jest tests\n `${root}/src/api${nestedFolder}+(*.)+(spec|test).+(js|ts)`,\n `${root}/src/api${nestedFolder}+(*.)+(d).ts`, // .d.ts files\n ]\n }\n\n // Add the default site src/api directory.\n globs.push({\n globPattern: `${siteDirectoryPath}/src/api/**/*.{js,ts}`,\n ignorePattern: globIgnorePatterns(siteDirectoryPath),\n rootPath: path.join(siteDirectoryPath, `src/api`),\n pluginName: `default-site-plugin`,\n })\n\n // Add each plugin\n plugins.forEach(plugin => {\n // Ignore the \"default\" site plugin (aka the src tree) as we're\n // already watching that.\n if (plugin.name === `default-site-plugin`) {\n return\n }\n // Ignore any plugins we include by default. In the very unlikely case\n // we want to ship default functions, we'll special case add them. In the\n // meantime, we'll avoid extra FS IO.\n if (plugin.resolve.includes(`internal-plugin`)) {\n return\n }\n if (plugin.resolve.includes(`gatsby-plugin-typescript`)) {\n return\n }\n if (plugin.resolve.includes(`gatsby-plugin-page-creator`)) {\n return\n }\n\n const glob = {\n globPattern: `${plugin.resolve}/src/api/${plugin.name}/**/*.{js,ts}`,\n ignorePattern: globIgnorePatterns(plugin.resolve, plugin.name),\n rootPath: path.join(plugin.resolve, `src/api`),\n pluginName: plugin.name,\n } as IGlobPattern\n globs.push(glob)\n })\n\n // Only return unique paths\n return _.union(globs)\n}\n\nasync function globAsync(\n pattern: string,\n options: glob.IOptions = {}\n): Promise<Array<string>> {\n return await new Promise((resolve, reject) => {\n glob(pattern, options, (err, files) => {\n if (err) {\n reject(err)\n } else {\n resolve(files)\n }\n })\n })\n}\n\nconst createWebpackConfig = async ({\n siteDirectoryPath,\n store,\n reporter,\n}): Promise<webpack.Configuration> => {\n const compiledFunctionsDir = path.join(\n siteDirectoryPath,\n `.cache`,\n `functions`\n )\n\n const globs = createGlobArray(\n siteDirectoryPath,\n store.getState().flattenedPlugins\n )\n\n const seenFunctionIds = new Set<string>()\n // Glob and return object with relative/absolute paths + which plugin\n // they belong to.\n const allFunctions = await Promise.all(\n globs.map(async (glob): Promise<Array<IGatsbyFunction>> => {\n const knownFunctions: Array<IGatsbyFunction> = []\n const files = await globAsync(glob.globPattern, {\n ignore: glob.ignorePattern,\n })\n files.map(file => {\n const originalAbsoluteFilePath = file\n const originalRelativeFilePath = path.relative(glob.rootPath, file)\n\n const { dir, name } = path.parse(originalRelativeFilePath)\n // Ignore the original extension as all compiled functions now end with js.\n const compiledFunctionName = path.join(dir, name + `.js`)\n const compiledPath = path.join(\n compiledFunctionsDir,\n compiledFunctionName\n )\n const finalName = urlResolve(dir, name === `index` ? `` : name)\n\n // functionId should have only alphanumeric characters and dashes\n const functionIdBase = _.kebabCase(compiledFunctionName).replace(\n /[^a-zA-Z0-9-]/g,\n `-`\n )\n\n let functionId = functionIdBase\n\n if (seenFunctionIds.has(functionId)) {\n let counter = 2\n do {\n functionId = `${functionIdBase}-${counter}`\n counter++\n } while (seenFunctionIds.has(functionId))\n }\n\n knownFunctions.push({\n functionRoute: finalName,\n pluginName: glob.pluginName,\n originalAbsoluteFilePath,\n originalRelativeFilePath,\n relativeCompiledFilePath: compiledFunctionName,\n absoluteCompiledFilePath: compiledPath,\n matchPath: getMatchPath(finalName),\n functionId,\n })\n })\n\n return knownFunctions\n })\n )\n\n // Combine functions by the route name so that functions in the default\n // functions directory can override the plugin's implementations.\n // @ts-ignore - Seems like a TS bug: https://github.com/microsoft/TypeScript/issues/28010#issuecomment-713484584\n const knownFunctions = _.unionBy(...allFunctions, func => func.functionRoute)\n\n store.dispatch(internalActions.setFunctions(knownFunctions))\n\n // Write out manifest for use by `gatsby serve` and plugins\n fs.writeFileSync(\n path.join(compiledFunctionsDir, `manifest.json`),\n JSON.stringify(knownFunctions, null, 4)\n )\n\n const {\n config: { pathPrefix },\n program,\n } = store.getState()\n\n // Load environment variables from process.env.* and .env.* files.\n // Logic is shared with webpack.config.js\n\n // node env should be DEVELOPMENT | PRODUCTION as these are commonly used in node land\n const nodeEnv = process.env.NODE_ENV || `development`\n // config env is dependent on the env that it's run, this can be anything from staging-production\n // this allows you to set use different .env environments or conditions in gatsby files\n const configEnv = process.env.GATSBY_ACTIVE_ENV || nodeEnv\n const envFile = path.join(siteDirectoryPath, `./.env.${configEnv}`)\n let parsed = {}\n try {\n parsed = dotenv.parse(fs.readFileSync(envFile, { encoding: `utf8` }))\n } catch (err) {\n if (err.code !== `ENOENT`) {\n reporter.error(\n `There was a problem processing the .env file (${envFile})`,\n err\n )\n }\n }\n\n const envObject = Object.keys(parsed).reduce((acc, key) => {\n acc[key] = JSON.stringify(parsed[key])\n return acc\n }, {} as Record<string, string>)\n\n const varsFromProcessEnv = Object.keys(process.env).reduce((acc, key) => {\n acc[key] = JSON.stringify(process.env[key])\n return acc\n }, {} as Record<string, string>)\n\n // Don't allow overwriting of NODE_ENV, PUBLIC_DIR as to not break gatsby things\n envObject.NODE_ENV = JSON.stringify(nodeEnv)\n envObject.PUBLIC_DIR = JSON.stringify(`${siteDirectoryPath}/public`)\n\n const mergedEnvVars = Object.assign(envObject, varsFromProcessEnv)\n\n const processEnvVars = Object.keys(mergedEnvVars).reduce(\n (acc, key) => {\n acc[`process.env.${key}`] = mergedEnvVars[key]\n return acc\n },\n {\n \"process.env\": `({})`,\n }\n )\n\n const entries = {}\n\n const precompileDevFunctions =\n isProductionEnv ||\n process.env.GATSBY_PRECOMPILE_DEVELOP_FUNCTIONS === `true` ||\n process.env.GATSBY_PRECOMPILE_DEVELOP_FUNCTIONS === `1`\n\n const functionsList = precompileDevFunctions\n ? knownFunctions\n : activeDevelopmentFunctions\n\n functionsList.forEach(functionObj => {\n // Get path without the extension (as it could be ts or js)\n const parsedFile = path.parse(functionObj.originalRelativeFilePath)\n const compiledNameWithoutExtension = path.join(\n parsedFile.dir,\n parsedFile.name\n )\n\n let entryToTheFunction = functionObj.originalAbsoluteFilePath\n // we wrap user defined function with our preamble that handles matchPath as well as body parsing\n // see api-function-webpack-loader.ts for more info\n entryToTheFunction += `?matchPath=` + (functionObj.matchPath ?? ``)\n entries[compiledNameWithoutExtension] = entryToTheFunction\n })\n\n activeEntries = entries\n\n const stage = isProductionEnv\n ? `functions-production`\n : `functions-development`\n\n const gatsbyPluginTSRequire = mod.createRequire(\n require.resolve(`gatsby-plugin-typescript`)\n )\n\n return {\n entry: entries,\n output: {\n path: compiledFunctionsDir,\n filename: `[name].js`,\n libraryTarget: `commonjs2`,\n },\n target: `node`,\n\n // Minification is expensive and not as helpful for serverless functions.\n optimization: {\n minimize: false,\n },\n\n // Resolve files ending with .ts and the default extensions of .js, .json, .wasm\n resolve: {\n extensions: [`.ts`, `...`],\n },\n\n // Have webpack save its cache to the .cache/webpack directory\n cache: {\n type: `filesystem`,\n name: stage,\n cacheLocation: path.join(\n siteDirectoryPath,\n `.cache`,\n `webpack`,\n `stage-` + stage\n ),\n },\n\n mode: isProductionEnv ? `production` : `development`,\n // watch: !isProductionEnv,\n module: {\n rules: [\n // Webpack expects extensions when importing ESM modules as that's what the spec describes.\n // Not all libraries have adapted so we don't enforce its behaviour\n // @see https://github.com/webpack/webpack/issues/11467\n {\n test: /\\.[tj]sx?$/,\n resourceQuery: /matchPath/,\n use: {\n loader: require.resolve(`./api-function-webpack-loader`),\n },\n },\n {\n test: /\\.mjs$/i,\n resolve: {\n byDependency: {\n esm: {\n fullySpecified: false,\n },\n },\n },\n },\n {\n test: /\\.js$/i,\n descriptionData: {\n type: `module`,\n },\n resolve: {\n byDependency: {\n esm: {\n fullySpecified: false,\n },\n },\n },\n use: {\n loader: require.resolve(`babel-loader`),\n options: {\n presets: [\n gatsbyPluginTSRequire.resolve(`@babel/preset-typescript`),\n ],\n },\n },\n },\n {\n test: [/.js$/, /.ts$/],\n exclude: /node_modules/,\n use: {\n loader: require.resolve(`babel-loader`),\n options: {\n presets: [\n gatsbyPluginTSRequire.resolve(`@babel/preset-typescript`),\n ],\n },\n },\n },\n ],\n },\n plugins: [\n new webpack.DefinePlugin({\n PREFIX_TO_STRIP: JSON.stringify(\n program.prefixPaths ? pathPrefix?.replace(/(^\\/+|\\/+$)/g, ``) : ``\n ),\n ...processEnvVars,\n }),\n new webpack.IgnorePlugin({\n checkResource(resource): boolean {\n if (resource === `lmdb`) {\n reporter.warn(\n `LMDB and other modules with native dependencies are not supported in Gatsby Functions.\\nIf you are importing utils from \\`gatsby-core-utils\\`, make sure to import from a specific module (for example \\`gatsby-core-utils/create-content-digest\\`).`\n )\n return true\n }\n return false\n },\n }),\n ],\n }\n}\n\nlet isFirstBuild = true\nexport async function onPreBootstrap({\n reporter,\n store,\n parentSpan,\n}: ParentSpanPluginArgs): Promise<void> {\n const activity = reporter.activityTimer(`Compiling Gatsby Functions`, {\n parentSpan,\n })\n activity.start()\n\n const {\n program: { directory: siteDirectoryPath },\n } = store.getState()\n\n const compiledFunctionsDir = path.join(\n siteDirectoryPath,\n `.cache`,\n `functions`\n )\n\n await fs.ensureDir(compiledFunctionsDir)\n await fs.emptyDir(compiledFunctionsDir)\n\n try {\n // We do this ungainly thing as we need to make accessible\n // the resolve/reject functions to our shared callback function\n // eslint-disable-next-line\n await new Promise<any>(async (resolve, reject) => {\n const config = await createWebpackConfig({\n siteDirectoryPath,\n store,\n reporter,\n })\n\n function callback(err, stats?: webpack.Stats): void {\n const rawMessages = stats?.toJson({\n all: false,\n warnings: true,\n errors: true,\n })\n if (rawMessages?.warnings && rawMessages.warnings.length > 0) {\n reportWebpackWarnings(rawMessages.warnings, reporter)\n }\n\n if (err) return reject(err)\n const errors = stats?.compilation.errors || []\n\n // If there's errors, reject in production and print to the console\n // in development.\n if (isProductionEnv) {\n if (errors.length > 0) return reject(errors)\n } else {\n const formatted = formatWebpackMessages({\n errors: rawMessages?.errors\n ? rawMessages.errors.map(e => e.message)\n : [],\n warnings: [],\n })\n reporter.error(formatted.errors)\n }\n\n // Log success in dev\n if (!isProductionEnv) {\n if (isFirstBuild) {\n isFirstBuild = false\n } else {\n reporter.success(`Re-building functions`)\n }\n }\n\n return resolve(null)\n }\n\n if (isProductionEnv) {\n webpack(config).run(callback)\n } else {\n // When in watch mode, you call things differently\n let compiler = webpack(config).watch({}, callback)\n\n const globs = createGlobArray(\n siteDirectoryPath,\n store.getState().flattenedPlugins\n )\n\n // Watch for env files to change and restart the webpack watcher.\n chokidar\n .watch(\n [\n `${siteDirectoryPath}/.env*`,\n ...globs.map(glob => glob.globPattern),\n ],\n { ignoreInitial: true }\n )\n .on(`all`, async (event, path) => {\n // Ignore change events from the API directory for functions we're\n // already watching.\n if (\n event === `change` &&\n Object.values(activeEntries).includes(path) &&\n path.includes(`/src/api/`)\n ) {\n return\n }\n\n reporter.log(\n `Restarting function watcher due to change to \"${path}\"`\n )\n\n // Otherwise, restart the watcher\n compiler.close(async () => {\n const config = await createWebpackConfig({\n siteDirectoryPath,\n store,\n reporter,\n })\n compiler = webpack(config).watch({}, callback)\n })\n })\n }\n })\n } catch (error) {\n activity.panic({\n id: `11332`,\n error,\n context: {},\n })\n }\n\n activity.end()\n}\n\nexport async function onCreateDevServer({\n reporter,\n app,\n store,\n}: CreateDevServerArgs): Promise<void> {\n reporter.verbose(`Attaching functions to development server`)\n\n const {\n program: { directory: siteDirectoryPath },\n } = store.getState()\n\n const compiledFunctionsDir = path.join(\n siteDirectoryPath,\n `.cache`,\n `functions`\n )\n\n app.use(\n `/api/*`,\n ...functionMiddlewares({\n getFunctions(): Array<IGatsbyFunction> {\n const { functions }: { functions: Array<IGatsbyFunction> } =\n store.getState()\n return functions\n },\n async prepareFn(functionObj: IGatsbyFunction): Promise<void> {\n activeDevelopmentFunctions.add(functionObj)\n await ensureFunctionIsCompiled(functionObj, compiledFunctionsDir)\n },\n showDebugMessageInResponse: true,\n })\n )\n}\n"],"mappings":";;;;;;;;;AAAA;AACA;AACA;AACA;AAEA;AAEA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA,MAAMA,eAAe,GAAGC,OAAO,CAACC,GAAG,CAACC,wBAAwB,KAAM,SAAQ;AAa1E;AACA;AACA,MAAMC,0BAA0B,GAAG,IAAIC,GAAG,EAAmB;AAC7D,IAAIC,aAAa,GAAG,CAAC,CAAC;AAEtB,eAAeC,wBAAwB,CACrCC,WAA4B,EAC5BC,oBAA4B,EACd;EACd;EACA,IAAIC,kBAAkB,GAAG,KAAK;EAC9B,IAAI;IACFA,kBAAkB,GAAG,CAAC,EAAE,MAAMC,gBAAE,CAACC,IAAI,CAACJ,WAAW,CAACK,wBAAwB,CAAC,CAAC;EAC9E,CAAC,CAAC,OAAOC,CAAC,EAAE;IACV;EAAA;EAEF,IAAIJ,kBAAkB,EAAE;IACtB;EACF,CAAC,MAAM;IACL;IACA;IACA,MAAMK,IAAI,GAAG,IAAIC,IAAI,EAAE;IACvBL,gBAAE,CAACM,UAAU,CAACT,WAAW,CAACU,wBAAwB,EAAEH,IAAI,EAAEA,IAAI,CAAC;IAC/D,MAAM,IAAII,OAAO,CAACC,OAAO,IAAI;MAC3B,MAAMC,OAAO,GAAGC;MACd;MACA;M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rF,KAAK;MACLsF,OAAO,EAAE,CAAC;IACZ,CAAC,CAAC;EACJ;EAEA3B,QAAQ,CAAC4B,GAAG,EAAE;AAChB;AAEO,eAAeC,iBAAiB,CAAC;EACtCvI,QAAQ;EACRwI,GAAG;EACHzI;AACmB,CAAC,EAAiB;EACrCC,QAAQ,CAACyI,OAAO,CAAE,2CAA0C,CAAC;EAE7D,MAAM;IACJrG,OAAO,EAAE;MAAEyE,SAAS,EAAEvI;IAAkB;EAC1C,CAAC,GAAGyB,KAAK,CAACE,QAAQ,EAAE;EAEpB,MAAM9C,oBAAoB,GAAG8B,cAAI,CAACC,IAAI,CACpCZ,iBAAiB,EAChB,QAAO,EACP,WAAU,CACZ;EAEDkK,GAAG,CAACjD,GAAG,CACJ,QAAO,EACR,GAAG,IAAAmD,+BAAmB,EAAC;IACrBC,YAAY,GAA2B;MACrC,MAAM;QAAEC;MAAiD,CAAC,GACxD7I,KAAK,CAACE,QAAQ,EAAE;MAClB,OAAO2I,SAAS;IAClB,CAAC;IACD,MAAMC,SAAS,CAAC3L,WAA4B,EAAiB;MAC3DJ,0BAA0B,CAACgM,GAAG,CAAC5L,WAAW,CAAC;MAC3C,MAAMD,wBAAwB,CAACC,WAAW,EAAEC,oBAAoB,CAAC;IACnE,CAAC;IACD4L,0BAA0B,EAAE;EAC9B,CAAC,CAAC,CACH;AACH"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
1
|
import type { AdapterInit } from "./types";
|
|
2
|
-
export declare
|
|
2
|
+
export declare const getAdaptersCacheDir: () => string;
|
|
3
|
+
export declare function getAdapterInit(currentGatsbyVersion?: string): Promise<AdapterInit | undefined>;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
exports.__esModule = true;
|
|
5
5
|
exports.getAdapterInit = getAdapterInit;
|
|
6
|
-
|
|
6
|
+
exports.getAdaptersCacheDir = void 0;
|
|
7
7
|
var _reporter = _interopRequireDefault(require("gatsby-cli/lib/reporter"));
|
|
8
8
|
var _createRequireFromPath = require("gatsby-core-utils/create-require-from-path");
|
|
9
9
|
var _path = require("path");
|
|
@@ -14,6 +14,7 @@ var _semver = require("semver");
|
|
|
14
14
|
var _preferDefault = require("../../bootstrap/prefer-default");
|
|
15
15
|
var _getLatestGatsbyFiles = require("../get-latest-gatsby-files");
|
|
16
16
|
const getAdaptersCacheDir = () => (0, _path.join)(process.cwd(), `.cache/adapters`);
|
|
17
|
+
exports.getAdaptersCacheDir = getAdaptersCacheDir;
|
|
17
18
|
const createAdaptersCacheDir = async () => {
|
|
18
19
|
await (0, _fsExtra.ensureDir)(getAdaptersCacheDir());
|
|
19
20
|
await (0, _fsExtra.emptyDir)(getAdaptersCacheDir());
|
|
@@ -27,94 +28,155 @@ const createAdaptersCacheDir = async () => {
|
|
|
27
28
|
license: `MIT`
|
|
28
29
|
});
|
|
29
30
|
};
|
|
30
|
-
async
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
_reporter.default.verbose(`No adapter was found for the current environment. Skipping adapter initialization.`);
|
|
36
|
-
return undefined;
|
|
37
|
-
}
|
|
38
|
-
const versionForCurrentGatsbyVersion = adapterToUse.versions.find(entry => (0, _semver.satisfies)(_package.version, entry.gatsbyVersion, {
|
|
39
|
-
includePrerelease: true
|
|
40
|
-
}));
|
|
41
|
-
if (!versionForCurrentGatsbyVersion) {
|
|
42
|
-
_reporter.default.verbose(`The ${adapterToUse.name} adapter is not compatible with your current Gatsby version ${_package.version}.`);
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
// 2. Check if the user has manually installed the adapter and try to resolve it from there
|
|
31
|
+
const tryLoadingAlreadyInstalledAdapter = async ({
|
|
32
|
+
adapterToUse,
|
|
33
|
+
installLocation,
|
|
34
|
+
currentGatsbyVersion
|
|
35
|
+
}) => {
|
|
47
36
|
try {
|
|
48
|
-
const
|
|
49
|
-
const adapterPackageJson =
|
|
50
|
-
const
|
|
51
|
-
const moduleVersion = adapterPackageJson === null || adapterPackageJson === void 0 ? void 0 : adapterPackageJson.version;
|
|
37
|
+
const locationRequire = (0, _createRequireFromPath.createRequireFromPath)(`${installLocation}/:internal:`);
|
|
38
|
+
const adapterPackageJson = locationRequire(`${adapterToUse.module}/package.json`);
|
|
39
|
+
const adapterPackageVersion = adapterPackageJson === null || adapterPackageJson === void 0 ? void 0 : adapterPackageJson.version;
|
|
52
40
|
|
|
53
|
-
// Check if
|
|
54
|
-
if (
|
|
41
|
+
// Check if installed adapter version is compatible with the current Gatsby version based on the manifest
|
|
42
|
+
if (!(0, _semver.satisfies)(adapterPackageVersion, adapterToUse.moduleVersion, {
|
|
55
43
|
includePrerelease: true
|
|
56
44
|
})) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
includePrerelease: true
|
|
64
|
-
});
|
|
65
|
-
if (!isAdapterCompatible) {
|
|
66
|
-
_reporter.default.warn(`${adapterToUse.module}@${moduleVersion} is not compatible with your current Gatsby version ${_package.version} - Install ${adapterToUse.module}@${versionForCurrentGatsbyVersion.moduleVersion} or later.`);
|
|
67
|
-
return undefined;
|
|
45
|
+
return {
|
|
46
|
+
found: true,
|
|
47
|
+
compatible: false,
|
|
48
|
+
installedVersion: adapterPackageVersion,
|
|
49
|
+
incompatibilityReason: `Used gatsby version "${currentGatsbyVersion}" requires "${adapterToUse.module}@${adapterToUse.moduleVersion}". Installed "${adapterToUse.module}" version: "${adapterPackageVersion}".`
|
|
50
|
+
};
|
|
68
51
|
}
|
|
69
|
-
const required =
|
|
52
|
+
const required = locationRequire.resolve(adapterToUse.module);
|
|
70
53
|
if (required) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
54
|
+
return {
|
|
55
|
+
found: true,
|
|
56
|
+
compatible: true,
|
|
57
|
+
installedVersion: adapterPackageVersion,
|
|
58
|
+
loadedModule: (0, _preferDefault.preferDefault)((0, _preferDefault.preferDefault)(await import(required)))
|
|
59
|
+
};
|
|
60
|
+
} else {
|
|
61
|
+
return {
|
|
62
|
+
found: false
|
|
63
|
+
};
|
|
75
64
|
}
|
|
76
65
|
} catch (e) {
|
|
77
|
-
|
|
66
|
+
return {
|
|
67
|
+
found: false
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
const handleAdapterProblem = (message, panicFn = _reporter.default.panic) => {
|
|
72
|
+
if (!process.env.GATSBY_CONTINUE_BUILD_ON_ADAPTER_MISMATCH) {
|
|
73
|
+
panicFn(`${message}\n\nZero-configuration deployment failed to avoid potentially broken deployment.\nIf you want build to continue despite above problems:\n - configure adapter manually in gatsby-config which will skip zero-configuration deployment attempt\n - or set GATSBY_CONTINUE_BUILD_ON_MISSING_ADAPTER=true environment variable to continue build without an adapter.`);
|
|
74
|
+
} else {
|
|
75
|
+
_reporter.default.warn(`${message}\n\nContinuing build using without using any adapter due to GATSBY_CONTINUE_BUILD_ON_MISSING_ADAPTER environment variable being set`);
|
|
78
76
|
}
|
|
77
|
+
return undefined;
|
|
78
|
+
};
|
|
79
|
+
async function getAdapterInit(currentGatsbyVersion = _package.version) {
|
|
80
|
+
// 0. Try to fetch the latest adapters manifest - if it fails, we continue with manifest packaged with current version of gatsby
|
|
81
|
+
const latestAdapters = await (0, _getLatestGatsbyFiles.getLatestAdapters)();
|
|
79
82
|
|
|
80
|
-
//
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
83
|
+
// 1. Find adapter candidates that are compatible with the current environment
|
|
84
|
+
// we find all matching adapters in case package is renamed in the future and future gatsby versions will need different package than previous ones
|
|
85
|
+
const adapterEntry = latestAdapters.find(candidate => candidate.test());
|
|
86
|
+
if (!adapterEntry) {
|
|
87
|
+
_reporter.default.verbose(`No adapter was found for the current environment. Skipping adapter initialization.`);
|
|
88
|
+
return undefined;
|
|
89
|
+
}
|
|
86
90
|
|
|
87
|
-
|
|
88
|
-
|
|
91
|
+
// 2.From the manifest entry find one that supports current Gatsby version and identify it's version to use
|
|
92
|
+
// First matching one will be used.
|
|
93
|
+
let adapterToUse = undefined;
|
|
94
|
+
for (const versionEntry of adapterEntry.versions) {
|
|
95
|
+
if ((0, _semver.satisfies)(currentGatsbyVersion, versionEntry.gatsbyVersion, {
|
|
96
|
+
includePrerelease: true
|
|
97
|
+
})) {
|
|
98
|
+
var _versionEntry$module;
|
|
99
|
+
adapterToUse = {
|
|
100
|
+
name: adapterEntry.name,
|
|
101
|
+
module: (_versionEntry$module = versionEntry.module) !== null && _versionEntry$module !== void 0 ? _versionEntry$module : adapterEntry.module,
|
|
102
|
+
gatsbyVersion: versionEntry.gatsbyVersion,
|
|
103
|
+
moduleVersion: versionEntry.moduleVersion
|
|
104
|
+
};
|
|
105
|
+
break;
|
|
89
106
|
}
|
|
90
|
-
} catch (e) {
|
|
91
|
-
// no-op
|
|
92
107
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
108
|
+
if (!adapterToUse) {
|
|
109
|
+
return handleAdapterProblem(`No version of ${adapterEntry.name} adapter is compatible with your current Gatsby version ${currentGatsbyVersion}.`);
|
|
110
|
+
}
|
|
111
|
+
{
|
|
112
|
+
// 3. Check if the user has manually installed the adapter and try to resolve it from there
|
|
113
|
+
const adapterInstalledByUserResults = await tryLoadingAlreadyInstalledAdapter({
|
|
114
|
+
adapterToUse,
|
|
115
|
+
installLocation: process.cwd(),
|
|
116
|
+
currentGatsbyVersion
|
|
117
|
+
});
|
|
118
|
+
if (adapterInstalledByUserResults.found) {
|
|
119
|
+
if (adapterInstalledByUserResults.compatible) {
|
|
120
|
+
_reporter.default.verbose(`Using site's adapter dependency "${adapterToUse.module}@${adapterInstalledByUserResults.installedVersion}"`);
|
|
121
|
+
return adapterInstalledByUserResults.loadedModule;
|
|
122
|
+
} else {
|
|
123
|
+
_reporter.default.warn(`Ignoring incompatible ${adapterToUse.module}@${adapterInstalledByUserResults.installedVersion} installed by site. ${adapterInstalledByUserResults.incompatibilityReason}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
{
|
|
128
|
+
// 4. Check if a previous run has installed the correct adapter into .cache/adapters already and try to resolve it from there
|
|
129
|
+
const adapterPreviouslyInstalledInCacheAdaptersResults = await tryLoadingAlreadyInstalledAdapter({
|
|
130
|
+
adapterToUse,
|
|
131
|
+
installLocation: getAdaptersCacheDir(),
|
|
132
|
+
currentGatsbyVersion
|
|
133
|
+
});
|
|
134
|
+
if (adapterPreviouslyInstalledInCacheAdaptersResults.found) {
|
|
135
|
+
if (adapterPreviouslyInstalledInCacheAdaptersResults.compatible) {
|
|
136
|
+
_reporter.default.verbose(`Using previously adapter previously installed by gatsby "${adapterToUse.module}@${adapterPreviouslyInstalledInCacheAdaptersResults.installedVersion}"`);
|
|
137
|
+
return adapterPreviouslyInstalledInCacheAdaptersResults.loadedModule;
|
|
138
|
+
} else {
|
|
139
|
+
_reporter.default.verbose(`Ignoring incompatible ${adapterToUse.module} installed by gatsby in ".cache/adapters" before. ${adapterPreviouslyInstalledInCacheAdaptersResults.incompatibilityReason}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
{
|
|
144
|
+
// 5. If user has not installed the adapter manually or is incompatible and we don't have cached version installed by gatsby or that version is not compatible
|
|
145
|
+
// we try to install compatible version into .cache/adapters
|
|
146
|
+
const installTimer = _reporter.default.activityTimer(`Installing ${adapterToUse.name} adapter (${adapterToUse.module}@${adapterToUse.moduleVersion})`);
|
|
147
|
+
try {
|
|
148
|
+
installTimer.start();
|
|
149
|
+
await createAdaptersCacheDir();
|
|
150
|
+
const options = {
|
|
151
|
+
stderr: `inherit`,
|
|
152
|
+
cwd: getAdaptersCacheDir()
|
|
153
|
+
};
|
|
154
|
+
const npmAdditionalCliArgs = [`--no-progress`, `--no-audit`, `--no-fund`, `--loglevel`, `error`, `--color`, `always`, `--legacy-peer-deps`, `--save-exact`];
|
|
155
|
+
await (0, _execa.default)(`npm`, [`install`, ...npmAdditionalCliArgs, `${adapterToUse.module}@${adapterToUse.moduleVersion}`], options);
|
|
156
|
+
} catch (e) {
|
|
157
|
+
return handleAdapterProblem(`Could not install adapter "${adapterToUse.module}@${adapterToUse.moduleVersion}". Please install it yourself by adding it to your package.json's dependencies and try building your project again.`, installTimer.panic);
|
|
113
158
|
}
|
|
114
|
-
} catch (e) {
|
|
115
159
|
installTimer.end();
|
|
116
|
-
_reporter.default.warn(`Could not install adapter ${adapterToUse.module}. Please install it yourself by adding it to your package.json's dependencies and try building your project again.`);
|
|
117
160
|
}
|
|
118
|
-
|
|
161
|
+
{
|
|
162
|
+
// 5. Try to load again from ".cache/adapters"
|
|
163
|
+
const adapterAutoInstalledInCacheAdaptersResults = await tryLoadingAlreadyInstalledAdapter({
|
|
164
|
+
adapterToUse,
|
|
165
|
+
installLocation: getAdaptersCacheDir(),
|
|
166
|
+
currentGatsbyVersion
|
|
167
|
+
});
|
|
168
|
+
if (adapterAutoInstalledInCacheAdaptersResults.found) {
|
|
169
|
+
if (adapterAutoInstalledInCacheAdaptersResults.compatible) {
|
|
170
|
+
_reporter.default.info(`If you plan on staying on this deployment platform, consider installing "${adapterToUse.module}@${adapterToUse.moduleVersion}" as a dependency in your project. This will give you faster and more robust installs.`);
|
|
171
|
+
return adapterAutoInstalledInCacheAdaptersResults.loadedModule;
|
|
172
|
+
} else {
|
|
173
|
+
// this indicates a bug as we install version with range from manifest, and now after trying to load the adapter we consider that adapter incompatible
|
|
174
|
+
return handleAdapterProblem(`Auto installed adapter "${adapterToUse.module}@${adapterAutoInstalledInCacheAdaptersResults.installedVersion}"`);
|
|
175
|
+
}
|
|
176
|
+
} else {
|
|
177
|
+
// this indicates a bug with adapter itself (fail to resolve main entry point) OR the adapter loading logic
|
|
178
|
+
return handleAdapterProblem(`Could not load adapter "${adapterToUse.module}@${adapterToUse.moduleVersion}". Adapter entry point is not resolvable.`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
119
181
|
}
|
|
120
182
|
//# sourceMappingURL=init.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.js","names":["getAdaptersCacheDir","join","process","cwd","createAdaptersCacheDir","ensureDir","emptyDir","packageJsonPath","outputJson","name","description","version","private","author","license","getAdapterInit","latestAdapters","getLatestAdapters","adapterToUse","find","candidate","test","reporter","verbose","undefined","versionForCurrentGatsbyVersion","versions","entry","satisfies","gatsbyVersion","includePrerelease","siteRequire","createRequireFromPath","adapterPackageJson","module","adapterGatsbyPeerDependency","moduleVersion","warn","isAdapterCompatible","required","resolve","preferDefault","e","adaptersRequire","installTimer","activityTimer","start","options","stderr","npmAdditionalCliArgs","execa","end","info"],"sources":["../../../src/utils/adapter/init.ts"],"sourcesContent":["import reporter from \"gatsby-cli/lib/reporter\"\nimport _ from \"lodash\"\nimport { createRequireFromPath } from \"gatsby-core-utils/create-require-from-path\"\nimport { join } from \"path\"\nimport { emptyDir, ensureDir, outputJson } from \"fs-extra\"\nimport execa, { Options as ExecaOptions } from \"execa\"\nimport { version as gatsbyVersion } from \"gatsby/package.json\"\nimport { satisfies } from \"semver\"\nimport type { AdapterInit } from \"./types\"\nimport { preferDefault } from \"../../bootstrap/prefer-default\"\nimport { getLatestAdapters } from \"../get-latest-gatsby-files\"\n\nconst getAdaptersCacheDir = (): string => join(process.cwd(), `.cache/adapters`)\n\nconst createAdaptersCacheDir = async (): Promise<void> => {\n await ensureDir(getAdaptersCacheDir())\n await emptyDir(getAdaptersCacheDir())\n\n const packageJsonPath = join(getAdaptersCacheDir(), `package.json`)\n\n await outputJson(packageJsonPath, {\n name: `gatsby-adapters`,\n description: `This directory contains adapters that have been automatically installed by Gatsby.`,\n version: `1.0.0`,\n private: true,\n author: `Gatsby`,\n license: `MIT`,\n })\n}\n\nexport async function getAdapterInit(): Promise<AdapterInit | undefined> {\n // 1. Find the correct adapter and its details (e.g. version)\n const latestAdapters = await getLatestAdapters()\n const adapterToUse = latestAdapters.find(candidate => candidate.test())\n\n if (!adapterToUse) {\n reporter.verbose(\n `No adapter was found for the current environment. Skipping adapter initialization.`\n )\n return undefined\n }\n\n const versionForCurrentGatsbyVersion = adapterToUse.versions.find(entry =>\n satisfies(gatsbyVersion, entry.gatsbyVersion, { includePrerelease: true })\n )\n\n if (!versionForCurrentGatsbyVersion) {\n reporter.verbose(\n `The ${adapterToUse.name} adapter is not compatible with your current Gatsby version ${gatsbyVersion}.`\n )\n return undefined\n }\n\n // 2. Check if the user has manually installed the adapter and try to resolve it from there\n try {\n const siteRequire = createRequireFromPath(`${process.cwd()}/:internal:`)\n const adapterPackageJson = siteRequire(\n `${adapterToUse.module}/package.json`\n )\n const adapterGatsbyPeerDependency = _.get(\n adapterPackageJson,\n `peerDependencies.gatsby`\n )\n const moduleVersion = adapterPackageJson?.version\n\n // Check if the peerDependency of the adapter is compatible with the current Gatsby version\n if (\n adapterGatsbyPeerDependency &&\n !satisfies(gatsbyVersion, adapterGatsbyPeerDependency, {\n includePrerelease: true,\n })\n ) {\n reporter.warn(\n `The ${adapterToUse.name} adapter is not compatible with your current Gatsby version ${gatsbyVersion} - It requires gatsby@${adapterGatsbyPeerDependency}`\n )\n return undefined\n }\n\n // Cross-check the adapter version with the version manifest and see if the adapter version is correct for the current Gatsby version\n const isAdapterCompatible = satisfies(\n moduleVersion,\n versionForCurrentGatsbyVersion.moduleVersion,\n {\n includePrerelease: true,\n }\n )\n\n if (!isAdapterCompatible) {\n reporter.warn(\n `${adapterToUse.module}@${moduleVersion} is not compatible with your current Gatsby version ${gatsbyVersion} - Install ${adapterToUse.module}@${versionForCurrentGatsbyVersion.moduleVersion} or later.`\n )\n\n return undefined\n }\n\n const required = siteRequire.resolve(adapterToUse.module)\n\n if (required) {\n reporter.verbose(\n `Reusing existing adapter ${adapterToUse.module} inside node_modules`\n )\n\n // TODO: double preferDefault is most ceirtainly wrong - figure it out\n return preferDefault(preferDefault(await import(required))) as AdapterInit\n }\n } catch (e) {\n // no-op\n }\n\n // 3. Check if a previous run has installed the correct adapter into .cache/adapters already and try to resolve it from there\n try {\n const adaptersRequire = createRequireFromPath(\n `${getAdaptersCacheDir()}/:internal:`\n )\n const required = adaptersRequire.resolve(adapterToUse.module)\n\n if (required) {\n reporter.verbose(\n `Reusing existing adapter ${adapterToUse.module} inside .cache/adapters`\n )\n\n // TODO: double preferDefault is most ceirtainly wrong - figure it out\n return preferDefault(preferDefault(await import(required))) as AdapterInit\n }\n } catch (e) {\n // no-op\n }\n\n const installTimer = reporter.activityTimer(\n `Installing ${adapterToUse.name} adapter (${adapterToUse.module}@${versionForCurrentGatsbyVersion.moduleVersion})`\n )\n // 4. If both a manually installed version and a cached version are not found, install the adapter into .cache/adapters\n try {\n installTimer.start()\n await createAdaptersCacheDir()\n\n const options: ExecaOptions = {\n stderr: `inherit`,\n cwd: getAdaptersCacheDir(),\n }\n\n const npmAdditionalCliArgs = [\n `--no-progress`,\n `--no-audit`,\n `--no-fund`,\n `--loglevel`,\n `error`,\n `--color`,\n `always`,\n `--legacy-peer-deps`,\n `--save-exact`,\n ]\n\n await execa(\n `npm`,\n [\n `install`,\n ...npmAdditionalCliArgs,\n `${adapterToUse.module}@${versionForCurrentGatsbyVersion.moduleVersion}`,\n ],\n options\n )\n\n installTimer.end()\n\n reporter.info(\n `If you plan on staying on this deployment platform, consider installing ${adapterToUse.module} as a dependency in your project. This will give you faster and more robust installs.`\n )\n\n const adaptersRequire = createRequireFromPath(\n `${getAdaptersCacheDir()}/:internal:`\n )\n const required = adaptersRequire.resolve(adapterToUse.module)\n\n if (required) {\n reporter.verbose(\n `Using installed adapter ${adapterToUse.module} inside .cache/adapters`\n )\n\n // TODO: double preferDefault is most ceirtainly wrong - figure it out\n return preferDefault(preferDefault(await import(required))) as AdapterInit\n }\n } catch (e) {\n installTimer.end()\n\n reporter.warn(\n `Could not install adapter ${adapterToUse.module}. Please install it yourself by adding it to your package.json's dependencies and try building your project again.`\n )\n }\n\n return undefined\n}\n"],"mappings":";;;;;;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEA,MAAMA,mBAAmB,GAAG,MAAc,IAAAC,UAAI,EAACC,OAAO,CAACC,GAAG,EAAE,EAAG,iBAAgB,CAAC;AAEhF,MAAMC,sBAAsB,GAAG,YAA2B;EACxD,MAAM,IAAAC,kBAAS,EAACL,mBAAmB,EAAE,CAAC;EACtC,MAAM,IAAAM,iBAAQ,EAACN,mBAAmB,EAAE,CAAC;EAErC,MAAMO,eAAe,GAAG,IAAAN,UAAI,EAACD,mBAAmB,EAAE,EAAG,cAAa,CAAC;EAEnE,MAAM,IAAAQ,mBAAU,EAACD,eAAe,EAAE;IAChCE,IAAI,EAAG,iBAAgB;IACvBC,WAAW,EAAG,oFAAmF;IACjGC,OAAO,EAAG,OAAM;IAChBC,OAAO,EAAE,IAAI;IACbC,MAAM,EAAG,QAAO;IAChBC,OAAO,EAAG;EACZ,CAAC,CAAC;AACJ,CAAC;AAEM,eAAeC,cAAc,GAAqC;EACvE;EACA,MAAMC,cAAc,GAAG,MAAM,IAAAC,uCAAiB,GAAE;EAChD,MAAMC,YAAY,GAAGF,cAAc,CAACG,IAAI,CAACC,SAAS,IAAIA,SAAS,CAACC,IAAI,EAAE,CAAC;EAEvE,IAAI,CAACH,YAAY,EAAE;IACjBI,iBAAQ,CAACC,OAAO,CACb,oFAAmF,CACrF;IACD,OAAOC,SAAS;EAClB;EAEA,MAAMC,8BAA8B,GAAGP,YAAY,CAACQ,QAAQ,CAACP,IAAI,CAACQ,KAAK,IACrE,IAAAC,iBAAS,EAACC,gBAA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,GAAGD,oBAAoB,EACtB,GAAE/B,YAAY,CAACgB,MAAO,IAAGT,8BAA8B,CAACW,aAAc,EAAC,CACzE,EACDW,OAAO,CACR;IAEDH,YAAY,CAACO,GAAG,EAAE;IAElB7B,iBAAQ,CAAC8B,IAAI,CACV,2EAA0ElC,YAAY,CAACgB,MAAO,uFAAsF,CACtL;IAED,MAAMS,eAAe,GAAG,IAAAX,4CAAqB,EAC1C,GAAEhC,mBAAmB,EAAG,aAAY,CACtC;IACD,MAAMuC,QAAQ,GAAGI,eAAe,CAACH,OAAO,CAACtB,YAAY,CAACgB,MAAM,CAAC;IAE7D,IAAIK,QAAQ,EAAE;MACZjB,iBAAQ,CAACC,OAAO,CACb,2BAA0BL,YAAY,CAACgB,MAAO,yBAAwB,CACxE;;MAED;MACA,OAAO,IAAAO,4BAAa,EAAC,IAAAA,4BAAa,EAAC,MAAM,MAAM,CAACF,QAAQ,CAAC,CAAC,CAAC;IAC7D;EACF,CAAC,CAAC,OAAOG,CAAC,EAAE;IACVE,YAAY,CAACO,GAAG,EAAE;IAElB7B,iBAAQ,CAACe,IAAI,CACV,6BAA4BnB,YAAY,CAACgB,MAAO,oHAAmH,CACrK;EACH;EAEA,OAAOV,SAAS;AAClB"}
|
|
1
|
+
{"version":3,"file":"init.js","names":["getAdaptersCacheDir","join","process","cwd","createAdaptersCacheDir","ensureDir","emptyDir","packageJsonPath","outputJson","name","description","version","private","author","license","tryLoadingAlreadyInstalledAdapter","adapterToUse","installLocation","currentGatsbyVersion","locationRequire","createRequireFromPath","adapterPackageJson","module","adapterPackageVersion","satisfies","moduleVersion","includePrerelease","found","compatible","installedVersion","incompatibilityReason","required","resolve","loadedModule","preferDefault","e","handleAdapterProblem","message","panicFn","reporter","panic","env","GATSBY_CONTINUE_BUILD_ON_ADAPTER_MISMATCH","warn","undefined","getAdapterInit","gatsbyVersionFromPackageJson","latestAdapters","getLatestAdapters","adapterEntry","find","candidate","test","verbose","versionEntry","versions","gatsbyVersion","adapterInstalledByUserResults","adapterPreviouslyInstalledInCacheAdaptersResults","installTimer","activityTimer","start","options","stderr","npmAdditionalCliArgs","execa","end","adapterAutoInstalledInCacheAdaptersResults","info"],"sources":["../../../src/utils/adapter/init.ts"],"sourcesContent":["import reporter from \"gatsby-cli/lib/reporter\"\nimport _ from \"lodash\"\nimport { createRequireFromPath } from \"gatsby-core-utils/create-require-from-path\"\nimport { join } from \"path\"\nimport { emptyDir, ensureDir, outputJson } from \"fs-extra\"\nimport execa, { Options as ExecaOptions } from \"execa\"\nimport { version as gatsbyVersionFromPackageJson } from \"gatsby/package.json\"\nimport { satisfies } from \"semver\"\nimport type { AdapterInit } from \"./types\"\nimport { preferDefault } from \"../../bootstrap/prefer-default\"\nimport { getLatestAdapters } from \"../get-latest-gatsby-files\"\n\nexport const getAdaptersCacheDir = (): string =>\n join(process.cwd(), `.cache/adapters`)\n\nconst createAdaptersCacheDir = async (): Promise<void> => {\n await ensureDir(getAdaptersCacheDir())\n await emptyDir(getAdaptersCacheDir())\n\n const packageJsonPath = join(getAdaptersCacheDir(), `package.json`)\n\n await outputJson(packageJsonPath, {\n name: `gatsby-adapters`,\n description: `This directory contains adapters that have been automatically installed by Gatsby.`,\n version: `1.0.0`,\n private: true,\n author: `Gatsby`,\n license: `MIT`,\n })\n}\n\ninterface IAdapterToUse {\n name: string\n module: string\n gatsbyVersion: string\n moduleVersion: string\n}\n\nconst tryLoadingAlreadyInstalledAdapter = async ({\n adapterToUse,\n installLocation,\n currentGatsbyVersion,\n}: {\n adapterToUse: IAdapterToUse\n currentGatsbyVersion: string\n installLocation: string\n}): Promise<\n | {\n found: false\n }\n | ({\n found: true\n installedVersion: string\n } & (\n | {\n compatible: false\n incompatibilityReason: string\n }\n | {\n compatible: true\n loadedModule: AdapterInit\n }\n ))\n> => {\n try {\n const locationRequire = createRequireFromPath(\n `${installLocation}/:internal:`\n )\n const adapterPackageJson = locationRequire(\n `${adapterToUse.module}/package.json`\n )\n const adapterPackageVersion = adapterPackageJson?.version\n\n // Check if installed adapter version is compatible with the current Gatsby version based on the manifest\n if (\n !satisfies(adapterPackageVersion, adapterToUse.moduleVersion, {\n includePrerelease: true,\n })\n ) {\n return {\n found: true,\n compatible: false,\n installedVersion: adapterPackageVersion,\n incompatibilityReason: `Used gatsby version \"${currentGatsbyVersion}\" requires \"${adapterToUse.module}@${adapterToUse.moduleVersion}\". Installed \"${adapterToUse.module}\" version: \"${adapterPackageVersion}\".`,\n }\n }\n\n const required = locationRequire.resolve(adapterToUse.module)\n if (required) {\n return {\n found: true,\n compatible: true,\n installedVersion: adapterPackageVersion,\n loadedModule: preferDefault(\n preferDefault(await import(required))\n ) as AdapterInit,\n }\n } else {\n return {\n found: false,\n }\n }\n } catch (e) {\n return {\n found: false,\n }\n }\n}\n\nconst handleAdapterProblem = (\n message: string,\n panicFn = reporter.panic\n): never | undefined => {\n if (!process.env.GATSBY_CONTINUE_BUILD_ON_ADAPTER_MISMATCH) {\n panicFn(\n `${message}\\n\\nZero-configuration deployment failed to avoid potentially broken deployment.\\nIf you want build to continue despite above problems:\\n - configure adapter manually in gatsby-config which will skip zero-configuration deployment attempt\\n - or set GATSBY_CONTINUE_BUILD_ON_MISSING_ADAPTER=true environment variable to continue build without an adapter.`\n )\n } else {\n reporter.warn(\n `${message}\\n\\nContinuing build using without using any adapter due to GATSBY_CONTINUE_BUILD_ON_MISSING_ADAPTER environment variable being set`\n )\n }\n return undefined\n}\n\nexport async function getAdapterInit(\n currentGatsbyVersion: string = gatsbyVersionFromPackageJson\n): Promise<AdapterInit | undefined> {\n // 0. Try to fetch the latest adapters manifest - if it fails, we continue with manifest packaged with current version of gatsby\n const latestAdapters = await getLatestAdapters()\n\n // 1. Find adapter candidates that are compatible with the current environment\n // we find all matching adapters in case package is renamed in the future and future gatsby versions will need different package than previous ones\n const adapterEntry = latestAdapters.find(candidate => candidate.test())\n\n if (!adapterEntry) {\n reporter.verbose(\n `No adapter was found for the current environment. Skipping adapter initialization.`\n )\n return undefined\n }\n\n // 2.From the manifest entry find one that supports current Gatsby version and identify it's version to use\n // First matching one will be used.\n let adapterToUse: IAdapterToUse | undefined = undefined\n\n for (const versionEntry of adapterEntry.versions) {\n if (\n satisfies(currentGatsbyVersion, versionEntry.gatsbyVersion, {\n includePrerelease: true,\n })\n ) {\n adapterToUse = {\n name: adapterEntry.name,\n module: versionEntry.module ?? adapterEntry.module,\n gatsbyVersion: versionEntry.gatsbyVersion,\n moduleVersion: versionEntry.moduleVersion,\n }\n break\n }\n }\n\n if (!adapterToUse) {\n return handleAdapterProblem(\n `No version of ${adapterEntry.name} adapter is compatible with your current Gatsby version ${currentGatsbyVersion}.`\n )\n }\n\n {\n // 3. Check if the user has manually installed the adapter and try to resolve it from there\n const adapterInstalledByUserResults =\n await tryLoadingAlreadyInstalledAdapter({\n adapterToUse,\n installLocation: process.cwd(),\n currentGatsbyVersion,\n })\n if (adapterInstalledByUserResults.found) {\n if (adapterInstalledByUserResults.compatible) {\n reporter.verbose(\n `Using site's adapter dependency \"${adapterToUse.module}@${adapterInstalledByUserResults.installedVersion}\"`\n )\n return adapterInstalledByUserResults.loadedModule\n } else {\n reporter.warn(\n `Ignoring incompatible ${adapterToUse.module}@${adapterInstalledByUserResults.installedVersion} installed by site. ${adapterInstalledByUserResults.incompatibilityReason}`\n )\n }\n }\n }\n\n {\n // 4. Check if a previous run has installed the correct adapter into .cache/adapters already and try to resolve it from there\n const adapterPreviouslyInstalledInCacheAdaptersResults =\n await tryLoadingAlreadyInstalledAdapter({\n adapterToUse,\n installLocation: getAdaptersCacheDir(),\n currentGatsbyVersion,\n })\n\n if (adapterPreviouslyInstalledInCacheAdaptersResults.found) {\n if (adapterPreviouslyInstalledInCacheAdaptersResults.compatible) {\n reporter.verbose(\n `Using previously adapter previously installed by gatsby \"${adapterToUse.module}@${adapterPreviouslyInstalledInCacheAdaptersResults.installedVersion}\"`\n )\n return adapterPreviouslyInstalledInCacheAdaptersResults.loadedModule\n } else {\n reporter.verbose(\n `Ignoring incompatible ${adapterToUse.module} installed by gatsby in \".cache/adapters\" before. ${adapterPreviouslyInstalledInCacheAdaptersResults.incompatibilityReason}`\n )\n }\n }\n }\n\n {\n // 5. If user has not installed the adapter manually or is incompatible and we don't have cached version installed by gatsby or that version is not compatible\n // we try to install compatible version into .cache/adapters\n const installTimer = reporter.activityTimer(\n `Installing ${adapterToUse.name} adapter (${adapterToUse.module}@${adapterToUse.moduleVersion})`\n )\n\n try {\n installTimer.start()\n await createAdaptersCacheDir()\n\n const options: ExecaOptions = {\n stderr: `inherit`,\n cwd: getAdaptersCacheDir(),\n }\n\n const npmAdditionalCliArgs = [\n `--no-progress`,\n `--no-audit`,\n `--no-fund`,\n `--loglevel`,\n `error`,\n `--color`,\n `always`,\n `--legacy-peer-deps`,\n `--save-exact`,\n ]\n\n await execa(\n `npm`,\n [\n `install`,\n ...npmAdditionalCliArgs,\n `${adapterToUse.module}@${adapterToUse.moduleVersion}`,\n ],\n options\n )\n } catch (e) {\n return handleAdapterProblem(\n `Could not install adapter \"${adapterToUse.module}@${adapterToUse.moduleVersion}\". Please install it yourself by adding it to your package.json's dependencies and try building your project again.`,\n installTimer.panic\n )\n }\n\n installTimer.end()\n }\n\n {\n // 5. Try to load again from \".cache/adapters\"\n const adapterAutoInstalledInCacheAdaptersResults =\n await tryLoadingAlreadyInstalledAdapter({\n adapterToUse,\n installLocation: getAdaptersCacheDir(),\n currentGatsbyVersion,\n })\n\n if (adapterAutoInstalledInCacheAdaptersResults.found) {\n if (adapterAutoInstalledInCacheAdaptersResults.compatible) {\n reporter.info(\n `If you plan on staying on this deployment platform, consider installing \"${adapterToUse.module}@${adapterToUse.moduleVersion}\" as a dependency in your project. This will give you faster and more robust installs.`\n )\n return adapterAutoInstalledInCacheAdaptersResults.loadedModule\n } else {\n // this indicates a bug as we install version with range from manifest, and now after trying to load the adapter we consider that adapter incompatible\n return handleAdapterProblem(\n `Auto installed adapter \"${adapterToUse.module}@${adapterAutoInstalledInCacheAdaptersResults.installedVersion}\"`\n )\n }\n } else {\n // this indicates a bug with adapter itself (fail to resolve main entry point) OR the adapter loading logic\n return handleAdapterProblem(\n `Could not load adapter \"${adapterToUse.module}@${adapterToUse.moduleVersion}\". Adapter entry point is not resolvable.`\n )\n }\n }\n}\n"],"mappings":";;;;;;AAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AAEA;AACA;AAEO,MAAMA,mBAAmB,GAAG,MACjC,IAAAC,UAAI,EAACC,OAAO,CAACC,GAAG,EAAE,EAAG,iBAAgB,CAAC;AAAA;AAExC,MAAMC,sBAAsB,GAAG,YAA2B;EACxD,MAAM,IAAAC,kBAAS,EAACL,mBAAmB,EAAE,CAAC;EACtC,MAAM,IAAAM,iBAAQ,EAACN,mBAAmB,EAAE,CAAC;EAErC,MAAMO,eAAe,GAAG,IAAAN,UAAI,EAACD,mBAAmB,EAAE,EAAG,cAAa,CAAC;EAEnE,MAAM,IAAAQ,mBAAU,EAACD,eAAe,EAAE;IAChCE,IAAI,EAAG,iBAAgB;IACvBC,WAAW,EAAG,oFAAmF;IACjGC,OAAO,EAAG,OAAM;IAChBC,OAAO,EAAE,IAAI;IACbC,MAAM,EAAG,QAAO;IAChBC,OAAO,EAAG;EACZ,CAAC,CAAC;AACJ,CAAC;AASD,MAAMC,iCAAiC,GAAG,OAAO;EAC/CC,YAAY;EACZC,eAAe;EACfC;AAKF,CAAC,KAiBI;EACH,IAAI;IACF,MAAMC,eAAe,GAAG,IAAAC,4CAAqB,EAC1C,GAAEH,eAAgB,aAAY,CAChC;IACD,MAAMI,kBAAkB,GAAGF,eAAe,CACvC,GAAEH,YAAY,CAACM,MAAO,eAAc,CACtC;IACD,MAAMC,qBAAqB,GAAGF,kBAAkB,aAAlBA,kBAAkB,uBAAlBA,kBAAkB,CAAEV,OAAO;;IAEzD;IACA,IACE,CAAC,IAAAa,iBAAS,EAACD,qBAAqB,EAAEP,YAAY,CAACS,aAAa,EAAE;MAC5DC,iBAAiB,EAAE;IACrB,CAAC,CAAC,EACF;MACA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CAACM,MAAO,IAAGN,YAAY,CAACS,aAAc,qHAAoH,EACpMkC,YAAY,CAACnB,KAAK,CACnB;IACH;IAEAmB,YAAY,CAACO,GAAG,EAAE;EACpB;EAEA;IACE;IACA,MAAMC,0CAA0C,GAC9C,MAAMpD,iCAAiC,CAAC;MACtCC,YAAY;MACZC,eAAe,EAAEjB,mBAAmB,EAAE;MACtCkB;IACF,CAAC,CAAC;IAEJ,IAAIiD,0CAA0C,CAACxC,KAAK,EAAE;MACpD,IAAIwC,0CAA0C,CAACvC,UAAU,EAAE;QACzDW,iBAAQ,CAAC6B,IAAI,CACV,4EAA2EpD,YAAY,CAACM,MAAO,IAAGN,YAAY,CAACS,aAAc,wFAAuF,CACtN;QACD,OAAO0C,0CAA0C,CAAClC,YAAY;MAChE,CAAC,MAAM;QACL;QACA,OAAOG,oBAAoB,CACxB,2BAA0BpB,YAAY,CAACM,MAAO,IAAG6C,0CAA0C,CAACtC,gBAAiB,GAAE,CACjH;MACH;IACF,CAAC,MAAM;MACL;MACA,OAAOO,oBAAoB,CACxB,2BAA0BpB,YAAY,CAACM,MAAO,IAAGN,YAAY,CAACS,aAAc,2CAA0C,CACxH;IACH;EACF;AACF"}
|
|
@@ -262,5 +262,9 @@ export interface IAdapterManifestEntry {
|
|
|
262
262
|
* Version of the adapter. This is a semver range.
|
|
263
263
|
*/
|
|
264
264
|
moduleVersion: string;
|
|
265
|
+
/**
|
|
266
|
+
* Can override the module defined in the parent manifest entry - useful for when the adapter is renamed.
|
|
267
|
+
*/
|
|
268
|
+
module?: string;
|
|
265
269
|
}>;
|
|
266
270
|
}
|