Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(f36-codemod): ESM #2264

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat(f36-codemod): ESM
  • Loading branch information
denkristoffer committed Apr 9, 2024
commit 0608fe6645322a44f3e2e31545150e593138f502
596 changes: 305 additions & 291 deletions package-lock.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
const path = require('path');
const chalk = require('chalk');
const execa = require('execa');
const isGitClean = require('is-git-clean');
const inquirer = require('inquirer');
const meow = require('meow');
const globby = require('globby');
const inquirerChoices = require('./inquirer-choices');
const updateDependencies = require('./updateDependencies');

import path from 'node:path';
import { fileURLToPath } from 'node:url';
import chalk from 'chalk';
import execa from 'execa';
import isGitClean from 'is-git-clean';
import inquirer from 'inquirer';
import meow from 'meow';
import globby from 'globby';
import { createRequire } from 'module';
import * as inquirerChoices from './inquirer-choices.mjs';
import updateDependencies from './updateDependencies.mjs';

const require = createRequire(import.meta.url);
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const transformerDirectory = path.join(__dirname, '../', 'transforms');
const jscodeshiftExecutable = require.resolve('.bin/jscodeshift');

Expand Down Expand Up @@ -94,7 +99,7 @@ function expandFilePathsIfNeeded(files) {
return shouldExpandFiles ? globby.sync(files) : files;
}

function run() {
export function run() {
const cli = meow(
{
description: 'Codemods for updating Forma-36 codes',
Expand Down Expand Up @@ -235,7 +240,3 @@ function run() {
});
});
}

module.exports = {
run,
};
3 changes: 0 additions & 3 deletions packages/forma-36-codemod/bin/f36-codemod.js

This file was deleted.

5 changes: 5 additions & 0 deletions packages/forma-36-codemod/bin/f36-codemod.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env node

import { run } from './cli.mjs';

run();
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const inquirer = require('inquirer');
import inquirer from 'inquirer';

const PARSER_CHOICES = [
export const PARSER_CHOICES = [
{
name: 'JavaScript',
value: 'babel',
Expand All @@ -11,7 +11,7 @@ const PARSER_CHOICES = [
},
];

const SETUP_CHOICES = [
export const SETUP_CHOICES = [
{
name: 'run-all-v4: Update package json with new packages and remove old ones, remove v3 CSS imports and run all possible codemods for components.',
value: 'run-all-v4',
Expand Down Expand Up @@ -154,17 +154,11 @@ const V4_CODEMODS = [
// Add extra codemods - do not remove
].sort((a, b) => (a.value < b.value ? -1 : 1));

const TRANSFORMS_CHOICES = [
export const TRANSFORMS_CHOICES = [
{
name: 'color-tokens-to-new-tokens: Converts deprecated color tokens to the new ones',
value: 'color-tokens-to-new-tokens',
},
new inquirer.Separator(),
...V4_CODEMODS,
];

module.exports = {
PARSER_CHOICES,
TRANSFORMS_CHOICES,
SETUP_CHOICES,
};
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
const PACKAGES_UPGRADE = {
export const PACKAGES_UPGRADE = {
'@contentful/f36-components': '^4.0.0',
'@contentful/f36-tokens': '^4.0.0',
};

const PACKAGES_REMOVE = [
export const PACKAGES_REMOVE = [
'@contentful/forma-36-fcss',
'@contentful/forma-36-react-components',
'@contentful/forma-36-tokens',
];

module.exports = {
PACKAGES_UPGRADE,
PACKAGES_REMOVE,
};
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const path = require('path');
const fs = require('fs');
const chalk = require('chalk');
const execa = require('execa');
const semverSatisfies = require('semver/functions/satisfies');
const readPkgUp = require('read-pkg-up');
const packages = require('./packages-list');
const inquirer = require('inquirer');
import path from 'node:path';
import fs from 'node:fs';
import chalk from 'chalk';
import execa from 'execa';
import semverSatisfies from 'semver/functions/satisfies.js';
import readPkgUp from 'read-pkg-up';
import inquirer from 'inquirer';
import * as packages from './packages-list.mjs';

const dependencyProperties = [
'clientDependencies',
Expand Down Expand Up @@ -63,7 +63,8 @@ function getOutput({ newPackages, removePackages, pkgManager = null }) {
}
}

async function updateDependencies(targetDir) {
// eslint-disable-next-line import/no-default-export
export default async function updateDependencies(targetDir) {
const cwd = path.resolve(process.cwd(), targetDir);
const closestPkgJson = readPkgUp.sync({ cwd });
let removePackages = packages.PACKAGES_REMOVE;
Expand Down Expand Up @@ -154,5 +155,3 @@ async function updateDependencies(targetDir) {
return getOutput({ newPackages, removePackages, pkgManager });
});
}

module.exports = updateDependencies;
5 changes: 3 additions & 2 deletions packages/forma-36-codemod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@contentful/f36-codemod",
"description": "Forma 36 Codemod",
"version": "4.3.2",
"main": "bin/f36-codemod.js",
"main": "bin/f36-codemod.mjs",
"license": "MIT",
"files": [
"package.json",
Expand All @@ -11,14 +11,15 @@
"utils"
],
"bin": {
"f36-codemod": "./bin/f36-codemod.js"
"f36-codemod": "./bin/f36-codemod.mjs"
},
"scripts": {
"test": "jest",
"test:watch": "jest --watchAll",
"lint": "eslint ."
},
"devDependencies": {
"@types/semver": "^7.3.12",
"eslint": "^8.43.0",
"jest": "^29.3.1"
},
Expand Down
Loading