@putout/bundler 1.0.1 → 1.1.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/ChangeLog CHANGED
@@ -1,3 +1,14 @@
1
+ 2024.02.22, v1.1.0
2
+
3
+ feature:
4
+ - 57efbc0 package: drop unused dependencies
5
+ - 1ae4e71 bundler: improve support of external modules
6
+
7
+ 2024.02.19, v1.0.2
8
+
9
+ fix:
10
+ - 1cb74fe export: bundler -> bundle
11
+
1
12
  2024.02.19, v1.0.1
2
13
 
3
14
  fix:
package/lib/bundler.js CHANGED
@@ -19,7 +19,7 @@ const [, readAllFiles] = pluginFilesystem.rules['read-all-files'];
19
19
 
20
20
  const getMessage = (a) => a.message;
21
21
 
22
- export const bundler = (from, entry, filesystem, {
22
+ export const bundle = (from, entry, filesystem, {
23
23
  progress = createProgress(),
24
24
  branch = originalBranch,
25
25
  merge = originalMerge,
@@ -1,10 +1,10 @@
1
1
  import putout from 'putout';
2
2
  import {dirname} from 'node:path';
3
- // parse-require
4
- import * as parseRequire from './parse-require/index.js';
5
3
  import * as convertEsmToCommonjs from '@putout/plugin-nodejs/convert-esm-to-commonjs';
4
+ import * as parseRequire from './parse-require/index.js';
5
+
6
+ const returns = (a) => () => a;
6
7
 
7
- // parse-require
8
8
  const {operator} = putout;
9
9
  const {
10
10
  readFileContent,
@@ -13,26 +13,22 @@ const {
13
13
  } = operator;
14
14
 
15
15
  const getMessage = ({message}) => message;
16
+ const readExternalStub = returns('');
16
17
 
17
18
  export const report = (root, {file}) => file;
18
19
  export const fix = () => {};
19
20
  export const scan = (root, {push, options}) => {
20
- const {entry = '/index.js'} = options;
21
+ const {entry = '/index.js', readExternal = readExternalStub} = options;
21
22
  const files = new Set();
22
23
  const processingNames = new Set([entry]);
23
24
 
24
25
  for (const currentName of processingNames) {
25
- const [file] = findFile(root, currentName);
26
-
27
- if (!file)
28
- throw Error(`file '${currentName}' not found`);
29
-
30
- const filename = getFilename(file);
26
+ const [filename, content] = read(currentName, root, readExternal);
31
27
  const dir = dirname(filename);
32
28
 
33
29
  files.add(filename);
34
30
 
35
- const {places} = putout(readFileContent(file), {
31
+ const {places} = putout(content, {
36
32
  rules: {
37
33
  'parse-require': ['on', {
38
34
  dir,
@@ -54,3 +50,17 @@ export const scan = (root, {push, options}) => {
54
50
  });
55
51
  }
56
52
  };
53
+
54
+ function read(currentName, root, readExternal) {
55
+ if (!currentName.startsWith('/') && !currentName.startsWith('./'))
56
+ return [currentName, readExternal(currentName)];
57
+
58
+ const [file] = findFile(root, currentName);
59
+
60
+ if (!file)
61
+ throw Error(`file '${currentName}' not found`);
62
+
63
+ const filename = getFilename(file);
64
+
65
+ return [filename, readFileContent(file)];
66
+ }
@@ -1,23 +1,29 @@
1
- import {operator} from 'putout';
2
1
  import {resolve} from 'node:path';
2
+ import {operator} from 'putout';
3
3
 
4
4
  const {getTemplateValues} = operator;
5
5
 
6
- export const report = ({filename}) => maybeAddJs(filename);
7
- export const fix = () => {};
8
-
9
6
  const REQUIRE = 'require(__a)';
10
- const maybeAddJs = (a) => a.endsWith('js') ? a : `${a}.js`;
7
+
8
+ export const fix = () => {};
9
+ export const report = ({dir, filename}) => {
10
+ if (!filename.startsWith('/') && !filename.startsWith('./'))
11
+ return filename;
12
+
13
+ const resolved = resolve(dir, filename);
14
+
15
+ return resolved.endsWith('js') ? resolved : `${resolved}.js`;
16
+ };
11
17
 
12
18
  export const traverse = ({push, options}) => ({
13
19
  [REQUIRE]: (path) => {
14
20
  const {dir = '/'} = options;
15
21
  const {__a} = getTemplateValues(path, REQUIRE);
16
- const filename = resolve(dir, __a.value);
17
22
 
18
23
  push({
19
24
  path,
20
- filename,
25
+ filename: __a.value,
26
+ dir,
21
27
  });
22
28
  },
23
29
  });
@@ -0,0 +1,9 @@
1
+ import {createRequire} from 'node:module';
2
+ import {readFileSync} from 'node:fs';
3
+
4
+ const {resolve} = createRequire(import.meta.url);
5
+
6
+ export const readExternal = (name) => {
7
+ const absolute = resolve(name);
8
+ return readFileSync(absolute);
9
+ };
@@ -1,5 +1,5 @@
1
+ import path from 'node:path';
1
2
  import {operator} from 'putout';
2
- import {resolve} from 'node:path';
3
3
 
4
4
  const {
5
5
  getTemplateValues,
@@ -7,6 +7,9 @@ const {
7
7
  } = operator;
8
8
 
9
9
  const maybeAddJs = (a) => {
10
+ if (!a.startsWith('/') && !a.startsWith('./'))
11
+ return a;
12
+
10
13
  if (a.endsWith('.js'))
11
14
  return a;
12
15
 
@@ -37,3 +40,13 @@ export const traverse = ({push, options}) => ({
37
40
  });
38
41
  },
39
42
  });
43
+
44
+ function resolve(dir, filename) {
45
+ if (filename.startsWith('/'))
46
+ return filename;
47
+
48
+ if (filename.startsWith('./'))
49
+ return path.resolve(dir, filename);
50
+
51
+ return filename;
52
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@putout/bundler",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "author": "coderaiser <mnemonic.enemy@gmail.com> (https://github.com/coderaiser)",
6
6
  "description": "Lint Filesystem with 🐊Putout",
@@ -33,8 +33,6 @@
33
33
  "@putout/cli-choose": "^2.0.0",
34
34
  "@putout/cli-filesystem": "^2.0.1",
35
35
  "@putout/engine-runner": "^21.0.0",
36
- "@putout/formatter-codeframe": "^6.0.0",
37
- "@putout/formatter-dump": "^4.0.1",
38
36
  "@putout/operator-filesystem": "^4.0.1",
39
37
  "@putout/operator-json": "^2.0.0",
40
38
  "@putout/plugin-filesystem": "^4.0.0",