skuba 16.0.0 → 16.0.2
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.
- package/lib/cli/lint/internalLints/upgrade/patches/15.3.0/index.js +0 -5
- package/lib/cli/lint/internalLints/upgrade/patches/15.3.0/index.js.map +2 -2
- package/lib/cli/migrate/esm/migrateLambdas.js +1 -1
- package/lib/cli/migrate/esm/migrateLambdas.js.map +1 -1
- package/package.json +4 -4
- package/lib/cli/lint/internalLints/upgrade/patches/15.3.0/patchDockerfilePruneProd.d.ts +0 -3
- package/lib/cli/lint/internalLints/upgrade/patches/15.3.0/patchDockerfilePruneProd.js +0 -63
- package/lib/cli/lint/internalLints/upgrade/patches/15.3.0/patchDockerfilePruneProd.js.map +0 -7
|
@@ -1,12 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
import { tryMigrateToESM } from "./migrateToESM.js";
|
|
3
|
-
import { tryPatchDockerfilePruneProd } from "./patchDockerfilePruneProd.js";
|
|
4
3
|
import { tryRemovePnpmConfigPackageJson } from "./removePnpmConfigPackageJson.js";
|
|
5
4
|
export const patches = [
|
|
6
|
-
{
|
|
7
|
-
apply: tryPatchDockerfilePruneProd,
|
|
8
|
-
description: "Replace pnpm install --prod with pnpm prune --prod in Dockerfiles"
|
|
9
|
-
},
|
|
10
5
|
{
|
|
11
6
|
apply: tryRemovePnpmConfigPackageJson,
|
|
12
7
|
description: "Remove pnpm-plugin-skuba from package.json pnpm config"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../../../src/cli/lint/internalLints/upgrade/patches/15.3.0/index.ts"],
|
|
4
|
-
"sourcesContent": ["import type { Patches } from '../../index.js';\n\nimport { tryMigrateToESM } from './migrateToESM.js';\nimport {
|
|
5
|
-
"mappings": ";AAEA,SAAS,uBAAuB;AAChC,SAAS,
|
|
4
|
+
"sourcesContent": ["import type { Patches } from '../../index.js';\n\nimport { tryMigrateToESM } from './migrateToESM.js';\nimport { tryRemovePnpmConfigPackageJson } from './removePnpmConfigPackageJson.js';\n\nexport const patches: Patches = [\n {\n apply: tryRemovePnpmConfigPackageJson,\n description: 'Remove pnpm-plugin-skuba from package.json pnpm config',\n },\n {\n apply: tryMigrateToESM,\n description: 'Migrate to ESM',\n },\n];\n"],
|
|
5
|
+
"mappings": ";AAEA,SAAS,uBAAuB;AAChC,SAAS,sCAAsC;AAExC,aAAM,UAAmB;AAAA,EAC9B;AAAA,IACE,OAAO;AAAA,IACP,aAAa;AAAA,EACf;AAAA,EACA;AAAA,IACE,OAAO;AAAA,IACP,aAAa;AAAA,EACf;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -74,7 +74,7 @@ format: ${containsAwsLambdaNodeJsImport ? "aws_lambda_nodejs." : ""}OutputFormat
|
|
|
74
74
|
edits.push({
|
|
75
75
|
startPos: insertPos,
|
|
76
76
|
endPos: insertPos,
|
|
77
|
-
insertedText: "import { OutputFormat } from 'aws-cdk-lib/aws-
|
|
77
|
+
insertedText: "import { OutputFormat } from 'aws-cdk-lib/aws-lambda-nodejs';\n"
|
|
78
78
|
});
|
|
79
79
|
}
|
|
80
80
|
} else {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/cli/migrate/esm/migrateLambdas.ts"],
|
|
4
|
-
"sourcesContent": ["import { inspect } from 'util';\n\nimport { type Edit, parseAsync } from '@ast-grep/napi';\nimport fg from 'fast-glob';\nimport fs from 'fs-extra';\n\nimport { log } from '../../../utils/logging.js';\nimport { getCustomConditions } from '../../build/tsc.js';\nimport { registerAstGrepLanguages } from '../../lint/internalLints/registerAstGrepLanguages.js';\nimport type { PatchFunction } from '../../lint/internalLints/upgrade/index.js';\n\nconst migrateCdkLambdas = async (\n tsFiles: Array<{ file: string; contents: string }>,\n containsDatadogLambdaImport: boolean,\n) =>\n (\n await Promise.all(\n tsFiles.map(async ({ file, contents }) => {\n if (!contents.includes('NodejsFunction')) {\n return null;\n }\n\n const edits: Edit[] = [];\n\n const astRoot = (await parseAsync('TypeScript', contents)).root();\n\n const workerAst = astRoot.find({\n rule: {\n kind: 'new_expression',\n regex: '^new (aws_lambda_nodejs.NodejsFunction|NodejsFunction)',\n },\n });\n\n if (!workerAst) {\n return null;\n }\n\n const bundlingObject = workerAst.find({\n rule: {\n kind: 'object',\n inside: {\n kind: 'pair',\n regex: '^bundling',\n },\n },\n });\n\n if (!bundlingObject) {\n return null;\n }\n\n const format = bundlingObject.find({\n rule: {\n kind: 'pair',\n regex: '^format',\n },\n });\n\n const containsAwsLambdaNodeJsImport = astRoot.find({\n rule: {\n kind: 'import_specifier',\n regex: 'aws_lambda_nodejs',\n },\n });\n\n if (!format) {\n edits.push({\n startPos: bundlingObject.range().end.index - 1,\n endPos: bundlingObject.range().end.index - 1,\n insertedText: `\\nformat: ${containsAwsLambdaNodeJsImport ? 'aws_lambda_nodejs.' : ''}OutputFormat.ESM,\\n`,\n });\n if (!containsAwsLambdaNodeJsImport) {\n const lastImport = astRoot.find({\n rule: {\n kind: 'import_statement',\n inside: {\n kind: 'program',\n },\n nthChild: {\n ofRule: {\n kind: 'import_statement',\n },\n position: 1,\n reverse: true,\n },\n },\n });\n\n const insertPos = lastImport\n ? lastImport.range().end.index\n : astRoot.range().start.index;\n\n edits.push({\n startPos: insertPos,\n endPos: insertPos,\n insertedText:\n \"import { OutputFormat } from 'aws-cdk-lib/aws-lambda_nodejs';\\n\",\n });\n }\n } else {\n edits.push(format.replace(format.text().replace('CJS', 'ESM')));\n }\n\n const mainFields = bundlingObject.find({\n rule: {\n kind: 'pair',\n regex: '^mainFields',\n },\n });\n\n if (!mainFields) {\n edits.push({\n startPos: bundlingObject.range().end.index - 1,\n endPos: bundlingObject.range().end.index - 1,\n insertedText: \"\\nmainFields: ['module', 'main'],\\n\",\n });\n } else {\n edits.push(mainFields.replace(\"mainFields: ['module', 'main']\"));\n }\n\n const nodeModules = bundlingObject.find({\n rule: {\n kind: 'pair',\n regex: '^nodeModules',\n },\n });\n\n if (!nodeModules) {\n edits.push({\n startPos: bundlingObject.range().end.index - 1,\n endPos: bundlingObject.range().end.index - 1,\n insertedText: \"\\nnodeModules: ['pino'],\\n\",\n });\n } else {\n const nodeModulesArray = nodeModules.find({\n rule: {\n kind: 'array',\n },\n });\n\n if (nodeModulesArray && !nodeModules.text().includes('pino')) {\n edits.push({\n startPos: nodeModulesArray.range().end.index - 1,\n endPos: nodeModulesArray.range().end.index - 1,\n insertedText: `${nodeModules.text().includes('[') ? ',' : ''} 'pino'`,\n });\n }\n }\n\n const esbuildArgs = bundlingObject.find({\n rule: {\n kind: 'pair',\n regex: '^esbuildArgs',\n },\n });\n\n if (!esbuildArgs) {\n const customCondition = getCustomConditions();\n edits.push({\n startPos: bundlingObject.range().end.index - 1,\n endPos: bundlingObject.range().end.index - 1,\n insertedText: `\\nesbuildArgs: {\\n '--conditions': '${customCondition.join(',')},module',\\n},\\n`,\n });\n } else {\n const conditions = esbuildArgs.find({\n rule: {\n kind: 'pair',\n regex: \"^'--conditions'\",\n },\n });\n\n if (!conditions) {\n const customCondition = getCustomConditions();\n edits.push({\n startPos: esbuildArgs.range().end.index - 1,\n endPos: esbuildArgs.range().end.index - 1,\n insertedText: `\\n'--conditions': '${customCondition.join(',')},module',\\n`,\n });\n } else {\n const conditionsValue = conditions.field('value');\n if (conditionsValue && !conditionsValue.text().includes('module')) {\n edits.push({\n startPos: conditionsValue.range().end.index - 1,\n endPos: conditionsValue.range().end.index - 1,\n insertedText: ',module',\n });\n }\n }\n\n const datadogSettings = astRoot.find({\n rule: {\n kind: 'object',\n inside: {\n kind: 'arguments',\n inside: {\n kind: 'new_expression',\n regex: '^new DatadogLambda',\n },\n },\n },\n });\n\n const nodeLayerVersion = datadogSettings?.find({\n rule: {\n kind: 'pair',\n regex: '^nodeLayerVersion',\n },\n });\n\n const redirectHandler = datadogSettings?.find({\n rule: {\n kind: 'pair',\n regex: '^redirectHandler',\n },\n });\n\n if (datadogSettings && !nodeLayerVersion && !redirectHandler) {\n if (containsDatadogLambdaImport) {\n edits.push({\n startPos: datadogSettings.range().end.index - 1,\n endPos: datadogSettings.range().end.index - 1,\n insertedText: '\\nredirectHandler: false,\\n',\n });\n } else {\n const extensionVersion = datadogSettings.find({\n rule: {\n kind: 'lexical_declaration',\n regex: '^const DATADOG_EXTENSION_LAYER_VERSION ',\n },\n });\n\n const lastImport = astRoot.find({\n rule: {\n kind: 'import_statement',\n inside: {\n kind: 'program',\n },\n nthChild: {\n ofRule: {\n kind: 'import_statement',\n },\n position: 1,\n reverse: true,\n },\n },\n });\n\n const insertPos =\n extensionVersion?.range().end.index ??\n lastImport?.range().end.index ??\n astRoot.range().start.index;\n\n edits.push({\n startPos: insertPos,\n endPos: insertPos,\n insertedText: 'const DATADOG_NODE_LAYER_VERSION = 126;\\n',\n });\n\n edits.push({\n startPos: datadogSettings.range().end.index - 1,\n endPos: datadogSettings.range().end.index - 1,\n insertedText:\n '\\nnodeLayerVersion: DATADOG_NODE_LAYER_VERSION,\\n',\n });\n }\n }\n }\n\n if (!edits.length) {\n return null;\n }\n\n return {\n file,\n contents: astRoot.commitEdits(edits),\n };\n }),\n )\n ).filter((file) => file !== null);\n\nconst migrateServerlessLambdas = async (\n serverlessFiles: Array<{ file: string; contents: string }>,\n containsDatadogLambdaImport: boolean,\n) => {\n registerAstGrepLanguages();\n return (\n await Promise.all(\n serverlessFiles.map(async ({ file, contents }) => {\n if (!contents.includes('esbuild')) {\n return null;\n }\n\n const edits: Edit[] = [];\n\n const astRoot = (await parseAsync('yaml', contents)).root();\n\n const esbuildAst = astRoot.find({\n rule: {\n kind: 'block_node',\n inside: {\n kind: 'block_mapping_pair',\n regex: '^esbuild:',\n },\n },\n });\n\n if (!esbuildAst) {\n return null;\n }\n\n const conditions = esbuildAst.find({\n rule: {\n kind: 'block_node',\n inside: {\n kind: 'block_mapping_pair',\n regex: '^conditions:',\n },\n },\n });\n\n if (conditions) {\n const indent = conditions.range().start.column;\n edits.push({\n startPos: conditions.range().end.index,\n endPos: conditions.range().end.index,\n insertedText: `\\n${' '.repeat(indent)}- module`,\n });\n } else {\n const indent = esbuildAst.range().start.column;\n edits.push({\n startPos: esbuildAst.range().end.index,\n endPos: esbuildAst.range().end.index,\n insertedText: `\\n${' '.repeat(indent)}conditions:\\n${' '.repeat(\n indent + 2,\n )}- module\\n`,\n });\n }\n\n const external = esbuildAst.find({\n rule: {\n kind: 'block_node',\n inside: {\n kind: 'block_mapping_pair',\n regex: '^external:',\n },\n },\n });\n\n if (external) {\n const indent = external.range().start.column;\n if (!external.text().includes('pino')) {\n edits.push({\n startPos: external.range().start.index,\n endPos: external.range().start.index,\n insertedText: `- pino\\n${' '.repeat(indent)}`,\n });\n }\n } else {\n const indent = esbuildAst.range().start.column;\n edits.push({\n startPos: esbuildAst.range().end.index,\n endPos: esbuildAst.range().end.index,\n insertedText: `\\n${' '.repeat(indent)}external:\\n${' '.repeat(\n indent + 2,\n )}- pino\\n`,\n });\n }\n\n const mainFields = esbuildAst.find({\n rule: {\n kind: 'block_node',\n inside: {\n kind: 'block_mapping_pair',\n regex: '^mainFields:',\n },\n },\n });\n\n if (!mainFields) {\n const indent = esbuildAst.range().start.column;\n edits.push({\n startPos: esbuildAst.range().end.index,\n endPos: esbuildAst.range().end.index,\n insertedText: `\\n${' '.repeat(indent)}mainFields:\\n${' '.repeat(\n indent + 2,\n )}- module\\n${' '.repeat(indent + 2)}- main\\n`,\n });\n } else {\n edits.push(mainFields.replace('mainFields:\\n - module\\n - main\\n'));\n }\n\n const datadogSettings = astRoot.find({\n rule: {\n kind: 'block_node',\n inside: {\n kind: 'block_mapping_pair',\n regex: '^datadog:',\n },\n },\n });\n\n if (datadogSettings) {\n const addLayers = datadogSettings.find({\n rule: {\n kind: 'block_mapping_pair',\n regex: '^addLayers:',\n },\n });\n\n const addLayersDisabled = addLayers?.text().includes('false');\n\n if (addLayersDisabled && containsDatadogLambdaImport) {\n const redirectHandlers = datadogSettings.find({\n rule: {\n kind: 'block_node',\n inside: {\n kind: 'block_mapping_pair',\n regex: '^redirectHandlers:',\n },\n },\n });\n\n if (!redirectHandlers) {\n const indent = datadogSettings.range().start.column;\n edits.push({\n startPos: datadogSettings.range().end.index,\n endPos: datadogSettings.range().end.index,\n insertedText: `\\n${' '.repeat(indent)}redirectHandlers: false\\n`,\n });\n }\n }\n }\n\n if (edits.length === 0) {\n return null;\n }\n\n return {\n file,\n contents: astRoot.commitEdits(edits),\n };\n }),\n )\n ).filter((file) => file !== null);\n};\n\nexport const migrateLambdas: PatchFunction = async ({ mode }) => {\n const [tsFilePaths, serverlessFilePaths] = await Promise.all([\n fg(['**/*.ts'], {\n ignore: ['**/.git', '**/node_modules'],\n }),\n fg(['**/serverless*.{yml,yaml}'], {\n ignore: ['**/.git', '**/node_modules'],\n }),\n ]);\n\n const [tsFiles, serverlessFiles] = await Promise.all([\n Promise.all(\n tsFilePaths.map(async (file) => {\n const contents = await fs.promises.readFile(file, 'utf8');\n\n return {\n file,\n contents,\n };\n }),\n ),\n Promise.all(\n serverlessFilePaths.map(async (file) => {\n const contents = await fs.promises.readFile(file, 'utf8');\n\n return {\n file,\n contents,\n };\n }),\n ),\n ]);\n\n const containsDatadogLambdaImport = tsFiles.some(\n ({ contents }) =>\n contents.includes('datadog-lambda-js') ||\n contents.includes('withLambdaExtension'),\n );\n\n const [patchedTsFiles, patchedServerlessFiles] = await Promise.all([\n migrateCdkLambdas(tsFiles, containsDatadogLambdaImport),\n migrateServerlessLambdas(serverlessFiles, containsDatadogLambdaImport),\n ]);\n\n if (!patchedTsFiles.length && !patchedServerlessFiles.length) {\n return {\n result: 'skip',\n reason: 'no lambdas to migrate',\n };\n }\n\n if (mode === 'lint') {\n return {\n result: 'apply',\n };\n }\n\n await Promise.all(\n [...patchedTsFiles, ...patchedServerlessFiles].map(\n async ({ file, contents }) => {\n await fs.promises.writeFile(file, contents, 'utf8');\n },\n ),\n );\n\n return {\n result: 'apply',\n };\n};\n\nexport const tryMigrateLambdas: PatchFunction = async (opts) => {\n try {\n return await migrateLambdas(opts);\n } catch (err) {\n // Don't fail the entire lint/format if this fails since it's a non-critical part of the upgrade\n // and can be retried later by the user\n log.warn('Failed to migrate lambdas, skipping');\n log.subtle(inspect(err));\n return { result: 'skip', reason: 'due to an error' };\n }\n};\n"],
|
|
4
|
+
"sourcesContent": ["import { inspect } from 'util';\n\nimport { type Edit, parseAsync } from '@ast-grep/napi';\nimport fg from 'fast-glob';\nimport fs from 'fs-extra';\n\nimport { log } from '../../../utils/logging.js';\nimport { getCustomConditions } from '../../build/tsc.js';\nimport { registerAstGrepLanguages } from '../../lint/internalLints/registerAstGrepLanguages.js';\nimport type { PatchFunction } from '../../lint/internalLints/upgrade/index.js';\n\nconst migrateCdkLambdas = async (\n tsFiles: Array<{ file: string; contents: string }>,\n containsDatadogLambdaImport: boolean,\n) =>\n (\n await Promise.all(\n tsFiles.map(async ({ file, contents }) => {\n if (!contents.includes('NodejsFunction')) {\n return null;\n }\n\n const edits: Edit[] = [];\n\n const astRoot = (await parseAsync('TypeScript', contents)).root();\n\n const workerAst = astRoot.find({\n rule: {\n kind: 'new_expression',\n regex: '^new (aws_lambda_nodejs.NodejsFunction|NodejsFunction)',\n },\n });\n\n if (!workerAst) {\n return null;\n }\n\n const bundlingObject = workerAst.find({\n rule: {\n kind: 'object',\n inside: {\n kind: 'pair',\n regex: '^bundling',\n },\n },\n });\n\n if (!bundlingObject) {\n return null;\n }\n\n const format = bundlingObject.find({\n rule: {\n kind: 'pair',\n regex: '^format',\n },\n });\n\n const containsAwsLambdaNodeJsImport = astRoot.find({\n rule: {\n kind: 'import_specifier',\n regex: 'aws_lambda_nodejs',\n },\n });\n\n if (!format) {\n edits.push({\n startPos: bundlingObject.range().end.index - 1,\n endPos: bundlingObject.range().end.index - 1,\n insertedText: `\\nformat: ${containsAwsLambdaNodeJsImport ? 'aws_lambda_nodejs.' : ''}OutputFormat.ESM,\\n`,\n });\n if (!containsAwsLambdaNodeJsImport) {\n const lastImport = astRoot.find({\n rule: {\n kind: 'import_statement',\n inside: {\n kind: 'program',\n },\n nthChild: {\n ofRule: {\n kind: 'import_statement',\n },\n position: 1,\n reverse: true,\n },\n },\n });\n\n const insertPos = lastImport\n ? lastImport.range().end.index\n : astRoot.range().start.index;\n\n edits.push({\n startPos: insertPos,\n endPos: insertPos,\n insertedText:\n \"import { OutputFormat } from 'aws-cdk-lib/aws-lambda-nodejs';\\n\",\n });\n }\n } else {\n edits.push(format.replace(format.text().replace('CJS', 'ESM')));\n }\n\n const mainFields = bundlingObject.find({\n rule: {\n kind: 'pair',\n regex: '^mainFields',\n },\n });\n\n if (!mainFields) {\n edits.push({\n startPos: bundlingObject.range().end.index - 1,\n endPos: bundlingObject.range().end.index - 1,\n insertedText: \"\\nmainFields: ['module', 'main'],\\n\",\n });\n } else {\n edits.push(mainFields.replace(\"mainFields: ['module', 'main']\"));\n }\n\n const nodeModules = bundlingObject.find({\n rule: {\n kind: 'pair',\n regex: '^nodeModules',\n },\n });\n\n if (!nodeModules) {\n edits.push({\n startPos: bundlingObject.range().end.index - 1,\n endPos: bundlingObject.range().end.index - 1,\n insertedText: \"\\nnodeModules: ['pino'],\\n\",\n });\n } else {\n const nodeModulesArray = nodeModules.find({\n rule: {\n kind: 'array',\n },\n });\n\n if (nodeModulesArray && !nodeModules.text().includes('pino')) {\n edits.push({\n startPos: nodeModulesArray.range().end.index - 1,\n endPos: nodeModulesArray.range().end.index - 1,\n insertedText: `${nodeModules.text().includes('[') ? ',' : ''} 'pino'`,\n });\n }\n }\n\n const esbuildArgs = bundlingObject.find({\n rule: {\n kind: 'pair',\n regex: '^esbuildArgs',\n },\n });\n\n if (!esbuildArgs) {\n const customCondition = getCustomConditions();\n edits.push({\n startPos: bundlingObject.range().end.index - 1,\n endPos: bundlingObject.range().end.index - 1,\n insertedText: `\\nesbuildArgs: {\\n '--conditions': '${customCondition.join(',')},module',\\n},\\n`,\n });\n } else {\n const conditions = esbuildArgs.find({\n rule: {\n kind: 'pair',\n regex: \"^'--conditions'\",\n },\n });\n\n if (!conditions) {\n const customCondition = getCustomConditions();\n edits.push({\n startPos: esbuildArgs.range().end.index - 1,\n endPos: esbuildArgs.range().end.index - 1,\n insertedText: `\\n'--conditions': '${customCondition.join(',')},module',\\n`,\n });\n } else {\n const conditionsValue = conditions.field('value');\n if (conditionsValue && !conditionsValue.text().includes('module')) {\n edits.push({\n startPos: conditionsValue.range().end.index - 1,\n endPos: conditionsValue.range().end.index - 1,\n insertedText: ',module',\n });\n }\n }\n\n const datadogSettings = astRoot.find({\n rule: {\n kind: 'object',\n inside: {\n kind: 'arguments',\n inside: {\n kind: 'new_expression',\n regex: '^new DatadogLambda',\n },\n },\n },\n });\n\n const nodeLayerVersion = datadogSettings?.find({\n rule: {\n kind: 'pair',\n regex: '^nodeLayerVersion',\n },\n });\n\n const redirectHandler = datadogSettings?.find({\n rule: {\n kind: 'pair',\n regex: '^redirectHandler',\n },\n });\n\n if (datadogSettings && !nodeLayerVersion && !redirectHandler) {\n if (containsDatadogLambdaImport) {\n edits.push({\n startPos: datadogSettings.range().end.index - 1,\n endPos: datadogSettings.range().end.index - 1,\n insertedText: '\\nredirectHandler: false,\\n',\n });\n } else {\n const extensionVersion = datadogSettings.find({\n rule: {\n kind: 'lexical_declaration',\n regex: '^const DATADOG_EXTENSION_LAYER_VERSION ',\n },\n });\n\n const lastImport = astRoot.find({\n rule: {\n kind: 'import_statement',\n inside: {\n kind: 'program',\n },\n nthChild: {\n ofRule: {\n kind: 'import_statement',\n },\n position: 1,\n reverse: true,\n },\n },\n });\n\n const insertPos =\n extensionVersion?.range().end.index ??\n lastImport?.range().end.index ??\n astRoot.range().start.index;\n\n edits.push({\n startPos: insertPos,\n endPos: insertPos,\n insertedText: 'const DATADOG_NODE_LAYER_VERSION = 126;\\n',\n });\n\n edits.push({\n startPos: datadogSettings.range().end.index - 1,\n endPos: datadogSettings.range().end.index - 1,\n insertedText:\n '\\nnodeLayerVersion: DATADOG_NODE_LAYER_VERSION,\\n',\n });\n }\n }\n }\n\n if (!edits.length) {\n return null;\n }\n\n return {\n file,\n contents: astRoot.commitEdits(edits),\n };\n }),\n )\n ).filter((file) => file !== null);\n\nconst migrateServerlessLambdas = async (\n serverlessFiles: Array<{ file: string; contents: string }>,\n containsDatadogLambdaImport: boolean,\n) => {\n registerAstGrepLanguages();\n return (\n await Promise.all(\n serverlessFiles.map(async ({ file, contents }) => {\n if (!contents.includes('esbuild')) {\n return null;\n }\n\n const edits: Edit[] = [];\n\n const astRoot = (await parseAsync('yaml', contents)).root();\n\n const esbuildAst = astRoot.find({\n rule: {\n kind: 'block_node',\n inside: {\n kind: 'block_mapping_pair',\n regex: '^esbuild:',\n },\n },\n });\n\n if (!esbuildAst) {\n return null;\n }\n\n const conditions = esbuildAst.find({\n rule: {\n kind: 'block_node',\n inside: {\n kind: 'block_mapping_pair',\n regex: '^conditions:',\n },\n },\n });\n\n if (conditions) {\n const indent = conditions.range().start.column;\n edits.push({\n startPos: conditions.range().end.index,\n endPos: conditions.range().end.index,\n insertedText: `\\n${' '.repeat(indent)}- module`,\n });\n } else {\n const indent = esbuildAst.range().start.column;\n edits.push({\n startPos: esbuildAst.range().end.index,\n endPos: esbuildAst.range().end.index,\n insertedText: `\\n${' '.repeat(indent)}conditions:\\n${' '.repeat(\n indent + 2,\n )}- module\\n`,\n });\n }\n\n const external = esbuildAst.find({\n rule: {\n kind: 'block_node',\n inside: {\n kind: 'block_mapping_pair',\n regex: '^external:',\n },\n },\n });\n\n if (external) {\n const indent = external.range().start.column;\n if (!external.text().includes('pino')) {\n edits.push({\n startPos: external.range().start.index,\n endPos: external.range().start.index,\n insertedText: `- pino\\n${' '.repeat(indent)}`,\n });\n }\n } else {\n const indent = esbuildAst.range().start.column;\n edits.push({\n startPos: esbuildAst.range().end.index,\n endPos: esbuildAst.range().end.index,\n insertedText: `\\n${' '.repeat(indent)}external:\\n${' '.repeat(\n indent + 2,\n )}- pino\\n`,\n });\n }\n\n const mainFields = esbuildAst.find({\n rule: {\n kind: 'block_node',\n inside: {\n kind: 'block_mapping_pair',\n regex: '^mainFields:',\n },\n },\n });\n\n if (!mainFields) {\n const indent = esbuildAst.range().start.column;\n edits.push({\n startPos: esbuildAst.range().end.index,\n endPos: esbuildAst.range().end.index,\n insertedText: `\\n${' '.repeat(indent)}mainFields:\\n${' '.repeat(\n indent + 2,\n )}- module\\n${' '.repeat(indent + 2)}- main\\n`,\n });\n } else {\n edits.push(mainFields.replace('mainFields:\\n - module\\n - main\\n'));\n }\n\n const datadogSettings = astRoot.find({\n rule: {\n kind: 'block_node',\n inside: {\n kind: 'block_mapping_pair',\n regex: '^datadog:',\n },\n },\n });\n\n if (datadogSettings) {\n const addLayers = datadogSettings.find({\n rule: {\n kind: 'block_mapping_pair',\n regex: '^addLayers:',\n },\n });\n\n const addLayersDisabled = addLayers?.text().includes('false');\n\n if (addLayersDisabled && containsDatadogLambdaImport) {\n const redirectHandlers = datadogSettings.find({\n rule: {\n kind: 'block_node',\n inside: {\n kind: 'block_mapping_pair',\n regex: '^redirectHandlers:',\n },\n },\n });\n\n if (!redirectHandlers) {\n const indent = datadogSettings.range().start.column;\n edits.push({\n startPos: datadogSettings.range().end.index,\n endPos: datadogSettings.range().end.index,\n insertedText: `\\n${' '.repeat(indent)}redirectHandlers: false\\n`,\n });\n }\n }\n }\n\n if (edits.length === 0) {\n return null;\n }\n\n return {\n file,\n contents: astRoot.commitEdits(edits),\n };\n }),\n )\n ).filter((file) => file !== null);\n};\n\nexport const migrateLambdas: PatchFunction = async ({ mode }) => {\n const [tsFilePaths, serverlessFilePaths] = await Promise.all([\n fg(['**/*.ts'], {\n ignore: ['**/.git', '**/node_modules'],\n }),\n fg(['**/serverless*.{yml,yaml}'], {\n ignore: ['**/.git', '**/node_modules'],\n }),\n ]);\n\n const [tsFiles, serverlessFiles] = await Promise.all([\n Promise.all(\n tsFilePaths.map(async (file) => {\n const contents = await fs.promises.readFile(file, 'utf8');\n\n return {\n file,\n contents,\n };\n }),\n ),\n Promise.all(\n serverlessFilePaths.map(async (file) => {\n const contents = await fs.promises.readFile(file, 'utf8');\n\n return {\n file,\n contents,\n };\n }),\n ),\n ]);\n\n const containsDatadogLambdaImport = tsFiles.some(\n ({ contents }) =>\n contents.includes('datadog-lambda-js') ||\n contents.includes('withLambdaExtension'),\n );\n\n const [patchedTsFiles, patchedServerlessFiles] = await Promise.all([\n migrateCdkLambdas(tsFiles, containsDatadogLambdaImport),\n migrateServerlessLambdas(serverlessFiles, containsDatadogLambdaImport),\n ]);\n\n if (!patchedTsFiles.length && !patchedServerlessFiles.length) {\n return {\n result: 'skip',\n reason: 'no lambdas to migrate',\n };\n }\n\n if (mode === 'lint') {\n return {\n result: 'apply',\n };\n }\n\n await Promise.all(\n [...patchedTsFiles, ...patchedServerlessFiles].map(\n async ({ file, contents }) => {\n await fs.promises.writeFile(file, contents, 'utf8');\n },\n ),\n );\n\n return {\n result: 'apply',\n };\n};\n\nexport const tryMigrateLambdas: PatchFunction = async (opts) => {\n try {\n return await migrateLambdas(opts);\n } catch (err) {\n // Don't fail the entire lint/format if this fails since it's a non-critical part of the upgrade\n // and can be retried later by the user\n log.warn('Failed to migrate lambdas, skipping');\n log.subtle(inspect(err));\n return { result: 'skip', reason: 'due to an error' };\n }\n};\n"],
|
|
5
5
|
"mappings": ";AAAA,SAAS,eAAe;AAExB,SAAoB,kBAAkB;AACtC,OAAO,QAAQ;AACf,OAAO,QAAQ;AAEf,SAAS,WAAW;AACpB,SAAS,2BAA2B;AACpC,SAAS,gCAAgC;AAGzC,MAAM,oBAAoB,OACxB,SACA,iCAGE,MAAM,QAAQ;AAAA,EACZ,QAAQ,IAAI,OAAO,EAAE,MAAM,SAAS,MAAM;AACxC,QAAI,CAAC,SAAS,SAAS,gBAAgB,GAAG;AACxC,aAAO;AAAA,IACT;AAEA,UAAM,QAAgB,CAAC;AAEvB,UAA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AQ;AACnB,WAAO;AAAA,MACL,QAAQ;AAAA,IACV;AAAA,EACF;AAEA,QAAM,QAAQ;AAAA,IACZ,CAAC,GAAG,gBAAgB,GAAG,sBAAsB,EAAE;AAAA,MAC7C,OAAO,EAAE,MAAM,SAAS,MAAM;AAC5B,cAAM,GAAG,SAAS,UAAU,MAAM,UAAU,MAAM;AAAA,MACpD;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AAAA,IACL,QAAQ;AAAA,EACV;AACF;AAEO,aAAM,oBAAmC,OAAO,SAAS;AAC9D,MAAI;AACF,WAAO,MAAM,eAAe,IAAI;AAAA,EAClC,SAAS,KAAK;AAGZ,QAAI,KAAK,qCAAqC;AAC9C,QAAI,OAAO,QAAQ,GAAG,CAAC;AACvB,WAAO,EAAE,QAAQ,QAAQ,QAAQ,kBAAkB;AAAA,EACrD;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skuba",
|
|
3
|
-
"version": "16.0.
|
|
3
|
+
"version": "16.0.2",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "SEEK development toolkit for backend applications and packages",
|
|
6
6
|
"homepage": "https://github.com/seek-oss/skuba#readme",
|
|
@@ -106,9 +106,9 @@
|
|
|
106
106
|
"typescript": "~5.9.0",
|
|
107
107
|
"vitest": "^4.1.4",
|
|
108
108
|
"zod": "^4.3.5",
|
|
109
|
-
"@skuba-lib/api": "^2.1.0",
|
|
110
109
|
"eslint-config-skuba": "9.0.0",
|
|
111
|
-
"pnpm-plugin-skuba": "3.0.0"
|
|
110
|
+
"pnpm-plugin-skuba": "3.0.0",
|
|
111
|
+
"@skuba-lib/api": "^2.1.0"
|
|
112
112
|
},
|
|
113
113
|
"devDependencies": {
|
|
114
114
|
"@changesets/cli": "2.31.0",
|
|
@@ -138,7 +138,7 @@
|
|
|
138
138
|
"semver": "7.7.4",
|
|
139
139
|
"supertest": "7.2.2",
|
|
140
140
|
"type-fest": "2.19.0",
|
|
141
|
-
"@skuba-lib/changesets-changelog": "^1.0.
|
|
141
|
+
"@skuba-lib/changesets-changelog": "^1.0.1"
|
|
142
142
|
},
|
|
143
143
|
"engines": {
|
|
144
144
|
"node": ">=22.18.0"
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
import { inspect } from "util";
|
|
3
|
-
import fg from "fast-glob";
|
|
4
|
-
import fs from "fs-extra";
|
|
5
|
-
import { log } from "../../../../../../utils/logging.js";
|
|
6
|
-
const pnpmInstallProdTestRegex = /^RUN (CI=true )?pnpm install.*--prod/m;
|
|
7
|
-
const pnpmInstallProdReplaceRegex = /^RUN (CI=true )?pnpm install.*--prod/gm;
|
|
8
|
-
export const patchDockerfilePruneProd = async (mode) => {
|
|
9
|
-
const dockerfilePaths = await fg(["**/Dockerfile*"], {
|
|
10
|
-
ignore: ["**/.git", "**/node_modules"]
|
|
11
|
-
});
|
|
12
|
-
if (dockerfilePaths.length === 0) {
|
|
13
|
-
return {
|
|
14
|
-
result: "skip",
|
|
15
|
-
reason: "no dockerfiles found"
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
const dockerfiles = await Promise.all(
|
|
19
|
-
dockerfilePaths.map(async (file) => {
|
|
20
|
-
const contents = await fs.promises.readFile(file, "utf8");
|
|
21
|
-
return {
|
|
22
|
-
file,
|
|
23
|
-
contents
|
|
24
|
-
};
|
|
25
|
-
})
|
|
26
|
-
);
|
|
27
|
-
const dockerfilesToPatch = dockerfiles.filter(
|
|
28
|
-
({ contents }) => pnpmInstallProdTestRegex.test(contents)
|
|
29
|
-
);
|
|
30
|
-
if (dockerfilesToPatch.length === 0) {
|
|
31
|
-
return {
|
|
32
|
-
result: "skip",
|
|
33
|
-
reason: "no dockerfiles to patch"
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
if (mode === "lint") {
|
|
37
|
-
return {
|
|
38
|
-
result: "apply"
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
await Promise.all(
|
|
42
|
-
dockerfilesToPatch.map(async ({ file, contents }) => {
|
|
43
|
-
const updatedContents = contents.replace(
|
|
44
|
-
pnpmInstallProdReplaceRegex,
|
|
45
|
-
"RUN pnpm prune --prod"
|
|
46
|
-
);
|
|
47
|
-
await fs.promises.writeFile(file, updatedContents, "utf8");
|
|
48
|
-
})
|
|
49
|
-
);
|
|
50
|
-
return {
|
|
51
|
-
result: "apply"
|
|
52
|
-
};
|
|
53
|
-
};
|
|
54
|
-
export const tryPatchDockerfilePruneProd = async ({ mode }) => {
|
|
55
|
-
try {
|
|
56
|
-
return await patchDockerfilePruneProd(mode);
|
|
57
|
-
} catch (err) {
|
|
58
|
-
log.warn("Failed to apply Dockerfile pnpm prune --prod patch.");
|
|
59
|
-
log.subtle(inspect(err));
|
|
60
|
-
return { result: "skip", reason: "due to an error" };
|
|
61
|
-
}
|
|
62
|
-
};
|
|
63
|
-
//# sourceMappingURL=patchDockerfilePruneProd.js.map
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../../../../../src/cli/lint/internalLints/upgrade/patches/15.3.0/patchDockerfilePruneProd.ts"],
|
|
4
|
-
"sourcesContent": ["import { inspect } from 'util';\n\nimport fg from 'fast-glob';\nimport fs from 'fs-extra';\n\nimport { log } from '../../../../../../utils/logging.js';\nimport type { PatchFunction, PatchReturnType } from '../../index.js';\n\nconst pnpmInstallProdTestRegex = /^RUN (CI=true )?pnpm install.*--prod/m;\nconst pnpmInstallProdReplaceRegex = /^RUN (CI=true )?pnpm install.*--prod/gm;\n\nexport const patchDockerfilePruneProd = async (\n mode: 'lint' | 'format',\n): Promise<PatchReturnType> => {\n const dockerfilePaths = await fg(['**/Dockerfile*'], {\n ignore: ['**/.git', '**/node_modules'],\n });\n\n if (dockerfilePaths.length === 0) {\n return {\n result: 'skip',\n reason: 'no dockerfiles found',\n };\n }\n\n const dockerfiles = await Promise.all(\n dockerfilePaths.map(async (file) => {\n const contents = await fs.promises.readFile(file, 'utf8');\n\n return {\n file,\n contents,\n };\n }),\n );\n\n const dockerfilesToPatch = dockerfiles.filter(({ contents }) =>\n pnpmInstallProdTestRegex.test(contents),\n );\n\n if (dockerfilesToPatch.length === 0) {\n return {\n result: 'skip',\n reason: 'no dockerfiles to patch',\n };\n }\n\n if (mode === 'lint') {\n return {\n result: 'apply',\n };\n }\n\n await Promise.all(\n dockerfilesToPatch.map(async ({ file, contents }) => {\n const updatedContents = contents.replace(\n pnpmInstallProdReplaceRegex,\n 'RUN pnpm prune --prod',\n );\n await fs.promises.writeFile(file, updatedContents, 'utf8');\n }),\n );\n\n return {\n result: 'apply',\n };\n};\n\nexport const tryPatchDockerfilePruneProd: PatchFunction = async ({ mode }) => {\n try {\n return await patchDockerfilePruneProd(mode);\n } catch (err) {\n log.warn('Failed to apply Dockerfile pnpm prune --prod patch.');\n log.subtle(inspect(err));\n return { result: 'skip', reason: 'due to an error' };\n }\n};\n"],
|
|
5
|
-
"mappings": ";AAAA,SAAS,eAAe;AAExB,OAAO,QAAQ;AACf,OAAO,QAAQ;AAEf,SAAS,WAAW;AAGpB,MAAM,2BAA2B;AACjC,MAAM,8BAA8B;AAE7B,aAAM,2BAA2B,OACtC,SAC6B;AAC7B,QAAM,kBAAkB,MAAM,GAAG,CAAC,gBAAgB,GAAG;AAAA,IACnD,QAAQ,CAAC,WAAW,iBAAiB;AAAA,EACvC,CAAC;AAED,MAAI,gBAAgB,WAAW,GAAG;AAChC,WAAO;AAAA,MACL,QAAQ;AAAA,MACR,QAAQ;AAAA,IACV;AAAA,EACF;AAEA,QAAM,cAAc,MAAM,QAAQ;AAAA,IAChC,gBAAgB,IAAI,OAAO,SAAS;AAClC,YAAM,WAAW,MAAM,GAAG,SAAS,SAAS,MAAM,MAAM;AAExD,aAAO;AAAA,QACL;AAAA,QACA;AAAA,MACF;AAAA,IACF,CAAC;AAAA,EACH;AA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