@amazon/vinyl-build-utils 1.0.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.
Files changed (108) hide show
  1. package/README.md +49 -0
  2. package/dist/babel/compatTransform.d.ts +20 -0
  3. package/dist/babel/compatTransform.d.ts.map +1 -0
  4. package/dist/babel/compatTransform.js +46 -0
  5. package/dist/browserstack/BrowserStackWorker.d.ts +150 -0
  6. package/dist/browserstack/BrowserStackWorker.d.ts.map +1 -0
  7. package/dist/browserstack/BrowserStackWorker.js +280 -0
  8. package/dist/browserstack/BrowserStackWorkerController.d.ts +103 -0
  9. package/dist/browserstack/BrowserStackWorkerController.d.ts.map +1 -0
  10. package/dist/browserstack/BrowserStackWorkerController.js +199 -0
  11. package/dist/browserstack/browserStackLocal.d.ts +3 -0
  12. package/dist/browserstack/browserStackLocal.d.ts.map +1 -0
  13. package/dist/browserstack/browserStackLocal.js +36 -0
  14. package/dist/browserstack/browserStackRestApi.d.ts +304 -0
  15. package/dist/browserstack/browserStackRestApi.d.ts.map +1 -0
  16. package/dist/browserstack/browserStackRestApi.js +121 -0
  17. package/dist/browserstack/configureReporterApi.d.ts +85 -0
  18. package/dist/browserstack/configureReporterApi.d.ts.map +1 -0
  19. package/dist/browserstack/configureReporterApi.js +51 -0
  20. package/dist/browserstack/runBrowserStack.d.ts +123 -0
  21. package/dist/browserstack/runBrowserStack.d.ts.map +1 -0
  22. package/dist/browserstack/runBrowserStack.js +204 -0
  23. package/dist/esbuild/CompatTransformPlugin.d.ts +6 -0
  24. package/dist/esbuild/CompatTransformPlugin.d.ts.map +1 -0
  25. package/dist/esbuild/CompatTransformPlugin.js +59 -0
  26. package/dist/esbuild/PureExportsPlugin.d.ts +11 -0
  27. package/dist/esbuild/PureExportsPlugin.d.ts.map +1 -0
  28. package/dist/esbuild/PureExportsPlugin.js +55 -0
  29. package/dist/esbuild/TypeDeclarationsPlugin.d.ts +9 -0
  30. package/dist/esbuild/TypeDeclarationsPlugin.d.ts.map +1 -0
  31. package/dist/esbuild/TypeDeclarationsPlugin.js +60 -0
  32. package/dist/esbuild/analyzeExports.d.ts +7 -0
  33. package/dist/esbuild/analyzeExports.d.ts.map +1 -0
  34. package/dist/esbuild/analyzeExports.js +78 -0
  35. package/dist/esbuild/buildAll.d.ts +12 -0
  36. package/dist/esbuild/buildAll.d.ts.map +1 -0
  37. package/dist/esbuild/buildAll.js +16 -0
  38. package/dist/esbuild/optionalEntryPoints.d.ts +8 -0
  39. package/dist/esbuild/optionalEntryPoints.d.ts.map +1 -0
  40. package/dist/esbuild/optionalEntryPoints.js +20 -0
  41. package/dist/express/serve.d.ts +33 -0
  42. package/dist/express/serve.d.ts.map +1 -0
  43. package/dist/express/serve.js +31 -0
  44. package/dist/express/startExpressServer.d.ts +80 -0
  45. package/dist/express/startExpressServer.d.ts.map +1 -0
  46. package/dist/express/startExpressServer.js +114 -0
  47. package/dist/index.d.ts +36 -0
  48. package/dist/index.d.ts.map +1 -0
  49. package/dist/index.js +35 -0
  50. package/dist/tsconfig.tsbuildinfo +1 -0
  51. package/dist/typescript/buildTypeDeclarations.d.ts +47 -0
  52. package/dist/typescript/buildTypeDeclarations.d.ts.map +1 -0
  53. package/dist/typescript/buildTypeDeclarations.js +65 -0
  54. package/dist/typescript/parseTsConfig.d.ts +13 -0
  55. package/dist/typescript/parseTsConfig.d.ts.map +1 -0
  56. package/dist/typescript/parseTsConfig.js +23 -0
  57. package/dist/typescript/replacePathAliases.d.ts +10 -0
  58. package/dist/typescript/replacePathAliases.d.ts.map +1 -0
  59. package/dist/typescript/replacePathAliases.js +26 -0
  60. package/dist/typescript/resolveProjectReferences.d.ts +8 -0
  61. package/dist/typescript/resolveProjectReferences.d.ts.map +1 -0
  62. package/dist/typescript/resolveProjectReferences.js +42 -0
  63. package/dist/typescript/tsc.d.ts +15 -0
  64. package/dist/typescript/tsc.d.ts.map +1 -0
  65. package/dist/typescript/tsc.js +28 -0
  66. package/dist/util/Logger.d.ts +34 -0
  67. package/dist/util/Logger.d.ts.map +1 -0
  68. package/dist/util/Logger.js +88 -0
  69. package/dist/util/TaskQueue.d.ts +30 -0
  70. package/dist/util/TaskQueue.d.ts.map +1 -0
  71. package/dist/util/TaskQueue.js +55 -0
  72. package/dist/util/console.d.ts +22 -0
  73. package/dist/util/console.d.ts.map +1 -0
  74. package/dist/util/console.js +58 -0
  75. package/dist/util/copyFiles.d.ts +33 -0
  76. package/dist/util/copyFiles.d.ts.map +1 -0
  77. package/dist/util/copyFiles.js +55 -0
  78. package/dist/util/extractArgs.d.ts +12 -0
  79. package/dist/util/extractArgs.d.ts.map +1 -0
  80. package/dist/util/extractArgs.js +23 -0
  81. package/dist/util/getRootProjectDir.d.ts +2 -0
  82. package/dist/util/getRootProjectDir.d.ts.map +1 -0
  83. package/dist/util/getRootProjectDir.js +14 -0
  84. package/dist/util/prompt.d.ts +2 -0
  85. package/dist/util/prompt.d.ts.map +1 -0
  86. package/dist/util/prompt.js +15 -0
  87. package/dist/util/sleep.d.ts +6 -0
  88. package/dist/util/sleep.d.ts.map +1 -0
  89. package/dist/util/sleep.js +13 -0
  90. package/dist/util/string.d.ts +22 -0
  91. package/dist/util/string.d.ts.map +1 -0
  92. package/dist/util/string.js +35 -0
  93. package/dist/util/writeIndexFile.d.ts +13 -0
  94. package/dist/util/writeIndexFile.d.ts.map +1 -0
  95. package/dist/util/writeIndexFile.js +92 -0
  96. package/dist/vinyl/buildVinylPackage.d.ts +40 -0
  97. package/dist/vinyl/buildVinylPackage.d.ts.map +1 -0
  98. package/dist/vinyl/buildVinylPackage.js +167 -0
  99. package/dist/vinyl/vinylDefaultBrowserStackOptions.d.ts +25 -0
  100. package/dist/vinyl/vinylDefaultBrowserStackOptions.d.ts.map +1 -0
  101. package/dist/vinyl/vinylDefaultBrowserStackOptions.js +28 -0
  102. package/dist/vinyl/vinylDefaultTscOptions.d.ts +3 -0
  103. package/dist/vinyl/vinylDefaultTscOptions.d.ts.map +1 -0
  104. package/dist/vinyl/vinylDefaultTscOptions.js +11 -0
  105. package/dist/vinyl/vinylSupportedBrowsers.d.ts +18 -0
  106. package/dist/vinyl/vinylSupportedBrowsers.d.ts.map +1 -0
  107. package/dist/vinyl/vinylSupportedBrowsers.js +55 -0
  108. package/package.json +52 -0
