Skip to content

Commit

Permalink
Convert scripts to ES modules
Browse files Browse the repository at this point in the history
Signed-off-by: Jon Koops <[email protected]>
  • Loading branch information
jonkoops committed Aug 24, 2024
1 parent 2e6837e commit 6c9fed6
Show file tree
Hide file tree
Showing 30 changed files with 104 additions and 118 deletions.
2 changes: 1 addition & 1 deletion .github/actions/setup-project/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ runs:
- name: Run build
if: inputs.skip-build != 'true' && steps.cache-build.outputs.cache-hit != 'true'
shell: bash
run: yarn build && yarn build:umd
run: yarn build && yarn build:umd && yarn clean:exports
env:
# Disable V8 compile cache to hard crashes in Node.js. This can likely be removed once upgraded to the next LTS version (version 22).
# See: https://github.com/nodejs/node/issues/51555
Expand Down
6 changes: 3 additions & 3 deletions .github/split.js → .github/split.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/* eslint-disable no-console */
const fs = require('fs');
const path = require('path');
import fs from 'node:fs';
import path from 'node:path';

const BASE_DIR = path.join(__dirname, '../packages/react-integration/cypress/integration');
const BASE_DIR = path.resolve(import.meta.dirname, '../packages/react-integration/cypress/integration');
const WORKER_NUM = +process.env.WORKER_NUM;
const WORKER_COUNT = +process.env.WORKER_COUNT;

Expand Down
7 changes: 4 additions & 3 deletions .github/upload-preview.js → .github/upload-preview.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
/* eslint-disable no-console, camelcase */
const path = require('path');
const { Octokit } = require('@octokit/rest');
import { Octokit } from '@octokit/rest';
import path from 'node:path';
import surge from 'surge';

const octokit = new Octokit({ auth: process.env.GH_PR_TOKEN });
const surge = require('surge');
const publishFn = surge().publish();

// From github actions
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ jobs:

- name: Upload documentation
if: always()
run: node .github/upload-preview.js packages/react-docs/public
run: node .github/upload-preview.mjs packages/react-docs/public

- name: Run accessibility tests
run: yarn serve:docs & yarn test:a11y

- name: Upload accessibility results
if: always()
run: node .github/upload-preview.js packages/react-docs/coverage
run: node .github/upload-preview.mjs packages/react-docs/coverage
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ jobs:
run: printenv

