@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,55 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * A TaskQueue runs actions in a sequence.
7
+ */
8
+ export class TaskQueue {
9
+ /**
10
+ * Set to handle when a task rejects.
11
+ */
12
+ onError = () => { };
13
+ _running = 0;
14
+ /**
15
+ * How many simultaneous tasks may be run at a time.
16
+ */
17
+ simultaneous = 1;
18
+ pending = [];
19
+ /**
20
+ * How many tasks are currently running.
21
+ */
22
+ get running() {
23
+ return this._running;
24
+ }
25
+ /**
26
+ * Enqueues the given task, returning a Promise that settles when the task is complete.
27
+ */
28
+ enqueue(task) {
29
+ return new Promise((resolve, reject) => {
30
+ this.pending.push(() => {
31
+ this._running++;
32
+ Promise.resolve(task())
33
+ .then(resolve)
34
+ .catch((error) => {
35
+ reject(error);
36
+ this.onError(error);
37
+ })
38
+ .finally(() => {
39
+ this._running--;
40
+ this.checkQueue();
41
+ });
42
+ });
43
+ this.checkQueue();
44
+ });
45
+ }
46
+ /**
47
+ * Checks if the queue has any remaining actions and if there is additional capacity to execute.
48
+ * @private
49
+ */
50
+ checkQueue() {
51
+ if (this.pending.length === 0 || this._running >= this.simultaneous)
52
+ return;
53
+ Promise.resolve(this.pending.shift()()).catch(() => { });
54
+ }
55
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * ANSI escape codes
3
+ * https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
4
+ */
5
+ export declare const ansi: {
6
+ readonly cursorLeft: string;
7
+ readonly eraseLine: string;
8
+ readonly cursorUp: (count?: number) => string;
9
+ readonly cursorDown: (count?: number) => string;
10
+ readonly eraseLines: (count: number) => string;
11
+ readonly red: string;
12
+ readonly green: string;
13
+ readonly yellow: string;
14
+ readonly resetColor: string;
15
+ };
16
+ /**
17
+ * Returns the number of log lines a message will occupy.
18
+ * @param message
19
+ */
20
+ export declare function calculateLogLines(message: string): number;
21
+ export declare function progressBar(percent: number, width?: number): string;
22
+ //# sourceMappingURL=console.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"console.d.ts","sourceRoot":"","sources":["../../src/util/console.ts"],"names":[],"mappings":"AASA;;;GAGG;AACH,eAAO,MAAM,IAAI;;;gCAGK,MAAM,KAAO,MAAM;kCACjB,MAAM,KAAO,MAAM;iCAErB,MAAM,KAAG,MAAM;;;;;CAgB3B,CAAA;AAEV;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAUzD;AAMD,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,GAAE,MAAW,GAAG,MAAM,CAMvE"}
@@ -0,0 +1,58 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import process from 'node:process';
6
+ const ESC = '\x1b[';
7
+ /**
8
+ * ANSI escape codes
9
+ * https://gist.github.com/fnky/458719343aabd01cfb17a3a4f7296797
10
+ */
11
+ export const ansi = {
12
+ cursorLeft: ESC + 'G',
13
+ eraseLine: ESC + '2K',
14
+ cursorUp: (count = 1) => `${ESC}${count}A`,
15
+ cursorDown: (count = 1) => `${ESC}${count}B`,
16
+ eraseLines(count) {
17
+ if (!count)
18
+ return '';
19
+ let clear = '';
20
+ for (let i = 0; i < count; i++) {
21
+ clear += ansi.eraseLine;
22
+ if (i < count - 1)
23
+ clear += ansi.cursorUp();
24
+ }
25
+ clear += ansi.cursorLeft;
26
+ return clear;
27
+ },
28
+ // Colors
29
+ red: ESC + '31m',
30
+ green: ESC + '32m',
31
+ yellow: ESC + '33m',
32
+ resetColor: ESC + '0m',
33
+ };
34
+ /**
35
+ * Returns the number of log lines a message will occupy.
36
+ * @param message
37
+ */
38
+ export function calculateLogLines(message) {
39
+ const columns = process.stdout.columns;
40
+ // Split the message by newline characters to handle explicit new lines
41
+ const lines = message.split('\n');
42
+ let totalLines = 0;
43
+ lines.forEach((line) => {
44
+ // If the line is empty, count the line break.
45
+ totalLines += Math.ceil(line.length / columns) || 1;
46
+ });
47
+ return totalLines;
48
+ }
49
+ const percentFormatter = new Intl.NumberFormat(undefined, {
50
+ style: 'percent',
51
+ });
52
+ export function progressBar(percent, width = 50) {
53
+ const percentStr = percentFormatter.format(percent);
54
+ const n = Math.floor(Math.min(Math.max(percent + 0.001, 0), 1) * width);
55
+ // Show the angle bracket up until 100%
56
+ const remainingStr = n < width ? `>${' '.repeat(width - n - 1)}` : '';
57
+ return `[${'='.repeat(n)}${remainingStr}] ${percentStr}`;
58
+ }
@@ -0,0 +1,33 @@
1
+ export interface CopyFilesOptions {
2
+ /**
3
+ * The paths in files will be copied maintaining the relative path from here.
4
+ */
5
+ readonly src: string;
6
+ /**
7
+ * The destination directory.
8
+ */
9
+ readonly dest: string;
10
+ /**
11
+ * Function to filter copied files/directories. Return
12
+ * `true` to copy the item, `false` to ignore it.
13
+ */
14
+ readonly filter?: (source: string, destination: string) => boolean;
15
+ /**
16
+ * If false, an error will not be thrown if the src does not exist.
17
+ */
18
+ readonly required?: boolean;
19
+ /**
20
+ * If true, changes to the source will cause the build to repeat.
21
+ */
22
+ readonly watch?: boolean;
23
+ /**
24
+ * If true, logs debug messages.
25
+ */
26
+ readonly debug?: boolean;
27
+ }
28
+ /**
29
+ * Recursively copies files and directories from one location to another.
30
+ * Optionally watches matching files for changes.
31
+ */
32
+ export declare function copyFiles(options: CopyFilesOptions): void;
33
+ //# sourceMappingURL=copyFiles.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"copyFiles.d.ts","sourceRoot":"","sources":["../../src/util/copyFiles.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,gBAAgB;IAC7B;;OAEG;IACH,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IAEpB;;OAEG;IACH,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;IAErB;;;OAGG;IACH,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,KAAK,OAAO,CAAA;IAElE;;OAEG;IACH,QAAQ,CAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;IAE3B;;OAEG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;IAExB;;OAEG;IACH,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED;;;GAGG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,QAuClD"}
@@ -0,0 +1,55 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import fs from 'node:fs';
6
+ import path from 'path';
7
+ /**
8
+ * Recursively copies files and directories from one location to another.
9
+ * Optionally watches matching files for changes.
10
+ */
11
+ export function copyFiles(options) {
12
+ const copyOptions = {
13
+ preserveTimestamps: true,
14
+ recursive: true,
15
+ force: true,
16
+ errorOnExist: false,
17
+ };
18
+ if (options.filter)
19
+ copyOptions.filter = options.filter;
20
+ if (fs.existsSync(options.src)) {
21
+ if (options.debug)
22
+ console.log(`copy: '${options.src}' to '${options.dest}'`);
23
+ fs.cpSync(options.src, options.dest, copyOptions);
24
+ }
25
+ else {
26
+ if (options.required !== false) {
27
+ throw new Error(`copy: source '${options.src}' does not exist`);
28
+ }
29
+ return;
30
+ }
31
+ if (options.watch) {
32
+ fs.watch(options.src, { recursive: true }, (_, filename) => {
33
+ if (filename == null)
34
+ return;
35
+ const src = path.join(options.src, filename);
36
+ const dest = path.join(options.dest, filename);
37
+ if (!fs.existsSync(src)) {
38
+ if (fs.existsSync(dest)) {
39
+ fs.rmSync(dest, {
40
+ recursive: true,
41
+ });
42
+ if (options.debug)
43
+ console.log(`copy: deleted '${options.dest}'`);
44
+ }
45
+ }
46
+ else {
47
+ if (options.filter && !options.filter(src, dest))
48
+ return;
49
+ if (options.debug)
50
+ console.log(`copy: ${src} to '${dest}'`);
51
+ fs.cpSync(src, dest, copyOptions);
52
+ }
53
+ });
54
+ }
55
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Given CLI arguments, extracts properties starting with --, separating args that do not.
3
+ *
4
+ * @param argv process args.
5
+ */
6
+ export declare function extractArgs(argv: readonly string[]): {
7
+ properties: {
8
+ [key: string]: string;
9
+ };
10
+ args: string[];
11
+ };
12
+ //# sourceMappingURL=extractArgs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractArgs.d.ts","sourceRoot":"","sources":["../../src/util/extractArgs.ts"],"names":[],"mappings":"AAKA;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,SAAS,MAAM,EAAE,GAAG;IAClD,UAAU,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAA;IACrC,IAAI,EAAE,MAAM,EAAE,CAAA;CACjB,CAcA"}
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * Given CLI arguments, extracts properties starting with --, separating args that do not.
7
+ *
8
+ * @param argv process args.
9
+ */
10
+ export function extractArgs(argv) {
11
+ const properties = {};
12
+ const args = [];
13
+ argv.forEach((item) => {
14
+ if (item.startsWith('--')) {
15
+ const split = item.substring(2).split('=', 2);
16
+ properties[split[0]] = split[1] ?? true;
17
+ }
18
+ else {
19
+ args.push(item);
20
+ }
21
+ });
22
+ return { properties, args };
23
+ }
@@ -0,0 +1,2 @@
1
+ export declare function getRootProjectDir(dir?: string): string | null;
2
+ //# sourceMappingURL=getRootProjectDir.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRootProjectDir.d.ts","sourceRoot":"","sources":["../../src/util/getRootProjectDir.ts"],"names":[],"mappings":"AAQA,wBAAgB,iBAAiB,CAAC,GAAG,GAAE,MAAsB,GAAG,MAAM,GAAG,IAAI,CAM5E"}
@@ -0,0 +1,14 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import fs from 'node:fs';
6
+ import path from 'node:path';
7
+ export function getRootProjectDir(dir = process.cwd()) {
8
+ const packageJsonPath = path.join(dir, 'package.json');
9
+ const found = fs.existsSync(packageJsonPath) ? dir : null;
10
+ const parentDir = path.resolve(dir, '..');
11
+ if (parentDir === dir)
12
+ return found; // File system root
13
+ return getRootProjectDir(parentDir) ?? found;
14
+ }
@@ -0,0 +1,2 @@
1
+ export declare function prompt(question: string): Promise<string>;
2
+ //# sourceMappingURL=prompt.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt.d.ts","sourceRoot":"","sources":["../../src/util/prompt.ts"],"names":[],"mappings":"AAOA,wBAAgB,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAYxD"}
@@ -0,0 +1,15 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import readline from 'readline';
6
+ export function prompt(question) {
7
+ const rl = readline.createInterface({
8
+ input: process.stdin,
9
+ output: process.stdout,
10
+ });
11
+ return new Promise((resolve) => rl.question(question, (answer) => {
12
+ rl.close();
13
+ resolve(answer.trim());
14
+ }));
15
+ }
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Returns a promise that resolves after a set amount of time.
3
+ * @param time The number of seconds to sleep.
4
+ */
5
+ export declare function sleep(time: number): Promise<void>;
6
+ //# sourceMappingURL=sleep.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sleep.d.ts","sourceRoot":"","sources":["../../src/util/sleep.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAIjD"}
@@ -0,0 +1,13 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * Returns a promise that resolves after a set amount of time.
7
+ * @param time The number of seconds to sleep.
8
+ */
9
+ export function sleep(time) {
10
+ return new Promise((resolve) => {
11
+ setTimeout(resolve, time * 1000);
12
+ });
13
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Parses a string with name value pairs into an object.
3
+ *
4
+ * For example:
5
+ * ```
6
+ * key1=value1
7
+ * key2=value2
8
+ * ```
9
+ *
10
+ * Becomes
11
+ *
12
+ * ```
13
+ * {
14
+ * key1: 'value1'
15
+ * key2: 'value2'
16
+ * }
17
+ * ```
18
+ *
19
+ * @param str
20
+ */
21
+ export declare function parseKeyValueStr(str: string): Record<string, string>;
22
+ //# sourceMappingURL=string.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"string.d.ts","sourceRoot":"","sources":["../../src/util/string.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAUpE"}
@@ -0,0 +1,35 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ /**
6
+ * Parses a string with name value pairs into an object.
7
+ *
8
+ * For example:
9
+ * ```
10
+ * key1=value1
11
+ * key2=value2
12
+ * ```
13
+ *
14
+ * Becomes
15
+ *
16
+ * ```
17
+ * {
18
+ * key1: 'value1'
19
+ * key2: 'value2'
20
+ * }
21
+ * ```
22
+ *
23
+ * @param str
24
+ */
25
+ export function parseKeyValueStr(str) {
26
+ const config = {};
27
+ const lines = str.split('\n');
28
+ for (const line of lines) {
29
+ if (line.includes('=')) {
30
+ const [key, value] = line.split('=', 2);
31
+ config[key.trim()] = value.trim();
32
+ }
33
+ }
34
+ return config;
35
+ }
@@ -0,0 +1,13 @@
1
+ export interface IndexFileOptions {
2
+ readonly header?: string;
3
+ readonly footer?: string;
4
+ }
5
+ /**
6
+ * Generates an index.ts for the given directory.
7
+ *
8
+ * @param dir
9
+ * @param out
10
+ * @param options Extra configuration, see {@link IndexFileOptions}
11
+ */
12
+ export declare function writeIndexFile(dir: string, out?: string, options?: IndexFileOptions): void;
13
+ //# sourceMappingURL=writeIndexFile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"writeIndexFile.d.ts","sourceRoot":"","sources":["../../src/util/writeIndexFile.ts"],"names":[],"mappings":"AAgBA,MAAM,WAAW,gBAAgB;IAC7B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;CAC3B;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC1B,GAAG,EAAE,MAAM,EACX,GAAG,GAAE,MAAY,EACjB,OAAO,CAAC,EAAE,gBAAgB,QAmF7B"}
@@ -0,0 +1,92 @@
1
+ /*
2
+ * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3
+ * SPDX-License-Identifier: Apache-2.0
4
+ */
5
+ import fs from 'node:fs';
6
+ import { glob } from 'glob';
7
+ import path from 'node:path';
8
+ import { ansi } from './console';
9
+ /**
10
+ * If --check argument is provided, do not write an index.ts file, check that the existing one
11
+ * is correct.
12
+ */
13
+ const verifyMode = process.argv.includes('--check');
14
+ /**
15
+ * Generates an index.ts for the given directory.
16
+ *
17
+ * @param dir
18
+ * @param out
19
+ * @param options Extra configuration, see {@link IndexFileOptions}
20
+ */
21
+ export function writeIndexFile(dir, out = dir, options) {
22
+ const header = options?.header ?? `/** Auto-generated from build scripts */\n`;
23
+ let footer = options?.footer ?? '';
24
+ if (footer && !footer.endsWith('\n'))
25
+ footer += '\n';
26
+ const allSrcFiles = glob.sync(`${dir}/**/*.ts`, {
27
+ ignore: ['**/index.ts', '**/@types/**'],
28
+ });
29
+ const relativePaths = allSrcFiles
30
+ .map((srcFile) => {
31
+ const importPath = path.relative(out, srcFile);
32
+ return {
33
+ importOrExport: hasExports(srcFile)
34
+ ? 'export * from'
35
+ : 'import',
36
+ path: `./${importPath.substring(0, importPath.length - 3)}`,
37
+ };
38
+ })
39
+ .sort();
40
+ const outFile = path.join(out, 'index.ts');
41
+ function fail() {
42
+ console.error(`${ansi.red}${outFile} not valid, run indexFiles:write${ansi.resetColor}`);
43
+ process.exit(1);
44
+ }
45
+ if (verifyMode) {
46
+ console.log('validating index file:', outFile);
47
+ if (!fs.existsSync(outFile)) {
48
+ fail();
49
+ }
50
+ else {
51
+ let contents = fs.readFileSync(outFile, 'utf8');
52
+ if (contents.substring(0, header.length) !== header ||
53
+ contents.substring(contents.length - footer.length, contents.length) !== footer)
54
+ fail();
55
+ contents = contents.substring(header.length, contents.length - footer.length);
56
+ const lines = contents
57
+ .split('\n')
58
+ .filter((line) => line.startsWith('export') || line.startsWith('import'));
59
+ if (lines.length !== relativePaths.length)
60
+ fail();
61
+ for (let i = 0; i < lines.length; i++) {
62
+ const { path, importOrExport } = relativePaths[i];
63
+ if (!lines[i].startsWith(importOrExport) ||
64
+ !lines[i].includes(path))
65
+ fail();
66
+ }
67
+ }
68
+ }
69
+ else {
70
+ // Write the index.ts file
71
+ let indexStr = header;
72
+ indexStr +=
73
+ relativePaths
74
+ .map(({ importOrExport, path }) => `${importOrExport} '${path}'`)
75
+ .join('\n') + '\n';
76
+ if (!fs.existsSync(out)) {
77
+ fs.mkdirSync(out, { recursive: true });
78
+ }
79
+ indexStr += footer;
80
+ fs.writeFileSync(outFile, indexStr);
81
+ console.log(`indices written to ${out}`);
82
+ }
83
+ }
84
+ /**
85
+ * Checks if the given file has any exports.
86
+ *
87
+ * @param path
88
+ */
89
+ function hasExports(path) {
90
+ const contents = fs.readFileSync(path, 'utf8');
91
+ return /(?<!['"`])\bexport\b(?![`'"])/.test(contents);
92
+ }
@@ -0,0 +1,40 @@
1
+ import type { BuildOptions } from 'esbuild';
2
+ import { type ServerOptions } from '../express/serve';
3
+ export interface VinylPackageOptions {
4
+ /**
5
+ * Can be set to add additional entry points for bundling.
6
+ */
7
+ readonly buildOptions?: BuildOptions[];
8
+ /**
9
+ * Options to apply to each esbuild target defined in `buildOptions`.
10
+ *
11
+ * Takes precedence over `commonVinylBuildOptions`
12
+ */
13
+ readonly commonOptions?: Partial<BuildOptions>;
14
+ /**
15
+ * Express server options used when invoked with `--serve`.
16
+ * Packages that opt into a dev server (e.g. vinyl) supply
17
+ * their own configuration; if omitted, `--serve` will not start a server.
18
+ */
19
+ readonly serverOptions?: ServerOptions;
20
+ }
21
+ /**
22
+ * CLI args.
23
+ */
24
+ export declare const vinylBuildCliOptions: {
25
+ release: boolean;
26
+ serve: boolean;
27
+ watch: boolean;
28
+ debug: boolean;
29
+ };
30
+ /**
31
+ * Common vinyl library build config.
32
+ */
33
+ export declare const commonVinylBuildOptions: BuildOptions;
34
+ /**
35
+ * Builds a vinyl package with inferred configuration.
36
+ *
37
+ * @param options
38
+ */
39
+ export declare function buildVinylPackage(options?: VinylPackageOptions): void;
40
+ //# sourceMappingURL=buildVinylPackage.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buildVinylPackage.d.ts","sourceRoot":"","sources":["../../src/vinyl/buildVinylPackage.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAO3C,OAAO,EAAe,KAAK,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAclE,MAAM,WAAW,mBAAmB;IAChC;;OAEG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,YAAY,EAAE,CAAA;IAEtC;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAA;IAE9C;;;;OAIG;IACH,QAAQ,CAAC,aAAa,CAAC,EAAE,aAAa,CAAA;CACzC;AAQD;;GAEG;AACH,eAAO,MAAM,oBAAoB;;;;;CAKhC,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,uBAAuB,EAAE,YAarC,CAAA;AAED;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,CAAC,EAAE,mBAAmB,QA4H9D"}