@@ -0,0 +1,60 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import ts from 'typescript';
6
+ import fs from 'node:fs';
7
+ import { buildTypeDeclarations, } from '../typescript/buildTypeDeclarations';
8
+ /**
9
+ * A plugin to emit type declarations after each build.
10
+ *
11
+ * @param options
12
+ */
13
+ export function tscPlugin(options = {}) {
14
+ return {
15
+ name: 'TscPlugin',
16
+ setup(build) {
17
+ // Get the config file for each entry point.
18
+ const configPaths = getAllConfigFiles(build.initialOptions.entryPoints);
19
+ build.onStart(async () => {
20
+ for (const configPath of configPaths) {
21
+ try {
22
+ await buildTypeDeclarations(configPath, options);
23
+ }
24
+ catch (e) {
25
+ return {
26
+ errors: [
27
+ {
28
+ text: e.message,
29
+ location: { file: configPath },
30
+ },
31
+ ],
32
+ };
33
+ }
34
+ }
35
+ });
36
+ },
37
+ };
38
+ }
39
+ /**
40
+ * Returns the tsconfig locations for the list of ESBuild entry points.
41
+ *
42
+ * @param entryPoints
43
+ */
44
+ function getAllConfigFiles(entryPoints) {
45
+ if (!entryPoints)
46
+ return [];
47
+ let allInputs;
48
+ if (Array.isArray(entryPoints)) {
49
+ allInputs = entryPoints.map((entryPoint) => {
50
+ return typeof entryPoint === 'string' ? entryPoint : entryPoint.in;
51
+ });
52
+ }
53
+ else {
54
+ allInputs = Object.values(entryPoints);
55
+ }
56
+ allInputs = Array.from(new Set(allInputs)); // Return only unique tsconfig locations.
57
+ return allInputs
58
+ .map((input) => ts.findConfigFile(input, fs.existsSync))
59
+ .filter((value) => value != null);
60
+ }
@@ -0,0 +1,7 @@
1
+ export interface AnalyzeExportsOptions {
2
+ readonly name: string;
3
+ readonly target: string;
4
+ readonly reportPath?: string;
5
+ }
6
+ export declare function analyzeExports({ name, target, reportPath, }: AnalyzeExportsOptions): Promise<void>;
7
+ //# sourceMappingURL=analyzeExports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"analyzeExports.d.ts","sourceRoot":"","sources":["../../src/esbuild/analyzeExports.ts"],"names":[],"mappings":"AA2CA,MAAM,WAAW,qBAAqB;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IACrB,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;IACvB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAC/B;AAED,wBAAsB,cAAc,CAAC,EACjC,IAAI,EACJ,MAAM,EACN,UAAU,GACb,EAAE,qBAAqB,GAAG,OAAO,CAAC,IAAI,CAAC,CA6DvC"}
@@ -0,0 +1,78 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import path from 'path';
6
+ import { existsSync } from 'fs';
7
+ import fs from 'fs/promises';
8
+ import { exit } from 'process';
9
+ import os from 'os';
10
+ import esbuild from 'esbuild';
11
+ import crypto from 'node:crypto';
12
+ const write = process.argv.includes('--write');
13
+ async function getBundleSize(importName, importPath) {
14
+ const virtualEntry = path.join(os.tmpdir(), `esbuild-test-${importName}-${crypto.randomUUID()}.js`);
15
+ await fs.writeFile(virtualEntry, `import { ${importName} } from "${importPath}";\nconsole.log(${importName});`);
16
+ const result = await esbuild.build({
17
+ entryPoints: [virtualEntry],
18
+ bundle: true,
19
+ write: false,
20
+ treeShaking: true,
21
+ minify: true,
22
+ format: 'esm',
23
+ platform: 'node',
24
+ logLevel: 'silent',
25
+ });
26
+ await fs.unlink(virtualEntry);
27
+ return result.outputFiles[0].text.length;
28
+ }
29
+ export async function analyzeExports({ name, target, reportPath, }) {
30
+ const exportSizes = {};
31
+ // Resolve from local
32
+ const importPath = path.resolve(target);
33
+ const exports = await import(importPath);
34
+ const exportNames = Object.keys(exports);
35
+ for (const name of exportNames) {
36
+ try {
37
+ exportSizes[name] = await getBundleSize(name, importPath);
38
+ }
39
+ catch (err) {
40
+ exportSizes[name] = -1; // Mark error
41
+ console.error(`Failed to bundle "${name}":`, err.message);
42
+ }
43
+ }
44
+ const validSizes = Object.values(exportSizes).filter((size) => size > 0);
45
+ const minBundleSize = validSizes.length > 0 ? Math.min(...validSizes) : 0;
46
+ const report = { minBundleSize };
47
+ const outPath = path.resolve(reportPath ?? `./reports/treeShaking/${name}.json`);
48
+ if (existsSync(outPath)) {
49
+ const previousJson = JSON.parse(await fs.readFile(outPath, 'utf-8'));
50
+ const previousMinSize = previousJson.minBundleSize;
51
+ if (previousMinSize && minBundleSize > 0) {
52
+ const delta = minBundleSize - previousMinSize;
53
+ const percent = delta / previousMinSize;
54
+ if (percent > 0.1) {
55
+ console.log(` ⚠️ Size increase detected:`);
56
+ console.log(` from ${previousMinSize} → ${minBundleSize} bytes (+${Math.round(percent * 100)}%)`);
57
+ if (!write) {
58
+ console.error(` ❌ ${name} - Aborting due to significant size increase.`);
59
+ exit(1);
60
+ }
61
+ }
62
+ }
63
+ }
64
+ else {
65
+ if (!write) {
66
+ console.error(` ❌ Tree shaking report missing for ${name}`);
67
+ exit(1);
68
+ }
69
+ }
70
+ if (write) {
71
+ await fs.mkdir(path.dirname(outPath), { recursive: true });
72
+ await fs.writeFile(outPath, JSON.stringify(report, null, 2));
73
+ console.log(` ✅ Report written to ${outPath}`);
74
+ }
75
+ else {
76
+ console.log(` ✅ No significant size increase for ${name}.`);
77
+ }
78
+ }
@@ -0,0 +1,12 @@
1
+ import type { BuildOptions } from 'esbuild';
2
+ export interface BuildAllOptions {
3
+ /**
4
+ * If true, the process will remain open in watch mode until terminated via Ctrl+C
5
+ */
6
+ readonly watch?: boolean;
7
+ }
8
+ /**
9
+ * Builds all entries in parallel, optionally in watch mode.
10
+ */
11
+ export declare function buildAll(entries: readonly BuildOptions[], options?: BuildAllOptions): Promise<void>;
12
+ //# sourceMappingURL=buildAll.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildAll.d.ts","sourceRoot":"","sources":["../../src/esbuild/buildAll.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAG3C,MAAM,WAAW,eAAe;IAC5B;;OAEG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED;;GAEG;AACH,wBAAsB,QAAQ,CAC1B,OAAO,EAAE,SAAS,YAAY,EAAE,EAChC,OAAO,CAAC,EAAE,eAAe,GAC1B,OAAO,CAAC,IAAI,CAAC,CASf"}
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import { build, context } from 'esbuild';
6
+ /**
7
+ * Builds all entries in parallel, optionally in watch mode.
8
+ */
9
+ export async function buildAll(entries, options) {
10
+ // Build all entries in parallel.
11
+ await Promise.all(entries.map((entry) => build(entry)));
12
+ if (options?.watch) {
13
+ // Watch all entries.
14
+ await Promise.all(entries.map(async (entry) => (await context(entry)).watch()));
15
+ }
16
+ }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Filters a record of entry points, excluding any entries where the file path does not exist.
3
+ *
4
+ * @param entryPoints - A record of entry point names to file paths
5
+ * @returns A filtered record with only entries that exist on disk
6
+ */
7
+ export declare function optionalEntryPoints(entryPoints: Record<string, string>): Record<string, string>;
8
+ //# sourceMappingURL=optionalEntryPoints.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"optionalEntryPoints.d.ts","sourceRoot":"","sources":["../../src/esbuild/optionalEntryPoints.ts"],"names":[],"mappings":"AAOA;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAC/B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACpC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAQxB"}
@@ -0,0 +1,20 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import * as fs from 'fs';
6
+ /**
7
+ * Filters a record of entry points, excluding any entries where the file path does not exist.
8
+ *
9
+ * @param entryPoints - A record of entry point names to file paths
10
+ * @returns A filtered record with only entries that exist on disk
11
+ */
12
+ export function optionalEntryPoints(entryPoints) {
13
+ const result = {};
14
+ for (const [key, path] of Object.entries(entryPoints)) {
15
+ if (fs.existsSync(path)) {
16
+ result[key] = path;
17
+ }
18
+ }
19
+ return result;
20
+ }
@@ -0,0 +1,33 @@
1
+ import type { Express } from 'express';
2
+ import type { Options as ProxyOptions } from 'http-proxy-middleware';
3
+ import type { ServerHandle, ServerHostOptions } from './startExpressServer';
4
+ export interface ServerOptions extends ServerHostOptions {
5
+ /**
6
+ * The dist directory to serve.
7
+ */
8
+ readonly staticDir: string;
9
+ /**
10
+ * Starts the server with proxy middleware.
11
+ * The object should be key / value pairs where the key is the context and the value is ProxyOptions.
12
+ *
13
+ * proxy: {
14
+ * '/proxy': {
15
+ * target: 'https://music.amazon.com',
16
+ * pathRewrite: {
17
+ * '^/proxy': '',
18
+ * },
19
+ * },
20
+ * },
21
+ */
22
+ readonly proxy?: {
23
+ readonly [key: string]: ProxyOptions;
24
+ };
25
+ }
26
+ export declare function configureExpress(app: Express, config: ServerOptions): void;
27
+ /**
28
+ * Starts a server with the given configuration.
29
+ *
30
+ * @param config
31
+ */
32
+ export declare function startServer(config: ServerOptions): Promise<ServerHandle>;
33
+ //# sourceMappingURL=serve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serve.d.ts","sourceRoot":"","sources":["../../src/express/serve.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAEtC,OAAO,KAAK,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,uBAAuB,CAAA;AAEpE,OAAO,KAAK,EAAE,YAAY,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAA;AAI3E,MAAM,WAAW,aAAc,SAAQ,iBAAiB;IACpD;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAE1B;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE;QACb,QAAQ,EAAE,GAAG,EAAE,MAAM,GAAG,YAAY,CAAA;KACvC,CAAA;CACJ;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,QAenE;AAED;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,CAAC,CAKxE"}
@@ -0,0 +1,31 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import express, { static as expressStatic } from 'express';
6
+ import { createProxyMiddleware } from 'http-proxy-middleware';
7
+ import { startExpressServer } from './startExpressServer';
8
+ import { logger } from '../util/Logger';
9
+ export function configureExpress(app, config) {
10
+ // Serve static files. These are copied to dist in build.ts.
11
+ app.use(expressStatic(config.staticDir));
12
+ if (config.proxy) {
13
+ for (const [key, options] of Object.entries(config.proxy)) {
14
+ app.use(key, createProxyMiddleware({
15
+ changeOrigin: true,
16
+ ...options,
17
+ }));
18
+ }
19
+ }
20
+ }
21
+ /**
22
+ * Starts a server with the given configuration.
23
+ *
24
+ * @param config
25
+ */
26
+ export function startServer(config) {
27
+ logger.info('Starting server...');
28
+ const app = express();
29
+ configureExpress(app, config);
30
+ return startExpressServer({ app }, config);
31
+ }
@@ -0,0 +1,80 @@
1
+ import type { Express } from 'express';
2
+ import type { SecureContextOptions } from 'node:tls';
3
+ export interface ServerHostOptions {
4
+ /**
5
+ * SSL/TLS options.
6
+ */
7
+ readonly https?: {
8
+ readonly context: SecureContextOptions;
9
+ /**
10
+ * An SNI hostname, or wildcard (e.g. '*').
11
+ *
12
+ * If the SSL certificates are not present in the credentials folder, this will not be used.
13
+ *
14
+ * Default: 'local.maestro.amazon.dev'
15
+ */
16
+ readonly hostname: string;
17
+ /**
18
+ * The port for traffic.
19
+ * Default: 443.
20
+ */
21
+ readonly port?: number;
22
+ } | undefined | null;
23
+ /**
24
+ * Settings for an HTTP server.
25
+ * If both `https` and `http` settings are provided, both will be created.
26
+ */
27
+ readonly http?: {
28
+ /**
29
+ * The port for traffic.
30
+ * Default: 80.
31
+ */
32
+ readonly port?: number;
33
+ } | undefined | null;
34
+ /**
35
+ * If true, when the address is in use, auto increment and try again.
36
+ * Default: false
37
+ */
38
+ readonly addressInUseAutoIncrement?: boolean;
39
+ }
40
+ export interface ServerDetails {
41
+ /**
42
+ * The url of the server.
43
+ */
44
+ readonly url: string;
45
+ /**
46
+ * The port.
47
+ */
48
+ readonly port: number;
49
+ }
50
+ /**
51
+ * A ServerHandle for closing the server and accessing the http and/or https server details.
52
+ * At least one server is guaranteed to have been created.
53
+ */
54
+ export interface ServerHandle {
55
+ /**
56
+ * The http server details if it was created.
57
+ */
58
+ readonly http: ServerDetails | null;
59
+ /**
60
+ * The https server details if it was created.
61
+ */
62
+ readonly https: ServerDetails | null;
63
+ /**
64
+ * Stops the server from accepting new connections and keeps existing connections.
65
+ * A promise is returned which settles on completion.
66
+ */
67
+ close(): Promise<void>;
68
+ }
69
+ export interface CreateServerDeps {
70
+ /**
71
+ * The Express application.
72
+ */
73
+ readonly app: Express;
74
+ }
75
+ /**
76
+ * Creates a server for the given express application and settings.
77
+ * Returns a handle for closing.
78
+ */
79
+ export declare function startExpressServer(deps: CreateServerDeps, options: ServerHostOptions): Promise<ServerHandle>;
80
+ //# sourceMappingURL=startExpressServer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"startExpressServer.d.ts","sourceRoot":"","sources":["../../src/express/startExpressServer.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAA;AAGtC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAGpD,MAAM,WAAW,iBAAiB;IAC9B;;OAEG;IACH,QAAQ,CAAC,KAAK,CAAC,EACT;QACI,QAAQ,CAAC,OAAO,EAAE,oBAAoB,CAAA;QAEtC;;;;;;WAMG;QACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAA;QAEzB;;;WAGG;QACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KACzB,GACD,SAAS,GACT,IAAI,CAAA;IAEV;;;OAGG;IACH,QAAQ,CAAC,IAAI,CAAC,EACR;QACI;;;WAGG;QACH,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAA;KACzB,GACD,SAAS,GACT,IAAI,CAAA;IAEV;;;OAGG;IACH,QAAQ,CAAC,yBAAyB,CAAC,EAAE,OAAO,CAAA;CAC/C;AAED,MAAM,WAAW,aAAa;IAC1B;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IAEpB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACxB;AAED;;;GAGG;AACH,MAAM,WAAW,YAAY;IACzB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,CAAA;IAEnC;;OAEG;IACH,QAAQ,CAAC,KAAK,EAAE,aAAa,GAAG,IAAI,CAAA;IAEpC;;;OAGG;IACH,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACzB;AAED,MAAM,WAAW,gBAAgB;IAC7B;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,OAAO,CAAA;CACxB;AAQD;;;GAGG;AACH,wBAAsB,kBAAkB,CACpC,IAAI,EAAE,gBAAgB,EACtB,OAAO,EAAE,iBAAiB,GAC3B,OAAO,CAAC,YAAY,CAAC,CA+DvB"}
@@ -0,0 +1,114 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import nodeHttps from 'node:https';
6
+ import nodeHttp from 'node:http';
7
+ import { logger } from '../util/Logger';
8
+ /**
9
+ * The maximum number of ports to try when auto-incrementing server ports.
10
+ * This will only be used if `options.addressInUseAutoIncrement` is true.
11
+ */
12
+ const MAX_ADDRESS_IN_USE_ATTEMPTS = 10;
13
+ /**
14
+ * Creates a server for the given express application and settings.
15
+ * Returns a handle for closing.
16
+ */
17
+ export async function startExpressServer(deps, options) {
18
+ const { http, https } = options;
19
+ const { app } = deps;
20
+ let httpServer = null;
21
+ let httpsServer = null;
22
+ let httpsDetails = null;
23
+ let httpDetails = null;
24
+ const maxPortAttempts = options.addressInUseAutoIncrement
25
+ ? MAX_ADDRESS_IN_USE_ATTEMPTS
26
+ : 1;
27
+ if (https) {
28
+ // HTTPS
29
+ httpsServer = nodeHttps.createServer((req, res) => {
30
+ // call Express and ignore its Promise
31
+ void app(req, res);
32
+ });
33
+ httpsServer.addContext(https.hostname, https.context);
34
+ const startingPort = https.port ?? 443;
35
+ const port = await listenWithAddressIncrement(httpsServer, startingPort, maxPortAttempts);
36
+ httpsDetails = {
37
+ url: `https://${https.hostname}:${port}`,
38
+ port,
39
+ };
40
+ logger.info(`Server listening at: ${httpsDetails.url}`);
41
+ }
42
+ if (http || !https) {
43
+ // HTTP
44
+ httpServer = nodeHttp.createServer((req, res) => {
45
+ void app(req, res);
46
+ });
47
+ const startingPort = http?.port ?? 80;
48
+ const port = await listenWithAddressIncrement(httpServer, startingPort, maxPortAttempts);
49
+ httpDetails = {
50
+ url: `http://localhost:${port}`,
51
+ port,
52
+ };
53
+ logger.info(`Server listening at: ${httpDetails.url}`);
54
+ }
55
+ return {
56
+ https: httpsDetails,
57
+ http: httpDetails,
58
+ async close() {
59
+ await Promise.all([close(httpServer), close(httpsServer)]);
60
+ logger.info(`Stopped server`);
61
+ },
62
+ };
63
+ }
64
+ /**
65
+ * Promisifies the server listen callback.
66
+ */
67
+ function listen(server, port) {
68
+ return new Promise((resolve, reject) => {
69
+ const errorHandler = (error) => {
70
+ reject(error);
71
+ };
72
+ server.on('error', errorHandler);
73
+ server.listen(port, () => {
74
+ server.removeListener('error', errorHandler);
75
+ resolve();
76
+ });
77
+ });
78
+ }
79
+ async function listenWithAddressIncrement(server, startPort, maxAttempts) {
80
+ for (let i = 0; i < maxAttempts; i++) {
81
+ const port = startPort + i;
82
+ try {
83
+ await listen(server, port);
84
+ return port;
85
+ }
86
+ catch (error) {
87
+ if (i < maxAttempts - 1 && isAddressInUseError(error)) {
88
+ logger.info(`Port ${port} in use, incrementing...`);
89
+ }
90
+ else {
91
+ throw error;
92
+ }
93
+ }
94
+ }
95
+ throw new Error('maxAttempts must be greater than 0');
96
+ }
97
+ /**
98
+ * Promisifies the server close callback.
99
+ */
100
+ function close(server) {
101
+ if (!server)
102
+ return Promise.resolve();
103
+ return new Promise((resolve, reject) => {
104
+ server.close((error) => {
105
+ if (error)
106
+ reject(error);
107
+ else
108
+ resolve();
109
+ });
110
+ });
111
+ }
112
+ function isAddressInUseError(error) {
113
+ return 'code' in error && error.code === 'EADDRINUSE';
114
+ }
@@ -0,0 +1,36 @@
1
+ /** Auto-generated from build scripts */
2
+ export * from './vinyl/vinylSupportedBrowsers';
3
+ export * from './vinyl/vinylDefaultTscOptions';
4
+ export * from './vinyl/vinylDefaultBrowserStackOptions';
5
+ export * from './vinyl/buildVinylPackage';
6
+ export * from './util/writeIndexFile';
7
+ export * from './util/string';
8
+ export * from './util/sleep';
9
+ export * from './util/prompt';
10
+ export * from './util/getRootProjectDir';
11
+ export * from './util/extractArgs';
12
+ export * from './util/copyFiles';
13
+ export * from './util/console';
14
+ export * from './util/TaskQueue';
15
+ export * from './util/Logger';
16
+ export * from './typescript/tsc';
17
+ export * from './typescript/resolveProjectReferences';
18
+ export * from './typescript/replacePathAliases';
19
+ export * from './typescript/parseTsConfig';
20
+ export * from './typescript/buildTypeDeclarations';
21
+ export * from './express/startExpressServer';
22
+ export * from './express/serve';
23
+ export * from './esbuild/optionalEntryPoints';
24
+ export * from './esbuild/buildAll';
25
+ export * from './esbuild/analyzeExports';
26
+ export * from './esbuild/TypeDeclarationsPlugin';
27
+ export * from './esbuild/PureExportsPlugin';
28
+ export * from './esbuild/CompatTransformPlugin';
29
+ export * from './browserstack/runBrowserStack';
30
+ export * from './browserstack/configureReporterApi';
31
+ export * from './browserstack/browserStackRestApi';
32
+ export * from './browserstack/browserStackLocal';
33
+ export * from './browserstack/BrowserStackWorkerController';
34
+ export * from './browserstack/BrowserStackWorker';
35
+ export * from './babel/compatTransform';
36
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,wCAAwC;AACxC,cAAc,gCAAgC,CAAA;AAC9C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,yCAAyC,CAAA;AACvD,cAAc,2BAA2B,CAAA;AACzC,cAAc,uBAAuB,CAAA;AACrC,cAAc,eAAe,CAAA;AAC7B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAC7B,cAAc,0BAA0B,CAAA;AACxC,cAAc,oBAAoB,CAAA;AAClC,cAAc,kBAAkB,CAAA;AAChC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,kBAAkB,CAAA;AAChC,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,uCAAuC,CAAA;AACrD,cAAc,iCAAiC,CAAA;AAC/C,cAAc,4BAA4B,CAAA;AAC1C,cAAc,oCAAoC,CAAA;AAClD,cAAc,8BAA8B,CAAA;AAC5C,cAAc,iBAAiB,CAAA;AAC/B,cAAc,+BAA+B,CAAA;AAC7C,cAAc,oBAAoB,CAAA;AAClC,cAAc,0BAA0B,CAAA;AACxC,cAAc,kCAAkC,CAAA;AAChD,cAAc,6BAA6B,CAAA;AAC3C,cAAc,iCAAiC,CAAA;AAC/C,cAAc,gCAAgC,CAAA;AAC9C,cAAc,qCAAqC,CAAA;AACnD,cAAc,oCAAoC,CAAA;AAClD,cAAc,kCAAkC,CAAA;AAChD,cAAc,6CAA6C,CAAA;AAC3D,cAAc,mCAAmC,CAAA;AACjD,cAAc,yBAAyB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,35 @@
1
+ /** Auto-generated from build scripts */
2
+ export * from './vinyl/vinylSupportedBrowsers';
3
+ export * from './vinyl/vinylDefaultTscOptions';
4
+ export * from './vinyl/vinylDefaultBrowserStackOptions';
5
+ export * from './vinyl/buildVinylPackage';
6
+ export * from './util/writeIndexFile';
7
+ export * from './util/string';
8
+ export * from './util/sleep';
9
+ export * from './util/prompt';
10
+ export * from './util/getRootProjectDir';
11
+ export * from './util/extractArgs';
12
+ export * from './util/copyFiles';
13
+ export * from './util/console';
14
+ export * from './util/TaskQueue';
15
+ export * from './util/Logger';
16
+ export * from './typescript/tsc';
17
+ export * from './typescript/resolveProjectReferences';
18
+ export * from './typescript/replacePathAliases';
19
+ export * from './typescript/parseTsConfig';
20
+ export * from './typescript/buildTypeDeclarations';
21
+ export * from './express/startExpressServer';
22
+ export * from './express/serve';
23
+ export * from './esbuild/optionalEntryPoints';
24
+ export * from './esbuild/buildAll';
25
+ export * from './esbuild/analyzeExports';
26
+ export * from './esbuild/TypeDeclarationsPlugin';
27
+ export * from './esbuild/PureExportsPlugin';
28
+ export * from './esbuild/CompatTransformPlugin';
29
+ export * from './browserstack/runBrowserStack';
30
+ export * from './browserstack/configureReporterApi';
31
+ export * from './browserstack/browserStackRestApi';
32
+ export * from './browserstack/browserStackLocal';
33
+ export * from './browserstack/BrowserStackWorkerController';
34
+ export * from './browserstack/BrowserStackWorker';
35
+ export * from './babel/compatTransform';