skuba 12.1.0-hoist-less-20250722131939 → 12.1.0-main-20250810101347

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 (39) hide show
  1. package/README.md +1 -2
  2. package/config/tsconfig.json +3 -2
  3. package/lib/cli/build/tsc.d.ts +5 -1
  4. package/lib/cli/build/tsc.js +12 -0
  5. package/lib/cli/build/tsc.js.map +3 -3
  6. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/index.d.ts +2 -0
  7. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/index.js +35 -0
  8. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/index.js.map +7 -0
  9. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/unhandledRejections.d.ts +4 -0
  10. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/unhandledRejections.js +162 -0
  11. package/lib/cli/lint/internalLints/upgrade/patches/12.0.2/unhandledRejections.js.map +7 -0
  12. package/lib/cli/node/index.js +8 -2
  13. package/lib/cli/node/index.js.map +2 -2
  14. package/lib/cli/start/index.js +8 -2
  15. package/lib/cli/start/index.js.map +2 -2
  16. package/lib/cli/test/index.d.ts +1 -1
  17. package/lib/cli/test/index.js +18 -4
  18. package/lib/cli/test/index.js.map +2 -2
  19. package/lib/utils/args.d.ts +2 -0
  20. package/lib/utils/args.js +5 -0
  21. package/lib/utils/args.js.map +2 -2
  22. package/package.json +14 -15
  23. package/template/base/_pnpm-workspace.yaml +1 -0
  24. package/template/express-rest-api/package.json +4 -4
  25. package/template/express-rest-api/src/listen.ts +6 -0
  26. package/template/greeter/package.json +2 -2
  27. package/template/koa-rest-api/package.json +9 -9
  28. package/template/koa-rest-api/src/framework/server.test.ts +0 -1
  29. package/template/koa-rest-api/src/listen.ts +6 -0
  30. package/template/lambda-sqs-worker-cdk/infra/__snapshots__/appStack.test.ts.snap +16 -2
  31. package/template/lambda-sqs-worker-cdk/infra/appStack.ts +5 -1
  32. package/template/lambda-sqs-worker-cdk/infra/config.ts +4 -1
  33. package/template/lambda-sqs-worker-cdk/package.json +5 -5
  34. package/template/lambda-sqs-worker-cdk/src/app.test.ts +88 -48
  35. package/template/lambda-sqs-worker-cdk/src/app.ts +7 -9
  36. package/template/lambda-sqs-worker-cdk/src/framework/handler.test.ts +8 -3
  37. package/template/lambda-sqs-worker-cdk/src/framework/handler.ts +38 -5
  38. package/template/lambda-sqs-worker-cdk/src/framework/logging.ts +11 -3
  39. package/template/lambda-sqs-worker-cdk/src/testing/handler.ts +4 -1
package/README.md CHANGED
@@ -12,11 +12,10 @@
12
12
  - Write in [TypeScript]
13
13
  - Enforce coding standards with [ESLint] and [Prettier]
14
14
  - Test with [Jest]
15
- - Deploy with [Gantry], [Serverless] or the [AWS CDK]
15
+ - Deploy with [Gantry] or the [AWS CDK]
16
16
 
17
17
  [aws cdk]: https://docs.aws.amazon.com/cdk/latest/guide/work-with-cdk-typescript.html
18
18
  [gantry]: https://backstage.myseek.xyz/docs/default/component/gantry/
19
- [serverless]: https://serverless.com/
20
19
 
21
20
  It provides you with:
22
21
 
@@ -3,9 +3,10 @@
3
3
  "incremental": true,
4
4
  "isolatedModules": true,
5
5
  "moduleResolution": "node",
6
- "resolveJsonModule": true,
6
+ "noUncheckedSideEffectImports": true,
7
7
  "noUnusedLocals": false,
8
- "noUnusedParameters": false
8
+ "noUnusedParameters": false,
9
+ "resolveJsonModule": true
9
10
  },
10
11
  "extends": "tsconfig-seek"
11
12
  }
@@ -1,4 +1,8 @@
1
1
  import ts from 'typescript';
2
- import type { Logger } from '../../utils/logging.js';
2
+ import { type Logger } from '../../utils/logging.js';
3
3
  export declare const tsc: (args?: string[]) => Promise<import("execa").ExecaReturnValue<string>>;
4
4
  export declare const readTsconfig: (args: string[] | undefined, log: Logger) => ts.ParsedCommandLine | undefined;
5
+ /**
6
+ * Extract custom conditions from tsconfig that should be passed to tsx
7
+ */
8
+ export declare const getCustomConditions: () => string[];
@@ -28,12 +28,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
  var tsc_exports = {};
30
30
  __export(tsc_exports, {
31
+ getCustomConditions: () => getCustomConditions,
31
32
  readTsconfig: () => readTsconfig,
32
33
  tsc: () => tsc
33
34
  });
34
35
  module.exports = __toCommonJS(tsc_exports);
35
36
  var import_typescript = __toESM(require("typescript"));
36
37
  var import_exec = require("../../utils/exec.js");
38
+ var import_logging = require("../../utils/logging.js");
37
39
  var import_args = require("./args.js");
38
40
  const DEFAULT_ARGS = ["--project", "tsconfig.build.json"];
39
41
  const formatHost = {
@@ -94,8 +96,18 @@ const readTsconfig = (args = process.argv.slice(2), log) => {
94
96
  }
95
97
  return parsedCommandLine;
96
98
  };
99
+ const getCustomConditions = () => {
100
+ try {
101
+ const parsedConfig = readTsconfig([], import_logging.log);
102
+ const customConditions = parsedConfig?.options.customConditions;
103
+ return Array.isArray(customConditions) ? customConditions : [];
104
+ } catch {
105
+ return [];
106
+ }
107
+ };
97
108
  // Annotate the CommonJS export names for ESM import in node:
98
109
  0 && (module.exports = {
110
+ getCustomConditions,
99
111
  readTsconfig,
100
112
  tsc
101
113
  });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/cli/build/tsc.ts"],
