Registry / devops / contentful-smart-migration

contentful-smart-migration

JSON →
library1.3.1jsnpmunverified

Contentful Smart Migration (v1.3.1) is a wrapper around the official Contentful migration CLI that simplifies writing migration scripts that work across multiple Contentful environments. It provides an `OperateOn` class that automatically determines whether a content type or field is new (creates) or existing (edits), reducing boilerplate and making migration scripts reusable. The package is authored by caesarbell, last updated in 2018, with no recent releases. It relies on `contentful-migration` and is intended for Node.js projects using Contentful's Content Management API.

npm install contentful-smart-migration
INSTALL
IMPORT
SIG · CONTENTFUL-SMART-M
C
contentful-smart-migration
devopsjavascriptv1.3.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

OperateOn
import { OperateOn } from 'contentful-smart-migration'
const OperateOn = require('contentful-smart-migration')
Package is ESM-only; named export. CommonJS require will fail.
RunMigration
import { RunMigration } from 'contentful-smart-migration'
Utility function to execute migration scripts; not documented in README but available in source.
migration
operateOn(migration, context, contentTypeDef, fields)
new OperateOn(migration, context, contentTypeDef, fields)
The class constructor expects four arguments: migration object from contentful-migration, context, content type definition object, and fields array. Not instantiated with 'new'.

Create a Content Type and its fields using OperateOn class, handling both creation and editing across environments.

const { OperateOn } = require('contentful-smart-migration'); const migration = require('contentful-migration').default; const migrationFunction = (migration, context) => { const contentTypeDef = { id: 'componentExample', opts: { name: 'Component > Example', description: 'Component Link that accepts xyz', displayField: 'title', }, }; const fields = [ { id: 'title', name: 'Title', }, ]; const component = new OperateOn(migration, context, contentTypeDef, fields); await component.operationOnContent; await component.operationOnField; }; module.exports = migrationFunction;
Debug
Known issues
breakingPackage relies on outdated contentful-migration v1; breaking changes in contentful-migration v2+ may cause runtime errors.
fix
Pin contentful-migration to v1.x or fork and update.
affects: >=0.9.0
deprecatedClass OperateOn uses property accessor syntax (e.g., await component.operationOnContent; this is a getter that returns a Promise, not a method).
fix
Use await component.operationOnContent as shown; no parentheses.
affects: >=0.0.1
gotchaThe constructor expects contentTypeExample as an object with `id` and `opts` properties, but the README uses `contentTypeExample` as variable name but parameter name is different.
fix
Ensure you pass an object with `id` and `opts` keys, not just the id string.
affects: >=0.0.1
gotchaFields array items must have `id` and `name` for simple Symbol fields; for other types, `type` must be specified.
fix
Always include `type` key in field objects for non-Symbol fields (e.g., 'Text', 'Integer').
affects: >=0.0.1
Errors
Common errors & fixes
TypeError: migration.createContentType is not a function
Using contentful-migration v2+ which changed API; smart-migration expects v1 API.
fix
Downgrade contentful-migration to v1.x or patch migration object.
Cannot find module 'contentful-smart-migration'
Package is not installed or is ESM-only but used with CommonJS require.
fix
Install with 'npm i contentful-smart-migration' and use import syntax.
Uncaught TypeError: component.operationOnContent is not a function
Using method call syntax with parentheses; operationOnContent is a getter that returns a Promise.
fix
Use 'await component.operationOnContent' without parentheses.
Upgrade
Version history
1.3.1latest on npm
Audit
Dependencies
contentful-migrationrequiredCore dependency for Contentful migration functionality; this package wraps it.
Agent activity
8 hits · last 30 days
node
8
Resources
contentful-smart-migration — npm install contentful-smart-migration · libregistry