@vercel/build-utils 4.1.0 → 4.2.0

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.
@@ -7,7 +7,7 @@ interface ErrorResponse {
7
7
  link?: string;
8
8
  }
9
9
  interface Options {
10
- tag?: 'canary' | 'latest' | string;
10
+ tag?: string;
11
11
  functions?: BuilderFunctions;
12
12
  ignoreBuildScript?: boolean;
13
13
  projectSettings?: ProjectSettings;
@@ -187,7 +187,7 @@ async function detectBuilders(files, pkg, options = {}) {
187
187
  // and package.json can be served as static files
188
188
  frontendBuilder = {
189
189
  use: '@vercel/static',
190
- src: '!{api/**,package.json}',
190
+ src: '!{api/**,package.json,middleware.[jt]s}',
191
191
  config: {
192
192
  zeroConfig: true,
193
193
  },
@@ -237,7 +237,13 @@ async function detectBuilders(files, pkg, options = {}) {
237
237
  }
238
238
  exports.detectBuilders = detectBuilders;
239
239
  function maybeGetApiBuilder(fileName, apiMatches, options) {
240
- if (!fileName.startsWith('api/')) {
240
+ const middleware = fileName === 'middleware.js' || fileName === 'middleware.ts';
241
+ // Root-level Middleware file is handled by `@vercel/next`, so don't
242
+ // schedule a separate Builder when "nextjs" framework is selected
243
+ if (middleware && options.projectSettings?.framework === 'nextjs') {
244
+ return null;
245
+ }
246
+ if (!(fileName.startsWith('api/') || middleware)) {
241
247
  return null;
242
248
  }
243
249
  if (fileName.includes('/.')) {
@@ -256,11 +262,14 @@ function maybeGetApiBuilder(fileName, apiMatches, options) {
256
262
  return src === fileName || minimatch_1.default(fileName, src);
257
263
  });
258
264
  const { fnPattern, func } = getFunction(fileName, options);
259
- const use = (func && func.runtime) || (match && match.use);
265
+ const use = func?.runtime || match?.use;
260
266
  if (!use) {
261
267
  return null;
262
268
  }
263
269
  const config = { zeroConfig: true };
270
+ if (middleware) {
271
+ config.middleware = true;
272
+ }
264
273
  if (fnPattern && func) {
265
274
  config.functions = { [fnPattern]: func };
266
275
  if (func.includeFiles) {
@@ -290,6 +299,7 @@ function getFunction(fileName, { functions = {} }) {
290
299
  function getApiMatches() {
291
300
  const config = { zeroConfig: true };
292
301
  return [
302
+ { src: 'middleware.[jt]s', use: `@vercel/node`, config },
293
303
  { src: 'api/**/*.js', use: `@vercel/node`, config },
294
304
  { src: 'api/**/*.mjs', use: `@vercel/node`, config },
295
305
  { src: 'api/**/*.ts', use: `@vercel/node`, config },
@@ -0,0 +1,9 @@
1
+ import { DetectorFilesystem } from './detectors/filesystem';
2
+ export interface GetProjectPathsOptions {
3
+ fs: DetectorFilesystem;
4
+ path?: string;
5
+ skipPaths?: string[];
6
+ depth?: number;
7
+ }
8
+ export declare type ProjectPath = string;
9
+ export declare const getProjectPaths: ({ fs, path, skipPaths, depth, }: GetProjectPathsOptions) => Promise<ProjectPath[]>;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getProjectPaths = void 0;
7
+ const detect_framework_1 = require("./detect-framework");
8
+ const frameworks_1 = __importDefault(require("@vercel/frameworks"));
9
+ const MAX_DEPTH_TRAVERSE = 3;
10
+ const getProjectPaths = async ({ fs, path, skipPaths, depth = MAX_DEPTH_TRAVERSE, }) => {
11
+ if (depth === 0)
12
+ return [];
13
+ const allPaths = [];
14
+ const topPath = path ?? './';
15
+ if (path && skipPaths?.includes(path)) {
16
+ return allPaths;
17
+ }
18
+ const framework = await detect_framework_1.detectFramework({
19
+ fs: fs.chdir(topPath),
20
+ frameworkList: frameworks_1.default,
21
+ });
22
+ if (framework !== null)
23
+ allPaths.push(topPath);
24
+ if (depth > 1) {
25
+ const directoryContents = await fs.readdir(topPath);
26
+ const childDirectories = directoryContents.filter(stat => stat.type === 'dir' && !skipPaths?.includes(stat.path));
27
+ const paths = (await Promise.all(childDirectories.map(({ path }) => {
28
+ return exports.getProjectPaths({
29
+ fs,
30
+ path,
31
+ depth: depth - 1,
32
+ skipPaths,
33
+ });
34
+ }))).flat();
35
+ return [...paths, ...allPaths];
36
+ }
37
+ return allPaths;
38
+ };
39
+ exports.getProjectPaths = getProjectPaths;
package/dist/index.d.ts CHANGED
@@ -19,6 +19,7 @@ export { EdgeFunction } from './edge-function';
19
19
  export { detectBuilders, detectOutputDirectory, detectApiDirectory, detectApiExtensions, } from './detect-builders';
20
20
  export { detectFileSystemAPI } from './detect-file-system-api';
21
21
  export { detectFramework } from './detect-framework';
22
+ export { getProjectPaths } from './get-project-paths';
22
23
  export { DetectorFilesystem } from './detectors/filesystem';
23
24
  export { readConfigFile } from './fs/read-config-file';
24
25
  export { normalizePath } from './fs/normalize-path';
package/dist/index.js CHANGED
@@ -34075,7 +34075,7 @@ async function detectBuilders(files, pkg, options = {}) {
34075
34075
  // and package.json can be served as static files
34076
34076
  frontendBuilder = {
34077
34077
  use: '@vercel/static',
34078
- src: '!{api/**,package.json}',
34078
+ src: '!{api/**,package.json,middleware.[jt]s}',
34079
34079
  config: {
34080
34080
  zeroConfig: true,
34081
34081
  },
@@ -34125,7 +34125,13 @@ async function detectBuilders(files, pkg, options = {}) {
34125
34125
  }
34126
34126
  exports.detectBuilders = detectBuilders;
34127
34127
  function maybeGetApiBuilder(fileName, apiMatches, options) {
34128
- if (!fileName.startsWith('api/')) {
34128
+ const middleware = fileName === 'middleware.js' || fileName === 'middleware.ts';
34129
+ // Root-level Middleware file is handled by `@vercel/next`, so don't
34130
+ // schedule a separate Builder when "nextjs" framework is selected
34131
+ if (middleware && options.projectSettings?.framework === 'nextjs') {
34132
+ return null;
34133
+ }
34134
+ if (!(fileName.startsWith('api/') || middleware)) {
34129
34135
  return null;
34130
34136
  }
34131
34137
  if (fileName.includes('/.')) {
@@ -34144,11 +34150,14 @@ function maybeGetApiBuilder(fileName, apiMatches, options) {
34144
34150
  return src === fileName || minimatch_1.default(fileName, src);
34145
34151
  });
34146
34152
  const { fnPattern, func } = getFunction(fileName, options);
34147
- const use = (func && func.runtime) || (match && match.use);
34153
+ const use = func?.runtime || match?.use;
34148
34154
  if (!use) {
34149
34155
  return null;
34150
34156
  }
34151
34157
  const config = { zeroConfig: true };
34158
+ if (middleware) {
34159
+ config.middleware = true;
34160
+ }
34152
34161
  if (fnPattern && func) {
34153
34162
  config.functions = { [fnPattern]: func };
34154
34163
  if (func.includeFiles) {
@@ -34178,6 +34187,7 @@ function getFunction(fileName, { functions = {} }) {
34178
34187
  function getApiMatches() {
34179
34188
  const config = { zeroConfig: true };
34180
34189
  return [
34190
+ { src: 'middleware.[jt]s', use: `@vercel/node`, config },
34181
34191
  { src: 'api/**/*.js', use: `@vercel/node`, config },
34182
34192
  { src: 'api/**/*.mjs', use: `@vercel/node`, config },
34183
34193
  { src: 'api/**/*.ts', use: `@vercel/node`, config },
@@ -36382,6 +36392,53 @@ const getPlatformEnv = (name) => {
36382
36392
  exports.getPlatformEnv = getPlatformEnv;
36383
36393
 
36384
36394
 
36395
+ /***/ }),
36396
+
36397
+ /***/ 1886:
36398
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
36399
+
36400
+ "use strict";
36401
+
36402
+ var __importDefault = (this && this.__importDefault) || function (mod) {
36403
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36404
+ };
36405
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
36406
+ exports.getProjectPaths = void 0;
36407
+ const detect_framework_1 = __webpack_require__(5224);
36408
+ const frameworks_1 = __importDefault(__webpack_require__(8438));
36409
+ const MAX_DEPTH_TRAVERSE = 3;
36410
+ const getProjectPaths = async ({ fs, path, skipPaths, depth = MAX_DEPTH_TRAVERSE, }) => {
36411
+ if (depth === 0)
36412
+ return [];
36413
+ const allPaths = [];
36414
+ const topPath = path ?? './';
36415
+ if (path && skipPaths?.includes(path)) {
36416
+ return allPaths;
36417
+ }
36418
+ const framework = await detect_framework_1.detectFramework({
36419
+ fs: fs.chdir(topPath),
36420
+ frameworkList: frameworks_1.default,
36421
+ });
36422
+ if (framework !== null)
36423
+ allPaths.push(topPath);
36424
+ if (depth > 1) {
36425
+ const directoryContents = await fs.readdir(topPath);
36426
+ const childDirectories = directoryContents.filter(stat => stat.type === 'dir' && !skipPaths?.includes(stat.path));
36427
+ const paths = (await Promise.all(childDirectories.map(({ path }) => {
36428
+ return exports.getProjectPaths({
36429
+ fs,
36430
+ path,
36431
+ depth: depth - 1,
36432
+ skipPaths,
36433
+ });
36434
+ }))).flat();
36435
+ return [...paths, ...allPaths];
36436
+ }
36437
+ return allPaths;
36438
+ };
36439
+ exports.getProjectPaths = getProjectPaths;
36440
+
36441
+
36385
36442
  /***/ }),
36386
36443
 
36387
36444
  /***/ 2855:
@@ -36415,8 +36472,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36415
36472
  return (mod && mod.__esModule) ? mod : { "default": mod };
36416
36473
  };
36417
36474
  Object.defineProperty(exports, "__esModule", ({ value: true }));
36418
- exports.workspaceManagers = exports.isStaticRuntime = exports.isOfficialRuntime = exports.normalizePath = exports.readConfigFile = exports.DetectorFilesystem = exports.detectFramework = exports.detectFileSystemAPI = exports.detectApiExtensions = exports.detectApiDirectory = exports.detectOutputDirectory = exports.detectBuilders = exports.EdgeFunction = exports.getIgnoreFilter = exports.scanParentDirs = exports.getLambdaOptionsFromFunction = exports.isSymbolicLink = exports.debug = exports.streamToBuffer = exports.getPlatformEnv = exports.getSpawnOptions = exports.getDiscontinuedNodeVersions = exports.getLatestNodeVersion = exports.getNodeVersion = exports.getEnvForPackageManager = exports.runCustomInstallCommand = exports.runShellScript = exports.runPipInstall = exports.runBundleInstall = exports.runNpmInstall = exports.getNodeBinPath = exports.walkParentDirs = exports.spawnCommand = exports.execCommand = exports.runPackageJsonScript = exports.installDependencies = exports.getScriptName = exports.spawnAsync = exports.execAsync = exports.rename = exports.glob = exports.getWriteableDirectory = exports.download = exports.Prerender = exports.createLambda = exports.NodejsLambda = exports.Lambda = exports.FileRef = exports.FileFsRef = exports.FileBlob = void 0;
36419
- exports.monorepoManagers = exports.getWorkspacePackagePaths = exports.getWorkspaces = void 0;
36475
+ exports.isStaticRuntime = exports.isOfficialRuntime = exports.normalizePath = exports.readConfigFile = exports.DetectorFilesystem = exports.getProjectPaths = exports.detectFramework = exports.detectFileSystemAPI = exports.detectApiExtensions = exports.detectApiDirectory = exports.detectOutputDirectory = exports.detectBuilders = exports.EdgeFunction = exports.getIgnoreFilter = exports.scanParentDirs = exports.getLambdaOptionsFromFunction = exports.isSymbolicLink = exports.debug = exports.streamToBuffer = exports.getPlatformEnv = exports.getSpawnOptions = exports.getDiscontinuedNodeVersions = exports.getLatestNodeVersion = exports.getNodeVersion = exports.getEnvForPackageManager = exports.runCustomInstallCommand = exports.runShellScript = exports.runPipInstall = exports.runBundleInstall = exports.runNpmInstall = exports.getNodeBinPath = exports.walkParentDirs = exports.spawnCommand = exports.execCommand = exports.runPackageJsonScript = exports.installDependencies = exports.getScriptName = exports.spawnAsync = exports.execAsync = exports.rename = exports.glob = exports.getWriteableDirectory = exports.download = exports.Prerender = exports.createLambda = exports.NodejsLambda = exports.Lambda = exports.FileRef = exports.FileFsRef = exports.FileBlob = void 0;
36476
+ exports.monorepoManagers = exports.getWorkspacePackagePaths = exports.getWorkspaces = exports.workspaceManagers = void 0;
36420
36477
  const file_blob_1 = __importDefault(__webpack_require__(2397));
36421
36478
  exports.FileBlob = file_blob_1.default;
36422
36479
  const file_fs_ref_1 = __importDefault(__webpack_require__(9331));
@@ -36481,6 +36538,8 @@ var detect_file_system_api_1 = __webpack_require__(1182);
36481
36538
  Object.defineProperty(exports, "detectFileSystemAPI", ({ enumerable: true, get: function () { return detect_file_system_api_1.detectFileSystemAPI; } }));
36482
36539
  var detect_framework_1 = __webpack_require__(5224);
36483
36540
  Object.defineProperty(exports, "detectFramework", ({ enumerable: true, get: function () { return detect_framework_1.detectFramework; } }));
36541
+ var get_project_paths_1 = __webpack_require__(1886);
36542
+ Object.defineProperty(exports, "getProjectPaths", ({ enumerable: true, get: function () { return get_project_paths_1.getProjectPaths; } }));
36484
36543
  var filesystem_1 = __webpack_require__(461);
36485
36544
  Object.defineProperty(exports, "DetectorFilesystem", ({ enumerable: true, get: function () { return filesystem_1.DetectorFilesystem; } }));
36486
36545
  var read_config_file_1 = __webpack_require__(7792);
package/dist/types.d.ts CHANGED
@@ -377,6 +377,7 @@ export interface BuildResultV2Typical {
377
377
  }
378
378
  export declare type BuildResultV2 = BuildResultV2Typical | BuildResultBuildOutput;
379
379
  export interface BuildResultV3 {
380
+ routes?: any[];
380
381
  output: Lambda | EdgeFunction;
381
382
  }
382
383
  export declare type BuildV2 = (options: BuildOptions) => Promise<BuildResultV2>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vercel/build-utils",
3
- "version": "4.1.0",
3
+ "version": "4.2.0",
4
4
  "license": "MIT",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.js",
@@ -31,7 +31,7 @@
31
31
  "@types/node-fetch": "^2.1.6",
32
32
  "@types/semver": "6.0.0",
33
33
  "@types/yazl": "2.4.2",
34
- "@vercel/frameworks": "1.0.1",
34
+ "@vercel/frameworks": "1.0.2",
35
35
  "@vercel/ncc": "0.24.0",
36
36
  "aggregate-error": "3.0.1",
37
37
  "async-retry": "1.2.3",
@@ -50,5 +50,5 @@
50
50
  "typescript": "4.3.4",
51
51
  "yazl": "2.5.1"
52
52
  },
53
- "gitHead": "0c7b54edad6adf48505abf2cbec01691b85963bb"
53
+ "gitHead": "eed39913e1394477b224c38efe29429b17eeada6"
54
54
  }