4
- "sourcesContent": ["import ts from 'typescript';\n\nimport { exec } from '../../utils/exec.js';\nimport type { Logger } from '../../utils/logging.js';\n\nimport { parseTscArgs } from './args.js';\n\nconst DEFAULT_ARGS = ['--project', 'tsconfig.build.json'] as const;\n\nconst formatHost: ts.FormatDiagnosticsHost = {\n getCanonicalFileName: (fileName) => fileName,\n getCurrentDirectory: ts.sys.getCurrentDirectory.bind(undefined),\n getNewLine: () => ts.sys.newLine,\n};\n\nconst tsconfigCache = new Map<string, ts.ParsedCommandLine>();\nconst computeCacheKey = (args: string[]) => Array.from(args).sort().toString();\n\nexport const tsc = async (args = process.argv.slice(2)) => {\n const tscArgs = parseTscArgs(args);\n\n // Build flag is incompatible with project flag.\n const defaultArgs = tscArgs.build || tscArgs.project ? [] : DEFAULT_ARGS;\n\n return exec('tsc', ...defaultArgs, ...args);\n};\n\nexport const readTsconfig = (args = process.argv.slice(2), log: Logger) => {\n const tscArgs = parseTscArgs(args);\n\n let parsedCommandLine = tsconfigCache.get(computeCacheKey(args));\n\n if (!parsedCommandLine) {\n log.debug(\n log.bold(\n 'tsconfig',\n ...(tscArgs.project ? ['--project', tscArgs.project] : []),\n ),\n );\n log.debug(tscArgs.pathname);\n\n const tsconfigFile = ts.findConfigFile(\n tscArgs.dirname,\n ts.sys.fileExists.bind(undefined),\n tscArgs.basename,\n );\n if (!tsconfigFile) {\n log.err(`Could not find ${tscArgs.pathname}.`);\n process.exitCode = 1;\n return;\n }\n\n const readConfigFile = ts.readConfigFile(\n tsconfigFile,\n ts.sys.readFile.bind(undefined),\n );\n if (readConfigFile.error) {\n log.err(`Could not read ${tscArgs.pathname}.`);\n log.subtle(ts.formatDiagnostic(readConfigFile.error, formatHost));\n process.exitCode = 1;\n return;\n }\n\n parsedCommandLine = ts.parseJsonConfigFileContent(\n readConfigFile.config,\n ts.sys,\n tscArgs.dirname,\n );\n tsconfigCache.set(computeCacheKey(args), parsedCommandLine);\n }\n\n if (parsedCommandLine.errors.length) {\n log.err(`Could not parse ${tscArgs.pathname}.`);\n log.subtle(ts.formatDiagnostics(parsedCommandLine.errors, formatHost));\n process.exitCode = 1;\n return;\n }\n\n return parsedCommandLine;\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAe;AAEf,kBAAqB;AAGrB,kBAA6B;AAE7B,MAAM,eAAe,CAAC,aAAa,qBAAqB;AAExD,MAAM,aAAuC;AAAA,EAC3C,sBAAsB,CAAC,aAAa;AAAA,EACpC,qBAAqB,kBAAAA,QAAG,IAAI,oBAAoB,KA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ACnB;AAAA,IACF;AAEA,wBAAoB,kBAAAA,QAAG;AAAA,MACrB,eAAe;AAAA,MACf,kBAAAA,QAAG;AAAA,MACH,QAAQ;AAAA,IACV;AACA,kBAAc,IAAI,gBAAgB,IAAI,GAAG,iBAAiB;AAAA,EAC5D;AAEA,MAAI,kBAAkB,OAAO,QAAQ;AACnC,QAAI,IAAI,mBAAmB,QAAQ,QAAQ,GAAG;AAC9C,QAAI,OAAO,kBAAAA,QAAG,kBAAkB,kBAAkB,QAAQ,UAAU,CAAC;AACrE,YAAQ,WAAW;AACnB;AAAA,EACF;AAEA,SAAO;AACT;",
6
- "names": ["ts"]
4
+ "sourcesContent": ["import ts from 'typescript';\n\nimport { exec } from '../../utils/exec.js';\nimport { type Logger, log as logger } from '../../utils/logging.js';\n\nimport { parseTscArgs } from './args.js';\n\nconst DEFAULT_ARGS = ['--project', 'tsconfig.build.json'] as const;\n\nconst formatHost: ts.FormatDiagnosticsHost = {\n getCanonicalFileName: (fileName) => fileName,\n getCurrentDirectory: ts.sys.getCurrentDirectory.bind(undefined),\n getNewLine: () => ts.sys.newLine,\n};\n\nconst tsconfigCache = new Map<string, ts.ParsedCommandLine>();\nconst computeCacheKey = (args: string[]) => Array.from(args).sort().toString();\n\nexport const tsc = async (args = process.argv.slice(2)) => {\n const tscArgs = parseTscArgs(args);\n\n // Build flag is incompatible with project flag.\n const defaultArgs = tscArgs.build || tscArgs.project ? [] : DEFAULT_ARGS;\n\n return exec('tsc', ...defaultArgs, ...args);\n};\n\nexport const readTsconfig = (args = process.argv.slice(2), log: Logger) => {\n const tscArgs = parseTscArgs(args);\n\n let parsedCommandLine = tsconfigCache.get(computeCacheKey(args));\n\n if (!parsedCommandLine) {\n log.debug(\n log.bold(\n 'tsconfig',\n ...(tscArgs.project ? ['--project', tscArgs.project] : []),\n ),\n );\n log.debug(tscArgs.pathname);\n\n const tsconfigFile = ts.findConfigFile(\n tscArgs.dirname,\n ts.sys.fileExists.bind(undefined),\n tscArgs.basename,\n );\n if (!tsconfigFile) {\n log.err(`Could not find ${tscArgs.pathname}.`);\n process.exitCode = 1;\n return;\n }\n\n const readConfigFile = ts.readConfigFile(\n tsconfigFile,\n ts.sys.readFile.bind(undefined),\n );\n if (readConfigFile.error) {\n log.err(`Could not read ${tscArgs.pathname}.`);\n log.subtle(ts.formatDiagnostic(readConfigFile.error, formatHost));\n process.exitCode = 1;\n return;\n }\n\n parsedCommandLine = ts.parseJsonConfigFileContent(\n readConfigFile.config,\n ts.sys,\n tscArgs.dirname,\n );\n tsconfigCache.set(computeCacheKey(args), parsedCommandLine);\n }\n\n if (parsedCommandLine.errors.length) {\n log.err(`Could not parse ${tscArgs.pathname}.`);\n log.subtle(ts.formatDiagnostics(parsedCommandLine.errors, formatHost));\n process.exitCode = 1;\n return;\n }\n\n return parsedCommandLine;\n};\n\n/**\n * Extract custom conditions from tsconfig that should be passed to tsx\n */\nexport const getCustomConditions = (): string[] => {\n try {\n const parsedConfig = readTsconfig([], logger);\n const customConditions = parsedConfig?.options.customConditions;\n return Array.isArray(customConditions) ? customConditions : [];\n } catch {\n return [];\n }\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAAe;AAEf,kBAAqB;AACrB,qBAA2C;AAE3C,kBAA6B;AAE7B,MAAM,eAAe,CAAC,aAAa,qBAAqB;AAExD,MAAM,aAAuC;AAAA,EAC3C,sBAAsB,CAAC,aAAa;AAAA,EACpC,qBAAqB,kBAAAA,QAAG,IAAI,oBAAoB,KAAK,MAAS;AAAA,EAC9D,YAAY,MAAM,kBAAAA,QAAG,IAAI;AAC3B;AAEA,MAAM,gBAAgB,oBAAI,IAAkC;AAC5D,MAAM,kBAAkB,CAAC,SAAmB,MAAM,KAAK,IAAI,EAAE,KAAK,EAAE,SAAS;AAEtE,MAAM,MAAM,OAAO,OAAO,QAAQ,KAAK,MAAM,CAAC,MAAM;AACzD,QAAM,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,GAAG;AAC9C,QAAI,OAAO,kBAAAA,QAAG,kBAAkB,kBAAkB,QAAQ,UAAU,CAAC;AACrE,YAAQ,WAAW;AACnB;AAAA,EACF;AAEA,SAAO;AACT;AAKO,MAAM,sBAAsB,MAAgB;AACjD,MAAI;AACF,UAAM,eAAe,aAAa,CAAC,GAAG,eAAAC,GAAM;AAC5C,UAAM,mBAAmB,cAAc,QAAQ;AAC/C,WAAO,MAAM,QAAQ,gBAAgB,IAAI,mBAAmB,CAAC;AAAA,EAC/D,QAAQ;AACN,WAAO,CAAC;AAAA,EACV;AACF;",
6
+ "names": ["ts", "logger"]
7
7
  }
@@ -0,0 +1,2 @@
1
+ import type { Patches } from '../../index.js';
2
+ export declare const patches: Patches;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var __exports = {};
20
+ __export(__exports, {
21
+ patches: () => patches
22
+ });
23
+ module.exports = __toCommonJS(__exports);
24
+ var import_unhandledRejections = require("./unhandledRejections.js");
25
+ const patches = [
26
+ {
27
+ apply: import_unhandledRejections.tryPatchUnhandledRejections,
28
+ description: "Add event handler to log unhandled promise rejections instead of crashing the process"
29
+ }
30
+ ];
31
+ // Annotate the CommonJS export names for ESM import in node:
32
+ 0 && (module.exports = {
33
+ patches
34
+ });
35
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../../src/cli/lint/internalLints/upgrade/patches/12.0.2/index.ts"],
4
+ "sourcesContent": ["import type { Patches } from '../../index.js';\n\nimport { tryPatchUnhandledRejections } from './unhandledRejections.js';\n\nexport const patches: Patches = [\n {\n apply: tryPatchUnhandledRejections,\n description:\n 'Add event handler to log unhandled promise rejections instead of crashing the process',\n },\n];\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,iCAA4C;AAErC,MAAM,UAAmB;AAAA,EAC9B;AAAA,IACE,OAAO;AAAA,IACP,aACE;AAAA,EACJ;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,4 @@
1
+ import type { PatchFunction } from '../../index.js';
2
+ export declare const IMPORT_REGEX: RegExp;
3
+ export declare const NAMED_EXPORT_REGEX: RegExp;
4
+ export declare const tryPatchUnhandledRejections: PatchFunction;
@@ -0,0 +1,162 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var unhandledRejections_exports = {};
30
+ __export(unhandledRejections_exports, {
31
+ IMPORT_REGEX: () => IMPORT_REGEX,
32
+ NAMED_EXPORT_REGEX: () => NAMED_EXPORT_REGEX,
33
+ tryPatchUnhandledRejections: () => tryPatchUnhandledRejections
34
+ });
35
+ module.exports = __toCommonJS(unhandledRejections_exports);
36
+ var import_path = __toESM(require("path"));
37
+ var import_util = require("util");
38
+ var import_fast_glob = require("fast-glob");
39
+ var import_fs_extra = __toESM(require("fs-extra"));
40
+ var import_error = require("../../../../../../utils/error.js");
41
+ var import_logging = require("../../../../../../utils/logging.js");
42
+ var import_prettier = require("../../../../../configure/processing/prettier.js");
43
+ const addListener = (identifier) => `
44
+ // Report unhandled rejections instead of crashing the process
45
+ // Make sure to monitor these reports and alert as appropriate
46
+ process.on('unhandledRejection', (err) =>
47
+ ${identifier}.error(err, 'Unhandled promise rejection'),
48
+ );
49
+ `.trim();
50
+ const tryReadFilesSequentially = async (filepaths) => {
51
+ for (const filepath of filepaths) {
52
+ try {
53
+ const contents = await import_fs_extra.default.promises.readFile(filepath, "utf8");
54
+ return { contents, filepath };
55
+ } catch (err) {
56
+ if ((0, import_error.isErrorWithCode)(err, "ENOENT")) {
57
+ continue;
58
+ }
59
+ throw err;
60
+ }
61
+ }
62
+ return;
63
+ };
64
+ const IMPORT_REGEX = /import\s+(?:\{\s*(\w*[Ll]ogger)(?:\s+as\s+(\w*[Ll]ogger))?\s*\}|(\w*[Ll]ogger))\s+from\s+['"][^'"]+\/(?:logger|logging)(?:\/index)?(?:\.[jt]s)?['"]/u;
65
+ const NAMED_EXPORT_REGEX = /export\s+(?:const\s+|\{[^{}]*)\b(\w*[Ll]ogger)\b/u;
66
+ const findLogger = async ({
67
+ contents,
68
+ root
69
+ }) => {
70
+ const importResult = IMPORT_REGEX.exec(contents);
71
+ {
72
+ const identifier = importResult?.[3] ?? importResult?.[2] ?? importResult?.[1];
73
+ if (identifier) {
74
+ return { identifier };
75
+ }
76
+ }
77
+ const loggerPaths = await (0, import_fast_glob.glob)("**/{logger,logging}.ts", {
78
+ cwd: root,
79
+ ignore: ["**/.git", "**/node_modules"]
80
+ });
81
+ const loggingModule = await tryReadFilesSequentially(loggerPaths);
82
+ if (!loggingModule) {
83
+ return { identifier: "console" };
84
+ }
85
+ const parsedPath = import_path.default.parse(import_path.default.relative(root, loggingModule.filepath));
86
+ const importPath = import_path.default.join(parsedPath.dir, parsedPath.name);
87
+ const namedExportResult = NAMED_EXPORT_REGEX.exec(loggingModule.contents);
88
+ if (namedExportResult?.[1]) {
89
+ const identifier = namedExportResult[1];
90
+ return {
91
+ identifier: namedExportResult[1],
92
+ import: `import { ${identifier} } from '${importPath}';`
93
+ };
94
+ }
95
+ if (loggingModule.contents.includes("export default")) {
96
+ return {
97
+ identifier: "logger",
98
+ import: `import logger from '${importPath}';`
99
+ };
100
+ }
101
+ return { identifier: "console" };
102
+ };
103
+ const patchUnhandledRejections = async (mode) => {
104
+ const filepaths = await (0, import_fast_glob.glob)("**/src/listen.ts", {
105
+ ignore: ["**/.git", "**/node_modules"]
106
+ });
107
+ let hasPatched = false;
108
+ for (const filepath of filepaths) {
109
+ const contents = await import_fs_extra.default.promises.readFile(filepath, "utf8");
110
+ if (contents.includes("unhandledRejection")) {
111
+ import_logging.log.subtle(
112
+ "Skipping entry point that appears to have an unhandled rejection listener:",
113
+ filepath
114
+ );
115
+ continue;
116
+ }
117
+ const root = import_path.default.dirname(import_path.default.dirname(filepath));
118
+ const logger = await findLogger({ contents, root });
119
+ import_logging.log.subtle(
120
+ "Logging unhandled rejections to",
121
+ logger.identifier,
122
+ "in file:",
123
+ filepath
124
+ );
125
+ const patched = [
126
+ contents,
127
+ ...[logger.import ? [logger.import] : []],
128
+ addListener(logger.identifier)
129
+ ].join("\n\n");
130
+ const newContents = await (0, import_prettier.formatPrettier)(patched, { parser: "typescript" });
131
+ if (mode === "lint") {
132
+ return { result: "apply" };
133
+ }
134
+ await import_fs_extra.default.promises.writeFile(filepath, newContents);
135
+ hasPatched = true;
136
+ }
137
+ if (hasPatched) {
138
+ return { result: "apply" };
139
+ }
140
+ return {
141
+ result: "skip",
142
+ reason: "no applicable src/listen.ts entry points found"
143
+ };
144
+ };
145
+ const tryPatchUnhandledRejections = async ({
146
+ mode
147
+ }) => {
148
+ try {
149
+ return await patchUnhandledRejections(mode);
150
+ } catch (err) {
151
+ import_logging.log.warn("Failed to patch listeners for unhandled promise rejections");
152
+ import_logging.log.subtle((0, import_util.inspect)(err));
153
+ return { result: "skip", reason: "due to an error" };
154
+ }
155
+ };
156
+ // Annotate the CommonJS export names for ESM import in node:
157
+ 0 && (module.exports = {
158
+ IMPORT_REGEX,
159
+ NAMED_EXPORT_REGEX,
160
+ tryPatchUnhandledRejections
161
+ });
162
+ //# sourceMappingURL=unhandledRejections.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../../src/cli/lint/internalLints/upgrade/patches/12.0.2/unhandledRejections.ts"],
4
+ "sourcesContent": ["import path from 'path';\nimport { inspect } from 'util';\n\nimport { glob } from 'fast-glob';\nimport fs from 'fs-extra';\n\nimport { isErrorWithCode } from '../../../../../../utils/error.js';\nimport { log } from '../../../../../../utils/logging.js';\nimport { formatPrettier } from '../../../../../configure/processing/prettier.js';\nimport type { PatchFunction, PatchReturnType } from '../../index.js';\n\nconst addListener = (identifier: string) =>\n `\n// Report unhandled rejections instead of crashing the process\n// Make sure to monitor these reports and alert as appropriate\nprocess.on('unhandledRejection', (err) =>\n ${identifier}.error(err, 'Unhandled promise rejection'),\n);\n`.trim();\n\nconst tryReadFilesSequentially = async (\n filepaths: string[],\n): Promise<{ contents: string; filepath: string } | undefined> => {\n for (const filepath of filepaths) {\n try {\n const contents = await fs.promises.readFile(filepath, 'utf8');\n\n return { contents, filepath };\n } catch (err) {\n if (isErrorWithCode(err, 'ENOENT')) {\n continue;\n }\n\n throw err;\n }\n }\n\n return;\n};\n\nexport const IMPORT_REGEX =\n /import\\s+(?:\\{\\s*(\\w*[Ll]ogger)(?:\\s+as\\s+(\\w*[Ll]ogger))?\\s*\\}|(\\w*[Ll]ogger))\\s+from\\s+['\"][^'\"]+\\/(?:logger|logging)(?:\\/index)?(?:\\.[jt]s)?['\"]/u;\n\nexport const NAMED_EXPORT_REGEX =\n /export\\s+(?:const\\s+|\\{[^{}]*)\\b(\\w*[Ll]ogger)\\b/u;\n\nconst findLogger = async ({\n contents,\n root,\n}: {\n contents: string;\n root: string;\n}): Promise<{ identifier: string; import?: string }> => {\n const importResult = IMPORT_REGEX.exec(contents);\n\n {\n const identifier =\n importResult?.[3] ?? importResult?.[2] ?? importResult?.[1];\n\n if (identifier) {\n return { identifier };\n }\n }\n\n const loggerPaths = await glob('**/{logger,logging}.ts', {\n cwd: root,\n ignore: ['**/.git', '**/node_modules'],\n });\n\n const loggingModule = await tryReadFilesSequentially(loggerPaths);\n\n if (!loggingModule) {\n return { identifier: 'console' };\n }\n\n const parsedPath = path.parse(path.relative(root, loggingModule.filepath));\n\n const importPath = path.join(parsedPath.dir, parsedPath.name);\n\n const namedExportResult = NAMED_EXPORT_REGEX.exec(loggingModule.contents);\n\n if (namedExportResult?.[1]) {\n const identifier = namedExportResult[1];\n\n return {\n identifier: namedExportResult[1],\n import: `import { ${identifier} } from '${importPath}';`,\n };\n }\n\n if (loggingModule.contents.includes('export default')) {\n return {\n identifier: 'logger',\n import: `import logger from '${importPath}';`,\n };\n }\n\n return { identifier: 'console' };\n};\n\nconst patchUnhandledRejections = async (\n mode: 'format' | 'lint',\n): Promise<PatchReturnType> => {\n const filepaths = await glob('**/src/listen.ts', {\n ignore: ['**/.git', '**/node_modules'],\n });\n\n let hasPatched = false;\n\n for (const filepath of filepaths) {\n const contents = await fs.promises.readFile(filepath, 'utf8');\n\n if (contents.includes('unhandledRejection')) {\n log.subtle(\n 'Skipping entry point that appears to have an unhandled rejection listener:',\n filepath,\n );\n continue;\n }\n\n const root = path.dirname(path.dirname(filepath));\n\n const logger = await findLogger({ contents, root });\n\n log.subtle(\n 'Logging unhandled rejections to',\n logger.identifier,\n 'in file:',\n filepath,\n );\n\n const patched = [\n contents,\n\n ...[logger.import ? [logger.import] : []],\n\n addListener(logger.identifier),\n ].join('\\n\\n');\n\n const newContents = await formatPrettier(patched, { parser: 'typescript' });\n\n if (mode === 'lint') {\n return { result: 'apply' };\n }\n\n await fs.promises.writeFile(filepath, newContents);\n\n hasPatched = true;\n }\n\n if (hasPatched) {\n return { result: 'apply' };\n }\n\n return {\n result: 'skip',\n reason: 'no applicable src/listen.ts entry points found',\n };\n};\n\nexport const tryPatchUnhandledRejections: PatchFunction = async ({\n mode,\n}): Promise<PatchReturnType> => {\n try {\n return await patchUnhandledRejections(mode);\n } catch (err) {\n log.warn('Failed to patch listeners for unhandled promise rejections');\n log.subtle(inspect(err));\n return { result: 'skip', reason: 'due to an error' };\n }\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AACjB,kBAAwB;AAExB,uBAAqB;AACrB,sBAAe;AAEf,mBAAgC;AAChC,qBAAoB;AACpB,sBAA+B;AAG/B,MAAM,cAAc,CAAC,eACnB;AAAA;AAAA;AAAA;AAAA,IAIE,UAAU;AAAA;AAAA,EAEZ,KAAK;AAEP,MAAM,2BAA2B,OAC/B,cACgE;AAChE,aAAW,YAAY,WAAW;AAChC,QAAI;AACF,YAAM,WAAW,MAAM,gBAAAA,QAAG,SAAS,SAAS,UAAU,MAA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kB;AAAA,EACrD;AACF;",
6
+ "names": ["fs", "path"]
7
+ }
@@ -38,14 +38,20 @@ var import_get_port = __toESM(require("get-port"));
38
38
  var import_args = require("../../utils/args.js");
39
39
  var import_exec = require("../../utils/exec.js");
40
40
  var import_validation = require("../../utils/validation.js");
41
+ var import_tsc = require("../build/tsc.js");
41
42
  const longRunning = true;
42
43
  const node = async () => {
43
44
  const args = (0, import_args.parseRunArgs)(process.argv.slice(2));
45
+ const customConditions = (0, import_tsc.getCustomConditions)();
46
+ const uniqueConditions = [
47
+ .../* @__PURE__ */ new Set([...args.conditions ?? [], ...customConditions])
48
+ ];
44
49
  const availablePort = await (0, import_get_port.default)();
45
50
  const commonArgs = [
46
51
  ...args.node,
47
- "--require",
48
- require.resolve("dotenv/config"),
52
+ ...uniqueConditions.map((condition) => `--conditions=${condition}`),
53
+ "--env-file-if-exists",
54
+ ".env",
49
55
  "--require",
50
56
  require.resolve("tsconfig-paths/register")
51
57
  ];
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/cli/node/index.ts"],
4
- "sourcesContent": ["import path from 'path';\n\nimport execa from 'execa';\nimport getPort from 'get-port';\n\nimport { parseRunArgs } from '../../utils/args.js';\nimport { createExec } from '../../utils/exec.js';\nimport { isIpPort } from '../../utils/validation.js';\n\nexport const longRunning = true;\n\nexport const node = async () => {\n const args = parseRunArgs(process.argv.slice(2));\n\n const availablePort = await getPort();\n\n const commonArgs = [\n ...args.node,\n '--require',\n require.resolve('dotenv/config'),\n '--require',\n require.resolve('tsconfig-paths/register'),\n ];\n\n if (args.entryPoint) {\n const exec = createExec({\n env: {\n __SKUBA_ENTRY_POINT: args.entryPoint,\n __SKUBA_PORT: String(isIpPort(args.port) ? args.port : availablePort),\n },\n });\n\n return exec(\n 'tsx',\n ...commonArgs,\n path.join(__dirname, '..', '..', 'wrapper', 'index.js'),\n ...args.script,\n );\n }\n\n return execa(\n require.resolve('tsx/cli'),\n [\n ...commonArgs,\n '--require',\n // Unsure if bug or feature that this is needed, but tsx appears to not do anything typescript in the REPL without this!\n // Doesn't occur when just running the tsx binary directly \uD83E\uDDD0\n require.resolve('tsx/patch-repl'),\n ],\n {\n stdio: 'inherit',\n },\n );\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AAEjB,mBAAkB;AAClB,sBAAoB;AAEpB,kBAA6B;AAC7B,kBAA2B;AAC3B,wBAAyB;AAElB,MAAM,cAAc;AAEpB,MAAM,OAAO,YAAY;AAC9B,QAAM,WAAO,0BAAa,QAAQ,KAAK,MAAM,CAAC,CAAC;AAE/C,QAAM,gBAAgB,UAAM,gBAAAA,SAAQ;AAEpC,QAAM,aAAa;AAAA,IACjB,GAAG,KAAK;AAAA,IACR;AAAA,IACA,gBAAgB,eAAe;AAAA,IAC/B;AAAA,IACA,gBAAgB,yBAAyB;AAAA,EAC3C;AAEA,MAAI,KAAK,YAAY;AACnB,UAAM,WAAO,wBAAW;AAAA,MACtB,KAAK;AAAA,QACH,qBAAqB,KAAK;AAAA,QAC1B,cAAc,WAAO,4BAAS,KAAK,IAAI,IAAI,KAAK,OAAO,aAAa;AAAA,MACtE;AAAA,IACF,CAAC;AAED,WAAO;AAAA,MACL;AAAA,MACA,GAAG;AAAA,MACH,YAAAC,QAAK,KAAK,WAAW,MAAM,MAAM,WAAW,UAAU;AAAA,MACtD,GAAG,KAAK;AAAA,IACV;AAAA,EACF;AAEA,aAAO,aAAAC;AAAA,IACL,gBAAgB,SAAS;AAAA,IACzB;AAAA,MACE,GAAG;AAAA,MACH;AAAA;AAAA;AAAA,MAGA,gBAAgB,gBAAgB;AAAA,IAClC;AAAA,IACA;AAAA,MACE,OAAO;AAAA,IACT;AAAA,EACF;AACF;",
4
+ "sourcesContent": ["import path from 'path';\n\nimport execa from 'execa';\nimport getPort from 'get-port';\n\nimport { parseRunArgs } from '../../utils/args.js';\nimport { createExec } from '../../utils/exec.js';\nimport { isIpPort } from '../../utils/validation.js';\nimport { getCustomConditions } from '../build/tsc.js';\n\nexport const longRunning = true;\n\nexport const node = async () => {\n const args = parseRunArgs(process.argv.slice(2));\n const customConditions = getCustomConditions();\n\n const uniqueConditions = [\n ...new Set([...(args.conditions ?? []), ...customConditions]),\n ];\n\n const availablePort = await getPort();\n\n const commonArgs = [\n ...args.node,\n ...uniqueConditions.map((condition) => `--conditions=${condition}`),\n '--env-file-if-exists',\n '.env',\n '--require',\n require.resolve('tsconfig-paths/register'),\n ];\n\n if (args.entryPoint) {\n const exec = createExec({\n env: {\n __SKUBA_ENTRY_POINT: args.entryPoint,\n __SKUBA_PORT: String(isIpPort(args.port) ? args.port : availablePort),\n },\n });\n\n return exec(\n 'tsx',\n ...commonArgs,\n path.join(__dirname, '..', '..', 'wrapper', 'index.js'),\n ...args.script,\n );\n }\n\n return execa(\n require.resolve('tsx/cli'),\n [\n ...commonArgs,\n '--require',\n // Unsure if bug or feature that this is needed, but tsx appears to not do anything typescript in the REPL without this!\n // Doesn't occur when just running the tsx binary directly \uD83E\uDDD0\n require.resolve('tsx/patch-repl'),\n ],\n {\n stdio: 'inherit',\n },\n );\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AAEjB,mBAAkB;AAClB,sBAAoB;AAEpB,kBAA6B;AAC7B,kBAA2B;AAC3B,wBAAyB;AACzB,iBAAoC;AAE7B,MAAM,cAAc;AAEpB,MAAM,OAAO,YAAY;AAC9B,QAAM,WAAO,0BAAa,QAAQ,KAAK,MAAM,CAAC,CAAC;AAC/C,QAAM,uBAAmB,gCAAoB;AAE7C,QAAM,mBAAmB;AAAA,IACvB,GAAG,oBAAI,IAAI,CAAC,GAAI,KAAK,cAAc,CAAC,GAAI,GAAG,gBAAgB,CAAC;AAAA,EAC9D;AAEA,QAAM,gBAAgB,UAAM,gBAAAA,SAAQ;AAEpC,QAAM,aAAa;AAAA,IACjB,GAAG,KAAK;AAAA,IACR,GAAG,iBAAiB,IAAI,CAAC,cAAc,gBAAgB,SAAS,EAAE;AAAA,IAClE;AAAA,IACA;AAAA,IACA;AAAA,IACA,gBAAgB,yBAAyB;AAAA,EAC3C;AAEA,MAAI,KAAK,YAAY;AACnB,UAAM,WAAO,wBAAW;AAAA,MACtB,KAAK;AAAA,QACH,qBAAqB,KAAK;AAAA,QAC1B,cAAc,WAAO,4BAAS,KAAK,IAAI,IAAI,KAAK,OAAO,aAAa;AAAA,MACtE;AAAA,IACF,CAAC;AAED,WAAO;AAAA,MACL;AAAA,MACA,GAAG;AAAA,MACH,YAAAC,QAAK,KAAK,WAAW,MAAM,MAAM,WAAW,UAAU;AAAA,MACtD,GAAG,KAAK;AAAA,IACV;AAAA,EACF;AAEA,aAAO,aAAAC;AAAA,IACL,gBAAgB,SAAS;AAAA,IACzB;AAAA,MACE,GAAG;AAAA,MACH;AAAA;AAAA;AAAA,MAGA,gBAAgB,gBAAgB;AAAA,IAClC;AAAA,IACA;AAAA,MACE,OAAO;AAAA,IACT;AAAA,EACF;AACF;",
6
6
  "names": ["getPort", "path", "execa"]
7
7
  }
@@ -37,11 +37,16 @@ var import_args = require("../../utils/args.js");
37
37
  var import_exec = require("../../utils/exec.js");
38
38
  var import_manifest = require("../../utils/manifest.js");
39
39
  var import_validation = require("../../utils/validation.js");
40
+ var import_tsc = require("../build/tsc.js");
40
41
  const start = async () => {
42
+ const customConditions = (0, import_tsc.getCustomConditions)();
41
43
  const [args, availablePort] = await Promise.all([
42
44
  (0, import_args.parseRunArgs)(process.argv.slice(2)),
43
45
  (0, import_get_port.default)()
44
46
  ]);
47
+ const uniqueConditions = [
48
+ .../* @__PURE__ */ new Set([...args.conditions ?? [], ...customConditions])
49
+ ];
45
50
  args.entryPoint ??= await (0, import_manifest.getEntryPointFromManifest)();
46
51
  const execProcess = (0, import_exec.createExec)({
47
52
  env: {
@@ -54,8 +59,9 @@ const start = async () => {
54
59
  "watch",
55
60
  "--clear-screen=false",
56
61
  ...args.node,
57
- "--require",
58
- "dotenv/config",
62
+ ...uniqueConditions.map((condition) => `--conditions=${condition}`),
63
+ "--env-file-if-exists",
64
+ ".env",
59
65
  "--require",
60
66
  "tsconfig-paths/register",
61
67
  import_path.default.join(__dirname, "..", "..", "wrapper", "index.js"),
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/cli/start/index.ts"],
4
- "sourcesContent": ["import path from 'path';\n\nimport getPort from 'get-port';\n\nimport { parseRunArgs } from '../../utils/args.js';\nimport { createExec } from '../../utils/exec.js';\nimport { getEntryPointFromManifest } from '../../utils/manifest.js';\nimport { isIpPort } from '../../utils/validation.js';\n\nexport const start = async () => {\n const [args, availablePort] = await Promise.all([\n parseRunArgs(process.argv.slice(2)),\n getPort(),\n ]);\n\n args.entryPoint ??= await getEntryPointFromManifest();\n\n const execProcess = createExec({\n env: {\n __SKUBA_ENTRY_POINT: args.entryPoint,\n __SKUBA_PORT: String(isIpPort(args.port) ? args.port : availablePort),\n },\n });\n\n return execProcess(\n 'tsx',\n 'watch',\n '--clear-screen=false',\n ...args.node,\n '--require',\n 'dotenv/config',\n '--require',\n 'tsconfig-paths/register',\n path.join(__dirname, '..', '..', 'wrapper', 'index.js'),\n ...args.script,\n );\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AAEjB,sBAAoB;AAEpB,kBAA6B;AAC7B,kBAA2B;AAC3B,sBAA0C;AAC1C,wBAAyB;AAElB,MAAM,QAAQ,YAAY;AAC/B,QAAM,CAAC,MAAM,aAAa,IAAI,MAAM,QAAQ,IAAI;AAAA,QAC9C,0BAAa,QAAQ,KAAK,MAAM,CAAC,CAAC;AAAA,QAClC,gBAAAA,SAAQ;AAAA,EACV,CAAC;AAED,OAAK,eAAe,UAAM,2CAA0B;AAEpD,QAAM,kBAAc,wBAAW;AAAA,IAC7B,KAAK;AAAA,MACH,qBAAqB,KAAK;AAAA,MAC1B,cAAc,WAAO,4BAAS,KAAK,IAAI,IAAI,KAAK,OAAO,aAAa;AAAA,IACtE;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG,KAAK;AAAA,IACR;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAAC,QAAK,KAAK,WAAW,MAAM,MAAM,WAAW,UAAU;AAAA,IACtD,GAAG,KAAK;AAAA,EACV;AACF;",
4
+ "sourcesContent": ["import path from 'path';\n\nimport getPort from 'get-port';\n\nimport { parseRunArgs } from '../../utils/args.js';\nimport { createExec } from '../../utils/exec.js';\nimport { getEntryPointFromManifest } from '../../utils/manifest.js';\nimport { isIpPort } from '../../utils/validation.js';\nimport { getCustomConditions } from '../build/tsc.js';\n\nexport const start = async () => {\n const customConditions = getCustomConditions();\n const [args, availablePort] = await Promise.all([\n parseRunArgs(process.argv.slice(2)),\n getPort(),\n ]);\n\n const uniqueConditions = [\n ...new Set([...(args.conditions ?? []), ...customConditions]),\n ];\n\n args.entryPoint ??= await getEntryPointFromManifest();\n\n const execProcess = createExec({\n env: {\n __SKUBA_ENTRY_POINT: args.entryPoint,\n __SKUBA_PORT: String(isIpPort(args.port) ? args.port : availablePort),\n },\n });\n\n return execProcess(\n 'tsx',\n 'watch',\n '--clear-screen=false',\n ...args.node,\n ...uniqueConditions.map((condition) => `--conditions=${condition}`),\n '--env-file-if-exists',\n '.env',\n '--require',\n 'tsconfig-paths/register',\n path.join(__dirname, '..', '..', 'wrapper', 'index.js'),\n ...args.script,\n );\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAiB;AAEjB,sBAAoB;AAEpB,kBAA6B;AAC7B,kBAA2B;AAC3B,sBAA0C;AAC1C,wBAAyB;AACzB,iBAAoC;AAE7B,MAAM,QAAQ,YAAY;AAC/B,QAAM,uBAAmB,gCAAoB;AAC7C,QAAM,CAAC,MAAM,aAAa,IAAI,MAAM,QAAQ,IAAI;AAAA,QAC9C,0BAAa,QAAQ,KAAK,MAAM,CAAC,CAAC;AAAA,QAClC,gBAAAA,SAAQ;AAAA,EACV,CAAC;AAED,QAAM,mBAAmB;AAAA,IACvB,GAAG,oBAAI,IAAI,CAAC,GAAI,KAAK,cAAc,CAAC,GAAI,GAAG,gBAAgB,CAAC;AAAA,EAC9D;AAEA,OAAK,eAAe,UAAM,2CAA0B;AAEpD,QAAM,kBAAc,wBAAW;AAAA,IAC7B,KAAK;AAAA,MACH,qBAAqB,KAAK;AAAA,MAC1B,cAAc,WAAO,4BAAS,KAAK,IAAI,IAAI,KAAK,OAAO,aAAa;AAAA,IACtE;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA,GAAG,KAAK;AAAA,IACR,GAAG,iBAAiB,IAAI,CAAC,cAAc,gBAAgB,SAAS,EAAE;AAAA,IAClE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,YAAAC,QAAK,KAAK,WAAW,MAAM,MAAM,WAAW,UAAU;AAAA,IACtD,GAAG,KAAK;AAAA,EACV;AACF;",
6
6
  "names": ["getPort", "path"]
7
7
  }
@@ -1 +1 @@
1
- export declare const test: () => Promise<void>;
1
+ export declare const test: () => Promise<import("execa").ExecaReturnValue<string>>;
@@ -1,7 +1,9 @@
1
1
  "use strict";
2
+ var __create = Object.create;
2
3
  var __defProp = Object.defineProperty;
3
4
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
5
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
5
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
6
8
  var __export = (target, all) => {
7
9
  for (var name in all)
@@ -15,18 +17,30 @@ var __copyProps = (to, from, except, desc) => {
15
17
  }
16
18
  return to;
17
19
  };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
18
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
29
  var test_exports = {};
20
30
  __export(test_exports, {
21
31
  test: () => test
22
32
  });
23
33
  module.exports = __toCommonJS(test_exports);
24
- var import_jest = require("jest");
34
+ var import_exec = require("../../utils/exec.js");
25
35
  const test = async () => {
26
- process.env.NODE_ENV ??= "test";
27
- process.env.TS_JEST_LOG ??= "stdout:error";
28
36
  const argv = process.argv.slice(2);
29
- return (0, import_jest.run)(argv);
37
+ const nodeOptions = process.env.NODE_OPTIONS ?? "";
38
+ const execWithEnv = (0, import_exec.createExec)({
39
+ env: {
40
+ NODE_OPTIONS: !nodeOptions.includes("--experimental-vm-modules") ? `${nodeOptions} --experimental-vm-modules --no-warnings=ExperimentalWarning` : nodeOptions
41
+ }
42
+ });
43
+ return execWithEnv(require.resolve("jest/bin/jest"), ...argv);
30
44
  };
31
45
  // Annotate the CommonJS export names for ESM import in node:
32
46
  0 && (module.exports = {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/cli/test/index.ts"],
4
- "sourcesContent": ["import { run } from 'jest';\n\nexport const test = async () => {\n // This is usually set in `jest-cli`'s binary wrapper\n process.env.NODE_ENV ??= 'test';\n\n // ts-jest is logging a warning about `isolatedModules`.\n // This is a workaround until we can remove the `isolatedModules` option.\n // https://github.com/seek-oss/skuba/issues/1841\n process.env.TS_JEST_LOG ??= 'stdout:error';\n\n const argv = process.argv.slice(2);\n\n return run(argv);\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAoB;AAEb,MAAM,OAAO,YAAY;AAE9B,UAAQ,IAAI,aAAa;AAKzB,UAAQ,IAAI,gBAAgB;AAE5B,QAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AAEjC,aAAO,iBAAI,IAAI;AACjB;",
4
+ "sourcesContent": ["import { createExec } from '../../utils/exec.js';\n\nexport const test = async () => {\n const argv = process.argv.slice(2);\n\n const nodeOptions = process.env.NODE_OPTIONS ?? '';\n\n const execWithEnv = createExec({\n env: {\n NODE_OPTIONS: !nodeOptions.includes('--experimental-vm-modules')\n ? `${nodeOptions} --experimental-vm-modules --no-warnings=ExperimentalWarning`\n : nodeOptions,\n },\n });\n\n // Run Jest in a child process with proper environment\n return execWithEnv(require.resolve('jest/bin/jest'), ...argv);\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAA2B;AAEpB,MAAM,OAAO,YAAY;AAC9B,QAAM,OAAO,QAAQ,KAAK,MAAM,CAAC;AAEjC,QAAM,cAAc,QAAQ,IAAI,gBAAgB;AAEhD,QAAM,kBAAc,wBAAW;AAAA,IAC7B,KAAK;AAAA,MACH,cAAc,CAAC,YAAY,SAAS,2BAA2B,IAC3D,GAAG,WAAW,iEACd;AAAA,IACN;AAAA,EACF,CAAC;AAGD,SAAO,YAAY,gBAAgB,eAAe,GAAG,GAAG,IAAI;AAC9D;",
6
6
  "names": []
7
7
  }
@@ -18,6 +18,8 @@ export declare const parseProcessArgs: (args?: string[]) => {
18
18
  args: string[];
19
19
  };
20
20
  interface RunArgs {
21
+ /** The conditions to pass to the entry point script. */
22
+ conditions?: string[];
21
23
  /** The path to the entry point script. */
22
24
  entryPoint?: string;
23
25
  /** The port to start an HTTP server on. */
package/lib/utils/args.js CHANGED
@@ -100,6 +100,11 @@ const parseRunArgsIteration = (state, args) => {
100
100
  }
101
101
  return args.slice(1);
102
102
  }
103
+ if (arg1.startsWith("--conditions=")) {
104
+ state.conditions ??= [];
105
+ state.conditions.push(arg1.slice(13));
106
+ return args.slice(1);
107
+ }
103
108
  state.entryPoint = arg1;
104
109
  state.script.push(...args.slice(1));
105
110
  return [];
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/utils/args.ts"],
4
- "sourcesContent": ["import assert from 'assert';\n\nimport { COMMAND_ALIASES } from './command.js';\n\nexport const hasDebugFlag = (args = process.argv) =>\n args.some((arg) => arg.toLocaleLowerCase() === '--debug');\n\nexport const hasSerialFlag = (args = process.argv, env = process.env) =>\n args.some((arg) => arg.toLocaleLowerCase() === '--serial') ||\n Boolean(\n // Run serially on SEEK's central npm publishing pipeline.\n // Exhausting agents here can cause grief.\n env.BUILDKITE_AGENT_META_DATA_QUEUE?.split(',').some((queueName) =>\n queueName.startsWith('artefacts:npm'),\n ),\n );\n\n/**\n * Parse process arguments.\n *\n * This function mutates the input list by removing the command name element.\n * Downstream commands can access their args with an ordinary\n * `process.argv.slice(2)`.\n *\n * Example input:\n *\n * ```typescript\n * ['/bin/node', 'node_modules/.bin/skuba', 'test', '--foo', '--bar']\n * ```\n */\nexport const parseProcessArgs = (args = process.argv) => {\n const skubaIdx = args.findIndex((chunk) => /skuba(\\.[jt]s)?$/.test(chunk));\n\n assert(skubaIdx >= 0, 'Cannot parse args for `skuba`');\n\n const rawCommand = (args[skubaIdx + 1] ?? 'help').toLocaleLowerCase();\n\n const commandName = COMMAND_ALIASES[rawCommand] ?? rawCommand;\n\n const payload = {\n commandName,\n args: args.slice(skubaIdx + 2),\n };\n\n args.splice(skubaIdx + 1, 1);\n\n return payload;\n};\n\ninterface RunArgs {\n /** The path to the entry point script. */\n entryPoint?: string;\n\n /** The port to start an HTTP server on. */\n port?: number;\n\n /** Arguments passed through to the Node.js executable. */\n node: string[];\n\n /** Arguments passed through to the entry point script. */\n script: string[];\n}\n\n/**\n * Make a best effort to parse \"run\" args.\n *\n * These are arguments that would be passed to `skuba node` or `skuba start`.\n * Parsing is handrolled because we support some weird and wonderful behaviour:\n *\n * - The `--port` option may be intended for skuba itself\n * - The `--inspect` options may be intended for the Node.js inspector\n * - The entry point may be omitted in favour of `package.json` inference\n * - Other args may be intended for propagation to the entry point\n */\nexport const parseRunArgs = (argv: string[]): RunArgs => {\n const state: RunArgs = {\n node: [],\n script: [],\n };\n\n let args = argv.filter((element) => element.length);\n\n while (args.length) {\n args = parseRunArgsIteration(state, args);\n }\n\n return state;\n};\n\nconst isDigits = (arg: unknown): arg is string =>\n typeof arg === 'string' && /^\\d+$/.test(arg);\n\nconst parseRunArgsIteration = (state: RunArgs, args: string[]): string[] => {\n const [arg1, arg2] = args;\n\n if (!arg1) {\n return [];\n }\n\n if (/^--inspect(-brk)?=\\d+$/.test(arg1)) {\n state.node.push(arg1);\n return args.slice(1);\n }\n\n // Node.js inspector options that are optionally followed by a numeric port.\n if (['--inspect', '--inspect-brk'].includes(arg1)) {\n if (isDigits(arg2)) {\n state.node.push(`${arg1}=${arg2}`);\n return args.slice(2);\n }\n\n state.node.push(arg1);\n\n if (arg2) {\n // Some other string that doesn't relate to the Node.js inspector option.\n // This is presumably the entry point script to run.\n state.entryPoint = arg2;\n state.script.push(...args.slice(2));\n }\n\n return [];\n }\n\n if (/^--port=\\d+$/.test(arg1)) {\n state.port = Number(arg1.slice(7));\n return args.slice(1);\n }\n\n if (arg1 === '--port') {\n if (isDigits(arg2)) {\n state.port = Number(arg2);\n return args.slice(2);\n }\n\n // Invalid port argument; eat it.\n return args.slice(1);\n }\n\n state.entryPoint = arg1;\n state.script.push(...args.slice(1));\n return [];\n};\n"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmB;AAEnB,qBAAgC;AAEzB,MAAM,eAAe,CAA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pB,WAAO,KAAK,MAAM,CAAC;AAAA,EACrB;AAGA,MAAI,CAAC,aAAa,eAAe,EAAE,SAAS,IAAI,GAAG;AACjD,QAAI,SAAS,IAAI,GAAG;AAClB,YAAM,KAAK,KAAK,GAAG,IAAI,IAAI,IAAI,EAAE;AACjC,aAAO,KAAK,MAAM,CAAC;AAAA,IACrB;AAEA,UAAM,KAAK,KAAK,IAAI;AAEpB,QAAI,MAAM;AAGR,YAAM,aAAa;AACnB,YAAM,OAAO,KAAK,GAAG,KAAK,MAAM,CAAC,CAAC;AAAA,IACpC;AAEA,WAAO,CAAC;AAAA,EACV;AAEA,MAAI,eAAe,KAAK,IAAI,GAAG;AAC7B,UAAM,OAAO,OAAO,KAAK,MAAM,CAAC,CAAC;AACjC,WAAO,KAAK,MAAM,CAAC;AAAA,EACrB;AAEA,MAAI,SAAS,UAAU;AACrB,QAAI,SAAS,IAAI,GAAG;AAClB,YAAM,OAAO,OAAO,IAAI;AACxB,aAAO,KAAK,MAAM,CAAC;AAAA,IACrB;AAGA,WAAO,KAAK,MAAM,CAAC;AAAA,EACrB;AAEA,QAAM,aAAa;AACnB,QAAM,OAAO,KAAK,GAAG,KAAK,MAAM,CAAC,CAAC;AAClC,SAAO,CAAC;AACV;",
4
+ "sourcesContent": ["import assert from 'assert';\n\nimport { COMMAND_ALIASES } from './command.js';\n\nexport const hasDebugFlag = (args = process.argv) =>\n args.some((arg) => arg.toLocaleLowerCase() === '--debug');\n\nexport const hasSerialFlag = (args = process.argv, env = process.env) =>\n args.some((arg) => arg.toLocaleLowerCase() === '--serial') ||\n Boolean(\n // Run serially on SEEK's central npm publishing pipeline.\n // Exhausting agents here can cause grief.\n env.BUILDKITE_AGENT_META_DATA_QUEUE?.split(',').some((queueName) =>\n queueName.startsWith('artefacts:npm'),\n ),\n );\n\n/**\n * Parse process arguments.\n *\n * This function mutates the input list by removing the command name element.\n * Downstream commands can access their args with an ordinary\n * `process.argv.slice(2)`.\n *\n * Example input:\n *\n * ```typescript\n * ['/bin/node', 'node_modules/.bin/skuba', 'test', '--foo', '--bar']\n * ```\n */\nexport const parseProcessArgs = (args = process.argv) => {\n const skubaIdx = args.findIndex((chunk) => /skuba(\\.[jt]s)?$/.test(chunk));\n\n assert(skubaIdx >= 0, 'Cannot parse args for `skuba`');\n\n const rawCommand = (args[skubaIdx + 1] ?? 'help').toLocaleLowerCase();\n\n const commandName = COMMAND_ALIASES[rawCommand] ?? rawCommand;\n\n const payload = {\n commandName,\n args: args.slice(skubaIdx + 2),\n };\n\n args.splice(skubaIdx + 1, 1);\n\n return payload;\n};\n\ninterface RunArgs {\n /** The conditions to pass to the entry point script. */\n conditions?: string[];\n\n /** The path to the entry point script. */\n entryPoint?: string;\n\n /** The port to start an HTTP server on. */\n port?: number;\n\n /** Arguments passed through to the Node.js executable. */\n node: string[];\n\n /** Arguments passed through to the entry point script. */\n script: string[];\n}\n\n/**\n * Make a best effort to parse \"run\" args.\n *\n * These are arguments that would be passed to `skuba node` or `skuba start`.\n * Parsing is handrolled because we support some weird and wonderful behaviour:\n *\n * - The `--port` option may be intended for skuba itself\n * - The `--inspect` options may be intended for the Node.js inspector\n * - The entry point may be omitted in favour of `package.json` inference\n * - Other args may be intended for propagation to the entry point\n */\nexport const parseRunArgs = (argv: string[]): RunArgs => {\n const state: RunArgs = {\n node: [],\n script: [],\n };\n\n let args = argv.filter((element) => element.length);\n\n while (args.length) {\n args = parseRunArgsIteration(state, args);\n }\n\n return state;\n};\n\nconst isDigits = (arg: unknown): arg is string =>\n typeof arg === 'string' && /^\\d+$/.test(arg);\n\nconst parseRunArgsIteration = (state: RunArgs, args: string[]): string[] => {\n const [arg1, arg2] = args;\n\n if (!arg1) {\n return [];\n }\n\n if (/^--inspect(-brk)?=\\d+$/.test(arg1)) {\n state.node.push(arg1);\n return args.slice(1);\n }\n\n // Node.js inspector options that are optionally followed by a numeric port.\n if (['--inspect', '--inspect-brk'].includes(arg1)) {\n if (isDigits(arg2)) {\n state.node.push(`${arg1}=${arg2}`);\n return args.slice(2);\n }\n\n state.node.push(arg1);\n\n if (arg2) {\n // Some other string that doesn't relate to the Node.js inspector option.\n // This is presumably the entry point script to run.\n state.entryPoint = arg2;\n state.script.push(...args.slice(2));\n }\n\n return [];\n }\n\n if (/^--port=\\d+$/.test(arg1)) {\n state.port = Number(arg1.slice(7));\n return args.slice(1);\n }\n\n if (arg1 === '--port') {\n if (isDigits(arg2)) {\n state.port = Number(arg2);\n return args.slice(2);\n }\n\n // Invalid port argument; eat it.\n return args.slice(1);\n }\n\n if (arg1.startsWith('--conditions=')) {\n state.conditions ??= [];\n state.conditions.push(arg1.slice(13));\n return args.slice(1);\n }\n\n state.entryPoint = arg1;\n state.script.push(...args.slice(1));\n return [];\n};\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAmB;AAEnB,qBAAgC;AAEzB,MAAM,eAAe,CAAC,OAAO,QAAQ,SAC1C,KAAK,KAAK,CAAC,QAAQ,IAAI,kBAAkB,MAAM,SAAS;AAEnD,MAAM,gBAAgB,CAAC,OAAO,QAAQ,MAAM,MAAM,QAAQ,QAC/D,KAAK,KAAK,CAAC,QAAQ,IAAI,kBAAkB,MAAM,UAAU,KACzD;AAAA;AAAA;AAAA,EAGE,IAAI,iCAAiC,MAAM,GAAG,EAAE;AAAA,IAAK,CAAC,cACpD,UAAU,WAAW,eAAe;AAAA,EACtC;AACF;AAeK,MAAM,mBAAmB,CAAC,OAAO,QAAQ,SAAS;AACvD,QAAM,WAAW,KAAK,UAAU,CAAC,UAAU,mBAAmB,KAAK,KAAK,CAAC;AAEzE,oBAAAA,SAAO,YAAY,GAAG,+BAA+B;AAErD,QAAM,cAAc,KAAK,WAAW,CAAC,KAAK,QAAQ,kBAAkB;AAEpE,QAAM,cAAc,+BAAgB,UAAU,KAAK;AAEnD,QAAM,UAAU;AAAA,IACd;AAAA,IACA,MAAM,KAAK,M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