@vercel/static-build 1.0.36 → 1.0.38

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/index.js CHANGED
@@ -225074,7 +225074,7 @@ exports.injectVercelAnalyticsPlugin = void 0;
225074
225074
  const fs_1 = __webpack_require__(5747);
225075
225075
  const path = __importStar(__webpack_require__(5622));
225076
225076
  const _shared_1 = __webpack_require__(2229);
225077
- const defaultConfig = {
225077
+ const DEFAULT_CONFIG = {
225078
225078
  plugins: [
225079
225079
  {
225080
225080
  resolve: 'gatsby-plugin-vercel',
@@ -225082,26 +225082,77 @@ const defaultConfig = {
225082
225082
  },
225083
225083
  ],
225084
225084
  };
225085
+ const GATSBY_PLUGIN_PACKAGE_NAME = 'gatsby-plugin-vercel';
225086
+ const GATSBY_CONFIG_FILE = 'gatsby-config';
225085
225087
  async function injectVercelAnalyticsPlugin(dir) {
225086
225088
  // Gatsby requires a special variable name for environment variables to be
225087
225089
  // exposed to the client-side JavaScript bundles:
225088
225090
  process.env.GATSBY_VERCEL_ANALYTICS_ID = process.env.VERCEL_ANALYTICS_ID;
225089
- const gatsbyConfigName = 'gatsby-config.js';
225090
- const gatsbyPluginPackageName = 'gatsby-plugin-vercel';
225091
- const gatsbyConfigPath = path.join(dir, gatsbyConfigName);
225092
- console.log(`Injecting Gatsby.js analytics plugin "${gatsbyPluginPackageName}" to \`${gatsbyConfigPath}\``);
225091
+ const gatsbyConfigPathJs = path.join(dir, `${GATSBY_CONFIG_FILE}.js`);
225092
+ const gatsbyConfigPathTs = path.join(dir, `${GATSBY_CONFIG_FILE}.ts`);
225093
+ if (await _shared_1.fileExists(gatsbyConfigPathTs)) {
225094
+ console.log(`Injecting Gatsby.js analytics plugin "${GATSBY_PLUGIN_PACKAGE_NAME}" to \`${gatsbyConfigPathTs}\``);
225095
+ await addGatsbyPackage(dir);
225096
+ return updateGatsbyTsConfig(gatsbyConfigPathTs);
225097
+ }
225098
+ console.log(`Injecting Gatsby.js analytics plugin "${GATSBY_PLUGIN_PACKAGE_NAME}" to \`${gatsbyConfigPathJs}\``);
225099
+ await addGatsbyPackage(dir);
225100
+ if (await _shared_1.fileExists(gatsbyConfigPathJs)) {
225101
+ await updateGatsbyJsConfig(gatsbyConfigPathJs);
225102
+ }
225103
+ else {
225104
+ await fs_1.promises.writeFile(gatsbyConfigPathJs, `module.exports = ${JSON.stringify(DEFAULT_CONFIG)}`);
225105
+ }
225106
+ }
225107
+ exports.injectVercelAnalyticsPlugin = injectVercelAnalyticsPlugin;
225108
+ async function addGatsbyPackage(dir) {
225093
225109
  const pkgJson = (await _shared_1.readPackageJson(dir));
225094
225110
  if (!pkgJson.dependencies) {
225095
225111
  pkgJson.dependencies = {};
225096
225112
  }
225097
- if (!pkgJson.dependencies[gatsbyPluginPackageName]) {
225098
- console.log(`Adding "${gatsbyPluginPackageName}" to \`package.json\` "dependencies"`);
225099
- pkgJson.dependencies[gatsbyPluginPackageName] = 'latest';
225113
+ if (!pkgJson.dependencies[GATSBY_PLUGIN_PACKAGE_NAME]) {
225114
+ console.log(`Adding "${GATSBY_PLUGIN_PACKAGE_NAME}" to \`package.json\` "dependencies"`);
225115
+ pkgJson.dependencies[GATSBY_PLUGIN_PACKAGE_NAME] = 'latest';
225100
225116
  await _shared_1.writePackageJson(dir, pkgJson);
225101
225117
  }
225102
- if (await _shared_1.fileExists(gatsbyConfigPath)) {
225103
- await fs_1.promises.rename(gatsbyConfigPath, gatsbyConfigPath + '.__vercel_builder_backup__.js');
225104
- await fs_1.promises.writeFile(gatsbyConfigPath, `const userConfig = require("./gatsby-config.js.__vercel_builder_backup__.js");
225118
+ }
225119
+ async function updateGatsbyTsConfig(configPath) {
225120
+ await fs_1.promises.rename(configPath, configPath + '.__vercel_builder_backup__.ts');
225121
+ await fs_1.promises.writeFile(configPath, `import userConfig from "./gatsby-config.ts.__vercel_builder_backup__.ts";
225122
+ import type { PluginRef } from "gatsby";
225123
+
225124
+ // https://github.com/gatsbyjs/gatsby/blob/354003fb2908e02ff12109ca3a02978a5a6e608c/packages/gatsby/src/bootstrap/prefer-default.ts
225125
+ const preferDefault = (m: any) => (m && m.default) || m;
225126
+
225127
+ const vercelConfig = Object.assign(
225128
+ {},
225129
+
225130
+ // https://github.com/gatsbyjs/gatsby/blob/a6ecfb2b01d761e8a3612b8ea132c698659923d9/packages/gatsby/src/services/initialize.ts#L113-L117
225131
+ preferDefault(userConfig)
225132
+ );
225133
+ if (!vercelConfig.plugins) {
225134
+ vercelConfig.plugins = [];
225135
+ }
225136
+
225137
+ const hasPlugin = vercelConfig.plugins.find(
225138
+ (p: PluginRef) =>
225139
+ p && (p === "gatsby-plugin-vercel" || p.resolve === "gatsby-plugin-vercel")
225140
+ );
225141
+
225142
+ if (!hasPlugin) {
225143
+ vercelConfig.plugins = vercelConfig.plugins.slice();
225144
+ vercelConfig.plugins.push({
225145
+ resolve: "gatsby-plugin-vercel",
225146
+ options: {},
225147
+ });
225148
+ }
225149
+
225150
+ export default vercelConfig;
225151
+ `);
225152
+ }
225153
+ async function updateGatsbyJsConfig(configPath) {
225154
+ await fs_1.promises.rename(configPath, configPath + '.__vercel_builder_backup__.js');
225155
+ await fs_1.promises.writeFile(configPath, `const userConfig = require("./gatsby-config.js.__vercel_builder_backup__.js");
225105
225156
 
225106
225157
  // https://github.com/gatsbyjs/gatsby/blob/354003fb2908e02ff12109ca3a02978a5a6e608c/packages/gatsby/src/bootstrap/prefer-default.ts
225107
225158
  const preferDefault = m => (m && m.default) || m;
@@ -225130,12 +225181,7 @@ if (!hasPlugin) {
225130
225181
 
225131
225182
  module.exports = vercelConfig;
225132
225183
  `);
225133
- }
225134
- else {
225135
- await fs_1.promises.writeFile(gatsbyConfigPath, `module.exports = ${JSON.stringify(defaultConfig)}`);
225136
- }
225137
225184
  }
225138
- exports.injectVercelAnalyticsPlugin = injectVercelAnalyticsPlugin;
225139
225185
 
225140
225186
 
225141
225187
  /***/ }),
@@ -225150,7 +225196,7 @@ exports.injectVercelAnalyticsPlugin = void 0;
225150
225196
  const path_1 = __webpack_require__(5622);
225151
225197
  const rc9_1 = __webpack_require__(6649);
225152
225198
  const _shared_1 = __webpack_require__(2229);
225153
- // https://github.com/nuxt-community/web-vitals-module
225199
+ // https://github.com/nuxt-modules/web-vitals
225154
225200
  const ANALYTICS_PLUGIN_PACKAGE = '@nuxtjs/web-vitals';
225155
225201
  async function injectVercelAnalyticsPlugin(dir) {
225156
225202
  // First update the `.nuxtrc` file to inject the analytics plugin.
@@ -23,7 +23,7 @@ exports.injectVercelAnalyticsPlugin = void 0;
23
23
  const fs_1 = require("fs");
24
24
  const path = __importStar(require("path"));
25
25
  const _shared_1 = require("./_shared");
26
- const defaultConfig = {
26
+ const DEFAULT_CONFIG = {
27
27
  plugins: [
28
28
  {
29
29
  resolve: 'gatsby-plugin-vercel',
@@ -31,26 +31,77 @@ const defaultConfig = {
31
31
  },
32
32
  ],
33
33
  };
34
+ const GATSBY_PLUGIN_PACKAGE_NAME = 'gatsby-plugin-vercel';
35
+ const GATSBY_CONFIG_FILE = 'gatsby-config';
34
36
  async function injectVercelAnalyticsPlugin(dir) {
35
37
  // Gatsby requires a special variable name for environment variables to be
36
38
  // exposed to the client-side JavaScript bundles:
37
39
  process.env.GATSBY_VERCEL_ANALYTICS_ID = process.env.VERCEL_ANALYTICS_ID;
38
- const gatsbyConfigName = 'gatsby-config.js';
39
- const gatsbyPluginPackageName = 'gatsby-plugin-vercel';
40
- const gatsbyConfigPath = path.join(dir, gatsbyConfigName);
41
- console.log(`Injecting Gatsby.js analytics plugin "${gatsbyPluginPackageName}" to \`${gatsbyConfigPath}\``);
40
+ const gatsbyConfigPathJs = path.join(dir, `${GATSBY_CONFIG_FILE}.js`);
41
+ const gatsbyConfigPathTs = path.join(dir, `${GATSBY_CONFIG_FILE}.ts`);
42
+ if (await _shared_1.fileExists(gatsbyConfigPathTs)) {
43
+ console.log(`Injecting Gatsby.js analytics plugin "${GATSBY_PLUGIN_PACKAGE_NAME}" to \`${gatsbyConfigPathTs}\``);
44
+ await addGatsbyPackage(dir);
45
+ return updateGatsbyTsConfig(gatsbyConfigPathTs);
46
+ }
47
+ console.log(`Injecting Gatsby.js analytics plugin "${GATSBY_PLUGIN_PACKAGE_NAME}" to \`${gatsbyConfigPathJs}\``);
48
+ await addGatsbyPackage(dir);
49
+ if (await _shared_1.fileExists(gatsbyConfigPathJs)) {
50
+ await updateGatsbyJsConfig(gatsbyConfigPathJs);
51
+ }
52
+ else {
53
+ await fs_1.promises.writeFile(gatsbyConfigPathJs, `module.exports = ${JSON.stringify(DEFAULT_CONFIG)}`);
54
+ }
55
+ }
56
+ exports.injectVercelAnalyticsPlugin = injectVercelAnalyticsPlugin;
57
+ async function addGatsbyPackage(dir) {
42
58
  const pkgJson = (await _shared_1.readPackageJson(dir));
43
59
  if (!pkgJson.dependencies) {
44
60
  pkgJson.dependencies = {};
45
61
  }
46
- if (!pkgJson.dependencies[gatsbyPluginPackageName]) {
47
- console.log(`Adding "${gatsbyPluginPackageName}" to \`package.json\` "dependencies"`);
48
- pkgJson.dependencies[gatsbyPluginPackageName] = 'latest';
62
+ if (!pkgJson.dependencies[GATSBY_PLUGIN_PACKAGE_NAME]) {
63
+ console.log(`Adding "${GATSBY_PLUGIN_PACKAGE_NAME}" to \`package.json\` "dependencies"`);
64
+ pkgJson.dependencies[GATSBY_PLUGIN_PACKAGE_NAME] = 'latest';
49
65
  await _shared_1.writePackageJson(dir, pkgJson);
50
66
  }
51
- if (await _shared_1.fileExists(gatsbyConfigPath)) {
52
- await fs_1.promises.rename(gatsbyConfigPath, gatsbyConfigPath + '.__vercel_builder_backup__.js');
53
- await fs_1.promises.writeFile(gatsbyConfigPath, `const userConfig = require("./gatsby-config.js.__vercel_builder_backup__.js");
67
+ }
68
+ async function updateGatsbyTsConfig(configPath) {
69
+ await fs_1.promises.rename(configPath, configPath + '.__vercel_builder_backup__.ts');
70
+ await fs_1.promises.writeFile(configPath, `import userConfig from "./gatsby-config.ts.__vercel_builder_backup__.ts";
71
+ import type { PluginRef } from "gatsby";
72
+
73
+ // https://github.com/gatsbyjs/gatsby/blob/354003fb2908e02ff12109ca3a02978a5a6e608c/packages/gatsby/src/bootstrap/prefer-default.ts
74
+ const preferDefault = (m: any) => (m && m.default) || m;
75
+
76
+ const vercelConfig = Object.assign(
77
+ {},
78
+
79
+ // https://github.com/gatsbyjs/gatsby/blob/a6ecfb2b01d761e8a3612b8ea132c698659923d9/packages/gatsby/src/services/initialize.ts#L113-L117
80
+ preferDefault(userConfig)
81
+ );
82
+ if (!vercelConfig.plugins) {
83
+ vercelConfig.plugins = [];
84
+ }
85
+
86
+ const hasPlugin = vercelConfig.plugins.find(
87
+ (p: PluginRef) =>
88
+ p && (p === "gatsby-plugin-vercel" || p.resolve === "gatsby-plugin-vercel")
89
+ );
90
+
91
+ if (!hasPlugin) {
92
+ vercelConfig.plugins = vercelConfig.plugins.slice();
93
+ vercelConfig.plugins.push({
94
+ resolve: "gatsby-plugin-vercel",
95
+ options: {},
96
+ });
97
+ }
98
+
99
+ export default vercelConfig;
100
+ `);
101
+ }
102
+ async function updateGatsbyJsConfig(configPath) {
103
+ await fs_1.promises.rename(configPath, configPath + '.__vercel_builder_backup__.js');
104
+ await fs_1.promises.writeFile(configPath, `const userConfig = require("./gatsby-config.js.__vercel_builder_backup__.js");
54
105
 
55
106
  // https://github.com/gatsbyjs/gatsby/blob/354003fb2908e02ff12109ca3a02978a5a6e608c/packages/gatsby/src/bootstrap/prefer-default.ts
56
107
  const preferDefault = m => (m && m.default) || m;
@@ -79,9 +130,4 @@ if (!hasPlugin) {
79
130
 
80
131
  module.exports = vercelConfig;
81
132
  `);
82
- }
83
- else {
84
- await fs_1.promises.writeFile(gatsbyConfigPath, `module.exports = ${JSON.stringify(defaultConfig)}`);
85
- }
86
133
  }
87
- exports.injectVercelAnalyticsPlugin = injectVercelAnalyticsPlugin;
@@ -4,7 +4,7 @@ exports.injectVercelAnalyticsPlugin = void 0;
4
4
  const path_1 = require("path");
5
5
  const rc9_1 = require("rc9");
6
6
  const _shared_1 = require("./_shared");
7
- // https://github.com/nuxt-community/web-vitals-module
7
+ // https://github.com/nuxt-modules/web-vitals
8
8
  const ANALYTICS_PLUGIN_PACKAGE = '@nuxtjs/web-vitals';
9
9
  async function injectVercelAnalyticsPlugin(dir) {
10
10
  // First update the `.nuxtrc` file to inject the analytics plugin.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/static-build",
3
- "version": "1.0.36",
3
+ "version": "1.0.38",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/build-step",
@@ -36,7 +36,7 @@
36
36
  "@types/ms": "0.7.31",
37
37
  "@types/node-fetch": "2.5.4",
38
38
  "@types/promise-timeout": "1.3.0",
39
- "@vercel/build-utils": "5.5.7",
39
+ "@vercel/build-utils": "5.5.8",
40
40
  "@vercel/frameworks": "1.1.12",
41
41
  "@vercel/ncc": "0.24.0",
42
42
  "@vercel/routing-utils": "2.1.3",
@@ -49,5 +49,5 @@
49
49
  "rc9": "1.2.0",
50
50
  "typescript": "4.3.4"
51
51
  },
52
- "gitHead": "1b211f28dfdcb112f1aecb53a2b9f257ecc58420"
52
+ "gitHead": "4159b498b93cc340ee483beb5dd1ef18dc762408"
53
53
  }