Skip to content

Commit 00b856f

Browse files
committed
feature: @putout/plugin-esm: group-imports-by-source: css first
1 parent 6ea4e63 commit 00b856f

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import '#css/view.css';
2+
import rendy from 'rendy';
3+
import currify from 'currify';

packages/plugin-esm/lib/group-imports-by-source/index.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ export const fix = ({grouped}) => {
2525

2626
export const traverse = ({push}) => ({
2727
Program(path) {
28-
const external = [];
29-
const internal = [];
28+
const css = [];
3029
const builtin = [];
30+
const external = [];
3131
const hashed = [];
32+
const internal = [];
3233
const all = path.get('body').filter(isImportDeclaration);
3334

3435
if (!all.length)
@@ -37,6 +38,11 @@ export const traverse = ({push}) => ({
3738
for (const current of all) {
3839
const {value} = current.node.source;
3940

41+
if (value.endsWith('.css')) {
42+
css.push(current);
43+
continue;
44+
}
45+
4046
if (value.startsWith('.')) {
4147
internal.push(current);
4248
continue;
@@ -56,6 +62,7 @@ export const traverse = ({push}) => ({
5662
}
5763

5864
const grouped = [
65+
...css,
5966
...builtin,
6067
...external,
6168
...hashed,

packages/plugin-esm/lib/group-imports-by-source/index.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ test('putout: group-imports-by-source: transform: comment', (t) => {
3636
t.end();
3737
});
3838

39+
test('putout: group-imports-by-source: no report: css', (t) => {
40+
t.noReport('css');
41+
t.end();
42+
});
43+
3944
test('putout: group-imports-by-source: transform: convert-esm-to-commonjs', (t) => {
4045
t.transform('convert-esm-to-commonjs', {
4146
convertEsmToCommonJS,

0 commit comments

Comments
 (0)