Skip to content

Commit

Permalink
Add support for mjs and cjs extensions with CSS side-effect imports (#…
Browse files Browse the repository at this point in the history
…5564)

Co-authored-by: Logan McAnsh <logan@mcan.sh>
Co-authored-by: Mark Dalgleish <mark.john.dalgleish@gmail.com>
  • Loading branch information
3 people authored Mar 14, 2023
1 parent 4867713 commit 5782a43
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/css-side-effect-import-extensions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@remix-run/dev": patch
---

Add support for `.mjs` and `.cjs` extensions when detecting CSS side-effect imports
1 change: 1 addition & 0 deletions contributors.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
- derekr
- derenge
- developit
- devongovett
- dgurns
- dhargitai
- dhmacs
Expand Down
6 changes: 5 additions & 1 deletion integration/css-side-effect-imports-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
createFixture,
css,
js,
json,
} from "./helpers/create-fixture";

const TEST_PADDING_VALUE = "20px";
Expand Down Expand Up @@ -251,7 +252,7 @@ test.describe("CSS side-effect imports", () => {
padding: ${TEST_PADDING_VALUE};
}
`,
"node_modules/@test-package/esm/index.js": js`
"node_modules/@test-package/esm/index.mjs": js`
import React from 'react';
import './styles.css';
Expand All @@ -266,6 +267,9 @@ test.describe("CSS side-effect imports", () => {
);
};
`,
"node_modules/@test-package/esm/package.json": json({
exports: './index.mjs'
}),
"app/routes/esm-package-test.jsx": js`
import { Test } from "@test-package/esm";
export default function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,19 @@ export function isCssSideEffectImportPath(path: string): boolean {
return cssSideEffectFilter.test(path);
}

const loaders = ["js", "jsx", "ts", "tsx"] as const;
const allJsFilesFilter = new RegExp(`\\.(${loaders.join("|")})$`);
const extensions = ["js", "jsx", "ts", "tsx", "mjs", "cjs"] as const;
const allJsFilesFilter = new RegExp(`\\.(${extensions.join("|")})$`);

type Loader = typeof loaders[number];
type Extension = `.${Loader}`;
type Loader = 'js' | 'jsx' | 'ts' | 'tsx';
type Extension = `.${typeof extensions[number]}`;

const loaderForExtension: Record<Extension, Loader> = {
".js": "js",
".jsx": "jsx",
".ts": "ts",
".tsx": "tsx",
".mjs": "js",
".cjs": "js"
};

/**
Expand Down

0 comments on commit 5782a43

Please sign in to comment.