@vercel/static-build 1.2.1 → 1.3.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 +109 -88
- package/dist/utils/gatsby.js +77 -61
- package/package.json +9 -7
package/dist/index.js
CHANGED
|
@@ -240729,8 +240729,10 @@ async function getMonorepoDefaultSettings(projectName, projectPath, relativeToRo
|
|
|
240729
240729
|
return {
|
|
240730
240730
|
monorepoManager: 'turbo',
|
|
240731
240731
|
buildCommand: `cd ${relativeToRoot} && npx turbo run build --filter={${projectPath}}...`,
|
|
240732
|
-
installCommand:
|
|
240733
|
-
|
|
240732
|
+
installCommand: packageManager === 'npm'
|
|
240733
|
+
? `${packageManager} install --prefix=${relativeToRoot}`
|
|
240734
|
+
: `${packageManager} install`,
|
|
240735
|
+
commandForIgnoringBuildStep: `npx turbo-ignore`,
|
|
240734
240736
|
};
|
|
240735
240737
|
}
|
|
240736
240738
|
else if (monorepoManager === 'nx') {
|
|
@@ -240768,7 +240770,9 @@ async function getMonorepoDefaultSettings(projectName, projectPath, relativeToRo
|
|
|
240768
240770
|
return {
|
|
240769
240771
|
monorepoManager: 'nx',
|
|
240770
240772
|
buildCommand: `cd ${relativeToRoot} && npx nx build ${projectName}`,
|
|
240771
|
-
installCommand:
|
|
240773
|
+
installCommand: packageManager === 'npm'
|
|
240774
|
+
? `${packageManager} install --prefix=${relativeToRoot}`
|
|
240775
|
+
: `${packageManager} install`,
|
|
240772
240776
|
};
|
|
240773
240777
|
}
|
|
240774
240778
|
// TODO (@Ethan-Arrowood) - Revisit rush support when we can test it better
|
|
@@ -241716,16 +241720,7 @@ const build = async ({ files, entrypoint, workPath, config, meta = {}, }) => {
|
|
|
241716
241720
|
process.env[key] = value;
|
|
241717
241721
|
}
|
|
241718
241722
|
if (framework.slug === 'gatsby') {
|
|
241719
|
-
|
|
241720
|
-
if (injectedPlugins) {
|
|
241721
|
-
const packageManager = await fs_detectors_1.detectFramework({
|
|
241722
|
-
fs: localFileSystemDetector,
|
|
241723
|
-
frameworkList: fs_detectors_1.packageManagers,
|
|
241724
|
-
});
|
|
241725
|
-
if (packageManager === 'pnpm') {
|
|
241726
|
-
await build_utils_1.execCommand('pnpm install --lockfile-only');
|
|
241727
|
-
}
|
|
241728
|
-
}
|
|
241723
|
+
await GatsbyUtils.injectPlugins(detectedVersion, entrypointDir);
|
|
241729
241724
|
}
|
|
241730
241725
|
if (process.env.VERCEL_ANALYTICS_ID) {
|
|
241731
241726
|
const frameworkDirectory = path_1.default.join(workPath, path_1.default.dirname(entrypoint));
|
|
@@ -241827,6 +241822,9 @@ const build = async ({ files, entrypoint, workPath, config, meta = {}, }) => {
|
|
|
241827
241822
|
}
|
|
241828
241823
|
}
|
|
241829
241824
|
}
|
|
241825
|
+
if (framework?.slug === 'gatsby') {
|
|
241826
|
+
await GatsbyUtils.createPluginSymlinks(entrypointDir);
|
|
241827
|
+
}
|
|
241830
241828
|
let gemHome = undefined;
|
|
241831
241829
|
const pathList = [];
|
|
241832
241830
|
if (isNpmInstall || (pkg && (buildCommand || devCommand))) {
|
|
@@ -241910,20 +241908,27 @@ const build = async ({ files, entrypoint, workPath, config, meta = {}, }) => {
|
|
|
241910
241908
|
if (buildCommand) {
|
|
241911
241909
|
build_utils_1.debug(`Executing "${buildCommand}"`);
|
|
241912
241910
|
}
|
|
241913
|
-
|
|
241914
|
-
|
|
241915
|
-
|
|
241916
|
-
|
|
241917
|
-
|
|
241918
|
-
|
|
241919
|
-
|
|
241920
|
-
|
|
241921
|
-
|
|
241922
|
-
|
|
241923
|
-
|
|
241924
|
-
|
|
241925
|
-
|
|
241926
|
-
|
|
241911
|
+
try {
|
|
241912
|
+
const found = typeof buildCommand === 'string'
|
|
241913
|
+
? await build_utils_1.execCommand(buildCommand, {
|
|
241914
|
+
...spawnOpts,
|
|
241915
|
+
// Yarn v2 PnP mode may be activated, so force
|
|
241916
|
+
// "node-modules" linker style
|
|
241917
|
+
env: {
|
|
241918
|
+
YARN_NODE_LINKER: 'node-modules',
|
|
241919
|
+
...spawnOpts.env,
|
|
241920
|
+
},
|
|
241921
|
+
cwd: entrypointDir,
|
|
241922
|
+
})
|
|
241923
|
+
: await build_utils_1.runPackageJsonScript(entrypointDir, ['vercel-build', 'now-build', 'build'], spawnOpts);
|
|
241924
|
+
if (!found) {
|
|
241925
|
+
throw new Error(`Missing required "${buildCommand || 'vercel-build'}" script in "${entrypoint}"`);
|
|
241926
|
+
}
|
|
241927
|
+
}
|
|
241928
|
+
finally {
|
|
241929
|
+
if (framework?.slug === 'gatsby') {
|
|
241930
|
+
await GatsbyUtils.cleanupGatsbyFiles(entrypointDir);
|
|
241931
|
+
}
|
|
241927
241932
|
}
|
|
241928
241933
|
const outputDirPrefix = path_1.default.join(workPath, path_1.default.dirname(entrypoint));
|
|
241929
241934
|
distPath =
|
|
@@ -242533,22 +242538,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
242533
242538
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
242534
242539
|
};
|
|
242535
242540
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
242536
|
-
exports.injectPlugins = void 0;
|
|
242537
|
-
const
|
|
242541
|
+
exports.createPluginSymlinks = exports.cleanupGatsbyFiles = exports.injectPlugins = void 0;
|
|
242542
|
+
const fs_extra_1 = __importDefault(__webpack_require__(6365));
|
|
242538
242543
|
const path = __importStar(__webpack_require__(5622));
|
|
242539
242544
|
const semver_1 = __importDefault(__webpack_require__(7013));
|
|
242540
|
-
const url_1 = __webpack_require__(8835);
|
|
242541
242545
|
const _shared_1 = __webpack_require__(54);
|
|
242542
|
-
const { VERCEL_CLI_VERSION } = process.env;
|
|
242543
242546
|
const PLUGINS = [
|
|
242544
242547
|
'@vercel/gatsby-plugin-vercel-analytics',
|
|
242545
242548
|
'@vercel/gatsby-plugin-vercel-builder',
|
|
242546
242549
|
];
|
|
242547
242550
|
const GATSBY_CONFIG_FILE = 'gatsby-config';
|
|
242548
242551
|
const GATSBY_NODE_FILE = 'gatsby-node';
|
|
242552
|
+
const PLUGIN_PATHS = {
|
|
242553
|
+
'@vercel/gatsby-plugin-vercel-analytics': path.dirname(eval('require').resolve(`@vercel/gatsby-plugin-vercel-analytics/package.json`)),
|
|
242554
|
+
'@vercel/gatsby-plugin-vercel-builder': path.dirname(eval('require').resolve(`@vercel/gatsby-plugin-vercel-builder/package.json`)),
|
|
242555
|
+
};
|
|
242549
242556
|
async function injectPlugins(detectedVersion, dir) {
|
|
242550
242557
|
const plugins = new Set();
|
|
242551
|
-
if (process.env.VERCEL_GATSBY_BUILDER_PLUGIN && detectedVersion) {
|
|
242558
|
+
if (process.env.VERCEL_GATSBY_BUILDER_PLUGIN === '1' && detectedVersion) {
|
|
242552
242559
|
const version = semver_1.default.coerce(detectedVersion);
|
|
242553
242560
|
if (version && semver_1.default.satisfies(version, '>=4.0.0')) {
|
|
242554
242561
|
plugins.add('@vercel/gatsby-plugin-vercel-builder');
|
|
@@ -242561,7 +242568,14 @@ async function injectPlugins(detectedVersion, dir) {
|
|
|
242561
242568
|
if (plugins.size === 0) {
|
|
242562
242569
|
return false;
|
|
242563
242570
|
}
|
|
242564
|
-
|
|
242571
|
+
let pluginsStr = 'plugin';
|
|
242572
|
+
if (plugins.size > 1) {
|
|
242573
|
+
pluginsStr += 's';
|
|
242574
|
+
}
|
|
242575
|
+
console.log(`Injecting Gatsby.js ${pluginsStr} ${Array.from(plugins)
|
|
242576
|
+
.map(p => `"${p}"`)
|
|
242577
|
+
.join(', ')}`);
|
|
242578
|
+
const ops = [];
|
|
242565
242579
|
if (plugins.has('@vercel/gatsby-plugin-vercel-analytics')) {
|
|
242566
242580
|
ops.push(updateGatsbyConfig(dir, ['@vercel/gatsby-plugin-vercel-analytics']));
|
|
242567
242581
|
}
|
|
@@ -242572,64 +242586,33 @@ async function injectPlugins(detectedVersion, dir) {
|
|
|
242572
242586
|
return true;
|
|
242573
242587
|
}
|
|
242574
242588
|
exports.injectPlugins = injectPlugins;
|
|
242575
|
-
function printInjectingPlugins(plugins, configPath) {
|
|
242576
|
-
const pluginsArray = Array.from(plugins);
|
|
242577
|
-
let pluginsStr = 'plugin';
|
|
242578
|
-
if (pluginsArray.length > 1) {
|
|
242579
|
-
pluginsStr += 's';
|
|
242580
|
-
}
|
|
242581
|
-
console.log(`Injecting Gatsby.js ${pluginsStr} ${pluginsArray
|
|
242582
|
-
.map(p => `"${p}"`)
|
|
242583
|
-
.join(', ')} to \`${configPath}\``);
|
|
242584
|
-
}
|
|
242585
|
-
async function addGatsbyPackage(dir, plugins) {
|
|
242586
|
-
const pkgJson = (await _shared_1.readPackageJson(dir));
|
|
242587
|
-
if (!pkgJson.dependencies) {
|
|
242588
|
-
pkgJson.dependencies = {};
|
|
242589
|
-
}
|
|
242590
|
-
for (const plugin of plugins) {
|
|
242591
|
-
if (!pkgJson.dependencies[plugin]) {
|
|
242592
|
-
console.log(`Adding "${plugin}" to \`package.json\` "dependencies"`);
|
|
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;
|
|
242599
|
-
}
|
|
242600
|
-
}
|
|
242601
|
-
await _shared_1.writePackageJson(dir, pkgJson);
|
|
242602
|
-
}
|
|
242603
242589
|
async function updateGatsbyConfig(dir, plugins) {
|
|
242604
242590
|
const gatsbyConfigPathTs = path.join(dir, `${GATSBY_CONFIG_FILE}.ts`);
|
|
242605
242591
|
const gatsbyConfigPathMjs = path.join(dir, `${GATSBY_CONFIG_FILE}.mjs`);
|
|
242606
242592
|
const gatsbyConfigPathJs = path.join(dir, `${GATSBY_CONFIG_FILE}.js`);
|
|
242607
242593
|
if (await _shared_1.fileExists(gatsbyConfigPathTs)) {
|
|
242608
|
-
printInjectingPlugins(plugins, gatsbyConfigPathTs);
|
|
242609
242594
|
await updateGatsbyConfigTs(gatsbyConfigPathTs, plugins);
|
|
242610
242595
|
}
|
|
242611
242596
|
else if (await _shared_1.fileExists(gatsbyConfigPathMjs)) {
|
|
242612
|
-
printInjectingPlugins(plugins, gatsbyConfigPathMjs);
|
|
242613
242597
|
await updateGatsbyConfigMjs(gatsbyConfigPathMjs, plugins);
|
|
242614
242598
|
}
|
|
242599
|
+
else if (await _shared_1.fileExists(gatsbyConfigPathJs)) {
|
|
242600
|
+
await updateGatsbyConfigJs(gatsbyConfigPathJs, plugins);
|
|
242601
|
+
}
|
|
242615
242602
|
else {
|
|
242616
|
-
|
|
242617
|
-
|
|
242618
|
-
|
|
242619
|
-
}
|
|
242620
|
-
else {
|
|
242621
|
-
await fs_1.promises.writeFile(gatsbyConfigPathJs, `module.exports = ${JSON.stringify({
|
|
242622
|
-
plugins: Array.from(plugins),
|
|
242623
|
-
})}`);
|
|
242624
|
-
}
|
|
242603
|
+
await fs_extra_1.default.writeFile(gatsbyConfigPathJs, `module.exports = ${JSON.stringify({
|
|
242604
|
+
plugins,
|
|
242605
|
+
})}`);
|
|
242625
242606
|
}
|
|
242626
242607
|
}
|
|
242608
|
+
const GENERATED_FILE_COMMENT = `// This file was generated by @vercel/static-build`;
|
|
242627
242609
|
async function updateGatsbyConfigTs(configPath, plugins) {
|
|
242628
242610
|
const renamedPath = `${configPath}.__vercel_builder_backup__.ts`;
|
|
242629
242611
|
if (!(await _shared_1.fileExists(renamedPath))) {
|
|
242630
|
-
await
|
|
242612
|
+
await fs_extra_1.default.rename(configPath, renamedPath);
|
|
242631
242613
|
}
|
|
242632
|
-
await
|
|
242614
|
+
await fs_extra_1.default.writeFile(configPath, `${GENERATED_FILE_COMMENT}
|
|
242615
|
+
import userConfig from "./gatsby-config.ts.__vercel_builder_backup__.ts";
|
|
242633
242616
|
import type { PluginRef } from "gatsby";
|
|
242634
242617
|
|
|
242635
242618
|
const preferDefault = (m: any) => (m && m.default) || m;
|
|
@@ -242643,7 +242626,7 @@ if (!vercelConfig.plugins) {
|
|
|
242643
242626
|
vercelConfig.plugins = [];
|
|
242644
242627
|
}
|
|
242645
242628
|
|
|
242646
|
-
for (const plugin of ${JSON.stringify(
|
|
242629
|
+
for (const plugin of ${JSON.stringify(plugins)}) {
|
|
242647
242630
|
const hasPlugin = vercelConfig.plugins.find(
|
|
242648
242631
|
(p: PluginRef) =>
|
|
242649
242632
|
p && (p === plugin || p.resolve === plugin)
|
|
@@ -242661,9 +242644,10 @@ export default vercelConfig;
|
|
|
242661
242644
|
async function updateGatsbyConfigMjs(configPath, plugins) {
|
|
242662
242645
|
const renamedPath = `${configPath}.__vercel_builder_backup__.mjs`;
|
|
242663
242646
|
if (!(await _shared_1.fileExists(renamedPath))) {
|
|
242664
|
-
await
|
|
242647
|
+
await fs_extra_1.default.rename(configPath, renamedPath);
|
|
242665
242648
|
}
|
|
242666
|
-
await
|
|
242649
|
+
await fs_extra_1.default.writeFile(configPath, `${GENERATED_FILE_COMMENT}
|
|
242650
|
+
import userConfig from "./gatsby-config.mjs.__vercel_builder_backup__.mjs";
|
|
242667
242651
|
|
|
242668
242652
|
const preferDefault = (m) => (m && m.default) || m;
|
|
242669
242653
|
|
|
@@ -242671,11 +242655,12 @@ const vercelConfig = Object.assign(
|
|
|
242671
242655
|
{},
|
|
242672
242656
|
preferDefault(userConfig)
|
|
242673
242657
|
);
|
|
242658
|
+
|
|
242674
242659
|
if (!vercelConfig.plugins) {
|
|
242675
242660
|
vercelConfig.plugins = [];
|
|
242676
242661
|
}
|
|
242677
242662
|
|
|
242678
|
-
for (const plugin of ${JSON.stringify(
|
|
242663
|
+
for (const plugin of ${JSON.stringify(plugins)}) {
|
|
242679
242664
|
const hasPlugin = vercelConfig.plugins.find(
|
|
242680
242665
|
(p) => p && (p === plugin || p.resolve === plugin)
|
|
242681
242666
|
);
|
|
@@ -242692,9 +242677,10 @@ export default vercelConfig;
|
|
|
242692
242677
|
async function updateGatsbyConfigJs(configPath, plugins) {
|
|
242693
242678
|
const renamedPath = `${configPath}.__vercel_builder_backup__.js`;
|
|
242694
242679
|
if (!(await _shared_1.fileExists(renamedPath))) {
|
|
242695
|
-
await
|
|
242680
|
+
await fs_extra_1.default.rename(configPath, renamedPath);
|
|
242696
242681
|
}
|
|
242697
|
-
await
|
|
242682
|
+
await fs_extra_1.default.writeFile(configPath, `${GENERATED_FILE_COMMENT}
|
|
242683
|
+
const userConfig = require("./gatsby-config.js.__vercel_builder_backup__.js");
|
|
242698
242684
|
|
|
242699
242685
|
const preferDefault = m => (m && m.default) || m;
|
|
242700
242686
|
|
|
@@ -242702,11 +242688,12 @@ const vercelConfig = Object.assign(
|
|
|
242702
242688
|
{},
|
|
242703
242689
|
preferDefault(userConfig)
|
|
242704
242690
|
);
|
|
242691
|
+
|
|
242705
242692
|
if (!vercelConfig.plugins) {
|
|
242706
242693
|
vercelConfig.plugins = [];
|
|
242707
242694
|
}
|
|
242708
242695
|
|
|
242709
|
-
for (const plugin of ${JSON.stringify(
|
|
242696
|
+
for (const plugin of ${JSON.stringify(plugins)}) {
|
|
242710
242697
|
const hasPlugin = vercelConfig.plugins.find(
|
|
242711
242698
|
(p) => p && (p === plugin || p.resolve === plugin)
|
|
242712
242699
|
);
|
|
@@ -242733,15 +242720,16 @@ async function updateGatsbyNode(dir) {
|
|
|
242733
242720
|
await updateGatsbyNodeJs(gatsbyNodePathJs);
|
|
242734
242721
|
}
|
|
242735
242722
|
else {
|
|
242736
|
-
await
|
|
242723
|
+
await fs_extra_1.default.writeFile(gatsbyNodePathJs, `module.exports = require('@vercel/gatsby-plugin-vercel-builder/gatsby-node.js');`);
|
|
242737
242724
|
}
|
|
242738
242725
|
}
|
|
242739
242726
|
async function updateGatsbyNodeTs(configPath) {
|
|
242740
242727
|
const renamedPath = `${configPath}.__vercel_builder_backup__.ts`;
|
|
242741
242728
|
if (!(await _shared_1.fileExists(renamedPath))) {
|
|
242742
|
-
await
|
|
242729
|
+
await fs_extra_1.default.rename(configPath, renamedPath);
|
|
242743
242730
|
}
|
|
242744
|
-
await
|
|
242731
|
+
await fs_extra_1.default.writeFile(configPath, `${GENERATED_FILE_COMMENT}
|
|
242732
|
+
import type { GatsbyNode } from 'gatsby';
|
|
242745
242733
|
import * as vercelBuilder from '@vercel/gatsby-plugin-vercel-builder/gatsby-node.js';
|
|
242746
242734
|
import * as gatsbyNode from './gatsby-node.ts.__vercel_builder_backup__.ts';
|
|
242747
242735
|
|
|
@@ -242758,9 +242746,10 @@ export const onPostBuild: GatsbyNode['onPostBuild'] = async (args, options) => {
|
|
|
242758
242746
|
async function updateGatsbyNodeMjs(configPath) {
|
|
242759
242747
|
const renamedPath = `${configPath}.__vercel_builder_backup__.mjs`;
|
|
242760
242748
|
if (!(await _shared_1.fileExists(renamedPath))) {
|
|
242761
|
-
await
|
|
242749
|
+
await fs_extra_1.default.rename(configPath, renamedPath);
|
|
242762
242750
|
}
|
|
242763
|
-
await
|
|
242751
|
+
await fs_extra_1.default.writeFile(configPath, `${GENERATED_FILE_COMMENT}
|
|
242752
|
+
import * as vercelBuilder from '@vercel/gatsby-plugin-vercel-builder/gatsby-node.js';
|
|
242764
242753
|
import * as gatsbyNode from './gatsby-node.mjs.__vercel_builder_backup__.mjs';
|
|
242765
242754
|
|
|
242766
242755
|
export * from './gatsby-node.mjs.__vercel_builder_backup__.mjs';
|
|
@@ -242776,9 +242765,10 @@ export const onPostBuild = async (args, options) => {
|
|
|
242776
242765
|
async function updateGatsbyNodeJs(configPath) {
|
|
242777
242766
|
const renamedPath = `${configPath}.__vercel_builder_backup__.js`;
|
|
242778
242767
|
if (!(await _shared_1.fileExists(renamedPath))) {
|
|
242779
|
-
await
|
|
242768
|
+
await fs_extra_1.default.rename(configPath, renamedPath);
|
|
242780
242769
|
}
|
|
242781
|
-
await
|
|
242770
|
+
await fs_extra_1.default.writeFile(configPath, `${GENERATED_FILE_COMMENT}
|
|
242771
|
+
const vercelBuilder = require('@vercel/gatsby-plugin-vercel-builder/gatsby-node.js');
|
|
242782
242772
|
const gatsbyNode = require('./gatsby-node.js.__vercel_builder_backup__.js');
|
|
242783
242773
|
|
|
242784
242774
|
const origOnPostBuild = gatsbyNode.onPostBuild;
|
|
@@ -242793,6 +242783,37 @@ gatsbyNode.onPostBuild = async (args, options) => {
|
|
|
242793
242783
|
module.exports = gatsbyNode;
|
|
242794
242784
|
`);
|
|
242795
242785
|
}
|
|
242786
|
+
async function cleanupGatsbyFiles(dir) {
|
|
242787
|
+
const backup = '.__vercel_builder_backup__';
|
|
242788
|
+
const fileEndings = ['.js', '.ts', '.mjs'];
|
|
242789
|
+
for (const fileName of [GATSBY_CONFIG_FILE, GATSBY_NODE_FILE]) {
|
|
242790
|
+
for (const fileEnding of fileEndings) {
|
|
242791
|
+
const baseFile = `${fileName}${fileEnding}`;
|
|
242792
|
+
const baseFilePath = path.join(dir, baseFile);
|
|
242793
|
+
const backupFile = `${baseFile}${backup}${fileEnding}`;
|
|
242794
|
+
const backupFilePath = path.join(dir, backupFile);
|
|
242795
|
+
const [baseFileContent, backupFileContent] = await Promise.all([
|
|
242796
|
+
fs_extra_1.default.readFile(baseFilePath, 'utf-8').catch(() => null),
|
|
242797
|
+
fs_extra_1.default.readFile(backupFilePath, 'utf-8').catch(() => null),
|
|
242798
|
+
]);
|
|
242799
|
+
if (baseFileContent &&
|
|
242800
|
+
baseFileContent.startsWith(GENERATED_FILE_COMMENT)) {
|
|
242801
|
+
await fs_extra_1.default.rm(baseFilePath);
|
|
242802
|
+
}
|
|
242803
|
+
if (backupFileContent) {
|
|
242804
|
+
await fs_extra_1.default.rename(backupFilePath, baseFilePath);
|
|
242805
|
+
}
|
|
242806
|
+
}
|
|
242807
|
+
}
|
|
242808
|
+
}
|
|
242809
|
+
exports.cleanupGatsbyFiles = cleanupGatsbyFiles;
|
|
242810
|
+
async function createPluginSymlinks(dir) {
|
|
242811
|
+
const nodeModulesDir = path.join(dir, 'node_modules');
|
|
242812
|
+
await fs_extra_1.default.ensureDir(path.join(nodeModulesDir, '@vercel'));
|
|
242813
|
+
await Promise.all(PLUGINS.map(name => fs_extra_1.default.remove(path.join(nodeModulesDir, name))));
|
|
242814
|
+
await Promise.all(PLUGINS.map(name => fs_extra_1.default.symlink(PLUGIN_PATHS[name], path.join(nodeModulesDir, name))));
|
|
242815
|
+
}
|
|
242816
|
+
exports.createPluginSymlinks = createPluginSymlinks;
|
|
242796
242817
|
|
|
242797
242818
|
|
|
242798
242819
|
/***/ }),
|
package/dist/utils/gatsby.js
CHANGED
|
@@ -22,22 +22,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
22
22
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
23
|
};
|
|
24
24
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.injectPlugins = void 0;
|
|
26
|
-
const
|
|
25
|
+
exports.createPluginSymlinks = exports.cleanupGatsbyFiles = exports.injectPlugins = void 0;
|
|
26
|
+
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
27
27
|
const path = __importStar(require("path"));
|
|
28
28
|
const semver_1 = __importDefault(require("semver"));
|
|
29
|
-
const url_1 = require("url");
|
|
30
29
|
const _shared_1 = require("./_shared");
|
|
31
|
-
const { VERCEL_CLI_VERSION } = process.env;
|
|
32
30
|
const PLUGINS = [
|
|
33
31
|
'@vercel/gatsby-plugin-vercel-analytics',
|
|
34
32
|
'@vercel/gatsby-plugin-vercel-builder',
|
|
35
33
|
];
|
|
36
34
|
const GATSBY_CONFIG_FILE = 'gatsby-config';
|
|
37
35
|
const GATSBY_NODE_FILE = 'gatsby-node';
|
|
36
|
+
const PLUGIN_PATHS = {
|
|
37
|
+
'@vercel/gatsby-plugin-vercel-analytics': path.dirname(eval('require').resolve(`@vercel/gatsby-plugin-vercel-analytics/package.json`)),
|
|
38
|
+
'@vercel/gatsby-plugin-vercel-builder': path.dirname(eval('require').resolve(`@vercel/gatsby-plugin-vercel-builder/package.json`)),
|
|
39
|
+
};
|
|
38
40
|
async function injectPlugins(detectedVersion, dir) {
|
|
39
41
|
const plugins = new Set();
|
|
40
|
-
if (process.env.VERCEL_GATSBY_BUILDER_PLUGIN && detectedVersion) {
|
|
42
|
+
if (process.env.VERCEL_GATSBY_BUILDER_PLUGIN === '1' && detectedVersion) {
|
|
41
43
|
const version = semver_1.default.coerce(detectedVersion);
|
|
42
44
|
if (version && semver_1.default.satisfies(version, '>=4.0.0')) {
|
|
43
45
|
plugins.add('@vercel/gatsby-plugin-vercel-builder');
|
|
@@ -50,7 +52,14 @@ async function injectPlugins(detectedVersion, dir) {
|
|
|
50
52
|
if (plugins.size === 0) {
|
|
51
53
|
return false;
|
|
52
54
|
}
|
|
53
|
-
|
|
55
|
+
let pluginsStr = 'plugin';
|
|
56
|
+
if (plugins.size > 1) {
|
|
57
|
+
pluginsStr += 's';
|
|
58
|
+
}
|
|
59
|
+
console.log(`Injecting Gatsby.js ${pluginsStr} ${Array.from(plugins)
|
|
60
|
+
.map(p => `"${p}"`)
|
|
61
|
+
.join(', ')}`);
|
|
62
|
+
const ops = [];
|
|
54
63
|
if (plugins.has('@vercel/gatsby-plugin-vercel-analytics')) {
|
|
55
64
|
ops.push(updateGatsbyConfig(dir, ['@vercel/gatsby-plugin-vercel-analytics']));
|
|
56
65
|
}
|
|
@@ -61,64 +70,33 @@ async function injectPlugins(detectedVersion, dir) {
|
|
|
61
70
|
return true;
|
|
62
71
|
}
|
|
63
72
|
exports.injectPlugins = injectPlugins;
|
|
64
|
-
function printInjectingPlugins(plugins, configPath) {
|
|
65
|
-
const pluginsArray = Array.from(plugins);
|
|
66
|
-
let pluginsStr = 'plugin';
|
|
67
|
-
if (pluginsArray.length > 1) {
|
|
68
|
-
pluginsStr += 's';
|
|
69
|
-
}
|
|
70
|
-
console.log(`Injecting Gatsby.js ${pluginsStr} ${pluginsArray
|
|
71
|
-
.map(p => `"${p}"`)
|
|
72
|
-
.join(', ')} to \`${configPath}\``);
|
|
73
|
-
}
|
|
74
|
-
async function addGatsbyPackage(dir, plugins) {
|
|
75
|
-
const pkgJson = (await _shared_1.readPackageJson(dir));
|
|
76
|
-
if (!pkgJson.dependencies) {
|
|
77
|
-
pkgJson.dependencies = {};
|
|
78
|
-
}
|
|
79
|
-
for (const plugin of plugins) {
|
|
80
|
-
if (!pkgJson.dependencies[plugin]) {
|
|
81
|
-
console.log(`Adding "${plugin}" to \`package.json\` "dependencies"`);
|
|
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;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
await _shared_1.writePackageJson(dir, pkgJson);
|
|
91
|
-
}
|
|
92
73
|
async function updateGatsbyConfig(dir, plugins) {
|
|
93
74
|
const gatsbyConfigPathTs = path.join(dir, `${GATSBY_CONFIG_FILE}.ts`);
|
|
94
75
|
const gatsbyConfigPathMjs = path.join(dir, `${GATSBY_CONFIG_FILE}.mjs`);
|
|
95
76
|
const gatsbyConfigPathJs = path.join(dir, `${GATSBY_CONFIG_FILE}.js`);
|
|
96
77
|
if (await _shared_1.fileExists(gatsbyConfigPathTs)) {
|
|
97
|
-
printInjectingPlugins(plugins, gatsbyConfigPathTs);
|
|
98
78
|
await updateGatsbyConfigTs(gatsbyConfigPathTs, plugins);
|
|
99
79
|
}
|
|
100
80
|
else if (await _shared_1.fileExists(gatsbyConfigPathMjs)) {
|
|
101
|
-
printInjectingPlugins(plugins, gatsbyConfigPathMjs);
|
|
102
81
|
await updateGatsbyConfigMjs(gatsbyConfigPathMjs, plugins);
|
|
103
82
|
}
|
|
83
|
+
else if (await _shared_1.fileExists(gatsbyConfigPathJs)) {
|
|
84
|
+
await updateGatsbyConfigJs(gatsbyConfigPathJs, plugins);
|
|
85
|
+
}
|
|
104
86
|
else {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
await fs_1.promises.writeFile(gatsbyConfigPathJs, `module.exports = ${JSON.stringify({
|
|
111
|
-
plugins: Array.from(plugins),
|
|
112
|
-
})}`);
|
|
113
|
-
}
|
|
87
|
+
await fs_extra_1.default.writeFile(gatsbyConfigPathJs, `module.exports = ${JSON.stringify({
|
|
88
|
+
plugins,
|
|
89
|
+
})}`);
|
|
114
90
|
}
|
|
115
91
|
}
|
|
92
|
+
const GENERATED_FILE_COMMENT = `// This file was generated by @vercel/static-build`;
|
|
116
93
|
async function updateGatsbyConfigTs(configPath, plugins) {
|
|
117
94
|
const renamedPath = `${configPath}.__vercel_builder_backup__.ts`;
|
|
118
95
|
if (!(await _shared_1.fileExists(renamedPath))) {
|
|
119
|
-
await
|
|
96
|
+
await fs_extra_1.default.rename(configPath, renamedPath);
|
|
120
97
|
}
|
|
121
|
-
await
|
|
98
|
+
await fs_extra_1.default.writeFile(configPath, `${GENERATED_FILE_COMMENT}
|
|
99
|
+
import userConfig from "./gatsby-config.ts.__vercel_builder_backup__.ts";
|
|
122
100
|
import type { PluginRef } from "gatsby";
|
|
123
101
|
|
|
124
102
|
const preferDefault = (m: any) => (m && m.default) || m;
|
|
@@ -132,7 +110,7 @@ if (!vercelConfig.plugins) {
|
|
|
132
110
|
vercelConfig.plugins = [];
|
|
133
111
|
}
|
|
134
112
|
|
|
135
|
-
for (const plugin of ${JSON.stringify(
|
|
113
|
+
for (const plugin of ${JSON.stringify(plugins)}) {
|
|
136
114
|
const hasPlugin = vercelConfig.plugins.find(
|
|
137
115
|
(p: PluginRef) =>
|
|
138
116
|
p && (p === plugin || p.resolve === plugin)
|
|
@@ -150,9 +128,10 @@ export default vercelConfig;
|
|
|
150
128
|
async function updateGatsbyConfigMjs(configPath, plugins) {
|
|
151
129
|
const renamedPath = `${configPath}.__vercel_builder_backup__.mjs`;
|
|
152
130
|
if (!(await _shared_1.fileExists(renamedPath))) {
|
|
153
|
-
await
|
|
131
|
+
await fs_extra_1.default.rename(configPath, renamedPath);
|
|
154
132
|
}
|
|
155
|
-
await
|
|
133
|
+
await fs_extra_1.default.writeFile(configPath, `${GENERATED_FILE_COMMENT}
|
|
134
|
+
import userConfig from "./gatsby-config.mjs.__vercel_builder_backup__.mjs";
|
|
156
135
|
|
|
157
136
|
const preferDefault = (m) => (m && m.default) || m;
|
|
158
137
|
|
|
@@ -160,11 +139,12 @@ const vercelConfig = Object.assign(
|
|
|
160
139
|
{},
|
|
161
140
|
preferDefault(userConfig)
|
|
162
141
|
);
|
|
142
|
+
|
|
163
143
|
if (!vercelConfig.plugins) {
|
|
164
144
|
vercelConfig.plugins = [];
|
|
165
145
|
}
|
|
166
146
|
|
|
167
|
-
for (const plugin of ${JSON.stringify(
|
|
147
|
+
for (const plugin of ${JSON.stringify(plugins)}) {
|
|
168
148
|
const hasPlugin = vercelConfig.plugins.find(
|
|
169
149
|
(p) => p && (p === plugin || p.resolve === plugin)
|
|
170
150
|
);
|
|
@@ -181,9 +161,10 @@ export default vercelConfig;
|
|
|
181
161
|
async function updateGatsbyConfigJs(configPath, plugins) {
|
|
182
162
|
const renamedPath = `${configPath}.__vercel_builder_backup__.js`;
|
|
183
163
|
if (!(await _shared_1.fileExists(renamedPath))) {
|
|
184
|
-
await
|
|
164
|
+
await fs_extra_1.default.rename(configPath, renamedPath);
|
|
185
165
|
}
|
|
186
|
-
await
|
|
166
|
+
await fs_extra_1.default.writeFile(configPath, `${GENERATED_FILE_COMMENT}
|
|
167
|
+
const userConfig = require("./gatsby-config.js.__vercel_builder_backup__.js");
|
|
187
168
|
|
|
188
169
|
const preferDefault = m => (m && m.default) || m;
|
|
189
170
|
|
|
@@ -191,11 +172,12 @@ const vercelConfig = Object.assign(
|
|
|
191
172
|
{},
|
|
192
173
|
preferDefault(userConfig)
|
|
193
174
|
);
|
|
175
|
+
|
|
194
176
|
if (!vercelConfig.plugins) {
|
|
195
177
|
vercelConfig.plugins = [];
|
|
196
178
|
}
|
|
197
179
|
|
|
198
|
-
for (const plugin of ${JSON.stringify(
|
|
180
|
+
for (const plugin of ${JSON.stringify(plugins)}) {
|
|
199
181
|
const hasPlugin = vercelConfig.plugins.find(
|
|
200
182
|
(p) => p && (p === plugin || p.resolve === plugin)
|
|
201
183
|
);
|
|
@@ -222,15 +204,16 @@ async function updateGatsbyNode(dir) {
|
|
|
222
204
|
await updateGatsbyNodeJs(gatsbyNodePathJs);
|
|
223
205
|
}
|
|
224
206
|
else {
|
|
225
|
-
await
|
|
207
|
+
await fs_extra_1.default.writeFile(gatsbyNodePathJs, `module.exports = require('@vercel/gatsby-plugin-vercel-builder/gatsby-node.js');`);
|
|
226
208
|
}
|
|
227
209
|
}
|
|
228
210
|
async function updateGatsbyNodeTs(configPath) {
|
|
229
211
|
const renamedPath = `${configPath}.__vercel_builder_backup__.ts`;
|
|
230
212
|
if (!(await _shared_1.fileExists(renamedPath))) {
|
|
231
|
-
await
|
|
213
|
+
await fs_extra_1.default.rename(configPath, renamedPath);
|
|
232
214
|
}
|
|
233
|
-
await
|
|
215
|
+
await fs_extra_1.default.writeFile(configPath, `${GENERATED_FILE_COMMENT}
|
|
216
|
+
import type { GatsbyNode } from 'gatsby';
|
|
234
217
|
import * as vercelBuilder from '@vercel/gatsby-plugin-vercel-builder/gatsby-node.js';
|
|
235
218
|
import * as gatsbyNode from './gatsby-node.ts.__vercel_builder_backup__.ts';
|
|
236
219
|
|
|
@@ -247,9 +230,10 @@ export const onPostBuild: GatsbyNode['onPostBuild'] = async (args, options) => {
|
|
|
247
230
|
async function updateGatsbyNodeMjs(configPath) {
|
|
248
231
|
const renamedPath = `${configPath}.__vercel_builder_backup__.mjs`;
|
|
249
232
|
if (!(await _shared_1.fileExists(renamedPath))) {
|
|
250
|
-
await
|
|
233
|
+
await fs_extra_1.default.rename(configPath, renamedPath);
|
|
251
234
|
}
|
|
252
|
-
await
|
|
235
|
+
await fs_extra_1.default.writeFile(configPath, `${GENERATED_FILE_COMMENT}
|
|
236
|
+
import * as vercelBuilder from '@vercel/gatsby-plugin-vercel-builder/gatsby-node.js';
|
|
253
237
|
import * as gatsbyNode from './gatsby-node.mjs.__vercel_builder_backup__.mjs';
|
|
254
238
|
|
|
255
239
|
export * from './gatsby-node.mjs.__vercel_builder_backup__.mjs';
|
|
@@ -265,9 +249,10 @@ export const onPostBuild = async (args, options) => {
|
|
|
265
249
|
async function updateGatsbyNodeJs(configPath) {
|
|
266
250
|
const renamedPath = `${configPath}.__vercel_builder_backup__.js`;
|
|
267
251
|
if (!(await _shared_1.fileExists(renamedPath))) {
|
|
268
|
-
await
|
|
252
|
+
await fs_extra_1.default.rename(configPath, renamedPath);
|
|
269
253
|
}
|
|
270
|
-
await
|
|
254
|
+
await fs_extra_1.default.writeFile(configPath, `${GENERATED_FILE_COMMENT}
|
|
255
|
+
const vercelBuilder = require('@vercel/gatsby-plugin-vercel-builder/gatsby-node.js');
|
|
271
256
|
const gatsbyNode = require('./gatsby-node.js.__vercel_builder_backup__.js');
|
|
272
257
|
|
|
273
258
|
const origOnPostBuild = gatsbyNode.onPostBuild;
|
|
@@ -282,3 +267,34 @@ gatsbyNode.onPostBuild = async (args, options) => {
|
|
|
282
267
|
module.exports = gatsbyNode;
|
|
283
268
|
`);
|
|
284
269
|
}
|
|
270
|
+
async function cleanupGatsbyFiles(dir) {
|
|
271
|
+
const backup = '.__vercel_builder_backup__';
|
|
272
|
+
const fileEndings = ['.js', '.ts', '.mjs'];
|
|
273
|
+
for (const fileName of [GATSBY_CONFIG_FILE, GATSBY_NODE_FILE]) {
|
|
274
|
+
for (const fileEnding of fileEndings) {
|
|
275
|
+
const baseFile = `${fileName}${fileEnding}`;
|
|
276
|
+
const baseFilePath = path.join(dir, baseFile);
|
|
277
|
+
const backupFile = `${baseFile}${backup}${fileEnding}`;
|
|
278
|
+
const backupFilePath = path.join(dir, backupFile);
|
|
279
|
+
const [baseFileContent, backupFileContent] = await Promise.all([
|
|
280
|
+
fs_extra_1.default.readFile(baseFilePath, 'utf-8').catch(() => null),
|
|
281
|
+
fs_extra_1.default.readFile(backupFilePath, 'utf-8').catch(() => null),
|
|
282
|
+
]);
|
|
283
|
+
if (baseFileContent &&
|
|
284
|
+
baseFileContent.startsWith(GENERATED_FILE_COMMENT)) {
|
|
285
|
+
await fs_extra_1.default.rm(baseFilePath);
|
|
286
|
+
}
|
|
287
|
+
if (backupFileContent) {
|
|
288
|
+
await fs_extra_1.default.rename(backupFilePath, baseFilePath);
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
exports.cleanupGatsbyFiles = cleanupGatsbyFiles;
|
|
294
|
+
async function createPluginSymlinks(dir) {
|
|
295
|
+
const nodeModulesDir = path.join(dir, 'node_modules');
|
|
296
|
+
await fs_extra_1.default.ensureDir(path.join(nodeModulesDir, '@vercel'));
|
|
297
|
+
await Promise.all(PLUGINS.map(name => fs_extra_1.default.remove(path.join(nodeModulesDir, name))));
|
|
298
|
+
await Promise.all(PLUGINS.map(name => fs_extra_1.default.symlink(PLUGIN_PATHS[name], path.join(nodeModulesDir, name))));
|
|
299
|
+
}
|
|
300
|
+
exports.createPluginSymlinks = createPluginSymlinks;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vercel/static-build",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.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/gatsby.test.
|
|
18
|
+
"test-unit": "pnpm test test/build.test.ts test/gatsby.test.ts test/prepare-cache.test.ts",
|
|
19
19
|
"test-integration-once": "pnpm test test/integration-*.test.js"
|
|
20
20
|
},
|
|
21
21
|
"jest": {
|
|
@@ -28,6 +28,10 @@
|
|
|
28
28
|
}
|
|
29
29
|
}
|
|
30
30
|
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@vercel/gatsby-plugin-vercel-analytics": "1.0.7",
|
|
33
|
+
"@vercel/gatsby-plugin-vercel-builder": "1.0.3"
|
|
34
|
+
},
|
|
31
35
|
"devDependencies": {
|
|
32
36
|
"@types/aws-lambda": "8.10.64",
|
|
33
37
|
"@types/cross-spawn": "6.0.0",
|
|
@@ -38,11 +42,9 @@
|
|
|
38
42
|
"@types/node-fetch": "2.5.4",
|
|
39
43
|
"@types/promise-timeout": "1.3.0",
|
|
40
44
|
"@types/semver": "7.3.13",
|
|
41
|
-
"@vercel/build-utils": "6.0.
|
|
45
|
+
"@vercel/build-utils": "6.0.1",
|
|
42
46
|
"@vercel/frameworks": "1.3.0",
|
|
43
|
-
"@vercel/fs-detectors": "3.7.
|
|
44
|
-
"@vercel/gatsby-plugin-vercel-analytics": "1.0.7",
|
|
45
|
-
"@vercel/gatsby-plugin-vercel-builder": "1.0.1",
|
|
47
|
+
"@vercel/fs-detectors": "3.7.7",
|
|
46
48
|
"@vercel/ncc": "0.24.0",
|
|
47
49
|
"@vercel/routing-utils": "2.1.8",
|
|
48
50
|
"@vercel/static-config": "2.0.11",
|
|
@@ -58,5 +60,5 @@
|
|
|
58
60
|
"ts-morph": "12.0.0",
|
|
59
61
|
"typescript": "4.3.4"
|
|
60
62
|
},
|
|
61
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "ada9a48d57be8f4375494a369aaa98cee1f5eae2"
|
|
62
64
|
}
|