- name: Run Cypress tests
run: yarn serve:integration & yarn test:integration -s $(node .github/split.js)
run: yarn serve:integration & yarn test:integration -s $(node .github/split.mjs)
env:
WORKER_NUM: ${{ matrix.worker }}
WORKER_COUNT: 5
2 changes: 1 addition & 1 deletion packages/react-charts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
},
"scripts": {
"clean": "rimraf dist",
"build:single:packages": "node ../../scripts/build-single-packages.js --config single-packages.config.json"
"build:single:packages": "node ../../scripts/build-single-packages.mjs --config single-packages.config.json"
},
"devDependencies": {
"@types/lodash": "^4.17.5",
Expand Down
8 changes: 4 additions & 4 deletions packages/react-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
"homepage": "https://github.com/patternfly/patternfly-react#readme",
"scripts": {
"build:umd": "rollup -c --environment IS_PRODUCTION",
"build:single:packages": "node ../../scripts/build-single-packages.js --config single-packages.config.json",
"build:single:packages": "node ../../scripts/build-single-packages.mjs --config single-packages.config.json",
"clean": "rimraf dist components layouts helpers next deprecated",
"generate": "node scripts/copyStyles.js",
"subpaths": "node ../../scripts/exportSubpaths.js --config subpaths.config.json",
"clean:exports": "node scripts/cleanDistExports.js"
"generate": "node scripts/copyStyles.mjs",
"subpaths": "node ../../scripts/exportSubpaths.mjs --config subpaths.config.json",
"clean:exports": "node scripts/cleanDistExports.mjs"
},
"dependencies": {
"@patternfly/react-icons": "workspace:^",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const fs = require('fs');
const path = require('path');
import fs from 'node:fs';
import path from 'node:path';

const distIndexFiles = ['esm', 'js'].map((dir) => path.join(process.cwd(), 'dist', dir, 'index.js'));
const distIndexDeclarationFiles = ['esm', 'js'].map((dir) => path.join(process.cwd(), 'dist', dir, 'index.d.ts'));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
const { copySync, readFileSync, writeFileSync } = require('fs-extra');
const { resolve, dirname, join } = require('path');
const { parse: parseCSS, stringify: stringifyCSS } = require('css');
import { copySync } from 'fs-extra/esm';
import { readFileSync, writeFileSync } from 'node:fs';
import { createRequire } from 'node:module';
import { resolve, dirname, join } from 'node:path';
import { parse as parseCSS, stringify as stringifyCSS } from 'css';

const stylesDir = resolve(__dirname, '../dist/styles');
const require = createRequire(import.meta.url);
const stylesDir = resolve(import.meta.dirname, '../dist/styles');
const pfDir = dirname(require.resolve('@patternfly/patternfly/patternfly.css'));

const unusedSelectorRegEx = /(\.fas?|\.sr-only)/;
Expand Down
4 changes: 0 additions & 4 deletions packages/react-core/src/helpers/safeHTMLElement.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/react-icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"homepage": "https://github.com/patternfly/patternfly-react#readme",
"scripts": {
"build:single:packages": "node ../../scripts/build-single-packages.js --config single-packages.config.json",
"build:single:packages": "node ../../scripts/build-single-packages.mjs --config single-packages.config.json",
"clean": "rimraf dist src/icons src/index.js src/index.d.ts",
"generate": "rimraf dist/esm/icons dist/js/icons && node scripts/writeIcons.mjs"
},
Expand Down
4 changes: 2 additions & 2 deletions packages/react-icons/scripts/generateIcons.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import faIcons from './icons/fontawesomeIcons.js';
import faIcons from './icons/fontawesomeIcons.mjs';
import patternflyIcons from './icons/patternflyIcons.mjs';
import customIcons from './icons/customIcons.js';
import customIcons from './icons/customIcons.mjs';

/**
* Generates icons from FontAwesome, PatternFly CSS, and custom icons in this repo.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
openshift: {
xOffset: 116,
yOffset: 0,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { fas } = require('@fortawesome/free-solid-svg-icons');
const { far } = require('@fortawesome/free-regular-svg-icons');
const { fab } = require('@fortawesome/free-brands-svg-icons');
import { fas } from '@fortawesome/free-solid-svg-icons';
import { far } from '@fortawesome/free-regular-svg-icons';
import { fab } from '@fortawesome/free-brands-svg-icons';

/**
* @param {object} icon FontAwesome icon to convert
Expand Down Expand Up @@ -50,8 +50,10 @@ function convertIcons(icons) {
}, {});
}

module.exports = {
const faIcons = {
...convertIcons(fas),
...convertIcons(fab),
...convertIcons(far)
};

export default faIcons;
4 changes: 2 additions & 2 deletions packages/react-table/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
"homepage": "https://github.com/patternfly/patternfly-react/tree/main/packages/react-table#readme",
"scripts": {
"build:umd": "rollup -c --environment IS_PRODUCTION",
"build:single:packages": "node ../../scripts/build-single-packages.js --config single-packages.config.json",
"build:single:packages": "node ../../scripts/build-single-packages.mjs --config single-packages.config.json",
"clean": "rimraf dist components deprecated",
"subpaths": "node ../../scripts/exportSubpaths.js --config subpaths.config.json"
"subpaths": "node ../../scripts/exportSubpaths.mjs --config subpaths.config.json"
},
"dependencies": {
"@patternfly/react-core": "workspace:^",
Expand Down
4 changes: 2 additions & 2 deletions packages/react-templates/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
"homepage": "https://github.com/patternfly/patternfly-react/tree/main/packages/react-templates#readme",
"scripts": {
"build:umd": "rollup -c --environment IS_PRODUCTION",
"build:single:packages": "node ../../scripts/build-single-packages.js --config single-packages.config.json",
"build:single:packages": "node ../../scripts/build-single-packages.mjs --config single-packages.config.json",
"clean": "rimraf dist components deprecated",
"subpaths": "node ../../scripts/exportSubpaths.js --config subpaths.config.json"
"subpaths": "node ../../scripts/exportSubpaths.mjs --config subpaths.config.json"
},
"dependencies": {
"@patternfly/react-core": "workspace:^",
Expand Down
7 changes: 0 additions & 7 deletions packages/react-templates/rollup.config.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/react-tokens/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"homepage": "https://github.com/patternfly/patternfly-react#readme",
"scripts": {
"generate": "yarn clean && node scripts/writeTokens.js",
"generate": "yarn clean && node scripts/writeTokens.mjs",
"clean": "rimraf dist"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const { glob } = require('glob');
const { dirname, basename, sep } = require('path');
const { parse, stringify } = require('css');
const { readFileSync } = require('fs');
import { glob } from 'glob';
import { createRequire } from 'node:module';
import { dirname, basename, sep } from 'node:path';
import { parse, stringify } from 'css';
import { readFileSync } from 'node:fs';

const require = createRequire(import.meta.url);
const pfStylesDir = dirname(require.resolve('@patternfly/patternfly/patternfly.css'));
const version = 'v6';

Expand Down Expand Up @@ -91,7 +93,7 @@ const getLocalVarsMap = (cssFiles) => {
* }
* }
*/
function generateTokens() {
export function generateTokens() {
const cssFiles = glob
.sync(['{**/{components,layouts}/**/*.css', '**/patternfly-charts.css', '**/patternfly-variables.css}'].join(','), {
cwd: pfStylesDir,
Expand Down Expand Up @@ -249,7 +251,3 @@ function generateTokens() {

return fileTokens;
}

module.exports = {
generateTokens
};
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const { outputFileSync } = require('fs-extra');
const { resolve, join } = require('path');
const { generateTokens } = require('./generateTokens');
import { outputFileSync } from 'fs-extra/esm';
import { resolve, join } from 'node:path';
import { generateTokens } from './generateTokens.mjs';

const outDir = resolve(__dirname, '../dist');
const outDir = resolve(import.meta.dirname, '../dist');

const writeESMExport = (tokenName, tokenString) =>
outputFileSync(
Expand Down
12 changes: 0 additions & 12 deletions plopfile.js

This file was deleted.

12 changes: 12 additions & 0 deletions plopfile.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { setActionTypes } from './scripts/generators/actionTypes.mjs';
import { setHelpers } from './scripts/generators/helpers.mjs';
import setPFGenerators from './scripts/generators/patternfly-component/index.mjs';
import setPackageGenerators from './scripts/generators/package/index.mjs';

export default function (plop) {
setHelpers(plop);
setActionTypes(plop);

setPFGenerators(plop);
setPackageGenerators(plop);
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
/* eslint-disable no-console */
const fse = require('fs-extra');
const path = require('path');
const { glob } = require('glob');
const getDynamicModuleMap = require('./parse-dynamic-modules');
import fse from 'fs-extra';
import { createRequire } from 'node:module';
import path from 'node:path';
import { glob } from 'glob';
import getDynamicModuleMap from './parse-dynamic-modules.mjs';

const require = createRequire(import.meta.url);
const root = process.cwd();
const packageJson = require(`${root}/package.json`);

Expand Down
6 changes: 4 additions & 2 deletions scripts/exportSubpaths.js → scripts/exportSubpaths.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
/* eslint-disable no-console */
const fse = require('fs-extra');
const path = require('path');
import fse from 'fs-extra';
import { createRequire } from 'node:module';
import path from 'node:path';

const require = createRequire(import.meta.url);
const root = process.cwd();
const packageJson = require(`${root}/package.json`);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const path = require('path');
const fs = require('fs-extra');
import path from 'node:path';
import fs from 'fs-extra';

const ADD_TO_BARREL_FILE = 'addToBarrelFile';
export const ADD_TO_BARREL_FILE = 'addToBarrelFile';

function setActionTypes(plop) {
export function setActionTypes(plop) {
plop.setActionType(ADD_TO_BARREL_FILE, addToBarrelFile);
}

Expand All @@ -29,8 +29,3 @@ async function addToBarrelFile(answers, config, plop) {
await fs.outputFile(pathToFile, updatedLines.join('\n'));
return `-> ${pathToFile}`;
}

module.exports = {
setActionTypes,
ADD_TO_BARREL_FILE
};
10 changes: 0 additions & 10 deletions scripts/generators/helpers.js

This file was deleted.

5 changes: 5 additions & 0 deletions scripts/generators/helpers.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const REMOVE_NPM_SCOPE = 'removeNPMScope';

export function setHelpers(plop) {
plop.setHelper(REMOVE_NPM_SCOPE, (text) => text.replace(/^@patternfly\//i, ''));
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const { join, resolve } = require('path');
const { REMOVE_NPM_SCOPE } = require('../helpers');
import { join, resolve } from 'node:path';
import { REMOVE_NPM_SCOPE } from '../helpers.mjs';

const packagesRoot = resolve(__dirname, '../../../packages');
const packagesRoot = resolve(import.meta.dirname, '../../../packages');

function setPackageGenerators(plop) {
export default function setPackageGenerators(plop) {
plop.setGenerator('Package', {
description: 'A new package for the monorepo',
prompts: [
Expand All @@ -30,7 +30,7 @@ function setPackageGenerators(plop) {
{
type: 'add',
path: join(packageBaseTemplate, `package.json`),
templateFile: resolve(__dirname, './package.json.hbs')
templateFile: resolve(import.meta.dirname, './package.json.hbs')
},
{
type: 'add',
Expand All @@ -42,17 +42,17 @@ function setPackageGenerators(plop) {
answers.buildsWithTypescript && {
type: 'add',
path: join(packageBaseTemplate, `.npmignore`),
templateFile: resolve(__dirname, './.npmignore')
templateFile: resolve(import.meta.dirname, './.npmignore')
},
answers.buildsWithTypescript && {
type: 'add',
path: join(packageBaseTemplate, `tsconfig.json`),
templateFile: resolve(__dirname, './tsconfig.json')
templateFile: resolve(import.meta.dirname, './tsconfig.json')
},
answers.buildsWithTypescript && {
type: 'add',
path: join(packageBaseTemplate, `tsconfig.cjs.json`),
templateFile: resolve(__dirname, './tsconfig.cjs.json')
templateFile: resolve(import.meta.dirname, './tsconfig.cjs.json')
},
{
type: 'add',
Expand All @@ -63,5 +63,3 @@ function setPackageGenerators(plop) {
}
});
}

module.exports = setPackageGenerators;
Loading

0 comments on commit 6c9fed6

Please sign in to comment.