@vercel/static-build 1.3.30 → 1.3.32

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.
@@ -27,6 +27,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
29
  exports.createPluginSymlinks = exports.cleanupGatsbyFiles = exports.injectPlugins = void 0;
30
+ const error_utils_1 = require("@vercel/error-utils");
30
31
  const fs_extra_1 = __importDefault(require("fs-extra"));
31
32
  const path = __importStar(require("path"));
32
33
  const semver_1 = __importDefault(require("semver"));
@@ -41,12 +42,19 @@ const PLUGIN_PATHS = {
41
42
  '@vercel/gatsby-plugin-vercel-analytics': path.dirname(eval('require').resolve(`@vercel/gatsby-plugin-vercel-analytics/package.json`)),
42
43
  '@vercel/gatsby-plugin-vercel-builder': path.dirname(eval('require').resolve(`@vercel/gatsby-plugin-vercel-builder/package.json`)),
43
44
  };
45
+ let GLOBAL_EXIT_HANDLER;
44
46
  async function injectPlugins(detectedVersion, dir) {
45
47
  const plugins = new Set();
46
48
  if (detectedVersion) {
47
49
  const version = semver_1.default.coerce(detectedVersion);
48
50
  if (version && semver_1.default.satisfies(version, '>=4.0.0')) {
49
51
  plugins.add('@vercel/gatsby-plugin-vercel-builder');
52
+ if (!GLOBAL_EXIT_HANDLER) {
53
+ GLOBAL_EXIT_HANDLER = () => {
54
+ cleanupGatsbyFiles(dir);
55
+ };
56
+ process.on('exit', GLOBAL_EXIT_HANDLER);
57
+ }
50
58
  }
51
59
  }
52
60
  if (process.env.VERCEL_ANALYTICS_ID) {
@@ -271,28 +279,35 @@ gatsbyNode.onPostBuild = async (args, options) => {
271
279
  module.exports = gatsbyNode;
272
280
  `);
273
281
  }
274
- async function cleanupGatsbyFiles(dir) {
275
- const backup = '.__vercel_builder_backup__';
276
- const fileEndings = ['.js', '.ts', '.mjs'];
277
- for (const fileName of [GATSBY_CONFIG_FILE, GATSBY_NODE_FILE]) {
278
- for (const fileEnding of fileEndings) {
279
- const baseFile = `${fileName}${fileEnding}`;
280
- const baseFilePath = path.join(dir, baseFile);
281
- const backupFile = `${baseFile}${backup}${fileEnding}`;
282
- const backupFilePath = path.join(dir, backupFile);
283
- const [baseFileContent, backupFileContent] = await Promise.all([
284
- fs_extra_1.default.readFile(baseFilePath, 'utf-8').catch(() => null),
285
- fs_extra_1.default.readFile(backupFilePath, 'utf-8').catch(() => null),
286
- ]);
287
- if (baseFileContent &&
288
- baseFileContent.startsWith(GENERATED_FILE_COMMENT)) {
289
- await fs_extra_1.default.rm(baseFilePath);
290
- }
291
- if (backupFileContent) {
292
- await fs_extra_1.default.rename(backupFilePath, baseFilePath);
282
+ // must remain sync because it's called in an exit handler
283
+ function cleanupGatsbyFiles(dir) {
284
+ try {
285
+ const backup = '.__vercel_builder_backup__';
286
+ const fileEndings = ['.js', '.ts', '.mjs'];
287
+ for (const fileName of [GATSBY_CONFIG_FILE, GATSBY_NODE_FILE]) {
288
+ for (const fileEnding of fileEndings) {
289
+ const baseFile = `${fileName}${fileEnding}`;
290
+ const baseFilePath = path.join(dir, baseFile);
291
+ const backupFile = `${baseFile}${backup}${fileEnding}`;
292
+ const backupFilePath = path.join(dir, backupFile);
293
+ const baseFileContent = tryReadFileSync(baseFilePath);
294
+ const backupFileContent = tryReadFileSync(backupFilePath);
295
+ if (baseFileContent &&
296
+ baseFileContent.startsWith(GENERATED_FILE_COMMENT)) {
297
+ fs_extra_1.default.rmSync(baseFilePath);
298
+ }
299
+ if (backupFileContent) {
300
+ fs_extra_1.default.renameSync(backupFilePath, baseFilePath);
301
+ }
293
302
  }
294
303
  }
295
304
  }
305
+ catch (error) {
306
+ console.error(error);
307
+ if (GLOBAL_EXIT_HANDLER) {
308
+ process.off('exit', GLOBAL_EXIT_HANDLER);
309
+ }
310
+ }
296
311
  }
297
312
  exports.cleanupGatsbyFiles = cleanupGatsbyFiles;
298
313
  async function createPluginSymlinks(dir) {
@@ -302,3 +317,19 @@ async function createPluginSymlinks(dir) {
302
317
  await Promise.all(PLUGINS.map(name => fs_extra_1.default.symlink(PLUGIN_PATHS[name], path.join(nodeModulesDir, name))));
303
318
  }
304
319
  exports.createPluginSymlinks = createPluginSymlinks;
320
+ function tryReadFileSync(filePath) {
321
+ try {
322
+ return fs_extra_1.default.readFileSync(filePath, 'utf-8');
323
+ }
324
+ catch (error) {
325
+ if ((0, error_utils_1.isErrnoException)(error)) {
326
+ if (error.code !== 'ENOENT') {
327
+ console.error(error);
328
+ }
329
+ }
330
+ else {
331
+ console.error(error);
332
+ }
333
+ return undefined;
334
+ }
335
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/static-build",
3
- "version": "1.3.30",
3
+ "version": "1.3.32",
4
4
  "license": "Apache-2.0",
5
5
  "main": "./dist/index",
6
6
  "homepage": "https://vercel.com/docs/build-step",
@@ -12,15 +12,9 @@
12
12
  "url": "https://github.com/vercel/vercel.git",
13
13
  "directory": "packages/static-build"
14
14
  },
15
- "scripts": {
16
- "build": "node build",
17
- "test": "jest --env node --verbose --bail --runInBand",
18
- "test-unit": "pnpm test test/build.test.ts test/gatsby.test.ts test/prepare-cache.test.ts",
19
- "test-e2e": "pnpm test test/integration-*.test.js"
20
- },
21
15
  "dependencies": {
22
16
  "@vercel/gatsby-plugin-vercel-analytics": "1.0.10",
23
- "@vercel/gatsby-plugin-vercel-builder": "1.3.3"
17
+ "@vercel/gatsby-plugin-vercel-builder": "1.3.5"
24
18
  },
25
19
  "devDependencies": {
26
20
  "@types/aws-lambda": "8.10.64",
@@ -32,7 +26,7 @@
32
26
  "@types/node-fetch": "2.5.4",
33
27
  "@types/promise-timeout": "1.3.0",
34
28
  "@types/semver": "7.3.13",
35
- "@vercel/build-utils": "6.7.2",
29
+ "@vercel/build-utils": "6.7.3",
36
30
  "@vercel/error-utils": "1.0.10",
37
31
  "@vercel/frameworks": "1.4.2",
38
32
  "@vercel/fs-detectors": "3.9.2",
@@ -50,5 +44,10 @@
50
44
  "tree-kill": "1.2.2",
51
45
  "ts-morph": "12.0.0"
52
46
  },
53
- "gitHead": "d1d3e9384d139a06acca521348f8f9209bb3d214"
54
- }
47
+ "scripts": {
48
+ "build": "node build",
49
+ "test": "jest --env node --verbose --bail --runInBand",
50
+ "test-unit": "pnpm test test/build.test.ts test/gatsby.test.ts test/prepare-cache.test.ts",
51
+ "test-e2e": "pnpm test test/integration-*.test.js"
52
+ }
53
+ }