add more explicit support for .mjs and .cjs extensions

Signed-off-by: Patrik Oldsberg <poldsberg@gmail.com>
This commit is contained in:
Patrik Oldsberg
2021-12-02 22:48:07 +01:00
parent c2da6492fb
commit 25dfc2d483
9 changed files with 30 additions and 10 deletions
+13
View File
@@ -0,0 +1,13 @@
---
'@backstage/create-app': patch
---
Updated the root `package.json` to include files with `.cjs` and `.mjs` extensions in the `"lint-staged"` configuration.
The make this change to an existing app, apply the following changes to the `package.json` file:
```diff
"lint-staged": {
- "*.{js,jsx,ts,tsx}": [
+ "*.{js,jsx,ts,tsx,mjs,cjs}": [
```
+5
View File
@@ -0,0 +1,5 @@
---
'@backstage/cli': patch
---
Add support for `.cjs` and `.mjs` extensions in local and dependency modules.
+1 -1
View File
@@ -81,7 +81,7 @@
},
"prettier": "@spotify/prettier-config",
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"*.{js,jsx,ts,tsx,mjs,cjs}": [
"eslint --fix",
"prettier --write"
],
+5 -3
View File
@@ -96,20 +96,22 @@ async function getProjectConfig(targetPath, displayName) {
rootDir: path.resolve(targetPath, 'src'),
coverageDirectory: path.resolve(targetPath, 'coverage'),
coverageProvider: 'v8',
collectCoverageFrom: ['**/*.{js,jsx,ts,tsx}', '!**/*.d.ts'],
collectCoverageFrom: ['**/*.{js,jsx,ts,tsx,mjs,cjs}', '!**/*.d.ts'],
moduleNameMapper: {
'\\.(css|less|scss|sss|styl)$': require.resolve('jest-css-modules'),
},
transform: {
'\\.(js|jsx|ts|tsx)$': require.resolve('./jestSucraseTransform.js'),
'\\.(js|jsx|ts|tsx|mjs|cjs)$': require.resolve(
'./jestSucraseTransform.js',
),
'\\.(bmp|gif|jpg|jpeg|png|frag|xml|svg|eot|woff|woff2|ttf)$':
require.resolve('./jestFileTransform.js'),
'\\.(yaml)$': require.resolve('jest-transform-yaml'),
},
// A bit more opinionated
testMatch: ['**/?(*.)test.{js,jsx,mjs,ts,tsx}'],
testMatch: ['**/?(*.)test.{js,jsx,ts,tsx,mjs,cjs}'],
transformIgnorePatterns: [`/node_modules/(?:${transformIgnorePattern})/`],
};
+1 -1
View File
@@ -20,7 +20,7 @@ import { paths } from '../lib/paths';
export default async (cmd: Command, cmdArgs: string[]) => {
const args = [
'--ext=js,jsx,ts,tsx',
'--ext=js,jsx,ts,tsx,mjs,cjs',
'--max-warnings=0',
`--format=${cmd.format}`,
...(cmdArgs ?? [paths.targetDir]),
+2 -2
View File
@@ -61,7 +61,7 @@ export const transforms = (options: TransformOptions): Transforms => {
},
},
{
test: /\.(jsx?|mjs)$/,
test: /\.(jsx?|mjs|cjs)$/,
exclude: /node_modules/,
loader: require.resolve('@sucrase/webpack-loader'),
options: {
@@ -71,7 +71,7 @@ export const transforms = (options: TransformOptions): Transforms => {
},
},
{
test: /\.m?js/,
test: /\.(js|mjs|cjs)/,
resolve: {
fullySpecified: false,
},
@@ -38,7 +38,7 @@
},
"prettier": "@spotify/prettier-config",
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
"*.{js,jsx,ts,tsx,mjs,cjs}": [
"eslint --fix",
"prettier --write"
],
+1 -1
View File
@@ -59,7 +59,7 @@ module.exports = ({ args }) => {
},
},
{
test: /\.(jsx?|mjs)$/,
test: /\.(jsx?|mjs|cjs)$/,
exclude: /node_modules/,
loader: require.resolve('@sucrase/webpack-loader'),
options: {
+1 -1
View File
@@ -129,7 +129,7 @@ async function main() {
const srcDir = resolvePath(rootPath, packageDir, 'src');
if (await fs.pathExists(srcDir)) {
const files = await globby(['**/*.{js,jsx,ts,tsx}'], {
const files = await globby(['**/*.{js,jsx,ts,tsx,mjs,cjs}'], {
cwd: srcDir,
});
fileQueue.push(