diff --git a/netlify-sdk/0.8.1/addBuildEventContext/README.md b/netlify-sdk/0.8.1/addBuildEventContext/README.md new file mode 100644 index 00000000..d902c0d3 --- /dev/null +++ b/netlify-sdk/0.8.1/addBuildEventContext/README.md @@ -0,0 +1,59 @@ +# Rename addBuildEventContext + +## Description + +This codemod renames `addBuildContext` to `addBuildEventContext` as required in Netlify SDK v0.8.1. + +## Example + +### Before + +```jsx +import { NetlifyIntegration } from '@netlify/sdk'; + +const integration = new NetlifyIntegration(); + +// Adding a build event handler +integration.addBuildContext(() => {}); +``` + +### After + +```jsx +import { NetlifyIntegration } from '@netlify/sdk'; + +const integration = new NetlifyIntegration(); + +// Adding a build event handler +integration.addBuildEventContext(() => {}); +``` + +## Applicability Criteria + +Netlify SDK v0.8.1 or higher. + +## Other Metadata + +### Codemod Version + +v1.0.0 + +### Change Mode + +**Autonomous**: Changes can safely be pushed and merged without further human involvement. + +### **Codemod Engine** + +jscodeshift + +### Estimated Time Saving + +~1 minutes per occurrence + +### Owner + +[Intuita](https://github.com/intuita-inc) + +### Links for more info + +- [Netlify SDK v0.8.1 Release Notes](https://sdk.netlify.com/release-notes/#081) diff --git a/netlify-sdk/0.8.1/addBuildEventContext/config.json b/netlify-sdk/0.8.1/addBuildEventContext/config.json new file mode 100644 index 00000000..7ee32e96 --- /dev/null +++ b/netlify-sdk/0.8.1/addBuildEventContext/config.json @@ -0,0 +1,5 @@ +{ + "schemaVersion": "1.0.0", + "name": "netlify/0.8.1/addBuildEventContext", + "engine": "jscodeshift" +} diff --git a/netlify-sdk/0.8.1/addBuildEventContext/index.ts b/netlify-sdk/0.8.1/addBuildEventContext/index.ts new file mode 100644 index 00000000..841accc0 --- /dev/null +++ b/netlify-sdk/0.8.1/addBuildEventContext/index.ts @@ -0,0 +1,29 @@ +import type { FileInfo, API, Options } from 'jscodeshift'; +export default function transform( + file: FileInfo, + api: API, + options: Options, +): string | undefined { + const j = api.jscodeshift; + const root = j(file.source); + + // Find all CallExpressions + root.find(j.CallExpression).forEach((path) => { + // Ensure the callee is a MemberExpression + if (path.node.callee.type === 'MemberExpression') { + // Ensure the object is an Identifier named 'integration' + if (path.node.callee.object.type === 'Identifier') { + // Ensure the property is an Identifier named 'addBuildContext' + if ( + path.node.callee.property.type === 'Identifier' && + path.node.callee.property.name === 'addBuildContext' + ) { + // Replace 'addBuildContext' with 'addBuildEventContext' + path.node.callee.property.name = 'addBuildEventContext'; + } + } + } + }); + + return root.toSource(); +} diff --git a/netlify-sdk/0.8.1/addBuildEventContext/test.ts b/netlify-sdk/0.8.1/addBuildEventContext/test.ts new file mode 100644 index 00000000..e39ef701 --- /dev/null +++ b/netlify-sdk/0.8.1/addBuildEventContext/test.ts @@ -0,0 +1,32 @@ +import { FileInfo } from 'jscodeshift'; +import assert from 'node:assert'; +import transform from './index.js'; +import { buildApi } from '../../../utilities.js'; + +describe('netlify 0.8.1 addBuildEventContext', function () { + it('changes addBuildContext to addBuildEventContext', function () { + const INPUT = ` + integration.addBuildContext("onPreBuild", () => { + //FOO + }); + `; + + const OUTPUT = ` + integration.addBuildEventContext("onPreBuild", () => { + //FOO + }); + `; + + const fileInfo: FileInfo = { + path: 'index.js', + source: INPUT, + }; + + const actualOutput = transform(fileInfo, buildApi('tsx')); + + assert.deepEqual( + actualOutput?.replace(/\W/gm, ''), + OUTPUT.replace(/\W/gm, ''), + ); + }); +}); diff --git a/netlify-sdk/0.8.1/addBuildEventHandler/README.md b/netlify-sdk/0.8.1/addBuildEventHandler/README.md new file mode 100644 index 00000000..4547291f --- /dev/null +++ b/netlify-sdk/0.8.1/addBuildEventHandler/README.md @@ -0,0 +1,63 @@ +# Rename addBuildEventHandler + +## Description + +This codemod renames `addBuildHook` to `addBuildEventHandler` as required in Netlify SDK v0.8.1. + +## Example + +### Before + +```jsx +import { NetlifyIntegration } from '@netlify/sdk'; + +const integration = new NetlifyIntegration(); + +// Adding a build event handler +integration.addBuildHook('onPreBuild', () => { + console.log('This is my first build event handler!'); +}); +``` + +### After + +```jsx +import { NetlifyIntegration } from '@netlify/sdk'; + +const integration = new NetlifyIntegration(); + +// Adding a build event handler +integration.addBuildEventHandler('onPreBuild', () => { + console.log('This is my first build event handler!'); +}); +``` + +## Applicability Criteria + +Netlify SDK v0.8.1 or higher. + +## Other Metadata + +### Codemod Version + +v1.0.0 + +### Change Mode + +**Autonomous**: Changes can safely be pushed and merged without further human involvement. + +### **Codemod Engine** + +jscodeshift + +### Estimated Time Saving + +~1 minutes per occurrence + +### Owner + +[Intuita](https://github.com/intuita-inc) + +### Links for more info + +- [Netlify SDK v0.8.1 Release Notes](https://sdk.netlify.com/release-notes/#081) diff --git a/netlify-sdk/0.8.1/addBuildEventHandler/config.json b/netlify-sdk/0.8.1/addBuildEventHandler/config.json new file mode 100644 index 00000000..9fcf346b --- /dev/null +++ b/netlify-sdk/0.8.1/addBuildEventHandler/config.json @@ -0,0 +1,5 @@ +{ + "schemaVersion": "1.0.0", + "name": "netlify/0.8.1/addBuildEventHandler", + "engine": "jscodeshift" +} diff --git a/netlify-sdk/0.8.1/addBuildEventHandler/index.ts b/netlify-sdk/0.8.1/addBuildEventHandler/index.ts new file mode 100644 index 00000000..e13d8159 --- /dev/null +++ b/netlify-sdk/0.8.1/addBuildEventHandler/index.ts @@ -0,0 +1,32 @@ +import type { FileInfo, API, Options } from 'jscodeshift'; +export default function transform( + file: FileInfo, + api: API, + options: Options, +): string | undefined { + const j = api.jscodeshift; + const root = j(file.source); + + // Find all CallExpressions + root.find(j.CallExpression).forEach((path) => { + // Ensure the callee is a MemberExpression + if (path.node.callee.type === 'MemberExpression') { + // Ensure the object is an Identifier named 'integration' + if ( + path.node.callee.object.type === 'Identifier' && + path.node.callee.object.name === 'integration' + ) { + // Ensure the property is an Identifier named 'addBuildHook' + if ( + path.node.callee.property.type === 'Identifier' && + path.node.callee.property.name === 'addBuildHook' + ) { + // Replace 'addBuildHook' with 'addBuildEventHandler' + path.node.callee.property.name = 'addBuildEventHandler'; + } + } + } + }); + + return root.toSource(); +} diff --git a/netlify-sdk/0.8.1/addBuildEventHandler/test.ts b/netlify-sdk/0.8.1/addBuildEventHandler/test.ts new file mode 100644 index 00000000..296a6bbb --- /dev/null +++ b/netlify-sdk/0.8.1/addBuildEventHandler/test.ts @@ -0,0 +1,28 @@ +import { FileInfo } from 'jscodeshift'; +import assert from 'node:assert'; +import transform from './index.js'; +import { buildApi } from '../../../utilities.js'; + +describe('netlify 0.8.1 addBuildEventContext', function () { + it('changes addBuildHook to addBuildEventContext', function () { + const INPUT = ` + integration.addBuildHook("onPreBuild", () => {}); + `; + + const OUTPUT = ` + integration.addBuildEventHandler("onPreBuild", () => {}); + `; + + const fileInfo: FileInfo = { + path: 'index.js', + source: INPUT, + }; + + const actualOutput = transform(fileInfo, buildApi('tsx')); + + assert.deepEqual( + actualOutput?.replace(/\W/gm, ''), + OUTPUT.replace(/\W/gm, ''), + ); + }); +}); diff --git a/netlify-sdk/0.8.1/disableBuildEventHandlers/README.md b/netlify-sdk/0.8.1/disableBuildEventHandlers/README.md new file mode 100644 index 00000000..9a193268 --- /dev/null +++ b/netlify-sdk/0.8.1/disableBuildEventHandlers/README.md @@ -0,0 +1,49 @@ +# Rename disableBuildEventHandlers + +## Description + +This codemod renames `disableBuildhook` to `disableBuildEventHandlers` as required in Netlify SDK v0.8.1. + +## Example + +### Before + +```jsx +await client.disableBuildhook(siteId); +``` + +### After + +```jsx +await client.disableBuildEventHandlers(siteId); +``` + +## Applicability Criteria + +Netlify SDK v0.8.1 or higher. + +## Other Metadata + +### Codemod Version + +v1.0.0 + +### Change Mode + +**Autonomous**: Changes can safely be pushed and merged without further human involvement. + +### **Codemod Engine** + +jscodeshift + +### Estimated Time Saving + +~1 minutes per occurrence + +### Owner + +[Intuita](https://github.com/intuita-inc) + +### Links for more info + +- [Netlify SDK v0.8.1 Release Notes](https://sdk.netlify.com/release-notes/#081) diff --git a/netlify-sdk/0.8.1/disableBuildEventHandlers/config.json b/netlify-sdk/0.8.1/disableBuildEventHandlers/config.json new file mode 100644 index 00000000..7fcd4de7 --- /dev/null +++ b/netlify-sdk/0.8.1/disableBuildEventHandlers/config.json @@ -0,0 +1,5 @@ +{ + "schemaVersion": "1.0.0", + "name": "netlify/0.8.1/disableBuildEventHandlers", + "engine": "jscodeshift" +} diff --git a/netlify-sdk/0.8.1/disableBuildEventHandlers/index.ts b/netlify-sdk/0.8.1/disableBuildEventHandlers/index.ts new file mode 100644 index 00000000..0eaf39f4 --- /dev/null +++ b/netlify-sdk/0.8.1/disableBuildEventHandlers/index.ts @@ -0,0 +1,31 @@ +import type { FileInfo, API, Options } from 'jscodeshift'; +export default function transform( + file: FileInfo, + api: API, + options: Options, +): string | undefined { + const j = api.jscodeshift; + const root = j(file.source); + + // Find all CallExpressions + root.find(j.CallExpression).forEach((path) => { + // Ensure the callee is a MemberExpression + if (path.node.callee.type === 'MemberExpression') { + const memberExpression = path.node.callee; + // Ensure the object is an Identifier named 'client' + if (memberExpression.object.type === 'Identifier') { + // Ensure the property is an Identifier named 'disableBuildhook' + if ( + memberExpression.property.type === 'Identifier' && + memberExpression.property.name === 'disableBuildhook' + ) { + // Replace 'disableBuildhook' with 'disableBuildEventHandlers' + memberExpression.property.name = + 'disableBuildEventHandlers'; + } + } + } + }); + + return root.toSource(); +} diff --git a/netlify-sdk/0.8.1/disableBuildEventHandlers/test.ts b/netlify-sdk/0.8.1/disableBuildEventHandlers/test.ts new file mode 100644 index 00000000..b16125de --- /dev/null +++ b/netlify-sdk/0.8.1/disableBuildEventHandlers/test.ts @@ -0,0 +1,28 @@ +import { FileInfo } from 'jscodeshift'; +import assert from 'node:assert'; +import transform from './index.js'; +import { buildApi } from '../../../utilities.js'; + +describe('netlify 0.8.1 disableBuildEventHandlers', function () { + it('changes disableBuildhook to disableBuildEventHandlers', function () { + const INPUT = ` + await client.disableBuildhook(siteId); + `; + + const OUTPUT = ` + await client.disableBuildEventHandlers(siteId); + `; + + const fileInfo: FileInfo = { + path: 'index.js', + source: INPUT, + }; + + const actualOutput = transform(fileInfo, buildApi('tsx')); + + assert.deepEqual( + actualOutput?.replace(/\W/gm, ''), + OUTPUT.replace(/\W/gm, ''), + ); + }); +}); diff --git a/netlify-sdk/0.8.1/enableBuildEventHandlers/README.md b/netlify-sdk/0.8.1/enableBuildEventHandlers/README.md new file mode 100644 index 00000000..b9daa878 --- /dev/null +++ b/netlify-sdk/0.8.1/enableBuildEventHandlers/README.md @@ -0,0 +1,49 @@ +# Rename enableBuildEventHandlers + +## Description + +This codemod renames `enableBuildhook` to `enableBuildEventHandlers` as required in Netlify SDK v0.8.1. + +## Example + +### Before + +```jsx +await client.enableBuildhook(siteId); +``` + +### After + +```jsx +await client.enableBuildEventHandlers(siteId); +``` + +## Applicability Criteria + +Netlify SDK v0.8.1 or higher. + +## Other Metadata + +### Codemod Version + +v1.0.0 + +### Change Mode + +**Autonomous**: Changes can safely be pushed and merged without further human involvement. + +### **Codemod Engine** + +jscodeshift + +### Estimated Time Saving + +~1 minutes per occurrence + +### Owner + +[Intuita](https://github.com/intuita-inc) + +### Links for more info + +- [Netlify SDK v0.8.1 Release Notes](https://sdk.netlify.com/release-notes/#081) diff --git a/netlify-sdk/0.8.1/enableBuildEventHandlers/config.json b/netlify-sdk/0.8.1/enableBuildEventHandlers/config.json new file mode 100644 index 00000000..3eb055c4 --- /dev/null +++ b/netlify-sdk/0.8.1/enableBuildEventHandlers/config.json @@ -0,0 +1,5 @@ +{ + "schemaVersion": "1.0.0", + "name": "netlify/0.8.1/enableBuildEventHandlers", + "engine": "jscodeshift" +} diff --git a/netlify-sdk/0.8.1/enableBuildEventHandlers/index.ts b/netlify-sdk/0.8.1/enableBuildEventHandlers/index.ts new file mode 100644 index 00000000..1e71d788 --- /dev/null +++ b/netlify-sdk/0.8.1/enableBuildEventHandlers/index.ts @@ -0,0 +1,30 @@ +import type { FileInfo, API, Options } from 'jscodeshift'; +export default function transform( + file: FileInfo, + api: API, + options: Options, +): string | undefined { + const j = api.jscodeshift; + const root = j(file.source); + + // Find all CallExpressions + root.find(j.CallExpression).forEach((path) => { + // Ensure the callee is a MemberExpression + if (path.node.callee.type === 'MemberExpression') { + const memberExpression = path.node.callee; + // Ensure the object is an Identifier named 'client' + if (memberExpression.object.type === 'Identifier') { + // Ensure the property is an Identifier named 'disableBuildhook' + if ( + memberExpression.property.type === 'Identifier' && + memberExpression.property.name === 'enableBuildhook' + ) { + // Replace 'disableBuildhook' with 'disableBuildEventHandlers' + memberExpression.property.name = 'enableBuildEventHandlers'; + } + } + } + }); + + return root.toSource(); +} diff --git a/netlify-sdk/0.8.1/enableBuildEventHandlers/test.ts b/netlify-sdk/0.8.1/enableBuildEventHandlers/test.ts new file mode 100644 index 00000000..d9237431 --- /dev/null +++ b/netlify-sdk/0.8.1/enableBuildEventHandlers/test.ts @@ -0,0 +1,28 @@ +import { FileInfo } from 'jscodeshift'; +import assert from 'node:assert'; +import transform from './index.js'; +import { buildApi } from '../../../utilities.js'; + +describe('netlify 0.8.1 disableBuildEventHandlers', function () { + it('changes disableBuildhook to disableBuildEventHandlers', function () { + const INPUT = ` + await client.enableBuildhook(siteId); + `; + + const OUTPUT = ` + await client.enableBuildEventHandlers(siteId); + `; + + const fileInfo: FileInfo = { + path: 'index.js', + source: INPUT, + }; + + const actualOutput = transform(fileInfo, buildApi('tsx')); + + assert.deepEqual( + actualOutput?.replace(/\W/gm, ''), + OUTPUT.replace(/\W/gm, ''), + ); + }); +}); diff --git a/netlify-sdk/0.8.1/exportZod/README.md b/netlify-sdk/0.8.1/exportZod/README.md new file mode 100644 index 00000000..eaee0c0f --- /dev/null +++ b/netlify-sdk/0.8.1/exportZod/README.md @@ -0,0 +1,49 @@ +# Export Zod + +## Description + +This codemod exports z from zod as required in Netlify SDK v0.8.1. + +## Example + +### Before + +```jsx +import { z } from '@netlify/sdk'; +``` + +### After + +```jsx +import { z } from '@netlify/sdk'; +``` + +## Applicability Criteria + +Netlify SDK v0.8.1 or higher. + +## Other Metadata + +### Codemod Version + +v1.0.0 + +### Change Mode + +**Autonomous**: Changes can safely be pushed and merged without further human involvement. + +### **Codemod Engine** + +jscodeshift + +### Estimated Time Saving + +~1 minutes per occurrence + +### Owner + +[Intuita](https://github.com/intuita-inc) + +### Links for more info + +- [Netlify SDK v0.8.1 Release Notes](https://sdk.netlify.com/release-notes/#081) diff --git a/netlify-sdk/0.8.1/exportZod/config.json b/netlify-sdk/0.8.1/exportZod/config.json new file mode 100644 index 00000000..25455a1c --- /dev/null +++ b/netlify-sdk/0.8.1/exportZod/config.json @@ -0,0 +1,5 @@ +{ + "schemaVersion": "1.0.0", + "name": "netlify/0.8.1/exportZod", + "engine": "jscodeshift" +} diff --git a/netlify-sdk/0.8.1/exportZod/index.ts b/netlify-sdk/0.8.1/exportZod/index.ts new file mode 100644 index 00000000..1cdcbb16 --- /dev/null +++ b/netlify-sdk/0.8.1/exportZod/index.ts @@ -0,0 +1,20 @@ +import type { FileInfo, API, Options } from 'jscodeshift'; +export default function transform( + file: FileInfo, + api: API, + options: Options, +): string | undefined { + const j = api.jscodeshift; + const root = j(file.source); + + // Find import declarations + root.find(j.ImportDeclaration).forEach((path) => { + // Ensure the import source is 'zod' + if (path.node.source.value === 'zod') { + // Change the import source to '@netlify/sdk' + path.node.source.value = '@netlify/sdk'; + } + }); + + return root.toSource(); +} diff --git a/netlify-sdk/0.8.1/exportZod/test.ts b/netlify-sdk/0.8.1/exportZod/test.ts new file mode 100644 index 00000000..5ed4dd21 --- /dev/null +++ b/netlify-sdk/0.8.1/exportZod/test.ts @@ -0,0 +1,28 @@ +import { FileInfo } from 'jscodeshift'; +import assert from 'node:assert'; +import transform from './index.js'; +import { buildApi } from '../../../utilities.js'; + +describe('netlify 0.8.1 export zod', function () { + it('exports zod to netlify sdk', function () { + const INPUT = ` + import { z } from 'zod'; + `; + + const OUTPUT = ` + import { z } from '@netlify/sdk' + `; + + const fileInfo: FileInfo = { + path: 'index.js', + source: INPUT, + }; + + const actualOutput = transform(fileInfo, buildApi('tsx')); + + assert.deepEqual( + actualOutput?.replace(/\W/gm, ''), + OUTPUT.replace(/\W/gm, ''), + ); + }); +}); diff --git a/netlify-sdk/0.8.5/createEnvironmentVariable/index.ts b/netlify-sdk/0.8.5/createEnvironmentVariable/index.ts index bd5aff0c..67e56334 100644 --- a/netlify-sdk/0.8.5/createEnvironmentVariable/index.ts +++ b/netlify-sdk/0.8.5/createEnvironmentVariable/index.ts @@ -8,32 +8,32 @@ export default function transform( file: FileInfo, api: API, ): string | undefined { - const j = api.jscodeshift; - const root = j(file.source); - - let dirtyFlag = false; - - // Find all CallExpression nodes - root.find(j.CallExpression).forEach((path) => { - if ( - path.node.type !== 'CallExpression' || - path.node.callee.type !== 'Identifier' || - path.node.callee.name !== 'createEnvironmentVariable' - ) { - return; - } - - // Create an object expression from the arguments - const objectExpression = j.objectExpression( - path.node.arguments - .map((arg, i) => { - // Create a property from the identifier - if (i > 3 || arg.type === 'SpreadElement') { - return null; - } - - const name = - ['accountId', 'siteId', 'key', 'values'][i] ?? 'error'; + const j = api.jscodeshift; + const root = j(file.source); + + let dirtyFlag = false; + + // Find all CallExpression nodes + root.find(j.CallExpression).forEach((path) => { + if ( + path.node.type !== 'CallExpression' || + path.node.callee.type !== 'Identifier' || + path.node.callee.name !== 'createEnvironmentVariable' + ) { + return; + } + + // Create an object expression from the arguments + const objectExpression = j.objectExpression( + path.node.arguments + .map((arg, i) => { + // Create a property from the identifier + if (i > 3 || arg.type === 'SpreadElement') { + return null; + } + + const name = + ['accountId', 'siteId', 'key', 'values'][i] ?? 'error'; return j.property.from({ kind: 'init', @@ -44,11 +44,11 @@ export default function transform( .filter(isNeitherNullNorUndefined), ); - // Replace the arguments with the new object expression - path.node.arguments = [objectExpression]; + // Replace the arguments with the new object expression + path.node.arguments = [objectExpression]; - dirtyFlag = true; - }); + dirtyFlag = true; + }); - return dirtyFlag ? root.toSource() : undefined; -} + return dirtyFlag ? root.toSource() : undefined; +} \ No newline at end of file