From 54eae0125511c55c09f54c0185f092d489b7ea77 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 17 Jan 2023 18:34:11 -0600 Subject: [PATCH] Rename some files to .cjs, make the codebase aware of .cjs and .mjs extensions --- .eslintignore | 2 +- .eslintrc.js => .eslintrc.cjs | 2 +- .gitlab-ci.yml | 6 ++++-- .lintstagedrc.json | 3 +++ babel.config.js => babel.config.cjs | 0 jest.config.js => jest.config.cjs | 4 +++- jest/{assetTransformer.js => assetTransformer.cjs} | 0 package.json | 2 +- postcss.config.js => postcss.config.cjs | 0 tailwind.config.js => tailwind.config.cjs | 2 +- tailwind/__tests__/colors-test.js | 2 +- tailwind/{colors.js => colors.cjs} | 0 webpack/configuration.ts | 2 +- webpack/rules/babel.ts | 2 +- 14 files changed, 17 insertions(+), 10 deletions(-) rename .eslintrc.js => .eslintrc.cjs (99%) rename babel.config.js => babel.config.cjs (100%) rename jest.config.js => jest.config.cjs (92%) rename jest/{assetTransformer.js => assetTransformer.cjs} (100%) rename postcss.config.js => postcss.config.cjs (100%) rename tailwind.config.js => tailwind.config.cjs (98%) rename tailwind/{colors.js => colors.cjs} (100%) diff --git a/.eslintignore b/.eslintignore index 0c17e6907..1ab6f8d8c 100644 --- a/.eslintignore +++ b/.eslintignore @@ -5,4 +5,4 @@ /tmp/** /coverage/** /custom/** -!.eslintrc.js +!.eslintrc.cjs diff --git a/.eslintrc.js b/.eslintrc.cjs similarity index 99% rename from .eslintrc.js rename to .eslintrc.cjs index 7cefd7347..6b562e5bf 100644 --- a/.eslintrc.js +++ b/.eslintrc.cjs @@ -43,7 +43,7 @@ module.exports = { react: { version: 'detect', }, - 'import/extensions': ['.js', '.jsx', '.ts', '.tsx'], + 'import/extensions': ['.js', '.jsx', '.cjs', '.mjs', '.ts', '.tsx'], 'import/ignore': [ 'node_modules', '\\.(css|scss|json)$', diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f124eb505..ab2fb497d 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -48,10 +48,12 @@ lint-js: changes: - "**/*.js" - "**/*.jsx" + - "**/*.cjs" + - "**/*.mjs" - "**/*.ts" - "**/*.tsx" - ".eslintignore" - - ".eslintrc.js" + - ".eslintrc.cjs" lint-sass: stage: test @@ -72,7 +74,7 @@ jest: - "app/soapbox/**/*" - "webpack/**/*" - "custom/**/*" - - "jest.config.js" + - "jest.config.cjs" - "package.json" - "yarn.lock" - ".gitlab-ci.yml" diff --git a/.lintstagedrc.json b/.lintstagedrc.json index 5dcd5926a..97bad7f28 100644 --- a/.lintstagedrc.json +++ b/.lintstagedrc.json @@ -1,5 +1,8 @@ { "*.js": "eslint --cache", + "*.cjs": "eslint --cache", + "*.mjs": "eslint --cache", "*.ts": "eslint --cache", + "*.tsx": "eslint --cache", "app/styles/**/*.scss": "stylelint" } diff --git a/babel.config.js b/babel.config.cjs similarity index 100% rename from babel.config.js rename to babel.config.cjs diff --git a/jest.config.js b/jest.config.cjs similarity index 92% rename from jest.config.js rename to jest.config.cjs index 0974fb621..300e2c3ba 100644 --- a/jest.config.js +++ b/jest.config.cjs @@ -18,6 +18,8 @@ module.exports = { ], 'collectCoverageFrom': [ 'app/soapbox/**/*.js', + 'app/soapbox/**/*.cjs', + 'app/soapbox/**/*.mjs', 'app/soapbox/**/*.ts', 'app/soapbox/**/*.tsx', '!app/soapbox/features/emoji/emoji-compressed.js', @@ -43,6 +45,6 @@ module.exports = { ], 'transform': { '\\.[jt]sx?$': 'babel-jest', - [`\\.(${ASSET_EXTS})$`]: '/jest/assetTransformer.js', + [`\\.(${ASSET_EXTS})$`]: '/jest/assetTransformer.cjs', }, }; diff --git a/jest/assetTransformer.js b/jest/assetTransformer.cjs similarity index 100% rename from jest/assetTransformer.js rename to jest/assetTransformer.cjs diff --git a/package.json b/package.json index 6e34fa696..db1d4a810 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "test:coverage": "${npm_execpath} run test --coverage", "test:all": "${npm_execpath} run test:coverage && ${npm_execpath} run lint", "lint": "${npm_execpath} run lint:js && ${npm_execpath} run lint:sass", - "lint:js": "npx eslint --ext .js,.jsx,.ts,.tsx . --cache", + "lint:js": "npx eslint --ext .js,.jsx,.cjs,.mjs,.ts,.tsx . --cache", "lint:sass": "npx stylelint app/styles/**/*.scss", "prepare": "husky install" }, diff --git a/postcss.config.js b/postcss.config.cjs similarity index 100% rename from postcss.config.js rename to postcss.config.cjs diff --git a/tailwind.config.js b/tailwind.config.cjs similarity index 98% rename from tailwind.config.js rename to tailwind.config.cjs index 2f7b72fb2..d5c9d5f06 100644 --- a/tailwind.config.js +++ b/tailwind.config.cjs @@ -1,4 +1,4 @@ -const { parseColorMatrix } = require('./tailwind/colors'); +const { parseColorMatrix } = require('./tailwind/colors.cjs'); /** @type {import('tailwindcss').Config} */ module.exports = { diff --git a/tailwind/__tests__/colors-test.js b/tailwind/__tests__/colors-test.js index 36bc2526c..db5695e39 100644 --- a/tailwind/__tests__/colors-test.js +++ b/tailwind/__tests__/colors-test.js @@ -1,7 +1,7 @@ import { withOpacityValue, parseColorMatrix, -} from '../colors'; +} from '../colors.cjs'; describe('withOpacityValue()', () => { it('returns a Tailwind color function with alpha support', () => { diff --git a/tailwind/colors.js b/tailwind/colors.cjs similarity index 100% rename from tailwind/colors.js rename to tailwind/colors.cjs diff --git a/webpack/configuration.ts b/webpack/configuration.ts index 39b8bef8e..deb4e50b4 100644 --- a/webpack/configuration.ts +++ b/webpack/configuration.ts @@ -12,7 +12,7 @@ const settings = { test_root_path: `${FE_BUILD_DIR}-test`, cache_path: 'tmp/cache', resolved_paths: [], - extensions: [ '.mjs', '.js', '.jsx', '.ts', '.tsx', '.sass', '.scss', '.css', '.module.sass', '.module.scss', '.module.css', '.png', '.svg', '.gif', '.jpeg', '.jpg' ], + extensions: [ '.js', '.jsx', '.cjs', '.mjs', '.ts', '.tsx', '.sass', '.scss', '.css', '.module.sass', '.module.scss', '.module.css', '.png', '.svg', '.gif', '.jpeg', '.jpg' ], }; const outputDir = env.NODE_ENV === 'test' ? settings.test_root_path : settings.public_root_path; diff --git a/webpack/rules/babel.ts b/webpack/rules/babel.ts index 21e9c72db..9946bc87a 100644 --- a/webpack/rules/babel.ts +++ b/webpack/rules/babel.ts @@ -7,7 +7,7 @@ import type { RuleSetRule } from 'webpack'; const isDevelopment = process.env.NODE_ENV === 'development'; const rule: RuleSetRule = { - test: /\.(js|jsx|mjs|ts|tsx)$/, + test: /\.(js|jsx|cjs|mjs|ts|tsx)$/, include: [ settings.source_path, ...settings.resolved_paths,