@putout/plugin-esm 8.6.0 → 8.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -34,8 +34,8 @@ npm i putout @putout/plugin-esm -D
34
34
 
35
35
  ## File rules
36
36
 
37
- - ✅ [apply-name-to-imported-file](#apply-name-to-imported-file]]);
38
- - ✅ [apply-namespace-to-imported-file](#apply-namespace-to-imported-file]]);
37
+ - ✅ [apply-name-to-imported-file](#apply-name-to-imported-file);
38
+ - ✅ [apply-namespace-to-imported-file](#apply-namespace-to-imported-file);
39
39
  - ✅ [apply-privately-imported-file](#apply-privately-imported-file);
40
40
  - ✅ [apply-js-imported-file](#apply-js-imported-file);
41
41
  - ✅ [resolve-imported-file](#resolve-imported-file);
@@ -428,9 +428,9 @@ Let's consider file structure:
428
428
 
429
429
  ```
430
430
  /
431
- |-- lib/
432
- | `-- index.js "import a from './a.js';"
433
- | `-- a.js "export const x = 2;"
431
+ └── lib/
432
+ ├── index.js "import a from './a.js';"
433
+ └── b.js "export const b = 2;"
434
434
  ```
435
435
 
436
436
  In this case `index.js` can be fixed:
@@ -459,10 +459,10 @@ Let's consider file structure:
459
459
 
460
460
  ```
461
461
  /
462
- |-- lib/
463
- | `-- index.js "import a from './a.js';\n export * as b from './b.js'"
464
- | `-- a.js "export const a = 2;"
465
- | `-- b.js "export const b = 2;"
462
+ └── lib/
463
+ ├── index.js "import a from './a.js';\n export * as b from './b.js'"
464
+ ├── a.js "export const a = 2;"
465
+ └── b.js "export const b = 2;"
466
466
  ```
467
467
 
468
468
  In this case `index.js` can be fixed:
@@ -500,12 +500,12 @@ Let's consider file structure:
500
500
 
501
501
  ```
502
502
  /
503
- |-- package.json {"imports": {"#is: {"default": "./lib/tokenize/is.js"}}}
504
- |-- lib/
505
- | `-- tokenize/
506
- | `-- is.js "export const isPrev = () => {}"
507
- | `-- expressions/
508
- `-- spread-element.js "import {isPrev} from '../is.js"
503
+ ├── package.json {"imports": {"#is: {"default": "./lib/tokenize/is.js"}}}
504
+ └── lib/
505
+ └── tokenize/
506
+ ├── is.js "export const isPrev = () => {}"
507
+ └── expressions/
508
+ └── spread-element.js "import {isPrev} from '../is.js"
509
509
  ```
510
510
 
511
511
  In this case `spread-element.js` can be fixed:
@@ -534,9 +534,9 @@ Let's consider file structure:
534
534
 
535
535
  ```
536
536
  /
537
- |-- lib/
538
- | `-- index.js
539
- | `-- a.js
537
+ └── lib/
538
+ ├── index.js
539
+ └── a.js
540
540
  ```
541
541
 
542
542
  In this case `index.js` can be fixed:
@@ -564,9 +564,9 @@ Let's consider file structure:
564
564
 
565
565
  ```
566
566
  /
567
- |-- processors/
568
- | `-- index.js
569
- | `-- parse-processor-names.js
567
+ └── processors/
568
+ ├── index.js
569
+ └── parse-processor-names.js
570
570
  ```
571
571
 
572
572
  In this case `index.js` can be fixed:
@@ -594,9 +594,9 @@ Let's consider file structure:
594
594
 
595
595
  ```
596
596
  /
597
- |-- lib/
598
- | `-- index.js
599
- | `-- a.js
597
+ └── lib/
598
+ ├── index.js
599
+ └── a.js
600
600
  ```
601
601
 
602
602
  In this case `index.js` can be fixed:
@@ -5,20 +5,15 @@ import * as isESMPlugin from '#is-esm';
5
5
  const isESM = (a) => a.rule === 'is-esm';
6
6
  const hasExportDefault = (a) => a.rule === 'has-export-default';
7
7
 
8
- const {
9
- findFile,
10
- readFileContent,
11
- } = operator;
8
+ const {readFileContent} = operator;
12
9
 
13
- export const determineImportType = ({name, rootPath, importedFilename, privateImports, crawled}) => {
10
+ export const determineImportType = ({name, rootPath, importedFilename, privateImports, crawlFile}) => {
14
11
  const parsedName = parseImportedFilename({
15
12
  importedFilename,
16
13
  privateImports,
17
14
  });
18
15
 
19
- const [importedFile] = findFile(rootPath, parsedName, {
20
- crawled,
21
- });
16
+ const [importedFile] = crawlFile(rootPath, parsedName);
22
17
 
23
18
  if (!importedFile)
24
19
  return '';
@@ -31,6 +31,7 @@ const getImport = (path) => {
31
31
 
32
32
  if (isImportDefaultSpecifier(first)) {
33
33
  const {name} = first.local;
34
+
34
35
  return [
35
36
  name,
36
37
  source,
@@ -6,14 +6,13 @@ import {
6
6
  } from 'putout';
7
7
  import {createGetPrivateImports} from '#private-imports';
8
8
  import {determineImportType} from '#determine-import-type';
9
+ import {getImportsTuples} from '#get-imports-tuples';
9
10
  import {transformNamedImport} from './transform-named-import.js';
10
- import {getImportsTuples} from './get-imports-tuples.js';
11
11
 
12
12
  const {
13
13
  getFilename,
14
14
  readFileContent,
15
15
  writeFileContent,
16
- crawlDirectory,
17
16
  } = operator;
18
17
 
19
18
  export const report = (file, {name, source, type}) => {
@@ -37,14 +36,13 @@ export const fix = (file, {name, source, content, ast}) => {
37
36
  writeFileContent(file, newContent);
38
37
  };
39
38
 
40
- export const scan = (rootPath, {push, trackFile}) => {
39
+ export const scan = (rootPath, {push, trackFile, crawlFile}) => {
41
40
  const mask = [
42
41
  '*.js',
43
42
  '*.mjs',
44
43
  ];
45
44
 
46
45
  const getPrivateImports = createGetPrivateImports();
47
- const crawled = crawlDirectory(rootPath);
48
46
 
49
47
  for (const file of trackFile(rootPath, mask)) {
50
48
  const content = readFileContent(file);
@@ -65,7 +63,7 @@ export const scan = (rootPath, {push, trackFile}) => {
65
63
  rootPath,
66
64
  importedFilename,
67
65
  privateImports,
68
- crawled,
66
+ crawlFile,
69
67
  });
70
68
 
71
69
  if (importType === 'equal')
@@ -6,14 +6,13 @@ import {
6
6
  } from 'putout';
7
7
  import {createGetPrivateImports} from '#private-imports';
8
8
  import {determineImportType} from '#determine-import-type';
9
+ import {getImportsTuples} from '#get-imports-tuples';
9
10
  import {transformNamespaceImport} from './transform-namespace-import.js';
10
- import {getImportsTuples} from '../apply-name-to-imported-file/get-imports-tuples.js';
11
11
 
12
12
  const {
13
13
  getFilename,
14
14
  readFileContent,
15
15
  writeFileContent,
16
- crawlDirectory,
17
16
  } = operator;
18
17
 
19
18
  export const report = (file, {name, source}) => {
@@ -33,14 +32,13 @@ export const fix = (file, {name, source, content, ast}) => {
33
32
  writeFileContent(file, newContent);
34
33
  };
35
34
 
36
- export const scan = (rootPath, {push, trackFile}) => {
35
+ export const scan = (rootPath, {push, trackFile, crawlFile}) => {
37
36
  const mask = [
38
37
  '*.js',
39
38
  '*.mjs',
40
39
  ];
41
40
 
42
41
  const getPrivateImports = createGetPrivateImports();
43
- const crawled = crawlDirectory(rootPath);
44
42
 
45
43
  for (const file of trackFile(rootPath, mask)) {
46
44
  const content = readFileContent(file);
@@ -61,7 +59,7 @@ export const scan = (rootPath, {push, trackFile}) => {
61
59
  rootPath,
62
60
  importedFilename,
63
61
  privateImports,
64
- crawled,
62
+ crawlFile,
65
63
  });
66
64
 
67
65
  if (importType === 'namespace')
@@ -25,10 +25,11 @@ export const fix = ({grouped}) => {
25
25
 
26
26
  export const traverse = ({push}) => ({
27
27
  Program(path) {
28
- const external = [];
29
- const internal = [];
28
+ const css = [];
30
29
  const builtin = [];
30
+ const external = [];
31
31
  const hashed = [];
32
+ const internal = [];
32
33
  const all = path.get('body').filter(isImportDeclaration);
33
34
 
34
35
  if (!all.length)
@@ -37,6 +38,11 @@ export const traverse = ({push}) => ({
37
38
  for (const current of all) {
38
39
  const {value} = current.node.source;
39
40
 
41
+ if (value.endsWith('.css')) {
42
+ css.push(current);
43
+ continue;
44
+ }
45
+
40
46
  if (value.startsWith('.')) {
41
47
  internal.push(current);
42
48
  continue;
@@ -56,6 +62,7 @@ export const traverse = ({push}) => ({
56
62
  }
57
63
 
58
64
  const grouped = [
65
+ ...css,
59
66
  ...builtin,
60
67
  ...external,
61
68
  ...hashed,
@@ -1,6 +1,9 @@
1
1
  export const report = () => '';
2
2
  export const replace = ({options}) => {
3
- const {from = '', to = ''} = options;
3
+ const {
4
+ from = '',
5
+ to = '',
6
+ } = options;
4
7
 
5
8
  if (!from || !to)
6
9
  return {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/plugin-esm",
3
- "version": "8.6.0",
3
+ "version": "8.8.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "🐊Putout plugin improves ability to transform ESM code",
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "imports": {
14
14
  "#get-imports": "./lib/shorten-imported-file/get-imports/index.js",
15
- "#get-imports-tuples": "./lib/shorten-imported-file/get-imports-tuples.js",
15
+ "#get-imports-tuples": "./lib/apply-name-to-imported-file/get-imports-tuples.js",
16
16
  "#get-default-imports": "./lib/apply-name-to-imported-file/get-imports/index.js",
17
17
  "#change-imports": "./lib/resolve-imported-file/change-imports/index.js",
18
18
  "#private-imports": "./lib/apply-privately-imported-file/private-imports.js",