@vercel/static-build 1.2.0 → 1.2.1

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
@@ -237508,6 +237508,11 @@ exports.frameworks = [
237508
237508
  headers: { 'cache-control': 'public, max-age=31536000, immutable' },
237509
237509
  continue: true,
237510
237510
  },
237511
+ {
237512
+ src: '^/_astro/(.*)$',
237513
+ headers: { 'cache-control': 'public, max-age=31536000, immutable' },
237514
+ continue: true,
237515
+ },
237511
237516
  ],
237512
237517
  },
237513
237518
  {
@@ -242532,59 +242537,48 @@ exports.injectPlugins = void 0;
242532
242537
  const fs_1 = __webpack_require__(5747);
242533
242538
  const path = __importStar(__webpack_require__(5622));
242534
242539
  const semver_1 = __importDefault(__webpack_require__(7013));
242540
+ const url_1 = __webpack_require__(8835);
242535
242541
  const _shared_1 = __webpack_require__(54);
242536
- const PLUGINS = {
242537
- GATSBY_PLUGIN_VERCEL_ANALYTICS: '@vercel/gatsby-plugin-vercel-analytics',
242538
- GATSBY_PLUGIN_VERCEL_BUILDER: '@vercel/gatsby-plugin-vercel-builder',
242539
- };
242542
+ const { VERCEL_CLI_VERSION } = process.env;
242543
+ const PLUGINS = [
242544
+ '@vercel/gatsby-plugin-vercel-analytics',
242545
+ '@vercel/gatsby-plugin-vercel-builder',
242546
+ ];
242540
242547
  const GATSBY_CONFIG_FILE = 'gatsby-config';
242548
+ const GATSBY_NODE_FILE = 'gatsby-node';
242541
242549
  async function injectPlugins(detectedVersion, dir) {
242542
- const pluginsToInject = [];
242550
+ const plugins = new Set();
242543
242551
  if (process.env.VERCEL_GATSBY_BUILDER_PLUGIN && detectedVersion) {
242544
242552
  const version = semver_1.default.coerce(detectedVersion);
242545
242553
  if (version && semver_1.default.satisfies(version, '>=4.0.0')) {
242546
- pluginsToInject.push(PLUGINS.GATSBY_PLUGIN_VERCEL_BUILDER);
242554
+ plugins.add('@vercel/gatsby-plugin-vercel-builder');
242547
242555
  }
242548
242556
  }
242549
242557
  if (process.env.VERCEL_ANALYTICS_ID) {
242550
242558
  process.env.GATSBY_VERCEL_ANALYTICS_ID = process.env.VERCEL_ANALYTICS_ID;
242551
- pluginsToInject.push(PLUGINS.GATSBY_PLUGIN_VERCEL_ANALYTICS);
242559
+ plugins.add('@vercel/gatsby-plugin-vercel-analytics');
242552
242560
  }
242553
- if (pluginsToInject.length === 0) {
242561
+ if (plugins.size === 0) {
242554
242562
  return false;
242555
242563
  }
242556
- await addGatsbyPackage(dir, pluginsToInject);
242557
- const gatsbyConfigPathTs = path.join(dir, `${GATSBY_CONFIG_FILE}.ts`);
242558
- const gatsbyConfigPathMjs = path.join(dir, `${GATSBY_CONFIG_FILE}.mjs`);
242559
- const gatsbyConfigPathJs = path.join(dir, `${GATSBY_CONFIG_FILE}.js`);
242560
- if (await _shared_1.fileExists(gatsbyConfigPathTs)) {
242561
- printInjectingPlugins(pluginsToInject, gatsbyConfigPathTs);
242562
- await updateGatsbyTsConfig(gatsbyConfigPathTs, pluginsToInject);
242563
- }
242564
- else if (await _shared_1.fileExists(gatsbyConfigPathMjs)) {
242565
- printInjectingPlugins(pluginsToInject, gatsbyConfigPathMjs);
242566
- await updateGatsbyMjsConfig(gatsbyConfigPathMjs, pluginsToInject);
242564
+ const ops = [addGatsbyPackage(dir, plugins)];
242565
+ if (plugins.has('@vercel/gatsby-plugin-vercel-analytics')) {
242566
+ ops.push(updateGatsbyConfig(dir, ['@vercel/gatsby-plugin-vercel-analytics']));
242567
242567
  }
242568
- else {
242569
- printInjectingPlugins(pluginsToInject, gatsbyConfigPathJs);
242570
- if (await _shared_1.fileExists(gatsbyConfigPathJs)) {
242571
- await updateGatsbyJsConfig(gatsbyConfigPathJs, pluginsToInject);
242572
- }
242573
- else {
242574
- await fs_1.promises.writeFile(gatsbyConfigPathJs, `module.exports = ${JSON.stringify({
242575
- plugins: pluginsToInject,
242576
- })}`);
242577
- }
242568
+ if (plugins.has('@vercel/gatsby-plugin-vercel-builder')) {
242569
+ ops.push(updateGatsbyNode(dir));
242578
242570
  }
242571
+ await Promise.all(ops);
242579
242572
  return true;
242580
242573
  }
242581
242574
  exports.injectPlugins = injectPlugins;
242582
242575
  function printInjectingPlugins(plugins, configPath) {
242576
+ const pluginsArray = Array.from(plugins);
242583
242577
  let pluginsStr = 'plugin';
242584
- if (plugins.length > 1) {
242578
+ if (pluginsArray.length > 1) {
242585
242579
  pluginsStr += 's';
242586
242580
  }
242587
- console.log(`Injecting Gatsby.js ${pluginsStr} ${plugins
242581
+ console.log(`Injecting Gatsby.js ${pluginsStr} ${pluginsArray
242588
242582
  .map(p => `"${p}"`)
242589
242583
  .join(', ')} to \`${configPath}\``);
242590
242584
  }
@@ -242596,22 +242590,52 @@ async function addGatsbyPackage(dir, plugins) {
242596
242590
  for (const plugin of plugins) {
242597
242591
  if (!pkgJson.dependencies[plugin]) {
242598
242592
  console.log(`Adding "${plugin}" to \`package.json\` "dependencies"`);
242599
- pkgJson.dependencies[plugin] = 'latest';
242593
+ let version = 'latest';
242594
+ // Use the tarball URL for E2E tests
242595
+ if (VERCEL_CLI_VERSION?.startsWith('https://')) {
242596
+ version = new url_1.URL(`./${plugin}.tgz`, VERCEL_CLI_VERSION).href;
242597
+ }
242598
+ pkgJson.dependencies[plugin] = version;
242600
242599
  }
242601
242600
  }
242602
242601
  await _shared_1.writePackageJson(dir, pkgJson);
242603
242602
  }
242604
- async function updateGatsbyTsConfig(configPath, plugins) {
242605
- await fs_1.promises.rename(configPath, configPath + '.__vercel_builder_backup__.ts');
242603
+ async function updateGatsbyConfig(dir, plugins) {
242604
+ const gatsbyConfigPathTs = path.join(dir, `${GATSBY_CONFIG_FILE}.ts`);
242605
+ const gatsbyConfigPathMjs = path.join(dir, `${GATSBY_CONFIG_FILE}.mjs`);
242606
+ const gatsbyConfigPathJs = path.join(dir, `${GATSBY_CONFIG_FILE}.js`);
242607
+ if (await _shared_1.fileExists(gatsbyConfigPathTs)) {
242608
+ printInjectingPlugins(plugins, gatsbyConfigPathTs);
242609
+ await updateGatsbyConfigTs(gatsbyConfigPathTs, plugins);
242610
+ }
242611
+ else if (await _shared_1.fileExists(gatsbyConfigPathMjs)) {
242612
+ printInjectingPlugins(plugins, gatsbyConfigPathMjs);
242613
+ await updateGatsbyConfigMjs(gatsbyConfigPathMjs, plugins);
242614
+ }
242615
+ else {
242616
+ printInjectingPlugins(plugins, gatsbyConfigPathJs);
242617
+ if (await _shared_1.fileExists(gatsbyConfigPathJs)) {
242618
+ await updateGatsbyConfigJs(gatsbyConfigPathJs, plugins);
242619
+ }
242620
+ else {
242621
+ await fs_1.promises.writeFile(gatsbyConfigPathJs, `module.exports = ${JSON.stringify({
242622
+ plugins: Array.from(plugins),
242623
+ })}`);
242624
+ }
242625
+ }
242626
+ }
242627
+ async function updateGatsbyConfigTs(configPath, plugins) {
242628
+ const renamedPath = `${configPath}.__vercel_builder_backup__.ts`;
242629
+ if (!(await _shared_1.fileExists(renamedPath))) {
242630
+ await fs_1.promises.rename(configPath, renamedPath);
242631
+ }
242606
242632
  await fs_1.promises.writeFile(configPath, `import userConfig from "./gatsby-config.ts.__vercel_builder_backup__.ts";
242607
242633
  import type { PluginRef } from "gatsby";
242608
242634
 
242609
- // https://github.com/gatsbyjs/gatsby/blob/354003fb2908e02ff12109ca3a02978a5a6e608c/packages/gatsby/src/bootstrap/prefer-default.ts
242610
242635
  const preferDefault = (m: any) => (m && m.default) || m;
242611
242636
 
242612
242637
  const vercelConfig = Object.assign(
242613
242638
  {},
242614
- // https://github.com/gatsbyjs/gatsby/blob/a6ecfb2b01d761e8a3612b8ea132c698659923d9/packages/gatsby/src/services/initialize.ts#L113-L117
242615
242639
  preferDefault(userConfig)
242616
242640
  );
242617
242641
 
@@ -242619,7 +242643,7 @@ if (!vercelConfig.plugins) {
242619
242643
  vercelConfig.plugins = [];
242620
242644
  }
242621
242645
 
242622
- for (const plugin of ${JSON.stringify(plugins)}) {
242646
+ for (const plugin of ${JSON.stringify(Array.from(plugins))}) {
242623
242647
  const hasPlugin = vercelConfig.plugins.find(
242624
242648
  (p: PluginRef) =>
242625
242649
  p && (p === plugin || p.resolve === plugin)
@@ -242634,23 +242658,24 @@ for (const plugin of ${JSON.stringify(plugins)}) {
242634
242658
  export default vercelConfig;
242635
242659
  `);
242636
242660
  }
242637
- async function updateGatsbyMjsConfig(configPath, plugins) {
242638
- await fs_1.promises.rename(configPath, configPath + '.__vercel_builder_backup__.mjs');
242661
+ async function updateGatsbyConfigMjs(configPath, plugins) {
242662
+ const renamedPath = `${configPath}.__vercel_builder_backup__.mjs`;
242663
+ if (!(await _shared_1.fileExists(renamedPath))) {
242664
+ await fs_1.promises.rename(configPath, renamedPath);
242665
+ }
242639
242666
  await fs_1.promises.writeFile(configPath, `import userConfig from "./gatsby-config.mjs.__vercel_builder_backup__.mjs";
242640
242667
 
242641
- // https://github.com/gatsbyjs/gatsby/blob/354003fb2908e02ff12109ca3a02978a5a6e608c/packages/gatsby/src/bootstrap/prefer-default.ts
242642
242668
  const preferDefault = (m) => (m && m.default) || m;
242643
242669
 
242644
242670
  const vercelConfig = Object.assign(
242645
242671
  {},
242646
- // https://github.com/gatsbyjs/gatsby/blob/a6ecfb2b01d761e8a3612b8ea132c698659923d9/packages/gatsby/src/services/initialize.ts#L113-L117
242647
242672
  preferDefault(userConfig)
242648
242673
  );
242649
242674
  if (!vercelConfig.plugins) {
242650
242675
  vercelConfig.plugins = [];
242651
242676
  }
242652
242677
 
242653
- for (const plugin of ${JSON.stringify(plugins)}) {
242678
+ for (const plugin of ${JSON.stringify(Array.from(plugins))}) {
242654
242679
  const hasPlugin = vercelConfig.plugins.find(
242655
242680
  (p) => p && (p === plugin || p.resolve === plugin)
242656
242681
  );
@@ -242664,23 +242689,24 @@ for (const plugin of ${JSON.stringify(plugins)}) {
242664
242689
  export default vercelConfig;
242665
242690
  `);
242666
242691
  }
242667
- async function updateGatsbyJsConfig(configPath, plugins) {
242668
- await fs_1.promises.rename(configPath, configPath + '.__vercel_builder_backup__.js');
242692
+ async function updateGatsbyConfigJs(configPath, plugins) {
242693
+ const renamedPath = `${configPath}.__vercel_builder_backup__.js`;
242694
+ if (!(await _shared_1.fileExists(renamedPath))) {
242695
+ await fs_1.promises.rename(configPath, renamedPath);
242696
+ }
242669
242697
  await fs_1.promises.writeFile(configPath, `const userConfig = require("./gatsby-config.js.__vercel_builder_backup__.js");
242670
242698
 
242671
- // https://github.com/gatsbyjs/gatsby/blob/354003fb2908e02ff12109ca3a02978a5a6e608c/packages/gatsby/src/bootstrap/prefer-default.ts
242672
242699
  const preferDefault = m => (m && m.default) || m;
242673
242700
 
242674
242701
  const vercelConfig = Object.assign(
242675
242702
  {},
242676
- // https://github.com/gatsbyjs/gatsby/blob/a6ecfb2b01d761e8a3612b8ea132c698659923d9/packages/gatsby/src/services/initialize.ts#L113-L117
242677
242703
  preferDefault(userConfig)
242678
242704
  );
242679
242705
  if (!vercelConfig.plugins) {
242680
242706
  vercelConfig.plugins = [];
242681
242707
  }
242682
242708
 
242683
- for (const plugin of ${JSON.stringify(plugins)}) {
242709
+ for (const plugin of ${JSON.stringify(Array.from(plugins))}) {
242684
242710
  const hasPlugin = vercelConfig.plugins.find(
242685
242711
  (p) => p && (p === plugin || p.resolve === plugin)
242686
242712
  );
@@ -242693,6 +242719,80 @@ for (const plugin of ${JSON.stringify(plugins)}) {
242693
242719
  module.exports = vercelConfig;
242694
242720
  `);
242695
242721
  }
242722
+ async function updateGatsbyNode(dir) {
242723
+ const gatsbyNodePathTs = path.join(dir, `${GATSBY_NODE_FILE}.ts`);
242724
+ const gatsbyNodePathMjs = path.join(dir, `${GATSBY_NODE_FILE}.mjs`);
242725
+ const gatsbyNodePathJs = path.join(dir, `${GATSBY_NODE_FILE}.js`);
242726
+ if (await _shared_1.fileExists(gatsbyNodePathTs)) {
242727
+ await updateGatsbyNodeTs(gatsbyNodePathTs);
242728
+ }
242729
+ else if (await _shared_1.fileExists(gatsbyNodePathMjs)) {
242730
+ await updateGatsbyNodeMjs(gatsbyNodePathMjs);
242731
+ }
242732
+ else if (await _shared_1.fileExists(gatsbyNodePathJs)) {
242733
+ await updateGatsbyNodeJs(gatsbyNodePathJs);
242734
+ }
242735
+ else {
242736
+ await fs_1.promises.writeFile(gatsbyNodePathJs, `module.exports = require('@vercel/gatsby-plugin-vercel-builder/gatsby-node.js');`);
242737
+ }
242738
+ }
242739
+ async function updateGatsbyNodeTs(configPath) {
242740
+ const renamedPath = `${configPath}.__vercel_builder_backup__.ts`;
242741
+ if (!(await _shared_1.fileExists(renamedPath))) {
242742
+ await fs_1.promises.rename(configPath, renamedPath);
242743
+ }
242744
+ await fs_1.promises.writeFile(configPath, `import type { GatsbyNode } from 'gatsby';
242745
+ import * as vercelBuilder from '@vercel/gatsby-plugin-vercel-builder/gatsby-node.js';
242746
+ import * as gatsbyNode from './gatsby-node.ts.__vercel_builder_backup__.ts';
242747
+
242748
+ export * from './gatsby-node.ts.__vercel_builder_backup__.ts';
242749
+
242750
+ export const onPostBuild: GatsbyNode['onPostBuild'] = async (args, options) => {
242751
+ if (typeof (gatsbyNode as any).onPostBuild === 'function') {
242752
+ await (gatsbyNode as any).onPostBuild(args, options);
242753
+ }
242754
+ await vercelBuilder.onPostBuild(args, options);
242755
+ };
242756
+ `);
242757
+ }
242758
+ async function updateGatsbyNodeMjs(configPath) {
242759
+ const renamedPath = `${configPath}.__vercel_builder_backup__.mjs`;
242760
+ if (!(await _shared_1.fileExists(renamedPath))) {
242761
+ await fs_1.promises.rename(configPath, renamedPath);
242762
+ }
242763
+ await fs_1.promises.writeFile(configPath, `import * as vercelBuilder from '@vercel/gatsby-plugin-vercel-builder/gatsby-node.js';
242764
+ import * as gatsbyNode from './gatsby-node.mjs.__vercel_builder_backup__.mjs';
242765
+
242766
+ export * from './gatsby-node.mjs.__vercel_builder_backup__.mjs';
242767
+
242768
+ export const onPostBuild = async (args, options) => {
242769
+ if (typeof gatsbyNode.onPostBuild === 'function') {
242770
+ await gatsbyNode.onPostBuild(args, options);
242771
+ }
242772
+ await vercelBuilder.onPostBuild(args, options);
242773
+ };
242774
+ `);
242775
+ }
242776
+ async function updateGatsbyNodeJs(configPath) {
242777
+ const renamedPath = `${configPath}.__vercel_builder_backup__.js`;
242778
+ if (!(await _shared_1.fileExists(renamedPath))) {
242779
+ await fs_1.promises.rename(configPath, renamedPath);
242780
+ }
242781
+ await fs_1.promises.writeFile(configPath, `const vercelBuilder = require('@vercel/gatsby-plugin-vercel-builder/gatsby-node.js');
242782
+ const gatsbyNode = require('./gatsby-node.js.__vercel_builder_backup__.js');
242783
+
242784
+ const origOnPostBuild = gatsbyNode.onPostBuild;
242785
+
242786
+ gatsbyNode.onPostBuild = async (args, options) => {
242787
+ if (typeof origOnPostBuild === 'function') {
242788
+ await origOnPostBuild(args, options);
242789
+ }
242790
+ await vercelBuilder.onPostBuild(args, options);
242791
+ };
242792
+
242793
+ module.exports = gatsbyNode;
242794
+ `);
242795
+ }
242696
242796
 
242697
242797
 
242698
242798
  /***/ }),
@@ -26,59 +26,48 @@ exports.injectPlugins = void 0;
26
26
  const fs_1 = require("fs");
27
27
  const path = __importStar(require("path"));
28
28
  const semver_1 = __importDefault(require("semver"));
29
+ const url_1 = require("url");
29
30
  const _shared_1 = require("./_shared");
30
- const PLUGINS = {
31
- GATSBY_PLUGIN_VERCEL_ANALYTICS: '@vercel/gatsby-plugin-vercel-analytics',
32
- GATSBY_PLUGIN_VERCEL_BUILDER: '@vercel/gatsby-plugin-vercel-builder',
33
- };
31
+ const { VERCEL_CLI_VERSION } = process.env;
32
+ const PLUGINS = [
33
+ '@vercel/gatsby-plugin-vercel-analytics',
34
+ '@vercel/gatsby-plugin-vercel-builder',
35
+ ];
34
36
  const GATSBY_CONFIG_FILE = 'gatsby-config';
37
+ const GATSBY_NODE_FILE = 'gatsby-node';
35
38
  async function injectPlugins(detectedVersion, dir) {
36
- const pluginsToInject = [];
39
+ const plugins = new Set();
37
40
  if (process.env.VERCEL_GATSBY_BUILDER_PLUGIN && detectedVersion) {
38
41
  const version = semver_1.default.coerce(detectedVersion);
39
42
  if (version && semver_1.default.satisfies(version, '>=4.0.0')) {
40
- pluginsToInject.push(PLUGINS.GATSBY_PLUGIN_VERCEL_BUILDER);
43
+ plugins.add('@vercel/gatsby-plugin-vercel-builder');
41
44
  }
42
45
  }
43
46
  if (process.env.VERCEL_ANALYTICS_ID) {
44
47
  process.env.GATSBY_VERCEL_ANALYTICS_ID = process.env.VERCEL_ANALYTICS_ID;
45
- pluginsToInject.push(PLUGINS.GATSBY_PLUGIN_VERCEL_ANALYTICS);
48
+ plugins.add('@vercel/gatsby-plugin-vercel-analytics');
46
49
  }
47
- if (pluginsToInject.length === 0) {
50
+ if (plugins.size === 0) {
48
51
  return false;
49
52
  }
50
- await addGatsbyPackage(dir, pluginsToInject);
51
- const gatsbyConfigPathTs = path.join(dir, `${GATSBY_CONFIG_FILE}.ts`);
52
- const gatsbyConfigPathMjs = path.join(dir, `${GATSBY_CONFIG_FILE}.mjs`);
53
- const gatsbyConfigPathJs = path.join(dir, `${GATSBY_CONFIG_FILE}.js`);
54
- if (await _shared_1.fileExists(gatsbyConfigPathTs)) {
55
- printInjectingPlugins(pluginsToInject, gatsbyConfigPathTs);
56
- await updateGatsbyTsConfig(gatsbyConfigPathTs, pluginsToInject);
57
- }
58
- else if (await _shared_1.fileExists(gatsbyConfigPathMjs)) {
59
- printInjectingPlugins(pluginsToInject, gatsbyConfigPathMjs);
60
- await updateGatsbyMjsConfig(gatsbyConfigPathMjs, pluginsToInject);
53
+ const ops = [addGatsbyPackage(dir, plugins)];
54
+ if (plugins.has('@vercel/gatsby-plugin-vercel-analytics')) {
55
+ ops.push(updateGatsbyConfig(dir, ['@vercel/gatsby-plugin-vercel-analytics']));
61
56
  }
62
- else {
63
- printInjectingPlugins(pluginsToInject, gatsbyConfigPathJs);
64
- if (await _shared_1.fileExists(gatsbyConfigPathJs)) {
65
- await updateGatsbyJsConfig(gatsbyConfigPathJs, pluginsToInject);
66
- }
67
- else {
68
- await fs_1.promises.writeFile(gatsbyConfigPathJs, `module.exports = ${JSON.stringify({
69
- plugins: pluginsToInject,
70
- })}`);
71
- }
57
+ if (plugins.has('@vercel/gatsby-plugin-vercel-builder')) {
58
+ ops.push(updateGatsbyNode(dir));
72
59
  }
60
+ await Promise.all(ops);
73
61
  return true;
74
62
  }
75
63
  exports.injectPlugins = injectPlugins;
76
64
  function printInjectingPlugins(plugins, configPath) {
65
+ const pluginsArray = Array.from(plugins);
77
66
  let pluginsStr = 'plugin';
78
- if (plugins.length > 1) {
67
+ if (pluginsArray.length > 1) {
79
68
  pluginsStr += 's';
80
69
  }
81
- console.log(`Injecting Gatsby.js ${pluginsStr} ${plugins
70
+ console.log(`Injecting Gatsby.js ${pluginsStr} ${pluginsArray
82
71
  .map(p => `"${p}"`)
83
72
  .join(', ')} to \`${configPath}\``);
84
73
  }
@@ -90,22 +79,52 @@ async function addGatsbyPackage(dir, plugins) {
90
79
  for (const plugin of plugins) {
91
80
  if (!pkgJson.dependencies[plugin]) {
92
81
  console.log(`Adding "${plugin}" to \`package.json\` "dependencies"`);
93
- pkgJson.dependencies[plugin] = 'latest';
82
+ let version = 'latest';
83
+ // Use the tarball URL for E2E tests
84
+ if (VERCEL_CLI_VERSION?.startsWith('https://')) {
85
+ version = new url_1.URL(`./${plugin}.tgz`, VERCEL_CLI_VERSION).href;
86
+ }
87
+ pkgJson.dependencies[plugin] = version;
94
88
  }
95
89
  }
96
90
  await _shared_1.writePackageJson(dir, pkgJson);
97
91
  }
98
- async function updateGatsbyTsConfig(configPath, plugins) {
99
- await fs_1.promises.rename(configPath, configPath + '.__vercel_builder_backup__.ts');
92
+ async function updateGatsbyConfig(dir, plugins) {
93
+ const gatsbyConfigPathTs = path.join(dir, `${GATSBY_CONFIG_FILE}.ts`);
94
+ const gatsbyConfigPathMjs = path.join(dir, `${GATSBY_CONFIG_FILE}.mjs`);
95
+ const gatsbyConfigPathJs = path.join(dir, `${GATSBY_CONFIG_FILE}.js`);
96
+ if (await _shared_1.fileExists(gatsbyConfigPathTs)) {
97
+ printInjectingPlugins(plugins, gatsbyConfigPathTs);
98
+ await updateGatsbyConfigTs(gatsbyConfigPathTs, plugins);
99
+ }
100
+ else if (await _shared_1.fileExists(gatsbyConfigPathMjs)) {
101
+ printInjectingPlugins(plugins, gatsbyConfigPathMjs);
102
+ await updateGatsbyConfigMjs(gatsbyConfigPathMjs, plugins);
103
+ }
104
+ else {
105
+ printInjectingPlugins(plugins, gatsbyConfigPathJs);
106
+ if (await _shared_1.fileExists(gatsbyConfigPathJs)) {
107
+ await updateGatsbyConfigJs(gatsbyConfigPathJs, plugins);
108
+ }
109
+ else {
110
+ await fs_1.promises.writeFile(gatsbyConfigPathJs, `module.exports = ${JSON.stringify({
111
+ plugins: Array.from(plugins),
112
+ })}`);
113
+ }
114
+ }
115
+ }
116
+ async function updateGatsbyConfigTs(configPath, plugins) {
117
+ const renamedPath = `${configPath}.__vercel_builder_backup__.ts`;
118
+ if (!(await _shared_1.fileExists(renamedPath))) {
119
+ await fs_1.promises.rename(configPath, renamedPath);
120
+ }
100
121
  await fs_1.promises.writeFile(configPath, `import userConfig from "./gatsby-config.ts.__vercel_builder_backup__.ts";
101
122
  import type { PluginRef } from "gatsby";
102
123
 
103
- // https://github.com/gatsbyjs/gatsby/blob/354003fb2908e02ff12109ca3a02978a5a6e608c/packages/gatsby/src/bootstrap/prefer-default.ts
104
124
  const preferDefault = (m: any) => (m && m.default) || m;
105
125
 
106
126
  const vercelConfig = Object.assign(
107
127
  {},
108
- // https://github.com/gatsbyjs/gatsby/blob/a6ecfb2b01d761e8a3612b8ea132c698659923d9/packages/gatsby/src/services/initialize.ts#L113-L117
109
128
  preferDefault(userConfig)
110
129
  );
111
130
 
@@ -113,7 +132,7 @@ if (!vercelConfig.plugins) {
113
132
  vercelConfig.plugins = [];
114
133
  }
115
134
 
116
- for (const plugin of ${JSON.stringify(plugins)}) {
135
+ for (const plugin of ${JSON.stringify(Array.from(plugins))}) {
117
136
  const hasPlugin = vercelConfig.plugins.find(
118
137
  (p: PluginRef) =>
119
138
  p && (p === plugin || p.resolve === plugin)
@@ -128,23 +147,24 @@ for (const plugin of ${JSON.stringify(plugins)}) {
128
147
  export default vercelConfig;
129
148
  `);
130
149
  }
131
- async function updateGatsbyMjsConfig(configPath, plugins) {
132
- await fs_1.promises.rename(configPath, configPath + '.__vercel_builder_backup__.mjs');
150
+ async function updateGatsbyConfigMjs(configPath, plugins) {
151
+ const renamedPath = `${configPath}.__vercel_builder_backup__.mjs`;
152
+ if (!(await _shared_1.fileExists(renamedPath))) {
153
+ await fs_1.promises.rename(configPath, renamedPath);
154
+ }
133
155
  await fs_1.promises.writeFile(configPath, `import userConfig from "./gatsby-config.mjs.__vercel_builder_backup__.mjs";
134
156
 
135
- // https://github.com/gatsbyjs/gatsby/blob/354003fb2908e02ff12109ca3a02978a5a6e608c/packages/gatsby/src/bootstrap/prefer-default.ts
136
157
  const preferDefault = (m) => (m && m.default) || m;
137
158
 
138
159
  const vercelConfig = Object.assign(
139
160
  {},
140
- // https://github.com/gatsbyjs/gatsby/blob/a6ecfb2b01d761e8a3612b8ea132c698659923d9/packages/gatsby/src/services/initialize.ts#L113-L117
141
161
  preferDefault(userConfig)
142
162
  );
143
163
  if (!vercelConfig.plugins) {
144
164
  vercelConfig.plugins = [];
145
165
  }
146
166
 
147
- for (const plugin of ${JSON.stringify(plugins)}) {
167
+ for (const plugin of ${JSON.stringify(Array.from(plugins))}) {
148
168
  const hasPlugin = vercelConfig.plugins.find(
149
169
  (p) => p && (p === plugin || p.resolve === plugin)
150
170
  );
@@ -158,23 +178,24 @@ for (const plugin of ${JSON.stringify(plugins)}) {
158
178
  export default vercelConfig;
159
179
  `);
160
180
  }
161
- async function updateGatsbyJsConfig(configPath, plugins) {
162
- await fs_1.promises.rename(configPath, configPath + '.__vercel_builder_backup__.js');
181
+ async function updateGatsbyConfigJs(configPath, plugins) {
182
+ const renamedPath = `${configPath}.__vercel_builder_backup__.js`;
183
+ if (!(await _shared_1.fileExists(renamedPath))) {
184
+ await fs_1.promises.rename(configPath, renamedPath);
185
+ }
163
186
  await fs_1.promises.writeFile(configPath, `const userConfig = require("./gatsby-config.js.__vercel_builder_backup__.js");
164
187
 
165
- // https://github.com/gatsbyjs/gatsby/blob/354003fb2908e02ff12109ca3a02978a5a6e608c/packages/gatsby/src/bootstrap/prefer-default.ts
166
188
  const preferDefault = m => (m && m.default) || m;
167
189
 
168
190
  const vercelConfig = Object.assign(
169
191
  {},
170
- // https://github.com/gatsbyjs/gatsby/blob/a6ecfb2b01d761e8a3612b8ea132c698659923d9/packages/gatsby/src/services/initialize.ts#L113-L117
171
192
  preferDefault(userConfig)
172
193
  );
173
194
  if (!vercelConfig.plugins) {
174
195
  vercelConfig.plugins = [];
175
196
  }
176
197
 
177
- for (const plugin of ${JSON.stringify(plugins)}) {
198
+ for (const plugin of ${JSON.stringify(Array.from(plugins))}) {
178
199
  const hasPlugin = vercelConfig.plugins.find(
179
200
  (p) => p && (p === plugin || p.resolve === plugin)
180
201
  );
@@ -187,3 +208,77 @@ for (const plugin of ${JSON.stringify(plugins)}) {
187
208
  module.exports = vercelConfig;
188
209
  `);
189
210
  }
211
+ async function updateGatsbyNode(dir) {
212
+ const gatsbyNodePathTs = path.join(dir, `${GATSBY_NODE_FILE}.ts`);
213
+ const gatsbyNodePathMjs = path.join(dir, `${GATSBY_NODE_FILE}.mjs`);
214
+ const gatsbyNodePathJs = path.join(dir, `${GATSBY_NODE_FILE}.js`);
215
+ if (await _shared_1.fileExists(gatsbyNodePathTs)) {
216
+ await updateGatsbyNodeTs(gatsbyNodePathTs);
217
+ }
218
+ else if (await _shared_1.fileExists(gatsbyNodePathMjs)) {
219
+ await updateGatsbyNodeMjs(gatsbyNodePathMjs);
220
+ }
221
+ else if (await _shared_1.fileExists(gatsbyNodePathJs)) {
222
+ await updateGatsbyNodeJs(gatsbyNodePathJs);
223
+ }
224
+ else {
225
+ await fs_1.promises.writeFile(gatsbyNodePathJs, `module.exports = require('@vercel/gatsby-plugin-vercel-builder/gatsby-node.js');`);
226
+ }
227
+ }
228
+ async function updateGatsbyNodeTs(configPath) {
229
+ const renamedPath = `${configPath}.__vercel_builder_backup__.ts`;
230
+ if (!(await _shared_1.fileExists(renamedPath))) {
231
+ await fs_1.promises.rename(configPath, renamedPath);
232
+ }
233
+ await fs_1.promises.writeFile(configPath, `import type { GatsbyNode } from 'gatsby';
234
+ import * as vercelBuilder from '@vercel/gatsby-plugin-vercel-builder/gatsby-node.js';
235
+ import * as gatsbyNode from './gatsby-node.ts.__vercel_builder_backup__.ts';
236
+
237
+ export * from './gatsby-node.ts.__vercel_builder_backup__.ts';
238
+
239
+ export const onPostBuild: GatsbyNode['onPostBuild'] = async (args, options) => {
240
+ if (typeof (gatsbyNode as any).onPostBuild === 'function') {
241
+ await (gatsbyNode as any).onPostBuild(args, options);
242
+ }
243
+ await vercelBuilder.onPostBuild(args, options);
244
+ };
245
+ `);
246
+ }
247
+ async function updateGatsbyNodeMjs(configPath) {
248
+ const renamedPath = `${configPath}.__vercel_builder_backup__.mjs`;
249
+ if (!(await _shared_1.fileExists(renamedPath))) {
250
+ await fs_1.promises.rename(configPath, renamedPath);
251
+ }
252
+ await fs_1.promises.writeFile(configPath, `import * as vercelBuilder from '@vercel/gatsby-plugin-vercel-builder/gatsby-node.js';
253
+ import * as gatsbyNode from './gatsby-node.mjs.__vercel_builder_backup__.mjs';
254
+
255
+ export * from './gatsby-node.mjs.__vercel_builder_backup__.mjs';
256
+
257
+ export const onPostBuild = async (args, options) => {
258
+ if (typeof gatsbyNode.onPostBuild === 'function') {
259
+ await gatsbyNode.onPostBuild(args, options);
260
+ }
261
+ await vercelBuilder.onPostBuild(args, options);
262
+ };
263
+ `);
264
+ }
265
+ async function updateGatsbyNodeJs(configPath) {
266
+ const renamedPath = `${configPath}.__vercel_builder_backup__.js`;
267
+ if (!(await _shared_1.fileExists(renamedPath))) {
268
+ await fs_1.promises.rename(configPath, renamedPath);
269
+ }
270
+ await fs_1.promises.writeFile(configPath, `const vercelBuilder = require('@vercel/gatsby-plugin-vercel-builder/gatsby-node.js');
271
+ const gatsbyNode = require('./gatsby-node.js.__vercel_builder_backup__.js');
272
+
273
+ const origOnPostBuild = gatsbyNode.onPostBuild;
274
+
275
+ gatsbyNode.onPostBuild = async (args, options) => {
276
+ if (typeof origOnPostBuild === 'function') {
277
+ await origOnPostBuild(args, options);
278
+ }
279
+ await vercelBuilder.onPostBuild(args, options);
280
+ };
281
+
282
+ module.exports = gatsbyNode;
283
+ `);
284
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/static-build",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/build-step",
@@ -15,7 +15,7 @@
15
15
  "scripts": {
16
16
  "build": "node build",
17
17
  "test": "jest --env node --verbose --bail --runInBand",
18
- "test-unit": "pnpm test test/build.test.ts test/prepare-cache.test.ts",
18
+ "test-unit": "pnpm test test/build.test.ts test/gatsby.test.js test/prepare-cache.test.ts",
19
19
  "test-integration-once": "pnpm test test/integration-*.test.js"
20
20
  },
21
21
  "jest": {
@@ -38,9 +38,11 @@
38
38
  "@types/node-fetch": "2.5.4",
39
39
  "@types/promise-timeout": "1.3.0",
40
40
  "@types/semver": "7.3.13",
41
- "@vercel/build-utils": "5.9.0",
42
- "@vercel/frameworks": "1.2.4",
43
- "@vercel/fs-detectors": "3.7.5",
41
+ "@vercel/build-utils": "6.0.0",
42
+ "@vercel/frameworks": "1.3.0",
43
+ "@vercel/fs-detectors": "3.7.6",
44
+ "@vercel/gatsby-plugin-vercel-analytics": "1.0.7",
45
+ "@vercel/gatsby-plugin-vercel-builder": "1.0.1",
44
46
  "@vercel/ncc": "0.24.0",
45
47
  "@vercel/routing-utils": "2.1.8",
46
48
  "@vercel/static-config": "2.0.11",
@@ -56,5 +58,5 @@
56
58
  "ts-morph": "12.0.0",
57
59
  "typescript": "4.3.4"
58
60
  },
59
- "gitHead": "92f5b6e0c9be947a68b617d282fc39144f530813"
61
+ "gitHead": "25f6595d3698546ba69c7fe9f601a906167fef3f"
60
62
  }